CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

DIPTHONG.CPP (13688B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /* $Header: g:/library/source/rcs/./dipthong.c 1.15 1994/05/20 15:35:17 joe_bostic Exp $ */
     17 /***************************************************************************
     18  **   C O N F I D E N T I A L --- W E S T W O O D   A S S O C I A T E S   **
     19  ***************************************************************************
     20  *                                                                         *
     21  *                 Project Name : Westwood Library                         *
     22  *                                                                         *
     23  *                    File Name : DIPTHONG.C                               *
     24  *                                                                         *
     25  *                   Programmer : Joe L. Bostic                            *
     26  *                                                                         *
     27  *                   Start Date : February 23, 1992                        *
     28  *                                                                         *
     29  *                  Last Update : February 13, 1995 [BWG]                  *
     30  *                                                                         *
     31  * DIGRAM or DIATOMIC encoding is the correct term for this method.        *
     32  * This is a fixed dictionary digram encoding optimized for English text.  *
     33  *                                                                         *
     34  *-------------------------------------------------------------------------*
     35  * Functions:                                                              *
     36  *   Extract_String -- Extracts a string pointer from a string data block. *
     37  *   UnDip_Text -- Undipthongs a text string into specified buffer.        *
     38  *   Dip_Text -- Compresses text by using dipthonging.                     *
     39  *   Fixup_Text -- Converts dipthonged foreign text into normal text.      *
     40  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     41 
     42 //#include	"function.h"
     43 //#include	"ems.h"
     44 #include <keyboard.h>
     45 #include "dipthong.h"
     46 
     47 /***************************************************************************
     48  * Fixup_Text -- Converts dipthonged foreign text into normal text.        *
     49  *                                                                         *
     50  *    Takes text that has been processed (or undipped) to hold foriegn     *
     51  *    language character pairs (needed for Window_Print) and converts it   *
     52  *    so that Text_Print will print it properly.  Typically this would be  *
     53  *    used after text has been undipped but before it will be Text_Printed.*
     54  *    Text that is to be Window_Printed doesn't and mustn't have its text  *
     55  *    processed by this routine.                                           *
     56  *                                                                         *
     57  * INPUT:   source   -- Pointer to the source string to process.           *
     58  *                                                                         *
     59  *          dest     -- Destination buffer to hold the processed string.   *
     60  *                                                                         *
     61  * OUTPUT:  none                                                           *
     62  *                                                                         *
     63  * WARNINGS:   This routine will only reduce the size of the string if it  *
     64  *             modifies it at all.  Because of this it is quite legal to   *
     65  *             pass the same pointers to this routine so that it will      *
     66  *             modify the string "in place".                               *
     67  *                                                                         *
     68  * HISTORY:                                                                *
     69  *   08/13/1993 JLB : Created.                                             *
     70  *   10/06/1994 JLB : Handles source string in EMS.                        *
     71  *=========================================================================*/
     72 void Fixup_Text(char const *source, char *dest)
     73 {
     74 	if (source && dest) {
     75 		char const 	*src;
     76 		char			temp;
     77 
     78 		src = source;
     79 		while (*src) {
     80 			if (*src == KA_EXTEND) {
     81 				src++;
     82 				temp = *src++;
     83 				temp += 127;
     84 				*dest++ = temp;
     85 			} else {
     86 				*dest++ = *src++;
     87 			}
     88 		}
     89 		*dest = '\0';
     90 
     91 	}
     92 }
     93 
     94 
     95 /***************************************************************************
     96  * Dip_Text -- Compresses text by using dipthonging.                       *
     97  *                                                                         *
     98  *    This routine is used to compress text by using dipthonging.  Text    *
     99  *    that is compressed in this fashion usually is reduced in size by     *
    100  *    approximately 40%.                                                   *
    101  *                                                                         *
    102  * INPUT:   source   -- Pointer to the source string to compress.          *
    103  *                                                                         *
    104  *          dest     -- Pointer to the buffer that will hold the dipthong  *
    105  *                      text output.                                       *
    106  *                                                                         *
    107  * OUTPUT:  Returns the number of bytes output into the output buffer.     *
    108  *                                                                         *
    109  * WARNINGS:   none                                                        *
    110  *                                                                         *
    111  * HISTORY:                                                                *
    112  *   08/13/1993 JLB : Created.                                             *
    113  *=========================================================================*/
    114 int Dip_Text(char const *source, char *dest)
    115 {
    116 	unsigned char	first,		// First character in pair.
    117 						next;			// Second character in pair.
    118 	int				common,		// Common character index.
    119 						dipthong;	// Dipthong character index.
    120 
    121 	unsigned long length=0;		// Length of output string
    122 
    123 	first = *source++;
    124 	next = *source;
    125 	while (first) {
    126 
    127 		if (first > 127) {
    128 
    129 			/*
    130 			**	Characters greater than 127 cannot be dipthonged.  They must
    131 			**	be preceeded with an extended character code.
    132 			*/
    133 			*dest++ = (char)KA_EXTEND;
    134 			first -= 127;
    135 			length++;
    136 
    137 		} else {
    138 
    139 			/*
    140 			**	Normal characters can be dipthonged.  First see if there is a
    141 			**	match in the Common table.
    142 			*/
    143 			for (common = 0; common < 16; common++) {
    144 				if (Common[common] == first) {
    145 
    146 					/*
    147 					**	Common character found.  See if there is a matching
    148 					**	Dipthong character.
    149 					*/
    150 					for (dipthong = 0; dipthong < 8; dipthong++) {
    151 						if (Dipthong[common][dipthong] == next) {
    152 							first = (unsigned char) (common << 3);
    153 							first |= (unsigned char)dipthong;
    154 							first |= (unsigned char)0x80;
    155 							source++;
    156 						}
    157 					}
    158 				}
    159 			}
    160 		}
    161 
    162 		/*
    163 		**	Output the translated character to the destination buffer.
    164 		*/
    165 		*dest++ = first;
    166 		length++;
    167 
    168 		first = *source++;
    169 		next = *source;
    170 	}
    171 
    172 	*dest = '\0';
    173 
    174 	return(length);
    175 }
    176 
    177 
    178 /***************************************************************************
    179  * UnDip_Text -- Undipthongs a text string into specified buffer.          *
    180  *                                                                         *
    181  *    This routine is used to undipthong a text string and place the       *
    182  *    undipped text into the buffer specified.  Since dipthonged text is   *
    183  *    compressed, in order for the text to be used it must be undipped     *
    184  *    first.                                                               *
    185  *                                                                         *
    186  * INPUT:   source   -- Pointer to the dipped string.                      *
    187  *                                                                         *
    188  *          dest     -- Pointer to the destination buffer.                 *
    189  *                                                                         *
    190  * OUTPUT:  Returns the number of bytes placed into the destination        *
    191  *          buffer.                                                        *
    192  *                                                                         *
    193  * WARNINGS:   Be sure the destination buffer is big enough to hold the    *
    194  *             undipped text.                                              *
    195  *                                                                         *
    196  * HISTORY:                                                                *
    197  *   08/13/1993 JLB : Created.                                             *
    198  *   10/06/1994 JLB : Handles source string in EMS.                        *
    199  *=========================================================================*/
    200 int UnDip_Text(char const *source, char *dest)
    201 {
    202 	int	c;			// Source input character.
    203 	int	common;	// Common character index.
    204 	int	len;		// Length of output string.
    205 	char const *src;
    206 
    207 	len = 0;						// Presume no translation.
    208 
    209 	/*
    210 	**	Sweep through the source text and dipthong it.
    211 	*/
    212 	src = source;
    213 	c = *src++;
    214 	while (c) {
    215 
    216 		/*
    217 		**	Convert a dipthong character into it's component
    218 		**	ASCII characters.
    219 		*/
    220 		if (c & 0x80) {
    221 			c &= 0x7F;
    222 
    223 			common = (c & 0x78) >> 3;
    224 
    225 			*dest++ = Common[common];
    226 			len++;
    227 
    228 			c = Dipthong[common][c & 0x07];
    229 		}
    230 
    231 		*dest++ = (unsigned char)c;
    232 		len++;
    233 
    234 		c = *src++;
    235 	}
    236 
    237 	/*
    238 	**	End the output text with a '\0'.
    239 	*/
    240 	*dest++ = '\0';
    241 
    242 	return(len);
    243 }
    244 
    245 
    246 /***************************************************************************
    247  * Extract_String -- Extracts a string pointer from a string data block.   *
    248  *                                                                         *
    249  *    This routine is used to find a pointer to the specified string       *
    250  *    inside a string block.  String data blocks are created with the      *
    251  *    TEXTMAKE utility.  The data block my reside in XMS or EMS memory,    *
    252  *    but of course the returned string pointer will also point to         *
    253  *    such memory.  In this case, the string must be placed in real        *
    254  *    memory before it can be used.                                        *
    255  *                                                                         *
    256  * INPUT:   data     -- Pointer to the string data block.                  *
    257  *                                                                         *
    258  *          string   -- The string number to extract (if < 0 then NULL     *
    259  *                      is returned).                                      *
    260  *                                                                         *
    261  * OUTPUT:  Returns with pointer to the string number specified.           *
    262  *                                                                         *
    263  * WARNINGS:   none                                                        *
    264  *                                                                         *
    265  * HISTORY:                                                                *
    266  *   08/13/1993 JLB : Created.                                             *
    267  *   08/13/1993 JLB : Handles EMS or XMS data pointer.                     *
    268  *=========================================================================*/
    269 
    270 #define TXT_GUEST 					4567+3
    271 #define TXT_LOGIN 					4567+4
    272 #define TXT_LOGIN_TO_INTERNET 	4567+5
    273 #define TXT_YOUR_HANDLE 			4567+6
    274 #define TXT_YOUR_PASSWORD 		4567+7
    275 #define TXT_INTERNET_HOST		4567+8
    276 #define TXT_INTERNET_JOIN		4567+9
    277 #define TXT_INTERNET_GAME_TYPE	4567+10
    278 #define TXT_JOIN_INTERNET_GAME	4567+11
    279 #define TXT_ENTER_IP_ADDRESS	4567+12
    280 #define TXT_WINSOCK_CONNECTING							4567+13
    281 #define TXT_WINSOCK_NOT_CONNECTING					4567+14
    282 #define TXT_WINSOCK_UNABLE_TO_CONNECT_TO_SERVER	4567+15
    283 #define TXT_WINSOCK_CONTACTING_SERVER				4567+16
    284 #define TXT_WINSOCK_SERVER_ADDRESS_LOOKUP_FAILED	4567+17
    285 #define TXT_WINSOCK_UNABLE_TO_ACCEPT_CLIENT		4567+18
    286 #define TXT_WINSOCK_UNABLE_TO_CONNECT				4567+19
    287 #define TXT_WINSOCK_CONNECTION_LOST					4567+20
    288 #define TXT_WINSOCK_RESOLVING_HOST_ADDRESS			4567+21
    289 
    290 static char InternetTxt[22][40]={
    291 	"Internet H2H",
    292 	"Host Internet Game",
    293 	"Join Internet Game",
    294 	"Guest",
    295 	"Login",
    296 	"Login to Planet Westwood",
    297 	"Planet Westwood Handle",
    298 	"Planet Westwood Password",
    299 	"Host Game",
    300 	"Join Game",
    301 	"Choose Type of Internet Game",
    302 	"Join Internet Game",
    303 	"Address of Host",
    304 	"Connecting...",
    305 	"Connection Error!",
    306 	"Unable to connect to host!",
    307 	"Connecting to host...",
    308 	"Unable to resolve host address!",
    309 	"Unable to accept client connection",
    310 	"Unable to connect!",
    311 	"Connection lost!",
    312 	"Resolving address of host..."
    313 };
    314 
    315 char *Extract_String(void const *data, int string)
    316 {
    317 	unsigned short int	const *ptr;
    318 
    319 	if (!data || string < 0) return(NULL);
    320 
    321 	if (string >= 4567) return (InternetTxt[string-4567]);
    322 
    323 	ptr = (unsigned short int const *)data;
    324 	return (((char*)data) + ptr[string]);
    325 }