/* Tomato Firmware Copyright (C) 2006-2009 Jonathan Zarate */ #include #include #include #include #include #include #include #include #include "shutils.h" #include "shared.h" const char *find_word(const char *buffer, const char *word) { const char *p, *q; int n; n = strlen(word); p = buffer; while ((p = strstr(p, word)) != NULL) { if ((p == buffer) || (*(p - 1) == ' ') || (*(p - 1) == ',')) { q = p + n; if ((*q == ' ') || (*q == ',') || (*q == 0)) { return p; } } ++p; } return NULL; } /* static void add_word(char *buffer, const char *word, int max) { if ((*buffer != 0) && (buffer[strlen(buffer) - 1] != ' ')) strlcat(buffer, " ", max); strlcat(buffer, word, max); } */ int remove_word(char *buffer, const char *word) { char *p; char *q; if ((p = strstr(buffer, word)) == NULL) return 0; q = p; p += strlen(word); while (*p == ' ') ++p; while ((q > buffer) && (*(q - 1) == ' ')) --q; if (*q != 0) *q++ = ' '; strcpy(q, p); return 1; }