home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / comm / tcp / amitcp / src / devtools / rpcgen / rpc_tblout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-09  |  4.5 KB  |  173 lines

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