Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / util / tt_parse_utils.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                  
24 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.    
25 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                   
26 //%%  (c) Copyright 1993, 1994 Novell, Inc.                             
27 //%%  $XConsortium: tt_parse_utils.C /main/3 1995/10/23 10:43:13 rswiston $                                                     
28
29 #include <stdio.h>
30 #include <sys/param.h>
31 #include "tt_trace.tab.h"
32 #include "tt_trace_parser.h"
33
34 static _Tt_trace_parser_ptr trace_parser(NULL);
35
36 extern "C" {
37         void process_follow(const int);
38         void process_sink(const char* const);
39         void clear_functions(void);
40         void process_functionlist(const char* const);
41         void process_functions_allnone(const int);
42         void process_attributes(const int);
43         void clear_states();
44         int process_state(const int, const int);
45         void create_op_list(const char* const);
46         void add_op(const char* const);
47         void create_sp_list(const char* const);
48         void add_sender_ptype(const char* const);
49         void create_hp_list(const char* const);
50         void add_handler_ptype(const char* const);
51         int _tt_trace_input();
52         void _tt_trace_unput(int);
53 }
54
55 void set_trace_parser(const _Tt_trace_parser_ptr tp)
56 {
57         trace_parser = tp;
58 }
59
60 void process_follow(const int on_off)
61 {
62         trace_parser->set_follow(on_off);
63 }
64
65 void process_sink(const char* const fname)
66 {
67         _Tt_string tmp_fname(fname); // Shuts compiler up
68                 
69         trace_parser->set_sink(tmp_fname);
70 }
71
72 void clear_functions(void)
73 {
74         trace_parser->clear_functions();
75 }
76
77 void process_functionlist(const char* const text_item)
78 {
79         _Tt_string tmp_item(text_item); // Shuts compiler up
80                 
81         trace_parser->add_function(tmp_item);
82 }
83
84 void process_functions_allnone(const int all_none)
85 {
86         trace_parser->clear_functions(); /* clear any previous settings */
87         trace_parser->set_function(all_none);
88 }
89
90 void process_attributes(const int all_none)
91 {
92         trace_parser->set_attributes(all_none);
93 }
94
95 void clear_states(void)
96 {
97         trace_parser->clear_states(); /* clear any previous settings */
98 }
99
100 int process_state(const int state_type, const int state_val)
101 {
102         int sval = state_val;
103         
104         if (state_type == _TT_TRACE_STATES_NEDD) {
105                 switch (state_val) {
106                         
107                     case _TT_TRACE_NONE:
108                         sval = states_none;
109                         break;
110                     case _TT_TRACE_EDGE:
111                         sval = states_edge;
112                         break;
113                     case _TT_TRACE_DELIVER:
114                         sval = states_deliver;
115                         break;
116                     case _TT_TRACE_DISPATCH:
117                         sval = states_dispatch;
118                         break;
119                     default:
120                         sval = states_none;
121                         break;
122                 }
123         }
124         
125         return trace_parser->add_state(sval);
126 }
127
128 void create_op_list(const char* const op)
129 {
130         _Tt_string tmp_op(op);  // Shuts compiler up
131                 
132         trace_parser->clear_ops();
133         trace_parser->add_op(tmp_op);
134 }
135
136 void add_op(const char* const op)
137 {
138         _Tt_string tmp_op(op);  // Shuts compiler up
139                 
140         trace_parser->add_op(tmp_op);
141 }
142
143 void create_sp_list(const char* const sp)
144 {
145         _Tt_string tmp_sp(sp);  // Shuts compiler up
146                 
147         trace_parser->clear_sender_ptypes();
148         trace_parser->add_sender_ptype(tmp_sp);
149 }
150
151 void add_sender_ptype(const char* const sp)
152 {
153         _Tt_string tmp_sp(sp);  // Shuts compiler up
154                 
155         trace_parser->add_sender_ptype(tmp_sp);
156 }
157
158 void create_hp_list(const char* const hp)
159 {
160         _Tt_string tmp_hp(hp);  // Shuts compiler up
161                 
162         trace_parser->clear_handler_ptypes();
163         trace_parser->add_handler_ptype(tmp_hp);
164 }
165
166 void add_handler_ptype(const char* const hp)
167 {
168         _Tt_string tmp_hp(hp);  // Shuts compiler up
169                 
170         trace_parser->add_handler_ptype(tmp_hp);
171 }
172
173 // Lex utility functions
174
175 int _tt_trace_input(void)
176 {
177         return trace_parser->next_char();
178 }
179
180 void _tt_trace_unput(int ch)
181 {
182         trace_parser->ungetc(ch);
183 }