/* Generated by re2c 1.1.1 on Thu Apr 18 18:55:08 2019 */
#line 1 "../../lnav2/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 <stdio.h>
#include <string.h>
#include <sys/types.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

    const unsigned char *yyt1;
    loop:
    
#line 73 "../../lnav2/src/log_level_re.cc"
{
	YYCTYPE yych;
	unsigned int yyaccept = 0;
	yych = YYPEEK ();
	switch (yych) {
	case 0x00:	goto yy2;
	case 'C':
	case 'c':	goto yy6;
	case 'D':
	case 'd':	goto yy7;
	case 'E':
	case 'e':	goto yy8;
	case 'F':
	case 'f':	goto yy9;
	case 'I':
	case 'i':	goto yy10;
	case 'N':
	case 'n':	goto yy11;
	case 'S':
	case 's':	goto yy12;
	case 'T':
	case 't':	goto yy13;
	case 'W':
	case 'w':	goto yy14;
	default:	goto yy4;
	}
yy2:
	YYSKIP ();
#line 75 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_UNKNOWN); }
#line 104 "../../lnav2/src/log_level_re.cc"
yy4:
	YYSKIP ();
yy5:
#line 102 "../../lnav2/src/log_level_re.re"
	{ goto loop; }
#line 110 "../../lnav2/src/log_level_re.cc"
yy6:
	yyaccept = 0;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'R':
	case 'r':	goto yy15;
	default:	goto yy5;
	}
yy7:
	yyaccept = 0;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'E':
	case 'e':	goto yy17;
	default:	goto yy5;
	}
yy8:
	yyaccept = 0;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'R':
	case 'r':	goto yy18;
	default:	goto yy5;
	}
yy9:
	yyaccept = 0;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'A':
	case 'a':	goto yy19;
	default:	goto yy5;
	}
yy10:
	yyaccept = 0;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'N':
	case 'n':	goto yy20;
	default:	goto yy5;
	}
yy11:
	yyaccept = 0;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'O':
	case 'o':	goto yy21;
	default:	goto yy5;
	}
yy12:
	yyaccept = 0;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'E':
	case 'e':	goto yy22;
	case 'T':
	case 't':	goto yy23;
	default:	goto yy5;
	}
yy13:
	yyaccept = 0;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'R':
	case 'r':	goto yy24;
	default:	goto yy5;
	}
yy14:
	yyaccept = 0;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'A':
	case 'a':	goto yy25;
	default:	goto yy5;
	}
yy15:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'I':
	case 'i':	goto yy26;
	default:	goto yy16;
	}
yy16:
	YYRESTORE ();
	switch (yyaccept) {
	case 0: 	goto yy5;
	case 1: 	goto yy29;
	default:	goto yy48;
	}
yy17:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'B':
	case 'b':	goto yy27;
	default:	goto yy16;
	}
yy18:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'R':
	case 'r':	goto yy28;
	default:	goto yy16;
	}
yy19:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'T':
	case 't':	goto yy30;
	default:	goto yy16;
	}
yy20:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'F':
	case 'f':	goto yy31;
	default:	goto yy16;
	}
yy21:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'T':
	case 't':	goto yy32;
	default:	goto yy16;
	}
yy22:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'V':
	case 'v':	goto yy33;
	default:	goto yy16;
	}
yy23:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'A':
	case 'a':	goto yy34;
	default:	goto yy16;
	}
yy24:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'A':
	case 'a':	goto yy35;
	default:	goto yy16;
	}
yy25:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'R':
	case 'r':	goto yy36;
	default:	goto yy16;
	}
yy26:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'T':
	case 't':	goto yy37;
	default:	goto yy16;
	}
yy27:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'U':
	case 'u':	goto yy38;
	default:	goto yy16;
	}
yy28:
	yyaccept = 1;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'O':
	case 'o':	goto yy39;
	default:	goto yy29;
	}
yy29:
#line 98 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_ERROR); }
#line 319 "../../lnav2/src/log_level_re.cc"
yy30:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'A':
	case 'a':	goto yy40;
	default:	goto yy16;
	}
