From 202e855cb8d78c8a1af9645bf79c7a6ca0713310 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sat, 30 Oct 2010 17:02:39 +0100 Subject: Implement wildcard name to number lookups --- blasms.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/blasms.c b/blasms.c index 4780d37..84a3a2e 100644 --- a/blasms.c +++ b/blasms.c @@ -104,6 +104,12 @@ void settelnum(char* telnum, char* sms, int *offsetptr) { name[offset] = '\0'; } + if (!strcmp(name, "*")) { + strcpy(telnum, name); + *offsetptr = *offsetptr + 2; + return; + } + strtolower(name, name); while (fgets(line, 1024, fp) != NULL) { @@ -145,6 +151,8 @@ int main(int argc, char *argv[]) { char smscommand[11]; /* Command to execute */ char systemcmd[1000]; + /* Dynamic systemcmd for wildcard matches */ + char wildcardcmd[1000]; /* Default command to execute */ char defaultcmd[1000]; /* Length of command */ @@ -162,6 +170,11 @@ int main(int argc, char *argv[]) { /* Command match / telnum set */ short int match = 0; + struct { + int pos; + } wildcard[1000]; + int wildcards = 0; + if (argc != 3 || !strcmp(argv[argc - 1], "--help")) { fprintf(stderr, "Usage: %s sender-number send-date\n" "\n" @@ -278,14 +291,40 @@ int main(int argc, char *argv[]) { settelnum(telnum, sms, &offset); match = 1; } + if (!strcmp(telnum, "*")) { + wildcard[wildcards].pos = i; + wildcards++; + } replacestr(systemcmd, i, 2, telnum); break; } } } - printf("Executing: %s\n", systemcmd); - system(systemcmd); + if (wildcards) { + fp = fopen("phonebook.conf", "r"); + + if (fp == NULL) { + printf("Error opening phonebook.conf.\n"); + return 1; + } + + while (fgets(line, 1024, fp) != NULL) { + if ((strchrp = strchr(line, ' ')) != NULL) { + offset = 1; + strcpy(wildcardcmd, systemcmd); + line[strchrp - line] = '\0'; + for (i = 0; i < wildcards; i++) { + replacestr(wildcardcmd, wildcard[i].pos + (int)strlen(line) * i - i, 1, line); + } + printf("Executing: %s\n", wildcardcmd); + system(wildcardcmd); + } + } + } else { + printf("Executing: %s\n", systemcmd); + system(systemcmd); + } return 0; } -- cgit v1.2.3