main.c (a8f92a7ce5678c7ac2c635f123aea79b13ba8dd7) main.c (c9346414d95d69f958210e825deb3b086dac3529)
1/* $FreeBSD$ */
2/*
3 * Copyright (C) 1984-2000 Mark Nudelman
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Less License, as specified in the README file.
7 *
8 * For more information about less, or for information on how to
9 * contact the author, see the README file.
10 */
11
12
13/*
14 * Entry point, initialization, miscellaneous routines.
15 */
16
17#include "less.h"
1/*
2 * Copyright (C) 1984-2000 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information about less, or for information on how to
8 * contact the author, see the README file.
9 */
10
11
12/*
13 * Entry point, initialization, miscellaneous routines.
14 */
15
16#include "less.h"
17#if MSDOS_COMPILER==WIN32C
18#include <windows.h>
19#endif
18
19public char * every_first_cmd = NULL;
20public int new_file;
21public int is_tty;
22public IFILE curr_ifile = NULL_IFILE;
23public IFILE old_ifile = NULL_IFILE;
24public struct scrpos initial_scrpos;
25public int any_display = FALSE;
26public POSITION start_attnpos = NULL_POSITION;
27public POSITION end_attnpos = NULL_POSITION;
28public int wscroll;
29public char * progname;
30public int quitting;
31public int secure;
32public int dohelp;
20
21public char * every_first_cmd = NULL;
22public int new_file;
23public int is_tty;
24public IFILE curr_ifile = NULL_IFILE;
25public IFILE old_ifile = NULL_IFILE;
26public struct scrpos initial_scrpos;
27public int any_display = FALSE;
28public POSITION start_attnpos = NULL_POSITION;
29public POSITION end_attnpos = NULL_POSITION;
30public int wscroll;
31public char * progname;
32public int quitting;
33public int secure;
34public int dohelp;
33public int more_mode = 0;
34
35#if LOGFILE
36public int logfile = -1;
37public int force_logfile = FALSE;
38public char * namelogfile = NULL;
39#endif
40
41#if EDITOR
42public char * editor;
43public char * editproto;
44#endif
45
46#if TAGS
35
36#if LOGFILE
37public int logfile = -1;
38public int force_logfile = FALSE;
39public char * namelogfile = NULL;
40#endif
41
42#if EDITOR
43public char * editor;
44public char * editproto;
45#endif
46
47#if TAGS
48extern char * tags;
47extern char * tagoption;
48extern int jump_sline;
49#endif
50
49extern char * tagoption;
50extern int jump_sline;
51#endif
52
53#ifdef WIN32
54static char consoleTitle[256];
55#endif
56
51extern int missing_cap;
52extern int know_dumb;
53
54
55/*
56 * Entry point.
57 */
58int
59main(argc, argv)
60 int argc;
61 char *argv[];
62{
63 IFILE ifile;
64 char *s;
57extern int missing_cap;
58extern int know_dumb;
59
60
61/*
62 * Entry point.
63 */
64int
65main(argc, argv)
66 int argc;
67 char *argv[];
68{
69 IFILE ifile;
70 char *s;
65 extern char *__progname;
66
67#ifdef __EMX__
68 _response(&argc, &argv);
69 _wildcard(&argc, &argv);
70#endif
71
72 progname = *argv++;
73 argc--;

--- 17 unchanged lines hidden (view full) ---

91 char *env = (char *) ecalloc(strlen(drive) +
92 strlen(path) + 6, sizeof(char));
93 strcpy(env, "HOME=");
94 strcat(env, drive);
95 strcat(env, path);
96 putenv(env);
97 }
98 }
71
72#ifdef __EMX__
73 _response(&argc, &argv);
74 _wildcard(&argc, &argv);
75#endif
76
77 progname = *argv++;
78 argc--;

--- 17 unchanged lines hidden (view full) ---

