int isIdentifier(char red) { int stateNum = 0; while((red = fgetc(myFile)) != EOF) { if(isTerminated(red)) { if(red == '\n') iLn--; ungetc(red,myFile); if(red == '\'' || red == '=') return 0; return 1; } addletter(red); switch(stateNum) { case 0: { if(isalpha(red) || red == '_') stateNum = 1; else return 0; break; } case 1: { if(isalnum(red) || red == '_') stateNum = 1; else return 0; break; } } }//while((red=fgetc(myFile)) != EOF); return 1; }
char *isKeyword(char red) { int stateNum = 0; while((red = fgetc(myFile)) != EOF) { if(isTerminated(red)) { if(red == '\n') iLn--; ungetc(red,myFile); break; } addletter(red); switch(stateNum) { case 0: { if(red == 'a') stateNum = 1; else if(red == 'b') stateNum = 7; else if(red == 'c') stateNum = 11; else if(red == 'd') stateNum = 15; else if(red == 'e') stateNum = 18; else if(red == 'f') stateNum = 21; else if(red == 'i') stateNum = 26; else if(red == 'l') stateNum = 31; else if(red == 'n') stateNum = 34; else if(red == 'p') stateNum = 38; else if(red == 'r') stateNum = 47; else if(red == 's') stateNum = 53; else if(red == 't') stateNum = 56; else return "ERR"; break; } case 1: { if(red == 'd') stateNum = 2; else if(red == 's') stateNum = 4; else if(red == 'r') stateNum = 201; else return "ERR"; break; } case 2: { if(red == 'd') stateNum = 3; else return "ERR"; break; } case 3: { return "ERR"; } case 4: { return "ERR"; } case 201: { if(red == 'r') stateNum = 5; else return "ERR"; break; } case 5: { if(red == 'y') stateNum = 6; else return "ERR"; break; } case 6: return "ERR"; case 7: { if(red == 'o') stateNum = 8; else return "ERR"; break; } case 8: { if(red == 'o') stateNum = 9; else return "ERR"; break; } case 9: { if(red == 'l') stateNum = 10; else return "ERR"; break; } case 10: return "ERR"; case 11: { if(red == 'n') stateNum = 12; else return "ERR"; break; } case 12: { if(red == 's') stateNum = 13; else return "ERR"; break; } case 13: { if(red == 't') stateNum = 14; else return "ERR"; break; } case 14: return "ERR"; case 15: { if(red == 'q') stateNum = 16; else return "ERR"; break; } case 16: { if(red == 'e') stateNum = 17; else return "ERR"; break; } case 17: return "ERR"; case 18: { if(red == 'q') stateNum = 19; else return "ERR"; break; } case 19: { if(red == 'e') stateNum = 20; else return "ERR"; break; } case 20: return "ERR"; case 21: { if(red == 'l') stateNum = 22; else return "ERR"; break; } case 22: { if(red == 't') stateNum = 23; else if(red == 's') stateNum = 24; else return "ERR"; break; } case 23: return "ERR"; case 24: { if(red == 'e') stateNum = 25; else return "ERR"; break; } case 25: return "ERR"; case 26: { if(red == 's') stateNum = 27; else if(red == 'n') stateNum = 28; else return "ERR"; break; } case 27: return "ERR"; case 28: { if(red == 'p') stateNum = 29; else return "ERR"; break; } case 29: { if(red == 't') stateNum = 30; else return "ERR"; break; } case 30: return "ERR"; case 31: { if(red == 's') stateNum = 32; else return "ERR"; break; } case 32: { if(red == 't') stateNum = 33; else return "ERR"; break; } case 33: return "ERR"; case 34: { if(red == 'u') stateNum = 36; else if(red == 'o') stateNum = 35; else return "ERR"; break; } case 35: return "ERR"; case 36: { if(red == 'm') stateNum = 37; else return "ERR"; break; } case 37: return "ERR"; case 38: { if(red == 'o') stateNum = 39; else if(red == 'u') stateNum = 41; else if(red == 'r') stateNum = 44; else return "ERR"; break; } case 39: { if(red == 'p') stateNum = 40; else return "ERR"; break; } case 40: return "ERR"; case 41: { if(red == 's') stateNum = 42; else return "ERR"; break; } case 42: { if(red == 'h') stateNum = 43; else return "ERR"; break; } case 43: return "ERR"; case 44: { if(red == 'n') stateNum = 45; else return "ERR"; break; } case 45: { if(red == 't') stateNum = 46; else return "ERR"; break; } case 46: return "ERR"; case 47: { if(red == 'p') stateNum = 48; else if(red == 't') stateNum = 50; else return "ERR"; break; } case 48: { if(red == 't') stateNum = 49; else return "ERR"; break; } case 49: return "ERR"; case 50: { if(red == 'r') stateNum = 51; else return "ERR"; break; } case 51: { if(red == 'n') stateNum = 52; else return "ERR"; break; } case 52: return "ERR"; case 53: { if(red == 't') stateNum = 54; else return "ERR"; break; } case 54: { if(red == 'r') stateNum = 55; else return "ERR"; break; } case 55: return "ERR"; case 56: { if(red == 'h') stateNum = 57; else if(red == 'r') stateNum = 60; else return "ERR"; break; } case 57: { if(red == 'i') stateNum = 58; else return "ERR"; break; } case 58: { if(red == 's') stateNum = 59; else return "ERR"; break; } case 59: return "ERR"; case 60: { if(red == 'u') stateNum = 61; else return "ERR"; break; } case 61: { if(red == 'e') stateNum = 62; else return "ERR"; break; } case 62: return "ERR"; }//switch }//while((red = fgetc(myFile)) != EOF); switch(stateNum) { case 3: return "ADD_TO_LIST"; case 4: return "ITR_AS"; case 6: return "ARRY_TYPE"; case 10: return "BOOL_TYP"; case 14: return "CONSTANT"; case 17: return "DEQ_LIST"; case 20: return "ENQ_LIST"; case 23: return "FLT_TYP"; case 25: return "FALSE"; case 27: return "IF_"; case 30: return "INPT_DATA"; case 33: return "LIST_TYPE"; case 35: return "ELSE_"; case 37: return "INT_TYP"; case 40: return "POP_LIST"; case 43: return "PUSH_LIST"; case 46: return "PRNT_DATA"; case 49: return "LOOP_THIS"; case 52: return "RETURN_VAL"; case 55: return "STR_TYP"; case 59: return "THIS"; case 62: return "TRUE"; default: { //ungetc(red,myFile); return "ERR"; } } }
ErrorCode PipeServer::runProc() { HANDLE hPipe = INVALID_HANDLE_VALUE; // this means that lpszPipename is type of LPWSTR wchar_t lpszPipename[CPPL_PIPESERV_WIN_MAXFNAMEBYTES]; // = TEXT("\\\\.\\pipe\\mynamedpipe"); if (strlen(pipename) >= CPPL_PIPESERV_WIN_MAXCHARPIPENAME) return ErrorCode::FAILURE; // LPCSTR -> LPCWSTR if (!MultiByteToWideChar(CP_UTF8, 0, pipename, strlen(pipename) + 1, lpszPipename, CPPL_PIPESERV_WIN_MAXFNAMEBYTES)) { printf("Error PipeServer::start()::MultiByteToWideChar::GLA: %d", GetLastError()); return ErrorCode::FAILURE; } int joined; OVERLAPPED o; memset(&o, 0, sizeof(OVERLAPPED)); // might be unnecessary o.Offset = 0; o.OffsetHigh = 0; // maybe second parameter false ResetEvent()??? o.hEvent = CreateEvent(NULL, true, false, NULL); if (o.hEvent == NULL) return ErrorCode::FAILURE; // The main loop creates an instance of the named pipe and // then waits for a client to connect to it. When the client // connects, a thread is created to handle communications // with that client, and this loop is free to wait for the // next client connect request. It is an infinite loop. while(1) // TODO: Termination through IPC or "something like signal" { if (isTerminated()) { CloseHandle(o.hEvent); CloseHandle(hPipe); manager.terminateAndJoin(); return ErrorCode::TERMINATED; } joined = manager.joinIfFinished(); if (joined) printf("joined %d and remains %d\n", joined, manager.threadCount()); hPipe = CreateNamedPipeW( lpszPipename, // pipe name PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, // read/write access, asnyc becouse of timeout implementation PIPE_REJECT_REMOTE_CLIENTS | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, PIPE_UNLIMITED_INSTANCES, // max. instances CPPL_PIPESERV_WIN_OUTBUFSIZE, // output buffer size CPPL_PIPESERV_WIN_INBUFSIZE, // input buffer size CPPL_PIPESERV_WIN_CONNECTTIMEO, // client time-out NULL); // default security attribute if (hPipe == INVALID_HANDLE_VALUE) { printf("CreateNamedPipe failed, GLE=%d.\n", GetLastError()); CloseHandle(o.hEvent); CloseHandle(hPipe); return ErrorCode::FAILURE; } // beware of overlapped io. Return value behaves very weird. ConnectNamedPipe(hPipe, &o); DWORD errCode = GetLastError(); if (errCode != ERROR_IO_PENDING && errCode != ERROR_SUCCESS && errCode != ERROR_PIPE_CONNECTED) { printf("ConnectNamedPipe() fatal error: GLA:%d\n", errCode); CloseHandle(o.hEvent); CloseHandle(hPipe); return ErrorCode::FAILURE; } DWORD rval; while(1) { rval = WaitForSingleObject(o.hEvent, mTimCON); if (isTerminated()) { CloseHandle(o.hEvent); CloseHandle(hPipe); manager.terminateAndJoin(); return ErrorCode::TERMINATED; } joined = manager.joinIfFinished(); if (joined) printf("joined %d and remains %d\n", joined, manager.threadCount()); if (rval == WAIT_OBJECT_0) break; if (rval == WAIT_TIMEOUT) { if (ResetEvent(o.hEvent) == FALSE) { printf("PipeServer::start():2:ResetEvent failed\n"); CloseHandle(o.hEvent); CloseHandle(hPipe); return ErrorCode::FAILURE; } continue; } CloseHandle(o.hEvent); CloseHandle(hPipe); return ErrorCode::FAILURE; } // GetOverlappedResult is useless because for ConnectNamedPipe() is return value undefined // http://msdn.microsoft.com/en-us/library/windows/desktop/ms683209(v=vs.85).aspx manager.startThread<PipeChannel>([=](){return m_proc(hPipe, mTimRX, mTimTX);}); } CloseHandle(o.hEvent); CloseHandle(hPipe); return ErrorCode::SUCCESS; }
// muust be exec only once! ErrorCode PipeServer::runProc() { int listenSocket = -1; struct sockaddr_un localAddress; if ((listenSocket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { perror("socket"); return ErrorCode::FAILURE; } localAddress.sun_family = AF_UNIX; strcpy(localAddress.sun_path, pipename); unlink(localAddress.sun_path); unsigned int len = strlen(localAddress.sun_path) + sizeof(localAddress.sun_family); if (bind(listenSocket, (struct sockaddr *)&localAddress, len) == -1) { perror("bind"); close(listenSocket); return ErrorCode::FAILURE; } /* * The backlog argument defines the maximum length to which the queue of pending connections * for sockfd may grow. If a connection request arrives when the queue is full, * the client may receive an error with an indication of ECONNREFUSED or, if the underlying * protocol supports retransmission, the request may be ignored so that * a later reattempt at connection succeeds. */ if (listen(listenSocket, CPPL_PIPESERV_UNIX_MAXCONNQUEUE) == -1) { perror("listen"); close(listenSocket); return ErrorCode::FAILURE; } socklen_t t; int acceptSocket; struct sockaddr_un remoteAddress; // int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); int tmperrno; // Set timeout on accept struct timeval tv; ms2tv(mTimCON, &tv); setsockopt(listenSocket, SOL_SOCKET, SO_RCVTIMEO, (const void *) &tv, sizeof(struct timeval)); while(1) // TODO: Termination through IPC or SIGTERM or by closing socket { t = sizeof(sockaddr_un); errno = 0; acceptSocket = accept(listenSocket, (struct sockaddr *)&remoteAddress, &t); tmperrno = errno; if (isTerminated()) { close(listenSocket); printf("PipeServer terminating ....\n"); manager.terminateAndJoin(); return ErrorCode::TERMINATED; } int joined = manager.joinIfFinished(); if (joined) printf("joined %d and remains %d\n", joined, manager.threadCount()); if (tmperrno == EAGAIN) { continue; } // TODO: if timeout continue; if (acceptSocket == -1) { perror("accept"); close(listenSocket); // TODO: we should here terminate and join all threads here return ErrorCode::FAILURE; } manager.startThread<PipeChannel>([=](){return m_proc(acceptSocket, mTimRX, mTimTX);}); } return ErrorCode::SUCCESS; }
// returns: ERROR_OK, ERROR_INPUTOUPUT, ERROR_INTEGRITY void extractDataToFile(LauncherProperties * props, WCHAR *output, int64t * fileSize, DWORD expectedCRC ) { if(isOK(props)) { DWORD * status = & props->status; HANDLE hFileRead = props->handler; int64t * size = fileSize; DWORD counter = 0; DWORD crc32 = -1L; HANDLE hFileWrite = CreateFileW(output, GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, hFileRead); if (hFileWrite == INVALID_HANDLE_VALUE) { WCHAR * err; writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "[ERROR] Can`t create file ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, output, 1); err = getErrorDescription(GetLastError()); writeMessageA(props, OUTPUT_LEVEL_DEBUG, 0, "Error description : ", 0); writeMessageW(props, OUTPUT_LEVEL_DEBUG, 0, err, 1); showErrorW(props, OUTPUT_ERROR_PROP, 2, output, err); FREE(err); *status = ERROR_INPUTOUPUT; return; } if(props->restOfBytes->length!=0 && props->restOfBytes->bytes!=NULL) { //check if the data stored in restBytes is more than we neen // rest bytes contains much less than int64t so we operate here only bith low bits of size DWORD restBytesToWrite = (compare(size, props->restOfBytes->length)> 0 ) ? props->restOfBytes->length : size->Low; DWORD usedBytes = restBytesToWrite; char *ptr = props->restOfBytes->bytes; DWORD write = 0; while (restBytesToWrite >0) { WriteFile(hFileWrite, ptr, restBytesToWrite, &write, 0); update_crc32(&crc32, ptr, write); restBytesToWrite -= write; ptr +=write; } modifyRestBytes(props->restOfBytes, usedBytes); minus(size, usedBytes); } if(compare(size, 0) > 0 ) { DWORD bufferSize = props->bufsize; char * buf = newpChar(bufferSize); DWORD bufsize = (compare(size, bufferSize) > 0) ? bufferSize : size->Low; DWORD read = 0 ; // printf("Using buffer size: %u/%u\n", bufsize, bufferSize); while (ReadFile(hFileRead, buf, bufsize, &read, 0) && read && compare(size, 0) > 0) { addProgressPosition(props, read); WriteFile(hFileWrite, buf, read, &read, 0); update_crc32(&crc32, buf, read); minus(size, read); if((compare(size, bufsize)<0) && (compare(size, 0)>0) ) { bufsize = size->Low; } ZERO(buf, sizeof(char) * bufferSize); if(compare(size, 0)==0) { break; } if((counter ++) % 20 == 0) { if(isTerminated(props)) break; } } if((compare(size, 0)>0 || read==0) && !isTerminated(props)) { // we could not read requested size * status = ERROR_INTEGRITY; writeMessageA(props, OUTPUT_LEVEL_DEBUG, 1, "Can`t read data from file : not enought data", 1); } FREE(buf); } CloseHandle(hFileWrite); crc32=~crc32; if(isOK(props) && crc32!=expectedCRC) { writeDWORD(props, OUTPUT_LEVEL_DEBUG, 0, "expected CRC : ", expectedCRC, 1); writeDWORD(props, OUTPUT_LEVEL_DEBUG, 0, "real CRC : ", crc32, 1); * status = ERROR_INTEGRITY; } } }
char *isNumber(char red) { int stateNum = 0; while((red=fgetc(myFile)) != EOF) { /*/if(red == '-' || red == '+') { if(stateNum == 0) ; else { ungetc(red, myFile); break; } } else //*/ if(isTerminated(red)) { ungetc(red,myFile); if(red == '\n') iLn--; if(red == '\'' || red == '=') return "ERR"; break; } addletter(red); switch(stateNum) { case -2: { if(isdigit(red)) stateNum = 2; else return "ERR"; break; } case -1: { if(isdigit(red)) stateNum = 1; else if(red == '.') stateNum = 2; else return "ERR"; break; } case 0: { if(isdigit(red)) stateNum = 1; else if(red == '.') stateNum = -2; else if(red == '-' || red == '+') stateNum = -1; else return "ERR"; break; } case 1: { if(isdigit(red)) stateNum = 1; else if(red == '.') stateNum = 2; else return "ERR"; break; } case 2: { if(isdigit(red)) stateNum = 2; else return "ERR"; } } }//while((red=fgetc(myFile)) != EOF); if(stateNum == 1) return "INTEGER"; if(stateNum == 2) return "FLOAT"; else return "ERR"; }
int Analyzer::isTerminated() {return isTerminated(act);}
JSCWebWorker::~JSCWebWorker() { FBASSERTMSGF(isTerminated(), "Didn't terminate the web worker before releasing it!"); }
void Enchantment::update() { if(isTerminated()) return; //Have we lost our target? std::shared_ptr<Object> target = _target.lock(); std::shared_ptr<Object> owner = _owner.lock(); if(target == nullptr || target->isTerminated()) { requestTerminate(); return; } //End enchant if owner of the Enchant has died? if(!_enchantProfile->_owner._stay) { if(!owner || !owner->isAlive()) { requestTerminate(); return; } } //End enchant if target of the enchant has died? if(!_enchantProfile->_target._stay && !target->isAlive()) { requestTerminate(); return; } //Spawn particles? if(_spawnParticlesTimer > 0) { _spawnParticlesTimer--; if(_spawnParticlesTimer == 0) { _spawnParticlesTimer = _enchantProfile->contspawn._delay; FACING_T facing = target->ori.facing_z; for (uint8_t i = 0; i < _enchantProfile->contspawn._amount; ++i) { ParticleHandler::get().spawnLocalParticle(target->getPosition(), facing, _spawnerProfileID, _enchantProfile->contspawn._lpip, ObjectRef::Invalid, GRIP_LAST, owner != nullptr ? owner->getTeam().toRef() : static_cast<TEAM_REF>(Team::TEAM_DAMAGE), owner != nullptr ? owner->getObjRef() : ObjectRef::Invalid, ParticleRef::Invalid, i, ObjectRef::Invalid); facing += _enchantProfile->contspawn._facingAdd; } } } //Can we kill the target by draining life? if(target->isAlive()) { if (target->getLife() + _targetLifeDrain < 0.0f) { target->kill(owner, false); } } //Can the owner still sustain us? if (owner && owner->isAlive()) { //Killed by draining life? if(owner->getLife() + _ownerLifeSustain < 0.0f) { owner->kill(target, false); if(_enchantProfile->endIfCannotPay || !_enchantProfile->_target._stay) { requestTerminate(); return; } } //Owner has no longer enough mana to sustain the enchant? if(_enchantProfile->endIfCannotPay) { if(owner->getMana() + _ownerManaSustain < 0.0f) { requestTerminate(); return; } } } //Decrement the lifetimer if(_lifeTime > 0) { if(_lifeTime == 0) { requestTerminate(); } } }
bool DemodulatorInstance::isModemInitialized() { if (!demodulatorPreThread || isTerminated()) { return false; } return demodulatorPreThread->isInitialized(); }
/* determines whether a given email address is valid. */ int isValidEmailAddress(char * address, char ** terminators, int num_terminators) { int identifier1 = 0; int atSymbol = 0; int identifier2 = 0; int terminated = 0; int numberOfStops = findNumberOfStops(address); int stopNumber = 0; int result = 0; char nullPointer = '\0'; int alphaCheck = 0; for(int i = 0; *(address+i) != nullPointer; i++) { if(!isalpha(*(address+i)) && !isdigit(*(address+i)) && *(address+i) != '.' && *(address+i) != '@') { result = 0; return result; } if(isalpha(*(address+i))) { alphaCheck = 1; if(identifier1 == 0) { identifier1 = 1; } else { identifier2 = 1; } } if(isdigit(*(address+i))) { if(identifier1 == 0) { identifier1 = 1; } else { identifier2 = 1; } if(alphaCheck != 1) { return 0; } } if(*(address+i) == '.') { alphaCheck = 0; stopNumber++; if(stopNumber == numberOfStops) { if(atSymbol == 0) { result = 0; return result; } if(isTerminated(address + i + 1, terminators, num_terminators)) // == 1 ? { terminated = 1; } else { result = 0; return result; } } if(identifier1 == 0) { result = 0; return result; } if(atSymbol == 0) { identifier1 = 0; } else { if(identifier2 == 0) { result = 0; return result; } else { identifier2 = 0; } } } if(*(address+i) == '@') { if(identifier1 == 0) { result = 0; return result; } if(atSymbol == 1) { result = 0; return result; } else { atSymbol = 1; } } } if(identifier1 != 1 || atSymbol != 1 || identifier2 != 1 || terminated != 1) { result = 0; return result; } result = 1; return result; }
void HookThread::Execute(void * data) { apmOptions = LoadAPMAlertOptions(); RazerMonitorThread * rmt = new RazerMonitorThread(); HotkeyThread * hkt = new HotkeyThread(); rmt->Start(NULL); hkt->Start(NULL); bool wasIngame = false; while(!isTerminated()) { if(!hooksSetup) { SetupHooks(); if(!hooksSetup) Sleep(5000); } else { if(isIngame && !wasIngame) { logInfo("Game detected. Beginning initialization."); isObs = true; if(apmOptions != NULL) FreeAPMAlertOptions(apmOptions); apmOptions = LoadAPMAlertOptions(); if(pApmFont != NULL) pApmFont->Release(); if(pClockFont != NULL) pClockFont->Release(); if(pLine != NULL) pLine->Release(); pApmFont = NULL; pClockFont = NULL; pLine = NULL; initializeAPMCalculator(); minPassed = false; WriteHooks(); wasIngame = isIngame; } else if(wasIngame && !isIngame) { logInfo("Game end detected."); ClearHooks(); wasIngame = isIngame; } if(isIngame) { doAlert(); } } Sleep(100); } logInfo("APMAlert2 beginning termination."); rmt->setTerminated(true); hkt->setTerminated(true); ClearHooks(); logInfo("Freeing resources."); if(pApmFont != NULL) { pApmFont->Release(); pApmFont = NULL; } if(pClockFont != NULL) { pClockFont->Release(); pClockFont = NULL; } if(pLine != NULL) { pLine->Release(); pLine = NULL; } if(apmOptions != NULL) FreeAPMAlertOptions(apmOptions); logInfo("Termination complete."); freeLogger(); }
JSCWebWorker::~JSCWebWorker() { CHECK(isTerminated()) << "Didn't terminate the web worker before releasing it!";; }
void startLex() { char *result; char red; char *number; int iString; while((red = fgetc(myFile)) != EOF) { if(red == '\n') iLn++; if(red == ' ' || red == '\n' || red == '\t') continue; if(isComment(red) == 1) { remove(); continue; } else returnItAll(); iString = isString(red); if(iString) { if(iString == 2) { iUnrec++; printf("\nUnrecognized lexeme: %s",word); recognized(word,"UNIDENTIFIED"); continue; } iRec++; recognized(word, "STRING_LITERAL"); continue; } else returnItAll(); if(red == '\''); else if(isTerminated(red) == 1) { int found = 1; red = fgetc(myFile); addletter(red); char sec = fgetc(myFile); if(sec == '=') { addletter(sec); if(red == '<') { iRec++; recognized(word,"LESSEQL"); continue; } else if(red == '>') { iRec++; recognized(word,"GRTREQL"); continue; } else if(red == '!') { iRec++; recognized(word,"NOTEQL"); continue; } else if(red == '=') found = 0; } else if(red == '<') recognized(word,"GRTRTH"); else if(red == '>') recognized(word,"LESSTH"); else if(red == '!') recognized(word,"NOT"); else if(red == '+') recognized(word,"ADD"); else if(red == '-') recognized(word,"SUB"); else if(red == '*') recognized(word,"MUL"); else if(red == '^') recognized(word,"RAISE"); else if(red == '/') recognized(word,"DIV"); else if(red == '%') recognized(word,"MOD"); else if(red == '~') recognized(word,"TRUNC_DIV"); else if(red == '|') recognized(word,"OR"); else if(red == '&') recognized(word,"AND"); else if(red == '=') recognized(word,"EQLTO"); else if(red == '?') recognized(word,"COND_END"); else if(red == ':') recognized(word,"ASSIGN"); else if(red == '{') recognized(word,"B_START"); else if(red == '}') recognized(word,"B_END"); else if(red == ';') recognized(word,"STMNT_END"); else if(red == '(') recognized(word,"P_START"); else if(red == ')') recognized(word,"P_END"); else if(red == ',') recognized(word,"COM"); if(found) { iRec++; ungetc(sec,myFile); continue; } else returnItAll(); } if(!(strcmp((number = isNumber(red)),"ERR") == 0)) { iRec++; recognized(word, number); continue; } else returnItAll(); if(!(strcmp((result = isKeyword(red)),"ERR") == 0)) { iRec++; recognized(word, result); continue; } else returnItAll(); if(isIdentifier(red)) { iRec++; recognized(word,"ID"); continue; } else returnItAll(); { iUnrec++; while((red = fgetc(myFile)) != EOF) { if(red == EOF) break; if(isTerminated(red)) { if(red == '\n') iLn--; if(red == '\'' || red == '='); else { ungetc(red,myFile); break; } } addletter(red); } printf("\nLine %d: Unrecognized lexeme %s",iLn,word); recognized(word, "UNIDENTIFIED"); } }//while((red = fgetc(myFile)) != EOF); }
void Analyzer::considerValue() { if(isTerminated()) { return; } haveEmptyCell = false; for(int i=0; i<act->getSize(); i++) { for(int j=0; j<act->getSize(); j++) { if(haveEmptyCell || act->getCell(i, j) == 0) {haveEmptyCell = true;} if( act->getCell(i, j) == 0 && (act->getCell(i-1, j)>0 || act->getCell(i-1, j-1)>0 || act->getCell(i-1, j-2)>0 || act->getCell(i-1, j+1)>0 || act->getCell(i-1, j+2)>0 || act->getCell(i-2, j)>0 || act->getCell(i-2, j-1)>0 || act->getCell(i-2, j-2)>0 || act->getCell(i-2, j+1)>0 || act->getCell(i-2, j+2)>0 || act->getCell(i+1, j)>0 || act->getCell(i+1, j-1)>0 || act->getCell(i+1, j-2)>0 || act->getCell(i+1, j+1)>0 || act->getCell(i+1, j+2)>0 || act->getCell(i+2, j)>0 || act->getCell(i+2, j-1)>0 || act->getCell(i+2, j-2)>0 || act->getCell(i+2, j+1)>0 || act->getCell(i+2, j+2)>0 || act->getCell(i, j-1)>0 || act->getCell(i, j-2)>0 || act->getCell(i, j+1)>0 || act->getCell(i, j+2)>0 )) { signCells->setCell(i, j, 1); } else {signCells->setCell(i, j, 0);} } } myValue = 0; opValue = 0; int opNumber = pn==1?2:1; for(int i=0; i<act->getSize(); i++) { for(int j=0; j<act->getSize(); j++) { if(signCells->getCell(i,j)) { myValues->setCell(i,j, ValueUP(i, j, pn) + ValueRIGHTUP(i, j, pn) + ValueRIGHT(i, j, pn) + ValueRIGHTDOWN(i, j, pn) + ValueDOWN(i, j, pn) + ValueLEFTDOWN(i, j, pn) + ValueLEFT(i, j, pn) + ValueLEFTUP(i, j, pn) ); opValues->setCell(i,j, ValueUP(i, j, opNumber) + ValueRIGHTUP(i, j, opNumber) + ValueRIGHT(i, j, opNumber) + ValueRIGHTDOWN(i, j, opNumber) + ValueDOWN(i, j, opNumber) + ValueLEFTDOWN(i, j, opNumber) + ValueLEFT(i, j, opNumber) + ValueLEFTUP(i, j, opNumber) ); myValue += myValues->getCell(i, j); opValue += opValues->getCell(i, j); } } } }
void searchCurrentJavaRegistry(LauncherProperties * props, BOOL access64key) { DWORD i=0; WCHAR ** keys = JAVA_REGISTRY_KEYS; DWORD k=0; WCHAR * buffer = newpWCHAR(MAX_LEN_VALUE_NAME); HKEY rootKeys [2] = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER}; DWORD rootKeysNumber = sizeof(rootKeys)/sizeof(HKEY); DWORD keysNumber = sizeof(JAVA_REGISTRY_KEYS)/sizeof(WCHAR*); DWORD status = ERROR_OK; writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "Search java in CurrentVersion values...", 1); for ( k = 0; k < rootKeysNumber; k++) { for(i=0; i < keysNumber;i++) { if(isTerminated(props)) { return; } else { WCHAR * value = getStringValue(rootKeys[k], keys[i], CURRENT_VERSION, access64key); if(value!=NULL) { WCHAR *javaHome = getStringValuePC(rootKeys[k], keys[i], value, JAVA_HOME, access64key); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "... ", 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, (rootKeys[k]==HKEY_LOCAL_MACHINE) ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER", 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "\\", 0); writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, keys[i], 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "\\", 0); writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, CURRENT_VERSION, 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "->", 0); writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, value, 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "[", 0); writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, JAVA_HOME, 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "] = ", 0); writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, javaHome, 1); FREE(value); trySetCompatibleJava(javaHome, props); FREE(javaHome); if(props->java!=NULL) { FREE(buffer); return; } } } } } // we found no CurrentVersion java... just search for other possible keys writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "Search java in other values...", 1); for(k=0;k<rootKeysNumber;k++) { for(i=0;i<keysNumber;i++) { HKEY hkey = 0; DWORD index = 0 ; if (RegOpenKeyExW(rootKeys[k], keys[i], 0, KEY_READ | ((access64key && IsWow64) ? KEY_WOW64_64KEY : 0), &hkey) == ERROR_SUCCESS) { DWORD number = 0; if (RegQueryInfoKeyW(hkey, NULL, NULL, NULL, &number, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { DWORD err = 0; do { DWORD size = MAX_LEN_VALUE_NAME; buffer[0] = 0; err = RegEnumKeyExW(hkey, index, buffer, &size, NULL, NULL, NULL, NULL); if (err == ERROR_SUCCESS) { WCHAR * javaHome = getJavaHomeValue(keys[i], buffer, access64key); status = ERROR_OK; writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, (rootKeys[k]==HKEY_LOCAL_MACHINE) ? "HKEY_LOCAL_MACHINE" : "HKEY_CURRENT_USER", 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "\\", 0); writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, keys[i], 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "\\", 0); writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, buffer, 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "[", 0); writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, JAVA_HOME, 0); writeMessageA(props, OUTPUT_LEVEL_NORMAL, 0, "] = ", 0); writeMessageW(props, OUTPUT_LEVEL_NORMAL, 0, javaHome, 1); trySetCompatibleJava(javaHome, props); FREE(javaHome); if(props->java!=NULL) { i = keysNumber; // to the end of cycles k = rootKeysNumber; break; } } index++; } while (err == ERROR_SUCCESS); } } if (hkey != 0) { RegCloseKey(hkey); } } } FREE(buffer); return; }
void interactive(image_processor p, unsigned imageWidth, unsigned imageHeight, unsigned nsSize, unsigned nsDepth) { image* img = image_new(imageWidth, imageHeight); fill_image(img, 1, 1, 1); #define WIND_COUNT 4 wind* w[WIND_COUNT]; vec2 wOrigin[WIND_COUNT] = { {0, 0}, {imageWidth, 0}, {0, imageHeight}, {imageWidth, imageHeight} }; float wColors[3 * WIND_COUNT] = { 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, }; for(unsigned i = 0; i < WIND_COUNT; i++) { w[i] = wind_new(imageWidth * imageHeight * 10 / 1000); } unsigned particlesToDraw = 5; float maxSpread = 2.5; float particleNoiseVelocity = 2.0; float drag = 0.99; float wAlpha = 0.125; //Potentials noise_sum* ncl = initialize_noise_sum_2d(nsSize, nsDepth); noise_sum_scale_in(ncl, 1.0 / (imageWidth * 4.0)); vec2 gradient = {0, 0}; #define GRAVITY_COUNT 16 centered_cl orbits[ORBIT_COUNT]; for(unsigned i = 0; i < ORBIT_COUNT; i++) { orbits[i].cx = uniformFloat(0, imageWidth); orbits[i].cy = uniformFloat(0, imageWidth); orbits[i].strength = imageWidth * imageWidth; if(i % 2) orbits[i].strength *= -1; orbits[i].denominatorSummand = (imageWidth / 4.0) * (imageWidth / 4.0); } //orbits[0].strength /= 4; orbits[0].strength *= 4; #undef POTENTIAL_COUNT #define POTENTIAL_COUNT (2 + GRAVITY_COUNT) float(*potentialFunctions[POTENTIAL_COUNT])(float, float, void*) = { noiseSumPotential, gradientPotential }; void* pcls[POTENTIAL_COUNT] = { ncl, &gradient }; float weights[POTENTIAL_COUNT] = { 10, 0.5, }; for(unsigned i = 0; i < ORBIT_COUNT; i++) { potentialFunctions[i + 2] = distanceSquaredPotential; pcls[i + 2] = &orbits[i]; weights[i + 2] = 1.0 / 2.0; } poly_weighted_cl pcl = { potentialFunctions, pcls, weights, POTENTIAL_COUNT }; for(unsigned i = 0; !isTerminated(); i++) { processXEvents(); //Update player gravity source //TODO replace the latter with the prior. vec2 mouse = getMousePosition(); orbits[0].cx = mouse.x; orbits[0].cy = mouse.y; //printf("%f %f\n", mouse.x, mouse.y); if(isKeyPressed(SPACE)) { //Reverse polarity for(unsigned i = 1; i < ORBIT_COUNT; i++) { orbits[i].strength *= -1; } setKeyPressed(SPACE, false); } if(isKeyPressed(SHIFT)) { //Change colors. //TODO: use color structs.. /* for(unsigned c = 0; c < C; c++) { color.c[c] += uniformFloatS(tracerColorChange); //color.c[c] *= uniformFloat(tracerColorReduction, 1); if(color.c[c] <= tracerColorLow) { if(color.c[c] < 0) { color.c[c] = 0; } else { color.c[c] /= tracerColorReduction; } } else if(color.c[c] >= tracerColorHigh) { color.c[c] *= tracerColorReduction; } } */ for(unsigned i = 0; i < 3 * WIND_COUNT; i++) { wColors[i] += uniformFloatS(0.01); } } if(isKeyPressed('a')) { for(unsigned j = 0; j < WIND_COUNT; j++) { wind_append(w[j], mouse.x, mouse.y, 0, 0, uniformFloat(1, 2)); } } //Whiten the image. if(i % 2 == 0) { if(i % 8 == 0) fill_image_a(img, 1, 1, 1, 1.0 / 64.0); } else { image_blur_fast_inplace(img, i / 2); } //Render the noise /* for(unsigned y = 0; y < imageHeight; y++) { for(unsigned x = 0; x < imageWidth; x++) { float intensity = noise_sum_2d(x, y, ncl); for(unsigned c = 0; c < C; c++) { *image_pixel(img, x, y, c) = intensity; } } } */ for(unsigned a = 0; a < WIND_COUNT; a++) { wind_remove_rand(w[a], imageWidth * imageHeight / 1000); //Add wind particles. unsigned particlesToAdd = w[a]->maxParticles - w[a]->particles; for(unsigned j = 0; j < (particlesToAdd + 15) / 16; j++) { //float x = uniformFloat(-(int)(imageWidth / 4), 5 * imageWidth / 4); //float y = uniformFloat(-(int)(imageHeight / 4), 5 * imageHeight / 4); float x = wOrigin[a].x; float y = wOrigin[a].y; float dx = imageWidth / 2 - wOrigin[a].x; float dy = imageHeight / 2 - wOrigin[a].y; dx /= imageWidth; dy /= imageHeight; vec2 noise = vScale((particleNoiseVelocity), symmetricUnitBall()); wind_append(w[a], x, y, noise.x + dx, noise.y + dy, uniformFloat(0.5, 2)); } //Update wind. wind_scale_velocity(w[a], drag); wind_update_bound(w[a], 1.0, sumWeightedPotential, &pcl, -(imageWidth / 2.0), -(imageHeight / 2.0), 3.0 * imageWidth / 2.0, 3.0 * imageWidth / 2.0); /* //Perturb particle momentum just a bit. This prevents clumping. for(unsigned j = 0; j < w[a]->particles; j++) { vec2 noise = vScale((particleNoiseVelocity / 16.0), symmetricUnitBall()); wind_x(w[a])[j] += noise.x; wind_y(w[a])[j] += noise.y; } */ //Draw the wind. //wind_draw_roffset(w[a], img, 0, 0, 0, wAlpha * 0.5, 0, 0, 1, particlesToDraw, maxSpread); //wind_draw(w[a], img, 0, 0, 0, wAlpha, 0, 0, 1); wind_draw_roffset(w[a], img, wColors[a * 3 + 0], wColors[a * 3 + 1], wColors[a * 3 + 2], wAlpha * 0.5, 0, 0, 1, particlesToDraw, maxSpread); wind_draw(w[a], img, wColors[a * 3 + 0], wColors[a * 3 + 1], wColors[a * 3 + 2], wAlpha, 0, 0, 1); } //Update noise. perturb_noise_sum(ncl, 2, 0, 1, 1.0 / 16.0, 0.25, 0.001); //Move the orbits. #define ORBBROWN 1 #define ORBSHIFT 0.0001 #define ORBKEEP 0.9999 for(unsigned i = 1; i < ORBIT_COUNT; i++) { orbits[i].cx += uniformFloatS(ORBBROWN); orbits[i].cy += uniformFloatS(ORBBROWN); orbits[i].cx = ORBKEEP * orbits[i].cx + ORBSHIFT * imageWidth / 2; orbits[i].cy = ORBKEEP * orbits[i].cy + ORBSHIFT * imageHeight / 2; //Apply a repulsive force between the orbits (proportional to 1 / distance). for(unsigned j = i + 1; j < ORBIT_COUNT; j++) { float dx = orbits[i].cx - orbits[j].cx; float dy = orbits[i].cy - orbits[j].cy; float dSqr = dx * dx + dy * dy; float scale = imageWidth / 4; //Half the image away has effect 1. scale /= 16; orbits[i].cx += scale * dx / dSqr; orbits[i].cy += scale * dy / dSqr; orbits[j].cx -= scale * dx / dSqr; orbits[j].cx -= scale * dy / dSqr; } } //Perturb the gradient. gradient = vScale(uniformFloat(0.98, 1.0), vPlus(gradient, symmetricBall(0.01))); p(img, NULL); //Process the image (send it to the screen or to disk). } }