Deleted Added
full compact
lesskey.c (89019) lesskey.c (128345)
1/*
1/*
2 * Copyright (C) 1984-2000 Mark Nudelman
2 * Copyright (C) 1984-2002 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

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

88struct cmdname
89{
90 char *cn_name;
91 int cn_action;
92};
93
94struct cmdname cmdnames[] =
95{
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

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

88struct cmdname
89{
90 char *cn_name;
91 int cn_action;
92};
93
94struct cmdname cmdnames[] =
95{
96 "back-bracket", A_B_BRACKET,
97 "back-line", A_B_LINE,
98 "back-line-force", A_BF_LINE,
99 "back-screen", A_B_SCREEN,
100 "back-scroll", A_B_SCROLL,
101 "back-search", A_B_SEARCH,
102 "back-window", A_B_WINDOW,
103 "debug", A_DEBUG,
104 "digit", A_DIGIT,
105 "display-flag", A_DISP_OPTION,
106 "display-option", A_DISP_OPTION,
107 "end", A_GOEND,
108 "examine", A_EXAMINE,
109 "first-cmd", A_FIRSTCMD,
110 "firstcmd", A_FIRSTCMD,
111 "flush-repaint", A_FREPAINT,
112 "forw-bracket", A_F_BRACKET,
113 "forw-forever", A_F_FOREVER,
114 "forw-line", A_F_LINE,
115 "forw-line-force", A_FF_LINE,
116 "forw-screen", A_F_SCREEN,
117 "forw-screen-force", A_FF_SCREEN,
118 "forw-scroll", A_F_SCROLL,
119 "forw-search", A_F_SEARCH,
120 "forw-window", A_F_WINDOW,
121 "goto-end", A_GOEND,
122 "goto-line", A_GOLINE,
123 "goto-mark", A_GOMARK,
124 "help", A_HELP,
125 "index-file", A_INDEX_FILE,
126 "invalid", A_UINVALID,
127 "left-scroll", A_LSHIFT,
128 "next-file", A_NEXT_FILE,
129 "next-tag", A_NEXT_TAG,
130 "noaction", A_NOACTION,
131 "percent", A_PERCENT,
132 "pipe", A_PIPE,
133 "prev-file", A_PREV_FILE,
134 "prev-tag", A_PREV_TAG,
135 "quit", A_QUIT,
136 "remove-file", A_REMOVE_FILE,
137 "repaint", A_REPAINT,
138 "repaint-flush", A_FREPAINT,
139 "repeat-search", A_AGAIN_SEARCH,
140 "repeat-search-all", A_T_AGAIN_SEARCH,
141 "reverse-search", A_REVERSE_SEARCH,
142 "reverse-search-all", A_T_REVERSE_SEARCH,
143 "right-scroll", A_RSHIFT,
144 "set-mark", A_SETMARK,
145 "shell", A_SHELL,
146 "status", A_STAT,
147 "toggle-flag", A_OPT_TOGGLE,
148 "toggle-option", A_OPT_TOGGLE,
149 "undo-hilite", A_UNDO_SEARCH,
150 "version", A_VERSION,
151 "visual", A_VISUAL,
152 NULL, 0
96 { "back-bracket", A_B_BRACKET },
97 { "back-line", A_B_LINE },
98 { "back-line-force", A_BF_LINE },
99 { "back-screen", A_B_SCREEN },
100 { "back-scroll", A_B_SCROLL },
101 { "back-search", A_B_SEARCH },
102 { "back-window", A_B_WINDOW },
103 { "debug", A_DEBUG },
104 { "digit", A_DIGIT },
105 { "display-flag", A_DISP_OPTION },
106 { "display-option", A_DISP_OPTION },
107 { "end", A_GOEND },
108 { "examine", A_EXAMINE },
109 { "first-cmd", A_FIRSTCMD },
110 { "firstcmd", A_FIRSTCMD },
111 { "flush-repaint", A_FREPAINT },
112 { "forw-bracket", A_F_BRACKET },
113 { "forw-forever", A_F_FOREVER },
114 { "forw-line", A_F_LINE },
115 { "forw-line-force", A_FF_LINE },
116 { "forw-screen", A_F_SCREEN },
117 { "forw-screen-force", A_FF_SCREEN },
118 { "forw-scroll", A_F_SCROLL },
119 { "forw-search", A_F_SEARCH },
120 { "forw-window", A_F_WINDOW },
121 { "goto-end", A_GOEND },
122 { "goto-line", A_GOLINE },
123 { "goto-mark", A_GOMARK },
124 { "help", A_HELP },
125 { "index-file", A_INDEX_FILE },
126 { "invalid", A_UINVALID },
127 { "left-scroll", A_LSHIFT },
128 { "next-file", A_NEXT_FILE },
129 { "next-tag", A_NEXT_TAG },
130 { "noaction", A_NOACTION },
131 { "percent", A_PERCENT },
132 { "pipe", A_PIPE },
133 { "prev-file", A_PREV_FILE },
134 { "prev-tag", A_PREV_TAG },
135 { "quit", A_QUIT },
136 { "remove-file", A_REMOVE_FILE },
137 { "repaint", A_REPAINT },
138 { "repaint-flush", A_FREPAINT },
139 { "repeat-search", A_AGAIN_SEARCH },
140 { "repeat-search-all", A_T_AGAIN_SEARCH },
141 { "reverse-search", A_REVERSE_SEARCH },
142 { "reverse-search-all", A_T_REVERSE_SEARCH },
143 { "right-scroll", A_RSHIFT },
144 { "set-mark", A_SETMARK },
145 { "shell", A_SHELL },
146 { "status", A_STAT },
147 { "toggle-flag", A_OPT_TOGGLE },
148 { "toggle-option", A_OPT_TOGGLE },
149 { "undo-hilite", A_UNDO_SEARCH },
150 { "version", A_VERSION },
151 { "visual", A_VISUAL },
152 { NULL, 0 }
153};
154
155struct cmdname editnames[] =
156{
153};
154
155struct cmdname editnames[] =
156{
157 "back-complete", EC_B_COMPLETE,
158 "backspace", EC_BACKSPACE,
159 "delete", EC_DELETE,
160 "down", EC_DOWN,
161 "end", EC_END,
162 "expand", EC_EXPAND,
163 "forw-complete", EC_F_COMPLETE,
164 "home", EC_HOME,
165 "insert", EC_INSERT,
166 "invalid", EC_UINVALID,
167 "kill-line", EC_LINEKILL,
168 "left", EC_LEFT,
169 "literal", EC_LITERAL,
170 "right", EC_RIGHT,
171 "up", EC_UP,
172 "word-backspace", EC_W_BACKSPACE,
173 "word-delete", EC_W_DELETE,
174 "word-left", EC_W_LEFT,
175 "word-right", EC_W_RIGHT,
176 NULL, 0
157 { "back-complete", EC_B_COMPLETE },
158 { "backspace", EC_BACKSPACE },
159 { "delete", EC_DELETE },
160 { "down", EC_DOWN },
161 { "end", EC_END },
162 { "expand", EC_EXPAND },
163 { "forw-complete", EC_F_COMPLETE },
164 { "home", EC_HOME },
165 { "insert", EC_INSERT },
166 { "invalid", EC_UINVALID },
167 { "kill-line", EC_LINEKILL },
168 { "left", EC_LEFT },
169 { "literal", EC_LITERAL },
170 { "right", EC_RIGHT },
171 { "up", EC_UP },
172 { "word-backspace", EC_W_BACKSPACE },
173 { "word-delete", EC_W_DELETE },
174 { "word-left", EC_W_LEFT },
175 { "word-right", EC_W_RIGHT },
176 { NULL, 0 }
177};
178
179struct table
180{
181 struct cmdname *names;
182 char *pbuffer;
183 char buffer[MAX_USERCMD];
184};

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

347 vartable.names = NULL;
348 vartable.pbuffer = vartable.buffer;
349}
350
351/*
352 * Parse one character of a string.
353 */
354 char *
177};
178
179struct table
180{
181 struct cmdname *names;
182 char *pbuffer;
183 char buffer[MAX_USERCMD];
184};

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

