Annotation of src/usr.bin/rpcgen/rpc_tblout.c, Revision 1.9
1.9 ! deraadt 1: /* $OpenBSD: rpc_tblout.c,v 1.8 2002/02/16 21:27:51 millert Exp $ */
1.1 deraadt 2: /* $NetBSD: rpc_tblout.c,v 1.3 1995/06/24 15:00:15 pk Exp $ */
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 or with the express written consent of
10: * Sun Microsystems, Inc.
11: *
12: * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
13: * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
14: * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15: *
16: * Sun RPC is provided with no support and without any obligation on the
17: * part of Sun Microsystems, Inc. to assist in its use, correction,
18: * modification or enhancement.
19: *
20: * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
21: * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
22: * OR ANY PART THEREOF.
23: *
24: * In no event will Sun Microsystems, Inc. be liable for any lost revenue
25: * or profits or other special, indirect and consequential damages, even if
26: * Sun has been advised of the possibility of such damages.
27: *
28: * Sun Microsystems, Inc.
29: * 2550 Garcia Avenue
30: * Mountain View, California 94043
31: */
32:
33: #ifndef lint
34: static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
35: #endif
36:
37: /*
38: * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
39: */
40: #include <sys/cdefs.h>
41: #include <stdio.h>
42: #include <string.h>
43: #include "rpc_parse.h"
44: #include "rpc_util.h"
45:
46: #define TABSIZE 8
47: #define TABCOUNT 5
48: #define TABSTOP (TABSIZE*TABCOUNT)
49:
50: static char tabstr[TABCOUNT+1] = "\t\t\t\t\t";
51:
52: static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
53: static char tbl_end[] = "};\n";
54:
55: static char null_entry[] = "\n\t(char *(*)())0,\n\
1.7 deraadt 56: \t(xdrproc_t) xdr_void,\t\t\t0,\n\
57: \t(xdrproc_t) xdr_void,\t\t\t0,\n";
1.1 deraadt 58:
59: static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
60:
1.8 millert 61: static void write_table(definition *);
62: static void printit(char *, char *);
1.1 deraadt 63:
64: void
65: write_tables()
66: {
1.7 deraadt 67: definition *def;
1.6 deraadt 68: list *l;
1.1 deraadt 69:
1.9 ! deraadt 70: fprintf(fout, "\n");
1.1 deraadt 71: for (l = defined; l != NULL; l = l->next) {
72: def = (definition *) l->val;
1.7 deraadt 73: if (def->def_kind == DEF_PROGRAM)
1.1 deraadt 74: write_table(def);
75: }
76: }
77:
1.7 deraadt 78: static void
1.1 deraadt 79: write_table(def)
80: definition *def;
81: {
82: version_list *vp;
83: proc_list *proc;
84: int current;
85: int expected;
86: char progvers[100];
87: int warning;
88:
89: for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
90: warning = 0;
1.9 ! deraadt 91: snprintf(progvers, sizeof progvers, "%s_%s",
1.1 deraadt 92: locase(def->def_name), vp->vers_num);
93: /* print the table header */
1.9 ! deraadt 94: fprintf(fout, tbl_hdr, progvers);
1.1 deraadt 95:
96: if (nullproc(vp->procs)) {
97: expected = 0;
98: } else {
99: expected = 1;
1.9 ! deraadt 100: fprintf(fout, null_entry);
1.1 deraadt 101: }
102: for (proc = vp->procs; proc != NULL; proc = proc->next) {
103: current = atoi(proc->proc_num);
104: if (current != expected++) {
1.9 ! deraadt 105: fprintf(fout,
1.7 deraadt 106: "\n/*\n * WARNING: table out of order\n */\n");
1.1 deraadt 107: if (warning == 0) {
1.9 ! deraadt 108: fprintf(stderr,
1.7 deraadt 109: "WARNING %s table is out of order\n",
1.1 deraadt 110: progvers);
111: warning = 1;
112: nonfatalerrors = 1;
113: }
114: expected = current + 1;
115: }
1.9 ! deraadt 116: fprintf(fout, "\n\t(char *(*)())RPCGEN_ACTION(");
1.1 deraadt 117:
118: /* routine to invoke */
1.7 deraadt 119: if (!newstyle)
120: pvname_svc(proc->proc_name, vp->vers_num);
1.1 deraadt 121: else {
1.7 deraadt 122: if (newstyle)
1.9 ! deraadt 123: fprintf(fout, "_"); /* calls internal func */
1.7 deraadt 124: pvname(proc->proc_name, vp->vers_num);
1.1 deraadt 125: }
1.9 ! deraadt 126: fprintf(fout, "),\n");
1.1 deraadt 127:
128: /* argument info */
1.7 deraadt 129: if (proc->arg_num > 1)
130: printit((char*) NULL, proc->args.argname);
131: else
132: /* do we have to do something special for newstyle */
133: printit(proc->args.decls->decl.prefix,
134: proc->args.decls->decl.type);
1.1 deraadt 135: /* result info */
136: printit(proc->res_prefix, proc->res_type);
137: }
138:
139: /* print the table trailer */
1.9 ! deraadt 140: fprintf(fout, tbl_end);
! 141: fprintf(fout, tbl_nproc, progvers, progvers, progvers);
1.1 deraadt 142: }
143: }
144:
1.7 deraadt 145: static void
1.1 deraadt 146: printit(prefix, type)
147: char *prefix;
148: char *type;
149: {
1.7 deraadt 150: int len, tabs;
1.1 deraadt 151:
152: len = fprintf(fout, "\txdr_%s,", stringfix(type));
153: /* account for leading tab expansion */
154: len += TABSIZE - 1;
155: /* round up to tabs required */
156: tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE;
1.9 ! deraadt 157: fprintf(fout, "%s", &tabstr[TABCOUNT-tabs]);
1.1 deraadt 158:
159: if (streq(type, "void")) {
1.9 ! deraadt 160: fprintf(fout, "0");
1.1 deraadt 161: } else {
1.9 ! deraadt 162: fprintf(fout, "sizeof (");
1.1 deraadt 163: /* XXX: should "follow" be 1 ??? */
164: ptype(prefix, type, 0);
1.9 ! deraadt 165: fprintf(fout, ")");
1.1 deraadt 166: }
1.9 ! deraadt 167: fprintf(fout, ",\n");
1.1 deraadt 168: }