This is a slow ctype library for sjis characters. 高速ではない シフトジス用の ctype 文字類識別ライブラリです。
Révision | 7ee41ca246cb6a1028b6e02f416708e5861ce91a (tree) |
---|---|
l'heure | 2014-01-03 14:48:47 |
Auteur | Joel Matthew Rees <reiisi@user...> |
Commiter | Joel Matthew Rees |
Now we have some shift JIS hexdump
@@ -11,6 +11,9 @@ | ||
11 | 11 | #include <ctype.h> |
12 | 12 | |
13 | 13 | |
14 | +#include "slowsjctype.h" | |
15 | + | |
16 | + | |
14 | 17 | #define DEFAULTWIDTH 16 |
15 | 18 | |
16 | 19 | #define READSIZE 128 |
@@ -25,11 +28,11 @@ char hexbuff[ BUFFSIZE * 3 ]; | ||
25 | 28 | |
26 | 29 | int formatHexByte( int byte, char * target ) |
27 | 30 | { |
28 | - char out = (char) ( ( byte & 0xf0 ) >> 4 ); | |
31 | + char outch = (char) ( ( byte & 0xf0 ) >> 4 ); | |
29 | 32 | |
30 | - * target++ = TOHEX( out ); | |
31 | - out = (char) ( byte & 0x0f ); | |
32 | - * target++ = TOHEX( out ); | |
33 | + * target++ = TOHEX( outch ); | |
34 | + outch = (char) ( byte & 0x0f ); | |
35 | + * target++ = TOHEX( outch ); | |
33 | 36 | * target++ = ' '; |
34 | 37 | return 3; |
35 | 38 | } |
@@ -42,6 +45,7 @@ int main( int argc, char * argv[] ) | ||
42 | 45 | int column = 0; |
43 | 46 | int columnLimit = DEFAULTWIDTH; |
44 | 47 | int hexcolumn = 0; |
48 | + int offset = 0; | |
45 | 49 | int ch; |
46 | 50 | |
47 | 51 | if ( argc > 1 ) |
@@ -56,13 +60,36 @@ int main( int argc, char * argv[] ) | ||
56 | 60 | do |
57 | 61 | { |
58 | 62 | if ( ( ch = fgetc( in ) ) != EOF ) |
59 | - { hexcolumn += formatHexByte( ch, hexbuff + hexcolumn ); | |
60 | - chbuff[ column ] = (char) ( isprint( ch ) ? ch : '.' ); | |
61 | - ++column; | |
63 | + { | |
64 | + hexcolumn += formatHexByte( ch, hexbuff + hexcolumn ); | |
65 | + chbuff[ column++ ] = (char) ch; | |
62 | 66 | } |
63 | 67 | if ( ( column >= columnLimit ) || ( ch == EOF ) ) |
64 | 68 | { |
65 | - hexbuff[ hexcolumn ] = chbuff[ column ] = '\0'; | |
69 | + int scan; | |
70 | + hexbuff[ hexcolumn ] = '\0'; /* 念のため、ここ */ | |
71 | + chbuff[ column ] = '\0'; | |
72 | + /* 表示のための置き換え */ | |
73 | + for ( scan = offset; scan < columnLimit; ++scan ) | |
74 | + { | |
75 | + if ( slowsjIsPOneByte( &chbuff[ scan ] ) ) | |
76 | + { | |
77 | + if ( !isprint( chbuff[ scan ] ) ) | |
78 | + { | |
79 | + chbuff[ scan ] = '.'; | |
80 | + } | |
81 | + } | |
82 | + else if ( slowsjIsP2Byte( &chbuff[ scan ] ) ) | |
83 | + { | |
84 | + ++scan; | |
85 | + } | |
86 | + else | |
87 | + { | |
88 | + chbuff[ scan ] = '.'; | |
89 | + } | |
90 | + } | |
91 | + /* 最後のバイトがしつこい。 */ | |
92 | + /* 置き換え完了 */ | |
66 | 93 | printf( "0x%08x: %*s %*s\n", |
67 | 94 | address, |
68 | 95 | -columnLimit * 3, hexbuff, |