rpc_tblout.c revision 141614
112795Swpaul/* 212795Swpaul * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 312795Swpaul * unrestricted use provided that this legend is included on all tape 412795Swpaul * media and as a part of the software program in whole or part. Users 512795Swpaul * may copy or modify Sun RPC without charge, but are not authorized 612795Swpaul * to license or distribute it to anyone else except as part of a product or 712795Swpaul * program developed by the user. 8100441Scharnier * 912795Swpaul * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 1012795Swpaul * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR 1112795Swpaul * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 12100441Scharnier * 1312795Swpaul * Sun RPC is provided with no support and without any obligation on the 1412795Swpaul * part of Sun Microsystems, Inc. to assist in its use, correction, 1512795Swpaul * modification or enhancement. 16100441Scharnier * 1712795Swpaul * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 1812795Swpaul * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 1912795Swpaul * OR ANY PART THEREOF. 20100441Scharnier * 2112795Swpaul * In no event will Sun Microsystems, Inc. be liable for any lost revenue 2212795Swpaul * or profits or other special, indirect and consequential damages, even if 2312795Swpaul * Sun has been advised of the possibility of such damages. 24100441Scharnier * 2512795Swpaul * Sun Microsystems, Inc. 2612795Swpaul * 2550 Garcia Avenue 2712795Swpaul * Mountain View, California 94043 2812795Swpaul */ 2912795Swpaul 30100441Scharnier#ident "@(#)rpc_tblout.c 1.11 93/07/05 SMI" 3112795Swpaul 32100441Scharnier#if 0 3312795Swpaul#ifndef lint 3412795Swpaulstatic char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI"; 3512795Swpaul#endif 3627935Scharnier#endif 3712795Swpaul 38100441Scharnier#include <sys/cdefs.h> 39100441Scharnier__FBSDID("$FreeBSD: head/usr.bin/rpcgen/rpc_tblout.c 141614 2005-02-10 10:44:29Z alfred $"); 40100441Scharnier 4112795Swpaul/* 4212795Swpaul * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 4312795Swpaul * Copyright (C) 1989, Sun Microsystems, Inc. 4412795Swpaul */ 4527935Scharnier#include <err.h> 4612795Swpaul#include <stdio.h> 4712795Swpaul#include <string.h> 4812795Swpaul#include "rpc_parse.h" 4912795Swpaul#include "rpc_util.h" 5012795Swpaul 5112795Swpaul#define TABSIZE 8 5212795Swpaul#define TABCOUNT 5 5312795Swpaul#define TABSTOP (TABSIZE*TABCOUNT) 5412795Swpaul 5512795Swpaulstatic char tabstr[TABCOUNT+1] = "\t\t\t\t\t"; 5612795Swpaul 5712795Swpaulstatic char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 58141614Salfredstatic char tbl_end[] = "};\n"; 5912795Swpaul 60141614Salfredstatic char null_entry[] = "\n\t(char *(*)())0,\n\ 6112795Swpaul \t(xdrproc_t) xdr_void,\t\t\t0,\n\ 62141614Salfred \t(xdrproc_t) xdr_void,\t\t\t0,\n"; 6312795Swpaul 6412795Swpaul 6512795Swpaulstatic char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n"; 6612795Swpaul 6792921Simpextern int nullproc( proc_list * ); 6892921Simpstatic void write_table( definition * ); 6992921Simpstatic void printit( char *, char * ); 7012795Swpaul 7112795Swpaulvoid 7212795Swpaulwrite_tables() 7312795Swpaul{ 7412795Swpaul list *l; 7512795Swpaul definition *def; 7612795Swpaul 7712795Swpaul f_print(fout, "\n"); 7812795Swpaul for (l = defined; l != NULL; l = l->next) { 7912795Swpaul def = (definition *) l->val; 8012795Swpaul if (def->def_kind == DEF_PROGRAM) { 8112795Swpaul write_table(def); 8212795Swpaul } 8312795Swpaul } 8412795Swpaul} 8512795Swpaul 8617142Sjkhstatic void 8712795Swpaulwrite_table(def) 8812795Swpaul definition *def; 8912795Swpaul{ 9012795Swpaul version_list *vp; 9112795Swpaul proc_list *proc; 9212795Swpaul int current; 9312795Swpaul int expected; 9412795Swpaul char progvers[100]; 9512795Swpaul int warning; 9612795Swpaul 9712795Swpaul for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 9812795Swpaul warning = 0; 9912795Swpaul s_print(progvers, "%s_%s", 10012795Swpaul locase(def->def_name), vp->vers_num); 10112795Swpaul /* print the table header */ 10212795Swpaul f_print(fout, tbl_hdr, progvers); 10312795Swpaul 10412795Swpaul if (nullproc(vp->procs)) { 10512795Swpaul expected = 0; 10612795Swpaul } else { 10712795Swpaul expected = 1; 10812795Swpaul f_print(fout, null_entry); 10912795Swpaul } 11012795Swpaul for (proc = vp->procs; proc != NULL; proc = proc->next) { 11112795Swpaul current = atoi(proc->proc_num); 11212795Swpaul if (current != expected++) { 11312795Swpaul f_print(fout, 11412795Swpaul "\n/*\n * WARNING: table out of order\n */\n"); 11512795Swpaul if (warning == 0) { 11627935Scharnier warnx("WARNING %s table is out of order", progvers); 11712795Swpaul warning = 1; 11812795Swpaul nonfatalerrors = 1; 11912795Swpaul } 12012795Swpaul expected = current + 1; 12112795Swpaul } 122141614Salfred f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION("); 12312795Swpaul 12412795Swpaul /* routine to invoke */ 12512795Swpaul if( Cflag && !newstyle ) 12612795Swpaul pvname_svc(proc->proc_name, vp->vers_num); 12712795Swpaul else { 12812795Swpaul if( newstyle ) 12912795Swpaul f_print( fout, "_"); /* calls internal func */ 13012795Swpaul pvname(proc->proc_name, vp->vers_num); 13112795Swpaul } 13212795Swpaul f_print(fout, "),\n"); 13312795Swpaul 13412795Swpaul /* argument info */ 13512795Swpaul if( proc->arg_num > 1 ) 13612795Swpaul printit((char*) NULL, proc->args.argname ); 137100441Scharnier else 13812795Swpaul /* do we have to do something special for newstyle */ 13912795Swpaul printit( proc->args.decls->decl.prefix, 14012795Swpaul proc->args.decls->decl.type ); 14112795Swpaul /* result info */ 14212795Swpaul printit(proc->res_prefix, proc->res_type); 14312795Swpaul } 14412795Swpaul 14512795Swpaul /* print the table trailer */ 14612795Swpaul f_print(fout, tbl_end); 14712795Swpaul f_print(fout, tbl_nproc, progvers, progvers, progvers); 14812795Swpaul } 14912795Swpaul} 15012795Swpaul 15117142Sjkhstatic void 15212795Swpaulprintit(prefix, type) 15312795Swpaul char *prefix; 15412795Swpaul char *type; 15512795Swpaul{ 15612795Swpaul int len; 15712795Swpaul int tabs; 15812795Swpaul 15912795Swpaul 160141614Salfred len = fprintf(fout, "\txdr_%s,", stringfix(type)); 16112795Swpaul /* account for leading tab expansion */ 16212795Swpaul len += TABSIZE - 1; 16312795Swpaul /* round up to tabs required */ 16412795Swpaul tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE; 16512795Swpaul f_print(fout, "%s", &tabstr[TABCOUNT-tabs]); 16612795Swpaul 16712795Swpaul if (streq(type, "void")) { 16812795Swpaul f_print(fout, "0"); 16912795Swpaul } else { 170141614Salfred f_print(fout, "sizeof ( "); 17112795Swpaul /* XXX: should "follow" be 1 ??? */ 17212795Swpaul ptype(prefix, type, 0); 17312795Swpaul f_print(fout, ")"); 17412795Swpaul } 17512795Swpaul f_print(fout, ",\n"); 17612795Swpaul} 177