From 1ce849652bd6b35e10525e1def932b7ef84988d0 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 18 Dec 1998 17:49:51 +0000 Subject: [PATCH] Added -s option. --- ascii.c | 25 +++++++++++++++++++------ ascii.xml | 6 ++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ascii.c b/ascii.c index 3cf1a5f..030fec1 100644 --- a/ascii.c +++ b/ascii.c @@ -10,6 +10,7 @@ * v2.2 November 1997 -- merge in more changes by Ioannis Tambouras. * v2.3 November 1997 -- incorporated Colin Plumb's splash-screen idea. * v2.4 December 1998 -- additions by Brian Ginsbach. + * v2.5 -- -s option by David N. Welton. * * Tries to interpret arguments as names or aliases of ascii characters * and dumps out *all* the aliases of each. Accepts literal characters, @@ -26,7 +27,7 @@ */ -#define REVISION "$Revision: 1.10 $" +#define REVISION "$Revision: 1.11 $" #include #include @@ -37,6 +38,7 @@ typedef char *string; static unsigned char terse = 0; static unsigned char help = 0; +static unsigned char line = 0; enum { decimal, hex, octal } mode; @@ -304,6 +306,10 @@ process_options(int argc, char *argv[], char * opt_string) case 't': terse = 1; break; + case 's': + terse=1; + line=1; + break; case 'd': print_table(decimal); exit(0); @@ -441,6 +447,14 @@ char *str; if (len == 1) { speak(str[0]); return; } + /* process multiple letters */ + if (line == 1) { + for (ch = 0; ch < len; ch ++) { + speak(str[ch]); + } + return; + } + /* interpret ^-escapes as control-character notation */ if (strcmp(str, "^?") == 0) { speak(0x7F); return; } @@ -595,17 +609,16 @@ int main(argc, argv) int argc; char **argv; { - char *optstring="thvxod" ; + char *optstring="tshvxod" ; process_options(argc, argv, optstring) ; if (help || argc == optind) showHelp(stdout, argv[0]); - else { - for(argc--, argv++ ; argc > 0; argv++, argc--) - ascii(*argv) ; - } + else + while (optind < argc) + ascii(argv[optind++]); exit(0); } /******************************************************************/ diff --git a/ascii.xml b/ascii.xml index c8d925d..a476a5e 100644 --- a/ascii.xml +++ b/ascii.xml @@ -11,6 +11,9 @@ are as follows: Script-friendly mode, emits only ISO/decimal/hex/octal/binary encodings of the character. .TP +.B \-s +Parse multiple characters. Convenient way of parsing strings. +.TP .B \-d Ascii table in decimal. .TP @@ -128,6 +131,8 @@ and a few common-use alternatives (such as NL for LF). All comparisons are case-insensitive, and dashes are mapped to spaces. Any unrecognized arguments or out of range values are silently ignored. +Note that the -s option will not recognize 'long' names, as it cannot +differentiate them from other parts of the string. .P For correct results, be careful to stringize or quote shell metacharacters in arguments (especially backslash). @@ -146,3 +151,4 @@ Ioannis E. Tambouras added command options and minor enhancements. Brian J. Ginsbach fixed several bugs and expanded the man page. +David N. Welton added the -s option. \ No newline at end of file -- 2.43.0