initial checkin, based on GSS 0.46 CVS
[gss-tcad.git] / src / include / cmdbuf.h
blob98d2cb98dcdaacc6acbc6a3cd40a090557f3c0de
1 /*****************************************************************************/
2 /* 8888888 88888888 88888888 */
3 /* 8 8 8 */
4 /* 8 8 8 */
5 /* 8 88888888 88888888 */
6 /* 8 8888 8 8 */
7 /* 8 8 8 8 */
8 /* 888888 888888888 888888888 */
9 /* */
10 /* A Two-Dimensional General Purpose Semiconductor Simulator. */
11 /* */
12 /* GSS 0.4x */
13 /* Last update: May 14, 2006 */
14 /* */
15 /* Gong Ding */
16 /* gdiso@ustc.edu */
17 /* NINT, No.69 P.O.Box, Xi'an City, China */
18 /* */
19 /*****************************************************************************/
21 #ifndef _cmdparse_h
22 #define _cmdparse_h
23 #include <stdio.h>
24 #include <list>
25 #include <stack>
26 #include <map>
27 #include <string>
28 #include <stdarg.h>
29 using namespace std;
31 //structures work with lex/yacc
33 const int BOOLVAR = 20;
34 const int INTERGER = 21;
35 const int DOUBLE = 22;
36 const int CHARS = 23;
38 // value can be double ,int, bool or string
39 typedef union
41 bool bval;
42 int ival;
43 double dval;
44 char sval[32];
45 }Arg_value;
47 //this structure storage: parameter_name = arg_value;
48 typedef struct
50 int arg_type;
51 string arg_label;
52 Arg_value arg_value;
53 }Arg;
55 typedef multimap<string, Arg> ARG_MAP;
57 //this structure storage: cmd_type Keyword line number and arg_map
58 //the sequence of parameters is not critical, multimap is very efficent.
59 class Cmd
61 public:
62 string KeyWord;
63 int lineno;
64 ARG_MAP arg_map;
65 ARG_MAP::iterator parg;
66 public:
67 int get_current_lineno() {return lineno;};
68 // search the arg list of current cmd
69 bool allowed_args(int argc,...);
70 void arg_search_begin() {parg=arg_map.begin();}
71 void goto_next_arg() {parg++;}
72 bool arg_search_end() {return parg==arg_map.end();}
73 const char *get_cmd_keyword() { return KeyWord.c_str();}
74 const char *get_current_arg_label() { return parg->second.arg_label.c_str();}
75 Arg_value get_current_arg_value() { return parg->second.arg_value;}
76 // get parameter value of current cmd
77 double get_number(const char *name, int alias_num, ...);
78 int get_integer(const char *name, int alias_num, ...);
79 bool get_bool(const char *name, int alias_num, ...);
80 char * get_string(const char *name, int alias_num, ...);
81 bool is_arg_exist(const char *name);
82 bool is_arg_value(const char *name, const char * value);
86 extern int yyparse(list<Cmd> & cmd_list);
87 extern FILE* yyin;
89 // because the sequence of commands must be keep,
90 // I choose list as data structure.
91 class CmdBuf
93 public:
94 list<Cmd> cmd_list;
95 list<Cmd>::iterator pcmd;
96 stack<list<Cmd>::iterator> cmd_iterator_stack;
97 public:
98 int parse_file(char *cmd_file)
100 yyin=fopen(cmd_file,"r");
101 if(yyin==NULL)
102 { printf("Can't open input file, does it exist?\n"); return 1; }
103 if(yyparse(cmd_list))
104 { printf("Input parse interrupt.\n"); return 1; }
105 fclose(yyin);
106 return 0;
108 // cmd search
109 void cmd_search_begin() {cmd_iterator_stack.push(pcmd);pcmd=cmd_list.begin();}
110 void goto_next_cmd() {pcmd++;}
111 bool cmd_search_end()
113 if(pcmd==cmd_list.end())
115 pcmd=cmd_iterator_stack.top();
116 cmd_iterator_stack.pop();
117 return true;
119 else
120 return false;
122 list<Cmd>::iterator get_current_cmd() {return pcmd;}
123 bool is_current_cmd(const char *cmd_name) {return !strcmp(pcmd->KeyWord.c_str(),cmd_name);}
124 void delete_current_cmd() {pcmd = cmd_list.erase(pcmd);}
125 void delete_cmd(const char *cmd_name)
127 for(pcmd=cmd_list.begin();pcmd!=cmd_list.end();pcmd++)
128 if(!strcmp(cmd_name,pcmd->KeyWord.c_str())) pcmd = cmd_list.erase(pcmd);
132 #endif