96 char *env = (char *) ecalloc(strlen(drive) +
97 strlen(path) + 6, sizeof(char));
98 strcpy(env, "HOME=");
99 strcat(env, drive);
100 strcat(env, path);
101 putenv(env);
102 }
103 }
104 GetConsoleTitle(consoleTitle, sizeof(consoleTitle)/sizeof(char));
99#endif /* WIN32 */
100
101 /*
102 * Process command line arguments and LESS environment arguments.
103 * Command line arguments override environment arguments.
104 */
105#endif /* WIN32 */
106
107 /*
108 * Process command line arguments and LESS environment arguments.
109 * Command line arguments override environment arguments.
110 */
105 if (strcmp(__progname, "more") == 0)
106 more_mode = 1;
107
108 is_tty = isatty(1);
109 get_term();
110 init_cmds();
111 init_prompt();
112 init_charset();
113 init_line();
114 init_option();
111 is_tty = isatty(1);
112 get_term();
113 init_cmds();
114 init_prompt();
115 init_charset();
116 init_line();
117 init_option();
115
116 if (more_mode) {
117 scan_option("-E");
118 scan_option("-m");
119 scan_option("-G");
120 scan_option("-f");
121 s = lgetenv("MORE");
122 } else {
123 s = lgetenv("LESS");
124 }
118 s = lgetenv("LESS");
125 if (s != NULL)
126 scan_option(save(s));
127
128#define isoptstring(s) (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0')
129 while (argc > 0 && (isoptstring(*argv) || isoptpending()))
130 {
131 s = *argv++;
132 argc--;

--- 30 unchanged lines hidden (view full) ---

163 * Call get_ifile with all the command line filenames
164 * to "register" them with the ifile system.
165 */
166 ifile = NULL_IFILE;
167 if (dohelp)
168 ifile = get_ifile(FAKE_HELPFILE, ifile);
169 while (argc-- > 0)
170 {
119 if (s != NULL)
120 scan_option(save(s));
121
122#define isoptstring(s) (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0')
123 while (argc > 0 && (isoptstring(*argv) || isoptpending()))
124 {
125 s = *argv++;
126 argc--;

--- 30 unchanged lines hidden (view full) ---

157 * Call get_ifile with all the command line filenames
158 * to "register" them with the ifile system.
159 */
160 ifile = NULL_IFILE;
161 if (dohelp)
162 ifile = get_ifile(FAKE_HELPFILE, ifile);
163 while (argc-- > 0)
164 {
171#if (MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC) || OS2
165#if (MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC)
172 /*
173 * Because the "shell" doesn't expand filename patterns,
174 * treat each argument as a filename pattern rather than
175 * a single filename.
176 * Expand the pattern and iterate over the expanded list.
177 */
178 struct textlist tlist;
179 char *gfilename;

--- 27 unchanged lines hidden (view full) ---

207 {
208 do {
209 cat_file();
210 } while (edit_next(1) == 0);
211 }
212 quit(QUIT_OK);
213 }
214
166 /*
167 * Because the "shell" doesn't expand filename patterns,
168 * treat each argument as a filename pattern rather than
169 * a single filename.
170 * Expand the pattern and iterate over the expanded list.
171 */
172 struct textlist tlist;
173 char *gfilename;

--- 27 unchanged lines hidden (view full) ---

201 {
202 do {
203 cat_file();
204 } while (edit_next(1) == 0);
205 }
206 quit(QUIT_OK);
207 }
208
215 if (missing_cap && !know_dumb && !more_mode)
209 if (missing_cap && !know_dumb)
216 error("WARNING: terminal is not fully functional", NULL_PARG);
217 init_mark();
218 raw_mode(1);
219 open_getchr();
220 init_signals(1);
221
222
223 /*
224 * Select the first file to examine.
225 */
226#if TAGS
210 error("WARNING: terminal is not fully functional", NULL_PARG);
211 init_mark();
212 raw_mode(1);
213 open_getchr();
214 init_signals(1);
215
216
217 /*
218 * Select the first file to examine.
219 */
220#if TAGS
227 if (tagoption != NULL)
221 if (tagoption != NULL || strcmp(tags, "-") == 0)
228 {
229 /*
230 * A -t option was given.
231 * Verify that no filenames were also given.
232 * Edit the file selected by the "tags" search,
233 * and search for the proper line in the file.
234 */
235 if (nifile() > 0)

--- 139 unchanged lines hidden (view full) ---

375 /*
376 * If we don't close 2, we get some garbage from
377 * 2's buffer when it flushes automatically.
378 * I cannot track this one down RB
379 * The same bug shows up if we use ^C^C to abort.
380 */
381 close(2);
382#endif
222 {
223 /*
224 * A -t option was given.
225 * Verify that no filenames were also given.
226 * Edit the file selected by the "tags" search,
227 * and search for the proper line in the file.
228 */
229 if (nifile() > 0)

--- 139 unchanged lines hidden (view full) ---

369 /*
370 * If we don't close 2, we get some garbage from
371 * 2's buffer when it flushes automatically.
372 * I cannot track this one down RB
373 * The same bug shows up if we use ^C^C to abort.
374 */
375 close(2);
376#endif
377#if WIN32
378 SetConsoleTitle(consoleTitle);
379#endif
383 close_getchr();
384 exit(status);
385}
380 close_getchr();
381 exit(status);
382}