/* **************************************************************************** * euint32 dir_findFileinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc) * This function searches for a given fatfilename in the buffer provided. * It will iterate through the 16 direntry's in the buffer and searches * for the fatfilename. If found, it will store the offset and attribute * entry of the directoryrecord in the loc structure. * If loc is 0, then it's members are not touched. * Return value: This function returns 0 when it cannot find the file, * if it can find the file it will return the first cluster number. */ euint32 dir_findFileinBuf(euint8 *buf, eint8 *fatname, FileLocation *loc) { FileRecord fileEntry; euint8 c; for(c=0; c<16; c++) { fileEntry = *(((FileRecord*)buf) + c); /* Check if the entry is for short filenames */ if( !( (fileEntry.Attribute & 0x0F) == 0x0F ) ) { if( strMatch((eint8*)fileEntry.FileName,fatname,11) == 0 ) { /* The entry has been found, return the location in the dir */ if(loc)loc->Offset = c; if(loc)loc->attrib = fileEntry.Attribute; if((((euint32 )fileEntry.FirstClusterHigh)<<16)+ fileEntry.FirstClusterLow==0) { return(1); /* Lie about cluster, 0 means not found! */ } else { return ( (((euint32 )fileEntry.FirstClusterHigh)<<16) + fileEntry.FirstClusterLow ); } } } } return(0); }
vm_handler VmpHandler::MatchHandler(Inst_UD_Chain* chain) { for (int i = 0; i < sizeof(_vmhc) / sizeof(vm_handler_chara); i++) { ulong cindex = 0; chara_unit pch = _vmhc[i].chara[cindex]; Inst_UD_Node* tmp = chain->GetHeader(); while (pch.ch[0] && tmp) { _strlwr(tmp->cmdInfo.cmd); ulong ccindex = 0; while (ccindex<3 && pch.ch[ccindex]) { if (strMatch(pch.ch[ccindex],tmp->cmdInfo.cmd)) { cindex++; pch = _vmhc[i].chara[cindex]; break; } ccindex++; } tmp = tmp->nextNode; } if (!pch.ch[0]) { return _vmhc[i].handler; } } return VM_Unknown; }
/*static*/ void ComponentInterface::ThrowException(int nExceptionFlags ,const char *pzExceptionMatch, const char *pzData, const char *pzExecSignature ) { if (!nExceptionFlags) return; // set defaults int bThrowOnNullOrEmpty = 0; int nComparisonType = 0; //0=NoCompare int bLookForXMLException = 0; // extract bit flag settings if ( ( nExceptionFlags & EX_EMPTYORNULL ) != 0) bThrowOnNullOrEmpty = 1; if ( ( nExceptionFlags & EX_RETURN_EQUAL ) != 0) nComparisonType = EX_RETURN_EQUAL; if ( ( nExceptionFlags & EX_RETURN_CONTAINS ) != 0) nComparisonType = EX_RETURN_CONTAINS; if ( ( nExceptionFlags & EX_RETURN_STARTSWITH ) != 0) nComparisonType = EX_RETURN_STARTSWITH; if ( ( nExceptionFlags & EX_XMLEXCEPTION ) != 0) bLookForXMLException = 1; if (bThrowOnNullOrEmpty) { if (!pzExceptionMatch || !pzExceptionMatch[0]) throw GException("CustomException", 1, pzExecSignature); } if (nComparisonType == EX_RETURN_EQUAL) { GString strEXMatch(pzExceptionMatch); if ( strEXMatch.CompareNoCase(pzData) == 0 ) throw GException("CustomException", 3, pzExecSignature, pzData); } if (nComparisonType == EX_RETURN_STARTSWITH) { GString strEXMatch( pzExceptionMatch ); if ( (int)strlen(pzData) >= strEXMatch.Length() ) { GString strMatch(pzData,strEXMatch.Length()); if ( strEXMatch.CompareNoCase((const char *)strMatch) == 0 ) throw GException("CustomException", 4, pzExecSignature, (const char *)strMatch); } } if (nComparisonType == EX_RETURN_CONTAINS) { if ( strstr(pzData,pzExceptionMatch) ) { throw GException("CustomException", 5, pzExecSignature, pzExceptionMatch); } } if ( bLookForXMLException ) { int bIsXMLException = 0; try { CXMLTree xmlGraftTree; xmlGraftTree.parseXML( (char *)pzData ); CXMLElementx *pRoot = xmlGraftTree.getRoot(); GString strRootTag(pRoot->getTag(), pRoot->getTagLen()); if (strRootTag.CompareNoCase("Exception") == 0) { int nError = 0; CXMLElementx *pE = pRoot->findChild("ErrorNumber"); if (pE) { GString strE(pE->getTag(), pE->getTagLen()); nError = atoi((const char *)strE); } int nSubSys = 0; CXMLElementx *pS = pRoot->findChild("SubSystem"); if (pS) { GString strS(pS->getTag(), pS->getTagLen()); nSubSys = atoi((const char *)strS); } GString strDescription("User Defined Exception with no Description"); CXMLElementx *pD = pRoot->findChild("Description"); if (pD) { GString strD(pD->getTag(), pD->getTagLen()); strDescription = (const char *)strD; } GStringList Stack; CXMLElementx *pC = pRoot->findChild("CallStack"); if (pC) { int i = 0; while (1) { CXMLElementx *pF = pC->findChild("Frame",++i); if (!pF) break; GString strF(pF->getTag(), pF->getTagLen()); Stack.AddLast(strF); } } Stack.AddLast(pzExecSignature); bIsXMLException = 1; throw GException(nError, nSubSys, (const char *)strDescription, &Stack); } } catch( GException &) { if (bIsXMLException) { // propigate the user exception throw; } else { // ignore this exception. // If we can't parse the pzData then we know this is not an XMLException. } } } }
int main (void) { char *args[MAXLINE/2 + 1]; /* command line with max 40 arguments */ int should_run = 1; /* flag to determine when to exit program */ //char exitStr[] = "exit"; printf("CS149 Shell from Sajay Shah\n"); /* replace w/ name */ while (should_run) { printf("Sajay-591>"); /* prompt- replace FirstName and L3SID */ fflush(stdout); /* After reading user input, the steps are: * (1) fork a child process using fork() * (2) the child process will invoke execvp() * (3) if command included &, parent will NOT invoke wait() */ char str[MAXLINE]; // read user input fgets(str, MAXLINE, stdin); // ampersand detection const char *invalid_characters = "&"; int ampersandFlag = 0; char *c = str; while (*c) { if (strchr(invalid_characters, *c)) { ampersandFlag = 1; } c++; } // the following removes the trailing newline char from fgets str[strcspn(str, "\n")] = 0; // begin tokenizing input, fill args array char *token; /* get the first token */ token = strtok(str, " "); args[0] = token; int i = 1; while(token) { //printf("%s\n", token ); token = strtok(NULL, " "); args[i] = token; i++; } // check if user enterted "exit" if (strMatch(args[0], "exit")) { should_run = 0; break; } // remove the ampersand from args array if(ampersandFlag) { args[i-2] = NULL; } int pid, status; if((pid = fork()) < 0 ) { printf("Fork error\n"); exit(1); } if(pid == 0) { execvp(args[0], args); printf("Not a valid command \n"); //printf("Sajay-591>"); exit(1); } // if there's no '&' then we wait. If there is '&' then we don't wait if (!ampersandFlag) { wait(&status); } } return 0; }
Game::status TicTacToe::gameStatus(GameStatePtr state) { string s = state->toString(); s[9]='.'; //string sX= replaceAll(state->toString(),"O","."); // string sX= replaceAll(s,"O","."); // sX=replaceAll(sX,"_","."); // // string sO= replaceAll(s,"X","."); // sO=replaceAll(sO,"_","."); /*if (sX=="XXX......." || sX=="...XXX...." || sX=="......XXX." || sX=="X..X..X..." || sX==".X..X..X.." || sX=="..X..X..X." || sX=="X...X...X." || sX=="..X.X.X...") */ if (strMatch(s.c_str(), "XXX???????") || strMatch(s.c_str(), "???XXX????") || strMatch(s.c_str(), "??????XXX?") || strMatch(s.c_str(), "X??X??X???") || strMatch(s.c_str(), "?X??X??X??") || strMatch(s.c_str(), "??X??X??X?") || strMatch(s.c_str(), "X???X???X?") || strMatch(s.c_str(), "??X?X?X???")) { return Game::status::PLAYER1WIN; } /*else if (s=="OOO......." || s=="...OOO...." || s=="......OOO." || s=="O..O..O..." || s==".O..O..O.." || s=="..O..O..O." || s=="O...O...O." || s=="..O.O.O...")*/ else if (strMatch(s.c_str(), "OOO???????") || strMatch(s.c_str(), "???OOO????") || strMatch(s.c_str(), "??????OOO?") || strMatch(s.c_str(), "O??O??O???") || strMatch(s.c_str(), "?O??O??O??") || strMatch(s.c_str(), "??O??O??O?") || strMatch(s.c_str(), "O???O???O?") || strMatch(s.c_str(), "??O?O?O???")) { return Game::status::PLAYER2WIN; } else if (s.find("_") == string::npos) { return Game::status::DRAW; } else { return Game::status::ONGOING; } }
TokenTag keyLongest(String str) { Bool okay, matched; String tokstr; int i, ch, maxlen, matchlen, matchno; /* * If we have something, do any tokens start with the * same character? */ if (!str || (ch = str[0]) == 0 || keyIx[ch] == KeyNope) return TK_LIMIT; /* Initially there are no matching tokens */ maxlen = 0; matchno = TK_LIMIT; /* * Search the token table starting with the first token that * shares the same first character as the target. */ for (i = keyIx[ch]; ; i++) { /* Get the name and state of the i'th token */ tokstr = tokInfo(i).str; okay = !(tokInfo(i).isDisabled); /* Have we run out of tokens with the same start? */ if (tokstr[0] != ch) break; /* Yes */ /* Compute the length of the match */ matchlen = strMatch(tokInfo(i).str, str); /* * Perfect match? Note that if we stored the * length of every token in a table then we * could avoid calls to strlen. Mind you, the * scanner is blindly fast already so we might * not notice any speed difference. */ matched = (matchlen == strlen(tokInfo(i).str)); /* * If the word matches the name of the token and it * hasn't been disabled then remember the token if * it is the longest that we've found so far. */ if (okay && matched && (matchlen > maxlen)) { maxlen = matchlen; matchno= i; } } /* Return the longest token found */ return matchno; }
static bool parseError(const TLang *lng, const wchar_t *compiler, const wchar_t *path, const wchar_t *fn, const wchar_t *line, uintptr_t ci, intptr_t &aj) { intptr_t lineBounds[2], colBounds[2], fileBounds[2]; const TCompiler *e = nullptr; bool found = false, res = false; for (size_t i = 0; i < lng->compilerColl.getCount (); i++) { e = lng->compilerColl[i]; if (e && !e->err.empty() && !_wcsicmp (compiler, e->title)) { intptr_t bounds[3][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 } }; intptr_t pos[3] = { e->line, e->col, e->fileMatch }; if (strMatch (line, e->err, L"/", L".*/i", 3, bounds, pos)) { for (int j = 0; j < 2; j++) { lineBounds[j] = bounds[0][j]; colBounds[j] = bounds[1][j]; fileBounds[j] = bounds[2][j]; } found = true; break; } } } if (found && e && !e->err.empty()) { intptr_t len, lineNo = -1, colNo = -1; compilerOut[ci].Flags = 0; wchar_t fileName[NM]; String colSearch; if (e->line >= 0) { len = lineBounds[1] - lineBounds[0]; wcsncpy (fileName, line + lineBounds[0], len + 1); fileName[len] = 0; if (len) lineNo = FSF.atoi (fileName); } if (e->col >= 0) { len = colBounds[1] - colBounds[0]; wcsncpy (fileName, line + colBounds[0], len + 1); fileName[len] = 0; if (len) { if (e->searchCol) { colNo = -2; colSearch = fileName; } else colNo = FSF.atoi (fileName); } } if (e->fileMatch >= 0) { len = fileBounds[1] - fileBounds[0]; wcsncpy (fileName, line + fileBounds[0], len + 1); fileName[len] = 0; if (!len) wcscpy (fileName, fn); } else wcscpy (fileName, fn); TErrData *errData = new TErrData; fExpand (wcscpy (errData->fn, fileName), path); const wchar_t *p = line; errData->msgCount = 0; for (;;) { wchar_t brk[260]; //Info.AdvControl (&MainGuid, ACTL_GETSYSWORDDIV, brk); brk[0] = L' '; brk[1] = L'\t'; brk[2] = 0; wchar_t *pb = errData->message[errData->msgCount]; wcsncpy (pb, p, 64); pb[63] = 0; if (wcspbrk (pb, brk)) { wchar_t *pp = wcschr (pb, 0); if (pp > pb) { while (!wcschr (brk, *(--pp))) if (pp <= pb) break; pp[1] = 0; } } p += wcslen (pb); FSF.Trim (pb); if (!*pb) { wcscpy (pb, L"\x01"); errData->msgCount++; break; } errData->msgCount++; } errData->line = lineNo; errData->col = colNo; errData->colSearch = colSearch; errColl->insert (errData); compilerOut[ci].UserData = errColl->getCount (); if (aj < 0) { compilerOut[ci].Flags = MIF_SELECTED; aj = (intptr_t)ci; } res = true; } return (res); }
int main(){ int pos=strMatch("abbcabcabbbc","abc"); printf("%d\n",pos); }