347 vartable.names = NULL;
348 vartable.pbuffer = vartable.buffer;
349}
350
351/*
352 * Parse one character of a string.
353 */
354 char *
355tstr(pp)
355tstr(pp, xlate)
356 char **pp;
356 char **pp;
357 int xlate;
357{
358 register char *p;
359 register char ch;
360 register int i;
361 static char buf[10];
362 static char tstr_control_k[] =
363 { SK_SPECIAL_KEY, SK_CONTROL_K, 6, 1, 1, 1, '\0' };
364

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

375 * Parse an octal number.
376 */
377 ch = 0;
378 i = 0;
379 do
380 ch = 8*ch + (*p - '0');
381 while (*++p >= '0' && *p <= '7' && ++i < 3);
382 *pp = p;
358{
359 register char *p;
360 register char ch;
361 register int i;
362 static char buf[10];
363 static char tstr_control_k[] =
364 { SK_SPECIAL_KEY, SK_CONTROL_K, 6, 1, 1, 1, '\0' };
365

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

376 * Parse an octal number.
377 */
378 ch = 0;
379 i = 0;
380 do
381 ch = 8*ch + (*p - '0');
382 while (*++p >= '0' && *p <= '7' && ++i < 3);
383 *pp = p;
383 if (ch == CONTROL('K'))
384 if (xlate && ch == CONTROL('K'))
384 return tstr_control_k;
385 buf[0] = ch;
386 buf[1] = '\0';
387 return (buf);
388 case 'b':
389 *pp = p+1;
390 return ("\b");
391 case 'e':

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

398 return ("\n");
399 case 'r':
400 *pp = p+1;
401 return ("\r");
402 case 't':
403 *pp = p+1;
404 return ("\t");
405 case 'k':
385 return tstr_control_k;
386 buf[0] = ch;
387 buf[1] = '\0';
388 return (buf);
389 case 'b':
390 *pp = p+1;
391 return ("\b");
392 case 'e':

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

399 return ("\n");
400 case 'r':
401 *pp = p+1;
402 return ("\r");
403 case 't':
404 *pp = p+1;
405 return ("\t");
406 case 'k':
406 switch (*++p)
407 if (xlate)
407 {
408 {
408 case 'u': ch = SK_UP_ARROW; break;
409 case 'd': ch = SK_DOWN_ARROW; break;
410 case 'r': ch = SK_RIGHT_ARROW; break;
411 case 'l': ch = SK_LEFT_ARROW; break;
412 case 'U': ch = SK_PAGE_UP; break;
413 case 'D': ch = SK_PAGE_DOWN; break;
414 case 'h': ch = SK_HOME; break;
415 case 'e': ch = SK_END; break;
416 case 'x': ch = SK_DELETE; break;
417 default:
418 error("illegal char after \\k");
409 switch (*++p)
410 {
411 case 'u': ch = SK_UP_ARROW; break;
412 case 'd': ch = SK_DOWN_ARROW; break;
413 case 'r': ch = SK_RIGHT_ARROW; break;
414 case 'l': ch = SK_LEFT_ARROW; break;
415 case 'U': ch = SK_PAGE_UP; break;
416 case 'D': ch = SK_PAGE_DOWN; break;
417 case 'h': ch = SK_HOME; break;
418 case 'e': ch = SK_END; break;
419 case 'x': ch = SK_DELETE; break;
420 default:
421 error("illegal char after \\k");
422 *pp = p+1;
423 return ("");
424 }
419 *pp = p+1;
425 *pp = p+1;
420 return ("");
426 buf[0] = SK_SPECIAL_KEY;
427 buf[1] = ch;
428 buf[2] = 6;
429 buf[3] = 1;
430 buf[4] = 1;
431 buf[5] = 1;
432 buf[6] = '\0';
433 return (buf);
421 }
434 }
422 *pp = p+1;
423 buf[0] = SK_SPECIAL_KEY;
424 buf[1] = ch;
425 buf[2] = 6;
426 buf[3] = 1;
427 buf[4] = 1;
428 buf[5] = 1;
429 buf[6] = '\0';
430 return (buf);
435 /* FALLTHRU */
431 default:
432 /*
433 * Backslash followed by any other char
434 * just means that char.
435 */
436 *pp = p+1;
437 buf[0] = *p;
438 buf[1] = '\0';
436 default:
437 /*
438 * Backslash followed by any other char
439 * just means that char.
440 */
441 *pp = p+1;
442 buf[0] = *p;
443 buf[1] = '\0';
439 if (buf[0] == CONTROL('K'))
444 if (xlate && buf[0] == CONTROL('K'))
440 return tstr_control_k;
441 return (buf);
442 }
443 case '^':
444 /*
445 * Carat means CONTROL.
446 */
447 *pp = p+2;
448 buf[0] = CONTROL(p[1]);
449 buf[1] = '\0';
450 if (buf[0] == CONTROL('K'))
451 return tstr_control_k;
452 return (buf);
453 }
454 *pp = p+1;
455 buf[0] = *p;
456 buf[1] = '\0';
445 return tstr_control_k;
446 return (buf);
447 }
448 case '^':
449 /*
450 * Carat means CONTROL.
451 */
452 *pp = p+2;
453 buf[0] = CONTROL(p[1]);
454 buf[1] = '\0';
455 if (buf[0] == CONTROL('K'))
456 return tstr_control_k;
457 return (buf);
458 }
459 *pp = p+1;
460 buf[0] = *p;
461 buf[1] = '\0';
457 if (buf[0] == CONTROL('K'))
462 if (xlate && buf[0] == CONTROL('K'))
458 return tstr_control_k;
459 return (buf);
460}
461
462/*
463 * Skip leading spaces in a string.
464 */
465 public char *

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

