toybox/toys/other/ascii.c
<<
>>
Prefs
   1/* ascii.c - display ascii table
   2 *
   3 * Copyright 2017 Rob Landley <rob@landley.net>
   4 *
   5 * Technically 7-bit ASCII is ANSI X3.4-1986, a standard available as
   6 * INCITS 4-1986[R2012] on ansi.org, but they charge for it.
   7
   8USE_ASCII(NEWTOY(ascii, 0, TOYFLAG_USR|TOYFLAG_BIN))
   9
  10config ASCII
  11  bool "ascii"
  12  default y
  13  help
  14    usage: ascii
  15
  16    Display ascii character set.
  17*/
  18
  19#include "toys.h"
  20
  21void ascii_main(void)
  22{
  23  char *low="NULSOHSTXETXEOTENQACKBELBS HT LF VT FF CR SO SI DLEDC1DC2DC3DC4"
  24            "NAKSYNETBCANEM SUBESCFS GS RS US ";
  25  int x, y;
  26
  27  for (x = 0; x<8; x++) printf("Dec Hex%*c", 2+2*(x<2)+(x>4), ' ');
  28  xputc('\n');
  29  for (y=0; y<=15; y++) {
  30    for (x=0; x<8; x++) {
  31      int i = x*16+y;
  32
  33      if (i>95 && i<100) putchar(' ');
  34      printf("% 3d %02X ", i, i);
  35      if (i<32 || i==127) printf("%.3s ", (i==127) ? "DEL" : low+3*i);
  36      else printf("%c ", i);
  37    }
  38    xputc('\n');
  39  }
  40}
  41