2
* Copyright (C) 1984-2000 Mark Nudelman
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.
7
* For more information about less, or for information on how to
8
* contact the author, see the README file.
13
* lessecho [-ox] [-cx] [-pn] [-dn] [-a] file ...
14
* Simply echos its filename arguments on standard output.
15
* But any argument containing spaces is enclosed in quotes.
17
* -ox Specifies "x" to be the open quote character.
18
* -cx Specifies "x" to be the close quote character.
19
* -pn Specifies "n" to be the open quote character, as an integer.
20
* -dn Specifies "n" to be the close quote character, as an integer.
21
* -mx Specifies "x" to be a metachar.
22
* -nn Specifies "n" to be a metachar, as an integer.
23
* -ex Specifies "x" to be the escape char for metachars.
24
* -fn Specifies "x" to be the escape char for metachars, as an integer.
25
* -a Specifies that all arguments are to be quoted.
26
* The default is that only arguments containing spaces are quoted.
31
static char *version = "$Revision: 1.7 $";
33
static int quote_all = 0;
34
static char openquote = '"';
35
static char closequote = '"';
36
static char *meta_escape = "\\";
37
static char metachars[64] = "";
38
static int num_metachars = 0;
44
"usage: lessecho [-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-a] file ...\n");
54
for (p = version; *p != ' '; p++)
57
for (p++; *p != '$' && *p != ' ' && *p != '\0'; p++)
67
fprintf(stderr, "%s\n", s);
72
lstrtol(s, radix, pend)
81
/* Skip leading white space. */
82
while (*s == ' ' || *s == '\t')
85
/* Check for a leading + or -. */
95
/* Determine radix if caller does not specify. */
114
/* Parse the digits of the number. */
117
if (*s >= '0' && *s <= '9')
119
else if (*s >= 'a' && *s <= 'f')
121
else if (*s >= 'A' && *s <= 'F')
133
/* Skip trailing white space. */
134
while (*s == ' ' || *s == '\t')
150
for ( ; *s != '\0'; s++)
172
if (*arg != '-' || no_more_options)
183
closequote = lstrtol(++arg, 0, &s);
185
pr_error("Missing number after -d");
188
if (strcmp(++arg, "-") == 0)
197
openquote = lstrtol(++arg, 0, &s);
199
pr_error("Missing number after -p");
202
metachars[num_metachars++] = *++arg;
203
metachars[num_metachars] = '\0';
206
metachars[num_metachars++] = lstrtol(++arg, 0, &s);
208
pr_error("Missing number after -n");
209
metachars[num_metachars] = '\0';
220
if (strcmp(arg, "version") == 0)
225
if (strcmp(arg, "help") == 0)
230
pr_error("Invalid option after --");
232
pr_error("Invalid option letter");
240
for (s = arg; *s != '\0'; s++)
242
if (strchr(metachars, *s) != NULL)
248
if (quote_all || (has_meta && strlen(meta_escape) == 0))
249
printf("%c%s%c", openquote, arg, closequote);
252
for (s = arg; *s != '\0'; s++)
254
if (strchr(metachars, *s) != NULL)
255
printf("%s", meta_escape);