diff options
author | Tim J. Robbins <tjr@FreeBSD.org> | 2004-04-17 07:16:34 +0000 |
---|---|---|
committer | Tim J. Robbins <tjr@FreeBSD.org> | 2004-04-17 07:16:34 +0000 |
commit | 000ba3e8196af5b890e39cbe6e7d007d08fae507 (patch) | |
tree | f46d7e51d83360c5b6bdacf5b08e16a415ed61b5 /contrib/less/lessecho.c | |
parent | c9346414d95d69f958210e825deb3b086dac3529 (diff) | |
download | src-000ba3e8196af5b890e39cbe6e7d007d08fae507.tar.gz src-000ba3e8196af5b890e39cbe6e7d007d08fae507.zip |
Notes
Diffstat (limited to 'contrib/less/lessecho.c')
-rw-r--r-- | contrib/less/lessecho.c | 72 |
1 files changed, 59 insertions, 13 deletions
diff --git a/contrib/less/lessecho.c b/contrib/less/lessecho.c index 03739fc98833..6fa41ef4ba05 100644 --- a/contrib/less/lessecho.c +++ b/contrib/less/lessecho.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2000 Mark Nudelman + * Copyright (C) 1984-2002 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -18,23 +18,31 @@ * -cx Specifies "x" to be the close quote character. * -pn Specifies "n" to be the open quote character, as an integer. * -dn Specifies "n" to be the close quote character, as an integer. + * -mx Specifies "x" to be a metachar. + * -nn Specifies "n" to be a metachar, as an integer. + * -ex Specifies "x" to be the escape char for metachars. + * -fn Specifies "x" to be the escape char for metachars, as an integer. * -a Specifies that all arguments are to be quoted. * The default is that only arguments containing spaces are quoted. */ #include "less.h" -static char *version = "$Revision: 1.6 $"; +static char *version = "$Revision: 1.9 $"; static int quote_all = 0; static char openquote = '"'; static char closequote = '"'; +static char *meta_escape = "\\"; +static char meta_escape_buf[2]; +static char metachars[64] = ""; +static int num_metachars = 0; static void pr_usage() { fprintf(stderr, - "usage: lessecho [-ox] [-cx] [-pn] [-dn] [-a] file ...\n"); + "usage: lessecho [-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-fn] [-a] file ...\n"); } static void @@ -169,21 +177,43 @@ main(argc, argv) case 'a': quote_all = 1; break; - case 'o': - openquote = *++arg; - break; case 'c': closequote = *++arg; break; + case 'd': + closequote = lstrtol(++arg, 0, &s); + if (s == arg) + pr_error("Missing number after -d"); + break; + case 'e': + if (strcmp(++arg, "-") == 0) + meta_escape = ""; + else + meta_escape = arg; + break; + case 'f': + meta_escape_buf[0] = lstrtol(++arg, 0, &s); + meta_escape = meta_escape_buf; + if (s == arg) + pr_error("Missing number after -f"); + break; + case 'o': + openquote = *++arg; + break; case 'p': openquote = lstrtol(++arg, 0, &s); if (s == arg) - pr_error("Missing number after -O"); + pr_error("Missing number after -p"); break; - case 'd': - closequote = lstrtol(++arg, 0, &s); + case 'm': + metachars[num_metachars++] = *++arg; + metachars[num_metachars] = '\0'; + break; + case 'n': + metachars[num_metachars++] = lstrtol(++arg, 0, &s); if (s == arg) - pr_error("Missing number after -C"); + pr_error("Missing number after -n"); + metachars[num_metachars] = '\0'; break; case '?': pr_usage(); @@ -212,11 +242,27 @@ main(argc, argv) while (argc-- > 0) { + int has_meta = 0; arg = *argv++; - if (quote_all || strchr(arg, ' ') != NULL) + for (s = arg; *s != '\0'; s++) + { + if (strchr(metachars, *s) != NULL) + { + has_meta = 1; + break; + } + } + if (quote_all || (has_meta && strlen(meta_escape) == 0)) printf("%c%s%c", openquote, arg, closequote); - else - printf("%s", arg); + else + { + for (s = arg; *s != '\0'; s++) + { + if (strchr(metachars, *s) != NULL) + printf("%s", meta_escape); + printf("%c", *s); + } + } if (argc > 0) printf(" "); else |