/* ** Command & Conquer Generals Zero Hour(tm) ** Copyright 2025 Electronic Arts Inc. ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program. If not, see . */ // JSUPPORT.CPP // DBCS Support Codes #include #include "jsupport.h" // ‘O’u‹Ö‘Ľ•śŽš // Can't set these characters on top of line static BOOL IsDBCSInvalidAtTop(unsigned int c) { static BYTE * dtbl = (BYTE *)"‘‹fhńŒŽABXrtvxzl‚Ÿ‚Ą‚Ł‚Ľ‚§‚Á‚á‚ă‚ĺ‚ěJKTUƒ@ƒBƒDƒFƒHƒbƒƒƒ…ƒ‡ƒŽƒ•ƒ–E[RSI“jCDFGHnp"; static BYTE * stbl = (BYTE *)"!%),.:;?]}ĄŁ¤ĽŢß"; if(c<0x100) { if(strchr((char *)stbl,(char)c)) return TRUE; } else { BYTE c1,c2,*p; c1 = (BYTE)(c >> 8); c2 = (BYTE)(c & 0xff); p = dtbl; while(*p) { if((*p==c1)&&(*(p+1)==c2)) return TRUE; p+=2; } } return FALSE; } // Œă’u‹Ö‘Ľ•śŽš // Can't set these characters on end of line static BOOL IsDBCSInvalidAtEnd( unsigned int c ) { static BYTE * dtbl = (BYTE *)"egqsuwykimo’"; static BYTE * stbl = (BYTE *)"˘({["; if(c<0x100) { if(strchr((char *)stbl,(char)c)) return TRUE; } else { BYTE c1,c2,*p; c1 = (BYTE)(c >> 8); c2 = (BYTE)(c & 0xff); p = dtbl; while(*p) { if((*p==c1)&&(*(p+1)==c2)) return TRUE; p+=2; } } return FALSE; } int nGetWord( char *string, int fdbcs ) { BOOL bCiae0, bCiat1, bDbcs0, bDbcs1; BYTE *p = (BYTE *)string; UINT c0, c1, c; //-------------------------------------------------------------------------- // If no string was passed in, exit. //-------------------------------------------------------------------------- if( !p || !( c0 = *p++ )) { // if(( p == NULL ) || ( *p == '\0' )) { return 0; } // c0 = *p; //-------------------------------------------------------------------------- // If we are NOT a double-byte language, then just parse first word. //-------------------------------------------------------------------------- if( !fdbcs ) { int n = 0; while( *p >' ' ) { n++; p++; } if( *p ) { n++; } return n; } //-------------------------------------------------------------------------- // If we are a double-byte language... //-------------------------------------------------------------------------- bDbcs0 = IsDBCSLeadByte( c0 ) && *p; if( bDbcs0 ) { c0 = ( c0 << 8 ) | *p++; } bCiae0 = IsDBCSInvalidAtEnd( c0 ); while( c1 = *p ) { bDbcs1 = ( IsDBCSLeadByte( c1 ) && ( c = *( p + 1 ))); if( bDbcs1 ) { c1 = ( c1<<8 ) | c; } if(( bDbcs0 || bDbcs1 ) && !( bDbcs0 && bDbcs1 )) { // XOR break; } if( bDbcs1 ) { bCiat1 = IsDBCSInvalidAtTop( c1 ); if( !( bCiae0 || bCiat1 )) { break; } bCiae0 = IsDBCSInvalidAtEnd( c1 ); p+=2; } else { if( c0<=' ' ) { break; } p++; } bDbcs0 = bDbcs1; c0 = c1; } return( p - (BYTE *)string ); }