(__opendir): Don't block on FIFOs etc.
[glibc.git] / sunrpc / rpc_tblout.c
blob7a362471dbf925d2a8cddfcd25b2c43985f52a38
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.
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.
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.
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.
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.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
31 /*
32 * From: @(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI
34 char tblout_rcsid[] =
35 "$Id$";
38 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
40 #include <stdio.h>
41 #include <string.h>
42 #include "rpc_parse.h"
43 #include "rpc_util.h"
44 #include "proto.h"
46 #define TABSIZE 8
47 #define TABCOUNT 5
48 #define TABSTOP (TABSIZE*TABCOUNT)
50 static char tabstr[TABCOUNT+1] = "\t\t\t\t\t";
52 static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
53 static char tbl_end[] = "};\n";
55 static char null_entry[] = "\n\t(char *(*)())0,\n\
56 \t(xdrproc_t) xdr_void,\t\t\t0,\n\
57 \t(xdrproc_t) xdr_void,\t\t\t0,\n";
60 static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
62 static void write_table(const definition *def);
63 static void printit(const char *prefix, const char *type);
65 void
66 write_tables(void)
68 list *l;
69 definition *def;
71 f_print(fout, "\n");
72 for (l = defined; l != NULL; l = l->next) {
73 def = (definition *) l->val;
74 if (def->def_kind == DEF_PROGRAM) {
75 write_table(def);
80 static void
81 write_table(const definition *def)
83 version_list *vp;
84 proc_list *proc;
85 int current;
86 int expected;
87 char progvers[100];
88 int warning;
90 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
91 warning = 0;
92 s_print(progvers, "%s_%s",
93 locase(def->def_name), vp->vers_num);
94 /* print the table header */
95 f_print(fout, tbl_hdr, progvers);
97 if (nullproc(vp->procs)) {
98 expected = 0;
100 else {
101 expected = 1;
102 f_print(fout, null_entry);
104 for (proc = vp->procs; proc != NULL; proc = proc->next) {
105 current = atoi(proc->proc_num);
106 if (current != expected++) {
107 f_print(fout,
108 "\n/*\n * WARNING: table out of order\n */\n");
109 if (warning == 0) {
110 f_print(stderr,
111 "WARNING %s table is out of order\n",
112 progvers);
113 warning = 1;
114 nonfatalerrors = 1;
116 expected = current + 1;
118 f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION(");
120 /* routine to invoke */
121 if( Cflag && !newstyle )
122 pvname_svc(proc->proc_name, vp->vers_num);
123 else {
124 if( newstyle )
125 f_print( fout, "_"); /* calls internal func */
126 pvname(proc->proc_name, vp->vers_num);
128 f_print(fout, "),\n");
130 /* argument info */
131 if( proc->arg_num > 1 )
132 printit((char*) NULL, proc->args.argname );
133 else
134 /* do we have to do something special for newstyle */
135 printit( proc->args.decls->decl.prefix,
136 proc->args.decls->decl.type );
137 /* result info */
138 printit(proc->res_prefix, proc->res_type);
141 /* print the table trailer */
142 f_print(fout, tbl_end);
143 f_print(fout, tbl_nproc, progvers, progvers, progvers);
147 static void
148 printit(const char *prefix, const char *type)
150 int len;
151 int tabs;
154 len = fprintf(fout, "\txdr_%s,", stringfix(type));
155 /* account for leading tab expansion */
156 len += TABSIZE - 1;
157 /* round up to tabs required */
158 tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE;
159 f_print(fout, "%s", &tabstr[TABCOUNT-tabs]);
161 if (streq(type, "void")) {
162 f_print(fout, "0");
163 } else {
164 f_print(fout, "sizeof ( ");
165 /* XXX: should "follow" be 1 ??? */
166 ptype(prefix, type, 0);
167 f_print(fout, ")");
169 f_print(fout, ",\n");