KNF, ANSI C
[unix-history] / usr / src / usr.bin / more / option.c
CommitLineData
bfe13c81
KB
1/*
2 * Copyright (c) 1988 Mark Nudleman
1e3ab5ee
KB
3 * Copyright (c) 1988, 1993
4 * The Regents of the University of California. All rights reserved.
bfe13c81 5 *
f15db449 6 * %sccs.include.redist.c%
bfe13c81
KB
7 */
8
9#ifndef lint
1e3ab5ee 10static char sccsid[] = "@(#)option.c 8.1 (Berkeley) %G%";
bfe13c81
KB
11#endif /* not lint */
12
966c6ec0
KB
13#include <stdio.h>
14#include <less.h>
15
16int top_scroll; /* Repaint screen from top */
17int bs_mode; /* How to process backspaces */
18int caseless; /* Do "caseless" searches */
19int cbufs = 10; /* Current number of buffers */
20int linenums = 1; /* Use line numbers */
21int quit_at_eof;
22int squeeze; /* Squeeze multiple blank lines into one */
23int tabstop = 8; /* Tab settings */
24int tagoption;
966c6ec0
KB
25
26char *firstsearch;
27extern int sc_height;
28
29option(argc, argv)
30 int argc;
31 char **argv;
bfe13c81 32{
966c6ec0
KB
33 extern char *optarg;
34 extern int optind;
35 static int sc_window_set = 0;
36 int ch;
37 char *p;
38
56c4581e
KB
39 /* backward compatible processing for "+/search" */
40 char **a;
41 for (a = argv; *a; ++a)
42 if ((*a)[0] == '+' && (*a)[1] == '/')
43 (*a)[0] = '-';
44
966c6ec0 45 optind = 1; /* called twice, re-init getopt. */
ab46231c 46 while ((ch = getopt(argc, argv, "0123456789/:ceinst:ux:f")) != EOF)
966c6ec0
KB
47 switch((char)ch) {
48 case '0': case '1': case '2': case '3': case '4':
49 case '5': case '6': case '7': case '8': case '9':
bfe13c81 50 /*
966c6ec0
KB
51 * kludge: more was originally designed to take
52 * a number after a dash.
bfe13c81 53 */
966c6ec0
KB
54 if (!sc_window_set) {
55 p = argv[optind - 1];
56 if (p[0] == '-' && p[1] == ch && !p[2])
57 sc_height = atoi(++p);
58 else
59 sc_height = atoi(argv[optind] + 1);
60 sc_window_set = 1;
bfe13c81 61 }
966c6ec0
KB
62 break;
63 case '/':
64 firstsearch = optarg;
65 break;
66 case 'c':
67 top_scroll = 1;
68 break;
69 case 'e':
70 quit_at_eof = 1;
71 break;
72 case 'i':
73 caseless = 1;
74 break;
75 case 'n':
76 linenums = 0;
77 break;
966c6ec0
KB
78 case 's':
79 squeeze = 1;
80 break;
81 case 't':
82 tagoption = 1;
83 findtag(optarg);
84 break;
85 case 'u':
86 bs_mode = 1;
87 break;
88 case 'x':
89 tabstop = atoi(optarg);
90 if (tabstop <= 0)
91 tabstop = 8;
92 break;
ab46231c
MT
93 case 'f': /* ignore -f, compatability with old more */
94 break;
966c6ec0
KB
95 case '?':
96 default:
97 fprintf(stderr,
750ed434 98 "usage: more [-ceinus] [-t tag] [-x tabs] [-/ pattern] [-#] [file ...]\n");
966c6ec0
KB
99 exit(1);
100 }
101 return(optind);
bfe13c81 102}