home *** CD-ROM | disk | FTP | other *** search
- /*
- Stuff 1.1
-
- Handle a response file for the stuff program.
- Written by Andre van Dalen (uunet!mcvax!targon!andre).
- */
-
- #include "stuff.h"
- #include <stdlib.h>
- #include <fcntl.h>
- #include <ctype.h>
- #ifndef UNBUF_IO
- #include <stdio.h>
- #endif
-
- static char *myalloc(int);
- static void bad_file(char *);
- static void no_nesting(char *);
-
- void do_response (filename)
- char *filename;
- {
- static int response = 0;
- char *argv[MAX_OPTS];
- int argc = 0;
- char *buf, *s, *e, *os;
- int fd, len, i;
-
- if (response++)
- no_nesting(filename);
-
- if ((fd = open(filename, O_RDONLY)) < 0)
- bad_file(filename);
-
- /* Read file, assume that files are < 32 Kbytes */
-
- len = (int) lseek(fd, 0L, 2);
- lseek(fd, 0L, 0);
- buf = myalloc(len);
- len = read(fd, buf, len);
- close(fd);
-
- s = buf;
- e = buf + len;
-
- /* Build an argv[] from this file */
-
- while (s < e)
- {
- if (!isspace(*s))
- {
- os = s;
- while (s < e && !isspace(*s))
- s++;
- argv[argc] = myalloc(s - os + 1);
- *s++ = '\0';
- strcpy(argv[argc++], os);
- }
- while (s < e && isspace(*s))
- s++;
- }
-
- free(buf);
-
- /* Parse options */
-
- for (i=0 ; i < argc ; i++)
- parseopt(argv, &i, argc);
-
- for (i=0 ; i < argc ; i++)
- free(argv[i]);
-
- response = 0;
- }
-
- static char *myalloc (len)
- int len;
- {
- char *s;
-
- if ((s = malloc(len)) == NULL)
- {
- #ifdef UNBUF_IO
- errmsg ("stuff: FATAL: Out of memory.\n");
- #else
- fprintf (stderr, "stuff: FATAL: Out of memory.\n");
- #endif
- exit(1);
- }
- return s;
- }
-
- static void no_nesting (filename)
- char *filename;
- {
- #ifdef UNBUF_IO
- errmsg ("stuff: FATAL: Nested response file ");
- errmsg (filename);
- errmsg (".\n");
- #else
- fprintf (stderr, "stuff: FATAL: Nested response file %s.\n", filename)
- ;
- #endif
- exit(1);
- }
-
- static void bad_file (filename)
- char *filename;
- {
- #ifdef UNBUF_IO
- errmsg ("stuff: FATAL: Cannot read response file ");
- errmsg (filename);
- errmsg (".\n");
- #else
- fprintf (stderr, "stuff: FATAL: Cannot read response file %s.\n", file
- name);
- #endif
- exit(1);
- }
-