[ttssh2-commit] [10714] テストで表示できる文字を増やした

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2023年 5月 20日 (土) 23:14:27 JST


Revision: 10714
          https://osdn.net/projects/ttssh2/scm/svn/commits/10714
Author:   zmatsuo
Date:     2023-05-20 23:14:27 +0900 (Sat, 20 May 2023)
Log Message:
-----------
テストで表示できる文字を増やした

- キーで表示コードを選べるようにした

Modified Paths:
--------------
    trunk/tests/various_code_texts/dump_code.pl

Added Paths:
-----------
    trunk/tests/various_code_texts/dump_code.md

-------------- next part --------------
Added: trunk/tests/various_code_texts/dump_code.md
===================================================================
--- trunk/tests/various_code_texts/dump_code.md	                        (rev 0)
+++ trunk/tests/various_code_texts/dump_code.md	2023-05-20 14:14:27 UTC (rev 10714)
@@ -0,0 +1,103 @@
+# dump_code.pl
+
+## 概要
+
+- 0x00から0xFFを表示するプログラム。
+- 端末の設定に合わせた文字を表示。
+- C0(0x00-0x1F),C1(0x80-0x9F)は略号を表示。
+
+## 実行
+
+```
+$ perl dump_code.pl
+a   All
+      all chars, 0x00...0xFF
+      ISO/IEC 8859(=Unicode)
+      ISO/IEC 2022 8bit
+u   Unicode + UTF-8
+      CES(character encoding scheme) = UTF-8
+      U+0000...U+00FF
+7   ISO/IEC 2022 7bit (jis)
+s   Shift_JIS
+e   Japanese/EUC (euc-jp)
+j   JIS
+q   quit
+>
+```
+端末の設定に合わせて文字を入力すると文字表を表示。
+
+
+例
+
+JIS
+```
+> j
+C0(0x00-0x1F) & GL(0x20-0x7F):
+      | +0| +1| +2| +3| +4| +5| +6| +7| +8| +9| +a| +b| +c| +d| +e| +f|
+------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|
+ 0x0X |NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS |HT |LF |VT |FF |CR |SO |SI |
+ 0x1X |DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM |SUB|ESC|FS |GS |RS |US |
+ 0x2X |SP | ! | " | # | $ | % | & | ' | ( | ) | * | + | , | - | . | / |
+ 0x3X | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ? |
+ 0x4X | @ | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
+ 0x5X | P | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ |
+ 0x6X | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o |
+ 0x7X | p | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ |DEL|
+C1(0x80-0x9F) & GR(0xA0-0xFF):
+      | +0| +1| +2| +3| +4| +5| +6| +7| +8| +9| +a| +b| +c| +d| +e| +f|
+------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|
+ 0x8X |PAD|HOP|BPH|NBH|IND|NEL|SSA|ESA|HTS|HTJ|VTS|PLD|PLU|RI |SS2|SS3|
+ 0x9X |DCS|PU1|PU2|STS|CCH|MW |SPA|EPA|SOS|SGC|SCI|CSI|ST |OSC|PM |APC|
+ 0xaX |---| 。 | 「 | 」 | 、 | ・ | ヲ | ァ | ィ | ゥ | ェ | ォ | ャ | ュ | ョ | ッ |
+ 0xbX | ー | ア | イ | ウ | エ | オ | カ | キ | ク | ケ | コ | サ | シ | ス | セ | ソ |
+ 0xcX | タ | チ | ツ | テ | ト | ナ | ニ | ヌ | ネ | ノ | ハ | ヒ | フ | ヘ | ホ | マ |
+ 0xdX | ミ | ム | メ | モ | ヤ | ユ | ヨ | ラ | リ | ル | レ | ロ | ワ | ン | ゙ | ゚ |
+ 0xeX |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
+ 0xfX |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
+```
+
+SJIS
+```
+> s
+      | +0| +1| +2| +3| +4| +5| +6| +7| +8| +9| +a| +b| +c| +d| +e| +f|
+------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|
+ 0x0X |NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS |HT |LF |VT |FF |CR |SO |SI |
+ 0x1X |DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM |SUB|ESC|FS |GS |RS |US |
+ 0x2X |SP | ! | " | # | $ | % | & | ' | ( | ) | * | + | , | - | . | / |
+ 0x3X | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ? |
+ 0x4X | @ | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
+ 0x5X | P | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ |
+ 0x6X | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o |
+ 0x7X | p | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ |DEL|
+ 0x8X |PAD|HOP|BPH|NBH|IND|NEL|SSA|ESA|HTS|HTJ|VTS|PLD|PLU|RI |SS2|SS3|
+ 0x9X |DCS|PU1|PU2|STS|CCH|MW |SPA|EPA|SOS|SGC|SCI|CSI|ST |OSC|PM |APC|
+ 0xaX |---| 。 | 「 | 」 | 、 | ・ | ヲ | ァ | ィ | ゥ | ェ | ォ | ャ | ュ | ョ | ッ |
+ 0xbX | ー | ア | イ | ウ | エ | オ | カ | キ | ク | ケ | コ | サ | シ | ス | セ | ソ |
+ 0xcX | タ | チ | ツ | テ | ト | ナ | ニ | ヌ | ネ | ノ | ハ | ヒ | フ | ヘ | ホ | マ |
+ 0xdX | ミ | ム | メ | モ | ヤ | ユ | ヨ | ラ | リ | ル | レ | ロ | ワ | ン | ゙ | ゚ |
+ 0xeX |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
+ 0xfX |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
+```
+
+ISO8859-1
+```
+> a
+      | +0| +1| +2| +3| +4| +5| +6| +7| +8| +9| +a| +b| +c| +d| +e| +f|
+------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---|
+ 0x0X |NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS |HT |LF |VT |FF |CR |SO |SI |
+ 0x1X |DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM |SUB|ESC|FS |GS |RS |US |
+ 0x2X |SP | ! | " | # | $ | % | & | ' | ( | ) | * | + | , | - | . | / |
+ 0x3X | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | < | = | > | ? |
+ 0x4X | @ | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
+ 0x5X | P | Q | R | S | T | U | V | W | X | Y | Z | [ | \ | ] | ^ | _ |
+ 0x6X | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o |
+ 0x7X | p | q | r | s | t | u | v | w | x | y | z | { | | | } | ~ |DEL|
+ 0x8X |PAD|HOP|BPH|NBH|IND|NEL|SSA|ESA|HTS|HTJ|VTS|PLD|PLU|RI |SS2|SS3|
+ 0x9X |DCS|PU1|PU2|STS|CCH|MW |SPA|EPA|SOS|SGC|SCI|CSI|ST |OSC|PM |APC|
+ 0xaX |   | ¡ | ¢ | £ | ¤ | ¥ | ¦ | § | ¨ | © | ª | « | ¬ | ­ | ® | ¯ |
+ 0xbX | ° | ± | ² | ³ | ´ | µ | ¶ | · | ¸ | ¹ | º | » | ¼ | ½ | ¾ | ¿ |
+ 0xcX | À | Á | Â | Ã | Ä | Å | Æ | Ç | È | É | Ê | Ë | Ì | Í | Î | Ï |
+ 0xdX | Ð | Ñ | Ò | Ó | Ô | Õ | Ö | × | Ø | Ù | Ú | Û | Ü | Ý | Þ | ß |
+ 0xeX | à | á | â | ã | ä | å | æ | ç | è | é | ê | ë | ì | í | î | ï |
+ 0xfX | ð | ñ | ò | ó | ô | õ | ö | ÷ | ø | ù | ú | û | ü | ý | þ | ÿ |
+```

