Qt::MatchFlags SearchOptions::getMatchFlags() const { // *** match flags *** // MatchExactly = 0, Performs QVariant-based matching. // MatchContains = 1, // MatchStartsWith = 2, // MatchEndsWith = 3, // MatchRegExp = 4, // MatchWildcard = 5, // MatchFixedString = 8, Performs string-based matching. // MatchCaseSensitive = 16, // MatchWrap = 32, // MatchRecursive = 64 Searches the entire hierarchy, but I do not have heirarchical data. Qt::MatchFlags flags = Qt::MatchExactly; if (isMatchEntireString()) flags |= Qt::MatchFixedString; if (isContains()) flags |= Qt::MatchContains; if (isStartsWith()) flags |= Qt::MatchStartsWith; if (isEndsWith()) flags |= Qt::MatchEndsWith; //if (isMatchAsString()) flags |= Qt::MatchFixedString; if (isRegularExpression()) flags |= Qt::MatchRegExp; if (isWildCard()) flags |= Qt::MatchWildcard; if (isCaseSensitive()) flags |= Qt::MatchCaseSensitive; if (isWrap()) flags |= Qt::MatchWrap; return flags; }
QRegularExpression SearchOptions::getRegularExpression() const { QRegularExpression regexp = isWildCard() ? StringUtil::wildCardToRegExp(getFindValue()) : QRegularExpression(getFindValue()); if (!isCaseSensitive()) { regexp.setPatternOptions(QRegularExpression::CaseInsensitiveOption); } return regexp; }
//----------------------------------------------------------------------------- QStringList ctk::nameFilterToExtensions(const QString& nameFilter) { QRegExp regexp(QString::fromLatin1(ctkNameFilterRegExp)); int i = regexp.indexIn(nameFilter); if (i < 0) { QRegExp isWildCard(QString::fromLatin1(ctkValidWildCard)); if (isWildCard.indexIn(nameFilter) >= 0) { return QStringList(nameFilter); } return QStringList(); } QString f = regexp.cap(2); return f.split(QLatin1Char(' '), QString::SkipEmptyParts); }
INT32 _optQgmSortFilterSty::calcResult( qgmOprUnit * oprUnit, qgmOptiTreeNode * curNode, qgmOptiTreeNode * subNode, OPT_QGM_SS_RESULT & result ) { qgmOptiSelect *filter = (qgmOptiSelect*)subNode ; if ( filter->hasConstraint() ) { qgmOPFieldVec outSort ; INT32 getSortRC = filter->outputSort( outSort ) ; qgmOPFieldVec *fields = oprUnit->getFields() ; UINT32 count = fields->size() ; if ( isWildCard( outSort ) ) { result = OPT_SS_PROCESSED ; } else if ( SDB_OK != getSortRC || count > outSort.size() ) { result = OPT_SS_REFUSE ; } else { UINT32 index = 0 ; BOOLEAN allSame = TRUE ; while ( index < count ) { if ( (*fields)[index].value.attr() != outSort[index].value.attr() || (*fields)[index].type != outSort[index].type ) { allSame = FALSE ; break ; } ++index ; } result = allSame ? OPT_SS_PROCESSED : OPT_SS_REFUSE ; } } else { result = OPT_SS_TAKEOVER ; } return SDB_OK ; }
QString SearchOptions::serializeSettings() const { QStringList list; if (isMatchEntireString()) list << "MatchEntireString"; if (isContains()) list << "Contains"; if (isStartsWith()) list << "StartsWith"; if (isEndsWith()) list << "EndsWith"; if (isMatchAsString()) list << "AsString"; if (isRegularExpression()) list << "RegExp"; if (isWildCard()) list << "Wildcard"; list << (isCaseSensitive() ? "CaseSensitive" : "CaseInSensitive"); list << (isWrap() ? "Wrap" : "NoWrap"); list << (isBackwards() ? "Backward" : "Forward"); list << (isAllColumns() ? "AllColumns" : "OneColumn"); if (isReplace()) list << "Replace"; if (isReplaceAll()) list << "ReplaceAll"; return list.join(","); }
INT32 _optQgmSortAggrSty::calcResult( qgmOprUnit * oprUnit, qgmOptiTreeNode * curNode, qgmOptiTreeNode * subNode, OPT_QGM_SS_RESULT & result ) { INT32 rc = SDB_OK ; qgmOPFieldVec outSorts ; INT32 getSortRC = subNode->outputSort( outSorts ) ; qgmOPFieldVec *sortFields = oprUnit->getFields() ; UINT32 count = sortFields->size() ; if ( isWildCard( outSorts ) ) { result = OPT_SS_PROCESSED ; goto done ; } else if ( SDB_OK != getSortRC || count > outSorts.size() ) { result = OPT_SS_REFUSE ; goto done ; } else { UINT32 index = 0 ; INT32 findPos = -1 ; BOOLEAN otherAllSame = TRUE ; BOOLEAN nameAllSame = TRUE ; while ( index < count ) { findPos = findSameSortField( (*sortFields)[index], outSorts ) ; if ( -1 == findPos ) { nameAllSame = FALSE ; otherAllSame = FALSE ; break ; } if ( otherAllSame && (UINT32)findPos != index ) { otherAllSame = FALSE ; } else if ( otherAllSame && (*sortFields)[index].type != outSorts[findPos].type ) { otherAllSame = FALSE ; } ++index ; } if ( !nameAllSame ) { result = OPT_SS_REFUSE ; goto done ; } else if ( otherAllSame ) { result = OPT_SS_PROCESSED ; goto done ; } result = OPT_SS_ACCEPT ; } done: return rc ; }
/* * Take a command string and break it up into an argc, argv list while * handling quoting and wildcards. The returned argument list and * strings are in static memory, and so are overwritten on each call. * The argument list is ended with a NULL pointer for convenience. * Returns TRUE if successful, or FALSE on an error with a message * already output. */ BOOL makeArgs(const char * cmd, int * retArgc, const char *** retArgv) { const char * argument; char * cp; char * cpOut; char * newStrings; const char ** fileTable; const char ** newArgTable; int newArgTableSize; int fileCount; int len; int ch; int quote; BOOL quotedWildCards; BOOL unquotedWildCards; BOOL dollarMode; static int stringsLength; static char * strings; static int argCount; static int argTableSize; static const char ** argTable; /* * Clear the returned values until we know them. */ argCount = 0; *retArgc = 0; *retArgv = NULL; /* * Copy the command string into a buffer that we can modify, * reallocating it if necessary. */ len = strlen(cmd) + 1; if (len > stringsLength) { newStrings = realloc(strings, len); if (newStrings == NULL) { fprintf(stderr, "Cannot allocate string\n"); return FALSE; } strings = newStrings; stringsLength = len; } memcpy(strings, cmd, len); cp = strings; /* * Keep parsing the command string as long as there are any * arguments left. */ while (*cp) { /* * Save the beginning of this argument. */ argument = cp; cpOut = cp; /* * Reset quoting and wildcarding for this argument. */ quote = '\0'; quotedWildCards = FALSE; unquotedWildCards = FALSE; dollarMode = FALSE; /* * Loop over the string collecting the next argument while * looking for quoted strings or quoted characters, and * remembering whether there are any wildcard characters * in the argument. */ while (*cp) { ch = *cp++; /* * If we are not in a quote and we see a blank then * this argument is done. */ if (isBlank(ch) && (quote == '\0')) break; /* * If we see a backslash then accept the next * character no matter what it is. */ if (ch == '\\') { ch = *cp++; /* * Make sure there is a next character. */ if (ch == '\0') { fprintf(stderr, "Bad quoted character\n"); return FALSE; } /* * Remember whether the quoted character * is a wildcard. */ if (isWildCard(ch)) quotedWildCards = TRUE; *cpOut++ = ch; continue; } /* * If we see one of the wildcard characters then * remember whether it was seen inside or outside * of quotes. */ if (isWildCard(ch) && !dollarMode) { if (quote) quotedWildCards = TRUE; else unquotedWildCards = TRUE; } /* * If we were in a quote and we saw the same quote * character again then the quote is done. */ if (ch == quote) { quote = '\0'; continue; } /* * If we weren't in a quote and we see either type * of quote character, then remember that we are * now inside of a quote. */ if ((quote == '\0') && ((ch == '\'') || (ch == '"'))) { quote = ch; continue; } /* * TP1 * If we see a $ */ if(ch == '$' && !quote) { dollarMode = TRUE; } /* * Store the character. */ *cpOut++ = ch; } /* * Make sure that quoting is terminated properly. */ if (quote) { fprintf(stderr, "Unmatched quote character\n"); return FALSE; } /* * Null terminate the argument if it had shrunk, and then * skip over all blanks to the next argument, nulling them * out too. */ if (cp != cpOut) *cpOut = '\0'; while (isBlank(*cp)) *cp++ = '\0'; if(dollarMode) { if(*(argument+1)=='$'){ char* buff = (char*)malloc(5*sizeof(char)); sprintf(buff,"%d",getpid()); argument=buff; }else if(*(argument+1)=='['){ char* buff = (char*)malloc((strlen(argument)-3)*sizeof(char)); strncpy(buff,argument+2,strlen(argument)-3); printf("test %s\n",infixToPrefix(buff)); }else{ argument=getenv(argument+1); } } /* * If both quoted and unquoted wildcards were used then * complain since we don't handle them properly. */ if (quotedWildCards && unquotedWildCards) { fprintf(stderr, "Cannot use quoted and unquoted wildcards\n"); return FALSE; } /* * Expand the argument into the matching filenames or accept * it as is depending on whether there were any unquoted * wildcard characters in it. */ if (unquotedWildCards) { /* * Expand the argument into the matching filenames. */ fileCount = expandWildCards(argument, &fileTable); /* * Return an error if the wildcards failed to match. */ if (fileCount < 0) return FALSE; if (fileCount == 0) { fprintf(stderr, "Wildcard expansion error\n"); return FALSE; } } else { /* * Set up to only store the argument itself. */ fileTable = &argument; fileCount = 1; } /* * Now reallocate the argument table to hold the file name. */ if (argCount + fileCount >= argTableSize) { newArgTableSize = argCount + fileCount + 1; newArgTable = (const char **) realloc(argTable, (sizeof(const char *) * newArgTableSize)); if (newArgTable == NULL) { fprintf(stderr, "No memory for arg list\n"); return FALSE; } argTable = newArgTable; argTableSize = newArgTableSize; } /* * Copy the new arguments to the end of the old ones. */ memcpy((void *) &argTable[argCount], (const void *) fileTable, (sizeof(const char **) * fileCount)); /* * Add to the argument count. */ argCount += fileCount; } /* * Null terminate the argument list and return it. */ argTable[argCount] = NULL; *retArgc = argCount; *retArgv = argTable; return TRUE; }
/* * Take a command string and break it up into an argc, argv list while * handling quoting and wildcards. The returned argument list and * strings are in static memory, and so are overwritten on each call. * The argument list is ended with a NULL pointer for convenience. * Returns TRUE if successful, or FALSE on an error with a message * already output. */ BOOL makeArgs(const char * cmd, int * retArgc, const char *** retArgv) { const char * argument; char * cp; char * cpOut; char * newStrings; const char ** fileTable; const char ** newArgTable; int newArgTableSize; int fileCount; int len; int ch; int quote; BOOL quotedWildCards; BOOL unquotedWildCards; static int stringsLength; static char * strings; static int argCount; static int argTableSize; static const char ** argTable; /* * Clear the returned values until we know them. */ argCount = 0; *retArgc = 0; *retArgv = NULL; /* * Copy the command string into a buffer that we can modify, * reallocating it if necessary. */ len = strlen(cmd) + 1; if (len > stringsLength) { newStrings = realloc(strings, len); if (newStrings == NULL) { fprintf(stderr, "Cannot allocate string\n"); return FALSE; } strings = newStrings; stringsLength = len; } memcpy(strings, cmd, len); cp = strings; /* * Keep parsing the command string as long as there are any * arguments left. */ while (*cp) { /* * Save the beginning of this argument. */ argument = cp; cpOut = cp; /* * Reset quoting and wildcarding for this argument. */ quote = '\0'; quotedWildCards = FALSE; unquotedWildCards = FALSE; /* * Loop over the string collecting the next argument while * looking for quoted strings or quoted characters, and * remembering whether there are any wildcard characters * in the argument. */ while (*cp) { ch = *cp++; /* * If we are not in a quote and we see a blank then * this argument is done. */ if (isBlank(ch) && (quote == '\0')) break; /* * If we see a backslash then accept the next * character no matter what it is. */ if (ch == '\\') { ch = *cp++; /* * Make sure there is a next character. */ if (ch == '\0') { fprintf(stderr, "Bad quoted character\n"); return FALSE; } /* * Remember whether the quoted character * is a wildcard. */ if (isWildCard(ch)) quotedWildCards = TRUE; *cpOut++ = ch; continue; } /* * If we see one of the wildcard characters then * remember whether it was seen inside or outside * of quotes. */ if (isWildCard(ch)) { if (quote) quotedWildCards = TRUE; else unquotedWildCards = TRUE; } /* * If we were in a quote and we saw the same quote * character again then the quote is done. */ if (ch == quote) { quote = '\0'; continue; } /* * If we weren't in a quote and we see either type * of quote character, then remember that we are * now inside of a quote. */ if ((quote == '\0') && ((ch == '\'') || (ch == '"'))) { quote = ch; continue; } /* * Store the character. */ *cpOut++ = ch; } /* * Make sure that quoting is terminated properly. */ if (quote) { fprintf(stderr, "Unmatched quote character\n"); return FALSE; } /* * Null terminate the argument if it had shrunk, and then * skip over all blanks to the next argument, nulling them * out too. */ if (cp != cpOut) *cpOut = '\0'; while (isBlank(*cp)) *cp++ = '\0'; /* * If both quoted and unquoted wildcards were used then * complain since we don't handle them properly. */ if (quotedWildCards && unquotedWildCards) { fprintf(stderr, "Cannot use quoted and unquoted wildcards\n"); return FALSE; } /* * Expand the argument into the matching filenames or accept * it as is depending on whether there were any unquoted * wildcard characters in it. */ if (unquotedWildCards) { /* * Expand the argument into the matching filenames. */ fileCount = expandWildCards(argument, &fileTable); /* * Return an error if the wildcards failed to match. */ if (fileCount < 0) return FALSE; if (fileCount == 0) { fprintf(stderr, "Wildcard expansion error\n"); return FALSE; } } else { /* * Set up to only store the argument itself. */ fileTable = &argument; fileCount = 1; } /* * Now reallocate the argument table to hold the file name. */ if (argCount + fileCount >= argTableSize) { newArgTableSize = argCount + fileCount + 1; newArgTable = (const char **) realloc(argTable, (sizeof(const char *) * newArgTableSize)); if (newArgTable == NULL) { fprintf(stderr, "No memory for arg list\n"); return FALSE; } argTable = newArgTable; argTableSize = newArgTableSize; } /* * Copy the new arguments to the end of the old ones. */ memcpy((void *) &argTable[argCount], (const void *) fileTable, (sizeof(const char **) * fileCount)); /* * Add to the argument count. */ argCount += fileCount; } /* * Null terminate the argument list and return it. */ argTable[argCount] = NULL; /*arithmetic part code*/ int i; int j; int flag = 1; int res; char *env; static char *result = NULL; if (result == NULL) { result = malloc(sizeof (char) * 256); if (result == NULL) { fprintf(stderr, "Memory error\n"); return FALSE; } } for ( i = 0; i < argCount; i++) { if (argTable[i][0] == '$') { if (argTable[i][1] == '(') { memcpy(result, argTable[i], strlen(argTable[i])); for (j = 2; argTable[i][j] != '\0'; j++) { if (isdigit(result[j])) flag = 0; else if (result[j] == '+' || result[j] == '-' || result[j] == 'x' || result[j] == '/') { if (flag == 1) { fprintf(stderr, "Wrong arithmetic expression\n"); return FALSE; } flag = 1; } else if (result[j] == ')') { result[j] = '\0'; if (result[j + 1] != '\0') { fprintf(stderr, "Wrong arithmetic expression\n"); return FALSE; } } else { fprintf(stderr, "Wrong arithmetic expression\n"); return FALSE; } } res = eval_expr(&result[2]); sprintf(result, "%d", res); argTable[i] = result; } else { env = getenv(&argTable[i][1]); if (env != NULL) argTable[i] = env; else argTable[i] = "\0"; } } } *retArgc = argCount; *retArgv = argTable; return TRUE; }