Home | History | Annotate | Line # | Download | only in rpcgen
rpc_tblout.c revision 1.7.12.1
      1  1.7.12.1        tv /*	$NetBSD: rpc_tblout.c,v 1.7.12.1 2000/10/18 01:32:50 tv 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.1        pk #ifndef 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.7.12.1        tv __RCSID("$NetBSD: rpc_tblout.c,v 1.7.12.1 2000/10/18 01:32:50 tv 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.7.12.1        tv static const char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n";
     58  1.7.12.1        tv static const char tbl_end[] = "};\n";
     59       1.1        pk 
     60  1.7.12.1        tv 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.7.12.1        tv static const char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n";
     65       1.1        pk 
     66       1.4  christos static void write_table __P((definition *));
     67       1.4  christos static void printit __P((char *, char *));
     68       1.1        pk 
     69       1.1        pk void
     70       1.1        pk write_tables()
     71       1.1        pk {
     72       1.7     lukem 	list   *l;
     73       1.1        pk 	definition *def;
     74       1.1        pk 
     75       1.1        pk 	f_print(fout, "\n");
     76       1.1        pk 	for (l = defined; l != NULL; l = l->next) {
     77       1.1        pk 		def = (definition *) l->val;
     78       1.1        pk 		if (def->def_kind == DEF_PROGRAM) {
     79       1.1        pk 			write_table(def);
     80       1.1        pk 		}
     81       1.1        pk 	}
     82       1.1        pk }
     83       1.1        pk 
     84       1.4  christos static void
     85       1.1        pk write_table(def)
     86       1.1        pk 	definition *def;
     87       1.1        pk {
     88       1.1        pk 	version_list *vp;
     89       1.1        pk 	proc_list *proc;
     90       1.7     lukem 	int     current;
     91       1.7     lukem 	int     expected;
     92       1.7     lukem 	char    progvers[100];
     93       1.7     lukem 	int     warning;
     94       1.1        pk 
     95       1.1        pk 	for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
     96       1.1        pk 		warning = 0;
     97       1.1        pk 		s_print(progvers, "%s_%s",
     98       1.1        pk 		    locase(def->def_name), vp->vers_num);
     99       1.1        pk 		/* print the table header */
    100       1.1        pk 		f_print(fout, tbl_hdr, progvers);
    101       1.1        pk 
    102       1.1        pk 		if (nullproc(vp->procs)) {
    103       1.1        pk 			expected = 0;
    104       1.1        pk 		} else {
    105       1.1        pk 			expected = 1;
    106       1.1        pk 			f_print(fout, null_entry);
    107       1.1        pk 		}
    108       1.1        pk 		for (proc = vp->procs; proc != NULL; proc = proc->next) {
    109       1.5   mycroft 			if (expected != 0)
    110       1.5   mycroft 				f_print(fout, "\n");
    111       1.1        pk 			current = atoi(proc->proc_num);
    112       1.1        pk 			if (current != expected++) {
    113       1.1        pk 				f_print(fout,
    114       1.7     lukem 				    "/*\n * WARNING: table out of order\n */\n\n");
    115       1.1        pk 				if (warning == 0) {
    116       1.1        pk 					f_print(stderr,
    117       1.7     lukem 					    "WARNING %s table is out of order\n",
    118       1.1        pk 					    progvers);
    119       1.1        pk 					warning = 1;
    120       1.1        pk 					nonfatalerrors = 1;
    121       1.1        pk 				}
    122       1.1        pk 				expected = current + 1;
    123       1.1        pk 			}
    124       1.5   mycroft 			f_print(fout, "\t(char *(*)())RPCGEN_ACTION(");
    125       1.1        pk 
    126       1.1        pk 			/* routine to invoke */
    127       1.7     lukem 			if (!newstyle)
    128       1.7     lukem 				pvname_svc(proc->proc_name, vp->vers_num);
    129       1.1        pk 			else {
    130       1.7     lukem 				if (newstyle)
    131       1.7     lukem 					f_print(fout, "_");	/* calls internal func */
    132       1.7     lukem 				pvname(proc->proc_name, vp->vers_num);
    133       1.1        pk 			}
    134       1.1        pk 			f_print(fout, "),\n");
    135       1.1        pk 
    136       1.1        pk 			/* argument info */
    137       1.7     lukem 			if (proc->arg_num > 1)
    138       1.7     lukem 				printit((char *) NULL, proc->args.argname);
    139       1.7     lukem 			else
    140       1.7     lukem 				/* do we have to do something special for
    141       1.7     lukem 				 * newstyle */
    142       1.7     lukem 				printit(proc->args.decls->decl.prefix,
    143       1.7     lukem 				    proc->args.decls->decl.type);
    144       1.1        pk 			/* result info */
    145       1.1        pk 			printit(proc->res_prefix, proc->res_type);
    146       1.1        pk 		}
    147       1.1        pk 
    148       1.1        pk 		/* print the table trailer */
    149       1.1        pk 		f_print(fout, tbl_end);
    150       1.1        pk 		f_print(fout, tbl_nproc, progvers, progvers, progvers);
    151       1.1        pk 	}
    152       1.1        pk }
    153       1.1        pk 
    154       1.4  christos static void
    155       1.1        pk printit(prefix, type)
    156       1.7     lukem 	char   *prefix;
    157       1.7     lukem 	char   *type;
    158       1.1        pk {
    159       1.7     lukem 	int     len;
    160       1.7     lukem 	int     tabs;
    161       1.1        pk 
    162       1.1        pk 
    163       1.7     lukem 	len = fprintf(fout, "\txdr_%s,", stringfix(type));
    164       1.1        pk 	/* account for leading tab expansion */
    165       1.1        pk 	len += TABSIZE - 1;
    166       1.1        pk 	/* round up to tabs required */
    167       1.7     lukem 	tabs = (TABSTOP - len + TABSIZE - 1) / TABSIZE;
    168       1.7     lukem 	f_print(fout, "%s", &tabstr[TABCOUNT - tabs]);
    169       1.1        pk 
    170       1.1        pk 	if (streq(type, "void")) {
    171       1.1        pk 		f_print(fout, "0");
    172       1.1        pk 	} else {
    173       1.1        pk 		f_print(fout, "sizeof ( ");
    174       1.1        pk 		/* XXX: should "follow" be 1 ??? */
    175       1.1        pk 		ptype(prefix, type, 0);
    176       1.1        pk 		f_print(fout, ")");
    177       1.1        pk 	}
    178       1.1        pk 	f_print(fout, ",\n");
    179       1.1        pk }
    180