Commit | Line | Data |
---|---|---|
bfe13c81 KB |
1 | /* |
2 | * Copyright (c) 1988 Mark Nudleman | |
3 | * Copyright (c) 1988 Regents of the University of California. | |
4 | * All rights reserved. | |
5 | * | |
bfe13c81 KB |
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 | |
a942b40b KB |
11 | * by Mark Nudleman and the University of California, Berkeley. The |
12 | * name of Mark Nudleman or the | |
bfe13c81 KB |
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 | |
966c6ec0 | 21 | static char sccsid[] = "@(#)option.c 5.6 (Berkeley) %G%"; |
bfe13c81 KB |
22 | #endif /* not lint */ |
23 | ||
966c6ec0 KB |
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 | int terseprompt; | |
37 | ||
38 | char *firstsearch; | |
39 | extern int sc_height; | |
40 | ||
41 | option(argc, argv) | |
42 | int argc; | |
43 | char **argv; | |
bfe13c81 | 44 | { |
966c6ec0 KB |
45 | extern char *optarg; |
46 | extern int optind; | |
47 | static int sc_window_set = 0; | |
48 | int ch; | |
49 | char *p; | |
50 | ||
51 | optind = 1; /* called twice, re-init getopt. */ | |
52 | while ((ch = getopt(argc, argv, "0123456789/:ceinpst:ux:")) != EOF) | |
53 | switch((char)ch) { | |
54 | case '0': case '1': case '2': case '3': case '4': | |
55 | case '5': case '6': case '7': case '8': case '9': | |
bfe13c81 | 56 | /* |
966c6ec0 KB |
57 | * kludge: more was originally designed to take |
58 | * a number after a dash. | |
bfe13c81 | 59 | */ |
966c6ec0 KB |
60 | if (!sc_window_set) { |
61 | p = argv[optind - 1]; | |
62 | if (p[0] == '-' && p[1] == ch && !p[2]) | |
63 | sc_height = atoi(++p); | |
64 | else | |
65 | sc_height = atoi(argv[optind] + 1); | |
66 | sc_window_set = 1; | |
bfe13c81 | 67 | } |
966c6ec0 KB |
68 | break; |
69 | case '/': | |
70 | firstsearch = optarg; | |
71 | break; | |
72 | case 'c': | |
73 | top_scroll = 1; | |
74 | break; | |
75 | case 'e': | |
76 | quit_at_eof = 1; | |
77 | break; | |
78 | case 'i': | |
79 | caseless = 1; | |
80 | break; | |
81 | case 'n': | |
82 | linenums = 0; | |
83 | break; | |
84 | case 'p': | |
85 | terseprompt = 1; | |
86 | break; | |
87 | case 's': | |
88 | squeeze = 1; | |
89 | break; | |
90 | case 't': | |
91 | tagoption = 1; | |
92 | findtag(optarg); | |
93 | break; | |
94 | case 'u': | |
95 | bs_mode = 1; | |
96 | break; | |
97 | case 'x': | |
98 | tabstop = atoi(optarg); | |
99 | if (tabstop <= 0) | |
100 | tabstop = 8; | |
101 | break; | |
102 | case '?': | |
103 | default: | |
104 | fprintf(stderr, | |
105 | "usage: less [-ceinpus] [-t tag] [-x tabs] [-/ pattern] [-#] [file ...]\n"); | |
106 | exit(1); | |
107 | } | |
108 | return(optind); | |
bfe13c81 | 109 | } |