Print this page
rpcgen should only produce ANSI code


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*


  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
  27 /* All Rights Reserved */
  28 /*
  29  * University Copyright- Copyright (c) 1982, 1986, 1988
  30  * The Regents of the University of California
  31  * All Rights Reserved
  32  *
  33  * University Acknowledgment- Portions of this document are derived from
  34  * software developed by the University of California, Berkeley, and its
  35  * contributors.
  36  */
  37 
  38 /*
  39  * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
  40  */
  41 #include <stdio.h>
  42 #include <string.h>


  99                 }
 100         }
 101 }
 102 
 103 /*
 104  * Writes out declarations of procedure's argument list.
 105  * In either ANSI C style, in one of old rpcgen style (pass by reference),
 106  * or new rpcgen style (multiple arguments, pass by value);
 107  */
 108 
 109 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
 110 
 111 void
 112 printarglist(proc_list *proc, char *result, char *addargname, char *addargtype)
 113 {
 114         bool_t oneway = streq(proc->res_type, "oneway");
 115         decl_list *l;
 116 
 117         if (!newstyle) {
 118                 /* old style: always pass argument by reference */
 119                 if (Cflag) {    /* C++ style heading */
 120                         f_print(fout, "(");
 121                         ptype(proc->args.decls->decl.prefix,
 122                             proc->args.decls->decl.type, 1);
 123 
 124                         if (mtflag) {   /* Generate result field */
 125                                 f_print(fout, "*argp, ");
 126                                 if (!oneway) {
 127                                         ptype(proc->res_prefix,
 128                                             proc->res_type, 1);
 129                                         f_print(fout, "*%s, ", result);
 130                                 }
 131                                 f_print(fout, "%s%s)\n",
 132                                     addargtype, addargname);
 133                         } else
 134                                 f_print(fout, "*argp, %s%s)\n",
 135                                     addargtype, addargname);
 136                 } else {
 137                         if (!mtflag)
 138                                 f_print(fout, "(argp, %s)\n", addargname);
 139                         else {
 140                                 f_print(fout, "(argp, ");
 141                                 if (!oneway) {
 142                                         f_print(fout, "%s, ",
 143                                             result);
 144                                 }
 145                                 f_print(fout, "%s)\n",
 146                                     addargname);
 147                         }
 148                         f_print(fout, "\t");
 149                         ptype(proc->args.decls->decl.prefix,
 150                             proc->args.decls->decl.type, 1);
 151                         f_print(fout, "*argp;\n");
 152                         if (mtflag && !oneway) {
 153                                 f_print(fout, "\t");
 154                                 ptype(proc->res_prefix, proc->res_type, 1);
 155                                 f_print(fout, "*%s;\n", result);
 156                         }
 157                 }
 158         } else if (streq(proc->args.decls->decl.type, "void")) {
 159                 /* newstyle, 0 argument */
 160                 if (mtflag) {
 161                         f_print(fout, "(");
 162 
 163                         if (Cflag) {
 164                                 if (!oneway) {
 165                                         ptype(proc->res_prefix,
 166                                             proc->res_type, 1);
 167                                         f_print(fout, "*%s, ", result);
 168                                 }
 169                                 f_print(fout, "%s%s)\n",
 170                                     addargtype, addargname);
 171                         } else
 172                                 f_print(fout, "(%s)\n", addargname);
 173 
 174                 } else
 175                 if (Cflag)
 176                         f_print(fout, "(%s%s)\n", addargtype, addargname);
 177                 else
 178                         f_print(fout, "(%s)\n", addargname);
 179         } else {
 180                 /* new style, 1 or multiple arguments */
 181                 if (!Cflag) {
 182                         f_print(fout, "(");
 183                         for (l = proc->args.decls;  l != NULL; l = l->next)
 184                                 f_print(fout, "%s, ", l->decl.name);
 185                         if (mtflag && !oneway)
 186                                 f_print(fout, "%s, ", result);
 187 
 188                         f_print(fout, "%s)\n", addargname);
 189                         for (l = proc->args.decls; l != NULL; l = l->next) {
 190                                 pdeclaration(proc->args.argname,
 191                                     &l->decl, 1, ";\n");
 192                         }
 193                         if (mtflag && !oneway) {
 194                                 f_print(fout, "\t");
 195                                 ptype(proc->res_prefix, proc->res_type, 1);
 196                                 f_print(fout, "*%s;\n", result);
 197                         }
 198 
 199                 } else {        /* C++ style header */
 200                         f_print(fout, "(");
 201                         for (l = proc->args.decls; l != NULL; l = l->next) {
 202                                 pdeclaration(proc->args.argname, &l->decl, 0,
 203                                     ", ");
 204                         }
 205                         if (mtflag && !oneway) {
 206                                 ptype(proc->res_prefix, proc->res_type, 1);
 207                                 f_print(fout, "*%s, ", result);
 208 
 209                         }
 210                         f_print(fout, "%s%s)\n", addargtype, addargname);
 211                 }
 212         }
 213 
 214         if (!Cflag)
 215                 f_print(fout, "\t%s%s;\n", addargtype, addargname);
 216 }
 217 
 218 
 219 
 220 static char *
 221 ampr(char *type)
 222 {
 223         if (isvectordef(type, REL_ALIAS)) {
 224                 return ("");
 225         } else {
 226                 return ("&");
 227         }
 228 }
 229 
 230 static void
 231 printbody(proc_list *proc)
 232 {
 233         decl_list *l;
 234         bool_t args2 = (proc->arg_num > 1);
 235         bool_t oneway = streq(proc->res_type, "oneway");




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  24  *
  25  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
  29 /* All Rights Reserved */
  30 /*
  31  * University Copyright- Copyright (c) 1982, 1986, 1988
  32  * The Regents of the University of California
  33  * All Rights Reserved
  34  *
  35  * University Acknowledgment- Portions of this document are derived from
  36  * software developed by the University of California, Berkeley, and its
  37  * contributors.
  38  */
  39 
  40 /*
  41  * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
  42  */
  43 #include <stdio.h>
  44 #include <string.h>


 101                 }
 102         }
 103 }
 104 
 105 /*
 106  * Writes out declarations of procedure's argument list.
 107  * In either ANSI C style, in one of old rpcgen style (pass by reference),
 108  * or new rpcgen style (multiple arguments, pass by value);
 109  */
 110 
 111 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
 112 
 113 void
 114 printarglist(proc_list *proc, char *result, char *addargname, char *addargtype)
 115 {
 116         bool_t oneway = streq(proc->res_type, "oneway");
 117         decl_list *l;
 118 
 119         if (!newstyle) {
 120                 /* old style: always pass argument by reference */

 121                 f_print(fout, "(");
 122                 ptype(proc->args.decls->decl.prefix,
 123                     proc->args.decls->decl.type, 1);
 124 
 125                 if (mtflag) {   /* Generate result field */
 126                         f_print(fout, "*argp, ");
 127                         if (!oneway) {
 128                                 ptype(proc->res_prefix, proc->res_type, 1);

 129                                 f_print(fout, "*%s, ", result);
 130                         }
 131                         f_print(fout, "%s%s)\n", addargtype, addargname);

 132                 } else
 133                         f_print(fout, "*argp, %s%s)\n", addargtype, addargname);























 134         } else if (streq(proc->args.decls->decl.type, "void")) {
 135                 /* newstyle, 0 argument */
 136                 if (mtflag) {
 137                         f_print(fout, "(");
 138 

 139                         if (!oneway) {
 140                                 ptype(proc->res_prefix, proc->res_type, 1);

 141                                 f_print(fout, "*%s, ", result);
 142                         }
 143                         f_print(fout, "%s%s)\n", addargtype, addargname);



 144 
 145                 } else

 146                         f_print(fout, "(%s%s)\n", addargtype, addargname);


 147         } else {
 148                 /* new style, 1 or multiple arguments */

 149                 f_print(fout, "(");






 150                 for (l = proc->args.decls; l != NULL; l = l->next) {
 151                         pdeclaration(proc->args.argname, &l->decl, 0, ", ");

 152                 }
 153                 if (mtflag && !oneway) {

 154                         ptype(proc->res_prefix, proc->res_type, 1);











 155                         f_print(fout, "*%s, ", result);
 156 
 157                 }
 158                 f_print(fout, "%s%s)\n", addargtype, addargname);
 159         }




 160 }
 161 
 162 
 163 
 164 static char *
 165 ampr(char *type)
 166 {
 167         if (isvectordef(type, REL_ALIAS)) {
 168                 return ("");
 169         } else {
 170                 return ("&");
 171         }
 172 }
 173 
 174 static void
 175 printbody(proc_list *proc)
 176 {
 177         decl_list *l;
 178         bool_t args2 = (proc->arg_num > 1);
 179         bool_t oneway = streq(proc->res_type, "oneway");