From d17a8ed18ca5e154faa8f753e8dac98188afcde5 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Wed, 27 Oct 2010 23:34:34 +0100 Subject: Added %P macro, which converts a name to a number for sending SMSes --- blasms.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'blasms.c') 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; } } } -- cgit v1.2.3