More to come...
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

120 行
6.4KB

  1. #include "../chapter/chapter_0.c"
  2. #include "../chapter/chapter_1.c"
  3. static void echo_separator (void) {
  4. terminal_colour (COLOUR_GREY, EFFECT_BOLD);
  5. echo (" | ");
  6. terminal_cancel ();
  7. }
  8. static void echo_base (int character, int base, int colour, int effect) {
  9. echo_separator ();
  10. terminal_colour (colour, effect);
  11. if (base == 2) {
  12. echo (format_to_string (character, 0, base, 7, '0'));
  13. } else if (base == 8) {
  14. echo (format_to_string (character, 0, base, 3, '0'));
  15. } else if (base == 16) {
  16. echo (format_to_string (character, 0, base, 2, '0'));
  17. } else {
  18. echo (format_to_string (character, 0, base, 3, ' '));
  19. }
  20. terminal_cancel ();
  21. }
  22. static void echo_code (int character, int colour, int effect) {
  23. char * code [32] = {
  24. "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
  25. "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
  26. };
  27. echo_separator ();
  28. terminal_colour (colour, effect);
  29. if (character == 0X7F) {
  30. echo ("DEL");
  31. } else if (character_is_invisible (character) != 0) {
  32. echo (code [character]);
  33. if (string_length (code [character]) == 2) {
  34. echo (" ");
  35. }
  36. } else {
  37. out (& character, 1);
  38. echo (" ");
  39. }
  40. terminal_cancel ();
  41. }
  42. static void echo_name (int character, int colour, int effect) {
  43. char * name [128] = {
  44. "Null", "Start of heading", "Start of text", "End of text",
  45. "End of transmission", "Enquiry", "Acknowledge", "Bell",
  46. "Backspace", "Horizontal tab", "Line feed", "Vertical tab",
  47. "Form feed", "Carriage return", "Shift out", "Shift in",
  48. "Data link escape", "Device control 1", "Device control 2", "Device control 3",
  49. "Device control 4", "Negative acknowledge", "Synchronous idle", "End transmission block",
  50. "Cancel", "End of medium", "Substitute", "Escape",
  51. "File separator", "Group separator", "Record separator", "Unit separator",
  52. "Space", "Exclamation mark", "Speech mark", "Number sign",
  53. "Dollar sign", "Percent", "Ampersand", "Quote",
  54. "Open parenthesis", "Close parenthesis", "Asterisk", "Plus",
  55. "Comma", "Minus", "Period", "Slash",
  56. "Zero", "One", "Two", "Three",
  57. "Four", "Five", "Six", "Seven",
  58. "Eight", "Nine", "Colon", "Semicolon",
  59. "Open angled bracket", "Equal", "Close angled bracket", "Question mark",
  60. "At sign", "Uppercase A", "Uppercase B", "Uppercase C",
  61. "Uppercase D", "Uppercase E", "Uppercase F", "Uppercase G",
  62. "Uppercase H", "Uppercase I", "Uppercase J", "Uppercase K",
  63. "Uppercase L", "Uppercase M", "Uppercase N", "Uppercase O",
  64. "Uppercase P", "Uppercase Q", "Uppercase R", "Uppercase S",
  65. "Uppercase T", "Uppercase U", "Uppercase V", "Uppercase W",
  66. "Uppercase X", "Uppercase Y", "Uppercase Z", "Opening bracket",
  67. "Backslash", "Closing bracket", "Caret", "Underscore",
  68. "Grave", "Lowercase a", "Lowercase b", "Lowercase c",
  69. "Lowercase d", "Lowercase e", "Lowercase f", "Lowercase g",
  70. "Lowercase h", "Lowercase i", "Lowercase j", "Lowercase k",
  71. "Lowercase l", "Lowercase m", "Lowercase n", "Lowercase o",
  72. "Lowercase p", "Lowercase q", "Lowercase r", "Lowercase s",
  73. "Lowercase t", "Lowercase u", "Lowercase v", "Lowercase w",
  74. "Lowercase x", "Lowercase y", "Lowercase z", "Opening brace",
  75. "Vertical bar", "Closing brace", "Tilde", "Delete"
  76. };
  77. echo_separator ();
  78. terminal_colour (colour, effect);
  79. echo (name [character]);
  80. out (" ", 40 - string_length (name [character]));
  81. terminal_cancel ();
  82. }
  83. int main (void) {
  84. int character;
  85. for (character = 0; character != 128; ++character) {
  86. echo_base (character, 2, COLOUR_BLUE, EFFECT_NORMAL);
  87. echo_base (character, 8, COLOUR_CYAN, EFFECT_NORMAL);
  88. echo_base (character, 10, COLOUR_CYAN, EFFECT_ITALIC);
  89. echo_base (character, 16, COLOUR_CYAN, EFFECT_BOLD);
  90. echo_code (character, COLOUR_PINK, EFFECT_BOLD);
  91. echo_name (character, COLOUR_WHITE, EFFECT_NORMAL);
  92. if ((character % 2) != 0) {
  93. echo ("\n");
  94. }
  95. }
  96. return (EXIT_SUCCESS);
  97. }