1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (C) 2009-2012 Semihalf
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD: stable/12/usr.sbin/nandsim/nandsim_cfgparse.h 326276 2017-11-27 15:37:16Z pfg $
29  */
30 
31 #ifndef _NANDSIM_CONFPARSER_H_
32 #define _NANDSIM_CONFPARSER_H_
33 
34 #define VALUE_UINT	0x08
35 #define VALUE_INT	0x10
36 #define VALUE_UINTARRAY	0x18
37 #define VALUE_INTARRAY	0x20
38 #define VALUE_STRING	0x28
39 #define VALUE_CHAR	0x40
40 #define VALUE_BOOL	0x48
41 
42 #define SIZE_8	0x01
43 #define SIZE_16	0x02
44 #define SIZE_32	0x04
45 
46 #include "nandsim_rcfile.h"
47 
48 /*
49  * keyname	= name of a key,
50  * mandatory	= is key mandatory in section belonging to, 0=false 1=true
51  * valuetype	= what kind of value is assigned to that key, e.g.
52  *		  VALUE_UINT | SIZE_8 -- unsigned uint size 8 bits;
53  *		  VALUE_UINTARRAY | SIZE_8 -- array of uints 8-bit long;
54  *		  VALUE_BOOL -- 'on', 'off','true','false','yes' or 'no'
55  *		  literals;
56  *		  VALUE_STRING -- strings
57  * field	= ptr to the field that should hold value for parsed value
58  * maxlength	= contains maximum length of an array (used only with either
59  *		  VALUE_STRING or VALUE_(U)INTARRAY value types.
60  */
61 struct nandsim_key {
62 	const char	*keyname;
63 	uint8_t		mandatory;
64 	uint8_t		valuetype;
65 	void		*field;
66 	uint32_t	maxlength;
67 };
68 struct nandsim_section {
69 	const char		*name;
70 	struct nandsim_key	*keys;
71 };
72 
73 struct nandsim_config {
74 	struct sim_param	**simparams;
75 	struct sim_chip		**simchips;
76 	struct sim_ctrl		**simctrls;
77 	int			chipcnt;
78 	int			ctrlcnt;
79 };
80 
81 int parse_intarray(char *, int **);
82 int parse_config(char *, const char *);
83 int parse_section(struct rcfile *, const char *, int);
84 int compare_configs(struct nandsim_config *, struct nandsim_config *);
85 int convert_argint(char *, int *);
86 int convert_arguint(char *, unsigned int *);
87 
88 #endif /* _NANDSIM_CONFPARSER_H_ */
89