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