main
options.c
1/* Copyright (c) 1985 Ceriel J.H. Jacobs */
2
3#include "in_all.h"
4#include "options.h"
5#include "output.h"
6#include "display.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
26 char **av = argv + 1;
27 char *p;
28
29 if ((p = getenv("YAP")) != 0) {
30 (void)parsopt(p);
31 }
32 while (*av && **av == '-') {
33 if (parsopt(*av)) {
34 /*
35 * Error in option
36 */
37 putline(*av);
38 putline(": illegal option\n");
39 return (char **)0;
40 }
41 av++;
42 }
43 if (*av && **av == '+') {
44 /*
45 * Command in command line
46 */
47 startcomm = *av + 1;
48 av++;
49 }
50 return av;
51}
52
53static int
54parsopt(char *s)
55{
56 int i;
57
58 if (*s == '-')
59 s++;
60 if (isdigit(*s)) {
61 /*
62 * pagesize option
63 */
64 i = 0;
65 do {
66 i = i * 10 + *s++ - '0';
67 } while (isdigit(*s));
68 if (i < MINPAGESIZE)
69 i = MINPAGESIZE;
70 pagesize = i;
71 }
72 while (*s) {
73 switch (*s++) {
74 case 'c':
75 cflag++;
76 break;
77 case 'n':
78 nflag++;
79 break;
80 case 'u':
81 uflag++;
82 break;
83 case 'q':
84 qflag++;
85 break;
86 default:
87 return 1;
88 }
89 }
90 return 0;
91}