• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

This is a slow ctype library for sjis characters. 高速ではない シフトジス用の ctype 文字類識別ライブラリです。


Commit MetaInfo

Revisión1c093f9b32e6c2fe75d69d3a31ffd8efb138b0c0 (tree)
Tiempo2014-01-03 14:45:01
AutorJoel Matthew Rees <reiisi@user...>
CommiterJoel Matthew Rees

Log Message

working on the shift jis hexdump

Cambiar Resumen

Diferencia incremental

--- a/sjhexdump.c
+++ b/sjhexdump.c
@@ -16,7 +16,23 @@
1616 #define READSIZE 128
1717 #define BUFFSIZE ( READSIZE + 4 )
1818
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+}
2036
2137
2238 int main( void )
@@ -25,27 +41,25 @@ int main( void )
2541 unsigned long address = 0; /* 4ギガより小さいファイル。 */
2642 int column = 0;
2743 int columnLimit = DEFAULTWIDTH;
44+ int hexcolumn = 0;
2845 int ch;
2946
30- while ( ( ch = fgetc( in ) ) != EOF )
47+ do
3148 {
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;
3553 }
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 ) )
4155 {
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 );
4458 column = 0;
59+ hexcolumn = 0;
60+ address += columnLimit;
4561 }
46- }
47- if ( column > 0 )
48- fputc( '\n', stdout );
62+ } while ( ch != EOF );
4963
5064 return EXIT_SUCCESS;
5165 }