home *** CD-ROM | disk | FTP | other *** search
- /* vi:tabstop=4:shiftwidth=4:smartindent
- *
- * read.c - read a line from stdin to the named variable
- *
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <readline.h>
- #include <sys/os.h>
- #include "psh.h"
-
- int sh_read(int argc, char **argv)
- {
- os_error *e;
- int r[10];
- char line[MAXLEN];
-
- if (argc != 2)
- {
- fprintf(stderr, "Usage: read <variable>\n");
- return 1;
- }
-
- if (fgets(line, MAXLEN, rl_instream) == NULL)
- {
- return 1;
- }
-
- r[0] = (int) argv[1];
- r[1] = (int) line;
- r[2] = strlen(line) - 1;
- r[3] = 0;
- r[4] = 0;
- if (e = os_swi(OS_SetVarVal, r))
- {
- fprintf(stderr, "Error: %s\n", e->mess);
- return e->err;
- }
- return 0;
- }
-