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 /blasms.c | |
parent | af1b36c5339598c8837199e40aec2e66845a3556 (diff) |
Add support for multiple names per line in phonebook.conf
Diffstat (limited to 'blasms.c')
-rw-r--r-- | blasms.c | 41 |
1 files changed, 29 insertions, 12 deletions
@@ -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; + } } } } |