* ascii.c -- quick crossreference for ASCII character aliases
*
* by Eric S. Raymond <esr@snark.thyrsus.com>, v1.0 March 1990
- * v1.1 November 1990 -- revised `slang' from the 2.2 pronunciation guide
- * v1.2 March 1995 -- Fixed a core-dump bug
- * v1.3 October 1995 -- Fixed a bug that shows up only under ELF.
- * v2.0 December 1995 -- Interpret ISO-style code table escapes.
- * v2.1 August 1997 -- nerge in changes by Ioannes Tambouras.
+ * v1.1 November 1990 -- revised `slang' from the 2.2 pronunciation guide
+ * v1.2 March 1995 -- Fixed a core-dump bug
+ * v1.3 October 1995 -- Fixed a bug that shows up only under ELF.
+ * v2.0 December 1995 -- Interpret ISO-style code table escapes.
+ * v2.1 August 1997 -- merge in changes by Ioannis Tambouras.
+ * v2.2 November 1997 -- merge in more changes by Ioannis Tambouras.
*
* Tries to interpret arguments as names or aliases of ascii characters
* and dumps out *all* the aliases of each. Accepts literal characters,
*/
-#define REVISION "$Revision$"
+#define REVISION "$Revision: 1.5 $"
#include <unistd.h>
#include <stdio.h>
static unsigned char terse = 0;
+enum { decimal, hex, octal } mode;
+
+void print_table(unsigned short delivery);
+
+
static string cnames[128][15] =
{
{"NUL", "Null", (char *)NULL},
void
showHelp(FILE *out, char *progname)
{
- fprintf(out,"Usage: $ %s [options] char-alias...\n",progname);
+ fprintf(out,"Usage: $ %s [t] char-alias...\n",progname);
+ fprintf(out," $ %s [dxo] \n",progname);
fprintf(out,"Options:\n");
- fprintf(out," -t \t\t Script-friendly mode; output is brief and terse\n");
+ fprintf(out," -t \t\t Script-friendly mode with terse output \n");
+ fprintf(out," -d \t\t Ascii table in decimal \n");
+ fprintf(out," -x \t\t Ascii table in hex \n");
+ fprintf(out," -o \t\t Ascii table in octal \n");
fprintf(out," -h \t\t This help screen\n");
fprintf(out," -v \t\t Version info\n");
fprintf(out,"Description:\n");
case 't':
terse=1;
break;
+ case 'd':
+ print_table(decimal);
+ exit(0);
+ case 'x':
+ print_table(hex);
+ exit(0);
+ case 'o':
+ print_table(octal);
+ exit(0);
case 'h':
showHelp(stdout, argv[0]) ;
break;
} /* outer if */
}
/******************************************************************/
+void
+print_table(unsigned short delivery)
+{
+ static unsigned short i, j, len;
+ char separator[]= " ";
+ char *tail = separator + 3 ;
+ char *space;
+ char *name ;
+
+ for (i=0;i<16; i++) {
+ for (j=0; j<8; j++) {
+ name= *cnames[i+(j*16)];
+ len = strlen(name);
+ space = tail - (len % 3) ;
+ switch (delivery) {
+ case decimal: printf("%5d %1s%1s",i+(j*16),name,space);
+ break;
+ case octal : printf("%5o %1s%1s",i+(j*16),name,space);
+ break;
+ case hex : printf("%5X %1s%1s",i+(j*16),name,space);
+ break;
+ }
+ }
+ printf("\n");
+ }
+
+}
/*----------------------------------------- M A I N --------------*/
int main(argc, argv)
int argc;
char **argv;
{
- char *optstring="thv" ;
+ char *optstring="thvxod" ;
process_options(argc, argv, optstring) ;
+
if (argc == optind ) {
showHelp(stderr, argv[0]);
}else{