summaryrefslogtreecommitdiffstats
path: root/src/log_level_re.cc
blob: a53f2942fe49a2575c22b788cebec0c5cdc57b7c (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
/* Generated by re2c 3.1 on Mon Apr  1 11:22:38 2024 */
#line 1 "../../lnav/src/log_level_re.re"
/**
 * Copyright (c) 2018, Timothy Stack
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * * Neither the name of Timothy Stack nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "config.h"

#include <string.h>

#include "log_level.hh"

log_level_t string2level(const char *levelstr, ssize_t len, bool exact)
{
    log_level_t retval = LEVEL_UNKNOWN;

    if (len == (ssize_t)-1) {
        len = strlen(levelstr);
    }

    if (((len == 1) || ((len > 1) && (levelstr[1] == ' '))) &&
        (retval = abbrev2level(levelstr, 1)) != LEVEL_UNKNOWN) {
        return retval;
    }

#   define YYCTYPE unsigned char
#   define RET(tok) { \
        return tok; \
    }

    const YYCTYPE *YYCURSOR = (const unsigned char *) levelstr;
    const YYCTYPE *YYLIMIT = (const unsigned char *) levelstr + len;
    const YYCTYPE *YYMARKER = YYCURSOR;
    const YYCTYPE *debug_level = nullptr;

#   define YYPEEK()    (YYCURSOR < YYLIMIT ? *YYCURSOR : 0)
#   define YYSKIP()    ++YYCURSOR
#   define YYBACKUP()  YYMARKER = YYCURSOR
#   define YYRESTORE() YYCURSOR = YYMARKER
#   define YYSTAGP(x)  x = YYCURSOR - 1

    
#line 69 "../../lnav/src/log_level_re.cc"
#line 65 "../../lnav/src/log_level_re.re"

    loop:
    
#line 74 "../../lnav/src/log_level_re.cc"
{
	YYCTYPE yych;
	unsigned int yyaccept = 0;
	yych = YYPEEK();
	if (yych <= 'W') {
		if (yych <= 'H') {
			if (yych <= 'C') {
				if (yych <= 0x00) goto yy1;
				if (yych <= 'B') goto yy2;
				goto yy4;
			} else {
				if (yych <= 'D') goto yy5;
				if (yych <= 'E') goto yy6;
				if (yych <= 'F') goto yy7;
				goto yy2;
			}
		} else {
			if (yych <= 'R') {
				if (yych <= 'I') goto yy8;
				if (yych == 'N') goto yy9;
				goto yy2;
			} else {
				if (yych <= 'S') goto yy10;
				if (yych <= 'T') goto yy11;
				if (yych <= 'V') goto yy2;
				goto yy12;
			}
		}
	} else {
		if (yych <= 'i') {
			if (yych <= 'd') {
				if (yych <= 'b') goto yy2;
				if (yych <= 'c') goto yy4;
				goto yy5;
			} else {
				if (yych <= 'e') goto yy6;
				if (yych <= 'f') goto yy7;
				if (yych <= 'h') goto yy2;
				goto yy8;
			}
		} else {
			if (yych <= 's') {
				if (yych == 'n') goto yy9;
				if (yych <= 'r') goto yy2;
				goto yy10;
			} else {
				if (yych <= 't') goto yy11;
				if (yych == 'w') goto yy12;
				goto yy2;
			}
		}
	}
yy1:
	YYSKIP();
#line 74 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_UNKNOWN); }
#line 131 "../../lnav/src/log_level_re.cc"
yy2:
	YYSKIP();
yy3:
#line 101 "../../lnav/src/log_level_re.re"
	{ goto loop; }
#line 137 "../../lnav/src/log_level_re.cc"
yy4:
	yyaccept = 0;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'R') goto yy13;
	if (yych == 'r') goto yy13;
	goto yy3;
yy5:
	yyaccept = 0;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'E') goto yy15;
	if (yych == 'e') goto yy15;
	goto yy3;
yy6:
	yyaccept = 0;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'R') goto yy16;
	if (yych == 'r') goto yy16;
	goto yy3;
yy7:
	yyaccept = 0;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'A') goto yy17;
	if (yych == 'a') goto yy17;
	goto yy3;
yy8:
	yyaccept = 0;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'N') goto yy18;
	if (yych == 'n') goto yy18;
	goto yy3;
yy9:
	yyaccept = 0;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'O') goto yy19;
	if (yych == 'o') goto yy19;
	goto yy3;
yy10:
	yyaccept = 0;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych <= 'T') {
		if (yych == 'E') goto yy20;
		if (yych <= 'S') goto yy3;
		goto yy21;
	} else {
		if (yych <= 'e') {
			if (yych <= 'd') goto yy3;
			goto yy20;
		} else {
			if (yych == 't') goto yy21;
			goto yy3;
		}
	}
yy11:
	yyaccept = 0;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'R') goto yy22;
	if (yych == 'r') goto yy22;
	goto yy3;
yy12:
	yyaccept = 0;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'A') goto yy23;
	if (yych == 'a') goto yy23;
	goto yy3;
yy13:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'I') goto yy24;
	if (yych == 'i') goto yy24;
yy14:
	YYRESTORE();
	if (yyaccept <= 1) {
		if (yyaccept == 0) {
			goto yy3;
		} else {
			goto yy27;
		}
	} else {
		goto yy45;
	}
yy15:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'B') goto yy25;
	if (yych == 'b') goto yy25;
	goto yy14;
yy16:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'R') goto yy26;
	if (yych == 'r') goto yy26;
	goto yy14;
yy17:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'T') goto yy28;
	if (yych == 't') goto yy28;
	goto yy14;
yy18:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'F') goto yy29;
	if (yych == 'f') goto yy29;
	goto yy14;
yy19:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'T') goto yy30;
	if (yych == 't') goto yy30;
	goto yy14;
yy20:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'V') goto yy31;
	if (yych == 'v') goto yy31;
	goto yy14;
yy21:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'A') goto yy32;
	if (yych == 'a') goto yy32;
	goto yy14;
yy22:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'A') goto yy33;
	if (yych == 'a') goto yy33;
	goto yy14;
yy23:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'R') goto yy34;
	if (yych == 'r') goto yy34;
	goto yy14;
yy24:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'T') goto yy35;
	if (yych == 't') goto yy35;
	goto yy14;
yy25:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'U') goto yy36;
	if (yych == 'u') goto yy36;
	goto yy14;
yy26:
	yyaccept = 1;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'O') goto yy37;
	if (yych == 'o') goto yy37;
yy27:
#line 97 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_ERROR); }
#line 312 "../../lnav/src/log_level_re.cc"
yy28:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'A') goto yy38;
	if (yych == 'a') goto yy38;
	goto yy14;
yy29:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'O') goto yy39;
	if (yych == 'o') goto yy39;
	goto yy14;
yy30:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'I') goto yy40;
	if (yych == 'i') goto yy40;
	goto yy14;
yy31:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'E') goto yy41;
	if (yych == 'e') goto yy41;
	goto yy14;
yy32:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'T') goto yy42;
	if (yych == 't') goto yy42;
	goto yy14;
yy33:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'C') goto yy43;
	if (yych == 'c') goto yy43;
	goto yy14;
yy34:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'N') goto yy44;
	if (yych == 'n') goto yy44;
	goto yy14;
yy35:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'I') goto yy46;
	if (yych == 'i') goto yy46;
	goto yy14;
yy36:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'G') goto yy47;
	if (yych == 'g') goto yy47;
	goto yy14;
yy37:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'R') goto yy49;
	if (yych == 'r') goto yy49;
	goto yy14;
yy38:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'L') goto yy50;
	if (yych == 'l') goto yy50;
	goto yy14;
yy39:
	YYSKIP();
#line 93 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_INFO); }
#line 383 "../../lnav/src/log_level_re.cc"
yy40:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'C') goto yy51;
	if (yych == 'c') goto yy51;
	goto yy14;
yy41:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'R') goto yy52;
	if (yych == 'r') goto yy52;
	goto yy14;
yy42:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'S') goto yy53;
	if (yych == 's') goto yy53;
	goto yy14;
yy43:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'E') goto yy54;
	if (yych == 'e') goto yy54;
	goto yy14;
yy44:
	yyaccept = 2;
	YYSKIP();
	YYBACKUP();
	yych = YYPEEK();
	if (yych == 'I') goto yy55;
	if (yych == 'i') goto yy55;
yy45:
#line 96 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_WARNING); }
#line 418 "../../lnav/src/log_level_re.cc"
yy46:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'C') goto yy56;
	if (yych == 'c') goto yy56;
	goto yy14;
yy47:
	YYSKIP();
	yych = YYPEEK();
	if (yych <= '1') goto yy48;
	if (yych <= '5') goto yy57;
yy48:
	YYSTAGP(debug_level);
#line 76 "../../lnav/src/log_level_re.re"
	{
         if (debug_level == nullptr) {
             RET(LEVEL_DEBUG);
         }
         switch (*debug_level) {
         case '2':
             RET(LEVEL_DEBUG2);
         case '3':
             RET(LEVEL_DEBUG3);
         case '4':
             RET(LEVEL_DEBUG4);
         case '5':
             RET(LEVEL_DEBUG5);
         default:
             RET(LEVEL_DEBUG);
         }
     }
#line 450 "../../lnav/src/log_level_re.cc"
yy49:
	YYSKIP();
	goto yy27;
yy50:
	YYSKIP();
#line 100 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_FATAL); }
#line 458 "../../lnav/src/log_level_re.cc"
yy51:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'E') goto yy58;
	if (yych == 'e') goto yy58;
	goto yy14;
yy52:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'E') goto yy59;
	if (yych == 'e') goto yy59;
	goto yy14;
yy53:
	YYSKIP();
#line 95 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_STATS); }
#line 475 "../../lnav/src/log_level_re.cc"
yy54:
	YYSKIP();
#line 75 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_TRACE); }
#line 480 "../../lnav/src/log_level_re.cc"
yy55:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'N') goto yy60;
	if (yych == 'n') goto yy60;
	goto yy14;
yy56:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'A') goto yy61;
	if (yych == 'a') goto yy61;
	goto yy14;
yy57:
	YYSKIP();
	goto yy48;
yy58:
	YYSKIP();
#line 94 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_NOTICE); }
#line 500 "../../lnav/src/log_level_re.cc"
yy59:
	YYSKIP();
#line 99 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_CRITICAL); }
#line 505 "../../lnav/src/log_level_re.cc"
yy60:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'G') goto yy62;
	if (yych == 'g') goto yy62;
	goto yy14;
yy61:
	YYSKIP();
	yych = YYPEEK();
	if (yych == 'L') goto yy63;
	if (yych == 'l') goto yy63;
	goto yy14;
yy62:
	YYSKIP();
	goto yy45;
yy63:
	YYSKIP();
#line 98 "../../lnav/src/log_level_re.re"
	{ RET(LEVEL_CRITICAL); }
#line 525 "../../lnav/src/log_level_re.cc"
}
#line 103 "../../lnav/src/log_level_re.re"

}