xref: /freebsd/usr.bin/rpcgen/rpc_util.h (revision bdcbfde3)
14e115012SGarrett Wollman /*
240ad8885SAlfred Perlstein  */
340ad8885SAlfred Perlstein /*
44e115012SGarrett Wollman  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
54e115012SGarrett Wollman  * unrestricted use provided that this legend is included on all tape
64e115012SGarrett Wollman  * media and as a part of the software program in whole or part.  Users
74e115012SGarrett Wollman  * may copy or modify Sun RPC without charge, but are not authorized
84e115012SGarrett Wollman  * to license or distribute it to anyone else except as part of a product or
94e115012SGarrett Wollman  * program developed by the user.
104e115012SGarrett Wollman  *
114e115012SGarrett Wollman  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
124e115012SGarrett Wollman  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
134e115012SGarrett Wollman  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
144e115012SGarrett Wollman  *
154e115012SGarrett Wollman  * Sun RPC is provided with no support and without any obligation on the
164e115012SGarrett Wollman  * part of Sun Microsystems, Inc. to assist in its use, correction,
174e115012SGarrett Wollman  * modification or enhancement.
184e115012SGarrett Wollman  *
194e115012SGarrett Wollman  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
204e115012SGarrett Wollman  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
214e115012SGarrett Wollman  * OR ANY PART THEREOF.
224e115012SGarrett Wollman  *
234e115012SGarrett Wollman  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
244e115012SGarrett Wollman  * or profits or other special, indirect and consequential damages, even if
254e115012SGarrett Wollman  * Sun has been advised of the possibility of such damages.
264e115012SGarrett Wollman  *
274e115012SGarrett Wollman  * Sun Microsystems, Inc.
284e115012SGarrett Wollman  * 2550 Garcia Avenue
294e115012SGarrett Wollman  * Mountain View, California  94043
304e115012SGarrett Wollman  */
31ff49530fSBill Paul /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
32ff49530fSBill Paul /*	  All Rights Reserved  	*/
33ff49530fSBill Paul 
34ff49530fSBill Paul /*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
35ff49530fSBill Paul /*	The copyright notice above does not evidence any   	*/
36ff49530fSBill Paul /*	actual or intended publication of such source code.	*/
37ff49530fSBill Paul 
38ff49530fSBill Paul 
39ff49530fSBill Paul /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
40ff49530fSBill Paul *	PROPRIETARY NOTICE (Combined)
41ff49530fSBill Paul *
42ff49530fSBill Paul * This source code is unpublished proprietary information
43ff49530fSBill Paul * constituting, or derived under license from AT&T's UNIX(r) System V.
44ff49530fSBill Paul * In addition, portions of such source code were derived from Berkeley
45ff49530fSBill Paul * 4.3 BSD under license from the Regents of the University of
46ff49530fSBill Paul * California.
47ff49530fSBill Paul *
48ff49530fSBill Paul *
49ff49530fSBill Paul *
50ff49530fSBill Paul *	Copyright Notice
51ff49530fSBill Paul *
52ff49530fSBill Paul * Notice of copyright on this source code product does not indicate
53ff49530fSBill Paul *  publication.
54ff49530fSBill Paul *
55ff49530fSBill Paul *	(c) 1986,1987,1988.1989  Sun Microsystems, Inc
56ff49530fSBill Paul *	(c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
57ff49530fSBill Paul *          All rights reserved.
58ff49530fSBill Paul */
59ff49530fSBill Paul 
604e115012SGarrett Wollman /*
614e115012SGarrett Wollman  * rpc_util.h, Useful definitions for the RPC protocol compiler
624e115012SGarrett Wollman  */
63ff49530fSBill Paul #include <sys/types.h>
64ff49530fSBill Paul #include <stdlib.h>
654e115012SGarrett Wollman 
6675863a6dSPhilippe Charnier #define	XALLOC(object)   (object *) xmalloc(sizeof(object))
674e115012SGarrett Wollman 
684e115012SGarrett Wollman #define	s_print	(void) sprintf
694e115012SGarrett Wollman #define	f_print (void) fprintf
704e115012SGarrett Wollman 
714e115012SGarrett Wollman struct list {
72ff49530fSBill Paul 	definition *val;
734e115012SGarrett Wollman 	struct list *next;
744e115012SGarrett Wollman };
754e115012SGarrett Wollman typedef struct list list;
764e115012SGarrett Wollman 
77ff49530fSBill Paul struct xdrfunc {
78e390e3afSDavid Malone 	const char *name;
79ff49530fSBill Paul 	int pointerp;
80ff49530fSBill Paul 	struct xdrfunc *next;
81ff49530fSBill Paul };
82ff49530fSBill Paul typedef struct xdrfunc xdrfunc;
83ff49530fSBill Paul 
84ff49530fSBill Paul struct commandline {
85ff49530fSBill Paul 	int cflag;		/* xdr C routines */
86ff49530fSBill Paul 	int hflag;		/* header file */
87ff49530fSBill Paul 	int lflag;		/* client side stubs */
88ff49530fSBill Paul 	int mflag;		/* server side stubs */
89ff49530fSBill Paul 	int nflag;		/* netid flag */
90ff49530fSBill Paul 	int sflag;		/* server stubs for the given transport */
91ff49530fSBill Paul 	int tflag;		/* dispatch Table file */
92ff49530fSBill Paul 	int Ssflag;		/* produce server sample code */
93ff49530fSBill Paul 	int Scflag;		/* produce client sample code */
94ff49530fSBill Paul 	int makefileflag;       /* Generate a template Makefile */
95e390e3afSDavid Malone 	const char *infile;	/* input module name */
96e390e3afSDavid Malone 	const char *outfile;	/* output module name */
97ff49530fSBill Paul };
98ff49530fSBill Paul 
99ff49530fSBill Paul #define	PUT 1
100ff49530fSBill Paul #define	GET 2
101ff49530fSBill Paul 
1024e115012SGarrett Wollman /*
1034e115012SGarrett Wollman  * Global variables
1044e115012SGarrett Wollman  */
1054e115012SGarrett Wollman #define	MAXLINESIZE 1024
1064e115012SGarrett Wollman extern char curline[MAXLINESIZE];
1074e115012SGarrett Wollman extern char *where;
1084e115012SGarrett Wollman extern int linenum;
109e390e3afSDavid Malone extern int tirpc_socket;
1104e115012SGarrett Wollman 
111e390e3afSDavid Malone extern const char *infilename;
1124e115012SGarrett Wollman extern FILE *fout;
1134e115012SGarrett Wollman extern FILE *fin;
1144e115012SGarrett Wollman 
1154e115012SGarrett Wollman extern list *defined;
1164e115012SGarrett Wollman 
117ff49530fSBill Paul 
118ff49530fSBill Paul extern bas_type *typ_list_h;
119ff49530fSBill Paul extern bas_type *typ_list_t;
120ff49530fSBill Paul extern xdrfunc *xdrfunc_head, *xdrfunc_tail;
121ff49530fSBill Paul 
122ff49530fSBill Paul /*
123ff49530fSBill Paul  * All the option flags
124ff49530fSBill Paul  */
125ff49530fSBill Paul extern int inetdflag;
126ff49530fSBill Paul extern int pmflag;
127ff49530fSBill Paul extern int tblflag;
128ff49530fSBill Paul extern int logflag;
129ff49530fSBill Paul extern int newstyle;
130ff49530fSBill Paul extern int CCflag;     /* C++ flag */
131ff49530fSBill Paul extern int tirpcflag; /* flag for generating tirpc code */
132122562cdSStefan Farfeleder extern int inline_size; /* if this is 0, then do not generate inline code */
133ff49530fSBill Paul extern int mtflag;
134ff49530fSBill Paul 
135ff49530fSBill Paul /*
136ff49530fSBill Paul  * Other flags related with inetd jumpstart.
137ff49530fSBill Paul  */
138ff49530fSBill Paul extern int indefinitewait;
139ff49530fSBill Paul extern int exitnow;
140ff49530fSBill Paul extern int timerflag;
141ff49530fSBill Paul 
142ff49530fSBill Paul extern int nonfatalerrors;
143ff49530fSBill Paul 
144ff49530fSBill Paul extern pid_t childpid;
145ff49530fSBill Paul 
1464e115012SGarrett Wollman /*
1474e115012SGarrett Wollman  * rpc_util routines
1484e115012SGarrett Wollman  */
149d0cc804bSStefan Farfeleder void reinitialize(void);
1501d1694a7SConrad Meyer void crash(void) __dead2;
151e390e3afSDavid Malone void add_type(int len, const char *type);
152d0cc804bSStefan Farfeleder void storeval(list **lstp, definition *val);
15375863a6dSPhilippe Charnier void *xmalloc(size_t size);
15475863a6dSPhilippe Charnier void *xrealloc(void *ptr, size_t size);
155e390e3afSDavid Malone char *xstrdup(const char *);
156e390e3afSDavid Malone char *make_argname(const char *pname, const char *vname);
1574e115012SGarrett Wollman 
1584e115012SGarrett Wollman #define	STOREVAL(list,item)	\
159ff49530fSBill Paul 	storeval(list,item)
1604e115012SGarrett Wollman 
161e390e3afSDavid Malone definition *findval(list *lst, const char *val, int (*cmp)(definition *, const char *));
1624e115012SGarrett Wollman 
1634e115012SGarrett Wollman #define	FINDVAL(list,item,finder) \
164ff49530fSBill Paul 	findval(list, item, finder)
1654e115012SGarrett Wollman 
166e390e3afSDavid Malone const char *fixtype(const char *type);
167e390e3afSDavid Malone const char *stringfix(const char *type);
168e390e3afSDavid Malone char *locase(const char *str);
169e390e3afSDavid Malone void pvname_svc(const char *pname, const char *vnum);
170e390e3afSDavid Malone void pvname(const char *pname, const char *vnum);
171e390e3afSDavid Malone void ptype(const char *prefix, const char *type, int follow);
172e390e3afSDavid Malone int isvectordef(const char *type, relation rel);
173e390e3afSDavid Malone int streq(const char *a, const char *b);
174e390e3afSDavid Malone void error(const char *msg);
175d0cc804bSStefan Farfeleder void expected1(tok_kind exp1);
176d0cc804bSStefan Farfeleder void expected2(tok_kind exp1, tok_kind exp2);
177d0cc804bSStefan Farfeleder void expected3(tok_kind exp1, tok_kind exp2, tok_kind exp3);
178d0cc804bSStefan Farfeleder void tabify(FILE *f, int tab);
179e390e3afSDavid Malone void record_open(const char *file);
180e390e3afSDavid Malone bas_type *find_type(const char *type);
181d0cc804bSStefan Farfeleder 
1824e115012SGarrett Wollman /*
1834e115012SGarrett Wollman  * rpc_cout routines
1844e115012SGarrett Wollman  */
185d0cc804bSStefan Farfeleder void emit(definition *def);
1864e115012SGarrett Wollman 
1874e115012SGarrett Wollman /*
1884e115012SGarrett Wollman  * rpc_hout routines
1894e115012SGarrett Wollman  */
190e390e3afSDavid Malone void pdeclaration(const char *name, declaration *dec, int tab, const char *separator);
191ec06b5e8SStefan Farfeleder void print_datadef(definition *def, int headeronly);
192ec06b5e8SStefan Farfeleder void print_funcdef(definition *def, int headeronly);
193e390e3afSDavid Malone void print_xdr_func_def(const char* name, int pointerp);
1944e115012SGarrett Wollman 
1954e115012SGarrett Wollman /*
1964e115012SGarrett Wollman  * rpc_svcout routines
1974e115012SGarrett Wollman  */
198e390e3afSDavid Malone void write_most(const char *infile, int netflag, int nomain);
199d0cc804bSStefan Farfeleder void write_rest(void);
200e390e3afSDavid Malone void write_programs(const char *storage);
201d0cc804bSStefan Farfeleder void write_svc_aux(int nomain);
202e390e3afSDavid Malone void write_inetd_register(const char *transp);
203e390e3afSDavid Malone void write_netid_register(const char *transp);
204e390e3afSDavid Malone void write_nettype_register(const char *transp);
205e390e3afSDavid Malone int nullproc(proc_list *proc);
206d0cc804bSStefan Farfeleder 
2074e115012SGarrett Wollman /*
2084e115012SGarrett Wollman  * rpc_clntout routines
2094e115012SGarrett Wollman  */
210d0cc804bSStefan Farfeleder void write_stubs(void);
211e390e3afSDavid Malone void printarglist(proc_list *proc, const char *result, const char *addargname,
212e390e3afSDavid Malone     const char *addargtype);
213ff49530fSBill Paul 
214ff49530fSBill Paul /*
215ff49530fSBill Paul  * rpc_tblout routines
216ff49530fSBill Paul  */
217d0cc804bSStefan Farfeleder void write_tables(void);
218e390e3afSDavid Malone 
219e390e3afSDavid Malone /*
220e390e3afSDavid Malone  * rpc_sample routines
221e390e3afSDavid Malone  */
222e390e3afSDavid Malone void write_sample_svc(definition *);
223e390e3afSDavid Malone int write_sample_clnt(definition *);
224e390e3afSDavid Malone void write_sample_clnt_main(void);
225e390e3afSDavid Malone void add_sample_msg(void);
226