]> icculus.org git repositories - btb/d2x.git/blob - main/text.c
Fix detection of opengl
[btb/d2x.git] / main / text.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 #ifdef HAVE_CONFIG_H
15 #include <conf.h>
16 #endif
17
18 #ifdef RCS
19 static char rcsid[] = "$Id: text.c,v 1.3 2001-01-31 15:17:59 bradleyb Exp $";
20 #endif
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "pstypes.h"
27 #include "cfile.h"
28 #include "u_mem.h"
29 #include "error.h"
30
31 #include "inferno.h"
32 #include "text.h"
33 #include "args.h"
34 #include "compbit.h"
35
36 char *text;
37
38 char *Text_string[N_TEXT_STRINGS];
39
40 void free_text()
41 {
42         d_free(text);
43 }
44
45 // rotates a byte left one bit, preserving the bit falling off the right
46 void
47 encode_rotate_left(char *c)
48 {
49         int found;
50
51         found = 0;
52         if (*c & 0x80)
53                 found = 1;
54         *c = *c << 1;
55         if (found)
56                 *c |= 0x01;
57 }
58
59 //decode and encoded line of text
60 void decode_text_line(char *p)
61 {
62         for (;*p;p++) {
63                 encode_rotate_left(p);
64                 *p = *p ^ BITMAP_TBL_XOR;
65                 encode_rotate_left(p);
66         }
67 }
68
69 //load all the text strings for Descent
70 void load_text()
71 {
72         CFILE  *tfile;
73         CFILE *ifile;
74         int len,i, have_binary = 0;
75         char *tptr;
76         char *filename="descent.tex";
77
78         if ((i=FindArg("-text"))!=0)
79                 filename = Args[i+1];
80
81         if ((tfile = cfopen(filename,"rb")) == NULL) {
82                 filename="descent.txb";
83                 if ((ifile = cfopen(filename, "rb")) == NULL)
84                         Error("Cannot open file DESCENT.TEX or DESCENT.TXB\nIs descent2.hog in your current directory?");
85                 have_binary = 1;
86
87                 len = cfilelength(ifile);
88
89                 MALLOC(text,char,len);
90
91                 atexit(free_text);
92
93                 cfread(text,1,len,ifile);
94
95                 cfclose(ifile);
96
97         } else {
98                 int c;
99                 char * p;
100
101                 len = cfilelength(tfile);
102
103                 MALLOC(text,char,len);
104
105                 atexit(free_text);
106
107                 //fread(text,1,len,tfile);
108                 p = text;
109                 do {
110                         c = cfgetc( tfile );
111                         if ( c != 13 )
112                                 *p++ = c;
113                 } while ( c!=EOF );
114
115                 cfclose(tfile);
116         }
117
118         for (i=0,tptr=text;i<N_TEXT_STRINGS;i++) {
119                 char *p;
120
121                 Text_string[i] = tptr;
122
123                 tptr = strchr(tptr,'\n');
124
125                 #ifdef MACINTOSH                        // total hack for mac patch since they don't want to patch data.
126                 if (!tptr && (i == 644) )
127                         break;
128                 #else
129                 if (!tptr)
130                 {
131                         Warning("Not enough strings in text file - expecting %d, found %d\nThis probably means you have the wrong version of the descent 2 datafiles. You need version 1.2\n",N_TEXT_STRINGS,i);
132                         if (i == 644) break;
133                 }
134                 #endif
135
136                 if ( tptr ) *tptr++ = 0;
137
138                 if (have_binary)
139                         decode_text_line(Text_string[i]);
140
141                 //scan for special chars (like \n)
142                 for (p=Text_string[i];(p=strchr(p,'\\'));) {
143                         char newchar;
144
145                         if (p[1] == 'n') newchar = '\n';
146                         else if (p[1] == 't') newchar = '\t';
147                         else if (p[1] == '\\') newchar = '\\';
148                         else
149                                 Error("Unsupported key sequence <\\%c> on line %d of file <%s>",p[1],i+1,filename); 
150
151                         p[0] = newchar;
152                         strcpy(p+1,p+2);
153                         p++;
154                 }
155  
156         }
157
158 //      Assert(tptr==text+len || tptr==text+len-2);
159         
160 }
161
162