From 3dc600edda0023d218a903c16269bd2bd6818e25 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sat, 30 Oct 2010 23:21:00 +0100 Subject: Implement %M, which reads in a file, attempting to look up the first word as a number --- blasms.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/blasms.c b/blasms.c index b95e6a6..d9e10dc 100644 --- a/blasms.c +++ b/blasms.c @@ -145,6 +145,8 @@ void settelnum(char* telnum, char* sms, int *offsetptr) { int main(int argc, char *argv[]) { /* Telephone number (may contain name)*/ char telnum[100]; + /* Unmodified telephone number length */ + int telnumlen; /* SMS content */ char sms[500]; /* SMS command */ @@ -296,6 +298,40 @@ int main(int argc, char *argv[]) { wildcards++; } replacestr(systemcmd, i, 2, telnum); + break; + case 'M': + strcpy(telnum, "pending/"); + strcat(telnum, sms + offset + 1); + + fp = fopen(telnum, "r"); + + if (fp == NULL) { + printf("Error opening message file.\n"); + return 1; + } + + if (fgets(line, 1024, fp) == NULL) { + printf("Error reading message file.\n"); + return 1; + } + + fclose(fp); + + if ((strchrp = strchr(line + offset, ' ')) != NULL) { + remtrailn(line); + strncpy(telnum, line, strchrp - line); + telnum[strchrp - line] = '\0'; + telnumlen = strlen(telnum); + setname(telnum); + } else { + printf("Error, malformed message file.\n"); + return 1; + } + + replacestr(systemcmd, i, 2, telnum); + replacestr(systemcmd, strlen(systemcmd) - 1, 0, ":"); + replacestr(systemcmd, strlen(systemcmd) - 1, 0, line + telnumlen); + break; } } -- cgit v1.2.3