summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <l_bratch@yahoo.co.uk>2010-10-30 23:21:00 +0100
committerLuke Bratch <l_bratch@yahoo.co.uk>2010-10-30 23:21:00 +0100
commit3dc600edda0023d218a903c16269bd2bd6818e25 (patch)
treefd1d002cae7b34a23dbe06c0bf29677b229bc0b5
parentabe944bb43c457246a7f0e932b4dcf2d5c4bc40c (diff)
Implement %M, which reads in a file, attempting to look up the first word as a number
-rw-r--r--blasms.c36
1 files changed, 36 insertions, 0 deletions
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 */
@@ -297,6 +299,40 @@ int main(int argc, char *argv[]) {
}
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;
}
}
}