]> icculus.org git repositories - btb/d2x.git/blob - utilities/tex2txb.c
changed txt to tex
[btb/d2x.git] / utilities / tex2txb.c
1 #include <stdio.h>
2
3 int
4 main(int argc, char *argv[])
5 {
6         FILE *file, *outfile;
7         char ch;
8         int code;
9
10         if (argc != 3) {
11                 printf("TEX2TXB V1.0 Copyright (c) Bryan Aamot, 1995\n"
12                            "Modified by Bradley Bell, 2002\n"
13                        "Text to TXB converter for Descent HOG files.\n"
14                        "Converts a ascii text files to *.txb descent hog file format.\n"
15                        "Usage: TEX2TXB <text file name> <txb file name>\n"
16                        "Example: TEX2TXB briefing.tex briefing.txb\n");
17                 exit(1);
18         }
19         file = fopen(argv[1], "rb");
20         if (!file) {
21                 printf("Can't open file (%s)\n", argv[1]);
22                 exit(2);
23         }
24
25         outfile = fopen(argv[2], "wb");
26         if (!outfile) {
27                 printf("Can't open file (%s)\n", argv[2]);
28                 fclose(file);
29                 exit(2);
30         }
31
32         for (;;) {
33                 ch = getc(file);
34                 if (feof(file)) break;
35                 if (ch!=0x0d) {
36                         if (ch==0x0a) {
37                                 fprintf(outfile, "\x0a");
38                         } else {
39                                 code = ( ( (ch &0xfC) >> 2) + ( (ch &0x03) << 6 ) ) ^ 0xe9;
40                                 fprintf(outfile, "%c", code);
41                         }
42                 }
43         }
44
45         fclose(outfile);
46         fclose(file);
47
48         return 0;
49 }