/** * Take a string representing a VARTYPE expression and turn it into a string * representing its numerical value. Only valid VARIANTARGs are allowed, that * is, only VARTYPEs that are valid to use in DISPPARAMS are converted. * * @param rxStr The string to convert. * * @return The numerical value of the VARIANTARG corresponding to rxStr, * or null if the string is not valid. */ static RexxObjectPtr stringToVT(RexxMethodContext *context, RexxObjectPtr rxStr ) { RexxObjectPtr rxResult = NULL; CHAR *pszRxStr; CHAR *pTmp; CHAR szBuffer[6]; // Largest value is 0xFFFF == 65535. VARENUM v1, v2; pszRxStr = pszStringDupe(context->ObjectToStringValue(rxStr)); if ( !pszRxStr ) { context->RaiseException0(Rexx_Error_System_resources); } // Allow case insensitive. pszRxStr = strupr(pszRxStr); // There must be either 1 or 2 VT_xx symbols, anything else is not valid. switch ( countSymbols(pszRxStr, FLAG_SEPARATOR_CHAR) ) { case 0 : v1 = findVT(stripNonCSyms(pszRxStr)); if ( v1 != VT_ILLEGAL && v1 != VT_VARIANT && v1 != VT_BYREF && v1 != VT_ARRAY ) { sprintf(szBuffer, "%d", v1); rxResult = context->WholeNumberToObject(v1); } break; case 1 : pTmp = strchr(pszRxStr, FLAG_SEPARATOR_CHAR); v2 = findVT(stripNonCSyms(pTmp)); *pTmp = 0x0; v1 = findVT(stripNonCSyms(pszRxStr)); if ( v1 != VT_ILLEGAL && v2 != VT_ILLEGAL && areValidVTs(v1, v2) ) { sprintf(szBuffer, "%d", v1 | v2); rxResult = context->WholeNumberToObject(v1 | v2); } break; default : break; } ORexxOleFree(pszRxStr); return rxResult; }
/** * Take a string representing the wParmFlags field in a PARAMDESC struct and * turn it into a string representing its numerical value. * * wParmFlags are true flags, as long as each token is a valid flag, any number * of tokens can be or'd together any number of times and the result is valid. * * @param The string to convert. * * @return The integer value (as a string) of the wParamFlags, or null if the * string to convert was not valid. */ static RexxObjectPtr stringToFlags(RexxMethodContext *context, RexxObjectPtr rxStr ) { RexxObjectPtr rxResult = NULL; // Return null if invalid. CHAR *pszRxStr; CHAR *ptr; int tmp, count, i; int val = 0; pszRxStr = pszStringDupe(context->ObjectToStringValue(rxStr)); if ( !pszRxStr ) { context->RaiseException0(Rexx_Error_System_resources); } // Allow case insensitive. pszRxStr = strupr(pszRxStr); count = countSymbols(pszRxStr, FLAG_SEPARATOR_CHAR); // Look at each token, and if valid use it. for ( i = 0; i < count; i++ ) { ptr = strrchr(pszRxStr, FLAG_SEPARATOR_CHAR); tmp = findFlag(stripNonCSyms(ptr)); if ( tmp == PARAMFLAG_ILLEGAL ) { val = tmp; break; } val |= tmp; *ptr = 0x0; } // If still valid, pick up the last token. if ( val != PARAMFLAG_ILLEGAL ) { tmp = findFlag(stripNonCSyms(pszRxStr)); if ( tmp != PARAMFLAG_ILLEGAL ) { rxResult = context->WholeNumberToObject(val | tmp); } } ORexxOleFree(pszRxStr); return rxResult; }
bool compare(char * memeWord, char * phraseWord) { bool found; int i; char meme[256]; char phrase[256]; int j; char symbol[256]; char prefixLetter; char suffixLetter; char * token; if (debug) printf("Comparing %s and %s\n", memeWord, phraseWord); // If the meme word is longer than the phrase word, then it can't match if (strlen(memeWord) > strlen(phraseWord)) return false; // If these words match, they will have some prefix and/or some // suffix that matches so find those first and get rid of them // Find the common prefix strcpy(symbol, " "); strcpy(meme, memeWord); strcpy(phrase, phraseWord); prefixLetter = ' '; suffixLetter = ' '; found = false; i = strlen(meme); while ( (found == false) && (i >= 0) ) { meme[i] = '\0'; if (strstr(phrase, meme) == phrase) found = true; else i--; } if (i < 0) i = 0; // Find the common suffix if (i >= 1) prefixLetter = memeWord[i-1]; strcpy(meme, &memeWord[i]); strcpy(phrase, &phraseWord[i]); found = false; j = strlen(meme); while ( (found == false) && (j >= 0) ) { if (strstr(&phrase[strlen(phrase)-j], &meme[strlen(meme)-j]) == &phrase[strlen(phrase)-j]) found = true; else j--; } // Get the leftover if (found == true) { phrase[strlen(phrase)-j] = '\0'; if (suffixLetter == ' ') suffixLetter = meme[strlen(meme)-j]; meme[strlen(meme)-j] = '\0'; } if (debug) printf(" last letter is *%c* *%c*\n", prefixLetter, suffixLetter); if (debug) printf(" Core is *%s* and *%s*\n", meme, phrase); // If the core is empty, then the words matched perfectly if ( (strlen(meme) == 0) && (strlen(phrase) == 0) ) return true; // Check the parts of the meme we can (single symbol) if (strlen(meme) > 0) { // Check if starts with symbol if (isSymbol(phrase[0]) == true) { // Store the symbol sprintf(symbol, "%c", phrase[0]); // Clear off the first character and check rest memmove(&meme[0], &meme[1], strlen(&meme[1])+1); memmove(&phrase[0], &phrase[1], strlen(&phrase[1])+1); // while ( (strlen(meme) > 0) && (strlen(phrase) > 0) && (meme[0] == phrase[0]) ) { memmove(&meme[0], &meme[1], strlen(&meme[1])+1); memmove(&phrase[0], &phrase[1], strlen(&phrase[1])+1); } } else if (isSymbol(phrase[strlen(phrase)-1]) == true) { // Store the symbol sprintf(symbol, "%c", phrase[strlen(phrase)-1]); // Clear off the last character and check rest meme[strlen(meme)-1] = '\0'; phrase[strlen(phrase)-1] = '\0'; while ( (strlen(meme) > 0) && (strlen(phrase) > 0) && (meme[strlen(meme)-1] == phrase[strlen(phrase)-1]) ) { meme[strlen(meme)-1] = '\0'; phrase[strlen(phrase)-1] = '\0'; } } } if (debug) printf(" Now core is *%s* and *%s*\n", meme, phrase); // See if we ate up everything if ( (strlen(meme) == 0) && (strlen(phrase) == 0) ) return true; // Process based on meme core length if (strlen(meme) == 1) { // Meme core has a single character so it either mismatched // to a symbol or to a letter if ( (isSymbol(phrase[0]) == true) && (symbol[0] == ' ') ) { // It is a symbol so remove the match sprintf(symbol, "%c", phrase[0]); meme[0] = '\0'; memmove(&phrase[0], &phrase[1], strlen(&phrase[1])+1); // If we used up the phrase, we're done and matched if (strlen(phrase) == 0) return true; } else { // Two letters must have mismatched so return false return false; } } if (strlen(meme) == 0) { // If we already processed one repeat, then we fail if (repeatSeen == true) return false; // Otherwise, we must have a repeat (otherwise, the phrase // wouldn't have left over characters) repeatSeen = true; // Used up the meme so we just have to verify the // left over phrase if ( (symbol[0] != ' ') && (strspn(phrase, symbol) == strlen(phrase)) ) { // All the characters are the same and the removed symbol return true; } else if ( (symbol[0] == ' ') && (isSymbol(phrase[0]) == true) && (strspn(phrase, &phrase[strlen(phrase)-1]) == strlen(phrase)) ) { // All the characters are the same and a new symbol if (strlen(phrase) == 1) return true; else return false; } else if (strspn(phrase, &phrase[strlen(phrase)-1]) == strlen(phrase)) { // All the characters are the same letter (and match the // last one in the prefix or first one in the suffix) if ( (phrase[0] == prefixLetter) || (phrase[0] == suffixLetter) ) return true; else return false; } else if (countSymbols(phrase) == 1) { // There are multiple characters and one symbol (the symbol // itself can't be repeated or we repeated two characters) i = 0; while (isSymbol(phrase[i]) == false) i++; memmove(&phrase[i], &phrase[i+1], strlen(&phrase[i+1])+1); if ( (strspn(phrase, &phrase[strlen(phrase)-1]) == strlen(phrase)) ) return true; else return false; } else { // Multiple characters that aren't the same so can't match return false; } } else { // If the meme still has two characters left, it must not // match return false; } }
Symbol* SymbolTable::getSymbol(uint32_t i){ EPAXAssert(i < countSymbols(), "Symbol table index out of range"); return symbols->at(i); }