diff options
-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 |