/* 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"

}
