home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / text.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  5KB  |  197 lines

  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-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/text.c $
  15.  * $Revision: 2.0 $
  16.  * $Author: john $
  17.  * $Date: 1995/02/27 11:33:09 $
  18.  * 
  19.  * Code for localizable text
  20.  * 
  21.  * $Log: text.c $
  22.  * Revision 2.0  1995/02/27  11:33:09  john
  23.  * New version 2.0, which has no anonymous unions, builds with
  24.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  25.  * 
  26.  * Revision 1.11  1994/12/14  12:53:23  matt
  27.  * Improved error handling
  28.  * 
  29.  * Revision 1.10  1994/12/09  18:36:44  john
  30.  * Added code to make text read from hogfile.
  31.  * 
  32.  * Revision 1.9  1994/12/08  20:56:34  john
  33.  * More cfile stuff.
  34.  * 
  35.  * Revision 1.8  1994/12/08  17:20:06  yuan
  36.  * Cfiling stuff.
  37.  * 
  38.  * Revision 1.7  1994/12/05  15:10:36  allender
  39.  * support encoded descent.tex file (descent.txb)
  40.  * 
  41.  * Revision 1.6  1994/12/01  14:18:34  matt
  42.  * Now support backslash chars in descent.tex file
  43.  * 
  44.  * Revision 1.5  1994/10/27  00:13:10  john
  45.  * Took out cfile.
  46.  * 
  47.  * Revision 1.4  1994/07/11  15:33:49  matt
  48.  * Put in command-line switch to load different text files
  49.  * 
  50.  * Revision 1.3  1994/07/10  09:56:25  yuan
  51.  * #include <stdio.h> added for FILE type.
  52.  * 
  53.  * Revision 1.2  1994/07/09  22:48:14  matt
  54.  * Added localizable text
  55.  * 
  56.  * Revision 1.1  1994/07/09  21:30:46  matt
  57.  * Initial revision
  58.  * 
  59.  * 
  60.  */
  61.  
  62.  
  63. #pragma off (unreferenced)
  64. static char rcsid[] = "$Id: text.c 2.0 1995/02/27 11:33:09 john Exp $";
  65. #pragma on (unreferenced)
  66.  
  67. #include <stdio.h>
  68. #include <stdlib.h>
  69. #include <string.h>
  70. #include <io.h>
  71.  
  72. //#include "cfile.h"
  73. #include "cfile.h"
  74. #include "mem.h"
  75. #include "error.h"
  76.  
  77. #include "inferno.h"
  78. #include "text.h"
  79. #include "args.h"
  80. #include "compbit.h"
  81.  
  82. char *text;
  83.  
  84. char *Text_string[N_TEXT_STRINGS];
  85.  
  86. free_text()
  87. {
  88.     free(text);
  89. }
  90.  
  91. // rotates a byte left one bit, preserving the bit falling off the right
  92. void
  93. encode_rotate_left(char *c)
  94. {
  95.     int found;
  96.  
  97.     found = 0;
  98.     if (*c & 0x80)
  99.         found = 1;
  100.     *c = *c << 1;
  101.     if (found)
  102.         *c |= 0x01;
  103. }
  104.  
  105. //load all the text strings for Descent
  106. void load_text()
  107. {
  108.     CFILE  *tfile;
  109.     CFILE *ifile;
  110.     int len,i, have_binary = 0;
  111.     char *tptr;
  112.     char *filename="descent.tex";
  113.  
  114.     if ((i=FindArg("-text"))!=0)
  115.         filename = Args[i+1];
  116.  
  117.     if ((tfile = cfopen(filename,"rb")) == NULL) {
  118.         filename="descent.txb";
  119.         if ((ifile = cfopen(filename, "rb")) == NULL)
  120.             Error("Cannot open file DESCENT.TEX or DESCENT.TXB");
  121.         have_binary = 1;
  122.  
  123.         len = cfilelength(ifile);
  124.  
  125.         //MALLOC(text,char,len);//Won't compile... working on it..-KRB
  126.         text=malloc(len*sizeof(char));//my hack -KRB
  127.         atexit(free_text);
  128.  
  129.         cfread(text,1,len,ifile);
  130.  
  131.         cfclose(ifile);
  132.  
  133.     } else {
  134.         int c;
  135.         char * p;
  136.  
  137.         len = cfilelength(tfile);
  138.  
  139.         //MALLOC(text,char,len);//Won't compile... working on it..-KRB
  140.         text=malloc(len*sizeof(char));//my hack -KRB
  141.  
  142.         atexit(free_text);
  143.  
  144.         //fread(text,1,len,tfile);
  145.         p = text;
  146.         do {
  147.             c = cfgetc( tfile );
  148.             if ( c != 13 )
  149.                 *p++ = c;
  150.         } while ( c!=EOF );
  151.  
  152.         cfclose(tfile);
  153.     }
  154.  
  155.     for (i=0,tptr=text;i<N_TEXT_STRINGS;i++) {
  156.         char *p;
  157.  
  158.         Text_string[i] = tptr;
  159.  
  160.         tptr = strchr(tptr,'\n');
  161.  
  162.         if (!tptr)
  163.             Error("Not enough strings in text file - expecting %d, found %d",N_TEXT_STRINGS,i);
  164.  
  165.         if ( tptr ) *tptr++ = 0;
  166.  
  167.         if (have_binary) {
  168.             for (p=Text_string[i]; p < tptr - 1; p++) {
  169.                 encode_rotate_left(p);
  170.                 *p = *p ^ BITMAP_TBL_XOR;
  171.                 encode_rotate_left(p);
  172.             }
  173.         }
  174.  
  175.         //scan for special chars (like \n)
  176.         for (p=Text_string[i];p=strchr(p,'\\');) {
  177.             char newchar;
  178.  
  179.             if (p[1] == 'n') newchar = '\n';
  180.             else if (p[1] == 't') newchar = '\t';
  181.             else if (p[1] == '\\') newchar = '\\';
  182.             else
  183.                 Error("Unsupported key sequence <\\%c> on line %d of file <%s>",p[1],i+1,filename); 
  184.  
  185.             p[0] = newchar;
  186.             strcpy(p+1,p+2);
  187.             p++;
  188.         }
  189.  
  190.     }
  191.  
  192. //    Assert(tptr==text+len || tptr==text+len-2);
  193.     
  194. }
  195.  
  196.  
  197.