17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*61961e0fSrobinson */ 22*61961e0fSrobinson 23*61961e0fSrobinson /* 24*61961e0fSrobinson * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 317c478bd9Sstevel@tonic-gate * The Regents of the University of California 327c478bd9Sstevel@tonic-gate * All Rights Reserved 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 357c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 367c478bd9Sstevel@tonic-gate * contributors. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * rpc_tblout.c, Dispatch table outputter for the RPC protocol compiler 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate #include <stdio.h> 457c478bd9Sstevel@tonic-gate #include <string.h> 467c478bd9Sstevel@tonic-gate #include "rpc_parse.h" 477c478bd9Sstevel@tonic-gate #include "rpc_util.h" 487c478bd9Sstevel@tonic-gate 49*61961e0fSrobinson extern int nullproc(proc_list *); 50*61961e0fSrobinson 51*61961e0fSrobinson static void write_table(definition *); 52*61961e0fSrobinson static void printit(char *, char *); 53*61961e0fSrobinson 547c478bd9Sstevel@tonic-gate #define TABSIZE 8 557c478bd9Sstevel@tonic-gate #define TABCOUNT 5 567c478bd9Sstevel@tonic-gate #define TABSTOP (TABSIZE*TABCOUNT) 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate static char tabstr[TABCOUNT+1] = "\t\t\t\t\t"; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate static char tbl_hdr[] = "struct rpcgen_table %s_table[] = {\n"; 617c478bd9Sstevel@tonic-gate static char tbl_end[] = "};\n"; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate static char null_entry_b[] = "\n\t(char *(*)())0,\n" 647c478bd9Sstevel@tonic-gate " \t(xdrproc_t)xdr_void,\t\t\t0,\n" 657c478bd9Sstevel@tonic-gate " \t(xdrproc_t)xdr_void,\t\t\t0,\n"; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate static char null_entry[] = "\n\t(void *(*)())0,\n" 687c478bd9Sstevel@tonic-gate " \t(xdrproc_t)xdr_void,\t\t\t0,\n" 697c478bd9Sstevel@tonic-gate " \t(xdrproc_t)xdr_void,\t\t\t0,\n"; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate static char tbl_nproc[] = "int %s_nproc =\n\tsizeof(%s_table)" 737c478bd9Sstevel@tonic-gate "/sizeof(%s_table[0]);\n\n"; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate void 76*61961e0fSrobinson write_tables(void) 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate list *l; 797c478bd9Sstevel@tonic-gate definition *def; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 827c478bd9Sstevel@tonic-gate for (l = defined; l != NULL; l = l->next) { 837c478bd9Sstevel@tonic-gate def = (definition *)l->val; 847c478bd9Sstevel@tonic-gate if (def->def_kind == DEF_PROGRAM) { 857c478bd9Sstevel@tonic-gate write_table(def); 867c478bd9Sstevel@tonic-gate } 877c478bd9Sstevel@tonic-gate } 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 90*61961e0fSrobinson static void 91*61961e0fSrobinson write_table(definition *def) 927c478bd9Sstevel@tonic-gate { 937c478bd9Sstevel@tonic-gate version_list *vp; 947c478bd9Sstevel@tonic-gate proc_list *proc; 957c478bd9Sstevel@tonic-gate int current; 967c478bd9Sstevel@tonic-gate int expected; 977c478bd9Sstevel@tonic-gate char progvers[100]; 987c478bd9Sstevel@tonic-gate int warning; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 1017c478bd9Sstevel@tonic-gate warning = 0; 102*61961e0fSrobinson (void) snprintf(progvers, sizeof (progvers), "%s_%s", 1037c478bd9Sstevel@tonic-gate locase(def->def_name), vp->vers_num); 1047c478bd9Sstevel@tonic-gate /* print the table header */ 1057c478bd9Sstevel@tonic-gate f_print(fout, tbl_hdr, progvers); 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate if (nullproc(vp->procs)) { 1087c478bd9Sstevel@tonic-gate expected = 0; 1097c478bd9Sstevel@tonic-gate } else { 1107c478bd9Sstevel@tonic-gate expected = 1; 1117c478bd9Sstevel@tonic-gate if (tirpcflag) 1127c478bd9Sstevel@tonic-gate f_print(fout, null_entry); 1137c478bd9Sstevel@tonic-gate else 1147c478bd9Sstevel@tonic-gate f_print(fout, null_entry_b); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate for (proc = vp->procs; proc != NULL; proc = proc->next) { 1177c478bd9Sstevel@tonic-gate current = atoi(proc->proc_num); 1187c478bd9Sstevel@tonic-gate if (current != expected++) { 1197c478bd9Sstevel@tonic-gate f_print(fout, 1207c478bd9Sstevel@tonic-gate "\n/*\n * WARNING: table out of order\n */\n"); 1217c478bd9Sstevel@tonic-gate if (warning == 0) { 1227c478bd9Sstevel@tonic-gate f_print(stderr, 1237c478bd9Sstevel@tonic-gate "WARNING %s table is out of order\n", 1247c478bd9Sstevel@tonic-gate progvers); 1257c478bd9Sstevel@tonic-gate warning = 1; 1267c478bd9Sstevel@tonic-gate nonfatalerrors = 1; 1277c478bd9Sstevel@tonic-gate } 1287c478bd9Sstevel@tonic-gate expected = current + 1; 1297c478bd9Sstevel@tonic-gate } 1307c478bd9Sstevel@tonic-gate if (tirpcflag) 1317c478bd9Sstevel@tonic-gate f_print(fout, 1327c478bd9Sstevel@tonic-gate "\n\t(void *(*)())RPCGEN_ACTION("); 1337c478bd9Sstevel@tonic-gate else 1347c478bd9Sstevel@tonic-gate f_print(fout, 1357c478bd9Sstevel@tonic-gate "\n\t(char *(*)())RPCGEN_ACTION("); 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* routine to invoke */ 1387c478bd9Sstevel@tonic-gate if (Cflag && !newstyle) 1397c478bd9Sstevel@tonic-gate pvname_svc(proc->proc_name, vp->vers_num); 1407c478bd9Sstevel@tonic-gate else { 1417c478bd9Sstevel@tonic-gate if (newstyle) /* calls internal func */ 1427c478bd9Sstevel@tonic-gate f_print(fout, "_"); 1437c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate f_print(fout, "),\n"); 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* argument info */ 1487c478bd9Sstevel@tonic-gate if (proc->arg_num > 1) 149*61961e0fSrobinson printit(NULL, proc->args.argname); 1507c478bd9Sstevel@tonic-gate else 1517c478bd9Sstevel@tonic-gate /* do we have to do something special for newstyle */ 1527c478bd9Sstevel@tonic-gate printit(proc->args.decls->decl.prefix, 1537c478bd9Sstevel@tonic-gate proc->args.decls->decl.type); 1547c478bd9Sstevel@tonic-gate /* result info */ 1557c478bd9Sstevel@tonic-gate printit(proc->res_prefix, proc->res_type); 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* print the table trailer */ 1597c478bd9Sstevel@tonic-gate f_print(fout, tbl_end); 1607c478bd9Sstevel@tonic-gate f_print(fout, tbl_nproc, progvers, progvers, progvers); 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate 164*61961e0fSrobinson static void 165*61961e0fSrobinson printit(char *prefix, char *type) 1667c478bd9Sstevel@tonic-gate { 1677c478bd9Sstevel@tonic-gate int len; 1687c478bd9Sstevel@tonic-gate int tabs; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate 171*61961e0fSrobinson if (streq(type, "oneway")) 1727c478bd9Sstevel@tonic-gate len = fprintf(fout, "\t(xdrproc_t)xdr_void,"); 173*61961e0fSrobinson else 1747c478bd9Sstevel@tonic-gate len = fprintf(fout, "\t(xdrproc_t)xdr_%s,", stringfix(type)); 1757c478bd9Sstevel@tonic-gate /* account for leading tab expansion */ 1767c478bd9Sstevel@tonic-gate len += TABSIZE - 1; 1777c478bd9Sstevel@tonic-gate if (len >= TABSTOP) { 1787c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 1797c478bd9Sstevel@tonic-gate len = 0; 1807c478bd9Sstevel@tonic-gate } 1817c478bd9Sstevel@tonic-gate /* round up to tabs required */ 1827c478bd9Sstevel@tonic-gate tabs = (TABSTOP - len + TABSIZE - 1)/TABSIZE; 1837c478bd9Sstevel@tonic-gate f_print(fout, "%s", &tabstr[TABCOUNT-tabs]); 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate if (streq(type, "void") || streq(type, "oneway")) { 1867c478bd9Sstevel@tonic-gate f_print(fout, "0"); 1877c478bd9Sstevel@tonic-gate } else { 1887c478bd9Sstevel@tonic-gate f_print(fout, "sizeof ( "); 1897c478bd9Sstevel@tonic-gate /* XXX: should "follow" be 1 ??? */ 1907c478bd9Sstevel@tonic-gate ptype(prefix, type, 0); 1917c478bd9Sstevel@tonic-gate f_print(fout, ")"); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate f_print(fout, ",\n"); 1947c478bd9Sstevel@tonic-gate } 195