-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiwordreader.c
160 lines (148 loc) · 4.04 KB
/
iwordreader.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned char magic[] = { 0xc3, 0xe8, 0xe1, 0xfa, 0xca, 0xe5, 0xfa, 0xca, 0xe9, 0xed, 0xc9, 0xe1, 0xee, 0x01, 0x00, 0x00 };
int main(int argc, char **argv)
{
FILE *inhandle;
int i;
unsigned char byte;
inhandle=fopen(argv[1], "rb");
// read magic
for (i=0; i<16;i++)
{
byte=fgetc(inhandle);
//if (byte != magic[i])
//{
// printf("Not an Interword file: magic doesnt match\n");
// exit(1);
//}
}
// Now read information
int textstart;
fseek(inhandle,0x32,SEEK_SET);
textstart=fgetc(inhandle)+(fgetc(inhandle)<<8);
#ifdef DEBUG
fseek(inhandle,0x43,SEEK_SET);
byte=fgetc(inhandle);
printf("Cursor Line: %d\n",byte);
byte=fgetc(inhandle);
printf("Number of Lines: %d\n",byte);
byte=fgetc(inhandle);
printf("Number of Columns: %d\n",byte);
byte=fgetc(inhandle);
printf("Unknown: %d\n",byte);
byte=fgetc(inhandle);
printf("Flags: ",byte);
if (byte&0x40) printf("show_line_numbers ");
if (byte&0x02) printf("show_print_codes ");
if (byte&0x01) printf("interlace ");
printf("\n");
byte=fgetc(inhandle);
printf("Unknown: %d\n",byte);
byte=fgetc(inhandle);
printf("Unknown: %d\n",byte);
byte=fgetc(inhandle);
printf("Unknown: %d\n",byte);
byte=fgetc(inhandle);
printf("Foreground Colour: %d\n",byte);
byte=fgetc(inhandle);
printf("Background Colour: %d\n",byte);
byte=fgetc(inhandle);
printf("Unknown: %d\n",byte);
byte=fgetc(inhandle);
printf("Keyboard repeat rate: %d\n",byte);
byte=fgetc(inhandle);
printf("Keyboard repeat delay: %d\n",byte);
#endif
fseek(inhandle,textstart,SEEK_SET);
int ruler[255];
unsigned char pos=0;
for (i=0;i<150;i++) ruler[i]=0;
char underline,bold,italic,centre,right,justify;
while (!feof(inhandle))
{
byte=fgetc(inhandle);
byte&=0x7f;
if (byte < 32 || byte == 0x7f)
{
switch (byte)
{
case 0x0d:
{
// reset to nowt special
if (italic==1) { printf("</em>"); italic=0; }
if (centre==1) { printf("</center>"); centre=0; }
if (right==1) { printf("</right>"); right=0; }
if (justify==1) { printf("</justify>"); justify=0; }
printf("\n");
pos=0;
break;
}
case 0x05:
{
// In ruler
fgetc(inhandle);
// copy ruler to array rule, 0 = nowt 1 = LM, 2 = RM, 3= RetM, 4 = Tab
ruler[fgetc(inhandle)]=1;
ruler[fgetc(inhandle)]=2;
ruler[fgetc(inhandle)]=3;
int tab=0;
do
{
tab=fgetc(inhandle);
if (tab != 0x87)
ruler[tab]=4;
} while (tab != 0x87);
break;
}
case 0x09:
{
/*for(i=pos;i<106;i++)
{
if (ruler[i]==4)
{
break;
}
else
{
printf(" ");
}
}*/
printf("\t");
break;
}
case 0x0b:
{
printf("<strong>");
bold=1;
break;
}
case 0x0c:
{
printf("<u>");
underline=1;
break;
}
case 0x13:
{
if (bold==1) { printf("</strong>"); bold=0; }
break;
}
case 0x14:
{
if (underline==1) { printf("</u>"); underline=0; }
break;
}
default:
break;
}
}
else
{
printf("%c",byte);
pos++;
}
}
fclose(inhandle);
}