version 1.4, 2003/04/05 01:03:35 |
version 1.5, 2003/04/13 18:26:26 |
|
|
/* $OpenBSD$ */ |
|
|
|
/* |
/* |
* Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman |
* Copyright (C) 1984-2002 Mark Nudelman |
* All rights reserved. |
|
* |
* |
* Redistribution and use in source and binary forms, with or without |
* You may distribute under the terms of either the GNU General Public |
* modification, are permitted provided that the following conditions |
* License or the Less License, as specified in the README file. |
* are met: |
|
* 1. Redistributions of source code must retain the above copyright |
|
* notice, this list of conditions and the following disclaimer. |
|
* 2. Redistributions in binary form must reproduce the above copyright |
|
* notice in the documentation and/or other materials provided with |
|
* the distribution. |
|
* |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY |
* For more information about less, or for information on how to |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* contact the author, see the README file. |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
|
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
*/ |
*/ |
|
|
|
|
|
|
* |
* |
* Blank lines and lines which start with # are ignored, |
* Blank lines and lines which start with # are ignored, |
* except for the special control lines: |
* except for the special control lines: |
|
* #command Signals the beginning of the command |
|
* keys section. |
* #line-edit Signals the beginning of the line-editing |
* #line-edit Signals the beginning of the line-editing |
* keys section. |
* keys section. |
|
* #env Signals the beginning of the environment |
|
* variable section. |
* #stop Stops command parsing in less; |
* #stop Stops command parsing in less; |
* causes all default keys to be disabled. |
* causes all default keys to be disabled. |
* |
* |
|
|
|
|
struct cmdname cmdnames[] = |
struct cmdname cmdnames[] = |
{ |
{ |
"back-bracket", A_B_BRACKET, |
{ "back-bracket", A_B_BRACKET }, |
"back-line", A_B_LINE, |
{ "back-line", A_B_LINE }, |
"back-line-force", A_BF_LINE, |
{ "back-line-force", A_BF_LINE }, |
"back-screen", A_B_SCREEN, |
{ "back-screen", A_B_SCREEN }, |
"back-scroll", A_B_SCROLL, |
{ "back-scroll", A_B_SCROLL }, |
"back-search", A_B_SEARCH, |
{ "back-search", A_B_SEARCH }, |
"back-window", A_B_WINDOW, |
{ "back-window", A_B_WINDOW }, |
"debug", A_DEBUG, |
{ "debug", A_DEBUG }, |
"display-flag", A_DISP_OPTION, |
{ "digit", A_DIGIT }, |
"display-option", A_DISP_OPTION, |
{ "display-flag", A_DISP_OPTION }, |
"end", A_GOEND, |
{ "display-option", A_DISP_OPTION }, |
"examine", A_EXAMINE, |
{ "end", A_GOEND }, |
"first-cmd", A_FIRSTCMD, |
{ "examine", A_EXAMINE }, |
"firstcmd", A_FIRSTCMD, |
{ "first-cmd", A_FIRSTCMD }, |
"flush-repaint", A_FREPAINT, |
{ "firstcmd", A_FIRSTCMD }, |
"forw-bracket", A_F_BRACKET, |
{ "flush-repaint", A_FREPAINT }, |
"forw-forever", A_F_FOREVER, |
{ "forw-bracket", A_F_BRACKET }, |
"forw-line", A_F_LINE, |
{ "forw-forever", A_F_FOREVER }, |
"forw-line-force", A_FF_LINE, |
{ "forw-line", A_F_LINE }, |
"forw-screen", A_F_SCREEN, |
{ "forw-line-force", A_FF_LINE }, |
"forw-scroll", A_F_SCROLL, |
{ "forw-screen", A_F_SCREEN }, |
"forw-search", A_F_SEARCH, |
{ "forw-screen-force", A_FF_SCREEN }, |
"forw-window", A_F_WINDOW, |
{ "forw-scroll", A_F_SCROLL }, |
"goto-end", A_GOEND, |
{ "forw-search", A_F_SEARCH }, |
"goto-line", A_GOLINE, |
{ "forw-window", A_F_WINDOW }, |
"goto-mark", A_GOMARK, |
{ "goto-end", A_GOEND }, |
"help", A_HELP, |
{ "goto-line", A_GOLINE }, |
"index-file", A_INDEX_FILE, |
{ "goto-mark", A_GOMARK }, |
"invalid", A_UINVALID, |
{ "help", A_HELP }, |
"next-file", A_NEXT_FILE, |
{ "index-file", A_INDEX_FILE }, |
"noaction", A_NOACTION, |
{ "invalid", A_UINVALID }, |
"percent", A_PERCENT, |
{ "left-scroll", A_LSHIFT }, |
"pipe", A_PIPE, |
{ "next-file", A_NEXT_FILE }, |
"prev-file", A_PREV_FILE, |
{ "next-tag", A_NEXT_TAG }, |
"quit", A_QUIT, |
{ "noaction", A_NOACTION }, |
"repaint", A_REPAINT, |
{ "percent", A_PERCENT }, |
"repaint-flush", A_FREPAINT, |
{ "pipe", A_PIPE }, |
"repeat-search", A_AGAIN_SEARCH, |
{ "prev-file", A_PREV_FILE }, |
"repeat-search-all", A_T_AGAIN_SEARCH, |
{ "prev-tag", A_PREV_TAG }, |
"reverse-search", A_REVERSE_SEARCH, |
{ "quit", A_QUIT }, |
"reverse-search-all", A_T_REVERSE_SEARCH, |
{ "remove-file", A_REMOVE_FILE }, |
"set-mark", A_SETMARK, |
{ "repaint", A_REPAINT }, |
"shell", A_SHELL, |
{ "repaint-flush", A_FREPAINT }, |
"status", A_STAT, |
{ "repeat-search", A_AGAIN_SEARCH }, |
"toggle-flag", A_OPT_TOGGLE, |
{ "repeat-search-all", A_T_AGAIN_SEARCH }, |
"toggle-option", A_OPT_TOGGLE, |
{ "reverse-search", A_REVERSE_SEARCH }, |
"undo-hilite", A_UNDO_SEARCH, |
{ "reverse-search-all", A_T_REVERSE_SEARCH }, |
"version", A_VERSION, |
{ "right-scroll", A_RSHIFT }, |
"visual", A_VISUAL, |
{ "set-mark", A_SETMARK }, |
NULL, 0 |
{ "shell", A_SHELL }, |
|
{ "status", A_STAT }, |
|
{ "toggle-flag", A_OPT_TOGGLE }, |
|
{ "toggle-option", A_OPT_TOGGLE }, |
|
{ "undo-hilite", A_UNDO_SEARCH }, |
|
{ "version", A_VERSION }, |
|
{ "visual", A_VISUAL }, |
|
{ NULL, 0 } |
}; |
}; |
|
|
struct cmdname editnames[] = |
struct cmdname editnames[] = |
{ |
{ |
"back-complete", EC_B_COMPLETE, |
{ "back-complete", EC_B_COMPLETE }, |
"backspace", EC_BACKSPACE, |
{ "backspace", EC_BACKSPACE }, |
"delete", EC_DELETE, |
{ "delete", EC_DELETE }, |
"down", EC_DOWN, |
{ "down", EC_DOWN }, |
"end", EC_END, |
{ "end", EC_END }, |
"expand", EC_EXPAND, |
{ "expand", EC_EXPAND }, |
"forw-complete", EC_F_COMPLETE, |
{ "forw-complete", EC_F_COMPLETE }, |
"home", EC_HOME, |
{ "home", EC_HOME }, |
"insert", EC_INSERT, |
{ "insert", EC_INSERT }, |
"invalid", EC_UINVALID, |
{ "invalid", EC_UINVALID }, |
"kill-line", EC_LINEKILL, |
{ "kill-line", EC_LINEKILL }, |
"left", EC_LEFT, |
{ "left", EC_LEFT }, |
"literal", EC_LITERAL, |
{ "literal", EC_LITERAL }, |
"right", EC_RIGHT, |
{ "right", EC_RIGHT }, |
"up", EC_UP, |
{ "up", EC_UP }, |
"word-backspace", EC_W_BACKSPACE, |
{ "word-backspace", EC_W_BACKSPACE }, |
"word-delete", EC_W_DELETE, |
{ "word-delete", EC_W_DELETE }, |
"word-left", EC_W_RIGHT, |
{ "word-left", EC_W_LEFT }, |
"word-right", EC_W_LEFT, |
{ "word-right", EC_W_RIGHT }, |
NULL, 0 |
{ NULL, 0 } |
}; |
}; |
|
|
struct table |
struct table |
|
|
|
|
struct table cmdtable; |
struct table cmdtable; |
struct table edittable; |
struct table edittable; |
|
struct table vartable; |
struct table *currtable = &cmdtable; |
struct table *currtable = &cmdtable; |
|
|
char fileheader[] = { |
char fileheader[] = { |
|
|
}; |
}; |
char cmdsection[1] = { CMD_SECTION }; |
char cmdsection[1] = { CMD_SECTION }; |
char editsection[1] = { EDIT_SECTION }; |
char editsection[1] = { EDIT_SECTION }; |
|
char varsection[1] = { VAR_SECTION }; |
char endsection[1] = { END_SECTION }; |
char endsection[1] = { END_SECTION }; |
|
|
char *infile = NULL; |
char *infile = NULL; |
|
|
|
|
extern char version[]; |
extern char version[]; |
|
|
|
void |
|
usage() |
|
{ |
|
fprintf(stderr, "usage: lesskey [-o output] [input]\n"); |
|
exit(1); |
|
} |
|
|
char * |
char * |
mkpathname(dirname, filename) |
mkpathname(dirname, filename) |
char *dirname; |
char *dirname; |
|
|
len = strlen(dirname) + strlen(filename) + 2; |
len = strlen(dirname) + strlen(filename) + 2; |
pathname = calloc(len, sizeof(char)); |
pathname = calloc(len, sizeof(char)); |
strlcpy(pathname, dirname, len); |
strlcpy(pathname, dirname, len); |
#if MSOFTC || OS2 |
strlcat(pathname, PATHNAME_SEP, len); |
strlcat(pathname, "\\", len); |
|
#else |
|
strlcat(pathname, "/", len); |
|
#endif |
|
strlcat(pathname, filename, len); |
strlcat(pathname, filename, len); |
return (pathname); |
return (pathname); |
} |
} |
|
|
int argc; |
int argc; |
char **argv; |
char **argv; |
{ |
{ |
|
char *arg; |
|
|
outfile = NULL; |
outfile = NULL; |
while (--argc > 0 && **(++argv) == '-' && argv[0][1] != '\0') |
while (--argc > 0) |
{ |
{ |
switch (argv[0][1]) |
arg = *++argv; |
|
if (arg[0] != '-') |
|
/* Arg does not start with "-"; it's not an option. */ |
|
break; |
|
if (arg[1] == '\0') |
|
/* "-" means standard input. */ |
|
break; |
|
if (arg[1] == '-' && arg[2] == '\0') |
{ |
{ |
|
/* "--" means end of options. */ |
|
argc--; |
|
argv++; |
|
break; |
|
} |
|
switch (arg[1]) |
|
{ |
|
case '-': |
|
if (strncmp(arg, "--output", 8) == 0) |
|
{ |
|
if (arg[8] == '\0') |
|
outfile = &arg[8]; |
|
else if (arg[8] == '=') |
|
outfile = &arg[9]; |
|
else |
|
usage(); |
|
goto opt_o; |
|
} |
|
if (strcmp(arg, "--version") == 0) |
|
{ |
|
goto opt_V; |
|
} |
|
usage(); |
|
break; |
case 'o': |
case 'o': |
outfile = &argv[0][2]; |
outfile = &argv[0][2]; |
|
opt_o: |
if (*outfile == '\0') |
if (*outfile == '\0') |
{ |
{ |
if (--argc <= 0) |
if (--argc <= 0) |
|
|
} |
} |
break; |
break; |
case 'V': |
case 'V': |
|
opt_V: |
printf("lesskey version %s\n", version); |
printf("lesskey version %s\n", version); |
exit(0); |
exit(0); |
default: |
default: |
|
|
|
|
edittable.names = editnames; |
edittable.names = editnames; |
edittable.pbuffer = edittable.buffer; |
edittable.pbuffer = edittable.buffer; |
|
|
|
vartable.names = NULL; |
|
vartable.pbuffer = vartable.buffer; |
} |
} |
|
|
/* |
/* |
* Parse one character of a string. |
* Parse one character of a string. |
*/ |
*/ |
int |
char * |
tchar(pp) |
tstr(pp, xlate) |
char **pp; |
char **pp; |
|
int xlate; |
{ |
{ |
char *p; |
register char *p; |
char ch; |
register char ch; |
int i; |
register int i; |
|
static char buf[10]; |
|
static char tstr_control_k[] = |
|
{ SK_SPECIAL_KEY, SK_CONTROL_K, 6, 1, 1, 1, '\0' }; |
|
|
p = *pp; |
p = *pp; |
switch (*p) |
switch (*p) |
|
|
ch = 8*ch + (*p - '0'); |
ch = 8*ch + (*p - '0'); |
while (*++p >= '0' && *p <= '7' && ++i < 3); |
while (*++p >= '0' && *p <= '7' && ++i < 3); |
*pp = p; |
*pp = p; |
return (ch); |
if (xlate && ch == CONTROL('K')) |
|
return tstr_control_k; |
|
buf[0] = ch; |
|
buf[1] = '\0'; |
|
return (buf); |
case 'b': |
case 'b': |
*pp = p+1; |
*pp = p+1; |
return ('\r'); |
return ("\b"); |
case 'e': |
case 'e': |
*pp = p+1; |
*pp = p+1; |
return (ESC); |
buf[0] = ESC; |
|
buf[1] = '\0'; |
|
return (buf); |
case 'n': |
case 'n': |
*pp = p+1; |
*pp = p+1; |
return ('\n'); |
return ("\n"); |
case 'r': |
case 'r': |
*pp = p+1; |
*pp = p+1; |
return ('\r'); |
return ("\r"); |
case 't': |
case 't': |
*pp = p+1; |
*pp = p+1; |
return ('\t'); |
return ("\t"); |
|
case 'k': |
|
if (xlate) |
|
{ |
|
switch (*++p) |
|
{ |
|
case 'u': ch = SK_UP_ARROW; break; |
|
case 'd': ch = SK_DOWN_ARROW; break; |
|
case 'r': ch = SK_RIGHT_ARROW; break; |
|
case 'l': ch = SK_LEFT_ARROW; break; |
|
case 'U': ch = SK_PAGE_UP; break; |
|
case 'D': ch = SK_PAGE_DOWN; break; |
|
case 'h': ch = SK_HOME; break; |
|
case 'e': ch = SK_END; break; |
|
case 'x': ch = SK_DELETE; break; |
|
default: |
|
error("illegal char after \\k"); |
|
*pp = p+1; |
|
return (""); |
|
} |
|
*pp = p+1; |
|
buf[0] = SK_SPECIAL_KEY; |
|
buf[1] = ch; |
|
buf[2] = 6; |
|
buf[3] = 1; |
|
buf[4] = 1; |
|
buf[5] = 1; |
|
buf[6] = '\0'; |
|
return (buf); |
|
} |
|
/* FALLTHRU */ |
default: |
default: |
/* |
/* |
* Backslash followed by any other char |
* Backslash followed by any other char |
* just means that char. |
* just means that char. |
*/ |
*/ |
*pp = p+1; |
*pp = p+1; |
return (*p); |
buf[0] = *p; |
|
buf[1] = '\0'; |
|
if (xlate && buf[0] == CONTROL('K')) |
|
return tstr_control_k; |
|
return (buf); |
} |
} |
case '^': |
case '^': |
/* |
/* |
* Carat means CONTROL. |
* Carat means CONTROL. |
*/ |
*/ |
*pp = p+2; |
*pp = p+2; |
return (CONTROL(p[1])); |
buf[0] = CONTROL(p[1]); |
|
buf[1] = '\0'; |
|
if (buf[0] == CONTROL('K')) |
|
return tstr_control_k; |
|
return (buf); |
} |
} |
*pp = p+1; |
*pp = p+1; |
return (*p); |
buf[0] = *p; |
|
buf[1] = '\0'; |
|
if (xlate && buf[0] == CONTROL('K')) |
|
return tstr_control_k; |
|
return (buf); |
} |
} |
|
|
/* |
/* |
|
|
*/ |
*/ |
public char * |
public char * |
skipsp(s) |
skipsp(s) |
char *s; |
register char *s; |
{ |
{ |
while (*s == ' ' || *s == '\t') |
while (*s == ' ' || *s == '\t') |
s++; |
s++; |
|
|
*/ |
*/ |
public char * |
public char * |
skipnsp(s) |
skipnsp(s) |
char *s; |
register char *s; |
{ |
{ |
while (*s != '\0' && *s != ' ' && *s != '\t') |
while (*s != '\0' && *s != ' ' && *s != '\t') |
s++; |
s++; |
|
|
clean_line(s) |
clean_line(s) |
char *s; |
char *s; |
{ |
{ |
int i; |
register int i; |
|
|
s = skipsp(s); |
s = skipsp(s); |
for (i = 0; s[i] != '\n' && s[i] != '\0'; i++) |
for (i = 0; s[i] != '\n' && s[i] != '\r' && s[i] != '\0'; i++) |
if (s[i] == '#' && (i == 0 || s[i-1] != '\\')) |
if (s[i] == '#' && (i == 0 || s[i-1] != '\\')) |
break; |
break; |
s[i] = '\0'; |
s[i] = '\0'; |
|
|
} |
} |
|
|
/* |
/* |
|
* Add a string to the output command table. |
|
*/ |
|
void |
|
add_cmd_str(s) |
|
char *s; |
|
{ |
|
for ( ; *s != '\0'; s++) |
|
add_cmd_char(*s); |
|
} |
|
|
|
/* |
* See if we have a special "control" line. |
* See if we have a special "control" line. |
*/ |
*/ |
int |
int |
|
|
currtable = &cmdtable; |
currtable = &cmdtable; |
return (1); |
return (1); |
} |
} |
|
if (PREFIX(s, "#env")) |
|
{ |
|
currtable = &vartable; |
|
return (1); |
|
} |
if (PREFIX(s, "#stop")) |
if (PREFIX(s, "#stop")) |
{ |
{ |
add_cmd_char('\0'); |
add_cmd_char('\0'); |
|
|
return (A_INVALID); |
return (A_INVALID); |
} |
} |
|
|
usage() |
|
{ |
|
fprintf(stderr, "usage: lesskey [-o output] [input]\n"); |
|
exit(1); |
|
} |
|
|
|
void |
void |
error(s) |
error(s) |
char *s; |
char *s; |
|
|
} |
} |
|
|
|
|
/* |
|
* Parse a line from the lesskey file. |
|
*/ |
|
void |
void |
parse_line(line) |
parse_cmdline(p) |
char *line; |
|
{ |
|
char *p; |
char *p; |
|
{ |
int cmdlen; |
int cmdlen; |
char *actname; |
char *actname; |
int action; |
int action; |
int c; |
char *s; |
|
char c; |
|
|
/* |
/* |
* See if it is a control line. |
|
*/ |
|
if (control_line(line)) |
|
return; |
|
/* |
|
* Skip leading white space. |
|
* Replace the final newline with a null byte. |
|
* Ignore blank lines and comments. |
|
*/ |
|
p = clean_line(line); |
|
if (*p == '\0') |
|
return; |
|
|
|
/* |
|
* Parse the command string and store it in the current table. |
* Parse the command string and store it in the current table. |
*/ |
*/ |
cmdlen = 0; |
cmdlen = 0; |
do |
do |
{ |
{ |
c = tchar(&p); |
s = tstr(&p, 1); |
if (++cmdlen > MAX_CMDLEN) |
cmdlen += strlen(s); |
|
if (cmdlen > MAX_CMDLEN) |
error("command too long"); |
error("command too long"); |
else |
else |
add_cmd_char(c); |
add_cmd_str(s); |
} while (*p != ' ' && *p != '\t' && *p != '\0'); |
} while (*p != ' ' && *p != '\t' && *p != '\0'); |
/* |
/* |
* Terminate the command string with a null byte. |
* Terminate the command string with a null byte. |
|
|
*/ |
*/ |
add_cmd_char(action | A_EXTRA); |
add_cmd_char(action | A_EXTRA); |
while (*p != '\0') |
while (*p != '\0') |
add_cmd_char(tchar(&p)); |
add_cmd_str(tstr(&p, 0)); |
add_cmd_char('\0'); |
add_cmd_char('\0'); |
} |
} |
} |
} |
|
|
|
void |
|
parse_varline(p) |
|
char *p; |
|
{ |
|
char *s; |
|
|
|
do |
|
{ |
|
s = tstr(&p, 0); |
|
add_cmd_str(s); |
|
} while (*p != ' ' && *p != '\t' && *p != '=' && *p != '\0'); |
|
/* |
|
* Terminate the variable name with a null byte. |
|
*/ |
|
add_cmd_char('\0'); |
|
|
|
p = skipsp(p); |
|
if (*p++ != '=') |
|
{ |
|
error("missing ="); |
|
return; |
|
} |
|
|
|
add_cmd_char(EV_OK|A_EXTRA); |
|
|
|
p = skipsp(p); |
|
while (*p != '\0') |
|
{ |
|
s = tstr(&p, 0); |
|
add_cmd_str(s); |
|
} |
|
add_cmd_char('\0'); |
|
} |
|
|
|
/* |
|
* Parse a line from the lesskey file. |
|
*/ |
|
void |
|
parse_line(line) |
|
char *line; |
|
{ |
|
char *p; |
|
|
|
/* |
|
* See if it is a control line. |
|
*/ |
|
if (control_line(line)) |
|
return; |
|
/* |
|
* Skip leading white space. |
|
* Replace the final newline with a null byte. |
|
* Ignore blank lines and comments. |
|
*/ |
|
p = clean_line(line); |
|
if (*p == '\0') |
|
return; |
|
|
|
if (currtable == &vartable) |
|
parse_varline(p); |
|
else |
|
parse_cmdline(p); |
|
} |
|
|
|
int |
main(argc, argv) |
main(argc, argv) |
int argc; |
int argc; |
char *argv[]; |
char *argv[]; |
{ |
{ |
FILE *desc; |
FILE *desc; |
FILE *out; |
FILE *out; |
char line[200]; |
char line[1024]; |
|
|
|
#ifdef WIN32 |
|
if (getenv("HOME") == NULL) |
|
{ |
|
/* |
|
* If there is no HOME environment variable, |
|
* try the concatenation of HOMEDRIVE + HOMEPATH. |
|
*/ |
|
char *drive = getenv("HOMEDRIVE"); |
|
char *path = getenv("HOMEPATH"); |
|
if (drive != NULL && path != NULL) |
|
{ |
|
size_t len = strlen(drive) + strlen(path) + 6; |
|
char *env = (char *) calloc(len, sizeof(char)); |
|
strlcpy(env, "HOME=", len); |
|
strlcat(env, drive, len); |
|
strlcat(env, path, len); |
|
putenv(env); |
|
} |
|
} |
|
#endif /* WIN32 */ |
|
|
/* |
/* |
* Process command line arguments. |
* Process command line arguments. |
*/ |
*/ |
|
|
desc = stdin; |
desc = stdin; |
else if ((desc = fopen(infile, "r")) == NULL) |
else if ((desc = fopen(infile, "r")) == NULL) |
{ |
{ |
|
#if HAVE_PERROR |
perror(infile); |
perror(infile); |
exit(1); |
#else |
|
fprintf(stderr, "Cannot open %s\n", infile); |
|
#endif |
|
usage(); |
} |
} |
|
|
/* |
/* |
|
|
} |
} |
|
|
if (outfile == NULL) |
if (outfile == NULL) |
|
outfile = getenv("LESSKEY"); |
|
if (outfile == NULL) |
outfile = homefile(LESSKEYFILE); |
outfile = homefile(LESSKEYFILE); |
if ((out = fopen(outfile, "wb")) == NULL) |
if ((out = fopen(outfile, "wb")) == NULL) |
{ |
{ |
|
#if HAVE_PERROR |
perror(outfile); |
perror(outfile); |
|
#else |
|
fprintf(stderr, "Cannot open %s\n", outfile); |
|
#endif |
exit(1); |
exit(1); |
} |
} |
|
|
|
|
fputint(out, edittable.pbuffer - edittable.buffer); |
fputint(out, edittable.pbuffer - edittable.buffer); |
fputbytes(out, (char *)edittable.buffer, edittable.pbuffer-edittable.buffer); |
fputbytes(out, (char *)edittable.buffer, edittable.pbuffer-edittable.buffer); |
|
|
|
/* Environment variable section */ |
|
fputbytes(out, varsection, sizeof(varsection)); |
|
fputint(out, vartable.pbuffer - vartable.buffer); |
|
fputbytes(out, (char *)vartable.buffer, vartable.pbuffer-vartable.buffer); |
|
|
/* File trailer */ |
/* File trailer */ |
fputbytes(out, endsection, sizeof(endsection)); |
fputbytes(out, endsection, sizeof(endsection)); |
fputbytes(out, filetrailer, sizeof(filetrailer)); |
fputbytes(out, filetrailer, sizeof(filetrailer)); |
exit(0); |
return (0); |
} |
} |