2 * From: @(#)rpc_tblout.c 1.4 89/02/22
4 * Copyright (c) 2010, Oracle America, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 * * Neither the name of the "Oracle America, Inc." nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
38 #include "rpc_parse.h"
44 #define TABSTOP (TABSIZE*TABCOUNT)
46 static const char tabstr
[TABCOUNT
+ 1] = "\t\t\t\t\t";
48 static const char tbl_hdr
[] = "struct rpcgen_table %s_table[] = {\n";
49 static const char tbl_end
[] = "};\n";
51 static const char null_entry
[] = "\n\t(char *(*)())0,\n\
52 \t(xdrproc_t) xdr_void,\t\t\t0,\n\
53 \t(xdrproc_t) xdr_void,\t\t\t0,\n";
56 static const char tbl_nproc
[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
58 static void write_table (const definition
* def
);
59 static void printit (const char *prefix
, const char *type
);
68 for (l
= defined
; l
!= NULL
; l
= l
->next
)
70 def
= (definition
*) l
->val
;
71 if (def
->def_kind
== DEF_PROGRAM
)
79 write_table (const definition
* def
)
88 for (vp
= def
->def
.pr
.versions
; vp
!= NULL
; vp
= vp
->next
)
91 s_print (progvers
, "%s_%s",
92 locase (def
->def_name
), vp
->vers_num
);
93 /* print the table header */
94 f_print (fout
, tbl_hdr
, progvers
);
96 if (nullproc (vp
->procs
))
103 f_print (fout
, null_entry
);
105 for (proc
= vp
->procs
; proc
!= NULL
; proc
= proc
->next
)
107 current
= atoi (proc
->proc_num
);
108 if (current
!= expected
++)
111 "\n/*\n * WARNING: table out of order\n */\n");
115 "WARNING %s table is out of order\n",
120 expected
= current
+ 1;
122 f_print (fout
, "\n\t(char *(*)())RPCGEN_ACTION(");
124 /* routine to invoke */
125 if (Cflag
&& !newstyle
)
126 pvname_svc (proc
->proc_name
, vp
->vers_num
);
130 f_print (fout
, "_"); /* calls internal func */
131 pvname (proc
->proc_name
, vp
->vers_num
);
133 f_print (fout
, "),\n");
136 if (proc
->arg_num
> 1)
137 printit ((char *) NULL
, proc
->args
.argname
);
139 /* do we have to do something special for newstyle */
140 printit (proc
->args
.decls
->decl
.prefix
,
141 proc
->args
.decls
->decl
.type
);
143 printit (proc
->res_prefix
, proc
->res_type
);
146 /* print the table trailer */
147 f_print (fout
, tbl_end
);
148 f_print (fout
, tbl_nproc
, progvers
, progvers
, progvers
);
153 printit (const char *prefix
, const char *type
)
159 len
= fprintf (fout
, "\txdr_%s,", stringfix (type
));
160 /* account for leading tab expansion */
162 /* round up to tabs required */
163 tabs
= (TABSTOP
- len
+ TABSIZE
- 1) / TABSIZE
;
164 f_print (fout
, "%s", &tabstr
[TABCOUNT
- tabs
]);
166 if (streq (type
, "void"))
172 f_print (fout
, "sizeof ( ");
173 /* XXX: should "follow" be 1 ??? */
174 ptype (prefix
, type
, 0);
177 f_print (fout
, ",\n");