diff options
author | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-10-30 17:02:39 +0100 |
---|---|---|
committer | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-10-30 17:02:39 +0100 |
commit | 202e855cb8d78c8a1af9645bf79c7a6ca0713310 (patch) | |
tree | 40d6f0e426d77ea8e18a9b5aa262d6205883ac4d | |
parent | 48693c1f54be57f718999ac156d12a25c1f53803 (diff) |
Implement wildcard name to number lookups
-rw-r--r-- | blasms.c | 43 |
1 files changed, 41 insertions, 2 deletions
@@ -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; } |