]> icculus.org git repositories - btb/d2x.git/blob - utilities/txb2tex.c
allow specifying file to extract
[btb/d2x.git] / utilities / txb2tex.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("TXB2TEX V1.0 Copyright (c) Bryan Aamot, 1995\n"
12                            "Modified by Bradley Bell, 2002\n"
13                        "TXB to Text converter for Descent HOG files.\n"
14                        "Converts a *.txb descent hog file to an ascii file.\n"
15                        "Usage: TXB2TEX <txb file name> <text file name>\n"
16                        "Example: TEX2TXB briefing.txb briefing.tex\n");
17                 exit(1);
18         }
19         file = fopen(argv[1], "rb");
20         if (!file) {
21                 printf("Can't open txb file (%s)\n", argv[1]);
22                 exit(2);
23         }
24         outfile = fopen(argv[2], "wb");
25         if (!outfile) {
26                 printf("Can't open file (%s)\n", argv[2]);
27                 fclose(file);
28                 exit(2);
29         }
30         for (;;) {
31                 code = getc(file);
32                 if (feof(file)) break;
33                 if (code == 0x0a) {
34                         fprintf(outfile, "\x0d\x0a");
35                 } else {
36                         ch = (  ( (code&0x3f) << 2 ) + ( (code&0xc0) >> 6 )  ) ^ 0xa7;
37                         fprintf(outfile, "%c", ch);
38                 }
39         }
40
41         fclose(outfile);
42         fclose(file);
43
44         return 0;
45 }