1
2
3
4
5
6
7#include <linux/kernel.h>
8#include <linux/string.h>
9#include <linux/ctype.h>
10#include <asm/setup.h>
11
12static inline int myisspace(u8 c)
13{
14 return c <= ' ';
15}
16
17
18
19
20
21
22
23
24
25
26int cmdline_find_option_bool(const char *cmdline, const char *option)
27{
28 char c;
29 int len, pos = 0, wstart = 0;
30 const char *opptr = NULL;
31 enum {
32 st_wordstart = 0,
33 st_wordcmp,
34 st_wordskip,
35 } state = st_wordstart;
36
37 if (!cmdline)
38 return -1;
39
40 len = min_t(int, strlen(cmdline), COMMAND_LINE_SIZE);
41 if (!len)
42 return 0;
43
44 while (len--) {
45 c = *(char *)cmdline++;
46 pos++;
47
48 switch (state) {
49 case st_wordstart:
50 if (!c)
51 return 0;
52 else if (myisspace(c))
53 break;
54
55 state = st_wordcmp;
56 opptr = option;
57 wstart = pos;
58
59
60 case st_wordcmp:
61 if (!*opptr)
62 if (!c || myisspace(c))
63 return wstart;
64 else
65 state = st_wordskip;
66 else if (!c)
67 return 0;
68 else if (c != *opptr++)
69 state = st_wordskip;
70 else if (!len)
71 return wstart;
72 break;
73
74 case st_wordskip:
75 if (!c)
76 return 0;
77 else if (myisspace(c))
78 state = st_wordstart;
79 break;
80 }
81 }
82
83 return 0;
84}
85