2 * Entry point, initialization, miscellaneous routines.
9 public char * every_first_cmd = NULL;
12 public IFILE curr_ifile = NULL_IFILE;
13 public IFILE old_ifile = NULL_IFILE;
14 public struct scrpos initial_scrpos;
15 public int any_display = 0;
17 public char * progname;
21 extern int quit_at_eof;
24 extern int screen_trashed;
25 extern int force_open;
28 public int logfile = -1;
29 public int force_logfile = 0;
30 public char * namelogfile = NULL;
35 public char * editproto;
39 extern char * tagfile;
40 extern char * tagpattern;
55 extern char *getenv();
60 * Process command line arguments and LESS environment arguments.
61 * Command line arguments override environment arguments.
66 scan_option(getenv("LESS"));
68 #define isoptstring(s) (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0')
69 while (--argc > 0 && (isoptstring(argv[0]) || isoptpending()))
76 * Last command line option was a flag requiring a
77 * following string, but there was no following string.
85 * Try to use the lesskey file "$HOME/.less".
90 editor = getenv("EDITOR");
91 if (editor == NULL || *editor == '\0')
93 editproto = getenv("LESSEDIT");
94 if (editproto == NULL || *editproto == '\0')
95 editproto = "%E ?lm+%lm. %f";
99 * Set up terminal, etc.
105 * Output is not a tty.
106 * Just copy the input file(s) to output.
110 if (edit("-", 0) == 0)
116 if (edit(*argv++, 0) == 0)
124 * Call get_ifile with all the command line filenames
125 * to "register" them with the ifile system.
129 h = get_ifile(*argv++, h);
139 * Select the first file to examine.
145 * A -t option was given.
146 * Verify that no filenames were also given.
147 * Edit the file selected by the "tags" search,
148 * and search for the proper line in the file.
152 error("No filenames allowed with -t option", NULL_PARG);
157 if (edit(tagfile, 0) || tagsearch())
163 nofiles = edit("-", 0); /* Standard input */
165 nofiles = edit_first();
180 * Copy a string, truncating to the specified length if necessary.
181 * Unlike strncpy(), the resulting string is guaranteed to be null-terminated.
184 strtcpy(to, from, len)
189 strncpy(to, from, len);
194 * Copy a string to a "safe" place
195 * (that is, to a buffer allocated by calloc).
203 p = (char *) ecalloc(strlen(s)+1, sizeof(char));
213 register VOID_POINTER p;
215 p = calloc(count, size);
218 error("Cannot allocate memory", NULL_PARG);
224 * Skip leading spaces in a string.
230 while (*s == ' ' || *s == '\t')
242 static int save_status;
245 * Put cursor at bottom left corner, clear the line,
246 * reset the terminal modes, and exit.
249 status = save_status;
251 save_status = status;
267 * If we don't close 2, we get some garbage from
268 * 2's buffer when it flushes automatically.
269 * I cannot track this one down RB
270 * The same bug shows up if we use ^C^C to abort.