Home | History | Annotate | Line # | Download | only in rpcgen
rpc_tblout.c revision 1.10
      1  1.10  christos /*	$NetBSD: rpc_tblout.c,v 1.10 2002/02/05 22:41:47 christos Exp $	*/
      2   1.1        pk /*
      3   1.1        pk  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
      4   1.1        pk  * unrestricted use provided that this legend is included on all tape
      5   1.1        pk  * media and as a part of the software program in whole or part.  Users
      6   1.1        pk  * may copy or modify Sun RPC without charge, but are not authorized
      7   1.1        pk  * to license or distribute it to anyone else except as part of a product or
      8   1.1        pk  * program developed by the user or with the express written consent of
      9   1.1        pk  * Sun Microsystems, Inc.
     10   1.1        pk  *
     11   1.1        pk  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
     12   1.1        pk  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
     13   1.1        pk  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
     14   1.1        pk  *
     15   1.1        pk  * Sun RPC is provided with no support and without any obligation on the
     16   1.1        pk  * part of Sun Microsystems, Inc. to assist in its use, correction,
     17   1.1        pk  * modification or enhancement.
     18   1.1        pk  *
     19   1.1        pk  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
     20   1.1        pk  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
     21   1.1        pk  * OR ANY PART THEREOF.
     22   1.1        pk  *
     23   1.1        pk  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
     24   1.1        pk  * or profits or other special, indirect and consequential damages, even if
     25   1.1        pk  * Sun has been advised of the possibility of such damages.
     26   1.1        pk  *
     27   1.1        pk  * Sun Microsystems, Inc.
     28   1.1        pk  * 2550 Garcia Avenue
     29   1.1        pk  * Mountain View, California  94043
     30   1.1        pk  */
     31   1.1        pk 
     32   1.4  christos #include <sys/cdefs.h>
     33   1.9        tv #if defined(__RCSID) && !defined(lint)
     34   1.4  christos #if 0
     35   1.1        pk static char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI";
     36   1.4  christos #else
     37  1.10  christos __RCSID("$NetBSD: rpc_tblout.c,v 1.10 2002/02/05 22:41:47 christos Exp $");
     38   1.4  christos #endif
     39   1.1        pk #endif
     40   1.1        pk 
     41   1.1        pk /*
     42   1.1        pk  * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler
     43   1.1        pk  */
     44   1.1        pk #include <stdio.h>
     45   1.1        pk #include <string.h>
     46   1.4  christos #include <stdlib.h>
     47   1.4  christos #include "rpc_scan.h"
     48   1.1        pk #include "rpc_parse.h"
     49   1.1        pk #include "rpc_util.h"
     50   1.1        pk 
     51   1.1        pk #define TABSIZE		8
     52   1.1        pk #define TABCOUNT	5
     53   1.1        pk #define TABSTOP		(TABSIZE*TABCOUNT)
     54   1.1        pk 
     55   1.7     lukem static char tabstr[TABCOUNT + 1] = "\t\t\t\t\t";
     56   1.1        pk 
     57   1.8        is static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
     58   1.8        is static const char tbl_end[] = "};\n";
     59   1.1        pk 
     60   1.8        is static const char null_entry[] = "\t(char *(*)())0,\n\
     61   1.6   mycroft  \t(xdrproc_t)xdr_void,\t\t0,\n\
     62   1.6   mycroft  \t(xdrproc_t)xdr_void,\t\t0,\n";
     63   1.1        pk 
     64  1.10  christos static const char tbl_nproc[] =
     65  1.10  christos     "u_int %s_nproc =\n\t(u_int)(sizeof(%s_table)/sizeof(%s_table[0]));\n\n";
     66   1.1        pk 
     67   1.4  christos static void write_table __P((definition *));
     68   1.4  christos static void printit __P((char *, char *));
     69   1.1        pk 
     70   1.1        pk void
     71   1.1        pk write_tables()
     72   1.1        pk {
     73   1.7     lukem 	list   *l;
     74   1.1        pk 	definition *def;
     75   1.1        pk 
     76   1.1        pk 	f_print(fout, "\n");
     77   1.1        pk 	for (l = defined; l != NULL; l = l->next) {
     78   1.1        pk 		def = (definition *) l->val;
     79   1.1        pk 		if (def->def_kind == DEF_PROGRAM) {
     80   1.1        pk 			write_table(def);
     81   1.1        pk 		}
     82   1.1        pk 	}
     83   1.1        pk }
     84   1.1        pk 
     85   1.4  christos static void
     86   1.1        pk write_table(def)
     87   1.1        pk 	definition *def;
     88   1.1        pk {
     89   1.1        pk 	version_list *vp;
     90   1.1        pk 	proc_list *proc;
     91   1.7     lukem 	int     current;
     92   1.7     lukem 	int     expected;
     93   1.7     lukem 	char    progvers[100];
     94   1.7     lukem 	int     warning;
     95   1.1        pk 
     96   1.1        pk 	for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
     97   1.1        pk 		warning = 0;
     98   1.1        pk 		s_print(progvers, "%s_%s",
     99   1.1        pk 		    locase(def->def_name), vp->vers_num);
    100   1.1        pk 		/* print the table header */
    101   1.1        pk 		f_print(fout, tbl_hdr, progvers);
    102   1.1        pk 
    103   1.1        pk 		if (nullproc(vp->procs)) {
    104   1.1        pk 			expected = 0;
    105   1.1        pk 		} else {
    106   1.1        pk 			expected = 1;
    107   1.1        pk 			f_print(fout, null_entry);
    108   1.1        pk 		}
    109   1.1        pk 		for (proc = vp->procs; proc != NULL; proc = proc->next) {
    110   1.5   mycroft 			if (expected != 0)
    111   1.5   mycroft 				f_print(fout, "\n");
    112   1.1        pk 			current = atoi(proc->proc_num);
    113   1.1        pk 			if (current != expected++) {
    114   1.1        pk 				f_print(fout,
    115   1.7     lukem 				    "/*\n * WARNING: table out of order\n */\n\n");
    116   1.1        pk 				if (warning == 0) {
    117   1.1        pk 					f_print(stderr,
    118   1.7     lukem 					    "WARNING %s table is out of order\n",
    119   1.1        pk 					    progvers);
    120   1.1        pk 					warning = 1;
    121   1.1        pk 					nonfatalerrors = 1;
    122   1.1        pk 				}
    123   1.1        pk 				expected = current + 1;
    124   1.1        pk 			}
    125   1.5   mycroft 			f_print(fout, "\t(char *(*)())RPCGEN_ACTION(");
    126   1.1        pk 
    127   1.1        pk 			/* routine to invoke */
    128   1.7     lukem 			if (!newstyle)
    129   1.7     lukem 				pvname_svc(proc->proc_name, vp->vers_num);
    130   1.1        pk 			else {
    131   1.7     lukem 				if (newstyle)
    132   1.7     lukem 					f_print(fout, "_");	/* calls internal func */
    133   1.7     lukem 				pvname(proc->proc_name, vp->vers_num);
    134   1.1        pk 			}
    135   1.1        pk 			f_print(fout, "),\n");
    136   1.1        pk 
    137   1.1        pk 			/* argument info */
    138   1.7     lukem 			if (proc->arg_num > 1)
    139   1.7     lukem 				printit((char *) NULL, proc->args.argname);
    140   1.7     lukem 			else
    141   1.7     lukem 				/* do we have to do something special for
    142   1.7     lukem 				 * newstyle */
    143   1.7     lukem 				printit(proc->args.decls->decl.prefix,
    144   1.7     lukem 				    proc->args.decls->decl.type);
    145   1.1        pk 			/* result info */
    146   1.1        pk 			printit(proc->res_prefix, proc->res_type);
    147   1.1        pk 		}
    148   1.1        pk 
    149   1.1        pk 		/* print the table trailer */
    150   1.1        pk 		f_print(fout, tbl_end);
    151   1.1        pk 		f_print(fout, tbl_nproc, progvers, progvers, progvers);
    152   1.1        pk 	}
    153   1.1        pk }
    154   1.1        pk 
    155   1.4  christos static void
    156   1.1        pk printit(prefix, type)
    157   1.7     lukem 	char   *prefix;
    158   1.7     lukem 	char   *type;
    159   1.1        pk {
    160   1.7     lukem 	int     len;
    161   1.7     lukem 	int     tabs;
    162   1.1        pk 
    163   1.1        pk 
    164   1.7     lukem 	len = fprintf(fout, "\txdr_%s,", stringfix(type));
    165   1.1        pk 	/* account for leading tab expansion */
    166   1.1        pk 	len += TABSIZE - 1;
    167   1.1        pk 	/* round up to tabs required */
    168   1.7     lukem 	tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE;
    169   1.7     lukem 	f_print(fout, "%s", &tabstr[TABCOUNT - tabs]);
    170   1.1        pk 
    171   1.1        pk 	if (streq(type, "void")) {
    172   1.1        pk 		f_print(fout, "0");
    173   1.1        pk 	} else {
    174  1.10  christos 		f_print(fout, "(u_int)sizeof(");
    175   1.1        pk 		/* XXX: should "follow" be 1 ??? */
    176   1.1        pk 		ptype(prefix, type, 0);
    177   1.1        pk 		f_print(fout, ")");
    178   1.1        pk 	}
    179   1.1        pk 	f_print(fout, ",\n");
    180   1.1        pk }
    181