xref: /original-bsd/usr.bin/more/option.c (revision a9392a99)
1 /*
2  * Copyright (c) 1988 Mark Nudleman
3  * Copyright (c) 1988 Regents of the University of California.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that the above copyright notice and this paragraph are
8  * duplicated in all such forms and that any documentation,
9  * advertising materials, and other materials related to such
10  * distribution and use acknowledge that the software was developed
11  * by Mark Nudleman and the University of California, Berkeley.  The
12  * name of Mark Nudleman or the
13  * University may not be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  */
19 
20 #ifndef lint
21 static char sccsid[] = "@(#)option.c	5.10 (Berkeley) 03/08/90";
22 #endif /* not lint */
23 
24 #include <stdio.h>
25 #include <less.h>
26 
27 int top_scroll;			/* Repaint screen from top */
28 int bs_mode;			/* How to process backspaces */
29 int caseless;			/* Do "caseless" searches */
30 int cbufs = 10;			/* Current number of buffers */
31 int linenums = 1;		/* Use line numbers */
32 int quit_at_eof;
33 int squeeze;			/* Squeeze multiple blank lines into one */
34 int tabstop = 8;		/* Tab settings */
35 int tagoption;
36 
37 char *firstsearch;
38 extern int sc_height;
39 
40 option(argc, argv)
41 	int argc;
42 	char **argv;
43 {
44 	extern char *optarg;
45 	extern int optind;
46 	static int sc_window_set = 0;
47 	int ch;
48 	char *p;
49 
50 	/* backward compatible processing for "+/search" */
51 	char **a;
52 	for (a = argv; *a; ++a)
53 		if ((*a)[0] == '+' && (*a)[1] == '/')
54 			(*a)[0] = '-';
55 
56 	optind = 1;		/* called twice, re-init getopt. */
57 	while ((ch = getopt(argc, argv, "0123456789/:ceinst:ux:f")) != EOF)
58 		switch((char)ch) {
59 		case '0': case '1': case '2': case '3': case '4':
60 		case '5': case '6': case '7': case '8': case '9':
61 			/*
62 			 * kludge: more was originally designed to take
63 			 * a number after a dash.
64 			 */
65 			if (!sc_window_set) {
66 				p = argv[optind - 1];
67 				if (p[0] == '-' && p[1] == ch && !p[2])
68 					sc_height = atoi(++p);
69 				else
70 					sc_height = atoi(argv[optind] + 1);
71 				sc_window_set = 1;
72 			}
73 			break;
74 		case '/':
75 			firstsearch = optarg;
76 			break;
77 		case 'c':
78 			top_scroll = 1;
79 			break;
80 		case 'e':
81 			quit_at_eof = 1;
82 			break;
83 		case 'i':
84 			caseless = 1;
85 			break;
86 		case 'n':
87 			linenums = 0;
88 			break;
89 		case 's':
90 			squeeze = 1;
91 			break;
92 		case 't':
93 			tagoption = 1;
94 			findtag(optarg);
95 			break;
96 		case 'u':
97 			bs_mode = 1;
98 			break;
99 		case 'x':
100 			tabstop = atoi(optarg);
101 			if (tabstop <= 0)
102 				tabstop = 8;
103 			break;
104 		case 'f':	/* ignore -f, compatability with old more */
105 			break;
106 		case '?':
107 		default:
108 			fprintf(stderr,
109 			    "usage: more [-ceinus] [-t tag] [-x tabs] [-/ pattern] [-#] [file ...]\n");
110 			exit(1);
111 		}
112 	return(optind);
113 }
114