xref: /freebsd/usr.bin/rpcgen/rpc_util.h (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
1 /*
2  */
3 /*
4  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5  * unrestricted use provided that this legend is included on all tape
6  * media and as a part of the software program in whole or part.  Users
7  * may copy or modify Sun RPC without charge, but are not authorized
8  * to license or distribute it to anyone else except as part of a product or
9  * program developed by the user.
10  *
11  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14  *
15  * Sun RPC is provided with no support and without any obligation on the
16  * part of Sun Microsystems, Inc. to assist in its use, correction,
17  * modification or enhancement.
18  *
19  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21  * OR ANY PART THEREOF.
22  *
23  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24  * or profits or other special, indirect and consequential damages, even if
25  * Sun has been advised of the possibility of such damages.
26  *
27  * Sun Microsystems, Inc.
28  * 2550 Garcia Avenue
29  * Mountain View, California  94043
30  */
31 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
32 /*	  All Rights Reserved  	*/
33 
34 /*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
35 /*	The copyright notice above does not evidence any   	*/
36 /*	actual or intended publication of such source code.	*/
37 
38 
39 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40 *	PROPRIETARY NOTICE (Combined)
41 *
42 * This source code is unpublished proprietary information
43 * constituting, or derived under license from AT&T's UNIX(r) System V.
44 * In addition, portions of such source code were derived from Berkeley
45 * 4.3 BSD under license from the Regents of the University of
46 * California.
47 *
48 *
49 *
50 *	Copyright Notice
51 *
52 * Notice of copyright on this source code product does not indicate
53 *  publication.
54 *
55 *	(c) 1986,1987,1988.1989  Sun Microsystems, Inc
56 *	(c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
57 *          All rights reserved.
58 */
59 
60 /*
61  * rpc_util.h, Useful definitions for the RPC protocol compiler
62  */
63 #include <sys/types.h>
64 #include <stdlib.h>
65 
66 #define	XALLOC(object)   (object *) xmalloc(sizeof(object))
67 
68 #define	s_print	(void) sprintf
69 #define	f_print (void) fprintf
70 
71 struct list {
72 	definition *val;
73 	struct list *next;
74 };
75 typedef struct list list;
76 
77 struct xdrfunc {
78 	const char *name;
79 	int pointerp;
80 	struct xdrfunc *next;
81 };
82 typedef struct xdrfunc xdrfunc;
83 
84 struct commandline {
85 	int cflag;		/* xdr C routines */
86 	int hflag;		/* header file */
87 	int lflag;		/* client side stubs */
88 	int mflag;		/* server side stubs */
89 	int nflag;		/* netid flag */
90 	int sflag;		/* server stubs for the given transport */
91 	int tflag;		/* dispatch Table file */
92 	int Ssflag;		/* produce server sample code */
93 	int Scflag;		/* produce client sample code */
94 	int makefileflag;       /* Generate a template Makefile */
95 	const char *infile;	/* input module name */
96 	const char *outfile;	/* output module name */
97 };
98 
99 #define	PUT 1
100 #define	GET 2
101 
102 /*
103  * Global variables
104  */
105 #define	MAXLINESIZE 1024
106 extern char curline[MAXLINESIZE];
107 extern char *where;
108 extern int linenum;
109 extern int tirpc_socket;
110 
111 extern const char *infilename;
112 extern FILE *fout;
113 extern FILE *fin;
114 
115 extern list *defined;
116 
117 
118 extern bas_type *typ_list_h;
119 extern bas_type *typ_list_t;
120 extern xdrfunc *xdrfunc_head, *xdrfunc_tail;
121 
122 /*
123  * All the option flags
124  */
125 extern int inetdflag;
126 extern int pmflag;
127 extern int tblflag;
128 extern int logflag;
129 extern int newstyle;
130 extern int CCflag;     /* C++ flag */
131 extern int tirpcflag; /* flag for generating tirpc code */
132 extern int inline_size; /* if this is 0, then do not generate inline code */
133 extern int mtflag;
134 
135 /*
136  * Other flags related with inetd jumpstart.
137  */
138 extern int indefinitewait;
139 extern int exitnow;
140 extern int timerflag;
141 
142 extern int nonfatalerrors;
143 
144 extern pid_t childpid;
145 
146 /*
147  * rpc_util routines
148  */
149 void reinitialize(void);
150 void crash(void) __dead2;
151 void add_type(int len, const char *type);
152 void storeval(list **lstp, definition *val);
153 void *xmalloc(size_t size);
154 void *xrealloc(void *ptr, size_t size);
155 char *xstrdup(const char *);
156 char *make_argname(const char *pname, const char *vname);
157 
158 #define	STOREVAL(list,item)	\
159 	storeval(list,item)
160 
161 definition *findval(list *lst, const char *val, int (*cmp)(definition *, const char *));
162 
163 #define	FINDVAL(list,item,finder) \
164 	findval(list, item, finder)
165 
166 const char *fixtype(const char *type);
167 const char *stringfix(const char *type);
168 char *locase(const char *str);
169 void pvname_svc(const char *pname, const char *vnum);
170 void pvname(const char *pname, const char *vnum);
171 void ptype(const char *prefix, const char *type, int follow);
172 int isvectordef(const char *type, relation rel);
173 int streq(const char *a, const char *b);
174 void error(const char *msg);
175 void expected1(tok_kind exp1);
176 void expected2(tok_kind exp1, tok_kind exp2);
177 void expected3(tok_kind exp1, tok_kind exp2, tok_kind exp3);
178 void tabify(FILE *f, int tab);
179 void record_open(const char *file);
180 bas_type *find_type(const char *type);
181 
182 /*
183  * rpc_cout routines
184  */
185 void emit(definition *def);
186 
187 /*
188  * rpc_hout routines
189  */
190 void pdeclaration(const char *name, declaration *dec, int tab, const char *separator);
191 void print_datadef(definition *def, int headeronly);
192 void print_funcdef(definition *def, int headeronly);
193 void print_xdr_func_def(const char* name, int pointerp);
194 
195 /*
196  * rpc_svcout routines
197  */
198 void write_most(const char *infile, int netflag, int nomain);
199 void write_rest(void);
200 void write_programs(const char *storage);
201 void write_svc_aux(int nomain);
202 void write_inetd_register(const char *transp);
203 void write_netid_register(const char *transp);
204 void write_nettype_register(const char *transp);
205 int nullproc(proc_list *proc);
206 
207 /*
208  * rpc_clntout routines
209  */
210 void write_stubs(void);
211 void printarglist(proc_list *proc, const char *result, const char *addargname,
212     const char *addargtype);
213 
214 /*
215  * rpc_tblout routines
216  */
217 void write_tables(void);
218 
219 /*
220  * rpc_sample routines
221  */
222 void write_sample_svc(definition *);
223 int write_sample_clnt(definition *);
224 void write_sample_clnt_main(void);
225 void add_sample_msg(void);
226