diff options
author | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-10-30 01:34:26 +0100 |
---|---|---|
committer | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-10-30 01:34:26 +0100 |
commit | 9df202451be8699dd32cbbd715acb9b5b547c6b1 (patch) | |
tree | 03953af8d7cca22a8f3a97f67d97ca1706eb64e2 | |
parent | af1b36c5339598c8837199e40aec2e66845a3556 (diff) |
Add support for multiple names per line in phonebook.conf
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | blasms.c | 41 | ||||
-rw-r--r-- | phonebook.conf | 4 |
3 files changed, 32 insertions, 15 deletions
@@ -26,7 +26,7 @@ An example blasms.conf might be: LS ls %s Sender names are looked up in phonebook.conf, which should be in the format: - NUMBER1 NAME1 + NUMBER1 NAME1 NAME1-ALT NUMBER2 NAME2 etc. @@ -65,13 +65,17 @@ void setname(char* telnum) { while (fgets(line, 1024, fp) != NULL) { remtrailn(line); - if ((strchrp = strchr(line, ' ')) != NULL) { + if ((strchrp = strchr(line + offset, ' ')) != NULL) { offset = strchrp - line; if ((strlen(telnum) == offset) && !strncmp(telnum, line, offset)) { + if ((strchrp = strchr(line + offset + 1, ' ')) != NULL) { + line[strchrp - line] = '\0'; + } //printf("Name match: %s\n", line); strcat(telnum, " ("); strcat(telnum, line + offset + 1); strcat(telnum, ")"); + return; } } } @@ -82,9 +86,10 @@ void settelnum(char* telnum, char* sms, int *offsetptr) { FILE *fp; char line[1024]; char name[1000]; - char namelower[1000]; + char curname[1000]; char *strchrp; int offset = *offsetptr; + int i, j; fp = fopen("phonebook.conf", "r"); @@ -100,18 +105,30 @@ void settelnum(char* telnum, char* sms, int *offsetptr) { name[offset] = '\0'; } + strtolower(name, name); + while (fgets(line, 1024, fp) != NULL) { remtrailn(line); - if ((strchrp = strchr(line, ' ')) != NULL) { - offset = strchrp - line; - strtolower(namelower, name); - strtolower(line, line); - if ((strlen(name) == strlen(line) - offset - 1) && !strncmp(namelower, line + offset + 1, strlen(name))) { - //printf("Name match: %s\n", line); - strxfrm(telnum, line, offset); - telnum[offset] = '\0'; - *offsetptr = *offsetptr + strlen(name) + 1; - return; + strtolower(line, line); + for (i = 0; i < strlen(line); i++) { + if (line[i] == ' ') { + break; + } + } + offset = i + 1; + for (i = 0, j = 0; i < strlen(line + offset - 1); i++, j++) { + if (line[i + offset] != ' ' && line[i + offset] != '\0') { + curname[j] = line[i + offset]; + } else { + curname[j] = '\0'; + if (!strcmp(name, curname)) { + strncpy(telnum, line, offset - 1); + telnum[offset] = '\0'; + *offsetptr = *offsetptr + strlen(name) + 1; + return; + } else { + j = -1; + } } } } diff --git a/phonebook.conf b/phonebook.conf index be470a8..cb1cfed 100644 --- a/phonebook.conf +++ b/phonebook.conf @@ -1,5 +1,5 @@ +447797827830 l_bratch +447515420226 FBeans -+447780152152 wjoe ++447780152152 wjoe george +447795076921 otherl -+447884380709 jagw
\ No newline at end of file ++447884380709 jagw |