alpha: fix ceil on sNaN input
[glibc.git] / sunrpc / rpc_tblout.c
bloba7d2f43528657300ec29dca365665cbed8774a4e
1 /*
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
7 * met:
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
36 #include <stdio.h>
37 #include <string.h>
38 #include "rpc_parse.h"
39 #include "rpc_util.h"
40 #include "proto.h"
42 #define TABSIZE 8
43 #define TABCOUNT 5
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);
61 void
62 write_tables (void)
64 list *l;
65 definition *def;
67 f_print (fout, "\n");
68 for (l = defined; l != NULL; l = l->next)
70 def = (definition *) l->val;
71 if (def->def_kind == DEF_PROGRAM)
73 write_table (def);
78 static void
79 write_table (const definition * def)
81 version_list *vp;
82 proc_list *proc;
83 int current;
84 int expected;
85 char progvers[100];
86 int warning;
88 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
90 warning = 0;
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))
98 expected = 0;
100 else
102 expected = 1;
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++)
110 f_print (fout,
111 "\n/*\n * WARNING: table out of order\n */\n");
112 if (warning == 0)
114 f_print (stderr,
115 "WARNING %s table is out of order\n",
116 progvers);
117 warning = 1;
118 nonfatalerrors = 1;
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);
127 else
129 if (newstyle)
130 f_print (fout, "_"); /* calls internal func */
131 pvname (proc->proc_name, vp->vers_num);
133 f_print (fout, "),\n");
135 /* argument info */
136 if (proc->arg_num > 1)
137 printit ((char *) NULL, proc->args.argname);
138 else
139 /* do we have to do something special for newstyle */
140 printit (proc->args.decls->decl.prefix,
141 proc->args.decls->decl.type);
142 /* result info */
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);
152 static void
153 printit (const char *prefix, const char *type)
155 int len;
156 int tabs;
159 len = fprintf (fout, "\txdr_%s,", stringfix (type));
160 /* account for leading tab expansion */
161 len += TABSIZE - 1;
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"))
168 f_print (fout, "0");
170 else
172 f_print (fout, "sizeof ( ");
173 /* XXX: should "follow" be 1 ??? */
174 ptype (prefix, type, 0);
175 f_print (fout, ")");
177 f_print (fout, ",\n");