#include "copyright.h"#include "autoconf.h"#include "config.h"#include "externs.h"#include "ansi.h"#include "pcre.h"Include dependency graph for stringutil.cpp:

Go to the source code of this file.
Data Structures | |
| struct | LITERAL_STRING_STRUCT |
Defines | |
| #define | ANSI_COLOR_INDEX_BLACK 0 |
| #define | ANSI_COLOR_INDEX_RED 1 |
| #define | ANSI_COLOR_INDEX_GREEN 2 |
| #define | ANSI_COLOR_INDEX_YELLOW 3 |
| #define | ANSI_COLOR_INDEX_BLUE 4 |
| #define | ANSI_COLOR_INDEX_MAGENTA 5 |
| #define | ANSI_COLOR_INDEX_CYAN 6 |
| #define | ANSI_COLOR_INDEX_WHITE 7 |
| #define | ANSI_COLOR_INDEX_DEFAULT 8 |
| #define | ANSI_MAXIMUM_BINARY_TRANSITION_LENGTH 60 |
| #define | ANSI_MAXIMUM_ESCAPE_TRANSITION_LENGTH 42 |
| #define | ATOF_LIMIT 100 |
| #define | VSNPRINTF vsnprintf |
| #define | BMH_LARGE 32767 |
Functions | |
| int | ANSI_lex (int nString, const char *pString, int *nLengthToken0, int *nLengthToken1) |
| char * | strip_ansi (const char *szString, size_t *pnString) |
| char * | strip_accents (const char *szString, size_t *pnString) |
| static void | ANSI_Parse_m (ANSI_ColorState *pacsCurrent, int nANSI, const char *pANSI, bool *pbSawNormal) |
| static char * | ANSI_TransitionColorBinary (ANSI_ColorState *acsCurrent, const ANSI_ColorState *pcsNext, int *nTransition, int iEndGoal) |
| static char * | ANSI_TransitionColorEscape (ANSI_ColorState *acsCurrent, ANSI_ColorState *acsNext, int *nTransition) |
| void | ANSI_String_In_Init (struct ANSI_In_Context *pacIn, const char *szString, int iEndGoal) |
| void | ANSI_String_Out_Init (struct ANSI_Out_Context *pacOut, char *pField, int nField, int vwMax, int iEndGoal) |
| void | ANSI_String_Skip (struct ANSI_In_Context *pacIn, int maxVisualWidth, int *pnVisualWidth) |
| void | ANSI_String_Copy (struct ANSI_Out_Context *pacOut, struct ANSI_In_Context *pacIn, int maxVisualWidth0) |
| int | ANSI_String_Finalize (struct ANSI_Out_Context *pacOut, int *pnVisualWidth) |
| int | ANSI_TruncateToField (const char *szString, int nField, char *pField0, int maxVisualWidth, int *pnVisualWidth, int iEndGoal) |
| char * | ANSI_TruncateAndPad_sbuf (const char *pString, int nMaxVisualWidth, char fill) |
| char * | normal_to_white (const char *szString) |
| char * | translate_string (const char *szString, bool bConvert) |
| char * | munge_space (const char *string) |
| char * | trim_spaces (char *string) |
| char * | grabto (char **str, char targ) |
| int | string_compare (const char *s1, const char *s2) |
| int | string_prefix (const char *string, const char *prefix) |
| const char * | string_match (const char *src, const char *sub) |
| char * | replace_string (const char *old, const char *new0, const char *s) |
| char * | replace_tokens (const char *s, const char *pBound, const char *pListPlace, const char *pSwitch) |
| bool | minmatch (char *str, char *target, int min) |
| char * | StringCloneLen (const char *str, size_t nStr) |
| char * | StringClone (const char *str) |
| void | safe_copy_str (const char *src, char *buff, char **bufp, int nSizeOfBuffer) |
| void | safe_copy_str_lbuf (const char *src, char *buff, char **bufp) |
| size_t | safe_copy_buf (const char *src, size_t nLen, char *buff, char **bufc) |
| size_t | safe_fill (char *buff, char **bufc, char chFill, size_t nSpaces) |
| bool | matches_exit_from_list (char *str, const char *pattern) |
| size_t | mux_ltoa (long val, char *buf) |
| char * | mux_ltoa_t (long val) |
| void | safe_ltoa (long val, char *buff, char **bufc) |
| size_t | mux_i64toa (INT64 val, char *buf) |
| void | safe_i64toa (INT64 val, char *buff, char **bufc) |
| long | mux_atol (const char *pString) |
| INT64 | mux_atoi64 (const char *pString) |
| bool | ParseFloat (PARSE_FLOAT_RESULT *pfr, const char *str, bool bStrict) |
| double | mux_atof (char *szString, bool bStrict) |
| char * | mux_ftoa (double r, bool bRounded, int frac) |
| bool | is_integer (char *str, int *pDigits) |
| bool | is_rational (char *str) |
| bool | is_real (char *str) |
| void | mux_strtok_src (MUX_STRTOK_STATE *tts, char *arg_pString) |
| void | mux_strtok_ctl (MUX_STRTOK_STATE *tts, char *pControl) |
| char * | mux_strtok_parseLEN (MUX_STRTOK_STATE *tts, int *pnLen) |
| char * | mux_strtok_parse (MUX_STRTOK_STATE *tts) |
| char * | RemoveSetOfCharacters (char *pString, char *pSetToRemove) |
| void | ItemToList_Init (ITL *p, char *arg_buff, char **arg_bufc, char arg_chPrefix, char arg_chSep) |
| bool | ItemToList_AddInteger (ITL *pContext, int i) |
| bool | ItemToList_AddStringLEN (ITL *pContext, size_t nStr, char *pStr) |
| bool | ItemToList_AddString (ITL *pContext, char *pStr) |
| void | ItemToList_Final (ITL *pContext) |
| int | mux_stricmp (const char *a, const char *b) |
| int | mux_memicmp (const void *p1_arg, const void *p2_arg, size_t n) |
| void | mux_strlwr (char *a) |
| void | mux_strupr (char *a) |
| int DCL_CDECL | mux_vsnprintf (char *buff, int count, const char *fmt, va_list va) |
| int | GetLineTrunc (char *Buffer, size_t nBuffer, FILE *fp) |
| void | BMH_Prepare (BMH_State *bmhs, int nPat, const char *pPat) |
| int | BMH_Execute (BMH_State *bmhs, int nPat, const char *pPat, int nSrc, const char *pSrc) |
| int | BMH_StringSearch (int nPat, const char *pPat, int nSrc, const char *pSrc) |
| void | BMH_PrepareI (BMH_State *bmhs, int nPat, const char *pPat) |
| int | BMH_ExecuteI (BMH_State *bmhs, int nPat, const char *pPat, int nSrc, const char *pSrc) |
| int | BMH_StringSearchI (int nPat, const char *pPat, int nSrc, const char *pSrc) |
| CF_HAND (cf_art_rule) | |
Variables | |
| const bool | mux_isprint [256] |
| const bool | mux_isdigit [256] |
| const bool | mux_ishex [256] |
| const bool | mux_isazAZ [256] |
| const bool | mux_isalpha [256] |
| const bool | mux_isalnum [256] |
| const bool | mux_isupper [256] |
| const bool | mux_islower [256] |
| const bool | mux_isspace [256] |
| bool | mux_AttrNameInitialSet [256] |
| bool | mux_AttrNameSet [256] |
| const bool | mux_ObjectNameSet [256] |
| bool | mux_PlayerNameSet [256] |
| const bool | mux_issecure [256] |
| const bool | mux_isescape [256] |
| const bool | ANSI_TokenTerminatorTable [256] |
| const unsigned char | mux_hex2dec [256] |
| const unsigned char | mux_toupper [256] |
| const unsigned char | mux_tolower [256] |
| const unsigned char | mux_StripAccents [256] |
| static const ANSI_ColorState | acsRestingStates [3] |
| static LITERAL_STRING_STRUCT | MU_Substitutes [] |
| const unsigned char | MU_EscapeConvert [256] |
| const unsigned char | MU_EscapeNoConvert [256] |
| const char | Digits100 [201] |
| const char | TableATOI [16][10] |
| static const double | powerstab [10] |
| #define ANSI_COLOR_INDEX_BLACK 0 |
Definition at line 641 of file stringutil.cpp.
| #define ANSI_COLOR_INDEX_BLUE 4 |
Definition at line 645 of file stringutil.cpp.
| #define ANSI_COLOR_INDEX_CYAN 6 |
Definition at line 647 of file stringutil.cpp.
| #define ANSI_COLOR_INDEX_DEFAULT 8 |
Definition at line 649 of file stringutil.cpp.
Referenced by ANSI_TransitionColorBinary(), and ANSI_TransitionColorEscape().
| #define ANSI_COLOR_INDEX_GREEN 2 |
Definition at line 643 of file stringutil.cpp.
| #define ANSI_COLOR_INDEX_MAGENTA 5 |
Definition at line 646 of file stringutil.cpp.
| #define ANSI_COLOR_INDEX_RED 1 |
Definition at line 642 of file stringutil.cpp.
| #define ANSI_COLOR_INDEX_WHITE 7 |
Definition at line 648 of file stringutil.cpp.
| #define ANSI_COLOR_INDEX_YELLOW 3 |
Definition at line 644 of file stringutil.cpp.
| #define ANSI_MAXIMUM_BINARY_TRANSITION_LENGTH 60 |
| #define ANSI_MAXIMUM_ESCAPE_TRANSITION_LENGTH 42 |
| #define ATOF_LIMIT 100 |
| #define BMH_LARGE 32767 |
Definition at line 3276 of file stringutil.cpp.
Referenced by BMH_Execute(), BMH_ExecuteI(), BMH_Prepare(), and BMH_PrepareI().
| #define VSNPRINTF vsnprintf |
| int ANSI_lex | ( | int | nString, | |
| const char * | pString, | |||
| int * | nLengthToken0, | |||
| int * | nLengthToken1 | |||
| ) |
Definition at line 499 of file stringutil.cpp.
References ANSI_TokenTerminatorTable, ESC_CHAR, TOKEN_ANSI, and TOKEN_TEXT_ANSI.
Referenced by ANSI_String_Copy(), ANSI_String_Skip(), ANSI_TransformTextReverseWithFunction(), ANSI_TransformTextWithTable(), FUNCTION(), strip_ansi(), and translate_string().
00500 { 00501 *nLengthToken0 = 0; 00502 *nLengthToken1 = 0; 00503 00504 const char *p = pString; 00505 00506 for (;;) 00507 { 00508 // Look for an ESC_CHAR 00509 // 00510 p = strchr(p, ESC_CHAR); 00511 if (!p) 00512 { 00513 // This is the most common case by far. 00514 // 00515 *nLengthToken0 = nString; 00516 return TOKEN_TEXT_ANSI; 00517 } 00518 00519 // We have an ESC_CHAR. Let's look at the next character. 00520 // 00521 if (p[1] != '[') 00522 { 00523 // Could be a '\0' or another non-'[' character. 00524 // Move the pointer to position ourselves over it. 00525 // And continue looking for an ESC_CHAR. 00526 // 00527 p = p + 1; 00528 continue; 00529 } 00530 00531 // We found the beginning of an ANSI sequence. 00532 // Find the terminating character. 00533 // 00534 const char *q = p+2; 00535 while (ANSI_TokenTerminatorTable[(unsigned char)*q] == 0) 00536 { 00537 q++; 00538 } 00539 if (q[0] == '\0') 00540 { 00541 // There was no good terminator. Treat everything like text. 00542 // Also, we are at the end of the string, so just return. 00543 // 00544 *nLengthToken0 = q - pString; 00545 return TOKEN_TEXT_ANSI; 00546 } 00547 else 00548 { 00549 // We found an ANSI sequence. 00550 // 00551 if (p == pString) 00552 { 00553 // The ANSI sequence started it. 00554 // 00555 *nLengthToken0 = q - pString + 1; 00556 return TOKEN_ANSI; 00557 } 00558 else 00559 { 00560 // We have TEXT followed by an ANSI sequence. 00561 // 00562 *nLengthToken0 = p - pString; 00563 *nLengthToken1 = q - p + 1; 00564 return TOKEN_TEXT_ANSI; 00565 } 00566 } 00567 } 00568 }
| static void ANSI_Parse_m | ( | ANSI_ColorState * | pacsCurrent, | |
| int | nANSI, | |||
| const char * | pANSI, | |||
| bool * | pbSawNormal | |||
| ) | [static] |
Definition at line 658 of file stringutil.cpp.
References acsRestingStates, ANSI_ENDGOAL_NORMAL, ANSI_ColorState::bBlink, ANSI_ColorState::bHighlite, ANSI_ColorState::bInverse, ANSI_ColorState::bNormal, ANSI_ColorState::bUnder, ANSI_ColorState::iBackground, ANSI_ColorState::iForeground, and mux_isdigit.
Referenced by ANSI_String_Copy(), ANSI_String_Skip(), and translate_string().
00660 { 00661 // If the last character isn't an 'm', then it's an ANSI sequence we 00662 // don't support, yet. TODO: There should be a ANSI_Parse() function 00663 // that calls into this one -only- if there's an 'm', but since 'm' 00664 // is the only command this game understands at the moment, it's easier 00665 // to put the test here. 00666 // 00667 if (pANSI[nANSI-1] != 'm') 00668 { 00669 return; 00670 } 00671 00672 // Process entire string and update the current color state structure. 00673 // 00674 while (nANSI) 00675 { 00676 // Process the next attribute phrase (terminated by ';' or 'm' 00677 // typically). 00678 // 00679 const char *p = pANSI; 00680 while (mux_isdigit(*p)) 00681 { 00682 p++; 00683 } 00684 size_t nLen = p - pANSI + 1; 00685 if (p[0] == 'm' || p[0] == ';') 00686 { 00687 // We have an attribute. 00688 // 00689 if (nLen == 2) 00690 { 00691 int iCode = pANSI[0] - '0'; 00692 switch (iCode) 00693 { 00694 case 0: 00695 // Normal. 00696 // 00697 *pacsCurrent = acsRestingStates[ANSI_ENDGOAL_NORMAL]; 00698 *pbSawNormal = true; 00699 break; 00700 00701 case 1: 00702 // High Intensity. 00703 // 00704 pacsCurrent->bHighlite = true; 00705 pacsCurrent->bNormal = false; 00706 break; 00707 00708 case 2: 00709 // Low Intensity. 00710 // 00711 pacsCurrent->bHighlite = false; 00712 pacsCurrent->bNormal = false; 00713 break; 00714 00715 case 4: 00716 // Underline. 00717 // 00718 pacsCurrent->bUnder = true; 00719 pacsCurrent->bNormal = false; 00720 break; 00721 00722 case 5: 00723 // Blinking. 00724 // 00725 pacsCurrent->bBlink = true; 00726 pacsCurrent->bNormal = false; 00727 break; 00728 00729 case 7: 00730 // Reverse Video 00731 // 00732 pacsCurrent->bInverse = true; 00733 pacsCurrent->bNormal = false; 00734 break; 00735 } 00736 } 00737 else if (nLen == 3) 00738 { 00739 int iCode0 = pANSI[0] - '0'; 00740 int iCode1 = pANSI[1] - '0'; 00741 if (iCode0 == 3) 00742 { 00743 // Foreground Color 00744 // 00745 if (iCode1 <= 7) 00746 { 00747 pacsCurrent->iForeground = iCode1; 00748 pacsCurrent->bNormal = false; 00749 } 00750 } 00751 else if (iCode0 == 4) 00752 { 00753 // Background Color 00754 // 00755 if (iCode1 <= 7) 00756 { 00757 pacsCurrent->iBackground = iCode1; 00758 pacsCurrent->bNormal = false; 00759 } 00760 } 00761 } 00762 } 00763 pANSI += nLen; 00764 nANSI -= nLen; 00765 } 00766 }
| void ANSI_String_Copy | ( | struct ANSI_Out_Context * | pacOut, | |
| struct ANSI_In_Context * | pacIn, | |||
| int | maxVisualWidth0 | |||
| ) |
Definition at line 1055 of file stringutil.cpp.
References acsRestingStates, ANSI_ENDGOAL_NOBLEED, ANSI_lex(), ANSI_Parse_m(), ANSI_TransitionColorBinary(), ANSI_In_Context::m_acs, ANSI_Out_Context::m_acs, ANSI_Out_Context::m_bDone, ANSI_In_Context::m_bSawNormal, ANSI_Out_Context::m_iEndGoal, ANSI_In_Context::m_n, ANSI_Out_Context::m_n, ANSI_Out_Context::m_nMax, ANSI_Out_Context::m_p, ANSI_In_Context::m_p, ANSI_Out_Context::m_vw, ANSI_Out_Context::m_vwMax, and TOKEN_TEXT_ANSI.
Referenced by ANSI_TruncateToField(), centerjustcombo(), FUNCTION(), and mux_exec().
01060 { 01061 // Check whether we have previous struck the session limits (given 01062 // by ANSI_String_Out_Init() for field size or visual width. 01063 // 01064 if (pacOut->m_bDone) 01065 { 01066 return; 01067 } 01068 01069 // What is the working limit for visual width. 01070 // 01071 int vw = 0; 01072 int vwMax = pacOut->m_vwMax; 01073 if (maxVisualWidth0 < vwMax) 01074 { 01075 vwMax = maxVisualWidth0; 01076 } 01077 01078 // What is the working limit for field size. 01079 // 01080 int nMax = pacOut->m_nMax; 01081 01082 char *pField = pacOut->m_p; 01083 while (pacIn->m_n) 01084 { 01085 int nTokenLength0; 01086 int nTokenLength1; 01087 int iType = ANSI_lex(pacIn->m_n, pacIn->m_p, &nTokenLength0, 01088 &nTokenLength1); 01089 01090 if (iType == TOKEN_TEXT_ANSI) 01091 { 01092 // We have a TEXT+[ANSI] phrase. The text length is given 01093 // by nTokenLength0, and the ANSI characters that follow 01094 // (if present) are of length nTokenLength1. 01095 // 01096 // Process TEXT part first. 01097 // 01098 // TODO: If there is a maximum size for the transitions, 01099 // and we have gobs of space, don't bother calculating 01100 // sizes so carefully. It might be faster 01101 01102 // nFieldEffective is used to allocate and plan space for 01103 // the rest of the physical field (given by the current 01104 // nField length). 01105 // 01106 int nFieldEffective = nMax - 1; // Leave room for '\0'. 01107 01108 int nTransitionFinal = 0; 01109 if (pacOut->m_iEndGoal <= ANSI_ENDGOAL_NOBLEED) 01110 { 01111 // If we lay down -any- of the TEXT part, we need to make 01112 // sure we always leave enough room to get back to the 01113 // required final ANSI color state. 01114 // 01115 if (memcmp( &(pacIn->m_acs), 01116 &acsRestingStates[pacOut->m_iEndGoal], 01117 sizeof(ANSI_ColorState)) != 0) 01118 { 01119 // The color state of the TEXT isn't the final state, 01120 // so how much room will the transition back to the 01121 // final state take? 01122 // 01123 ANSI_TransitionColorBinary( &(pacIn->m_acs), 01124 &acsRestingStates[pacOut->m_iEndGoal], 01125 &nTransitionFinal, 01126 pacOut->m_iEndGoal); 01127 01128 nFieldEffective -= nTransitionFinal; 01129 } 01130 } 01131 01132 // If we lay down -any- of the TEXT part, it needs to be 01133 // the right color. 01134 // 01135 int nTransition = 0; 01136 char *pTransition = 01137 ANSI_TransitionColorBinary( &(pacOut->m_acs), 01138 &(pacIn->m_acs), 01139 &nTransition, 01140 pacOut->m_iEndGoal); 01141 nFieldEffective -= nTransition; 01142 01143 // If we find that there is no room for any of the TEXT, 01144 // then we're done. 01145 // 01146 // TODO: The visual width test can be done further up to save time. 01147 // 01148 if ( nFieldEffective <= nTokenLength0 01149 || vw + nTokenLength0 > vwMax) 01150 { 01151 // We have reached the limits of the field. 01152 // 01153 if (nFieldEffective > 0) 01154 { 01155 // There was enough physical room in the field, but 01156 // we would have exceeded the maximum visual width 01157 // if we used all the text. 01158 // 01159 if (nTransition) 01160 { 01161 // Encode the TEXT color. 01162 // 01163 memcpy(pField, pTransition, nTransition); 01164 pField += nTransition; 01165 } 01166 01167 // Place just enough of the TEXT in the field. 01168 // 01169 int nTextToAdd = vwMax - vw; 01170 if (nTextToAdd < nFieldEffective) 01171 { 01172 nFieldEffective = nTextToAdd; 01173 } 01174 memcpy(pField, pacIn->m_p, nFieldEffective); 01175 pField += nFieldEffective; 01176 pacIn->m_p += nFieldEffective; 01177 pacIn->m_n -= nFieldEffective; 01178 vw += nFieldEffective; 01179 pacOut->m_acs = pacIn->m_acs; 01180 01181 // Was this visual width limit related to the session or 01182 // the call? 01183 // 01184 if (vwMax != maxVisualWidth0) 01185 { 01186 pacOut->m_bDone = true; 01187 } 01188 } 01189 else 01190 { 01191 // Was size limit related to the session or the call? 01192 // 01193 pacOut->m_bDone = true; 01194 } 01195 pacOut->m_n += pField - pacOut->m_p; 01196 pacOut->m_nMax -= pField - pacOut->m_p; 01197 pacOut->m_p = pField; 01198 pacOut->m_vw += vw; 01199 return; 01200 } 01201 01202 if (nTransition) 01203 { 01204 memcpy(pField, pTransition, nTransition); 01205 pField += nTransition; 01206 nMax -= nTransition; 01207 } 01208 memcpy(pField, pacIn->m_p, nTokenLength0); 01209 pField += nTokenLength0; 01210 nMax -= nTokenLength0; 01211 pacIn->m_p += nTokenLength0; 01212 pacIn->m_n -= nTokenLength0; 01213 vw += nTokenLength0; 01214 pacOut->m_acs = pacIn->m_acs; 01215 01216 if (nTokenLength1) 01217 { 01218 // Process ANSI 01219 // 01220 ANSI_Parse_m(&(pacIn->m_acs), nTokenLength1, pacIn->m_p, &(pacIn->m_bSawNormal)); 01221 pacIn->m_p += nTokenLength1; 01222 pacIn->m_n -= nTokenLength1; 01223 } 01224 } 01225 else 01226 { 01227 // Process ANSI 01228 // 01229 ANSI_Parse_m(&(pacIn->m_acs), nTokenLength0, pacIn->m_p, &(pacIn->m_bSawNormal)); 01230 pacIn->m_n -= nTokenLength0; 01231 pacIn->m_p += nTokenLength0; 01232 } 01233 } 01234 pacOut->m_n += pField - pacOut->m_p; 01235 pacOut->m_nMax -= pField - pacOut->m_p; 01236 pacOut->m_p = pField; 01237 pacOut->m_vw += vw; 01238 }
| int ANSI_String_Finalize | ( | struct ANSI_Out_Context * | pacOut, | |
| int * | pnVisualWidth | |||
| ) |
Definition at line 1241 of file stringutil.cpp.
References acsRestingStates, ANSI_ENDGOAL_NOBLEED, ANSI_TransitionColorBinary(), ANSI_Out_Context::m_acs, ANSI_Out_Context::m_iEndGoal, ANSI_Out_Context::m_n, ANSI_Out_Context::m_p, and ANSI_Out_Context::m_vw.
Referenced by ANSI_TruncateToField(), centerjustcombo(), FUNCTION(), and mux_exec().
01245 { 01246 char *pField = pacOut->m_p; 01247 if (pacOut->m_iEndGoal <= ANSI_ENDGOAL_NOBLEED) 01248 { 01249 int nTransition = 0; 01250 char *pTransition = 01251 ANSI_TransitionColorBinary( &(pacOut->m_acs), 01252 &acsRestingStates[pacOut->m_iEndGoal], 01253 &nTransition, pacOut->m_iEndGoal); 01254 if (nTransition) 01255 { 01256 memcpy(pField, pTransition, nTransition); 01257 pField += nTransition; 01258 } 01259 } 01260 *pField = '\0'; 01261 pacOut->m_n += pField - pacOut->m_p; 01262 pacOut->m_p = pField; 01263 *pnVisualWidth = pacOut->m_vw; 01264 return pacOut->m_n; 01265 }
| void ANSI_String_In_Init | ( | struct ANSI_In_Context * | pacIn, | |
| const char * | szString, | |||
| int | iEndGoal | |||
| ) |
Definition at line 948 of file stringutil.cpp.
References acsRestingStates, ANSI_In_Context::m_acs, ANSI_In_Context::m_bSawNormal, ANSI_In_Context::m_n, and ANSI_In_Context::m_p.
Referenced by ANSI_TruncateToField(), centerjustcombo(), FUNCTION(), and mux_exec().
00953 { 00954 pacIn->m_acs = acsRestingStates[iEndGoal]; 00955 pacIn->m_p = szString; 00956 pacIn->m_n = strlen(szString); 00957 pacIn->m_bSawNormal = false; 00958 }
| void ANSI_String_Out_Init | ( | struct ANSI_Out_Context * | pacOut, | |
| char * | pField, | |||
| int | nField, | |||
| int | vwMax, | |||
| int | iEndGoal | |||
| ) |
Definition at line 961 of file stringutil.cpp.
References acsRestingStates, ANSI_ENDGOAL_NORMAL, ANSI_Out_Context::m_acs, ANSI_Out_Context::m_bDone, ANSI_Out_Context::m_iEndGoal, ANSI_Out_Context::m_n, ANSI_Out_Context::m_nMax, ANSI_Out_Context::m_p, ANSI_Out_Context::m_vw, and ANSI_Out_Context::m_vwMax.
Referenced by ANSI_TruncateToField(), centerjustcombo(), FUNCTION(), and mux_exec().
00968 { 00969 pacOut->m_acs = acsRestingStates[ANSI_ENDGOAL_NORMAL]; 00970 pacOut->m_bDone = false; 00971 pacOut->m_iEndGoal = iEndGoal; 00972 pacOut->m_n = 0; 00973 pacOut->m_nMax = nField; 00974 pacOut->m_p = pField; 00975 pacOut->m_vw = 0; 00976 pacOut->m_vwMax = vwMax; 00977 }
| void ANSI_String_Skip | ( | struct ANSI_In_Context * | pacIn, | |
| int | maxVisualWidth, | |||
| int * | pnVisualWidth | |||
| ) |
Definition at line 980 of file stringutil.cpp.
References ANSI_lex(), ANSI_Parse_m(), ANSI_In_Context::m_acs, ANSI_In_Context::m_bSawNormal, ANSI_In_Context::m_n, ANSI_In_Context::m_p, and TOKEN_TEXT_ANSI.
Referenced by centerjustcombo(), and FUNCTION().
00984 { 00985 *pnVisualWidth = 0; 00986 while (pacIn->m_n) 00987 { 00988 int nTokenLength0; 00989 int nTokenLength1; 00990 int iType = ANSI_lex(pacIn->m_n, pacIn->m_p, &nTokenLength0, &nTokenLength1); 00991 00992 if (iType == TOKEN_TEXT_ANSI) 00993 { 00994 // Process TEXT 00995 // 00996 int nTextToSkip = maxVisualWidth - *pnVisualWidth; 00997 if (nTokenLength0 > nTextToSkip) 00998 { 00999 // We have reached the limits of the field 01000 // 01001 *pnVisualWidth += nTextToSkip; 01002 pacIn->m_p += nTextToSkip; 01003 pacIn->m_n -= nTextToSkip; 01004 return; 01005 } 01006 01007 pacIn->m_p += nTokenLength0; 01008 pacIn->m_n -= nTokenLength0; 01009 *pnVisualWidth += nTokenLength0; 01010 01011 if (nTokenLength1) 01012 { 01013 // Process ANSI 01014 // 01015 ANSI_Parse_m(&(pacIn->m_acs), nTokenLength1, pacIn->m_p, &(pacIn->m_bSawNormal)); 01016 pacIn->m_p += nTokenLength1; 01017 pacIn->m_n -= nTokenLength1; 01018 } 01019 } 01020 else 01021 { 01022 // Process ANSI 01023 // 01024 ANSI_Parse_m(&(pacIn->m_acs), nTokenLength0, pacIn->m_p, &(pacIn->m_bSawNormal)); 01025 pacIn->m_n -= nTokenLength0; 01026 pacIn->m_p += nTokenLength0; 01027 } 01028 } 01029 }
| static char* ANSI_TransitionColorBinary | ( | ANSI_ColorState * | acsCurrent, | |
| const ANSI_ColorState * | pcsNext, | |||
| int * | nTransition, | |||
| int | iEndGoal | |||
| ) | [static] |
Definition at line 777 of file stringutil.cpp.
References acsRestingStates, ANSI_ATTR_CMD, ANSI_BACKGROUND, ANSI_BLINK, ANSI_COLOR_INDEX_DEFAULT, ANSI_ENDGOAL_NORMAL, ANSI_FOREGROUND, ANSI_HILITE, ANSI_INVERSE, ANSI_MAXIMUM_BINARY_TRANSITION_LENGTH, ANSI_NORMAL, ANSI_UNDER, ANSI_ColorState::bBlink, ANSI_ColorState::bHighlite, ANSI_ColorState::bInverse, ANSI_ColorState::bNormal, ANSI_ColorState::bUnder, ANSI_ColorState::iBackground, and ANSI_ColorState::iForeground.
Referenced by ANSI_String_Copy(), and ANSI_String_Finalize().
00783 { 00784 static char Buffer[ANSI_MAXIMUM_BINARY_TRANSITION_LENGTH+1]; 00785 00786 if (memcmp(acsCurrent, pcsNext, sizeof(ANSI_ColorState)) == 0) 00787 { 00788 *nTransition = 0; 00789 Buffer[0] = '\0'; 00790 return Buffer; 00791 } 00792 ANSI_ColorState tmp = *acsCurrent; 00793 char *p = Buffer; 00794 00795 if (pcsNext->bNormal) 00796 { 00797 // With NOBLEED, we can't stay in the normal mode. We must eventually 00798 // be on a white foreground. 00799 // 00800 pcsNext = &acsRestingStates[iEndGoal]; 00801 } 00802 00803 // Do we need to go through the normal state? 00804 // 00805 if ( tmp.bHighlite && !pcsNext->bHighlite 00806 || tmp.bUnder && !pcsNext->bUnder 00807 || tmp.bBlink && !pcsNext->bBlink 00808 || tmp.bInverse && !pcsNext->bInverse 00809 || ( tmp.iBackground != ANSI_COLOR_INDEX_DEFAULT 00810 && pcsNext->iBackground == ANSI_COLOR_INDEX_DEFAULT) 00811 || ( tmp.iForeground != ANSI_COLOR_INDEX_DEFAULT 00812 && pcsNext->iForeground == ANSI_COLOR_INDEX_DEFAULT)) 00813 { 00814 memcpy(p, ANSI_NORMAL, sizeof(ANSI_NORMAL)-1); 00815 p += sizeof(ANSI_NORMAL)-1; 00816 tmp = acsRestingStates[ANSI_ENDGOAL_NORMAL]; 00817 } 00818 if (tmp.bHighlite != pcsNext->bHighlite) 00819 { 00820 memcpy(p, ANSI_HILITE, sizeof(ANSI_HILITE)-1); 00821 p += sizeof(ANSI_HILITE)-1; 00822 } 00823 if (tmp.bUnder != pcsNext->bUnder) 00824 { 00825 memcpy(p, ANSI_UNDER, sizeof(ANSI_UNDER)-1); 00826 p += sizeof(ANSI_UNDER)-1; 00827 } 00828 if (tmp.bBlink != pcsNext->bBlink) 00829 { 00830 memcpy(p, ANSI_BLINK, sizeof(ANSI_BLINK)-1); 00831 p += sizeof(ANSI_BLINK)-1; 00832 } 00833 if (tmp.bInverse != pcsNext->bInverse) 00834 { 00835 memcpy(p, ANSI_INVERSE, sizeof(ANSI_INVERSE)-1); 00836 p += sizeof(ANSI_INVERSE)-1; 00837 } 00838 if (tmp.iForeground != pcsNext->iForeground) 00839 { 00840 memcpy(p, ANSI_FOREGROUND, sizeof(ANSI_FOREGROUND)-1); 00841 p += sizeof(ANSI_FOREGROUND)-1; 00842 *p++ = pcsNext->iForeground + '0'; 00843 *p++ = ANSI_ATTR_CMD; 00844 } 00845 if (tmp.iBackground != pcsNext->iBackground) 00846 { 00847 memcpy(p, ANSI_BACKGROUND, sizeof(ANSI_BACKGROUND)-1); 00848 p += sizeof(ANSI_BACKGROUND)-1; 00849 *p++ = pcsNext->iBackground + '0'; 00850 *p++ = ANSI_ATTR_CMD; 00851 } 00852 *p = '\0'; 00853 *nTransition = p - Buffer; 00854 return Buffer; 00855 }
| static char* ANSI_TransitionColorEscape | ( | ANSI_ColorState * | acsCurrent, | |
| ANSI_ColorState * | acsNext, | |||
| int * | nTransition | |||
| ) | [static] |
Definition at line 865 of file stringutil.cpp.
References acsRestingStates, ANSI_COLOR_INDEX_DEFAULT, ANSI_ENDGOAL_NORMAL, ANSI_MAXIMUM_ESCAPE_TRANSITION_LENGTH, ANSI_ColorState::bBlink, ANSI_ColorState::bHighlite, ANSI_ColorState::bInverse, ANSI_ColorState::bUnder, ANSI_ColorState::iBackground, and ANSI_ColorState::iForeground.
Referenced by translate_string().
00870 { 00871 static char Buffer[ANSI_MAXIMUM_ESCAPE_TRANSITION_LENGTH+1]; 00872 static const char cForegroundColors[9] = "xrgybmcw"; 00873 static const char cBackgroundColors[9] = "XRGYBMCW"; 00874 00875 if (memcmp(acsCurrent, acsNext, sizeof(ANSI_ColorState)) == 0) 00876 { 00877 *nTransition = 0; 00878 Buffer[0] = '\0'; 00879 return Buffer; 00880 } 00881 ANSI_ColorState tmp = *acsCurrent; 00882 int i = 0; 00883 00884 // Do we need to go through the normal state? 00885 // 00886 if ( tmp.bBlink && !acsNext->bBlink 00887 || tmp.bHighlite && !acsNext->bHighlite 00888 || tmp.bInverse && !acsNext->bInverse 00889 || ( tmp.iBackground != ANSI_COLOR_INDEX_DEFAULT 00890 && acsNext->iBackground == ANSI_COLOR_INDEX_DEFAULT) 00891 || ( tmp.iForeground != ANSI_COLOR_INDEX_DEFAULT 00892 && acsNext->iForeground == ANSI_COLOR_INDEX_DEFAULT)) 00893 { 00894 Buffer[i ] = '%'; 00895 Buffer[i+1] = 'x'; 00896 Buffer[i+2] = 'n'; 00897 i = i + 3; 00898 tmp = acsRestingStates[ANSI_ENDGOAL_NORMAL]; 00899 } 00900 if (tmp.bHighlite != acsNext->bHighlite) 00901 { 00902 Buffer[i ] = '%'; 00903 Buffer[i+1] = 'x'; 00904 Buffer[i+2] = 'h'; 00905 i = i + 3; 00906 } 00907 if (tmp.bUnder != acsNext->bUnder) 00908 { 00909 Buffer[i ] = '%'; 00910 Buffer[i+1] = 'x'; 00911 Buffer[i+2] = 'u'; 00912 i = i + 3; 00913 } 00914 if (tmp.bBlink != acsNext->bBlink) 00915 { 00916 Buffer[i ] = '%'; 00917 Buffer[i+1] = 'x'; 00918 Buffer[i+2] = 'f'; 00919 i = i + 3; 00920 } 00921 if (tmp.bInverse != acsNext->bInverse) 00922 { 00923 Buffer[i ] = '%'; 00924 Buffer[i+1] = 'x'; 00925 Buffer[i+2] = 'i'; 00926 i = i + 3; 00927 } 00928 if (tmp.iForeground != acsNext->iForeground) 00929 { 00930 Buffer[i ] = '%'; 00931 Buffer[i+1] = 'x'; 00932 Buffer[i+2] = cForegroundColors[acsNext->iForeground]; 00933 i = i + 3; 00934 } 00935 if (tmp.iBackground != acsNext->iBackground) 00936 { 00937 Buffer[i ] = '%'; 00938 Buffer[i+1] = 'x'; 00939 Buffer[i+2] = cBackgroundColors[acsNext->iBackground]; 00940 i = i + 3; 00941 } 00942 Buffer[i] = '\0'; 00943 *nTransition = i; 00944 return Buffer; 00945 }
| char* ANSI_TruncateAndPad_sbuf | ( | const char * | pString, | |
| int | nMaxVisualWidth, | |||
| char | fill | |||
| ) |