Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
||
3 | * It is copyright by its individual contributors, as recorded in the |
||
4 | * project's Git history. See COPYING.txt at the top level for license |
||
5 | * terms and a link to the Git history. |
||
6 | */ |
||
7 | /* |
||
8 | * Modified by Bradley Bell, 2002, 2003 |
||
9 | * This program is licensed under the terms of the GPL, version 2 or later |
||
10 | */ |
||
11 | |||
12 | #include <stdio.h> |
||
13 | #include <string.h> |
||
14 | |||
15 | int |
||
16 | main(int argc, char *argv[]) |
||
17 | { |
||
18 | FILE *file, *outfile; |
||
19 | char outfilename[64]; |
||
20 | char ch; |
||
21 | int code; |
||
22 | |||
23 | if (argc < 2) { |
||
24 | printf("TEX2TXB V1.0 Copyright (c) Bryan Aamot, 1995\n" |
||
25 | "Modified by Bradley Bell, 2002, 2003\n" |
||
26 | "Text to TXB converter for Descent HOG files.\n" |
||
27 | "Converts an ascii text file to *.txb descent hog file.\n" |
||
28 | "Usage: TEX2TXB <text file name> <txb file name>\n" |
||
29 | "Example: TEX2TXB briefing.tex briefing.txb\n"); |
||
30 | return 1; |
||
31 | } |
||
32 | file = fopen(argv[1], "rb"); |
||
33 | if (!file) { |
||
34 | printf("Can't open file (%s)\n", argv[1]); |
||
35 | return 2; |
||
36 | } |
||
37 | |||
38 | if (argc > 2) |
||
39 | strcpy(outfilename, argv[2]); |
||
40 | else { |
||
41 | strcpy(outfilename, argv[1]); |
||
42 | strcpy(strrchr(outfilename, '.'), ".txb"); |
||
43 | } |
||
44 | |||
45 | outfile = fopen(outfilename, "wb"); |
||
46 | if (!outfile) { |
||
47 | printf("Can't open file (%s)\n", outfilename); |
||
48 | fclose(file); |
||
49 | return 2; |
||
50 | } |
||
51 | |||
52 | for (;;) { |
||
53 | ch = getc(file); |
||
54 | if (feof(file)) break; |
||
55 | if (ch!=0x0d) { |
||
56 | if (ch==0x0a) { |
||
57 | fprintf(outfile, "\x0a"); |
||
58 | } else { |
||
59 | code = ( ( (ch &0xfC) >> 2) + ( (ch &0x03) << 6 ) ) ^ 0xe9; |
||
60 | fprintf(outfile, "%c", code); |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | |||
65 | fclose(outfile); |
||
66 | fclose(file); |
||
67 | |||
68 | return 0; |
||
69 | } |