/* * Copyright (c) 1997-2000 Silicon Graphics, Inc. All Rights Reserved. * Copyright (c) 2011 Ken McDonell. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ %{ /* * pmlogrewrite configfile lexical scanner */ #include "pmapi.h" #include "impl.h" #include "logger.h" #include char mess[256]; #define LEX_NONE 0 #define LEX_GLOBAL 1 #define LEX_INDOM 2 #define LEX_METRIC 3 int mystate = LEX_NONE; static int comma_count; #include "gram.tab.h" static char * dupstr(char *s, int strip_quotes) { char *p; if (strip_quotes) p = strdup(&s[1]); else p = strdup(s); if (p == NULL) { fprintf(stderr, "Failed strdup(\"%s\") in lexer: %s\n", s, strerror(errno)); abandon(); /*NOTREACHED*/ } if (strip_quotes) { char *pend = p; while (*pend != '\0') pend++; *--pend = '\0'; } return p; } %} %option noinput %option nounput %{ #ifdef FLEX_SCANNER #ifndef YY_NO_UNPUT #define YY_NO_UNPUT #endif #endif %} %s none glob host indom metric type sem units space time count output %option case-insensitive %% "global" { mystate= LEX_GLOBAL; return TOK_GLOBAL; } "metric" { mystate = LEX_METRIC; return TOK_METRIC; } "indom" { mystate = LEX_INDOM; return TOK_INDOM; } "hostname" { BEGIN(host); return TOK_HOSTNAME; } "time" { return TOK_TIME; } "tz" { return TOK_TZ; } /* Hostname */ [A-Za-z0-9][A-Za-z0-9.-]* { yylval.str = dupstr(yytext, 0); BEGIN(glob); return TOK_HNAME; } "delete" { return TOK_DELETE; } "indom" { return TOK_INDOM; } "duplicate" { return TOK_DUPLICATE; } "iname" { return TOK_INAME; } "inst" { return TOK_INST; } "name" { return TOK_NAME; } "pmid" { return TOK_PMID; } "type" { BEGIN(type); return TOK_TYPE; } "indom" { return TOK_INDOM; } "NULL" { return TOK_NULL_INT; } "output" { BEGIN(output); return TOK_OUTPUT; } "sem" { BEGIN(sem); return TOK_SEM; } "units" { BEGIN(units); comma_count = 0; return TOK_UNITS; } "32" { yylval.ival = PM_TYPE_32; BEGIN(metric); return TOK_TYPE_NAME; } "U32" { yylval.ival = PM_TYPE_U32; BEGIN(metric); return TOK_TYPE_NAME; } "64" { yylval.ival = PM_TYPE_64; BEGIN(metric); return TOK_TYPE_NAME; } "U64" { yylval.ival = PM_TYPE_U64; BEGIN(metric); return TOK_TYPE_NAME; } "FLOAT" { yylval.ival = PM_TYPE_FLOAT; BEGIN(metric); return TOK_TYPE_NAME; } "DOUBLE" { yylval.ival = PM_TYPE_DOUBLE; BEGIN(metric); return TOK_TYPE_NAME; } "first" { yylval.ival = OUTPUT_FIRST; BEGIN(metric); return TOK_OUTPUT_TYPE; } "last" { yylval.ival = OUTPUT_LAST; BEGIN(metric); return TOK_OUTPUT_TYPE; } "min" { yylval.ival = OUTPUT_MIN; BEGIN(metric); return TOK_OUTPUT_TYPE; } "max" { yylval.ival = OUTPUT_MAX; BEGIN(metric); return TOK_OUTPUT_TYPE; } "sum" { yylval.ival = OUTPUT_SUM; BEGIN(metric); return TOK_OUTPUT_TYPE; } "avg" { yylval.ival = OUTPUT_AVG; BEGIN(metric); return TOK_OUTPUT_TYPE; } "inst" { BEGIN(metric); return TOK_INST; } "iname" { BEGIN(metric); return TOK_INAME; } "COUNTER" { yylval.ival = PM_SEM_COUNTER; BEGIN(metric); return TOK_SEM_NAME; } "INSTANT" { yylval.ival = PM_SEM_INSTANT; BEGIN(metric); return TOK_SEM_NAME; } "DISCRETE" { yylval.ival = PM_SEM_DISCRETE; BEGIN(metric); return TOK_SEM_NAME; } "," { ++comma_count; switch (comma_count) { case 1: case 2: break; case 3: BEGIN(space); break; case 4: BEGIN(time); break; case 5: BEGIN(count); break; } return TOK_COMMA; } "rescale" { return TOK_RESCALE; } "BYTE" { yylval.ival = PM_SPACE_BYTE; BEGIN(units); return TOK_SPACE_NAME; } "KBYTE" { yylval.ival = PM_SPACE_KBYTE; BEGIN(units); return TOK_SPACE_NAME; } "MBYTE" { yylval.ival = PM_SPACE_MBYTE; BEGIN(units); return TOK_SPACE_NAME; } "GBYTE" { yylval.ival = PM_SPACE_GBYTE; BEGIN(units); return TOK_SPACE_NAME; } "TBYTE" { yylval.ival = PM_SPACE_TBYTE; BEGIN(units); return TOK_SPACE_NAME; } "PBYTE" { yylval.ival = PM_SPACE_PBYTE; BEGIN(units); return TOK_SPACE_NAME; } "EBYTE" { yylval.ival = PM_SPACE_EBYTE; BEGIN(units); return TOK_SPACE_NAME; } "0" { yylval.ival = 0; BEGIN(units); return TOK_SPACE_NAME; }