remove COPYING* from .gitignore files
[platform/upstream/glibc.git] / sunrpc / 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 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
31 /*
32  * From: @(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI
33  */
34
35 /*
36  * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
37  */
38 #include <stdio.h>
39 #include <string.h>
40 #include "rpc_parse.h"
41 #include "rpc_util.h"
42 #include "proto.h"
43
44 #define TABSIZE         8
45 #define TABCOUNT        5
46 #define TABSTOP         (TABSIZE*TABCOUNT)
47
48 static const char tabstr[TABCOUNT + 1] = "\t\t\t\t\t";
49
50 static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
51 static const char tbl_end[] = "};\n";
52
53 static const char null_entry[] = "\n\t(char *(*)())0,\n\
54  \t(xdrproc_t) xdr_void,\t\t\t0,\n\
55  \t(xdrproc_t) xdr_void,\t\t\t0,\n";
56
57
58 static const char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
59
60 static void write_table (const definition * def);
61 static void printit (const char *prefix, const char *type);
62
63 void
64 write_tables (void)
65 {
66   list *l;
67   definition *def;
68
69   f_print (fout, "\n");
70   for (l = defined; l != NULL; l = l->next)
71     {
72       def = (definition *) l->val;
73       if (def->def_kind == DEF_PROGRAM)
74         {
75           write_table (def);
76         }
77     }
78 }
79
80 static void
81 write_table (const definition * def)
82 {
83   version_list *vp;
84   proc_list *proc;
85   int current;
86   int expected;
87   char progvers[100];
88   int warning;
89
90   for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
91     {
92       warning = 0;
93       s_print (progvers, "%s_%s",
94                locase (def->def_name), vp->vers_num);
95       /* print the table header */
96       f_print (fout, tbl_hdr, progvers);
97
98       if (nullproc (vp->procs))
99         {
100           expected = 0;
101         }
102       else
103         {
104           expected = 1;
105           f_print (fout, null_entry);
106         }
107       for (proc = vp->procs; proc != NULL; proc = proc->next)
108         {
109           current = atoi (proc->proc_num);
110           if (current != expected++)
111             {
112               f_print (fout,
113                        "\n/*\n * WARNING: table out of order\n */\n");
114               if (warning == 0)
115                 {
116                   f_print (stderr,
117                            "WARNING %s table is out of order\n",
118                            progvers);
119                   warning = 1;
120                   nonfatalerrors = 1;
121                 }
122               expected = current + 1;
123             }
124           f_print (fout, "\n\t(char *(*)())RPCGEN_ACTION(");
125
126           /* routine to invoke */
127           if (Cflag && !newstyle)
128             pvname_svc (proc->proc_name, vp->vers_num);
129           else
130             {
131               if (newstyle)
132                 f_print (fout, "_");    /* calls internal func */
133               pvname (proc->proc_name, vp->vers_num);
134             }
135           f_print (fout, "),\n");
136
137           /* argument info */
138           if (proc->arg_num > 1)
139             printit ((char *) NULL, proc->args.argname);
140           else
141             /* do we have to do something special for newstyle */
142             printit (proc->args.decls->decl.prefix,
143                      proc->args.decls->decl.type);
144           /* result info */
145           printit (proc->res_prefix, proc->res_type);
146         }
147
148       /* print the table trailer */
149       f_print (fout, tbl_end);
150       f_print (fout, tbl_nproc, progvers, progvers, progvers);
151     }
152 }
153
154 static void
155 printit (const char *prefix, const char *type)
156 {
157   int len;
158   int tabs;
159
160
161   len = fprintf (fout, "\txdr_%s,", stringfix (type));
162   /* account for leading tab expansion */
163   len += TABSIZE - 1;
164   /* round up to tabs required */
165   tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE;
166   f_print (fout, "%s", &tabstr[TABCOUNT - tabs]);
167
168   if (streq (type, "void"))
169     {
170       f_print (fout, "0");
171     }
172   else
173     {
174       f_print (fout, "sizeof ( ");
175       /* XXX: should "follow" be 1 ??? */
176       ptype (prefix, type, 0);
177       f_print (fout, ")");
178     }
179   f_print (fout, ",\n");
180 }