1 /* $Id: text.c,v 1.16 2004-11-28 07:32:12 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Code for localizable text
26 static char rcsid[] = "$Id: text.c,v 1.16 2004-11-28 07:32:12 btb Exp $";
41 #define SHAREWARE_TEXTSIZE 14677
45 char *Text_string[N_TEXT_STRINGS];
52 // rotates a byte left one bit, preserving the bit falling off the right
54 encode_rotate_left(char *c)
66 #define BITMAP_TBL_XOR 0xD3
68 //decode an encoded line of text of bitmaps.tbl
69 void decode_text_line(char *p)
72 encode_rotate_left(p);
73 *p = *p ^ BITMAP_TBL_XOR;
74 encode_rotate_left(p);
78 // decode buffer of text, preserves newlines
79 void decode_text(char *buf, int len)
84 for (i = 0, ptr = buf; i < len; i++, ptr++)
88 encode_rotate_left(ptr);
89 *ptr = *ptr ^ BITMAP_TBL_XOR;
90 encode_rotate_left(ptr);
96 #if !defined(_MSC_VER) && !defined(macintosh)
99 //load all the text strings for Descent
104 int len,i, have_binary = 0;
106 char *filename="descent.tex";
108 if ((i=FindArg("-text"))!=0)
109 filename = Args[i+1];
111 if ((tfile = cfopen(filename,"rb")) == NULL) {
112 filename="descent.txb";
113 if ((ifile = cfopen(filename, "rb")) == NULL) {
114 Warning("Cannot open file DESCENT.TEX or DESCENT.TXB");
119 len = cfilelength(ifile);
121 MALLOC(text,char,len);
125 cfread(text,1,len,ifile);
133 len = cfilelength(tfile);
135 MALLOC(text,char,len);
139 //fread(text,1,len,tfile);
150 for (i=0,tptr=text;i<N_TEXT_STRINGS;i++) {
153 Text_string[i] = tptr;
155 tptr = strchr(tptr,'\n');
159 if (i == 644) break; /* older datafiles */
161 Error("Not enough strings in text file - expecting %d, found %d\n", N_TEXT_STRINGS, i);
164 if ( tptr ) *tptr++ = 0;
167 decode_text_line(Text_string[i]);
169 //scan for special chars (like \n)
170 for (p=Text_string[i];(p=strchr(p,'\\'));) {
173 if (p[1] == 'n') newchar = '\n';
174 else if (p[1] == 't') newchar = '\t';
175 else if (p[1] == '\\') newchar = '\\';
177 Error("Unsupported key sequence <\\%c> on line %d of file <%s>",p[1],i+1,filename);
189 if (len == SHAREWARE_TEXTSIZE)
191 Text_string[173] = Text_string[172];
192 Text_string[172] = Text_string[171];
193 Text_string[171] = Text_string[170];
194 Text_string[170] = Text_string[169];
195 Text_string[169] = "Windows Joystick";
198 Text_string[644] = "Z1";
199 Text_string[645] = "UN";
200 Text_string[646] = "P1";
201 Text_string[647] = "R1";
202 Text_string[648] = "Y1";
205 //Assert(tptr==text+len || tptr==text+len-2);