1/* Copyright (c) 1985 Ceriel J.H. Jacobs */
2
3#include "options.h"
4#include "display.h"
5#include "in_all.h"
6#include "output.h"
7#include <ctype.h>
8
9int cflag;
10int uflag;
11int nflag;
12int qflag;
13char *startcomm;
14
15static int parsopt(char *s);
16
17/*
18 * Read the options. Return the argv pointer following them if there were
19 * no errors, otherwise return 0.
20 */
21
22char **
23readoptions(char **argv)
24{
25 char **av = argv + 1;
26 char *p;
27
28 if ((p = getenv("YAP")) != 0) {
29 (void)parsopt(p);
30 }
31 while (*av && **av == '-') {
32 if (parsopt(*av)) {
33 /*
34 * Error in option
35 */
36 putline(*av);
37 putline(": illegal option\n");
38 return (char **)0;
39 }
40 av++;
41 }
42 if (*av && **av == '+') {
43 /*
44 * Command in command line
45 */
46 startcomm = *av + 1;
47 av++;
48 }
49 return av;
50}
51
52static int
53parsopt(char *s)
54{
55 int i;
56
57 if (*s == '-')
58 s++;
59 if (isdigit(*s)) {
60 /*
61 * pagesize option
62 */
63 i = 0;
64 do {
65 i = i * 10 + *s++ - '0';
66 } while (isdigit(*s));
67 if (i < MINPAGESIZE)
68 i = MINPAGESIZE;
69 pagesize = i;
70 }
71 while (*s) {
72 switch (*s++) {
73 case 'c':
74 cflag++;
75 break;
76 case 'n':
77 nflag++;
78 break;
79 case 'u':
80 uflag++;
81 break;
82 case 'q':
83 qflag++;
84 break;
85 default:
86 return 1;
87 }
88 }
89 return 0;
90}