Home | History | Annotate | Line # | Download | only in more
option.c revision 1.2
      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  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by the University of
     17  *	California, Berkeley and its contributors.
     18  * 4. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 #ifndef lint
     36 static char sccsid[] = "@(#)option.c	8.1 (Berkeley) 6/6/93";
     37 #endif /* not lint */
     38 
     39 #include <stdio.h>
     40 #include <less.h>
     41 
     42 int top_scroll;			/* Repaint screen from top */
     43 int bs_mode;			/* How to process backspaces */
     44 int caseless;			/* Do "caseless" searches */
     45 int cbufs = 10;			/* Current number of buffers */
     46 int linenums = 1;		/* Use line numbers */
     47 int quit_at_eof;
     48 int squeeze;			/* Squeeze multiple blank lines into one */
     49 int tabstop = 8;		/* Tab settings */
     50 
     51 char *firstsearch;
     52 extern int sc_height;
     53 
     54 option(argc, argv)
     55 	int argc;
     56 	char **argv;
     57 {
     58 	extern char *optarg;
     59 	extern int optind;
     60 	static int sc_window_set = 0;
     61 	int ch;
     62 	char *p;
     63 
     64 	/* backward compatible processing for "+/search" */
     65 	char **a;
     66 	for (a = argv; *a; ++a)
     67 		if ((*a)[0] == '+' && (*a)[1] == '/')
     68 			(*a)[0] = '-';
     69 
     70 	optind = 1;		/* called twice, re-init getopt. */
     71 	while ((ch = getopt(argc, argv, "0123456789/:ceinst:ux:f")) != EOF)
     72 		switch((char)ch) {
     73 		case '0': case '1': case '2': case '3': case '4':
     74 		case '5': case '6': case '7': case '8': case '9':
     75 			/*
     76 			 * kludge: more was originally designed to take
     77 			 * a number after a dash.
     78 			 */
     79 			if (!sc_window_set) {
     80 				p = argv[optind - 1];
     81 				if (p[0] == '-' && p[1] == ch && !p[2])
     82 					sc_height = atoi(++p);
     83 				else
     84 					sc_height = atoi(argv[optind] + 1);
     85 				sc_window_set = 1;
     86 			}
     87 			break;
     88 		case '/':
     89 			firstsearch = optarg;
     90 			break;
     91 		case 'c':
     92 			top_scroll = 1;
     93 			break;
     94 		case 'e':
     95 			quit_at_eof = 1;
     96 			break;
     97 		case 'i':
     98 			caseless = 1;
     99 			break;
    100 		case 'n':
    101 			linenums = 0;
    102 			break;
    103 		case 's':
    104 			squeeze = 1;
    105 			break;
    106 		case 'u':
    107 			bs_mode = 1;
    108 			break;
    109 		case 'x':
    110 			tabstop = atoi(optarg);
    111 			if (tabstop <= 0)
    112 				tabstop = 8;
    113 			break;
    114 		case 'f':	/* ignore -f, compatability with old more */
    115 			break;
    116 		case '?':
    117 		default:
    118 			fprintf(stderr,
    119 			    "usage: more [-ceinus] [-x tabs] [-/ pattern] [-#] [file ...]\n");
    120 			exit(1);
    121 		}
    122 	return(optind);
    123 }
    124