]> icculus.org git repositories - btb/d2x.git/blob - utilities/tex2txb.c
gr_copy_palette no really a kludge, I think
[btb/d2x.git] / utilities / tex2txb.c
1 /*
2  * Modified by Bradley Bell, 2002, 2003
3  * This program is licensed under the terms of the GPL, version 2 or later
4  */
5
6 #include <stdio.h>
7 #include <string.h>
8
9 int
10 main(int argc, char *argv[])
11 {
12         FILE *file, *outfile;
13         char outfilename[64];
14         char ch;
15         int code;
16
17         if (argc < 2) {
18                 printf("TEX2TXB V1.0 Copyright (c) Bryan Aamot, 1995\n"
19                            "Modified by Bradley Bell, 2002, 2003\n"
20                        "Text to TXB converter for Descent HOG files.\n"
21                        "Converts an ascii text file to *.txb descent hog file.\n"
22                        "Usage: TEX2TXB <text file name> <txb file name>\n"
23                        "Example: TEX2TXB briefing.tex briefing.txb\n");
24                 return 1;
25         }
26         file = fopen(argv[1], "rb");
27         if (!file) {
28                 printf("Can't open file (%s)\n", argv[1]);
29                 return 2;
30         }
31
32         if (argc > 2)
33                 strcpy(outfilename, argv[2]);
34         else {
35                 strcpy(outfilename, argv[1]);
36                 strcpy(strrchr(outfilename, '.'), ".txb");
37         }
38
39         outfile = fopen(outfilename, "wb");
40         if (!outfile) {
41                 printf("Can't open file (%s)\n", outfilename);
42                 fclose(file);
43                 return 2;
44         }
45
46         for (;;) {
47                 ch = getc(file);
48                 if (feof(file)) break;
49                 if (ch!=0x0d) {
50                         if (ch==0x0a) {
51                                 fprintf(outfile, "\x0a");
52                         } else {
53                                 code = ( ( (ch &0xfC) >> 2) + ( (ch &0x03) << 6 ) ) ^ 0xe9;
54                                 fprintf(outfile, "%c", code);
55                         }
56                 }
57         }
58
59         fclose(outfile);
60         fclose(file);
61
62         return 0;
63 }