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