home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SATAN11.ZIP / SRC / RPCGEN / RPC_CLNT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-08  |  3.7 KB  |  132 lines

  1. /* @(#)rpc_clntout.c    2.1 88/08/01 4.0 RPCSRC */
  2. /*
  3.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  4.  * unrestricted use provided that this legend is included on all tape
  5.  * media and as a part of the software program in whole or part.  Users
  6.  * may copy or modify Sun RPC without charge, but are not authorized
  7.  * to license or distribute it to anyone else except as part of a product or
  8.  * program developed by the user.
  9.  * 
  10.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  11.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  13.  * 
  14.  * Sun RPC is provided with no support and without any obligation on the
  15.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  16.  * modification or enhancement.
  17.  * 
  18.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  19.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  20.  * OR ANY PART THEREOF.
  21.  * 
  22.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  23.  * or profits or other special, indirect and consequential damages, even if
  24.  * Sun has been advised of the possibility of such damages.
  25.  * 
  26.  * Sun Microsystems, Inc.
  27.  * 2550 Garcia Avenue
  28.  * Mountain View, California  94043
  29.  */
  30. #ifndef lint
  31. static char sccsid[] = "@(#)rpc_clntout.c 1.2 87/06/24 (C) 1987 SMI";
  32. #endif
  33.  
  34. /*
  35.  * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
  36.  * Copyright (C) 1987, Sun Microsytsems, Inc.
  37.  */
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <stdlib.h>
  41. #include <unistd.h>
  42. #include "rpc_parse.h"
  43. #include "rpc_util.h"
  44.  
  45. #define DEFAULT_TIMEOUT 25    /* in seconds */
  46.  
  47. static write_program();
  48. static printbody();
  49.  
  50. void
  51. write_stubs()
  52. {
  53.     list *l;
  54.     definition *def;
  55.  
  56.      f_print(fout,
  57.          "\n/* Default timeout can be changed using clnt_control() */\n");
  58.      f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
  59.         DEFAULT_TIMEOUT);
  60.     for (l = defined; l != NULL; l = l->next) {
  61.         def = (definition *) l->val;
  62.         if (def->def_kind == DEF_PROGRAM) {
  63.             write_program(def);
  64.         }
  65.     }
  66. }
  67.  
  68.  
  69. static
  70. write_program(def)
  71.     definition *def;
  72. {
  73.     version_list *vp;
  74.     proc_list *proc;
  75.  
  76.     for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
  77.         for (proc = vp->procs; proc != NULL; proc = proc->next) {
  78.             f_print(fout, "\n");
  79.             ptype(proc->res_prefix, proc->res_type, 1);
  80.             f_print(fout, "*\n");
  81.             pvname(proc->proc_name, vp->vers_num);
  82.             f_print(fout, "(argp, clnt)\n");
  83.             f_print(fout, "\t");
  84.             ptype(proc->arg_prefix, proc->arg_type, 1);
  85.             f_print(fout, "*argp;\n");
  86.             f_print(fout, "\tCLIENT *clnt;\n");
  87.             f_print(fout, "{\n");
  88.             printbody(proc);
  89.             f_print(fout, "}\n\n");
  90.         }
  91.     }
  92. }
  93.  
  94. static char *
  95. ampr(type)
  96.     char *type;
  97. {
  98.     if (isvectordef(type, REL_ALIAS)) {
  99.         return ("");
  100.     } else {
  101.         return ("&");
  102.     }
  103. }
  104.  
  105. static
  106. printbody(proc)
  107.     proc_list *proc;
  108. {
  109.     f_print(fout, "\tstatic ");
  110.     if (streq(proc->res_type, "void")) {
  111.         f_print(fout, "char ");
  112.     } else {
  113.         ptype(proc->res_prefix, proc->res_type, 0);
  114.     }
  115.     f_print(fout, "res;\n");
  116.     f_print(fout, "\n");
  117.      f_print(fout, "\tmemset((char *)%sres, 0, sizeof(res));\n",
  118.          ampr(proc->res_type));
  119.     f_print(fout,
  120.         "\tif (clnt_call(clnt, %s, xdr_%s, argp, xdr_%s, %sres, TIMEOUT) != RPC_SUCCESS) {\n",
  121.         proc->proc_name, stringfix(proc->arg_type),
  122.         stringfix(proc->res_type), ampr(proc->res_type));
  123.     f_print(fout, "\t\treturn (NULL);\n");
  124.     f_print(fout, "\t}\n");
  125.     if (streq(proc->res_type, "void")) {
  126.         f_print(fout, "\treturn ((void *)%sres);\n",
  127.             ampr(proc->res_type));
  128.     } else {
  129.         f_print(fout, "\treturn (%sres);\n", ampr(proc->res_type));
  130.     }
  131. }
  132.