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