summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--blasms.c43
2 files changed, 45 insertions, 0 deletions
diff --git a/README b/README
index ef98b97..d77e01a 100644
--- a/README
+++ b/README
@@ -18,6 +18,8 @@ are available, allowing for text replacement. The macros available are:
%n - replaced with the sender-number
%d - replaced with the send-date
%s - replaced with the SMS content
+ %P - attempts to replace the second word in the SMS with a destination number\n"
+ from phonebook.conf - SMS not processed if entry not found\n"
An example blasms.conf might be:
default echo \"SMS from %N at %d: %s\"
diff --git a/blasms.c b/blasms.c
index b32d59d..9cbd8c4 100644
--- a/blasms.c
+++ b/blasms.c
@@ -67,6 +67,43 @@ void setname(char* telnum) {
}
}
+/* Set a sender's number as part of their name */
+void settelnum(char* telnum, char* sms, int *offsetptr) {
+ FILE *fp;
+ char line[1024];
+ char name[1000];
+ char *strchrp;
+ int offset = *offsetptr;
+
+ fp = fopen("phonebook.conf", "r");
+
+ if (fp == NULL) {
+ printf("Error opening blasms.conf.\n");
+ return;
+ }
+
+ strcpy(name, sms + offset + 1);
+
+ if ((strchrp = strchr(name, ' ')) != NULL) {
+ offset = strchrp - name;
+ name[offset] = '\0';
+ }
+
+ while (fgets(line, 1024, fp) != NULL) {
+ remtrailn(line);
+ if ((strchrp = strchr(line, ' ')) != NULL) {
+ offset = strchrp - line;
+ if ((strlen(name) == strlen(line) - offset - 1) && !strncmp(name, line + offset + 1, strlen(name))) {
+ //printf("Name match: %s\n", line);
+ strxfrm(telnum, line, offset);
+ telnum[offset] = '\0';
+ }
+ }
+ }
+
+ *offsetptr = offset;
+}
+
int main(int argc, char *argv[]) {
/* Telephone number (may contain name)*/
char telnum[100];
@@ -114,6 +151,8 @@ int main(int argc, char *argv[]) {
" %%n - replaced with the sender-number\n"
" %%d - replaced with the send-date\n"
" %%s - replaced with the SMS content\n"
+ " %%P - attempts to replace the second word in the SMS with a destination number\n"
+ " from phonebook.conf - SMS not processed if entry not found\n"
"\n"
"An example blasms.conf might be:\n"
" default echo \\\"SMS from %%N at %%d: %%s\\\"\n"
@@ -199,6 +238,10 @@ int main(int argc, char *argv[]) {
case 's':
replacestr(systemcmd, i, sms + offset + 1);
break;
+ case 'P':
+ settelnum(telnum, sms, &offset);
+ replacestr(systemcmd, i, telnum);
+ break;
}
}
}