This is a slow ctype library for sjis characters. 高速ではない シフトジス用の ctype 文字類識別ライブラリです。
Revisión | 1c093f9b32e6c2fe75d69d3a31ffd8efb138b0c0 (tree) |
---|---|
Tiempo | 2014-01-03 14:45:01 |
Autor | Joel Matthew Rees <reiisi@user...> |
Commiter | Joel Matthew Rees |
working on the shift jis hexdump
@@ -16,7 +16,23 @@ | ||
16 | 16 | #define READSIZE 128 |
17 | 17 | #define BUFFSIZE ( READSIZE + 4 ) |
18 | 18 | |
19 | -char buffer[ BUFFSIZE ]; | |
19 | +char chbuff[ BUFFSIZE ]; | |
20 | + | |
21 | +char hexbuff[ BUFFSIZE * 3 ]; | |
22 | + | |
23 | + | |
24 | +#define TOHEX( c ) ( (char) ( ( (c) <= 9 ) ? (c) + '0' : (c) + 'A' - 1 ) ) | |
25 | + | |
26 | +int formatHexByte( int byte, char * target ) | |
27 | +{ | |
28 | + char out = (char) ( ( byte & 0xf0 ) >> 4 ); | |
29 | + | |
30 | + * target++ = TOHEX( out ); | |
31 | + out = (char) ( byte & 0x0f ); | |
32 | + * target++ = TOHEX( out ); | |
33 | + * target++ = ' '; | |
34 | + return 3; | |
35 | +} | |
20 | 36 | |
21 | 37 | |
22 | 38 | int main( void ) |
@@ -25,27 +41,25 @@ int main( void ) | ||
25 | 41 | unsigned long address = 0; /* 4ギガより小さいファイル。 */ |
26 | 42 | int column = 0; |
27 | 43 | int columnLimit = DEFAULTWIDTH; |
44 | + int hexcolumn = 0; | |
28 | 45 | int ch; |
29 | 46 | |
30 | - while ( ( ch = fgetc( in ) ) != EOF ) | |
47 | + do | |
31 | 48 | { |
32 | - if ( column == 0 ) | |
33 | - { | |
34 | - printf( "0x%08x: ", address ); | |
49 | + if ( ( ch = fgetc( in ) ) != EOF ) | |
50 | + { hexcolumn += formatHexByte( ch, hexbuff + hexcolumn ); | |
51 | + chbuff[ column ] = (char) ( isprint( ch ) ? ch : '.' ); | |
52 | + ++column; | |
35 | 53 | } |
36 | - buffer[ column ] = isprint( ch) ? (char) ch : '.'; | |
37 | - printf( "%02x ", ch ); | |
38 | - ++address; | |
39 | - ++column; | |
40 | - if ( column >= columnLimit ) | |
54 | + if ( ( column >= columnLimit ) || ( ch == EOF ) ) | |
41 | 55 | { |
42 | - buffer[ column ] = '\0'; | |
43 | - printf( " %s\n", buffer ); | |
56 | + hexbuff[ hexcolumn ] = chbuff[ column ] = '\0'; | |
57 | + printf( "0x%08x: %s %s\n", address, hexbuff, chbuff ); | |
44 | 58 | column = 0; |
59 | + hexcolumn = 0; | |
60 | + address += columnLimit; | |
45 | 61 | } |
46 | - } | |
47 | - if ( column > 0 ) | |
48 | - fputc( '\n', stdout ); | |
62 | + } while ( ch != EOF ); | |
49 | 63 | |
50 | 64 | return EXIT_SUCCESS; |
51 | 65 | } |