1*7c478bd9Sstevel@tonic-gate %{ 2*7c478bd9Sstevel@tonic-gate /* 3*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 4*7c478bd9Sstevel@tonic-gate * 5*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 6*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 7*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 8*7c478bd9Sstevel@tonic-gate * with the License. 9*7c478bd9Sstevel@tonic-gate * 10*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 12*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 13*7c478bd9Sstevel@tonic-gate * and limitations under the License. 14*7c478bd9Sstevel@tonic-gate * 15*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 16*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 18*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 19*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 20*7c478bd9Sstevel@tonic-gate * 21*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 22*7c478bd9Sstevel@tonic-gate * 23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate #pragma error_messages(off, E_STATEMENT_NOT_REACHED) 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * poolcfg.l 32*7c478bd9Sstevel@tonic-gate * 33*7c478bd9Sstevel@tonic-gate * Overview 34*7c478bd9Sstevel@tonic-gate * poolcfg.l implements a lexer for the poolcfg(1) utility.The lexer uses 35*7c478bd9Sstevel@tonic-gate * the token definitions generated by YACC in the file poolcfg_Grammar.h. 36*7c478bd9Sstevel@tonic-gate * To make token recognition simpler, the lexer uses a separate state for 37*7c478bd9Sstevel@tonic-gate * each of the different data types supported by poolcfg(1). 38*7c478bd9Sstevel@tonic-gate * 39*7c478bd9Sstevel@tonic-gate * States 40*7c478bd9Sstevel@tonic-gate * Lex provides the ability to minimise conflict between qualifying regexps 41*7c478bd9Sstevel@tonic-gate * by providing states. A regexp that is qualified by a state will only be 42*7c478bd9Sstevel@tonic-gate * used when the state is entered (using the BEGIN <state> command). (The 43*7c478bd9Sstevel@tonic-gate * exception to this rule, is that rules defined in the default state are 44*7c478bd9Sstevel@tonic-gate * available in all states.) 45*7c478bd9Sstevel@tonic-gate * 46*7c478bd9Sstevel@tonic-gate * poolcfg.l makes use of type states, one for each of the poolcfg(1) 47*7c478bd9Sstevel@tonic-gate * supported data types: 48*7c478bd9Sstevel@tonic-gate * 49*7c478bd9Sstevel@tonic-gate * ISTATE => int64_t 50*7c478bd9Sstevel@tonic-gate * USTATE => uint64_t 51*7c478bd9Sstevel@tonic-gate * BSTATE => uchar_t 52*7c478bd9Sstevel@tonic-gate * SSTATE => const char * 53*7c478bd9Sstevel@tonic-gate * DSTATE => double 54*7c478bd9Sstevel@tonic-gate * 55*7c478bd9Sstevel@tonic-gate * and a further state, CPUSTATE, to indicate the difference between matching 56*7c478bd9Sstevel@tonic-gate * a valid "name" (i.e. id) for a cpu and a valid name for other components of 57*7c478bd9Sstevel@tonic-gate * libpool. 58*7c478bd9Sstevel@tonic-gate * 59*7c478bd9Sstevel@tonic-gate * When a token indicating a variable declaration is matched, the corresponding 60*7c478bd9Sstevel@tonic-gate * state is saved in the state variable. Once the assignment ('=') token is 61*7c478bd9Sstevel@tonic-gate * matched, the stored state is entered and the additional state specific 62*7c478bd9Sstevel@tonic-gate * matching regular expressions become available. Once a state specific 63*7c478bd9Sstevel@tonic-gate * token is matched, the default state is restored. 64*7c478bd9Sstevel@tonic-gate * 65*7c478bd9Sstevel@tonic-gate */ 66*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 67*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 68*7c478bd9Sstevel@tonic-gate #include <assert.h> 69*7c478bd9Sstevel@tonic-gate #include <string.h> 70*7c478bd9Sstevel@tonic-gate #include <errno.h> 71*7c478bd9Sstevel@tonic-gate #include <libintl.h> 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate #include <pool.h> 74*7c478bd9Sstevel@tonic-gate #include "utils.h" 75*7c478bd9Sstevel@tonic-gate #include "poolcfg.h" 76*7c478bd9Sstevel@tonic-gate #include "poolcfg_grammar.h" 77*7c478bd9Sstevel@tonic-gate 78*7c478bd9Sstevel@tonic-gate static int lex_lineno = 1; /* line-number for error reporting */ 79*7c478bd9Sstevel@tonic-gate static int state = INITIAL; /* state to be used */ 80*7c478bd9Sstevel@tonic-gate extern void yyerror(char *s); 81*7c478bd9Sstevel@tonic-gate extern int dofile; /* are we processing a file? */ 82*7c478bd9Sstevel@tonic-gate %} 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate %s ISTATE 85*7c478bd9Sstevel@tonic-gate %s USTATE 86*7c478bd9Sstevel@tonic-gate %s BSTATE 87*7c478bd9Sstevel@tonic-gate %s SSTATE 88*7c478bd9Sstevel@tonic-gate %s DSTATE 89*7c478bd9Sstevel@tonic-gate %s CPUSTATE 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate %% 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate \n lex_lineno++; 94*7c478bd9Sstevel@tonic-gate 95*7c478bd9Sstevel@tonic-gate [ \t]+ ; 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate #.* ; 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate info { return PCC_INFO; } 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate create { return PCC_CREATE; } 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate destroy { return PCC_DESTROY; } 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate modify { return PCC_MODIFY; } 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate associate { return PCC_ASSOC; } 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate transfer { 110*7c478bd9Sstevel@tonic-gate BEGIN USTATE; 111*7c478bd9Sstevel@tonic-gate return PCC_TRANSFER; 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate discover { return PCC_DISC; } 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate rename { return PCC_RENAME; } 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate to { return PCK_TO; } 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate from { return PCK_FROM; } 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate int { 123*7c478bd9Sstevel@tonic-gate state=ISTATE; 124*7c478bd9Sstevel@tonic-gate return PCT_INT; 125*7c478bd9Sstevel@tonic-gate } 126*7c478bd9Sstevel@tonic-gate 127*7c478bd9Sstevel@tonic-gate uint { 128*7c478bd9Sstevel@tonic-gate state=USTATE; 129*7c478bd9Sstevel@tonic-gate return PCT_UINT; 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate boolean { 133*7c478bd9Sstevel@tonic-gate state=BSTATE; 134*7c478bd9Sstevel@tonic-gate return PCT_BOOLEAN; 135*7c478bd9Sstevel@tonic-gate } 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate string { 138*7c478bd9Sstevel@tonic-gate state=SSTATE; 139*7c478bd9Sstevel@tonic-gate return PCT_STRING; 140*7c478bd9Sstevel@tonic-gate } 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate float { 143*7c478bd9Sstevel@tonic-gate state=DSTATE; 144*7c478bd9Sstevel@tonic-gate return PCT_FLOAT; 145*7c478bd9Sstevel@tonic-gate } 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate cpu { 148*7c478bd9Sstevel@tonic-gate BEGIN CPUSTATE; 149*7c478bd9Sstevel@tonic-gate return PCE_CPU; 150*7c478bd9Sstevel@tonic-gate } 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate pset { return PCE_PSET; } 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate pool { return PCE_POOL; } 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate system { return PCE_SYSTEM; } 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate \( { return PCK_OPENLST; } 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate \) { return PCK_CLOSELST; } 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate = { 163*7c478bd9Sstevel@tonic-gate BEGIN state; 164*7c478bd9Sstevel@tonic-gate return PCK_ASSIGN; 165*7c478bd9Sstevel@tonic-gate } 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate \; { return PCK_SEPLST; } 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate ~ { return PCK_UNDEF; } 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate <ISTATE>-?[0-9]+ { 172*7c478bd9Sstevel@tonic-gate yylval.ival = strtoll(yytext, NULL, 0); 173*7c478bd9Sstevel@tonic-gate if (errno == EINVAL || errno == ERANGE) { 174*7c478bd9Sstevel@tonic-gate yyerror(gettext("Invalid value")); 175*7c478bd9Sstevel@tonic-gate exit(E_ERROR); 176*7c478bd9Sstevel@tonic-gate } 177*7c478bd9Sstevel@tonic-gate BEGIN INITIAL; 178*7c478bd9Sstevel@tonic-gate return PCV_VAL_INT; 179*7c478bd9Sstevel@tonic-gate } 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate <USTATE>[0-9]+ { 182*7c478bd9Sstevel@tonic-gate yylval.uval = strtoull(yytext, NULL, 0); 183*7c478bd9Sstevel@tonic-gate if (errno == EINVAL || errno == ERANGE) { 184*7c478bd9Sstevel@tonic-gate yyerror(gettext("Invalid value")); 185*7c478bd9Sstevel@tonic-gate exit(E_ERROR); 186*7c478bd9Sstevel@tonic-gate } 187*7c478bd9Sstevel@tonic-gate BEGIN INITIAL; 188*7c478bd9Sstevel@tonic-gate return PCV_VAL_UINT; 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate <BSTATE>true|false { 193*7c478bd9Sstevel@tonic-gate if (strcmp(yytext, "true") == 0) 194*7c478bd9Sstevel@tonic-gate yylval.bval = 1; 195*7c478bd9Sstevel@tonic-gate else 196*7c478bd9Sstevel@tonic-gate yylval.bval = 0; 197*7c478bd9Sstevel@tonic-gate BEGIN INITIAL; 198*7c478bd9Sstevel@tonic-gate return PCV_VAL_BOOLEAN; 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate <SSTATE>\"[^\"\n]*[\"\n] { 202*7c478bd9Sstevel@tonic-gate if((yylval.sval = strdup(yytext+1)) == NULL) { 203*7c478bd9Sstevel@tonic-gate yyerror(gettext("Out of memory")); 204*7c478bd9Sstevel@tonic-gate exit(E_ERROR); 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate if (yylval.sval[yyleng-2] =='"') 207*7c478bd9Sstevel@tonic-gate yylval.sval[yyleng-2] = 0; 208*7c478bd9Sstevel@tonic-gate BEGIN INITIAL; 209*7c478bd9Sstevel@tonic-gate return PCV_VAL_STRING; 210*7c478bd9Sstevel@tonic-gate } 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate <DSTATE>([0-9]+|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?) { 213*7c478bd9Sstevel@tonic-gate yylval.dval = strtod(yytext, (char **)NULL); 214*7c478bd9Sstevel@tonic-gate if (errno == EINVAL || errno == ERANGE) { 215*7c478bd9Sstevel@tonic-gate yyerror(gettext("Invalid value")); 216*7c478bd9Sstevel@tonic-gate exit(E_ERROR); 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate BEGIN INITIAL; 219*7c478bd9Sstevel@tonic-gate return PCV_VAL_FLOAT; 220*7c478bd9Sstevel@tonic-gate } 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate [A-Za-z][A-Za-z0-9,._-]* { 223*7c478bd9Sstevel@tonic-gate if ((yylval.sval = strdup(yytext)) == NULL) { 224*7c478bd9Sstevel@tonic-gate yyerror(gettext("Out of memory")); 225*7c478bd9Sstevel@tonic-gate exit(E_ERROR); 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate return PCV_SYMBOL; 228*7c478bd9Sstevel@tonic-gate } 229*7c478bd9Sstevel@tonic-gate 230*7c478bd9Sstevel@tonic-gate <CPUSTATE>[0-9]+ { 231*7c478bd9Sstevel@tonic-gate if ((yylval.sval = strdup(yytext)) == NULL) { 232*7c478bd9Sstevel@tonic-gate yyerror(gettext("Out of memory")); 233*7c478bd9Sstevel@tonic-gate exit(E_ERROR); 234*7c478bd9Sstevel@tonic-gate } 235*7c478bd9Sstevel@tonic-gate BEGIN INITIAL; 236*7c478bd9Sstevel@tonic-gate return PCV_SYMBOL; 237*7c478bd9Sstevel@tonic-gate } 238*7c478bd9Sstevel@tonic-gate . { 239*7c478bd9Sstevel@tonic-gate yyerror(gettext("Illegal character")); 240*7c478bd9Sstevel@tonic-gate exit(E_ERROR); 241*7c478bd9Sstevel@tonic-gate } 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate %% 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate void 246*7c478bd9Sstevel@tonic-gate yyerror(char *s) 247*7c478bd9Sstevel@tonic-gate { 248*7c478bd9Sstevel@tonic-gate if (dofile == PO_TRUE) { 249*7c478bd9Sstevel@tonic-gate if (yytext[0] == '\0') { 250*7c478bd9Sstevel@tonic-gate (void) warn(gettext("line %d, %s, token expected\n"), 251*7c478bd9Sstevel@tonic-gate lex_lineno, s); 252*7c478bd9Sstevel@tonic-gate return; 253*7c478bd9Sstevel@tonic-gate } 254*7c478bd9Sstevel@tonic-gate (void) warn(gettext("line %d, %s at '%s'\n"), lex_lineno, s, 255*7c478bd9Sstevel@tonic-gate yytext); 256*7c478bd9Sstevel@tonic-gate } else { 257*7c478bd9Sstevel@tonic-gate if (yytext[0] == '\0') { 258*7c478bd9Sstevel@tonic-gate (void) warn(gettext("%s, token expected\n"), s); 259*7c478bd9Sstevel@tonic-gate return; 260*7c478bd9Sstevel@tonic-gate } 261*7c478bd9Sstevel@tonic-gate (void) warn(gettext("%s at '%s'\n"), s, yytext); 262*7c478bd9Sstevel@tonic-gate } 263*7c478bd9Sstevel@tonic-gate } 264*7c478bd9Sstevel@tonic-gate 265