1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 * 22 * Copyright 2001 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 26 /* All Rights Reserved */ 27 /* 28 * University Copyright- Copyright (c) 1982, 1986, 1988 29 * The Regents of the University of California 30 * All Rights Reserved 31 * 32 * University Acknowledgment- Portions of this document are derived from 33 * software developed by the University of California, Berkeley, and its 34 * contributors. 35 */ 36 37 #pragma ident "%Z%%M% %I% %E% SMI" 38 39 /* 40 * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 41 */ 42 #include <stdio.h> 43 #include <string.h> 44 #include "rpc_parse.h" 45 #include "rpc_util.h" 46 47 #define TABSIZE 8 48 #define TABCOUNT 5 49 #define TABSTOP (TABSIZE*TABCOUNT) 50 51 static char tabstr[TABCOUNT+1] = "\t\t\t\t\t"; 52 53 static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 54 static char tbl_end[] = "};\n"; 55 56 static char null_entry_b[] = "\n\t(char *(*)())0,\n" 57 " \t(xdrproc_t) xdr_void,\t\t\t0,\n" 58 " \t(xdrproc_t) xdr_void,\t\t\t0,\n"; 59 60 static char null_entry[] = "\n\t(void *(*)())0,\n" 61 " \t(xdrproc_t) xdr_void,\t\t\t0,\n" 62 " \t(xdrproc_t) xdr_void,\t\t\t0,\n"; 63 64 65 static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)" 66 "/sizeof(%s_table[0]);\n\n"; 67 68 void 69 write_tables() 70 { 71 list *l; 72 definition *def; 73 74 f_print(fout, "\n"); 75 for (l = defined; l != NULL; l = l->next) { 76 def = (definition *) l->val; 77 if (def->def_kind == DEF_PROGRAM) { 78 write_table(def); 79 } 80 } 81 } 82 83 static 84 write_table(def) 85 definition *def; 86 { 87 version_list *vp; 88 proc_list *proc; 89 int current; 90 int expected; 91 char progvers[100]; 92 int warning; 93 94 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 95 warning = 0; 96 s_print(progvers, "%s_%s", 97 locase(def->def_name), vp->vers_num); 98 /* print the table header */ 99 f_print(fout, tbl_hdr, progvers); 100 101 if (nullproc(vp->procs)) { 102 expected = 0; 103 } else { 104 expected = 1; 105 if (tirpcflag) 106 f_print(fout, null_entry); 107 else 108 f_print(fout, null_entry_b); 109 } 110 for (proc = vp->procs; proc != NULL; proc = proc->next) { 111 current = atoi(proc->proc_num); 112 if (current != expected++) { 113 f_print(fout, 114 "\n/*\n * WARNING: table out of order\n */\n"); 115 if (warning == 0) { 116 f_print(stderr, 117 "WARNING %s table is out of order\n", 118 progvers); 119 warning = 1; 120 nonfatalerrors = 1; 121 } 122 expected = current + 1; 123 } 124 if (tirpcflag) 125 f_print(fout, 126 "\n\t(void *(*)())RPCGEN_ACTION("); 127 else 128 f_print(fout, 129 "\n\t(char *(*)())RPCGEN_ACTION("); 130 131 /* routine to invoke */ 132 if (Cflag && !newstyle) 133 pvname_svc(proc->proc_name, vp->vers_num); 134 else { 135 if (newstyle) /* calls internal func */ 136 f_print(fout, "_"); 137 pvname(proc->proc_name, vp->vers_num); 138 } 139 f_print(fout, "),\n"); 140 141 /* argument info */ 142 if (proc->arg_num > 1) 143 printit((char *) NULL, proc->args.argname); 144 else 145 /* do we have to do something special for newstyle */ 146 printit(proc->args.decls->decl.prefix, 147 proc->args.decls->decl.type); 148 /* result info */ 149 printit(proc->res_prefix, proc->res_type); 150 } 151 152 /* print the table trailer */ 153 f_print(fout, tbl_end); 154 f_print(fout, tbl_nproc, progvers, progvers, progvers); 155 } 156 } 157 158 static 159 printit(prefix, type) 160 char *prefix; 161 char *type; 162 { 163 int len; 164 int tabs; 165 166 167 if (streq(type, "oneway")) { 168 len = fprintf(fout, "\t(xdrproc_t) xdr_void,"); 169 } else { 170 len = fprintf(fout, "\t(xdrproc_t) xdr_%s,", stringfix(type)); 171 } 172 /* account for leading tab expansion */ 173 len += TABSIZE - 1; 174 if (len >= TABSTOP) { 175 f_print(fout, "\n"); 176 len = 0; 177 } 178 /* round up to tabs required */ 179 tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE; 180 f_print(fout, "%s", &tabstr[TABCOUNT-tabs]); 181 182 if (streq(type, "void") || streq(type, "oneway")) { 183 f_print(fout, "0"); 184 } else { 185 f_print(fout, "sizeof ( "); 186 /* XXX: should "follow" be 1 ??? */ 187 ptype(prefix, type, 0); 188 f_print(fout, ")"); 189 } 190 f_print(fout, ",\n"); 191 } 192