xref: /original-bsd/usr.bin/more/option.c (revision ec35a16d)
1 /*
2  * Copyright (c) 1988 Mark Nudleman
3  * Copyright (c) 1988, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  */
8 
9 #ifndef lint
10 static char sccsid[] = "@(#)option.c	8.1 (Berkeley) 06/06/93";
11 #endif /* not lint */
12 
13 #include <stdio.h>
14 #include <less.h>
15 
16 int top_scroll;			/* Repaint screen from top */
17 int bs_mode;			/* How to process backspaces */
18 int caseless;			/* Do "caseless" searches */
19 int cbufs = 10;			/* Current number of buffers */
20 int linenums = 1;		/* Use line numbers */
21 int quit_at_eof;
22 int squeeze;			/* Squeeze multiple blank lines into one */
23 int tabstop = 8;		/* Tab settings */
24 int tagoption;
25 
26 char *firstsearch;
27 extern int sc_height;
28 
29 option(argc, argv)
30 	int argc;
31 	char **argv;
32 {
33 	extern char *optarg;
34 	extern int optind;
35 	static int sc_window_set = 0;
36 	int ch;
37 	char *p;
38 
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 
45 	optind = 1;		/* called twice, re-init getopt. */
46 	while ((ch = getopt(argc, argv, "0123456789/:ceinst:ux:f")) != EOF)
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':
50 			/*
51 			 * kludge: more was originally designed to take
52 			 * a number after a dash.
53 			 */
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;
61 			}
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;
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;
93 		case 'f':	/* ignore -f, compatability with old more */
94 			break;
95 		case '?':
96 		default:
97 			fprintf(stderr,
98 			    "usage: more [-ceinus] [-t tag] [-x tabs] [-/ pattern] [-#] [file ...]\n");
99 			exit(1);
100 		}
101 	return(optind);
102 }
103