17c478bd9Sstevel@tonic-gate %{
27c478bd9Sstevel@tonic-gate /*
37c478bd9Sstevel@tonic-gate  * CDDL HEADER START
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
67c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
77c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
87c478bd9Sstevel@tonic-gate  * with the License.
97c478bd9Sstevel@tonic-gate  *
107c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
117c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
127c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
137c478bd9Sstevel@tonic-gate  * and limitations under the License.
147c478bd9Sstevel@tonic-gate  *
157c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
167c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
177c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
187c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
197c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
207c478bd9Sstevel@tonic-gate  *
217c478bd9Sstevel@tonic-gate  * CDDL HEADER END
227c478bd9Sstevel@tonic-gate  *
23*7aec1d6eScindi  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * FMA Event Injector language parser
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <limits.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include <inj.h>
387c478bd9Sstevel@tonic-gate #include <inj_err.h>
397c478bd9Sstevel@tonic-gate #include <inj_event.h>
407c478bd9Sstevel@tonic-gate #include <inj_hash.h>
417c478bd9Sstevel@tonic-gate #include <inj_lex.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate %}
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate %union {
467c478bd9Sstevel@tonic-gate 	inj_decl_t *l_decl;
477c478bd9Sstevel@tonic-gate 	inj_declmem_t *l_declmem;
487c478bd9Sstevel@tonic-gate 	inj_defn_t *l_defn;
497c478bd9Sstevel@tonic-gate 	inj_defnmem_t *l_defnmem;
507c478bd9Sstevel@tonic-gate 	inj_cmd_t *l_command;
517c478bd9Sstevel@tonic-gate 	inj_randelem_t *l_randelem;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	inj_hash_t *l_hash;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate 	char *l_string;
567c478bd9Sstevel@tonic-gate 	uint_t l_number;
577c478bd9Sstevel@tonic-gate 	hrtime_t l_hrtime;
587c478bd9Sstevel@tonic-gate }
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate %type	<l_decl>	decl_memlist
617c478bd9Sstevel@tonic-gate %type	<l_declmem>	decl_mem
627c478bd9Sstevel@tonic-gate %type	<l_declmem>	decl_baremem
637c478bd9Sstevel@tonic-gate %type	<l_declmem>	decl_mem_intr
647c478bd9Sstevel@tonic-gate %type	<l_number>	decl_intr_type
657c478bd9Sstevel@tonic-gate %type	<l_number>	decl_arraydim
667c478bd9Sstevel@tonic-gate %type	<l_declmem>	decl_mem_cplx
677c478bd9Sstevel@tonic-gate %type	<l_hash>	decl_enumlist
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate %type	<l_defn>	defn_memlist
707c478bd9Sstevel@tonic-gate %type	<l_defnmem>	defn_memvals
717c478bd9Sstevel@tonic-gate %type	<l_defnmem>	defn_val
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate %type	<l_command>	command
747c478bd9Sstevel@tonic-gate %type	<l_command>	cmd_repeatable
757c478bd9Sstevel@tonic-gate %type	<l_randelem>	rand_problist
767c478bd9Sstevel@tonic-gate %type	<l_randelem>	rand_element
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate %type	<l_defn>	defined_event
797c478bd9Sstevel@tonic-gate %type	<l_number>	number
807c478bd9Sstevel@tonic-gate %type	<l_hrtime>	hrtime
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate %token	INJ_TOK_EVDEF
837c478bd9Sstevel@tonic-gate %token	INJ_TOK_FMRIDEF
847c478bd9Sstevel@tonic-gate %token	INJ_TOK_AUTHDEF
85*7aec1d6eScindi %token	INJ_TOK_LISTDEF
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate %token	INJ_TOK_INT8
887c478bd9Sstevel@tonic-gate %token	INJ_TOK_INT16
897c478bd9Sstevel@tonic-gate %token	INJ_TOK_INT32
907c478bd9Sstevel@tonic-gate %token	INJ_TOK_INT64
917c478bd9Sstevel@tonic-gate %token	INJ_TOK_UINT8
927c478bd9Sstevel@tonic-gate %token	INJ_TOK_UINT16
937c478bd9Sstevel@tonic-gate %token	INJ_TOK_UINT32
947c478bd9Sstevel@tonic-gate %token	INJ_TOK_UINT64
957c478bd9Sstevel@tonic-gate %token	INJ_TOK_BOOLEAN
967c478bd9Sstevel@tonic-gate %token	INJ_TOK_STRING
977c478bd9Sstevel@tonic-gate %token	INJ_TOK_ENUM
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate %token	INJ_TOK_EVENT
1007c478bd9Sstevel@tonic-gate %token	INJ_TOK_FMRI
1017c478bd9Sstevel@tonic-gate %token	INJ_TOK_AUTH
102*7aec1d6eScindi %token	INJ_TOK_LIST
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate %token	INJ_TOK_ADDHRT
1057c478bd9Sstevel@tonic-gate %token	INJ_TOK_ENDHRT
1067c478bd9Sstevel@tonic-gate %token	INJ_TOK_SLEEP
1077c478bd9Sstevel@tonic-gate %token	INJ_TOK_REPEAT
1087c478bd9Sstevel@tonic-gate %token	INJ_TOK_RANDOMIZE
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate %token	<l_string> INJ_TOK_IDENT
1117c478bd9Sstevel@tonic-gate %token	<l_string> INJ_TOK_FMACLASS
1127c478bd9Sstevel@tonic-gate %token	<l_string> INJ_TOK_IMM
1137c478bd9Sstevel@tonic-gate %token	<l_string> INJ_TOK_QSTRING
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate %%
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate statement_list:	/* EMPTY */
1187c478bd9Sstevel@tonic-gate 	|	statement_list statement ';'
1197c478bd9Sstevel@tonic-gate 	;
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate statement:	decl
1227c478bd9Sstevel@tonic-gate 	|	defn
1237c478bd9Sstevel@tonic-gate 	|	command {
1247c478bd9Sstevel@tonic-gate 			if ($1 != NULL)
1257c478bd9Sstevel@tonic-gate 				inj_cmds_add($1);
1267c478bd9Sstevel@tonic-gate 		}
1277c478bd9Sstevel@tonic-gate 	;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
130*7aec1d6eScindi  * Event, FMRI, Authority, and list declarations
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate decl:		INJ_TOK_EVDEF INJ_TOK_FMACLASS '{' decl_memlist '}' {
1347c478bd9Sstevel@tonic-gate 			if ($4 != NULL)
1357c478bd9Sstevel@tonic-gate 				inj_decl_finish($4, $2, ITEMTYPE_EVENT);
1367c478bd9Sstevel@tonic-gate 		}
1377c478bd9Sstevel@tonic-gate 	|	INJ_TOK_FMRIDEF INJ_TOK_IDENT '{' decl_memlist '}' {
1387c478bd9Sstevel@tonic-gate 			if ($4 != NULL)
1397c478bd9Sstevel@tonic-gate 				inj_decl_finish($4, $2, ITEMTYPE_FMRI);
1407c478bd9Sstevel@tonic-gate 		}
1417c478bd9Sstevel@tonic-gate 	|	INJ_TOK_AUTHDEF INJ_TOK_IDENT '{' decl_memlist '}' {
1427c478bd9Sstevel@tonic-gate 			if ($4 != NULL)
1437c478bd9Sstevel@tonic-gate 				inj_decl_finish($4, $2, ITEMTYPE_AUTH);
1447c478bd9Sstevel@tonic-gate 		}
145*7aec1d6eScindi 	|	INJ_TOK_LISTDEF INJ_TOK_IDENT '{' decl_memlist '}' {
146*7aec1d6eScindi 			if ($4 != NULL)
147*7aec1d6eScindi 				inj_decl_finish($4, $2, ITEMTYPE_LIST);
148*7aec1d6eScindi 		}
1497c478bd9Sstevel@tonic-gate 	;
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate decl_memlist:	/* EMPTY */	{ $$ = NULL; }
1527c478bd9Sstevel@tonic-gate 	|	decl_memlist decl_mem ';' {
1537c478bd9Sstevel@tonic-gate 			if ($2 == NULL) {
1547c478bd9Sstevel@tonic-gate 				$$ = $1;
1557c478bd9Sstevel@tonic-gate 			} else if ($1 == NULL) {
1567c478bd9Sstevel@tonic-gate 				$$ = inj_decl_create($2);
1577c478bd9Sstevel@tonic-gate 			} else {
1587c478bd9Sstevel@tonic-gate 				inj_decl_addmem($1, $2);
1597c478bd9Sstevel@tonic-gate 				$$ = $1;
1607c478bd9Sstevel@tonic-gate 			}
1617c478bd9Sstevel@tonic-gate 		}
1627c478bd9Sstevel@tonic-gate 	;
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate decl_mem:	decl_baremem
1657c478bd9Sstevel@tonic-gate 	|	decl_baremem decl_arraydim {
1667c478bd9Sstevel@tonic-gate 			if ($1 != NULL)
1677c478bd9Sstevel@tonic-gate 				inj_decl_mem_make_array($1, $2);
1687c478bd9Sstevel@tonic-gate 			$$ = $1;
1697c478bd9Sstevel@tonic-gate 		}
1707c478bd9Sstevel@tonic-gate 	;
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate decl_baremem:	decl_mem_intr
1737c478bd9Sstevel@tonic-gate 	|	decl_mem_cplx
1747c478bd9Sstevel@tonic-gate 	;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate decl_mem_intr:	decl_intr_type INJ_TOK_IDENT {
1777c478bd9Sstevel@tonic-gate 			$$ = inj_decl_mem_create($2, $1);
1787c478bd9Sstevel@tonic-gate 		}
1797c478bd9Sstevel@tonic-gate 	;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate decl_intr_type:	INJ_TOK_INT8		{ $$ = MEMTYPE_INT8; }
1827c478bd9Sstevel@tonic-gate 	|	INJ_TOK_INT16		{ $$ = MEMTYPE_INT16; }
1837c478bd9Sstevel@tonic-gate 	|	INJ_TOK_INT32		{ $$ = MEMTYPE_INT32; }
1847c478bd9Sstevel@tonic-gate 	|	INJ_TOK_INT64		{ $$ = MEMTYPE_INT64; }
1857c478bd9Sstevel@tonic-gate 	|	INJ_TOK_UINT8		{ $$ = MEMTYPE_UINT8; }
1867c478bd9Sstevel@tonic-gate 	|	INJ_TOK_UINT16		{ $$ = MEMTYPE_UINT16; }
1877c478bd9Sstevel@tonic-gate 	|	INJ_TOK_UINT32		{ $$ = MEMTYPE_UINT32; }
1887c478bd9Sstevel@tonic-gate 	|	INJ_TOK_UINT64		{ $$ = MEMTYPE_UINT64; }
1897c478bd9Sstevel@tonic-gate 	|	INJ_TOK_BOOLEAN		{ $$ = MEMTYPE_BOOL; }
1907c478bd9Sstevel@tonic-gate 	|	INJ_TOK_STRING		{ $$ = MEMTYPE_STRING; }
1917c478bd9Sstevel@tonic-gate 	;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate decl_arraydim:	'[' number ']' {
1947c478bd9Sstevel@tonic-gate 			$$ = $2;
1957c478bd9Sstevel@tonic-gate 		}
1967c478bd9Sstevel@tonic-gate 	|	'[' ']' {
1977c478bd9Sstevel@tonic-gate 			$$ = 0;
1987c478bd9Sstevel@tonic-gate 		}
1997c478bd9Sstevel@tonic-gate 	;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate decl_mem_cplx:	INJ_TOK_ENUM INJ_TOK_IDENT '{' decl_enumlist '}' {
2027c478bd9Sstevel@tonic-gate 			$$ = inj_decl_mem_create_enum($2, $4);
2037c478bd9Sstevel@tonic-gate 		}
2047c478bd9Sstevel@tonic-gate 	|	INJ_TOK_EVENT INJ_TOK_FMACLASS INJ_TOK_IDENT {
2057c478bd9Sstevel@tonic-gate 			$$ = inj_decl_mem_create_defined($3, $2,
2067c478bd9Sstevel@tonic-gate 			    ITEMTYPE_EVENT);
2077c478bd9Sstevel@tonic-gate 		}
2087c478bd9Sstevel@tonic-gate 	|	INJ_TOK_FMRI INJ_TOK_IDENT INJ_TOK_IDENT {
2097c478bd9Sstevel@tonic-gate 			$$ = inj_decl_mem_create_defined($3, $2,
2107c478bd9Sstevel@tonic-gate 			    ITEMTYPE_FMRI);
2117c478bd9Sstevel@tonic-gate 		}
2127c478bd9Sstevel@tonic-gate 	|	INJ_TOK_AUTH INJ_TOK_IDENT INJ_TOK_IDENT {
2137c478bd9Sstevel@tonic-gate 			$$ = inj_decl_mem_create_defined($3, $2,
2147c478bd9Sstevel@tonic-gate 			    ITEMTYPE_AUTH);
2157c478bd9Sstevel@tonic-gate 		}
216*7aec1d6eScindi 	|	INJ_TOK_LIST INJ_TOK_IDENT INJ_TOK_IDENT {
217*7aec1d6eScindi 			$$ = inj_decl_mem_create_defined($3, $2,
218*7aec1d6eScindi 			    ITEMTYPE_LIST);
219*7aec1d6eScindi 		}
2207c478bd9Sstevel@tonic-gate 	;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate decl_enumlist:	INJ_TOK_IDENT {
2237c478bd9Sstevel@tonic-gate 			$$ = inj_zalloc(sizeof (inj_hash_t));
2247c478bd9Sstevel@tonic-gate 			inj_strhash_create($$);
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 			inj_strhash_insert($$, $1, 1);
2277c478bd9Sstevel@tonic-gate 		}
2287c478bd9Sstevel@tonic-gate 	|	decl_enumlist ',' INJ_TOK_IDENT {
2297c478bd9Sstevel@tonic-gate 			if (inj_strhash_lookup($1, $3) != NULL)
2307c478bd9Sstevel@tonic-gate 				yyerror("duplicate enum value \"%s\"", $3);
2317c478bd9Sstevel@tonic-gate 			else
2327c478bd9Sstevel@tonic-gate 				inj_strhash_insert($1, $3, 1);
2337c478bd9Sstevel@tonic-gate 			$$ = $1;
2347c478bd9Sstevel@tonic-gate 		}
2357c478bd9Sstevel@tonic-gate 	;
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /*
238*7aec1d6eScindi  * Event, FMRI, Authority, and list definitions
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate defn:		INJ_TOK_EVENT INJ_TOK_FMACLASS INJ_TOK_IDENT '='
2427c478bd9Sstevel@tonic-gate 		    '{' defn_memlist '}' {
2437c478bd9Sstevel@tonic-gate 			inj_defn_finish($6, $2, $3, ITEMTYPE_EVENT);
2447c478bd9Sstevel@tonic-gate 			inj_strfree($2);
2457c478bd9Sstevel@tonic-gate 		}
2467c478bd9Sstevel@tonic-gate 	|	INJ_TOK_FMRI INJ_TOK_IDENT INJ_TOK_IDENT '='
2477c478bd9Sstevel@tonic-gate 		    '{' defn_memlist '}' {
2487c478bd9Sstevel@tonic-gate 			inj_defn_finish($6, $2, $3, ITEMTYPE_FMRI);
2497c478bd9Sstevel@tonic-gate 			inj_strfree($2);
2507c478bd9Sstevel@tonic-gate 		}
2517c478bd9Sstevel@tonic-gate 	|	INJ_TOK_AUTH INJ_TOK_IDENT INJ_TOK_IDENT '='
2527c478bd9Sstevel@tonic-gate 		    '{' defn_memlist '}' {
2537c478bd9Sstevel@tonic-gate 			inj_defn_finish($6, $2, $3, ITEMTYPE_AUTH);
2547c478bd9Sstevel@tonic-gate 			inj_strfree($2);
2557c478bd9Sstevel@tonic-gate 		}
2567c478bd9Sstevel@tonic-gate 	;
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate defn_memlist:	defn_memvals {
2597c478bd9Sstevel@tonic-gate 			$$ = inj_defn_create($1);
2607c478bd9Sstevel@tonic-gate 		}
2617c478bd9Sstevel@tonic-gate 	|	defn_memlist ',' defn_memvals {
2627c478bd9Sstevel@tonic-gate 			inj_defn_addmem($1, $3);
2637c478bd9Sstevel@tonic-gate 			$$ = $1;
2647c478bd9Sstevel@tonic-gate 		}
2657c478bd9Sstevel@tonic-gate 	;
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate defn_memvals:	defn_val
2687c478bd9Sstevel@tonic-gate 	|	INJ_TOK_EVENT INJ_TOK_FMACLASS {
2697c478bd9Sstevel@tonic-gate 			$$ = inj_defn_mem_create($2, DEFNMEM_EVENT);
2707c478bd9Sstevel@tonic-gate 		}
2717c478bd9Sstevel@tonic-gate 	|	INJ_TOK_FMRI INJ_TOK_IDENT {
2727c478bd9Sstevel@tonic-gate 			$$ = inj_defn_mem_create($2, DEFNMEM_FMRI);
2737c478bd9Sstevel@tonic-gate 		}
2747c478bd9Sstevel@tonic-gate 	|	INJ_TOK_AUTH INJ_TOK_IDENT {
2757c478bd9Sstevel@tonic-gate 			$$ = inj_defn_mem_create($2, DEFNMEM_AUTH);
2767c478bd9Sstevel@tonic-gate 		}
2777c478bd9Sstevel@tonic-gate 	|	'[' defn_memlist ']' {
2787c478bd9Sstevel@tonic-gate 			$$ = inj_defn_mem_create_list($2, DEFNMEM_ARRAY);
2797c478bd9Sstevel@tonic-gate 		}
2807c478bd9Sstevel@tonic-gate 	|	'{' defn_memlist '}' {
281*7aec1d6eScindi 			$$ = inj_defn_mem_create_list($2, DEFNMEM_LIST);
2827c478bd9Sstevel@tonic-gate 		}
2837c478bd9Sstevel@tonic-gate 	;
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate defn_val:	INJ_TOK_IMM {
2867c478bd9Sstevel@tonic-gate 			$$ = inj_defn_mem_create($1, DEFNMEM_IMM);
2877c478bd9Sstevel@tonic-gate 		}
2887c478bd9Sstevel@tonic-gate 	|	INJ_TOK_IDENT {
2897c478bd9Sstevel@tonic-gate 			$$ = inj_defn_mem_create($1, DEFNMEM_IDENT);
2907c478bd9Sstevel@tonic-gate 		}
2917c478bd9Sstevel@tonic-gate 	|	INJ_TOK_QSTRING {
2927c478bd9Sstevel@tonic-gate 			$$ = inj_defn_mem_create($1, DEFNMEM_QSTRING);
2937c478bd9Sstevel@tonic-gate 		}
2947c478bd9Sstevel@tonic-gate 	;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate /*
2977c478bd9Sstevel@tonic-gate  * Commands
2987c478bd9Sstevel@tonic-gate  */
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate command:	cmd_repeatable
3017c478bd9Sstevel@tonic-gate 	|	INJ_TOK_ADDHRT hrtime { $$ = inj_cmd_addhrt($2); }
3027c478bd9Sstevel@tonic-gate 	|	INJ_TOK_ENDHRT { $$ = inj_cmd_endhrt(); }
3037c478bd9Sstevel@tonic-gate 	|	INJ_TOK_SLEEP number { $$ = inj_cmd_sleep($2); }
3047c478bd9Sstevel@tonic-gate 	|	INJ_TOK_REPEAT number cmd_repeatable {
3057c478bd9Sstevel@tonic-gate 			$$ = ($3 == NULL ? NULL : inj_cmd_repeat($3, $2));
3067c478bd9Sstevel@tonic-gate 		}
3077c478bd9Sstevel@tonic-gate 	;
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate cmd_repeatable:	defined_event {
3107c478bd9Sstevel@tonic-gate 			$$ = ($1 == NULL ? NULL : inj_cmd_send($1));
3117c478bd9Sstevel@tonic-gate 		}
3127c478bd9Sstevel@tonic-gate 	|	INJ_TOK_RANDOMIZE '{' rand_problist '}' {
3137c478bd9Sstevel@tonic-gate 			$$ = ($3 == NULL ? NULL : inj_cmd_rand($3));
3147c478bd9Sstevel@tonic-gate 		}
3157c478bd9Sstevel@tonic-gate 	;
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate rand_problist:	rand_element
3187c478bd9Sstevel@tonic-gate 	|	rand_problist ',' rand_element {
3197c478bd9Sstevel@tonic-gate 			$$ = ($1 == NULL || $3 == NULL) ?
3207c478bd9Sstevel@tonic-gate 			    NULL : inj_rand_add($1, $3);
3217c478bd9Sstevel@tonic-gate 		}
3227c478bd9Sstevel@tonic-gate 	;
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate rand_element:	'{' defined_event ',' number '}' {
3257c478bd9Sstevel@tonic-gate 			$$ = ($2 == NULL ? NULL : inj_rand_create($2, $4));
3267c478bd9Sstevel@tonic-gate 		}
3277c478bd9Sstevel@tonic-gate 	;
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate defined_event:	INJ_TOK_IDENT {
3307c478bd9Sstevel@tonic-gate 			inj_defn_t *ev;
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 			if ((ev = inj_defn_lookup($1, MEMTYPE_EVENT)) ==
3337c478bd9Sstevel@tonic-gate 			    NULL) {
3347c478bd9Sstevel@tonic-gate 				yyerror("unknown event \"%s\"\n", $1);
3357c478bd9Sstevel@tonic-gate 				$$ = NULL;
3367c478bd9Sstevel@tonic-gate 			} else
3377c478bd9Sstevel@tonic-gate 				$$ = ev;
3387c478bd9Sstevel@tonic-gate 		}
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate number:		INJ_TOK_IMM {
3417c478bd9Sstevel@tonic-gate 			u_longlong_t val;
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 			if (inj_strtoull($1, 32, &val) < 0) {
3447c478bd9Sstevel@tonic-gate 				yyerror("invalid number");
3457c478bd9Sstevel@tonic-gate 				$$ = 0;
3467c478bd9Sstevel@tonic-gate 			} else
3477c478bd9Sstevel@tonic-gate 				$$ = (uint32_t)val;
3487c478bd9Sstevel@tonic-gate 		}
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate hrtime:		INJ_TOK_IMM INJ_TOK_IDENT {
3517c478bd9Sstevel@tonic-gate 			longlong_t val;
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 			if (inj_strtoll($1, 64, &val) < 0 ||
3547c478bd9Sstevel@tonic-gate 			    inj_strtime(&val, $2) < 0) {
3557c478bd9Sstevel@tonic-gate 				yyerror("invalid time");
3567c478bd9Sstevel@tonic-gate 				$$ = 0;
3577c478bd9Sstevel@tonic-gate 			} else
3587c478bd9Sstevel@tonic-gate 				$$ = val;
3597c478bd9Sstevel@tonic-gate 		}
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate %%
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate inj_list_t *
3647c478bd9Sstevel@tonic-gate inj_program_read(const char *file)
3657c478bd9Sstevel@tonic-gate {
3667c478bd9Sstevel@tonic-gate 	if (strcmp(file, "-") == 0) {
3677c478bd9Sstevel@tonic-gate 		yyin = stdin;
3687c478bd9Sstevel@tonic-gate 		yyinname = "stdin";
3697c478bd9Sstevel@tonic-gate 	} else {
3707c478bd9Sstevel@tonic-gate 		if ((yyin = fopen(file, "r")) == NULL)
3717c478bd9Sstevel@tonic-gate 			die("failed to open %s", file);
3727c478bd9Sstevel@tonic-gate 
373*7aec1d6eScindi 		yyinname = strrchr(file, '/');
374*7aec1d6eScindi 		if (yyinname != NULL)
375*7aec1d6eScindi 			yyinname++;
376*7aec1d6eScindi 		else
3777c478bd9Sstevel@tonic-gate 			yyinname = file;
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	yyreset();
3817c478bd9Sstevel@tonic-gate 	(void) yyparse();
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 	if (yyin != stdin)
3847c478bd9Sstevel@tonic-gate 		(void) fclose(yyin);
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	if (yynerrors != 0) {
3877c478bd9Sstevel@tonic-gate 		die("parsing failed - %d error%s\n", yynerrors,
3887c478bd9Sstevel@tonic-gate 		    (yynerrors > 1 ? "s" : ""));
3897c478bd9Sstevel@tonic-gate 	}
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 	return (inj_cmds_get());
3927c478bd9Sstevel@tonic-gate }
393