634 char c;
635
636 /*
637 * Parse the command string and store it in the current table.
638 */
639 cmdlen = 0;
640 do
641 {
463 return tstr_control_k;
464 return (buf);
465}
466
467/*
468 * Skip leading spaces in a string.
469 */
470 public char *

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

639 char c;
640
641 /*
642 * Parse the command string and store it in the current table.
643 */
644 cmdlen = 0;
645 do
646 {
642 s = tstr(&p);
647 s = tstr(&p, 1);
643 cmdlen += strlen(s);
644 if (cmdlen > MAX_CMDLEN)
645 error("command too long");
646 else
647 add_cmd_str(s);
648 } while (*p != ' ' && *p != '\t' && *p != '\0');
649 /*
650 * Terminate the command string with a null byte.

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

683 } else
684 {
685 /*
686 * OR the special value A_EXTRA into the action byte.
687 * Put the extra string after the action byte.
688 */
689 add_cmd_char(action | A_EXTRA);
690 while (*p != '\0')
648 cmdlen += strlen(s);
649 if (cmdlen > MAX_CMDLEN)
650 error("command too long");
651 else
652 add_cmd_str(s);
653 } while (*p != ' ' && *p != '\t' && *p != '\0');
654 /*
655 * Terminate the command string with a null byte.

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

688 } else
689 {
690 /*
691 * OR the special value A_EXTRA into the action byte.
692 * Put the extra string after the action byte.
693 */
694 add_cmd_char(action | A_EXTRA);
695 while (*p != '\0')
691 add_cmd_str(tstr(&p));
696 add_cmd_str(tstr(&p, 0));
692 add_cmd_char('\0');
693 }
694}
695
696 void
697parse_varline(p)
698 char *p;
699{
700 char *s;
701
702 do
703 {
697 add_cmd_char('\0');
698 }
699}
700
701 void
702parse_varline(p)
703 char *p;
704{
705 char *s;
706
707 do
708 {
704 s = tstr(&p);
709 s = tstr(&p, 0);
705 add_cmd_str(s);
706 } while (*p != ' ' && *p != '\t' && *p != '=' && *p != '\0');
707 /*
708 * Terminate the variable name with a null byte.
709 */
710 add_cmd_char('\0');
711
712 p = skipsp(p);
713 if (*p++ != '=')
714 {
715 error("missing =");
716 return;
717 }
718
719 add_cmd_char(EV_OK|A_EXTRA);
720
721 p = skipsp(p);
722 while (*p != '\0')
723 {
710 add_cmd_str(s);
711 } while (*p != ' ' && *p != '\t' && *p != '=' && *p != '\0');
712 /*
713 * Terminate the variable name with a null byte.
714 */
715 add_cmd_char('\0');
716
717 p = skipsp(p);
718 if (*p++ != '=')
719 {
720 error("missing =");
721 return;
722 }
723
724 add_cmd_char(EV_OK|A_EXTRA);
725
726 p = skipsp(p);
727 while (*p != '\0')
728 {
724 s = tstr(&p);
729 s = tstr(&p, 0);
725 add_cmd_str(s);
726 }
727 add_cmd_char('\0');
728}
729
730/*
731 * Parse a line from the lesskey file.
732 */

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

758
759 int
760main(argc, argv)
761 int argc;
762 char *argv[];
763{
764 FILE *desc;
765 FILE *out;
730 add_cmd_str(s);
731 }
732 add_cmd_char('\0');
733}
734
735/*
736 * Parse a line from the lesskey file.
737 */

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

763
764 int
765main(argc, argv)
766 int argc;
767 char *argv[];
768{
769 FILE *desc;
770 FILE *out;
766 char line[200];
771 char line[1024];
767
768#ifdef WIN32
769 if (getenv("HOME") == NULL)
770 {
771 /*
772 * If there is no HOME environment variable,
773 * try the concatenation of HOMEDRIVE + HOMEPATH.
774 */

--- 92 unchanged lines hidden ---
772
773#ifdef WIN32
774 if (getenv("HOME") == NULL)
775 {
776 /*
777 * If there is no HOME environment variable,
778 * try the concatenation of HOMEDRIVE + HOMEPATH.
779 */

--- 92 unchanged lines hidden ---