* Entry point, initialization, miscellaneous routines.
public char * every_first_cmd
= NULL
;
public IFILE curr_ifile
= NULL_IFILE
;
public IFILE old_ifile
= NULL_IFILE
;
public struct scrpos initial_scrpos
;
public int any_display
= 0;
extern int screen_trashed
;
public int force_logfile
= 0;
public char * namelogfile
= NULL
;
extern char * tagpattern
;
* Process command line arguments and LESS environment arguments.
* Command line arguments override environment arguments.
scan_option(getenv("LESS"));
#define isoptstring(s) (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0')
while (--argc
> 0 && (isoptstring(argv
[0]) || isoptpending()))
* Last command line option was a flag requiring a
* following string, but there was no following string.
* Try to use the lesskey file "$HOME/.less".
editor
= getenv("EDITOR");
if (editor
== NULL
|| *editor
== '\0')
editproto
= getenv("LESSEDIT");
if (editproto
== NULL
|| *editproto
== '\0')
editproto
= "%E ?lm+%lm. %f";
* Just copy the input file(s) to output.
if (edit(*argv
++, 0) == 0)
* Call get_ifile with all the command line filenames
* to "register" them with the ifile system.
h
= get_ifile(*argv
++, h
);
* Select the first file to examine.
* Verify that no filenames were also given.
* Edit the file selected by the "tags" search,
* and search for the proper line in the file.
error("No filenames allowed with -t option", NULL_PARG
);
if (edit(tagfile
, 0) || tagsearch())
nofiles
= edit("-", 0); /* Standard input */
* Copy a string, truncating to the specified length if necessary.
* Unlike strncpy(), the resulting string is guaranteed to be null-terminated.
* Copy a string to a "safe" place
* (that is, to a buffer allocated by calloc).
p
= (char *) ecalloc(strlen(s
)+1, sizeof(char));
error("Cannot allocate memory", NULL_PARG
);
* Skip leading spaces in a string.
while (*s
== ' ' || *s
== '\t')
* Put cursor at bottom left corner, clear the line,
* reset the terminal modes, and exit.
* If we don't close 2, we get some garbage from
* 2's buffer when it flushes automatically.
* I cannot track this one down RB
* The same bug shows up if we use ^C^C to abort.