]> icculus.org git repositories - btb/d2x.git/blob - utilities/txt2txb.c
whitespace
[btb/d2x.git] / utilities / txt2txb.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("TXT2TXB V1.0 Copyright (c) Bryan Aamot, 1995\n"
12                        "Text to TXB converter for Descent HOG files.\n"
13                        "Converts a ascii text files to *.txb descent hog file format.\n"
14                        "Usage: TXT2TXB <text file name> <txb file name>\n"
15                        "Example: TXT2TXB briefing.txt briefing.txb\n");
16                 exit(1);
17         }
18         file = fopen(argv[1], "rb");
19         if (!file) {
20                 printf("Can't open file (%s)\n", argv[1]);
21                 exit(2);
22         }
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
31         for (;;) {
32                 ch = getc(file);
33                 if (feof(file)) break;
34                 if (ch!=0x0d) {
35                         if (ch==0x0a) {
36                                 fprintf(outfile, "\x0a");
37                         } else {
38                                 code = ( ( (ch &0xfC) >> 2) + ( (ch &0x03) << 6 ) ) ^ 0xe9;
39                                 fprintf(outfile, "%c", code);
40                         }
41                 }
42         }
43
44         fclose(outfile);
45         fclose(file);
46
47         return 0;
48 }