1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*
Tomato Firmware
Copyright (C) 2006-2009 Jonathan Zarate
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <bcmnvram.h>
#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;
}
|