home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / rpc-hm-1.0 / rpc-hm-client-program.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-28  |  3.0 KB  |  151 lines

  1. /*
  2.        Copyright (C) 1991, 1992 Eyvind Ness. All rights reserved.
  3. */
  4.  
  5. /* 
  6.     Author: Eyvind Ness (eyvind) 
  7.     Date:   Monday, June 29 1992 08:21 GMT
  8.     File:   /usr/local/gnu/emacs/elisp/rpc-hm-1.0/rpc-hm-client-program.c
  9. */
  10.  
  11. /*
  12.   GNU Emacs Note: To make this client work with rpc-hm.el put the
  13.   executable of this program in a place where it can be found somewhere
  14.   along your exec-path, e.g. /usr/local/gnu/bin/rpc-hm-client-program
  15.  
  16.   To generate the executable, just do M-x compile in Emacs, or type the
  17.   compile-command at the end of this file manually to a Unix shell.
  18.   
  19.  
  20. Dependencies: 
  21.  
  22.   - Sun RPC, UDP, IP network software
  23.   - Ethernet LAN
  24.  
  25. Description:
  26.  
  27.   An RPC client for evaluating LISP expression on a remote Lisp host
  28.   computer. It sends a string converted to the network standard
  29.   representation as defined by XDR to a LISP server process on the
  30.   server host. It expects a string back containing the result of the
  31.   requested operation. 
  32.  
  33. Notes:
  34.  
  35.   The RPC portmapper daemon must be running on both computers, see
  36.   portmap(1m).
  37.  
  38. */
  39.  
  40. #include <stdio.h>
  41. #include <rpc/rpc.h>
  42.  
  43. #define LISP_SERVICE 0x20000ffe
  44. #define VERSION_NO 1
  45. #define PROC_NO 1
  46.  
  47. /* 8K is the maximum packet size in UDP: */
  48. #define MAXBUFSZ 8192
  49.   
  50. int xdr_net_string ();
  51. void print_reply ();
  52. void prompt_if ();
  53.  
  54. main (argc, argv)
  55.      int argc;
  56.      char *argv[];
  57. {
  58.   char *reply_ptr, *query_ptr;
  59.   char reply[MAXBUFSZ], query[MAXBUFSZ];
  60.   int status, i=0;
  61.   int promptp = (argc == 3);
  62.   char prompt[64], nextch;
  63.   
  64.   query_ptr = query;
  65.   reply_ptr = reply;
  66. /*
  67.   A NULL ptr would force XDR to allocate memory for the reply.
  68. */
  69.  
  70.   if (argc < 2)
  71.     {
  72.       fprintf(stderr,
  73.           "Usage: %s <hostname> &optional (promptp nil)\n",
  74.           argv[0]);
  75.       exit (1);
  76.     }
  77.   strncpy(prompt,argv[1],64);
  78.  
  79.   prompt_if(promptp, prompt);
  80.   fflush(stdout);
  81.  
  82.   nextch=fgetc(stdin);
  83.   while (!feof(stdin) && (i<MAXBUFSZ-1) )
  84.     {
  85.       query[i]=nextch;
  86.       nextch=fgetc(stdin);
  87.       i++;
  88.     }
  89.   query[i]='\0';        /* Null terminate */
  90.       
  91.   status = callrpc(argv[1],
  92.            LISP_SERVICE,
  93.            VERSION_NO,
  94.            PROC_NO,
  95.            xdr_net_string,
  96.            &query_ptr,
  97.            xdr_net_string,
  98.            &reply_ptr);
  99.   if (status != 0) 
  100.     {
  101.       fprintf(stderr,"\ncallrpc error: ");
  102.       clnt_perrno(status);
  103.       fprintf(stderr,"\n");
  104.       exit (1);
  105.     }
  106.  
  107.   print_reply ( reply, promptp );
  108.   exit(0);
  109. }
  110. /* End main */
  111.  
  112.  
  113. int xdr_net_string (xdrs, sp)
  114. /* 
  115.           this  function  converts  both  to  and  from  the
  116.           network  standard representation  of    strings as
  117.           defined by XDR.
  118. */
  119.      XDR *xdrs;
  120.      char **sp;
  121. {
  122.   return ( xdr_string(xdrs,sp,MAXBUFSZ) );
  123. }
  124.   
  125. void print_reply(str, end_of_data_flagp)
  126.      char str[];
  127.      int end_of_data_flagp;
  128. {
  129.   if (end_of_data_flagp)
  130.     fprintf(stdout, "%s\n",str);
  131.   else
  132.     fprintf(stdout, "%s\nEOF\n",str);
  133.     
  134.   fflush(stdout);
  135. }
  136.  
  137. void prompt_if (cond, prompt)
  138.      int cond;
  139.      char *prompt;
  140. {
  141.   if (cond)
  142.     fprintf(stdout, "%s> ", prompt);
  143. }
  144.  
  145.  
  146. /*
  147.    Local Variables:
  148.    compile-command: "cc -O -o rpc-hm-client-program rpc-hm-client-program.c"
  149.    End:
  150. */
  151.