rpc_tblout.c revision 12795
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 3312795Swpaulstatic char sccsid[] = "@(#)rpc_tblout.c 1.4 89/02/22 (C) 1988 SMI"; 3412795Swpaul#endif 3512795Swpaul 3612795Swpaul/* 3712795Swpaul * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 3812795Swpaul * Copyright (C) 1989, Sun Microsystems, Inc. 3912795Swpaul */ 4012795Swpaul#include <stdio.h> 4112795Swpaul#include <string.h> 4212795Swpaul#include "rpc_parse.h" 4312795Swpaul#include "rpc_util.h" 4412795Swpaul 4512795Swpaul#define TABSIZE 8 4612795Swpaul#define TABCOUNT 5 4712795Swpaul#define TABSTOP (TABSIZE*TABCOUNT) 4812795Swpaul 4912795Swpaulstatic char tabstr[TABCOUNT+1] = "\t\t\t\t\t"; 5012795Swpaul 5112795Swpaulstatic char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 5212795Swpaulstatic char tbl_end[] = "};\n"; 5312795Swpaul 5412795Swpaulstatic char null_entry[] = "\n\t(char *(*)())0,\n\ 5512795Swpaul \t(xdrproc_t) xdr_void,\t\t\t0,\n\ 5612795Swpaul \t(xdrproc_t) xdr_void,\t\t\t0,\n"; 5712795Swpaul 5812795Swpaul 5912795Swpaulstatic char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)/sizeof(%s_table[0]);\n\n"; 6012795Swpaul 6112795Swpaulstatic int write_table __P(( definition * )); 6212795Swpaulstatic int printit __P(( char *, char * )); 6312795Swpaul 6412795Swpaulvoid 6512795Swpaulwrite_tables() 6612795Swpaul{ 6712795Swpaul list *l; 6812795Swpaul definition *def; 6912795Swpaul 7012795Swpaul f_print(fout, "\n"); 7112795Swpaul for (l = defined; l != NULL; l = l->next) { 7212795Swpaul def = (definition *) l->val; 7312795Swpaul if (def->def_kind == DEF_PROGRAM) { 7412795Swpaul write_table(def); 7512795Swpaul } 7612795Swpaul } 7712795Swpaul} 7812795Swpaul 7912795Swpaulstatic 8012795Swpaulwrite_table(def) 8112795Swpaul definition *def; 8212795Swpaul{ 8312795Swpaul version_list *vp; 8412795Swpaul proc_list *proc; 8512795Swpaul int current; 8612795Swpaul int expected; 8712795Swpaul char progvers[100]; 8812795Swpaul int warning; 8912795Swpaul 9012795Swpaul for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 9112795Swpaul warning = 0; 9212795Swpaul s_print(progvers, "%s_%s", 9312795Swpaul locase(def->def_name), vp->vers_num); 9412795Swpaul /* print the table header */ 9512795Swpaul f_print(fout, tbl_hdr, progvers); 9612795Swpaul 9712795Swpaul if (nullproc(vp->procs)) { 9812795Swpaul expected = 0; 9912795Swpaul } else { 10012795Swpaul expected = 1; 10112795Swpaul f_print(fout, null_entry); 10212795Swpaul } 10312795Swpaul for (proc = vp->procs; proc != NULL; proc = proc->next) { 10412795Swpaul current = atoi(proc->proc_num); 10512795Swpaul if (current != expected++) { 10612795Swpaul f_print(fout, 10712795Swpaul "\n/*\n * WARNING: table out of order\n */\n"); 10812795Swpaul if (warning == 0) { 10912795Swpaul f_print(stderr, 11012795Swpaul "WARNING %s table is out of order\n", 11112795Swpaul progvers); 11212795Swpaul warning = 1; 11312795Swpaul nonfatalerrors = 1; 11412795Swpaul } 11512795Swpaul expected = current + 1; 11612795Swpaul } 11712795Swpaul f_print(fout, "\n\t(char *(*)())RPCGEN_ACTION("); 11812795Swpaul 11912795Swpaul /* routine to invoke */ 12012795Swpaul if( Cflag && !newstyle ) 12112795Swpaul pvname_svc(proc->proc_name, vp->vers_num); 12212795Swpaul else { 12312795Swpaul if( newstyle ) 12412795Swpaul f_print( fout, "_"); /* calls internal func */ 12512795Swpaul pvname(proc->proc_name, vp->vers_num); 12612795Swpaul } 12712795Swpaul f_print(fout, "),\n"); 12812795Swpaul 12912795Swpaul /* argument info */ 13012795Swpaul if( proc->arg_num > 1 ) 13112795Swpaul printit((char*) NULL, proc->args.argname ); 13212795Swpaul else 13312795Swpaul /* do we have to do something special for newstyle */ 13412795Swpaul printit( proc->args.decls->decl.prefix, 13512795Swpaul proc->args.decls->decl.type ); 13612795Swpaul /* result info */ 13712795Swpaul printit(proc->res_prefix, proc->res_type); 13812795Swpaul } 13912795Swpaul 14012795Swpaul /* print the table trailer */ 14112795Swpaul f_print(fout, tbl_end); 14212795Swpaul f_print(fout, tbl_nproc, progvers, progvers, progvers); 14312795Swpaul } 14412795Swpaul} 14512795Swpaul 14612795Swpaulstatic 14712795Swpaulprintit(prefix, type) 14812795Swpaul char *prefix; 14912795Swpaul char *type; 15012795Swpaul{ 15112795Swpaul int len; 15212795Swpaul int tabs; 15312795Swpaul 15412795Swpaul 15512795Swpaul len = fprintf(fout, "\txdr_%s,", stringfix(type)); 15612795Swpaul /* account for leading tab expansion */ 15712795Swpaul len += TABSIZE - 1; 15812795Swpaul /* round up to tabs required */ 15912795Swpaul tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE; 16012795Swpaul f_print(fout, "%s", &tabstr[TABCOUNT-tabs]); 16112795Swpaul 16212795Swpaul if (streq(type, "void")) { 16312795Swpaul f_print(fout, "0"); 16412795Swpaul } else { 16512795Swpaul f_print(fout, "sizeof ( "); 16612795Swpaul /* XXX: should "follow" be 1 ??? */ 16712795Swpaul ptype(prefix, type, 0); 16812795Swpaul f_print(fout, ")"); 16912795Swpaul } 17012795Swpaul f_print(fout, ",\n"); 17112795Swpaul} 172