home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / psh / c / read < prev    next >
Text File  |  1995-05-08  |  647b  |  42 lines

  1. /* vi:tabstop=4:shiftwidth=4:smartindent
  2.  *
  3.  * read.c - read a line from stdin to the named variable
  4.  *
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <readline.h>
  10. #include <sys/os.h>
  11. #include "psh.h"
  12.  
  13. int sh_read(int argc, char **argv)
  14. {
  15.     os_error    *e;
  16.     int            r[10];
  17.     char        line[MAXLEN];
  18.  
  19.     if (argc != 2)
  20.     {
  21.         fprintf(stderr, "Usage: read <variable>\n");
  22.         return 1;
  23.     }
  24.  
  25.     if (fgets(line, MAXLEN, rl_instream) == NULL)
  26.     {
  27.         return 1;
  28.     }
  29.  
  30.     r[0] = (int) argv[1];
  31.     r[1] = (int) line;
  32.     r[2] = strlen(line) - 1;
  33.     r[3] = 0;
  34.     r[4] = 0;
  35.     if (e = os_swi(OS_SetVarVal, r))
  36.     {
  37.         fprintf(stderr, "Error: %s\n", e->mess);
  38.         return e->err;
  39.     }
  40.     return 0;
  41. }
  42.