rpc_tblout.c revision 50477
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. 812795Swpaul * 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. 1212795Swpaul * 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. 1612795Swpaul * 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. 2012795Swpaul * 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. 2412795Swpaul * 2512795Swpaul * Sun Microsystems, Inc. 2612795Swpaul * 2550 Garcia Avenue 2712795Swpaul * Mountain View, California 94043 2812795Swpaul */ 2912795Swpaul 3012795Swpaul#ident "@(#)rpc_tblout.c 1.11 93/07/05 SMI" 3112795Swpaul 3212795Swpaul#ifndef lint 3327935Scharnier#if 0 3412795Swpaulstatic char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI"; 3512795Swpaul#endif 3627935Scharnierstatic const char rcsid[] = 3750477Speter "$FreeBSD: head/usr.bin/rpcgen/rpc_tblout.c 50477 1999-08-28 01:08:13Z peter $"; 3827935Scharnier#endif 3912795Swpaul 4012795Swpaul/* 4112795Swpaul * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 4212795Swpaul * Copyright (C) 1989, Sun Microsystems, Inc. 4312795Swpaul */ 4427935Scharnier#include <err.h> 4512795Swpaul#include <stdio.h> 4612795Swpaul#include <string.h> 4712795Swpaul#include "rpc_parse.h" 4812795Swpaul#include "rpc_util.h" 4912795Swpaul 5012795Swpaul#define TABSIZE 8 5112795Swpaul#define TABCOUNT 5 5212795Swpaul#define TABSTOP (TABSIZE*TABCOUNT) 5312795Swpaul 5412795Swpaulstatic char tabstr[TABCOUNT+1] = "\t\t\t\t\t"; 5512795Swpaul 5612795Swpaulstatic char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 5712795Swpaulstatic char tbl_end[] = "};\n"; 5812795Swpaul 5912795Swpaulstatic char null_entry[] = "\n\t(char *(*)())0,\n\ 6012795Swpaul \t(xdrproc_t) xdr_void,\t\t\t0,\n\ 6112795Swpaul \t(xdrproc_t) xdr_void,\t\t\t0,\n"; 6212795Swpaul 6312795Swpaul 6412795Swpaulstatic char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n"; 6512795Swpaul 6617142Sjkhextern int nullproc __P(( proc_list * )); 6717142Sjkhstatic void write_table __P(( definition * )); 6817142Sjkhstatic void printit __P(( char *, char * )); 6912795Swpaul 7012795Swpaulvoid 7112795Swpaulwrite_tables() 7212795Swpaul{ 7312795Swpaul list *l; 7412795Swpaul definition *def; 7512795Swpaul 7612795Swpaul f_print(fout, "\n"); 7712795Swpaul for (l = defined; l != NULL; l = l->next) { 7812795Swpaul def = (definition *) l->val; 7912795Swpaul if (def->def_kind == DEF_PROGRAM) { 8012795Swpaul write_table(def); 8112795Swpaul } 8212795Swpaul } 8312795Swpaul} 8412795Swpaul 8517142Sjkhstatic void 8612795Swpaulwrite_table(def) 8712795Swpaul definition *def; 8812795Swpaul{ 8912795Swpaul version_list *vp; 9012795Swpaul proc_list *proc; 9112795Swpaul int current; 9212795Swpaul int expected; 9312795Swpaul char progvers[100]; 9412795Swpaul int warning; 9512795Swpaul 9612795Swpaul for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 9712795Swpaul warning = 0; 9812795Swpaul s_print(progvers, "%s_%s", 9912795Swpaul locase(def->def_name), vp->vers_num); 10012795Swpaul /* print the table header */ 10112795Swpaul f_print(fout, tbl_hdr, progvers); 10212795Swpaul 10312795Swpaul if (nullproc(vp->procs)) { 10412795Swpaul expected = 0; 10512795Swpaul } else { 10612795Swpaul expected = 1; 10712795Swpaul f_print(fout, null_entry); 10812795Swpaul } 10912795Swpaul for (proc = vp->procs; proc != NULL; proc = proc->next) { 11012795Swpaul current = atoi(proc->proc_num); 11112795Swpaul if (current != expected++) { 11212795Swpaul f_print(fout, 11312795Swpaul "\n/*\n * WARNING: table out of order\n */\n"); 11412795Swpaul if (warning == 0) { 11527935Scharnier warnx("WARNING %s table is out of order", progvers); 11612795Swpaul warning = 1; 11712795Swpaul nonfatalerrors = 1; 11812795Swpaul } 11912795Swpaul expected = current + 1; 12012795Swpaul } 12112795Swpaul f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION("); 12212795Swpaul 12312795Swpaul /* routine to invoke */ 12412795Swpaul if( Cflag && !newstyle ) 12512795Swpaul pvname_svc(proc->proc_name, vp->vers_num); 12612795Swpaul else { 12712795Swpaul if( newstyle ) 12812795Swpaul f_print( fout, "_"); /* calls internal func */ 12912795Swpaul pvname(proc->proc_name, vp->vers_num); 13012795Swpaul } 13112795Swpaul f_print(fout, "),\n"); 13212795Swpaul 13312795Swpaul /* argument info */ 13412795Swpaul if( proc->arg_num > 1 ) 13512795Swpaul printit((char*) NULL, proc->args.argname ); 13612795Swpaul else 13712795Swpaul /* do we have to do something special for newstyle */ 13812795Swpaul printit( proc->args.decls->decl.prefix, 13912795Swpaul proc->args.decls->decl.type ); 14012795Swpaul /* result info */ 14112795Swpaul printit(proc->res_prefix, proc->res_type); 14212795Swpaul } 14312795Swpaul 14412795Swpaul /* print the table trailer */ 14512795Swpaul f_print(fout, tbl_end); 14612795Swpaul f_print(fout, tbl_nproc, progvers, progvers, progvers); 14712795Swpaul } 14812795Swpaul} 14912795Swpaul 15017142Sjkhstatic void 15112795Swpaulprintit(prefix, type) 15212795Swpaul char *prefix; 15312795Swpaul char *type; 15412795Swpaul{ 15512795Swpaul int len; 15612795Swpaul int tabs; 15712795Swpaul 15812795Swpaul 15912795Swpaul len = fprintf(fout, "\txdr_%s,", stringfix(type)); 16012795Swpaul /* account for leading tab expansion */ 16112795Swpaul len += TABSIZE - 1; 16212795Swpaul /* round up to tabs required */ 16312795Swpaul tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE; 16412795Swpaul f_print(fout, "%s", &tabstr[TABCOUNT-tabs]); 16512795Swpaul 16612795Swpaul if (streq(type, "void")) { 16712795Swpaul f_print(fout, "0"); 16812795Swpaul } else { 16912795Swpaul f_print(fout, "sizeof ( "); 17012795Swpaul /* XXX: should "follow" be 1 ??? */ 17112795Swpaul ptype(prefix, type, 0); 17212795Swpaul f_print(fout, ")"); 17312795Swpaul } 17412795Swpaul f_print(fout, ",\n"); 17512795Swpaul} 176