xref: /openbsd-src/usr.bin/rpcgen/rpc_util.h (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: rpc_util.h,v 1.15 2010/09/01 14:43:34 millert Exp $	*/
2 /*	$NetBSD: rpc_util.h,v 1.3 1995/06/11 21:50:10 pk Exp $	*/
3 
4 /*
5  * Copyright (c) 2010, Oracle America, Inc.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above
14  *       copyright notice, this list of conditions and the following
15  *       disclaimer in the documentation and/or other materials
16  *       provided with the distribution.
17  *     * Neither the name of the "Oracle America, Inc." nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26  *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28  *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*      @(#)rpc_util.h  1.5  90/08/29  (C) 1987 SMI   */
36 
37 /*
38  * rpc_util.h, Useful definitions for the RPC protocol compiler
39  */
40 
41 #define alloc(size)		(void *)malloc((unsigned)(size))
42 #define ALLOC(object)   (object *) malloc(sizeof(object))
43 
44 struct list {
45 	definition *val;
46 	struct list *next;
47 };
48 typedef struct list list;
49 
50 #define PUT 1
51 #define GET 2
52 
53 /*
54  * Global variables
55  */
56 #define MAXLINESIZE 1024
57 extern char curline[MAXLINESIZE];
58 extern char *where;
59 extern int linenum;
60 
61 extern char *infilename;
62 extern FILE *fout;
63 extern FILE *fin;
64 
65 extern list *defined;
66 
67 
68 extern bas_type *typ_list_h;
69 extern bas_type *typ_list_t;
70 
71 /*
72  * All the option flags
73  */
74 extern int inetdflag;
75 extern int pmflag;
76 extern int tblflag;
77 extern int logflag;
78 extern int newstyle;
79 extern int Cflag;     /* C++ flag */
80 extern int tirpcflag; /* flag for generating tirpc code */
81 extern int doinline; /* if this is 0, then do not generate inline code */
82 extern int callerflag;
83 
84 /*
85  * Other flags related with inetd jumpstart.
86  */
87 extern int indefinitewait;
88 extern int exitnow;
89 extern int timerflag;
90 
91 extern int nonfatalerrors;
92 
93 /*
94  * rpc_util routines
95  */
96 void storeval(list **, definition *);
97 
98 #define STOREVAL(list,item)	\
99 	storeval(list,item)
100 
101 definition *findval(list *, char *, int (*)(definition *, char *));
102 
103 #define FINDVAL(list,item,finder) \
104 	findval(list, item, finder)
105 
106 void crash(void);
107 char *fixtype(char *);
108 char *stringfix(char *);
109 char *locase(char *);
110 void pvname_svc(char *, char *);
111 void pvname(char *, char *);
112 void ptype(char *, char *, int);
113 int isvectordef(char *, relation);
114 int streq(char *, char *);
115 void error(char *);
116 void tabify(FILE *, int);
117 void record_open(char *);
118 bas_type *find_type(char *);
119 char *make_argname(char *, char *);
120 /*
121  * rpc_cout routines
122  */
123 void emit(definition *);
124 
125 /*
126  * rpc_hout routines
127  */
128 void print_datadef(definition *);
129 void print_funcdef(definition *);
130 
131 /*
132  * rpc_svcout routines
133  */
134 void write_most(char *, int, int);
135 void write_rest(void);
136 void write_programs(char *);
137 void write_svc_aux(int);
138 void write_inetd_register(char *);
139 void write_netid_register(char *);
140 void write_nettype_register(char *);
141 int nullproc(proc_list *);
142 
143 /*
144  * rpc_clntout routines
145  */
146 void write_stubs(void);
147 void printarglist(proc_list *, char *, char *);
148 
149 
150 /*
151  * rpc_tblout routines
152  */
153 void write_tables(void);
154 
155 /*
156  * rpc_sample routines
157  */
158 void write_sample_svc(definition *);
159 int write_sample_clnt(definition *);
160 void write_sample_clnt_main(void);
161 
162 void add_type(int len, char *type);
163 
164 void pdeclaration(char *, declaration *, int, char *);
165 void add_sample_msg(void);
166