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 5*a2f144d1SJordan Brown * Common Development and Distribution License (the "License"). 6*a2f144d1SJordan Brown * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 2061961e0fSrobinson */ 2161961e0fSrobinson 2261961e0fSrobinson /* 23*a2f144d1SJordan Brown * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 307c478bd9Sstevel@tonic-gate * The Regents of the University of California 317c478bd9Sstevel@tonic-gate * All Rights Reserved 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 347c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 357c478bd9Sstevel@tonic-gate * contributors. 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * rpc_hout.c, Header file outputter for the RPC protocol compiler 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate #include <stdio.h> 4261961e0fSrobinson #include <stdlib.h> 437c478bd9Sstevel@tonic-gate #include <ctype.h> 447c478bd9Sstevel@tonic-gate #include "rpc_parse.h" 457c478bd9Sstevel@tonic-gate #include "rpc_util.h" 467c478bd9Sstevel@tonic-gate 4761961e0fSrobinson extern void pprocdef(proc_list *, version_list *, char *, int, int); 4861961e0fSrobinson extern void pdeclaration(char *, declaration *, int, char *); 497c478bd9Sstevel@tonic-gate 5061961e0fSrobinson static void storexdrfuncdecl(char *, int); 5161961e0fSrobinson static void pconstdef(definition *); 5261961e0fSrobinson static void pstructdef(definition *); 5361961e0fSrobinson static void puniondef(definition *); 5461961e0fSrobinson static void pdefine(char *, char *); 5561961e0fSrobinson static void pprogramdef(definition *); 5661961e0fSrobinson static void parglist(proc_list *, char *); 5761961e0fSrobinson static void penumdef(definition *); 5861961e0fSrobinson static void ptypedef(definition *); 5961961e0fSrobinson static uint_t undefined2(char *, char *); 607c478bd9Sstevel@tonic-gate 6161961e0fSrobinson enum rpc_gvc { 627c478bd9Sstevel@tonic-gate PROGRAM, 637c478bd9Sstevel@tonic-gate VERSION, 647c478bd9Sstevel@tonic-gate PROCEDURE 657c478bd9Sstevel@tonic-gate }; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * Print the C-version of an xdr definition 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate void 7161961e0fSrobinson print_datadef(definition *def) 727c478bd9Sstevel@tonic-gate { 737c478bd9Sstevel@tonic-gate if (def->def_kind == DEF_PROGRAM) /* handle data only */ 747c478bd9Sstevel@tonic-gate return; 757c478bd9Sstevel@tonic-gate 7661961e0fSrobinson if (def->def_kind != DEF_CONST) 777c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 787c478bd9Sstevel@tonic-gate switch (def->def_kind) { 797c478bd9Sstevel@tonic-gate case DEF_STRUCT: 807c478bd9Sstevel@tonic-gate pstructdef(def); 817c478bd9Sstevel@tonic-gate break; 827c478bd9Sstevel@tonic-gate case DEF_UNION: 837c478bd9Sstevel@tonic-gate puniondef(def); 847c478bd9Sstevel@tonic-gate break; 857c478bd9Sstevel@tonic-gate case DEF_ENUM: 867c478bd9Sstevel@tonic-gate penumdef(def); 877c478bd9Sstevel@tonic-gate break; 887c478bd9Sstevel@tonic-gate case DEF_TYPEDEF: 897c478bd9Sstevel@tonic-gate ptypedef(def); 907c478bd9Sstevel@tonic-gate break; 917c478bd9Sstevel@tonic-gate case DEF_PROGRAM: 927c478bd9Sstevel@tonic-gate pprogramdef(def); 937c478bd9Sstevel@tonic-gate break; 947c478bd9Sstevel@tonic-gate case DEF_CONST: 957c478bd9Sstevel@tonic-gate pconstdef(def); 967c478bd9Sstevel@tonic-gate break; 977c478bd9Sstevel@tonic-gate } 9861961e0fSrobinson if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST) 997c478bd9Sstevel@tonic-gate storexdrfuncdecl(def->def_name, def->def_kind != DEF_TYPEDEF || 1007c478bd9Sstevel@tonic-gate !isvectordef(def->def.ty.old_type, def->def.ty.rel)); 1017c478bd9Sstevel@tonic-gate } 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate void 1057c478bd9Sstevel@tonic-gate print_funcdef(definition *def) 1067c478bd9Sstevel@tonic-gate { 1077c478bd9Sstevel@tonic-gate switch (def->def_kind) { 1087c478bd9Sstevel@tonic-gate case DEF_PROGRAM: 1097c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 1107c478bd9Sstevel@tonic-gate pprogramdef(def); 1117c478bd9Sstevel@tonic-gate break; 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate } 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * store away enough information to allow the XDR functions to be spat 1177c478bd9Sstevel@tonic-gate * out at the end of the file 1187c478bd9Sstevel@tonic-gate */ 11961961e0fSrobinson static void 1207c478bd9Sstevel@tonic-gate storexdrfuncdecl(char *name, int pointerp) 1217c478bd9Sstevel@tonic-gate { 1227c478bd9Sstevel@tonic-gate xdrfunc *xdrptr; 1237c478bd9Sstevel@tonic-gate 12461961e0fSrobinson xdrptr = malloc(sizeof (struct xdrfunc)); 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate xdrptr->name = name; 1277c478bd9Sstevel@tonic-gate xdrptr->pointerp = pointerp; 1287c478bd9Sstevel@tonic-gate xdrptr->next = NULL; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate if (xdrfunc_tail == NULL) { 1317c478bd9Sstevel@tonic-gate xdrfunc_head = xdrptr; 1327c478bd9Sstevel@tonic-gate xdrfunc_tail = xdrptr; 1337c478bd9Sstevel@tonic-gate } else { 1347c478bd9Sstevel@tonic-gate xdrfunc_tail->next = xdrptr; 1357c478bd9Sstevel@tonic-gate xdrfunc_tail = xdrptr; 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate } 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate void 1427c478bd9Sstevel@tonic-gate print_xdr_func_def(char *name, int pointerp, int i) 1437c478bd9Sstevel@tonic-gate { 1447c478bd9Sstevel@tonic-gate if (i == 2) 1457c478bd9Sstevel@tonic-gate f_print(fout, "extern bool_t xdr_%s();\n", name); 1467c478bd9Sstevel@tonic-gate else 1477c478bd9Sstevel@tonic-gate f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name, 1487c478bd9Sstevel@tonic-gate name, pointerp ? "*" : ""); 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate 15261961e0fSrobinson static void 1537c478bd9Sstevel@tonic-gate pconstdef(definition *def) 1547c478bd9Sstevel@tonic-gate { 1557c478bd9Sstevel@tonic-gate pdefine(def->def_name, def->def.co); 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* 1597c478bd9Sstevel@tonic-gate * print out the definitions for the arguments of functions in the 1607c478bd9Sstevel@tonic-gate * header file 1617c478bd9Sstevel@tonic-gate */ 16261961e0fSrobinson static void 1637c478bd9Sstevel@tonic-gate pargdef(definition *def) 1647c478bd9Sstevel@tonic-gate { 1657c478bd9Sstevel@tonic-gate decl_list *l; 1667c478bd9Sstevel@tonic-gate version_list *vers; 1677c478bd9Sstevel@tonic-gate char *name; 1687c478bd9Sstevel@tonic-gate proc_list *plist; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { 17161961e0fSrobinson for (plist = vers->procs; plist != NULL; plist = plist->next) { 17261961e0fSrobinson if (!newstyle || plist->arg_num < 2) 1737c478bd9Sstevel@tonic-gate continue; /* old style or single args */ 1747c478bd9Sstevel@tonic-gate name = plist->args.argname; 1757c478bd9Sstevel@tonic-gate f_print(fout, "struct %s {\n", name); 17661961e0fSrobinson for (l = plist->args.decls; l != NULL; l = l->next) 1777c478bd9Sstevel@tonic-gate pdeclaration(name, &l->decl, 1, ";\n"); 1787c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 17961961e0fSrobinson f_print(fout, "typedef struct %s %s;\n", name, name); 1807c478bd9Sstevel@tonic-gate storexdrfuncdecl(name, 1); 1817c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate 18761961e0fSrobinson static void 18861961e0fSrobinson pstructdef(definition *def) 1897c478bd9Sstevel@tonic-gate { 1907c478bd9Sstevel@tonic-gate decl_list *l; 1917c478bd9Sstevel@tonic-gate char *name = def->def_name; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate f_print(fout, "struct %s {\n", name); 19461961e0fSrobinson for (l = def->def.st.decls; l != NULL; l = l->next) 1957c478bd9Sstevel@tonic-gate pdeclaration(name, &l->decl, 1, ";\n"); 1967c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 1977c478bd9Sstevel@tonic-gate f_print(fout, "typedef struct %s %s;\n", name, name); 1987c478bd9Sstevel@tonic-gate } 1997c478bd9Sstevel@tonic-gate 20061961e0fSrobinson static void 20161961e0fSrobinson puniondef(definition *def) 2027c478bd9Sstevel@tonic-gate { 2037c478bd9Sstevel@tonic-gate case_list *l; 2047c478bd9Sstevel@tonic-gate char *name = def->def_name; 2057c478bd9Sstevel@tonic-gate declaration *decl; 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate f_print(fout, "struct %s {\n", name); 2087c478bd9Sstevel@tonic-gate decl = &def->def.un.enum_decl; 20961961e0fSrobinson if (streq(decl->type, "bool")) 2107c478bd9Sstevel@tonic-gate f_print(fout, "\tbool_t %s;\n", decl->name); 21161961e0fSrobinson else 2127c478bd9Sstevel@tonic-gate f_print(fout, "\t%s %s;\n", decl->type, decl->name); 2137c478bd9Sstevel@tonic-gate f_print(fout, "\tunion {\n"); 2147c478bd9Sstevel@tonic-gate for (l = def->def.un.cases; l != NULL; l = l->next) { 2157c478bd9Sstevel@tonic-gate if (l->contflag == 0) 2167c478bd9Sstevel@tonic-gate pdeclaration(name, &l->case_decl, 2, ";\n"); 2177c478bd9Sstevel@tonic-gate } 2187c478bd9Sstevel@tonic-gate decl = def->def.un.default_decl; 21961961e0fSrobinson if (decl && !streq(decl->type, "void")) 2207c478bd9Sstevel@tonic-gate pdeclaration(name, decl, 2, ";\n"); 2217c478bd9Sstevel@tonic-gate f_print(fout, "\t} %s_u;\n", name); 2227c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 2237c478bd9Sstevel@tonic-gate f_print(fout, "typedef struct %s %s;\n", name, name); 2247c478bd9Sstevel@tonic-gate } 2257c478bd9Sstevel@tonic-gate 22661961e0fSrobinson static void 22761961e0fSrobinson pdefine(char *name, char *num) 2287c478bd9Sstevel@tonic-gate { 2297c478bd9Sstevel@tonic-gate f_print(fout, "#define\t%s %s\n", name, num); 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate 23261961e0fSrobinson static void 2337c478bd9Sstevel@tonic-gate puldefine(char *name, char *num, enum rpc_gvc which) 2347c478bd9Sstevel@tonic-gate { 2357c478bd9Sstevel@tonic-gate switch (which) { 2367c478bd9Sstevel@tonic-gate case PROGRAM: 2377c478bd9Sstevel@tonic-gate case VERSION: 2387c478bd9Sstevel@tonic-gate case PROCEDURE: 2397c478bd9Sstevel@tonic-gate f_print(fout, "#define\t%s\t%s\n", name, num); 2407c478bd9Sstevel@tonic-gate break; 2417c478bd9Sstevel@tonic-gate default: 2427c478bd9Sstevel@tonic-gate break; 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate 24661961e0fSrobinson static uint_t 2477c478bd9Sstevel@tonic-gate define_printed(proc_list *stop, version_list *start) 2487c478bd9Sstevel@tonic-gate { 2497c478bd9Sstevel@tonic-gate version_list *vers; 2507c478bd9Sstevel@tonic-gate proc_list *proc; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate for (vers = start; vers != NULL; vers = vers->next) { 2537c478bd9Sstevel@tonic-gate for (proc = vers->procs; proc != NULL; proc = proc->next) { 25461961e0fSrobinson if (proc == stop) 2557c478bd9Sstevel@tonic-gate return (0); 25661961e0fSrobinson if (streq(proc->proc_name, stop->proc_name)) 2577c478bd9Sstevel@tonic-gate return (1); 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate abort(); 2617c478bd9Sstevel@tonic-gate /* NOTREACHED */ 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate 26461961e0fSrobinson static void 2657c478bd9Sstevel@tonic-gate pfreeprocdef(char *name, char *vers, int mode) 2667c478bd9Sstevel@tonic-gate { 2677c478bd9Sstevel@tonic-gate f_print(fout, "extern int "); 2687c478bd9Sstevel@tonic-gate pvname(name, vers); 2697c478bd9Sstevel@tonic-gate if (mode == 1) 2707c478bd9Sstevel@tonic-gate f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n"); 2717c478bd9Sstevel@tonic-gate else 2727c478bd9Sstevel@tonic-gate f_print(fout, "_freeresult();\n"); 2737c478bd9Sstevel@tonic-gate } 2747c478bd9Sstevel@tonic-gate 27561961e0fSrobinson static void 27661961e0fSrobinson pprogramdef(definition *def) 2777c478bd9Sstevel@tonic-gate { 2787c478bd9Sstevel@tonic-gate version_list *vers; 2797c478bd9Sstevel@tonic-gate proc_list *proc; 2807c478bd9Sstevel@tonic-gate int i; 2817c478bd9Sstevel@tonic-gate char *ext; 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate pargdef(def); 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate puldefine(def->def_name, def->def.pr.prog_num, PROGRAM); 2867c478bd9Sstevel@tonic-gate for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) { 2877c478bd9Sstevel@tonic-gate if (tblflag) { 2887c478bd9Sstevel@tonic-gate f_print(fout, 2897c478bd9Sstevel@tonic-gate "extern struct rpcgen_table %s_%s_table[];\n", 2907c478bd9Sstevel@tonic-gate locase(def->def_name), vers->vers_num); 2917c478bd9Sstevel@tonic-gate f_print(fout, 29261961e0fSrobinson "extern int %s_%s_nproc;\n", 2937c478bd9Sstevel@tonic-gate locase(def->def_name), vers->vers_num); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate puldefine(vers->vers_name, vers->vers_num, VERSION); 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate /* 2987c478bd9Sstevel@tonic-gate * Print out 2 definitions, one for ANSI-C, another for 2997c478bd9Sstevel@tonic-gate * old K & R C 3007c478bd9Sstevel@tonic-gate */ 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate if (!Cflag) { 3037c478bd9Sstevel@tonic-gate ext = "extern "; 3047c478bd9Sstevel@tonic-gate for (proc = vers->procs; proc != NULL; 3057c478bd9Sstevel@tonic-gate proc = proc->next) { 30661961e0fSrobinson if (!define_printed(proc, def->def.pr.versions)) 3077c478bd9Sstevel@tonic-gate puldefine(proc->proc_name, 3087c478bd9Sstevel@tonic-gate proc->proc_num, PROCEDURE); 3097c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 3107c478bd9Sstevel@tonic-gate pprocdef(proc, vers, NULL, 0, 2); 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate if (mtflag) { 3137c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 3147c478bd9Sstevel@tonic-gate pprocdef(proc, vers, NULL, 1, 2); 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate pfreeprocdef(def->def_name, vers->vers_num, 2); 3187c478bd9Sstevel@tonic-gate } else { 3197c478bd9Sstevel@tonic-gate for (i = 1; i < 3; i++) { 3207c478bd9Sstevel@tonic-gate if (i == 1) { 3217c478bd9Sstevel@tonic-gate f_print(fout, "\n#if defined(__STDC__)" 3227c478bd9Sstevel@tonic-gate " || defined(__cplusplus)\n"); 3237c478bd9Sstevel@tonic-gate ext = "extern "; 3247c478bd9Sstevel@tonic-gate } else { 3257c478bd9Sstevel@tonic-gate f_print(fout, "\n#else /* K&R C */\n"); 3267c478bd9Sstevel@tonic-gate ext = "extern "; 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate for (proc = vers->procs; proc != NULL; 3307c478bd9Sstevel@tonic-gate proc = proc->next) { 3317c478bd9Sstevel@tonic-gate if (!define_printed(proc, 3327c478bd9Sstevel@tonic-gate def->def.pr.versions)) { 3337c478bd9Sstevel@tonic-gate puldefine(proc->proc_name, 3347c478bd9Sstevel@tonic-gate proc->proc_num, PROCEDURE); 3357c478bd9Sstevel@tonic-gate } 3367c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 3377c478bd9Sstevel@tonic-gate pprocdef(proc, vers, "CLIENT *", 0, i); 3387c478bd9Sstevel@tonic-gate f_print(fout, "%s", ext); 3397c478bd9Sstevel@tonic-gate pprocdef(proc, vers, 3407c478bd9Sstevel@tonic-gate "struct svc_req *", 1, i); 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate pfreeprocdef(def->def_name, vers->vers_num, i); 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate f_print(fout, "#endif /* K&R C */\n"); 3457c478bd9Sstevel@tonic-gate } 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate } 3487c478bd9Sstevel@tonic-gate 34961961e0fSrobinson void 35061961e0fSrobinson pprocdef(proc_list *proc, version_list *vp, char *addargtype, int server_p, 35161961e0fSrobinson int mode) 3527c478bd9Sstevel@tonic-gate { 3537c478bd9Sstevel@tonic-gate if (mtflag) { 3547c478bd9Sstevel@tonic-gate /* Print MT style stubs */ 3557c478bd9Sstevel@tonic-gate if (server_p) 3567c478bd9Sstevel@tonic-gate f_print(fout, "bool_t "); 3577c478bd9Sstevel@tonic-gate else 3587c478bd9Sstevel@tonic-gate f_print(fout, "enum clnt_stat "); 3597c478bd9Sstevel@tonic-gate } else { 3607c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 3617c478bd9Sstevel@tonic-gate f_print(fout, "* "); 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate if (server_p) 3647c478bd9Sstevel@tonic-gate pvname_svc(proc->proc_name, vp->vers_num); 3657c478bd9Sstevel@tonic-gate else 3667c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate /* 3697c478bd9Sstevel@tonic-gate * mode 1 = ANSI-C, mode 2 = K&R C 3707c478bd9Sstevel@tonic-gate */ 3717c478bd9Sstevel@tonic-gate if (mode == 1) 37261961e0fSrobinson parglist(proc, addargtype); 3737c478bd9Sstevel@tonic-gate else 3747c478bd9Sstevel@tonic-gate f_print(fout, "();\n"); 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate /* print out argument list of procedure */ 37861961e0fSrobinson static void 37961961e0fSrobinson parglist(proc_list *proc, char *addargtype) 3807c478bd9Sstevel@tonic-gate { 3817c478bd9Sstevel@tonic-gate decl_list *dl; 3827c478bd9Sstevel@tonic-gate int oneway = streq(proc->res_type, "oneway"); 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate f_print(fout, "("); 3857c478bd9Sstevel@tonic-gate if (proc->arg_num < 2 && newstyle && 3867c478bd9Sstevel@tonic-gate streq(proc->args.decls->decl.type, "void")) { 3877c478bd9Sstevel@tonic-gate /* 0 argument in new style: do nothing */ 38861961e0fSrobinson /* EMPTY */ 3897c478bd9Sstevel@tonic-gate } else { 3907c478bd9Sstevel@tonic-gate for (dl = proc->args.decls; dl != NULL; dl = dl->next) { 3917c478bd9Sstevel@tonic-gate ptype(dl->decl.prefix, dl->decl.type, 1); 3927c478bd9Sstevel@tonic-gate if (!newstyle || (dl->decl.rel == REL_POINTER)) 3937c478bd9Sstevel@tonic-gate f_print(fout, "*"); 3947c478bd9Sstevel@tonic-gate /* old style passes by reference */ 3957c478bd9Sstevel@tonic-gate f_print(fout, ", "); 3967c478bd9Sstevel@tonic-gate } 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 4007c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 4017c478bd9Sstevel@tonic-gate f_print(fout, "*, "); 4027c478bd9Sstevel@tonic-gate } 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate f_print(fout, "%s);\n", addargtype); 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate 40761961e0fSrobinson static void 40861961e0fSrobinson penumdef(definition *def) 4097c478bd9Sstevel@tonic-gate { 4107c478bd9Sstevel@tonic-gate char *name = def->def_name; 4117c478bd9Sstevel@tonic-gate enumval_list *l; 4127c478bd9Sstevel@tonic-gate char *last = NULL; 4137c478bd9Sstevel@tonic-gate int count = 0; 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate f_print(fout, "enum %s {\n", name); 4167c478bd9Sstevel@tonic-gate for (l = def->def.en.vals; l != NULL; l = l->next) { 4177c478bd9Sstevel@tonic-gate f_print(fout, "\t%s", l->name); 4187c478bd9Sstevel@tonic-gate if (l->assignment) { 4197c478bd9Sstevel@tonic-gate f_print(fout, " = %s", l->assignment); 4207c478bd9Sstevel@tonic-gate last = l->assignment; 4217c478bd9Sstevel@tonic-gate count = 1; 4227c478bd9Sstevel@tonic-gate } else { 42361961e0fSrobinson if (last == NULL) 4247c478bd9Sstevel@tonic-gate f_print(fout, " = %d", count++); 42561961e0fSrobinson else 4267c478bd9Sstevel@tonic-gate f_print(fout, " = %s + %d", last, count++); 4277c478bd9Sstevel@tonic-gate } 4287c478bd9Sstevel@tonic-gate if (l->next) 4297c478bd9Sstevel@tonic-gate f_print(fout, ",\n"); 4307c478bd9Sstevel@tonic-gate else 4317c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate f_print(fout, "};\n"); 4347c478bd9Sstevel@tonic-gate f_print(fout, "typedef enum %s %s;\n", name, name); 4357c478bd9Sstevel@tonic-gate } 4367c478bd9Sstevel@tonic-gate 43761961e0fSrobinson static void 43861961e0fSrobinson ptypedef(definition *def) 4397c478bd9Sstevel@tonic-gate { 4407c478bd9Sstevel@tonic-gate char *name = def->def_name; 4417c478bd9Sstevel@tonic-gate char *old = def->def.ty.old_type; 4427c478bd9Sstevel@tonic-gate char prefix[8]; /* enough to contain "struct ", including NUL */ 4437c478bd9Sstevel@tonic-gate relation rel = def->def.ty.rel; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate if (!streq(name, old)) { 4477c478bd9Sstevel@tonic-gate if (streq(old, "string")) { 4487c478bd9Sstevel@tonic-gate old = "char"; 4497c478bd9Sstevel@tonic-gate rel = REL_POINTER; 4507c478bd9Sstevel@tonic-gate } else if (streq(old, "opaque")) { 4517c478bd9Sstevel@tonic-gate old = "char"; 4527c478bd9Sstevel@tonic-gate } else if (streq(old, "bool")) { 4537c478bd9Sstevel@tonic-gate old = "bool_t"; 4547c478bd9Sstevel@tonic-gate } 45561961e0fSrobinson if (undefined2(old, name) && def->def.ty.old_prefix) 45661961e0fSrobinson (void) snprintf(prefix, sizeof (prefix), "%s ", 45761961e0fSrobinson def->def.ty.old_prefix); 45861961e0fSrobinson else 4597c478bd9Sstevel@tonic-gate prefix[0] = 0; 4607c478bd9Sstevel@tonic-gate f_print(fout, "typedef "); 4617c478bd9Sstevel@tonic-gate switch (rel) { 4627c478bd9Sstevel@tonic-gate case REL_ARRAY: 4637c478bd9Sstevel@tonic-gate f_print(fout, "struct {\n"); 4647c478bd9Sstevel@tonic-gate f_print(fout, "\tu_int %s_len;\n", name); 4657c478bd9Sstevel@tonic-gate f_print(fout, "\t%s%s *%s_val;\n", prefix, old, name); 4667c478bd9Sstevel@tonic-gate f_print(fout, "} %s", name); 4677c478bd9Sstevel@tonic-gate break; 4687c478bd9Sstevel@tonic-gate case REL_POINTER: 4697c478bd9Sstevel@tonic-gate f_print(fout, "%s%s *%s", prefix, old, name); 4707c478bd9Sstevel@tonic-gate break; 4717c478bd9Sstevel@tonic-gate case REL_VECTOR: 4727c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s[%s]", prefix, old, name, 4737c478bd9Sstevel@tonic-gate def->def.ty.array_max); 4747c478bd9Sstevel@tonic-gate break; 4757c478bd9Sstevel@tonic-gate case REL_ALIAS: 4767c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s", prefix, old, name); 4777c478bd9Sstevel@tonic-gate break; 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate f_print(fout, ";\n"); 4807c478bd9Sstevel@tonic-gate } 4817c478bd9Sstevel@tonic-gate } 4827c478bd9Sstevel@tonic-gate 48361961e0fSrobinson void 48461961e0fSrobinson pdeclaration(char *name, declaration *dec, int tab, char *separator) 4857c478bd9Sstevel@tonic-gate { 4867c478bd9Sstevel@tonic-gate char buf[8]; /* enough to hold "struct ", include NUL */ 4877c478bd9Sstevel@tonic-gate char *prefix; 4887c478bd9Sstevel@tonic-gate char *type; 4897c478bd9Sstevel@tonic-gate 49061961e0fSrobinson if (streq(dec->type, "void")) 4917c478bd9Sstevel@tonic-gate return; 4927c478bd9Sstevel@tonic-gate tabify(fout, tab); 49361961e0fSrobinson if (streq(dec->type, name) && !dec->prefix) 4947c478bd9Sstevel@tonic-gate f_print(fout, "struct "); 4957c478bd9Sstevel@tonic-gate if (streq(dec->type, "string")) { 4967c478bd9Sstevel@tonic-gate f_print(fout, "char *%s", dec->name); 4977c478bd9Sstevel@tonic-gate } else { 4987c478bd9Sstevel@tonic-gate prefix = ""; 4997c478bd9Sstevel@tonic-gate if (streq(dec->type, "bool")) { 5007c478bd9Sstevel@tonic-gate type = "bool_t"; 5017c478bd9Sstevel@tonic-gate } else if (streq(dec->type, "opaque")) { 5027c478bd9Sstevel@tonic-gate type = "char"; 5037c478bd9Sstevel@tonic-gate } else { 5047c478bd9Sstevel@tonic-gate if (dec->prefix) { 50561961e0fSrobinson (void) snprintf(buf, sizeof (buf), 50661961e0fSrobinson "%s ", dec->prefix); 5077c478bd9Sstevel@tonic-gate prefix = buf; 5087c478bd9Sstevel@tonic-gate } 5097c478bd9Sstevel@tonic-gate type = dec->type; 5107c478bd9Sstevel@tonic-gate } 5117c478bd9Sstevel@tonic-gate switch (dec->rel) { 5127c478bd9Sstevel@tonic-gate case REL_ALIAS: 5137c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s", prefix, type, dec->name); 5147c478bd9Sstevel@tonic-gate break; 5157c478bd9Sstevel@tonic-gate case REL_VECTOR: 5167c478bd9Sstevel@tonic-gate f_print(fout, "%s%s %s[%s]", prefix, type, dec->name, 5177c478bd9Sstevel@tonic-gate dec->array_max); 5187c478bd9Sstevel@tonic-gate break; 5197c478bd9Sstevel@tonic-gate case REL_POINTER: 5207c478bd9Sstevel@tonic-gate f_print(fout, "%s%s *%s", prefix, type, dec->name); 5217c478bd9Sstevel@tonic-gate break; 5227c478bd9Sstevel@tonic-gate case REL_ARRAY: 5237c478bd9Sstevel@tonic-gate f_print(fout, "struct {\n"); 5247c478bd9Sstevel@tonic-gate tabify(fout, tab); 5257c478bd9Sstevel@tonic-gate f_print(fout, "\tu_int %s_len;\n", dec->name); 5267c478bd9Sstevel@tonic-gate tabify(fout, tab); 5277c478bd9Sstevel@tonic-gate f_print(fout, 5287c478bd9Sstevel@tonic-gate "\t%s%s *%s_val;\n", prefix, type, dec->name); 5297c478bd9Sstevel@tonic-gate tabify(fout, tab); 5307c478bd9Sstevel@tonic-gate f_print(fout, "} %s", dec->name); 5317c478bd9Sstevel@tonic-gate break; 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate } 53461961e0fSrobinson /* LINTED variable format */ 5357c478bd9Sstevel@tonic-gate f_print(fout, separator); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate 53861961e0fSrobinson static uint_t 53961961e0fSrobinson undefined2(char *type, char *stop) 5407c478bd9Sstevel@tonic-gate { 5417c478bd9Sstevel@tonic-gate list *l; 5427c478bd9Sstevel@tonic-gate definition *def; 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate for (l = defined; l != NULL; l = l->next) { 5457c478bd9Sstevel@tonic-gate def = (definition *) l->val; 5467c478bd9Sstevel@tonic-gate if (def->def_kind != DEF_PROGRAM) { 54761961e0fSrobinson if (streq(def->def_name, stop)) 5487c478bd9Sstevel@tonic-gate return (1); 54961961e0fSrobinson if (streq(def->def_name, type)) 5507c478bd9Sstevel@tonic-gate return (0); 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate } 5537c478bd9Sstevel@tonic-gate return (1); 5547c478bd9Sstevel@tonic-gate } 555