option.c revision 1.1.1.1
11.1Scjs/* 21.1Scjs * Copyright (c) 1988 Mark Nudleman 31.1Scjs * Copyright (c) 1988, 1993 41.1Scjs * The Regents of the University of California. All rights reserved. 51.1Scjs * 61.1Scjs * Redistribution and use in source and binary forms, with or without 71.1Scjs * modification, are permitted provided that the following conditions 81.1Scjs * are met: 91.1Scjs * 1. Redistributions of source code must retain the above copyright 101.1Scjs * notice, this list of conditions and the following disclaimer. 111.1Scjs * 2. Redistributions in binary form must reproduce the above copyright 121.1Scjs * notice, this list of conditions and the following disclaimer in the 131.1Scjs * documentation and/or other materials provided with the distribution. 141.1Scjs * 3. All advertising materials mentioning features or use of this software 151.1Scjs * must display the following acknowledgement: 161.1Scjs * This product includes software developed by the University of 171.1Scjs * California, Berkeley and its contributors. 181.1Scjs * 4. Neither the name of the University nor the names of its contributors 191.1Scjs * may be used to endorse or promote products derived from this software 201.1Scjs * without specific prior written permission. 211.1Scjs * 221.1Scjs * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231.1Scjs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241.1Scjs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251.1Scjs * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261.1Scjs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271.1Scjs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281.1Scjs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291.1Scjs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301.1Scjs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311.1Scjs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.1Scjs * SUCH DAMAGE. 331.1Scjs */ 341.1Scjs 351.1Scjs#ifndef lint 361.1Scjsstatic char sccsid[] = "@(#)option.c 8.1 (Berkeley) 6/6/93"; 371.1Scjs#endif /* not lint */ 381.1Scjs 391.1Scjs#include <stdio.h> 401.1Scjs#include <less.h> 411.1Scjs 421.1Scjsint top_scroll; /* Repaint screen from top */ 431.1Scjsint bs_mode; /* How to process backspaces */ 441.1Scjsint caseless; /* Do "caseless" searches */ 451.1Scjsint cbufs = 10; /* Current number of buffers */ 461.1Scjsint linenums = 1; /* Use line numbers */ 471.1Scjsint quit_at_eof; 481.1Scjsint squeeze; /* Squeeze multiple blank lines into one */ 491.1Scjsint tabstop = 8; /* Tab settings */ 501.1Scjsint tagoption; 511.1Scjs 521.1Scjschar *firstsearch; 531.1Scjsextern int sc_height; 541.1Scjs 551.1Scjsoption(argc, argv) 561.1Scjs int argc; 571.1Scjs char **argv; 581.1Scjs{ 591.1Scjs extern char *optarg; 601.1Scjs extern int optind; 611.1Scjs static int sc_window_set = 0; 621.1Scjs int ch; 631.1Scjs char *p; 641.1Scjs 651.1Scjs /* backward compatible processing for "+/search" */ 661.1Scjs char **a; 671.1Scjs for (a = argv; *a; ++a) 681.1Scjs if ((*a)[0] == '+' && (*a)[1] == '/') 691.1Scjs (*a)[0] = '-'; 701.1Scjs 711.1Scjs optind = 1; /* called twice, re-init getopt. */ 721.1Scjs while ((ch = getopt(argc, argv, "0123456789/:ceinst:ux:f")) != EOF) 731.1Scjs switch((char)ch) { 741.1Scjs case '0': case '1': case '2': case '3': case '4': 751.1Scjs case '5': case '6': case '7': case '8': case '9': 761.1Scjs /* 771.1Scjs * kludge: more was originally designed to take 781.1Scjs * a number after a dash. 791.1Scjs */ 801.1Scjs if (!sc_window_set) { 811.1Scjs p = argv[optind - 1]; 821.1Scjs if (p[0] == '-' && p[1] == ch && !p[2]) 831.1Scjs sc_height = atoi(++p); 841.1Scjs else 851.1Scjs sc_height = atoi(argv[optind] + 1); 861.1Scjs sc_window_set = 1; 871.1Scjs } 881.1Scjs break; 891.1Scjs case '/': 901.1Scjs firstsearch = optarg; 911.1Scjs break; 921.1Scjs case 'c': 931.1Scjs top_scroll = 1; 941.1Scjs break; 951.1Scjs case 'e': 961.1Scjs quit_at_eof = 1; 971.1Scjs break; 981.1Scjs case 'i': 991.1Scjs caseless = 1; 1001.1Scjs break; 1011.1Scjs case 'n': 1021.1Scjs linenums = 0; 1031.1Scjs break; 1041.1Scjs case 's': 1051.1Scjs squeeze = 1; 1061.1Scjs break; 1071.1Scjs case 't': 1081.1Scjs tagoption = 1; 1091.1Scjs findtag(optarg); 1101.1Scjs break; 1111.1Scjs case 'u': 1121.1Scjs bs_mode = 1; 1131.1Scjs break; 1141.1Scjs case 'x': 1151.1Scjs tabstop = atoi(optarg); 1161.1Scjs if (tabstop <= 0) 1171.1Scjs tabstop = 8; 1181.1Scjs break; 1191.1Scjs case 'f': /* ignore -f, compatability with old more */ 1201.1Scjs break; 1211.1Scjs case '?': 1221.1Scjs default: 1231.1Scjs fprintf(stderr, 1241.1Scjs "usage: more [-ceinus] [-t tag] [-x tabs] [-/ pattern] [-#] [file ...]\n"); 1251.1Scjs exit(1); 1261.1Scjs } 1271.1Scjs return(optind); 1281.1Scjs} 129