Modified: trunk/tests/various_code_texts/dump_code.pl
===================================================================
--- trunk/tests/various_code_texts/dump_code.pl	2023-05-18 13:21:48 UTC (rev 10713)
+++ trunk/tests/various_code_texts/dump_code.pl	2023-05-20 14:14:27 UTC (rev 10714)
@@ -1,170 +1,296 @@
-use utf8;
-use strict;
-
-use Getopt::Long 'GetOptions';
-
-my $code = "utf8";
-my $usage = 0;
-
-GetOptions(
-	'code=s' => \$code,
-	'help' => \$usage,
-);
-
-sub IsCL {
-	my $ch = $_[0];
-	if (0x00 <= $ch && $ch <= 0x1f) {
-		return 1;
-	}
-	return 0;
-}
-
-sub IsCR {
-	my $ch = $_[0];
-	if (0x80 <= $ch && $ch <= 0x9f) {
-		return 1;
-	}
-	return 0;
-}
-
-sub IsPrintableUTF8 {
-	my $ch = $_[0];
-	if (IsCL($ch) || IsCR($ch)) {
-		return 0;
-	}
-	if ($ch == 0x7f) {
-		# DEL
-		return 0;
-	}
-	return 1;
-}
-
-sub IsPrintableShiftJIS {
-	my $ch = $_[0];
-	if (IsCL($ch) || IsCR($ch)) {
-		return 0;
-	}
-	if ($ch == 0x7f) {
-		# DEL
-		return 0;
-	}
-	if ($ch == 0x80 || $ch == 0xa0) {
-		return 0;
-	}
-	if (0xe0 <= $ch && $ch <= 0xff) {
-		return 0;
-	}
-	return 1;
-}
-
-sub IsPrintableJIS {
-	my $ch = $_[0];
-	if (IsCL($ch) || IsCR($ch)) {
-		return 0;
-	}
-	if ($ch == 0x7f) {
-		# DEL
-		return 0;
-	}
-	if (0x80 <= $ch && $ch <= 0xa0) {
-		return 0;
-	}
-	if (0xe0 <= $ch && $ch <= 0xff) {
-		return 0;
-	}
-	return 1;
-}
-
-sub IsPrintableEUCJP {
-	my $ch = $_[0];
-	if (IsCL($ch)) {
-		return 0;
-	}
-	if ($ch == 0x7f) {
-		# DEL
-		return 0;
-	}
-	if ($ch >= 0x80) {
-		return 0;
-	}
-	return 1;
-}
-
-my %check =
-(
- 'utf8' => \&IsPrintableUTF8,
- 'utf8-bin' => \&IsPrintableUTF8,
- 'iso8859' => \&IsPrintableUTF8,
- 'iso646' => \&IsPrintableEUCJP,
- 'sjis' => \&IsPrintableShiftJIS,
- 'shift_jis' => \&IsPrintableShiftJIS,
- 'euc-jp' => \&IsPrintableEUCJP,
- 'jis' => \&IsPrintableJIS,
- );
-
-sub usage {
-	print << 'EOS';
-option:
-  --code=[code]
-EOS
-	for my $key (sort keys %check) {
-		print "      $key\n";
-	}
-}
-
-if ($usage) {
-	usage();
-	exit(0);
-}
-
-my $find = 0;
-for my $key (sort keys %check) {
-	if (index($key, lc($code)) != -1) {
-		$find = 1;
-		$code = $key;
-		last;
-	}
-}
-if ($find == 0) {
-	print "check code\n";
-	usage();
-	exit(0);
-}
-printf("code=$code\n");
-
-# output
-if ($code eq "utf8") {
-	# utf8 encode
-	binmode STDOUT, ":utf8";
-} else {
-	binmode STDOUT;
-}
-local $| = 1;
-
-print "      |";
-for (my $i = 0; $i < 16; $i++) {
-	printf(" +%x|", $i);
-}
-print "\n";
-printf("------+");
-for (my $y = 0; $y < 15; $y++) {
-	printf("---+");
-}
-print "---|\n";
-for (my $y = 0; $y < 16; $y++) {
-	printf(" 0x%01xX |", $y);
-	for (my $x = 0; $x < 16; $x++) {
-		my $c = $y * 0x10 + $x;
-		my $ch = "-";
-		if ($check{$code}->($c)) {
-			$ch = chr($c);
-		}
-		printf(" %s |", $ch);
-		#printf(" %02x|", $c);
-		if ($ch == 0xa0) {
-			exit(1);
-		}
-	}
-	print "\n";
-}
-
+#! /usr/bin/perl
+#
+# show code chart
+#  0x00 - 0xff
+#
+use utf8;
+use strict;
+use warnings;
+
+use Getopt::Long 'GetOptions';
+
+my $code = "";
+my $usage = 0;
+
+local $| = 1;
+
+GetOptions(
+	'code=s' => \$code,
+	'help' => \$usage,
+);
+
+sub IsC0 {
+	my $ch= shift;
+	if (0x00 <= $ch && $ch <= 0x1f) {
+		return 1;
+	}
+	return 0;
+}
+
+sub IsC1 {
+	my $ch= shift;
+	if (0x80 <= $ch && $ch <= 0x9f) {
+		return 1;
+	}
+	return 0;
+}
+
+sub IsPrintableUTF8 {
+	my $ch= shift;
+	if (IsC0($ch) || IsC1($ch)) {
+		return 0;
+	}
+	if ($ch == 0x7f) {
+		# DEL
+		return 0;
+	}
+	return 1;
+}
+
+sub IsPrintableShiftJIS {
+	my $ch= shift;
+	if (IsC0($ch) || IsC1($ch)) {
+		return 0;
+	}
+	if ($ch == 0x7f) {
+		# DEL
+		return 0;
+	}
+	if ($ch == 0x80 || $ch == 0xa0) {
+		return 0;
+	}
+	if (0xe0 <= $ch && $ch <= 0xff) {
+		return 0;
+	}
+	return 1;
+}
+
+sub IsPrintableJIS {
+	my $ch= shift;
+	if (IsC0($ch) || IsC1($ch)) {
+		return 0;
+	}
+	if ($ch == 0x7f) {
+		# DEL
+		return 0;
+	}
+	if (0x80 <= $ch && $ch <= 0xa0) {
+		return 0;
+	}
+	if (0xe0 <= $ch && $ch <= 0xff) {
+		return 0;
+	}
+	return 1;
+}
+
+sub IsPrintableEUCJP {
+	my $ch= shift;
+	if (IsC0($ch)) {
+		return 0;
+	}
+	if ($ch == 0x7f) {
+		# DEL
+		return 0;
+	}
+	if ($ch >= 0x80) {
+		return 0;
+	}
+	return 1;
+}
+
+my %check =
+(
+ 'utf8' => \&IsPrintableUTF8,
+ 'utf8-bin' => \&IsPrintableUTF8,
+ 'iso8859' => \&IsPrintableUTF8,
+ 'iso646' => \&IsPrintableEUCJP,
+ 'sjis' => \&IsPrintableShiftJIS,
+ 'shift_jis' => \&IsPrintableShiftJIS,
+ 'euc-jp' => \&IsPrintableEUCJP,
+ 'jis' => \&IsPrintableJIS,
+ );
+
+sub usage {
+	print << 'EOS';
+option:
+  --code=[code]
+EOS
+	for my $key (sort keys %check) {
+		print "      $key\n";
+	}
+}
+
+my @C0_str = (
+"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
+"BS ", "HT ", "LF ", "VT ", "FF ", "CR ", "SO ", "SI ",
+"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
+"CAN", "EM ", "SUB", "ESC", "FS ", "GS ", "RS ", "US " );
+
+my @C1_str = (
+"PAD", "HOP", "BPH", "NBH", "IND", "NEL", "SSA", "ESA",
+"HTS", "HTJ", "VTS", "PLD", "PLU", "RI ", "SS2", "SS3",
+"DCS", "PU1", "PU2", "STS", "CCH", "MW ", "SPA", "EPA",
+"SOS", "SGC", "SCI", "CSI", "ST ", "OSC", "PM ", "APC" );
+
+sub ShowHeader
+{
+	print "      |";
+	for (my $i = 0; $i < 16; $i++) {
+		printf(" +%x|", $i);
+	}
+	print "\n";
+	printf("------+");
+	for (my $y = 0; $y < 15; $y++) {
+		printf("---+");
+	}
+	print "---|\n";
+}
+
+my $invoke_enter = "";
+my $invoke_leave = "";
+my $cell = 1;
+
+sub ShowCode
+{
+	my $code = shift;
+	my $s = shift;
+	my $e = shift;
+
+	ShowHeader();
+	for (my $y = int($s/16); $y < int(($e+1)/16); $y++) {
+		printf(" 0x%01xX |", $y);
+		for (my $x = 0; $x < 16; $x++) {
+			my $c = $y * 0x10 + $x;
+			if ($c == 0x20) {
+				printf("SP |");
+			} elsif ($c == 0x7f) {
+				printf("DEL|");
+			} elsif ($check{$code}->($c)) {
+				my $ch = chr($c);
+				if ($cell == 1) {
+					print " " . $invoke_enter . $ch . $invoke_leave . " |";
+				} else {
+					print $invoke_enter . $ch . $invoke_leave . " |";
+				}
+			} else {
+				if ($c >= 0 && $c <= 0x1f) {
+					printf("%s|", $C0_str[$c]);
+				} elsif ($c >= 0x80 && $c <= 0x9f) {
+					printf("%s|", $C1_str[$c-0x80]);
+				} else {
+					printf("---|");
+				}
+			}
+			#printf(" %02x|", $c);
+			#if (ord($ch) == 0xa0) {
+			#	exit(1);
+			#}
+		}
+		print "\n";
+	}
+}
+
+if ($usage) {
+	usage();
+	exit(0);
+}
+
+if (length($code) != 0) {
+	my $find = 0;
+	for my $key (sort keys %check) {
+		if (index($key, lc($code)) != -1) {
+			$find = 1;
+			$code = $key;
+			last;
+		}
+	}
+	if ($find == 0) {
+		print "check code\n";
+		usage();
+		exit(0);
+	}
+
+	# output
+	if ($code eq "utf8") {
+		# utf8 encode
+		binmode STDOUT, ":utf8";
+	} else {
+		binmode STDOUT;
+	}
+	printf("code=$code\n");
+	ShowCode($code);
+}
+
+# interactive
+ FINISH: for(;;)
+{
+	my $s;
+	binmode STDOUT;
+	print <<EOF;
+a   All
+      all chars, 0x00...0xFF
+      ISO/IEC 8859(=Unicode)
+      ISO/IEC 2022 8bit
+u   Unicode + UTF-8
+      CES(character encoding scheme) = UTF-8
+      U+0000...U+00FF
+7   ISO/IEC 2022 7bit (jis)
+s   Shift_JIS
+e   Japanese/EUC (euc-jp)
+j   JIS
+q   quit
+EOF
+	print "> ";
+	$s = <STDIN>;
+	$s =~ s/[\n\r]//g;
+
+	for(;;) {
+		if (length($s) == 0) {
+			next FINISH;
+		}
+		my $c = substr($s, 0, 1);
+		$s = substr($s, 1);
+
+		if ($c eq 'q') {
+			last FINISH;
+		} elsif ($c eq 'a') {
+			ShowCode('utf8', 0x00, 0xff);
+		} elsif ($c eq 'u') {
+			binmode STDOUT, ":utf8";
+			ShowCode('utf8', 0x00, 0xff);
+			binmode STDOUT;
+		} elsif ($c eq '8') {
+			ShowCode('iso8859', 0x00, 0xff);
+		} elsif ($c eq '7') {
+			print "GL(0x20-0x7F) <- G0:\n";
+			$invoke_enter = chr(0x0f);
+			$invoke_leave = chr(0x0f);
+			ShowCode('utf8', 0x00, 0x7f);
+			print "GL(0x20-0x7F) <- G1:\n";
+			$invoke_enter = chr(0x0e);
+			$invoke_leave = chr(0x0f);
+			ShowCode('utf8', 0x00, 0x7f);
+			print "GL(0x20-0x7F) <- G3, 0x21XX:\n";
+			$invoke_enter = chr(0x1b) . "o" . chr(0x21); # LS3(GL<-G3) + 0x21xx
+			$invoke_leave = chr(0x0f); # GL<-G0
+			$cell = 2;
+			ShowCode('utf8', 0x00, 0x7f);
+			$invoke_enter = "";
+			$invoke_leave = "";
+			$cell = 1;
+			# GL <- G0
+			print chr(0x0f);
+		} elsif ($c eq 's') {
+			ShowCode('shift_jis', 0x00, 0xff);
+		} elsif ($c eq 'e') {
+			ShowCode('euc-jp', 0x00, 0xff);
+		} elsif ($c eq 'j') {
+			print "C0(0x00-0x1F) & GL(0x20-0x7F):\n";
+			ShowCode('jis', 0x00, 0x7f);
+			print "C1(0x80-0x9F) & GR(0xA0-0xFF):\n";
+			ShowCode('jis', 0x80, 0xff);
+		} else {
+			print " ?\n"
+		}
+	}
+}


ttssh2-commit メーリングリストの案内
Back to archive index