fixes, fully translated tomato, with english dictionary and Polish translation
[tomato.git] / release / src / router / shared / strings.c
blob4b958e2446abad3c87454dab423de3473299d220
1 /*
3 Tomato Firmware
4 Copyright (C) 2006-2009 Jonathan Zarate
6 */
8 #include <string.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <fcntl.h>
13 #include <sys/stat.h>
14 #include <stdarg.h>
16 #include <bcmnvram.h>
17 #include "shutils.h"
18 #include "shared.h"
20 const char *find_word(const char *buffer, const char *word)
22 const char *p, *q;
23 int n;
25 n = strlen(word);
26 p = buffer;
27 while ((p = strstr(p, word)) != NULL) {
28 if ((p == buffer) || (*(p - 1) == ' ') || (*(p - 1) == ',')) {
29 q = p + n;
30 if ((*q == ' ') || (*q == ',') || (*q == 0)) {
31 return p;
34 ++p;
36 return NULL;
40 static void add_word(char *buffer, const char *word, int max)
42 if ((*buffer != 0) && (buffer[strlen(buffer) - 1] != ' '))
43 strlcat(buffer, " ", max);
44 strlcat(buffer, word, max);
48 int remove_word(char *buffer, const char *word)
50 char *p;
51 char *q;
53 if ((p = strstr(buffer, word)) == NULL) return 0;
54 q = p;
55 p += strlen(word);
56 while (*p == ' ') ++p;
57 while ((q > buffer) && (*(q - 1) == ' ')) --q;
58 if (*q != 0) *q++ = ' ';
59 strcpy(q, p);
61 return 1;