10Sstevel@tonic-gate %{ 20Sstevel@tonic-gate /* 30Sstevel@tonic-gate * CDDL HEADER START 40Sstevel@tonic-gate * 50Sstevel@tonic-gate * The contents of this file are subject to the terms of the 60Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 70Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 80Sstevel@tonic-gate * with the License. 90Sstevel@tonic-gate * 100Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 110Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 120Sstevel@tonic-gate * See the License for the specific language governing permissions 130Sstevel@tonic-gate * and limitations under the License. 140Sstevel@tonic-gate * 150Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 160Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 170Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 180Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 190Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 200Sstevel@tonic-gate * 210Sstevel@tonic-gate * CDDL HEADER END 220Sstevel@tonic-gate * 23*1414Scindi * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <stdio.h> 300Sstevel@tonic-gate #include <stdarg.h> 310Sstevel@tonic-gate #include <string.h> 320Sstevel@tonic-gate #include <errno.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate #include <inj.h> 350Sstevel@tonic-gate #include <inj_lex.h> 360Sstevel@tonic-gate #include <inj_string.h> 370Sstevel@tonic-gate #include <inj_event.h> 380Sstevel@tonic-gate #include <inj_grammar.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate int yynerrors; 410Sstevel@tonic-gate const char *yyinname; 420Sstevel@tonic-gate 430Sstevel@tonic-gate %} 440Sstevel@tonic-gate 450Sstevel@tonic-gate /* 460Sstevel@tonic-gate * S0 is for normal input processing. SCOMMENT is used to process comments. 470Sstevel@tonic-gate * We need a separate state for comments to prevent the lex regexp engine from 480Sstevel@tonic-gate * overflowing its own buffers as it searches for the end of comments. 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate %s S0 SCOMMENT 510Sstevel@tonic-gate 520Sstevel@tonic-gate RGX_IMM_SEQ -?([0-9]+|0[xX][0-9A-Fa-f]+) 530Sstevel@tonic-gate RGX_STR_SEQ ([^"\\\n]|\\[^"\n]|\\\")* 540Sstevel@tonic-gate RGX_IDENT [a-zA-Z][a-zA-Z0-9\-_]* 550Sstevel@tonic-gate 560Sstevel@tonic-gate %% 570Sstevel@tonic-gate 580Sstevel@tonic-gate <S0>"/*" { BEGIN(SCOMMENT); } 590Sstevel@tonic-gate <SCOMMENT>.|\n ; /* discard */ 600Sstevel@tonic-gate <SCOMMENT>"*/" { BEGIN(S0); } 610Sstevel@tonic-gate 620Sstevel@tonic-gate <S0>evdef { return (INJ_TOK_EVDEF); } 630Sstevel@tonic-gate <S0>fmridef { return (INJ_TOK_FMRIDEF); } 640Sstevel@tonic-gate <S0>authdef { return (INJ_TOK_AUTHDEF); } 65*1414Scindi <S0>listdef { return (INJ_TOK_LISTDEF); } 660Sstevel@tonic-gate 670Sstevel@tonic-gate <S0>int8_t { return (INJ_TOK_INT8); } 680Sstevel@tonic-gate <S0>int16_t { return (INJ_TOK_INT16); } 690Sstevel@tonic-gate <S0>int32_t { return (INJ_TOK_INT32); } 700Sstevel@tonic-gate <S0>int64_t { return (INJ_TOK_INT64); } 710Sstevel@tonic-gate <S0>uint8_t { return (INJ_TOK_UINT8); } 720Sstevel@tonic-gate <S0>uint16_t { return (INJ_TOK_UINT16); } 730Sstevel@tonic-gate <S0>uint32_t { return (INJ_TOK_UINT32); } 740Sstevel@tonic-gate <S0>uint64_t { return (INJ_TOK_UINT64); } 750Sstevel@tonic-gate <S0>boolean { return (INJ_TOK_BOOLEAN); } 760Sstevel@tonic-gate <S0>boolean_t { return (INJ_TOK_BOOLEAN); } 770Sstevel@tonic-gate <S0>string { return (INJ_TOK_STRING); } 780Sstevel@tonic-gate <S0>enum { return (INJ_TOK_ENUM); } 790Sstevel@tonic-gate 800Sstevel@tonic-gate <S0>event { return (INJ_TOK_EVENT); } 810Sstevel@tonic-gate <S0>fmri { return (INJ_TOK_FMRI); } 820Sstevel@tonic-gate <S0>auth { return (INJ_TOK_AUTH); } 83*1414Scindi <S0>list { return (INJ_TOK_LIST); } 840Sstevel@tonic-gate 850Sstevel@tonic-gate <S0>addhrtime { return (INJ_TOK_ADDHRT); } 860Sstevel@tonic-gate <S0>endhrtime { return (INJ_TOK_ENDHRT); } 870Sstevel@tonic-gate <S0>sleep { return (INJ_TOK_SLEEP); } 880Sstevel@tonic-gate <S0>repeat { return (INJ_TOK_REPEAT); } 890Sstevel@tonic-gate <S0>randomize { return (INJ_TOK_RANDOMIZE); } 900Sstevel@tonic-gate 910Sstevel@tonic-gate <S0>\"{RGX_STR_SEQ}$ { yyerror("syntax error: \" unmatched"); } 920Sstevel@tonic-gate 930Sstevel@tonic-gate <S0>\"{RGX_STR_SEQ}\" { 940Sstevel@tonic-gate /* Quoted string */ 950Sstevel@tonic-gate yylval.l_string = inj_strndup(yytext + 1, yyleng - 2); 960Sstevel@tonic-gate return (INJ_TOK_QSTRING); 970Sstevel@tonic-gate } 980Sstevel@tonic-gate 990Sstevel@tonic-gate <S0>{RGX_IDENT}("."{RGX_IDENT})+ { 1000Sstevel@tonic-gate yylval.l_string = inj_strdup(yytext); 1010Sstevel@tonic-gate return (INJ_TOK_FMACLASS); 1020Sstevel@tonic-gate } 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate <S0>{RGX_IDENT} { 1050Sstevel@tonic-gate yylval.l_string = inj_strdup(yytext); 1060Sstevel@tonic-gate return (INJ_TOK_IDENT); 1070Sstevel@tonic-gate } 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate <S0>{RGX_IMM_SEQ} { 1100Sstevel@tonic-gate yylval.l_string = inj_strdup(yytext); 1110Sstevel@tonic-gate return (INJ_TOK_IMM); 1120Sstevel@tonic-gate } 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate <S0>[ \t\n] ; /* Ignore whitespace */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate . { return (yytext[0]); } 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate %% 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate void 1210Sstevel@tonic-gate yyerror(const char *format, ...) 1220Sstevel@tonic-gate { 1230Sstevel@tonic-gate int err = errno; 1240Sstevel@tonic-gate va_list ap; 1250Sstevel@tonic-gate char *s; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate /* Don't print the line number if the message begins with a space */ 1280Sstevel@tonic-gate if (*format == ' ') { 1290Sstevel@tonic-gate (void) fprintf(stderr, "%s: ", yyinname, yylineno); 1300Sstevel@tonic-gate format++; 1310Sstevel@tonic-gate } else 1320Sstevel@tonic-gate (void) fprintf(stderr, "%s: %d: ", yyinname, yylineno); 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate va_start(ap, format); 1350Sstevel@tonic-gate (void) vfprintf(stderr, format, ap); 1360Sstevel@tonic-gate va_end(ap); 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate if (strchr(format, '\n') == NULL) 1390Sstevel@tonic-gate (void) fprintf(stderr, " near \"%s\"\n", yytext); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate yynerrors++; 1420Sstevel@tonic-gate errno = err; 1430Sstevel@tonic-gate } 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate int 1460Sstevel@tonic-gate yywrap(void) 1470Sstevel@tonic-gate { 1480Sstevel@tonic-gate return (1); 1490Sstevel@tonic-gate } 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate void 1520Sstevel@tonic-gate yyreset(void) 1530Sstevel@tonic-gate { 1540Sstevel@tonic-gate BEGIN(S0); 1550Sstevel@tonic-gate } 156