// Message handler for text messages // displays a string, looking them up from the titles.txt file, which can be localised // parameters: // byte: message direction ( HUD_PRINTCONSOLE, HUD_PRINTNOTIFY, HUD_PRINTCENTER, HUD_PRINTTALK ) // string: message // optional parameters: // string: message parameter 1 // string: message parameter 2 // string: message parameter 3 // string: message parameter 4 // any string that starts with the character '#' is a message name, and is used to look up the real message in titles.txt // the next (optional) one to four strings are parameters for that string (which can also be message names if they begin with '#') int CHudTextMessage::MsgFunc_TextMsg( const char *pszName, int iSize, void *pbuf ) { BEGIN_READ( pbuf, iSize ); int msg_dest = READ_BYTE(); #define MSG_BUF_SIZE 128 static char szBuf[6][MSG_BUF_SIZE]; char *msg_text = LookupString( READ_STRING(), &msg_dest ); msg_text = safe_strcpy( szBuf[0], msg_text , MSG_BUF_SIZE); // keep reading strings and using C format strings for subsituting the strings into the localised text string char *sstr1 = LookupString( READ_STRING() ); sstr1 = safe_strcpy( szBuf[1], sstr1 , MSG_BUF_SIZE); StripEndNewlineFromString( sstr1 ); // these strings are meant for subsitution into the main strings, so cull the automatic end newlines char *sstr2 = LookupString( READ_STRING() ); sstr2 = safe_strcpy( szBuf[2], sstr2 , MSG_BUF_SIZE); StripEndNewlineFromString( sstr2 ); char *sstr3 = LookupString( READ_STRING() ); sstr3 = safe_strcpy( szBuf[3], sstr3 , MSG_BUF_SIZE); StripEndNewlineFromString( sstr3 ); char *sstr4 = LookupString( READ_STRING() ); sstr4 = safe_strcpy( szBuf[4], sstr4 , MSG_BUF_SIZE); StripEndNewlineFromString( sstr4 ); char *psz = szBuf[5]; if ( gViewPort && gViewPort->AllowedToPrintText() == FALSE ) return 1; switch ( msg_dest ) { case HUD_PRINTCENTER: safe_sprintf( psz, MSG_BUF_SIZE, msg_text, sstr1, sstr2, sstr3, sstr4 ); CenterPrint( ConvertCRtoNL( psz ) ); break; case HUD_PRINTNOTIFY: psz[0] = 1; // mark this message to go into the notify buffer safe_sprintf( psz+1, MSG_BUF_SIZE, msg_text, sstr1, sstr2, sstr3, sstr4 ); ConsolePrint( ConvertCRtoNL( psz ) ); break; case HUD_PRINTTALK: safe_sprintf( psz, MSG_BUF_SIZE, msg_text, sstr1, sstr2, sstr3, sstr4 ); gHUD.m_SayText.SayTextPrint( ConvertCRtoNL( psz ), 128 ); break; case HUD_PRINTCONSOLE: safe_sprintf( psz, MSG_BUF_SIZE, msg_text, sstr1, sstr2, sstr3, sstr4 ); ConsolePrint( ConvertCRtoNL( psz ) ); break; } return 1; }
TToken ASNLexer::LookupToken(void) { char c = Char(); switch ( c ) { case ':': if ( Char(1) == ':' && Char(2) == '=' ) { StartToken(); AddChars(3); return T_DEFINE; } return T_SYMBOL; case '-': case '+': if ( IsDigit(Char(1)) ) { StartToken(); AddChar(); return LookupNumber(); } return T_SYMBOL; case '\"': StartToken(); AddChar(); StartString(); LookupString(); return T_STRING; case '\'': StartToken(); AddChar(); return LookupBinHexString(); case '[': StartToken(); AddChar(); LookupTag(); return T_TAG; default: if ( IsDigit(c) ) { StartToken(); AddChar(); return LookupNumber(); } else if ( c >= 'a' && c <= 'z' ) { StartToken(); AddChar(); LookupIdentifier(); return T_IDENTIFIER; } else if ( c >= 'A' && c <= 'Z' ) { StartToken(); AddChar(); LookupIdentifier(); return LookupKeyword(); } return T_SYMBOL; } }
// Add a string void AddString(string_table* table, char* str) { // replace escape characters with corresponding ASCII values // BACKSLASH ('\\') -> \ // NL ('\n') -> 10 int i, j; int len = strlen(str); for (i = 0; i < len - 1; i++) { if (str[i] == '\\' && str[i + 1] == 'n') { str[i] = 10; for (j = i + 1; j < len; j++) str[j] = str[j + 1]; } else if (str[i] == '\\' && str[i + 1] == '\\') { str[i] = '\\'; for (j = i + 1; j < len; j++) str[j] = str[j + 1]; } } // lookup string to see if it exsists if (LookupString(table, str) != -1) return; // add to table if (table->size >= table->cap) { // Expand array table->cap *= 2; char** tmp = (char**) malloc(sizeof(char*) * table->cap); for (i = 0; i < table->size; i++) tmp[i] = table->strings[i]; free(table->strings); table->strings = tmp; } table->strings[table->size++] = strdup(str); }
MarshalStringTable::MarshalStringTable() { for( uint8 i = 1; i <= s_mStringTableSize; i++ ) mStringTableMap.insert( std::make_pair( hash( LookupString( i ) ), i ) ); }
static bool stringToField(const char *str, enum action_field *field_rtrn) { return LookupString(fieldStrings, str, field_rtrn); }
static bool stringToAction(const char *str, unsigned *type_rtrn) { return LookupString(actionTypeNames, str, type_rtrn); }
static bool stringToAction(const char *str, enum xkb_action_type *type_rtrn) { return LookupString(actionTypeNames, str, type_rtrn); }