xref: /csrg-svn/usr.bin/more/option.c (revision 62131)
135209Sbostic /*
235209Sbostic  * Copyright (c) 1988 Mark Nudleman
3*62131Sbostic  * Copyright (c) 1988, 1993
4*62131Sbostic  *	The Regents of the University of California.  All rights reserved.
535209Sbostic  *
642742Sbostic  * %sccs.include.redist.c%
735209Sbostic  */
835209Sbostic 
935209Sbostic #ifndef lint
10*62131Sbostic static char sccsid[] = "@(#)option.c	8.1 (Berkeley) 06/06/93";
1135209Sbostic #endif /* not lint */
1235209Sbostic 
1336253Sbostic #include <stdio.h>
1436253Sbostic #include <less.h>
1535209Sbostic 
1636253Sbostic int top_scroll;			/* Repaint screen from top */
1736253Sbostic int bs_mode;			/* How to process backspaces */
1836253Sbostic int caseless;			/* Do "caseless" searches */
1936253Sbostic int cbufs = 10;			/* Current number of buffers */
2036253Sbostic int linenums = 1;		/* Use line numbers */
2136253Sbostic int quit_at_eof;
2236253Sbostic int squeeze;			/* Squeeze multiple blank lines into one */
2336253Sbostic int tabstop = 8;		/* Tab settings */
2436253Sbostic int tagoption;
2535209Sbostic 
2636253Sbostic char *firstsearch;
2736253Sbostic extern int sc_height;
2835209Sbostic 
option(argc,argv)2936253Sbostic option(argc, argv)
3036253Sbostic 	int argc;
3136253Sbostic 	char **argv;
3235209Sbostic {
3336253Sbostic 	extern char *optarg;
3436253Sbostic 	extern int optind;
3536253Sbostic 	static int sc_window_set = 0;
3636253Sbostic 	int ch;
3736253Sbostic 	char *p;
3835209Sbostic 
3936266Sbostic 	/* backward compatible processing for "+/search" */
4036266Sbostic 	char **a;
4136266Sbostic 	for (a = argv; *a; ++a)
4236266Sbostic 		if ((*a)[0] == '+' && (*a)[1] == '/')
4336266Sbostic 			(*a)[0] = '-';
4436266Sbostic 
4536253Sbostic 	optind = 1;		/* called twice, re-init getopt. */
4640364Smarc 	while ((ch = getopt(argc, argv, "0123456789/:ceinst:ux:f")) != EOF)
4736253Sbostic 		switch((char)ch) {
4836253Sbostic 		case '0': case '1': case '2': case '3': case '4':
4936253Sbostic 		case '5': case '6': case '7': case '8': case '9':
5035209Sbostic 			/*
5136253Sbostic 			 * kludge: more was originally designed to take
5236253Sbostic 			 * a number after a dash.
5335209Sbostic 			 */
5436253Sbostic 			if (!sc_window_set) {
5536253Sbostic 				p = argv[optind - 1];
5636253Sbostic 				if (p[0] == '-' && p[1] == ch && !p[2])
5736253Sbostic 					sc_height = atoi(++p);
5836253Sbostic 				else
5936253Sbostic 					sc_height = atoi(argv[optind] + 1);
6036253Sbostic 				sc_window_set = 1;
6135209Sbostic 			}
6236253Sbostic 			break;
6336253Sbostic 		case '/':
6436253Sbostic 			firstsearch = optarg;
6536253Sbostic 			break;
6636253Sbostic 		case 'c':
6736253Sbostic 			top_scroll = 1;
6836253Sbostic 			break;
6936253Sbostic 		case 'e':
7036253Sbostic 			quit_at_eof = 1;
7136253Sbostic 			break;
7236253Sbostic 		case 'i':
7336253Sbostic 			caseless = 1;
7436253Sbostic 			break;
7536253Sbostic 		case 'n':
7636253Sbostic 			linenums = 0;
7736253Sbostic 			break;
7836253Sbostic 		case 's':
7936253Sbostic 			squeeze = 1;
8036253Sbostic 			break;
8136253Sbostic 		case 't':
8236253Sbostic 			tagoption = 1;
8336253Sbostic 			findtag(optarg);
8436253Sbostic 			break;
8536253Sbostic 		case 'u':
8636253Sbostic 			bs_mode = 1;
8736253Sbostic 			break;
8836253Sbostic 		case 'x':
8936253Sbostic 			tabstop = atoi(optarg);
9036253Sbostic 			if (tabstop <= 0)
9136253Sbostic 				tabstop = 8;
9236253Sbostic 			break;
9340364Smarc 		case 'f':	/* ignore -f, compatability with old more */
9440364Smarc 			break;
9536253Sbostic 		case '?':
9636253Sbostic 		default:
9736253Sbostic 			fprintf(stderr,
9837999Sbostic 			    "usage: more [-ceinus] [-t tag] [-x tabs] [-/ pattern] [-#] [file ...]\n");
9936253Sbostic 			exit(1);
10035209Sbostic 		}
10136253Sbostic 	return(optind);
10235209Sbostic }
103