yy31:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'O':
	case 'o':	goto yy41;
	default:	goto yy16;
	}
yy32:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'I':
	case 'i':	goto yy43;
	default:	goto yy16;
	}
yy33:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'E':
	case 'e':	goto yy44;
	default:	goto yy16;
	}
yy34:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'T':
	case 't':	goto yy45;
	default:	goto yy16;
	}
yy35:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'C':
	case 'c':	goto yy46;
	default:	goto yy16;
	}
yy36:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'N':
	case 'n':	goto yy47;
	default:	goto yy16;
	}
yy37:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'I':
	case 'i':	goto yy49;
	default:	goto yy16;
	}
yy38:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'G':
	case 'g':	goto yy50;
	default:	goto yy16;
	}
yy39:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'R':
	case 'r':	goto yy52;
	default:	goto yy16;
	}
yy40:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'L':
	case 'l':	goto yy53;
	default:	goto yy16;
	}
yy41:
	YYSKIP ();
#line 94 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_INFO); }
#line 412 "../../lnav2/src/log_level_re.cc"
yy43:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'C':
	case 'c':	goto yy55;
	default:	goto yy16;
	}
yy44:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'R':
	case 'r':	goto yy56;
	default:	goto yy16;
	}
yy45:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'S':
	case 's':	goto yy57;
	default:	goto yy16;
	}
yy46:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'E':
	case 'e':	goto yy59;
	default:	goto yy16;
	}
yy47:
	yyaccept = 2;
	YYSKIP ();
	YYBACKUP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'I':
	case 'i':	goto yy61;
	default:	goto yy48;
	}
yy48:
#line 97 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_WARNING); }
#line 458 "../../lnav2/src/log_level_re.cc"
yy49:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'C':
	case 'c':	goto yy62;
	default:	goto yy16;
	}
yy50:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case '2':
	case '3':
	case '4':
	case '5':	goto yy63;
	default:
		YYSTAGP (yyt1);
		goto yy51;
	}
yy51:
	debug_level = yyt1;
#line 77 "../../lnav2/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 499 "../../lnav2/src/log_level_re.cc"
yy52:
	YYSKIP ();
	goto yy29;
yy53:
	YYSKIP ();
#line 101 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_FATAL); }
#line 507 "../../lnav2/src/log_level_re.cc"
yy55:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'E':
	case 'e':	goto yy64;
	default:	goto yy16;
	}
yy56:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'E':
	case 'e':	goto yy66;
	default:	goto yy16;
	}
yy57:
	YYSKIP ();
#line 96 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_STATS); }
#line 528 "../../lnav2/src/log_level_re.cc"
yy59:
	YYSKIP ();
#line 76 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_TRACE); }
#line 533 "../../lnav2/src/log_level_re.cc"
yy61:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'N':
	case 'n':	goto yy68;
	default:	goto yy16;
	}
yy62:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'A':
	case 'a':	goto yy69;
	default:	goto yy16;
	}
yy63:
	YYSKIP ();
	YYSTAGP (yyt1);
	goto yy51;
yy64:
	YYSKIP ();
#line 95 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_NOTICE); }
#line 558 "../../lnav2/src/log_level_re.cc"
yy66:
	YYSKIP ();
#line 100 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_CRITICAL); }
#line 563 "../../lnav2/src/log_level_re.cc"
yy68:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'G':
	case 'g':	goto yy70;
	default:	goto yy16;
	}
yy69:
	YYSKIP ();
	yych = YYPEEK ();
	switch (yych) {
	case 'L':
	case 'l':	goto yy71;
	default:	goto yy16;
	}
yy70:
	YYSKIP ();
	goto yy48;
yy71:
	YYSKIP ();
#line 99 "../../lnav2/src/log_level_re.re"
	{ RET(LEVEL_CRITICAL); }
#line 587 "../../lnav2/src/log_level_re.cc"
}
#line 104 "../../lnav2/src/log_level_re.re"

}
