This source file includes following definitions.
- myisspace
- __cmdline_find_option_bool
- __cmdline_find_option
- cmdline_find_option_bool
- cmdline_find_option
1
2
3
4
5
6 #include <linux/kernel.h>
7 #include <linux/string.h>
8 #include <linux/ctype.h>
9 #include <asm/setup.h>
10
11 static inline int myisspace(u8 c)
12 {
13 return c <= ' ';
14 }
15
16
17
18
19
20
21
22
23
24
25
26
27 static int
28 __cmdline_find_option_bool(const char *cmdline, int max_cmdline_size,
29 const char *option)
30 {
31 char c;
32 int pos = 0, wstart = 0;
33 const char *opptr = NULL;
34 enum {
35 st_wordstart = 0,
36 st_wordcmp,
37 st_wordskip,
38 } state = st_wordstart;
39
40 if (!cmdline)
41 return -1;
42
43
44
45
46
47 while (pos < max_cmdline_size) {
48 c = *(char *)cmdline++;
49 pos++;
50
51 switch (state) {
52 case st_wordstart:
53 if (!c)
54 return 0;
55 else if (myisspace(c))
56 break;
57
58 state = st_wordcmp;
59 opptr = option;
60 wstart = pos;
61
62
63 case st_wordcmp:
64 if (!*opptr) {
65
66
67
68
69
70
71 if (!c || myisspace(c))
72 return wstart;
73
74
75
76
77
78 } else if (!c) {
79
80
81
82
83 return 0;
84 } else if (c == *opptr++) {
85
86
87
88
89 break;
90 }
91 state = st_wordskip;
92
93
94 case st_wordskip:
95 if (!c)
96 return 0;
97 else if (myisspace(c))
98 state = st_wordstart;
99 break;
100 }
101 }
102
103 return 0;
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 static int
121 __cmdline_find_option(const char *cmdline, int max_cmdline_size,
122 const char *option, char *buffer, int bufsize)
123 {
124 char c;
125 int pos = 0, len = -1;
126 const char *opptr = NULL;
127 char *bufptr = buffer;
128 enum {
129 st_wordstart = 0,
130 st_wordcmp,
131 st_wordskip,
132 st_bufcpy,
133 } state = st_wordstart;
134
135 if (!cmdline)
136 return -1;
137
138
139
140
141
142 while (pos++ < max_cmdline_size) {
143 c = *(char *)cmdline++;
144 if (!c)
145 break;
146
147 switch (state) {
148 case st_wordstart:
149 if (myisspace(c))
150 break;
151
152 state = st_wordcmp;
153 opptr = option;
154
155
156 case st_wordcmp:
157 if ((c == '=') && !*opptr) {
158
159
160
161
162
163 len = 0;
164 bufptr = buffer;
165 state = st_bufcpy;
166 break;
167 } else if (c == *opptr++) {
168
169
170
171
172 break;
173 }
174 state = st_wordskip;
175
176
177 case st_wordskip:
178 if (myisspace(c))
179 state = st_wordstart;
180 break;
181
182 case st_bufcpy:
183 if (myisspace(c)) {
184 state = st_wordstart;
185 } else {
186
187
188
189
190
191 if (++len < bufsize)
192 *bufptr++ = c;
193 }
194 break;
195 }
196 }
197
198 if (bufsize)
199 *bufptr = '\0';
200
201 return len;
202 }
203
204 int cmdline_find_option_bool(const char *cmdline, const char *option)
205 {
206 return __cmdline_find_option_bool(cmdline, COMMAND_LINE_SIZE, option);
207 }
208
209 int cmdline_find_option(const char *cmdline, const char *option, char *buffer,
210 int bufsize)
211 {
212 return __cmdline_find_option(cmdline, COMMAND_LINE_SIZE, option,
213 buffer, bufsize);
214 }