Skip to content

Commit

Permalink
Change #version '<>' operator to '!='.
Browse files Browse the repository at this point in the history
Tweak error messages a little.
  • Loading branch information
gwsw committed Sep 6, 2021
1 parent dc1a097 commit 4f7b8d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
7 changes: 4 additions & 3 deletions lesskey.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ This can be helpful if a lesskey file is used by different versions of
For example, suppose that a new command named 'sideways-search' is added in version 777.
Then the following line would assign the command to the Q key, but only in versions of
.I less
which support it. The line would be ignored in earlier versions.
which support it. The line would be ignored by earlier versions.
.sp
.nf
#version >= 777 Q sideways-search
Expand All @@ -382,11 +382,12 @@ l l.
>= Greater than or equal to
<= Less than or equal to
= Equal to
<> Not equal to
!= Not equal to
.TE
.RE
.sp
In version 594 and earlier, all #version lines are ignored,
Due to lack of both foresight and time travel,
all #version lines are ignored in version 594 and all earlier versions,
regardless of the result of the relational operator.
.
.SH "SEE ALSO"
Expand Down
38 changes: 17 additions & 21 deletions lesskey_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ static struct lesskey_cmdname editnames[] =
* Print a parse error message.
*/
static void
parse_error(s1, s2)
char *s1;
char *s2;
parse_error(fmt, arg1)
char *fmt;
char *arg1;
{
char buf[1024];
int n = snprintf(buf, sizeof(buf), "%s: line %d: ", lesskey_file, linenum);
snprintf(buf+n, sizeof(buf)-n, fmt, arg1);
++errors;
snprintf(buf, sizeof(buf), "%s: line %d: %s%s", lesskey_file, linenum, s1, s2);
lesskey_parse_error(buf);
}

Expand Down Expand Up @@ -237,7 +238,7 @@ tstr(pp, xlate)
case 'X': ch = SK_CTL_DELETE; break;
case '1': ch = SK_F1; break;
default: { char buf[2]; buf[0] = *p; buf[1] = '\0';
parse_error("illegal escape sequence \\k", buf);
parse_error("invalid escape sequence \"\\k%s\"", buf);
*pp = p+1;
return (""); }
}
Expand Down Expand Up @@ -374,7 +375,7 @@ match_version(op, ver)
case '!': return less_version != ver;
default: {
char sop[2] = { op, '\0' };
parse_error("invalid operator in #version: ", sop);
parse_error("invalid operator '%s' in #version", sop);
return 0; }
}
}
Expand All @@ -396,24 +397,19 @@ version_line(s, tables)
s += strlen("#version");
s = skipsp(s);
op = *s++;
if (op == '<' && *s == '=')
{
op = '-';
s++;
} else if (op == '>' && *s == '=')
{
op = '+';
s++;
} else if (op == '<' && *s == '>')
/* Simplify 2-char op to one char. */
switch (op)
{
op = '!';
s++;
case '<': if (*s == '=') { s++; op = '-'; } break;
case '>': if (*s == '=') { s++; op = '+'; } break;
case '=': if (*s == '=') { s++; } break;
case '!': if (*s == '=') { s++; } break;
}
s = skipsp(s);
ver = lstrtoi(s, &e);
if (e == s)
{
parse_error("invalid version number in #version: ", s);
parse_error("non-numeric version number in #version", "");
return (NULL);
}
if (!match_version(op, ver))
Expand Down Expand Up @@ -472,7 +468,7 @@ findaction(actname, tables)
for (i = 0; tables->currtable->names[i].cn_name != NULL; i++)
if (strcmp(tables->currtable->names[i].cn_name, actname) == 0)
return (tables->currtable->names[i].cn_action);
parse_error("unknown action: ", actname);
parse_error("unknown action: \"%s\"", actname);
return (A_INVALID);
}

Expand Down Expand Up @@ -573,7 +569,7 @@ parse_varline(line, tables)
p = skipsp(p);
if (*p++ != '=')
{
parse_error("missing = in: ", line);
parse_error("missing = in variable definition", "");
return;
}

Expand Down Expand Up @@ -647,7 +643,7 @@ parse_lesskey(infile, tables)
desc = stdin;
else if ((desc = fopen(infile, "r")) == NULL)
{
/* parse_error("cannot open lesskey file ", infile); */
/* parse_error("cannot open lesskey file %s", infile); */
return (-1);
}

Expand Down

0 comments on commit 4f7b8d9

Please sign in to comment.