#include <ctype.h>
#include <string.h>
#include <stdlib.h>
+#include <stdbool.h>
typedef char *string;
-static unsigned char terse = 0;
-static unsigned char help = 0;
-static unsigned char line = 0;
+static bool terse = false;
+static bool help = false;
+static bool line = false;
enum { decimal, hex, octal } mode;
#include "nametable.h"
}
};
+
/******************************************************************/
static int atob(str)
/* ASCII-to-binary conversion */
{
int val;
- for (val = 0; *str; str++)
+ for (val = 0; *str != '\0'; str++)
{
val *= 2;
showHelp(FILE *out, char *progname)
{
fprintf(out,"Usage: %s [-dxohv] [-t] [char-alias...]\n", progname);
-#define P(s) fputs(s "\n", out);
+#define P(s) (void)fputs(s "\n", out);
#include "splashscreen.h"
#undef P
switch (op) {
case 't':
- terse = 1;
+ terse = true;
break;
case 's':
- terse=1;
- line=1;
+ terse = true;
+ line = true;
break;
case 'd':
print_table(decimal);
exit(0);
case '?':
case 'h':
- help = 1;
+ help = true;
break;
case 'v':
- printf("ascii %2.1f\n",REVISION); exit(0) ;
- break;
+ printf("ascii %2.1f\n",REVISION);
+ exit(0);
default :
- help = 1;
+ help = true;
break;
} /*switch*/
}/*while*/
}
/******************************************************************/
-static char *btoa(val)
+static char *btoa(unsigned int val)
/* binary-to-ASCII conversion */
{
#define BITSPERCHAR 8
/* write out external representation at least one char */
*(rp = rep + BITSPERCHAR) = '\0';
do {
- *--rp = (val & 1) + '0'; /* Is '1' == '0' + 1 in EBCDIC? */
+ *--rp = (char)('0' + (val & 1)); /* Is '1' == '0' + 1 in EBCDIC? */
val /= 2;
} while
- (val && rp > rep);
+ (val != 0 && rp > rep);
#ifndef SHORT_BINARY_REPRESENTATION
while (rp > rep)
}
/******************************************************************/
-static void speak(ch)
+static void speak(unsigned int ch)
/* list all the names for a given character */
-int ch;
{
char **ptr = &cnames[ch][0];
if (terse) {
- (void) printf("%d/%d %d 0x%02X 0o%o %s\n",
+ (void) printf("%u/%u %u 0x%02X 0o%o %s\n",
ch / 16, ch % 16, ch, ch, ch, btoa(ch));
return;
}
(void) printf(
- "ASCII %d/%d is decimal %03d, hex %02x, octal %03o, bits %s: ",
+ "ASCII %u/%u is decimal %03u, hex %02x, octal %03o, bits %s: ",
ch / 16, ch % 16, ch, ch, ch, btoa(ch));
/* display high-half characters */
ch &=~ 0x80;
if (ch == 0x7f)
(void) printf("meta-^?\n");
- else if (isprint(ch))
- (void) printf("meta-%c\n", ch);
+ else if (isprint((int)ch))
+ (void) printf("meta-%c\n", (char)ch);
else
(void) printf("meta-^%c\n", '@' + (ch & 0x1f));
return;
}
- if (isprint(ch))
+if (isprint((int)ch))
(void) printf("prints as `%s'\n", *ptr++);
- else if (iscntrl(ch) || ch == 0x7F)
+ else if (iscntrl((char)ch) || ch == 0x7F)
{
if (ch == 0x7f)
(void) printf("called ^?");
commentary = *ptr;
else
(void) printf("%s%s ", *ptr,
- (ptr[1] && *ptr[1] != '#') ? "," : "");
+ (ptr[1]!=NULL && *ptr[1] != '#') ? "," : "");
(void) putchar('\n');
if (commentary)
(void) printf("Note: %s\n", commentary+2);
(void) putchar('\n');
}
+
/******************************************************************/
-static int stricmp(s, t)
+static int stricmp(char *s, char *t)
/* case-blind string compare */
-register char *s, *t;
{
while (*s && tolower(*s) == tolower(*t))
s++, t++;
return(*t - *s);
}
+
/******************************************************************/
-static void ascii(str)
-char *str;
+static void ascii(char *str)
{
int ch, hi, lo;
char **ptr;
speak(ch);
} /* outer if */
}
+
/******************************************************************/
void
print_table(unsigned short delivery)
}
}
+
/*----------------------------------------- M A I N --------------*/
-int main(argc, argv)
-int argc;
-char **argv;
+int main(int argc, char **argv)
{
char *optstring="tshvxod" ;