xref: /third_party/toybox/toys/other/ascii.c (revision 0f66f451)
10f66f451Sopenharmony_ci/* ascii.c - display ascii table
20f66f451Sopenharmony_ci *
30f66f451Sopenharmony_ci * Copyright 2017 Rob Landley <rob@landley.net>
40f66f451Sopenharmony_ci *
50f66f451Sopenharmony_ci * Technically 7-bit ASCII is ANSI X3.4-1986, a standard available as
60f66f451Sopenharmony_ci * INCITS 4-1986[R2012] on ansi.org, but they charge for it.
70f66f451Sopenharmony_ci *
80f66f451Sopenharmony_ci * unicode.c - convert between Unicode and UTF-8
90f66f451Sopenharmony_ci *
100f66f451Sopenharmony_ci * Copyright 2020 The Android Open Source Project.
110f66f451Sopenharmony_ci *
120f66f451Sopenharmony_ci * Loosely based on the Plan9/Inferno unicode(1).
130f66f451Sopenharmony_ci
140f66f451Sopenharmony_ciUSE_ASCII(NEWTOY(ascii, 0, TOYFLAG_USR|TOYFLAG_BIN))
150f66f451Sopenharmony_ci
160f66f451Sopenharmony_ciconfig ASCII
170f66f451Sopenharmony_ci  bool "ascii"
180f66f451Sopenharmony_ci  default y
190f66f451Sopenharmony_ci  help
200f66f451Sopenharmony_ci    usage: ascii
210f66f451Sopenharmony_ci
220f66f451Sopenharmony_ci    Display ascii character set.
230f66f451Sopenharmony_ci*/
240f66f451Sopenharmony_ci
250f66f451Sopenharmony_ci#include "toys.h"
260f66f451Sopenharmony_ci
270f66f451Sopenharmony_civoid ascii_main(void)
280f66f451Sopenharmony_ci{
290f66f451Sopenharmony_ci  char *low="NULSOHSTXETXEOTENQACKBELBS HT LF VT FF CR SO SI DLEDC1DC2DC3DC4"
300f66f451Sopenharmony_ci            "NAKSYNETBCANEM SUBESCFS GS RS US ";
310f66f451Sopenharmony_ci  int x, y;
320f66f451Sopenharmony_ci
330f66f451Sopenharmony_ci  for (x = 0; x<8; x++) printf("Dec Hex%*c", 2+2*(x<2)+(x>4), ' ');
340f66f451Sopenharmony_ci  xputc('\n');
350f66f451Sopenharmony_ci  for (y=0; y<=15; y++) {
360f66f451Sopenharmony_ci    for (x=0; x<8; x++) {
370f66f451Sopenharmony_ci      int i = x*16+y;
380f66f451Sopenharmony_ci
390f66f451Sopenharmony_ci      if (i>95 && i<100) putchar(' ');
400f66f451Sopenharmony_ci      printf("% 3d %02X ", i, i);
410f66f451Sopenharmony_ci      if (i<32 || i==127) printf("%.3s ", (i==127) ? "DEL" : low+3*i);
420f66f451Sopenharmony_ci      else printf("%c ", i);
430f66f451Sopenharmony_ci    }
440f66f451Sopenharmony_ci    xputc('\n');
450f66f451Sopenharmony_ci  }
460f66f451Sopenharmony_ci}
47