File: ebdump.c

package info (click to toggle)
ebview 0.3.6-9
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,344 kB
  • ctags: 1,899
  • sloc: ansic: 24,290; sh: 7,910; xml: 1,771; makefile: 327; sed: 93
file content (162 lines) | stat: -rwxr-xr-x 3,497 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * ˡ:
 *     text <book-path> <subbook-index> <number>
 * :
 *     text /cdrom 0 10
 * :
 *     <book-path> ǻꤷ CD-ROM Ҥܤӡʸ
 *     Ƭ <number> ʬñϤޤ
 *
 *     <subbook-index> ˤϡоݤܤΥǥåꤷ
 *     ǥåϡҤκǽܤ 012 ... 
 *     ʤޤ
 */
#include "config.h"

#include <glib.h>

#include <stdio.h>
#include <stdlib.h>

#include <eb/eb.h>
#include <eb/error.h>
#include <eb/text.h>

inline gboolean isjis(gchar *buff){
	g_assert(buff != NULL);
	
	if((buff[0] >= 0x21) && (buff[0] <= 0x74) && 
	   (buff[1] >= 0x21) && (buff[1] <= 0x7E))
		return(TRUE);
	return(FALSE);
}


int
main(argc, argv)
int argc;
char *argv[];
{
	EB_Error_Code error_code;
	EB_Book book;
	EB_Subbook_Code subbook_list[EB_MAX_SUBBOOKS];
	int subbook_count;
	int subbook_index;
	char text[EB_SIZE_PAGE];
	ssize_t read_length;
	int text_count;
	int block_no;
	
	gchar *p_hex;
	gchar *p_char;
	gchar hex_buff[512];
	gchar char_buff[512];
	gchar buff[512];
	char *result;
	int i;
	
	/* ޥɹ԰å*/
	if (argc != 4) {
		fprintf(stderr, "Usage: %s book-path subbook-index block-number\n",
			argv[0]);
		exit(1);
	}
	
	block_no = strtol(argv[3], NULL, 16);
	
	/* EB 饤֥ `book' */
	eb_initialize_library();
	eb_initialize_book(&book);
	
	/* Ҥ `book' ˷դ롣*/
	error_code = eb_bind(&book, argv[1]);
	if (error_code != EB_SUCCESS) {
		fprintf(stderr, "%s: failed to bind the book, %s: %s\n",
			argv[0], eb_error_message(error_code), argv[1]);
		goto die;
	}
	
	/* ܤΰ*/
	error_code = eb_subbook_list(&book, subbook_list, &subbook_count);
	if (error_code != EB_SUCCESS) {
		fprintf(stderr, "%s: failed to get the subbbook list, %s\n",
			argv[0], eb_error_message(error_code));
		goto die;
	}
	
	/* ܤΥǥå*/
	subbook_index = atoi(argv[2]);
	
	/*ָߤ (current subbook)פꡣ*/
	if (eb_set_subbook(&book, subbook_list[subbook_index]) < 0) {
		fprintf(stderr, "%s: failed to set the current subbook, %s\n",
			argv[0], eb_error_message(error_code));
		goto die;
	}
	
	
	if (zio_lseek(&book.subbook_current->text_zio, 
		      (block_no - 1) * EB_SIZE_PAGE, SEEK_SET) == -1) {
		fprintf(stderr, "Failed to seek zio\n");
		goto die;
	}
	
	read_length = zio_read(&book.subbook_current->text_zio, text,
			       EB_SIZE_PAGE);
	if (read_length < 0) {
		fprintf(stderr, "Failed to read zio\n");
		goto die;
	}
	
	
	printf("block number : 0x%x\n\n", block_no);
	
	for( i = 0 ;  i < EB_SIZE_PAGE ; i=i+2){
		
                // ɥ쥹ɽ
		if((i % 16) == 0){
			p_hex = hex_buff;
			p_char = char_buff;
			sprintf(p_hex, "0x%02x(0x%08x) ", (i / 16), (block_no - 1) * EB_SIZE_PAGE + i);
			p_hex += 17;
			
			sprintf(p_char, " ");
			p_char += 1;
		}
		
		sprintf(p_hex, "%02x ", (unsigned char)text[i]);
		p_hex += 3;
		sprintf(p_hex, "%02x ", (unsigned char)text[i+1]);
		p_hex += 3;
		
		
		if(isjis(&text[i])) {
			*p_char = text[i] | 0x80;
			p_char ++;
			*p_char = text[i+1] | 0x80;
			p_char ++;
			*p_char = '\0';
		} else {
			sprintf(p_char, "..");
			p_char +=2;
		}
		
		if((i % 16) == 14){
			printf("%s", hex_buff);
			printf("%s\n", char_buff);
		}
	}
	
	
        
	/* Ҥ EB 饤֥Ѥλ*/
	eb_finalize_book(&book);
	eb_finalize_library();
	exit(0);
	
	/* 顼ȯǽλȤν*/
 die:
	eb_finalize_book(&book);
	eb_finalize_library();
	exit(1);
}