rpc_tblout.c revision 152398
1142399Swpaul/* 2142399Swpaul * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 3142399Swpaul * unrestricted use provided that this legend is included on all tape 4142399Swpaul * media and as a part of the software program in whole or part. Users 5142399Swpaul * may copy or modify Sun RPC without charge, but are not authorized 6142399Swpaul * to license or distribute it to anyone else except as part of a product or 7142399Swpaul * program developed by the user. 8142399Swpaul * 9142399Swpaul * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 10142399Swpaul * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 11142399Swpaul * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12142399Swpaul * 13142399Swpaul * Sun RPC is provided with no support and without any obligation on the 14142399Swpaul * part of Sun Microsystems, Inc. to assist in its use, correction, 15142399Swpaul * modification or enhancement. 16142399Swpaul * 17142399Swpaul * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 18142399Swpaul * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 19142399Swpaul * OR ANY PART THEREOF. 20142399Swpaul * 21142399Swpaul * In no event will Sun Microsystems, Inc. be liable for any lost revenue 22142399Swpaul * or profits or other special, indirect and consequential damages, even if 23142399Swpaul * Sun has been advised of the possibility of such damages. 24142399Swpaul * 25142399Swpaul * Sun Microsystems, Inc. 26142399Swpaul * 2550 Garcia Avenue 27142399Swpaul * Mountain View, California 94043 28142399Swpaul */ 29142399Swpaul 30142399Swpaul#if 0 31142399Swpaul#ifndef lint 32142399Swpaul#ident "@(#)rpc_tblout.c 1.11 93/07/05 SMI" 33142399Swpaulstatic char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI"; 34142399Swpaul#endif 35142399Swpaul#endif 36142399Swpaul 37142399Swpaul#include <sys/cdefs.h> 38186507Sweongyo__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_tblout.c 152398 2005-11-13 21:17:24Z dwmalone $"); 39142399Swpaul 40186507Sweongyo/* 41189488Sweongyo * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 42186507Sweongyo * Copyright (C) 1989, Sun Microsystems, Inc. 43186507Sweongyo */ 44186507Sweongyo#include <err.h> 45186507Sweongyo#include <stdio.h> 46186507Sweongyo#include <string.h> 47186507Sweongyo#include "rpc_parse.h" 48186507Sweongyo#include "rpc_scan.h" 49186507Sweongyo#include "rpc_util.h" 50186507Sweongyo 51186507Sweongyo#define TABSIZE 8 52186507Sweongyo#define TABCOUNT 5 53186507Sweongyo#define TABSTOP (TABSIZE*TABCOUNT) 54186507Sweongyo 55186507Sweongyostatic char tabstr[TABCOUNT+1] = "\t\t\t\t\t"; 56186507Sweongyo 57186507Sweongyostatic char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 58186507Sweongyostatic char tbl_end[] = "};\n"; 59186507Sweongyo 60186507Sweongyostatic char null_entry[] = "\n\t(char *(*)())0,\n\ 61186507Sweongyo \t(xdrproc_t) xdr_void,\t\t\t0,\n\ 62186507Sweongyo \t(xdrproc_t) xdr_void,\t\t\t0,\n"; 63186507Sweongyo 64186507Sweongyo 65186507Sweongyostatic char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n"; 66186507Sweongyo 67186507Sweongyostatic void write_table( definition * ); 68186507Sweongyostatic void printit(const char *, const char *); 69186507Sweongyo 70186507Sweongyovoid 71186507Sweongyowrite_tables(void) 72186507Sweongyo{ 73186507Sweongyo list *l; 74186507Sweongyo definition *def; 75186507Sweongyo 76186507Sweongyo f_print(fout, "\n"); 77186507Sweongyo for (l = defined; l != NULL; l = l->next) { 78186507Sweongyo def = (definition *) l->val; 79186507Sweongyo if (def->def_kind == DEF_PROGRAM) { 80186507Sweongyo write_table(def); 81186507Sweongyo } 82186507Sweongyo } 83186507Sweongyo} 84186507Sweongyo 85186507Sweongyostatic void 86186507Sweongyowrite_table(definition *def) 87186507Sweongyo{ 88186507Sweongyo version_list *vp; 89186507Sweongyo proc_list *proc; 90186507Sweongyo int current; 91186507Sweongyo int expected; 92186507Sweongyo char progvers[100]; 93186507Sweongyo int warning; 94186507Sweongyo 95186507Sweongyo for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 96186507Sweongyo warning = 0; 97186507Sweongyo s_print(progvers, "%s_%s", 98186507Sweongyo locase(def->def_name), vp->vers_num); 99186507Sweongyo /* print the table header */ 100186507Sweongyo f_print(fout, tbl_hdr, progvers); 101186507Sweongyo 102186507Sweongyo if (nullproc(vp->procs)) { 103186507Sweongyo expected = 0; 104186507Sweongyo } else { 105186507Sweongyo expected = 1; 106186507Sweongyo f_print(fout, null_entry); 107186507Sweongyo } 108186507Sweongyo for (proc = vp->procs; proc != NULL; proc = proc->next) { 109186507Sweongyo current = atoi(proc->proc_num); 110186507Sweongyo if (current != expected++) { 111186507Sweongyo f_print(fout, 112186507Sweongyo "\n/*\n * WARNING: table out of order\n */\n"); 113186507Sweongyo if (warning == 0) { 114186507Sweongyo warnx("WARNING %s table is out of order", progvers); 115186507Sweongyo warning = 1; 116186507Sweongyo nonfatalerrors = 1; 117186507Sweongyo } 118186507Sweongyo expected = current + 1; 119186507Sweongyo } 120186507Sweongyo f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION("); 121186507Sweongyo 122186507Sweongyo /* routine to invoke */ 123189488Sweongyo if( !newstyle ) 124189488Sweongyo pvname_svc(proc->proc_name, vp->vers_num); 125186507Sweongyo else { 126186507Sweongyo if( newstyle ) 127186507Sweongyo f_print( fout, "_"); /* calls internal func */ 128186507Sweongyo pvname(proc->proc_name, vp->vers_num); 129189488Sweongyo } 130189488Sweongyo f_print(fout, "),\n"); 131189488Sweongyo 132186507Sweongyo /* argument info */ 133186507Sweongyo if( proc->arg_num > 1 ) 134189488Sweongyo printit((char*) NULL, proc->args.argname ); 135189488Sweongyo else 136189488Sweongyo /* do we have to do something special for newstyle */ 137189488Sweongyo printit( proc->args.decls->decl.prefix, 138189488Sweongyo proc->args.decls->decl.type ); 139186507Sweongyo /* result info */ 140186507Sweongyo printit(proc->res_prefix, proc->res_type); 141186507Sweongyo } 142186507Sweongyo 143186507Sweongyo /* print the table trailer */ 144186507Sweongyo f_print(fout, tbl_end); 145189488Sweongyo f_print(fout, tbl_nproc, progvers, progvers, progvers); 146189488Sweongyo } 147186507Sweongyo} 148189488Sweongyo 149189488Sweongyostatic void 150189488Sweongyoprintit(const char *prefix, const char *type) 151189488Sweongyo{ 152189488Sweongyo int len; 153186507Sweongyo int tabs; 154186507Sweongyo 155186507Sweongyo 156186507Sweongyo len = fprintf(fout, "\txdr_%s,", stringfix(type)); 157189488Sweongyo /* account for leading tab expansion */ 158189488Sweongyo len += TABSIZE - 1; 159189488Sweongyo /* round up to tabs required */ 160189488Sweongyo tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE; 161189488Sweongyo f_print(fout, "%s", &tabstr[TABCOUNT-tabs]); 162189488Sweongyo 163189488Sweongyo if (streq(type, "void")) { 164189488Sweongyo f_print(fout, "0"); 165189488Sweongyo } else { 166189488Sweongyo f_print(fout, "sizeof ( "); 167189488Sweongyo /* XXX: should "follow" be 1 ??? */ 168189488Sweongyo ptype(prefix, type, 0); 169186507Sweongyo f_print(fout, ")"); 170186507Sweongyo } 171186507Sweongyo f_print(fout, ",\n"); 172186507Sweongyo} 173189488Sweongyo