Back to index

glibc  2.9
rpc_tblout.c
Go to the documentation of this file.
00001 /*
00002  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00003  * unrestricted use provided that this legend is included on all tape
00004  * media and as a part of the software program in whole or part.  Users
00005  * may copy or modify Sun RPC without charge, but are not authorized
00006  * to license or distribute it to anyone else except as part of a product or
00007  * program developed by the user or with the express written consent of
00008  * Sun Microsystems, Inc.
00009  *
00010  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00011  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00012  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00013  *
00014  * Sun RPC is provided with no support and without any obligation on the
00015  * part of Sun Microsystems, Inc. to assist in its use, correction,
00016  * modification or enhancement.
00017  *
00018  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00019  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00020  * OR ANY PART THEREOF.
00021  *
00022  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00023  * or profits or other special, indirect and consequential damages, even if
00024  * Sun has been advised of the possibility of such damages.
00025  *
00026  * Sun Microsystems, Inc.
00027  * 2550 Garcia Avenue
00028  * Mountain View, California  94043
00029  */
00030 
00031 /*
00032  * From: @(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI
00033  */
00034 
00035 /*
00036  * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
00037  */
00038 #include <stdio.h>
00039 #include <string.h>
00040 #include "rpc_parse.h"
00041 #include "rpc_util.h"
00042 #include "proto.h"
00043 
00044 #define TABSIZE             8
00045 #define TABCOUNT     5
00046 #define TABSTOP             (TABSIZE*TABCOUNT)
00047 
00048 static const char tabstr[TABCOUNT + 1] = "\t\t\t\t\t";
00049 
00050 static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
00051 static const char tbl_end[] = "};\n";
00052 
00053 static const char null_entry[] = "\n\t(char *(*)())0,\n\
00054  \t(xdrproc_t) xdr_void,\t\t\t0,\n\
00055  \t(xdrproc_t) xdr_void,\t\t\t0,\n";
00056 
00057 
00058 static const char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
00059 
00060 static void write_table (const definition * def);
00061 static void printit (const char *prefix, const char *type);
00062 
00063 void
00064 write_tables (void)
00065 {
00066   list *l;
00067   definition *def;
00068 
00069   f_print (fout, "\n");
00070   for (l = defined; l != NULL; l = l->next)
00071     {
00072       def = (definition *) l->val;
00073       if (def->def_kind == DEF_PROGRAM)
00074        {
00075          write_table (def);
00076        }
00077     }
00078 }
00079 
00080 static void
00081 write_table (const definition * def)
00082 {
00083   version_list *vp;
00084   proc_list *proc;
00085   int current;
00086   int expected;
00087   char progvers[100];
00088   int warning;
00089 
00090   for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
00091     {
00092       warning = 0;
00093       s_print (progvers, "%s_%s",
00094               locase (def->def_name), vp->vers_num);
00095       /* print the table header */
00096       f_print (fout, tbl_hdr, progvers);
00097 
00098       if (nullproc (vp->procs))
00099        {
00100          expected = 0;
00101        }
00102       else
00103        {
00104          expected = 1;
00105          f_print (fout, null_entry);
00106        }
00107       for (proc = vp->procs; proc != NULL; proc = proc->next)
00108        {
00109          current = atoi (proc->proc_num);
00110          if (current != expected++)
00111            {
00112              f_print (fout,
00113                      "\n/*\n * WARNING: table out of order\n */\n");
00114              if (warning == 0)
00115               {
00116                 f_print (stderr,
00117                         "WARNING %s table is out of order\n",
00118                         progvers);
00119                 warning = 1;
00120                 nonfatalerrors = 1;
00121               }
00122              expected = current + 1;
00123            }
00124          f_print (fout, "\n\t(char *(*)())RPCGEN_ACTION(");
00125 
00126          /* routine to invoke */
00127          if (Cflag && !newstyle)
00128            pvname_svc (proc->proc_name, vp->vers_num);
00129          else
00130            {
00131              if (newstyle)
00132               f_print (fout, "_"); /* calls internal func */
00133              pvname (proc->proc_name, vp->vers_num);
00134            }
00135          f_print (fout, "),\n");
00136 
00137          /* argument info */
00138          if (proc->arg_num > 1)
00139            printit ((char *) NULL, proc->args.argname);
00140          else
00141            /* do we have to do something special for newstyle */
00142            printit (proc->args.decls->decl.prefix,
00143                    proc->args.decls->decl.type);
00144          /* result info */
00145          printit (proc->res_prefix, proc->res_type);
00146        }
00147 
00148       /* print the table trailer */
00149       f_print (fout, tbl_end);
00150       f_print (fout, tbl_nproc, progvers, progvers, progvers);
00151     }
00152 }
00153 
00154 static void
00155 printit (const char *prefix, const char *type)
00156 {
00157   int len;
00158   int tabs;
00159 
00160 
00161   len = fprintf (fout, "\txdr_%s,", stringfix (type));
00162   /* account for leading tab expansion */
00163   len += TABSIZE - 1;
00164   /* round up to tabs required */
00165   tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE;
00166   f_print (fout, "%s", &tabstr[TABCOUNT - tabs]);
00167 
00168   if (streq (type, "void"))
00169     {
00170       f_print (fout, "0");
00171     }
00172   else
00173     {
00174       f_print (fout, "sizeof ( ");
00175       /* XXX: should "follow" be 1 ??? */
00176       ptype (prefix, type, 0);
00177       f_print (fout, ")");
00178     }
00179   f_print (fout, ",\n");
00180 }