void scan_arp_and_block(char *arpOutput) { char *line = strtok(arpOutput,"\n"); char *ip; char iptable_block_cmd[MAXSTRINGLENGTH] = {'\0',}; //char iptable_unblock_cmd[MAXSTRINGLENGTH] = {'\0'}; while (line) { line = strtok(NULL," \t\n"); if (!line) break; //printf("split the line and get %s\n",line); if (isValidIpAddress(line)) { ip = line; continue; } if (isValidMAC(line)) { if(strstr(conf->whitelist,line) || Query(arpList,ip)) { continue; } else { InsertEmptyLink(arpList,ip,BLOCKED_FLAG); sprintf(iptable_block_cmd,"iptables -t nat -I PREROUTING -s %s -p tcp --dport 80 -j REDIRECT --to-ports %s", ip, servPort); char *block_cmd_output = exec_cmd_shell(iptable_block_cmd); if(!block_cmd_output) free(block_cmd_output); LOGD("blocked ip addr %s \n",ip); } } } CheckList(arpList); }
void KeywordList( void ) { //=========================== bool morelist; if( RecNextOpr( OPR_EQU ) ) { morelist = true; } else { if( Permission( IO_UNIT ) ) { Unit(); AdvanceITPtr(); } else { NextComma(); } if( FormatIdentifier() ) { if( Permission( IO_FMT ) ) { FormatIdd(); AdvanceITPtr(); } else { NextComma(); } } morelist = RecComma(); } if( morelist ) { for(;;) { GetItem(); if( !RecComma() ) break; } } CheckList(); // check that list had necessities ( unit ) // also remember if end= is specified }
//Read a line and fill parameter void ExperimentalPoint::ReadLineAndTreat(int MagnetQuadrant, TString Grid, int Location, int Level, double Bx, double By, double Bz){ fMagnetQuadrant = MagnetQuadrant ; fLocation = Location ; fLevel = Level; fGrid = Grid ; TString key = Grid + Form("%d%d",MagnetQuadrant,Level); CheckList(Grid, MagnetQuadrant, Level); if(fSetBackground) SubtractBackground(Grid, Location, Bx,By,Bz); CalculateCentralPosition() ; //Correct for probe rotation if (Grid=="B" && Location>=4 && Location<=7) { // when the probe is tilted in the B grid, the sensorX receives most of the magnetic field in contrast to sensorY // to keep things in order, the sensorX value could be split into (x-component an y-component) fBField.SetXYZ(Bx/10.,0,-Bz/10.); //ignore By, it will be filled by rotation fBField.RotateZ(-45*TMath::DegToRad()); TVector3 SensorOffsetX = fSensorOffsetX; // copy the offset and rotate 45 degrees SensorOffsetX.RotateZ(-45*TMath::DegToRad()); fSensorPositionX = fPosition + SensorOffsetX; fSensorPositionY = fPosition + SensorOffsetX; // yes it is X! fSensorPositionZ = fPosition + fSensorOffsetZ; } else if (Grid=="D" && Location>=5 && Location<=7) { // when the probe is tilted in the D grid, the sensorY receives most of the magnetic field in contrast to sensorX // again, the sensorY value could be split into (x-component an y-component) fBField.SetXYZ(0.,-By/10.,-Bz/10.); //ignore Bx, it will be filled by rotation fBField.RotateZ(-45*TMath::DegToRad()); TVector3 SensorOffsetY = fSensorOffsetY; // copy the offset and rotate 45 degrees SensorOffsetY.RotateZ(-45*TMath::DegToRad()); fSensorPositionX = fPosition + SensorOffsetY; fSensorPositionY = fPosition + SensorOffsetY; // yes it is Y! fSensorPositionZ = fPosition + fSensorOffsetZ; } else { fBField.SetXYZ(Bx/10.,-By/10.,-Bz/10.); // turn to millitesla, By need to be multiplied by (-) to account for the axis change between simulation/experiment and the way the mapper is set fSensorPositionX = fPosition + fSensorOffsetX; fSensorPositionY = fPosition + fSensorOffsetY; fSensorPositionZ = fPosition + fSensorOffsetZ; } //correct for Lens rotations double angle = CalculateRotationAngle(MagnetQuadrant, Grid); fPosition.RotateZ(angle*TMath::DegToRad()); fSensorPositionX.RotateZ(angle*TMath::DegToRad()); fSensorPositionY.RotateZ(angle*TMath::DegToRad()); fSensorPositionZ.RotateZ(angle*TMath::DegToRad()); fBField.RotateZ(angle*TMath::DegToRad()); //ShowParameters(); //cin.get(); }
/* Check just the ECO tag from the game's tag details. */ Boolean CheckECOTag(char *Details[]) { Boolean wanted = TRUE; if(GlobalState.check_tags){ if(TagLists[ECO_TAG].num_used_elements != 0){ if(Details[ECO_TAG] != NULL){ wanted = CheckList(ECO_TAG,Details[ECO_TAG],&TagLists[ECO_TAG]); } else{ /* Required tag not present. */ wanted = FALSE; } } } return wanted; }
void ColorGrid::ccTouchMoved(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) { cocos2d::CCPoint touchLocation = touch->getLocation(); if (m_cbBounds.containsPoint(touchLocation)) { for(int i = 0; i < m_nNodes; i++) { if(m_pNodes[i].isOnSprite(touchLocation) && CheckList(i) && CheckAdjacency(i) && m_nSelectedNodesSize < m_nComboSize) { m_pNodes[i].select(); m_pSelectedNodes[m_nSelectedNodesSize] = &m_pNodes[i]; m_cbSequenceColors[m_nSelectedNodesSize] = m_pNodes[i].getPaletteIndex(); m_pSelectedNodeNumbers[m_nSelectedNodesSize] = i; m_nSelectedNodesSize++; } } } }
void EndTag(unl *tag, long len) { char *name = (char *) Parser->U32to8Str(tag, len); long etype = CurrEtype; if (!stricmp(name, "udx")) { if (PendingText) { WriteText(PendingText); PendingText = NULL; } WriteCode("</udx>"); CheckUdxEnd(); return; } if (DoMin && DoBlank && EndingPTag) { if (!SkippedPTag) WriteCode("</p>"); else SkippedPTag = false; EndingPTag = false; } if (PendingText) { EmptyTag = false; PendingText = WriteTextWithoutTrailingSpace(PendingText); } char *etag = NULL; char *shend = NULL; bool removed = false; if (DoFull) { if (((etag = CurrShort->find(CurrDepth)) != NULL) && !stricmp(etag, name)) { // close of replaced short tag //removed = true; return; } } else if (DoMin) { if (((etag = CurrFull->find(CurrDepth)) != NULL) && !stricmp(etag, name)) { // close of replaced full tag removed = true; CurrFull->remove(CurrDepth); } } bool skiptag = false; if (EmptyTag) { WriteChar('/'); WriteChar('>'); EmptyTag = false; } else if (!removed) { if (DoFull) { // see if end tag at same level as pending full end tag if (NestingLevel) { while (((((shend = CurrShortEnd->find(CurrDepth)) != NULL) && CheckList(shend, name)) // end of CurrFull goes here || (((etag = CurrStype->find(NestingLevel)) != NULL) && !stricmp(name, etag))) && (CurrDepth > NestingLevel)) WriteEndFullTag(); // close curr open tag if any if (((etag = CurrStype->find(CurrDepth)) != NULL) && !stricmp(name, etag)) { // see if closing CurrStype long depth = CurrDepth; while (LastFullEndDepth > depth) { CurrDepth = LastFullEndDepth; WriteEndFullTag(); // close last open tag in container if any } CurrDepth = depth; CurrStype->remove(CurrDepth); NestingLevel = Nesting->find(CurrDepth); Nesting->remove(CurrDepth); } } } else if (DoMin) { if (ShortTag) { skiptag = true; ShortTag = false; } if (NestingLevel) { if (((etag = CurrFull->find(CurrDepth)) != NULL) && !stricmp(name, etag)) { // see if end for removed full tag skiptag = true; CurrFull->remove(CurrDepth); CurrShort->remove(CurrDepth); } else if (((etag = CurrStype->find(CurrDepth)) != NULL) && !stricmp(name, etag)) { // see if closing CurrStype CurrStype->remove(CurrDepth); NestingLevel = Nesting->find(CurrDepth); Nesting->remove(CurrDepth); } } } if (PendingText) { WriteText(PendingText); PendingText = NULL; } if (DoMin) { if (DoWiki) { // check for wiki symbol tags if (WriteWikiSym(name, false)) skiptag = true;; } if (DoBlank) { if (!stricmp(CurrElem, "p") && !stricmp(name, "p")) { EndingPTag = true; skiptag = true;; } } if (DoPara) { if (SkippedPTag && !stricmp(name, "p")) skiptag = true;; } } if (DoFull && DoPara) { // if ending block, and in wrapped text, close the p if ((etype == 1) && WrappedText) { WriteCode("</p>"); WrappedText = false; } } if (!skiptag) { WriteChar('<'); WriteChar('/'); WriteText(name); if (IsCodeTag(name)) InCode--; WriteChar('>'); } } CurrElems->remove(CurrDepth); CurrEtypes->remove(CurrDepth); CurrElem = CurrElems->find(CurrDepth - 1); CurrEtype = CurrEtypes->find(CurrDepth - 1); CurrDepth--; }
void StartTag(unl *tag, long len, pair **attrs, long attrcnt) { if (EmptyTag) { // end of previous start tag WriteChar('>'); EmptyTag = false; } char *name = (char *) Parser->U32to8Str(tag, len); if (!stricmp(name, "udx")) { if (PendingText) { WriteText(PendingText); PendingText = NULL; } WriteStartTag(name, attrs, attrcnt); WriteChar('>'); CheckUdxTag(attrs, attrcnt); return; } IsPTag = !stricmp(name, "p"); long lastetype = CurrEtype; CurrElem = name; CurrEtype = GetCurrEtype(name); bool skiptag = false; if (DoMin) { if (DoBlank && EndingPTag && PendingText) { if (!IsPTag || attrs) { // mismatch WriteCode("</p>"); WriteText(PendingText); // double return } else { // suppress this one WriteText(PendingText); // double return skiptag = true; } PendingText = NULL; EndingPTag = false; } else if (IsPTag && !EndingPTag && !PendingText) { SkippedPTag = true; skiptag = true; } } char *shtag = NULL; char *futag = NULL; char *shend = NULL; char *tmptxt = NULL; if (PendingText) { tmptxt = PendingText + strlen(PendingText); while ((*(tmptxt - 1) == '\n') || (*(tmptxt - 1) == '\t')) { if (--tmptxt <= PendingText) break; } if (tmptxt > PendingText) { char ch = *tmptxt; *tmptxt = '\0'; WriteText(PendingText); PendingText = tmptxt; *tmptxt = ch; } // else write it later, after added end tags } if (DoFull && DoPara) { if (!WrappedText && (lastetype == 1) && (CurrEtype == 3)) { //block to inline WriteCode("<p>"); WrappedText = true; } else if (WrappedText && (CurrEtype == 1)) { WriteCode("</p>"); WrappedText = false; } } if (PendingText) // if writing end tag for short, keep \ns till after PendingText = WriteTextWithoutTrailingSpace(PendingText); while (DoFull && NestingLevel && ((shend = CurrShortEnd->find(CurrDepth)) != NULL) && CheckList(shend, name)) // end of CurrFull goes here WriteEndFullTag(); // close curr open tag if any if (PendingText) { // write \ns now WriteText(PendingText); PendingText = NULL; } CurrElems->add(name, CurrDepth + 1); CurrEtypes->add(CurrEtype, CurrDepth + 1); CurrDepth++; // NestingLevel of containers to check = depth of start tag // for each container type, list of sections to use char *stype = IniFile->GetVal("ShortTagContainers", name); if (stype) { // end tag at which to end last open short tag if (DoFull) { CurrStype->add(name, CurrDepth); if (IniFile->GetBool("udxFullTaggingOptions", "sConvert", stype)) { CurrSTR = IniFile->GetSect("ShortTagReplacement", stype); CurrSTE = IniFile->GetSect("ShortTagEnds", stype); Nesting->add(NestingLevel, CurrDepth); NestingLevel = CurrDepth; // use list as stack *** } } else if (DoMin) { CurrStype->add(name, CurrDepth); if (IniFile->GetBool("udxTagMinimizingOptions", "sToShortTagsConvert", stype)) { CurrLTR = IniFile->GetSect("LongTagReplacement", stype); Nesting->add(NestingLevel, CurrDepth); NestingLevel = CurrDepth; // use list as stack *** } } } if (NestingLevel) { if (DoFull) { shtag = (char *) CurrSTR->getitem(name); shend = (char *) CurrSTE->getitem(name); if (shtag) { // replace with full tag CurrShort->add(name, CurrDepth); // start tag before which to add end tag CurrShortEnd->add(shend, CurrDepth); CurrFull->add(shtag, CurrDepth); LastFullEndDepth = CurrDepth; name = shtag; } } else if (DoMin) { futag = (char *) CurrLTR->getitem(name); if (futag) { // replace with short tag CurrFull->add(name, CurrDepth); CurrShort->add(futag, CurrDepth); name = futag; ShortTag = true; } } } // check for wiki symbol tags if (DoMin && DoWiki && !attrs) { if (WriteWikiSym(name, true)) return; } if (skiptag) return; WriteStartTag(name, attrs, attrcnt); if (IsCodeTag(name)) InCode++; if (ShortTag) { // write end now WriteChar('/'); WriteChar('>'); ShortTag = false; } else EmptyTag = true; }
/* Check the Tag Details of this current game against those in * the wanted lists. Check all details apart from any ECO * tag as this is checked separately by CheckECOTag. * An empty list implies that there is no restriction on * the values in the corresponding tag field. * In consequence, completely empty lists imply that all * games reaching this far are wanted. * Return TRUE if wanted, FALSE otherwise. */ Boolean CheckTagDetailsNotECO(char *Details[],int num_details) { Boolean wanted = TRUE; int tag; if(GlobalState.check_tags){ /* Sanity check. */ if(num_details < tag_list_length){ fprintf(GlobalState.logfile, "Internal error: mismatch in tag set lengths in "); fprintf(GlobalState.logfile, "CheckTagDetailsNotECO: %d vs %d\n", num_details,tag_list_length); exit(1); } /* PSEUDO_PLAYER_TAG and PSEUDO_ELO_TAG are treated differently, * since they have the effect of or-ing together the WHITE_ and BLACK_ lists. * Otherwise, different tag lists are and-ed. */ if(TagLists[PSEUDO_PLAYER_TAG].num_used_elements != 0){ /* Check both the White and Black lists. */ if(Details[WHITE_TAG] != NULL){ wanted = CheckList(WHITE_TAG,Details[WHITE_TAG], &TagLists[PSEUDO_PLAYER_TAG]); /* If we didn't find a player there, try for the opponent. */ if(!wanted && (Details[BLACK_TAG] != NULL)){ wanted = CheckList(BLACK_TAG,Details[BLACK_TAG], &TagLists[PSEUDO_PLAYER_TAG]); } } else if(Details[BLACK_TAG] != NULL){ wanted = CheckList(BLACK_TAG,Details[BLACK_TAG], &TagLists[PSEUDO_PLAYER_TAG]); } else{ wanted = FALSE; } } else if(TagLists[PSEUDO_ELO_TAG].num_used_elements != 0){ /* Check both the White and Black lists. */ if(Details[WHITE_ELO_TAG] != NULL){ wanted = CheckElo(Details[WHITE_ELO_TAG], &TagLists[PSEUDO_ELO_TAG]); /* If we didn't find a player there, try for the opponent. */ if(!wanted && (Details[BLACK_ELO_TAG] != NULL)){ wanted = CheckElo(Details[BLACK_ELO_TAG], &TagLists[PSEUDO_ELO_TAG]); } } else if(Details[BLACK_ELO_TAG] != NULL){ wanted = CheckElo(Details[BLACK_ELO_TAG], &TagLists[PSEUDO_ELO_TAG]); } else{ wanted = FALSE; } } else{ /* No PSEUDO_*_TAG info to check. */ } /* Check the remaining tags in turn as long as we still have a match. */ for(tag = 0; (tag < tag_list_length) && wanted; tag++){ if(tag == PSEUDO_PLAYER_TAG){ } else if(tag == PSEUDO_ELO_TAG){ } else if(tag == ECO_TAG){ /* This is handled separately. */ } else if(TagLists[tag].num_used_elements != 0){ if(Details[tag] != NULL){ if(tag == DATE_TAG){ wanted = CheckDate(Details[tag],&TagLists[tag]); } else if((tag == WHITE_ELO_TAG) || (tag == BLACK_ELO_TAG)){ wanted = CheckElo(Details[tag],&TagLists[tag]); } else{ wanted = CheckList(tag,Details[tag],&TagLists[tag]); } } else{ /* Required tag not present. */ wanted = FALSE; } } else{ /* Not used. */ } } } return wanted; }
CmCError CheckSyntax(char *filename, CmCParser *synParser) { //***************************************** //parse the file //***************************************** int error; synParser->SetDelimiters("=(){},;'"); synParser->StoreDelimiters(true); error = synParser->Parse(filename); if(error) return (CmCError((CmCToken *) NULL, SYN_INVALID_FILE)); //***************************************** //check syntax //***************************************** int curveId; int parameterId; int commandTypeId, commandId; CmCToken *token, *(tokenSet)[MAX_TOKEN_NUM]; while(token = synParser->GetToken()) { //identify the command... commandId = Command(token->token_); commandTypeId = CommandType(commandId); //based on the command, identify the number of tokens //associated with it and obtain those tokens error = GetTokenSet(commandId, tokenSet, synParser); //if the specified number of tokens does not exist //then return an error if(error == SYN_ERROR) return CmCError((CmCToken *) NULL, error); //if the specified tokens exist, then check them for //their validity switch(commandTypeId) { case CMD_IO: switch(commandId) { case CMD_SAVE: //check structure if(strcmp(tokenSet[0]->token_, "(")) return CmCError(tokenSet[0], SYN_MISSING_LEFT_PARENTHESIS); if(strcmp(tokenSet[1]->token_, "'")) return CmCError(tokenSet[1],SYN_MISSING_QUOTATION); if(strcmp(tokenSet[3]->token_, "'")) return CmCError(tokenSet[3],SYN_MISSING_QUOTATION); if(strcmp(tokenSet[4]->token_, ",")) return CmCError(tokenSet[4],SYN_MISSING_COMMA); if(strcmp(tokenSet[6]->token_, ",")) return CmCError(tokenSet[6],SYN_MISSING_COMMA); if(strcmp(tokenSet[8]->token_, ")")) return CmCError(tokenSet[8],SYN_MISSING_RIGHT_PARENTHESIS); if(strcmp(tokenSet[9]->token_, ";")) return CmCError(tokenSet[9],SYN_MISSING_SEMICOLON); //check constants if(!validFileType(tokenSet[5]->token_)) return CmCError(tokenSet[5],SYN_INVALID_FILETYPE); if(!validOutputType(tokenSet[7]->token_))return CmCError(tokenSet[7],SYN_INVALID_OUTPUTTYPE); if(checkSupported(FileType(tokenSet[5]->token_))) return CmCError(tokenSet[5],SYN_UNSUPPORTED_FILETYPE); break; case CMD_LOAD: //check structure if(strcmp(tokenSet[0]->token_, "(")) return CmCError(tokenSet[0],SYN_MISSING_LEFT_PARENTHESIS); if(strcmp(tokenSet[1]->token_, "'")) return CmCError(tokenSet[1],SYN_MISSING_QUOTATION); if(strcmp(tokenSet[3]->token_, "'")) return CmCError(tokenSet[3],SYN_MISSING_QUOTATION); if(strcmp(tokenSet[4]->token_, ",")) return CmCError(tokenSet[4],SYN_MISSING_COMMA); if(strcmp(tokenSet[6]->token_, ")")) return CmCError(tokenSet[6],SYN_MISSING_RIGHT_PARENTHESIS); if(strcmp(tokenSet[7]->token_, ";")) return CmCError(tokenSet[7],SYN_MISSING_SEMICOLON); //check constants if(!validInputType(tokenSet[5]->token_)) return CmCError(tokenSet[5],SYN_INVALID_INPUTTYPE); break; case CMD_USE_RESULT: if(strcmp(tokenSet[0]->token_, "(")) return CmCError(tokenSet[0], SYN_MISSING_LEFT_PARENTHESIS); if(strcmp(tokenSet[2]->token_, ")")) return CmCError(tokenSet[2], SYN_MISSING_RIGHT_PARENTHESIS); if(strcmp(tokenSet[3]->token_, ";")) return CmCError(tokenSet[3], SYN_MISSING_SEMICOLON); if((OutputType(tokenSet[1]->token_) != OUTPUT_SEGM_IMAGE) && (OutputType(tokenSet[1]->token_) != OUTPUT_FILT_IMAGE)) { if(OutputType(tokenSet[1]->token_) != OUTPUT_UNKNOWN) { return CmCError(tokenSet[1], SYN_ASSIGN_INVALID_ARG); } else { return CmCError(tokenSet[1], SYN_INVALID_OUTPUTTYPE); } } break; } break; case CMD_EXECUTION: if(tokenSet[0]->token_[0] != ';') return CmCError(tokenSet[0],SYN_MISSING_SEMICOLON); break; case CMD_FLAGS: if(!validFlag(tokenSet[0]->token_)) return CmCError(tokenSet[0],SYN_INVALID_FLAG); if(tokenSet[1]->token_[0] != ';') return CmCError(tokenSet[1],SYN_MISSING_SEMICOLON); break; //unknown command default: break; } //if its not a command, then maybe its a parameter if(commandTypeId == UNKNOWN_COMMAND) { //get the parameter type parameterId = Parameter(token->token_); if(parameterId != UNKNOWN_PARAMETER) { //retreive tokens expected given a parameter error = GetParamTokenSet(tokenSet, synParser); if(error == SYN_ERROR) return CmCError(token, SYN_ERROR); //check those tokens for validity if(strcmp(tokenSet[0]->token_, "=")) return CmCError(tokenSet[0],SYN_MISSING_EQUALS); if(strcmp(tokenSet[2]->token_, ";")) return CmCError(tokenSet[2],SYN_MISSING_SEMICOLON); //make sure parameter is of the right type error = CheckParameter(parameterId, tokenSet[1]->token_); if(error) return CmCError(token, error); //if its an unknown parameter then maybe its a curve list } else { //get custom curve curveId = CustomCurve(token->token_); //if its not a custom curve list then flag an error if(curveId == UNKNOWN_CURVE) return CmCError(token,SYN_INVALID_PARAMCMD); //check for equals token = synParser->GetToken(); if(token->token_[0] != '=') return CmCError(token,SYN_MISSING_EQUALS); //if its a curve list, then check that a proper point list //is provided error = CheckList(synParser, &token); if(error) return CmCError(token, error); //check for semicolon token = synParser->GetToken(); if(token->token_[0] != ';') return CmCError(token,SYN_MISSING_SEMICOLON); } } //command/parameter identified and verified for //its validity, next command/parameter } //reset parser synParser->StartOver(); //file is syntaxically correct return CmCError((CmCToken *) NULL, NO_ERRORS); }
int main() { /* Label Main */ DWORD dw = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; //////////////////////////////////////////////////////////////////////////////////////// /* to test one of the controllers comment the "Label main" and un-commet the requested controller */ string list[5] = { "line 1", "line 2", "line 3", "line 4", "line 5" }; vector<string> list1 = { "line 1", "line 2", "line 3", "xxxxxxxxxx", "ff" }; /*Label l = Label(2, "Yossi gay 5"); l.SetBackground(BackgroundColor::White); l.SetForeground(ForegroundColor::Red); l.SetBorder(BorderType::None); l.Show();*/ //original ctor //CheckList controller = CheckList(list, 5, 5, 5, dw); //new ctor CheckList controller = CheckList(6, 15, list1); controller.SetForeground(ForegroundColor::White); controller.SetBackground(BackgroundColor::Green); controller.SetBorder(BorderType::Double); //controller.SelectIndex(2); //Sleep(1111); //controller.DeselectIndex(2); //controller.SetCoordinates(5, 5); controller.Show(); Sleep(2222); controller.Hide(); controller.AddSelectedItem("YOSSI GAY!"); //Sleep(1111); //controller.Hide(); Sleep(1111); controller.Show(); Sleep(1111); controller.Hide(); controller.RemoveSelectedItem("YOSSI GAY!"); Sleep(1111); controller.Show(); /*controller.SelectIndex(2); Sleep(1111); controller.SelectIndex(4);*/ //Sleep(1000); //controller.Hide(); vector<size_t> res = controller.GetSelectedIndices(); DWORD cNumRead, fdwMode, i; INPUT_RECORD irInBuf[128]; // Get the standard input handle. hStdin = GetStdHandle(STD_INPUT_HANDLE); if (hStdin == INVALID_HANDLE_VALUE) ErrorExit("GetStdHandle"); // Save the current input mode, to be restored on exit. if (!GetConsoleMode(hStdin, &fdwSaveOldMode)) ErrorExit("GetConsoleMode"); // Enable the window and mouse input events. fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT; if (!SetConsoleMode(hStdin, fdwMode)) ErrorExit("SetConsoleMode"); // Loop to read and handle the next 100 input events. while (true) { // Wait for the events. if (!ReadConsoleInput( hStdin, // input buffer handle irInBuf, // buffer to read into 128, // size of read buffer &cNumRead)) // number of records read ErrorExit("ReadConsoleInput"); // Dispatch the events to the appropriate handler. for (i = 0; i < cNumRead; i++) { //Send the input record to the textbox handler controller.HandleInput(irInBuf[i]); } } // Restore input mode on exit. SetConsoleMode(hStdin, fdwSaveOldMode); return 0; }
/*********************************************************************** * * * $FC Função: ProcessToEverywhere * * * * * ***********************************************************************/ void ProcessToEverywhere(Memory *Mmemory, ListOfProcesses *LBlock, ListOfProcesses *LReady, ListOfProcesses *LFinished, int fimExec){ /*Essa funcao devera ser usada logo depois da RunningProcess, pois esta foi implementada partindo da ideia que RunningProcess atualiza todos tempos de Execucao e IO dos processos em execucao e bloqueados. */ int indexMenor; int indexMaior; indexMenor = BuscaFHMR(Mmemory); indexMaior = BuscaMaiorOrdem(Mmemory); if ((CheckList(LReady) == -1 && CheckList(LBlock) == -1) || (CheckList(LReady) == -1 && CheckList(LBlock) == 1)){// Caso a Lista de Prontos esteja vazia e a Lista de Bloqueados esteja vazia OU pelo menos um processo.. if (Mmemory->LMemory->proc[indexMenor].TimeExec[0] == 0 && Mmemory->LMemory->proc[indexMenor].TimeIO[0] == 0){//Acabou tempo de Exec e IO -> Vai para Terminados LFinished->proc[LFinished->quantity] = Mmemory->LMemory->proc[indexMenor]; LFinished->quantity = LFinished->quantity + 1; Mmemory->LMemory->quantity = Mmemory->LMemory->quantity - 1; Mmemory->LMemory->proc[indexMenor].order = -1; } else if (Mmemory->LMemory->proc[indexMenor].TimeExec[0] > 0 && Mmemory->LMemory->proc[indexMenor].TimeIO[0] > 0){//SAI DA CPU, POREM NAO DA MEMORIA-> LOGO SE TIVER TIMEEXEC > 0 e TIMEIO > 0 , entra em IO.. if (fimExec == 0){ //se o valor de timeexec[0] for de outra execução vai pra BLOQUEADOS Mmemory->LMemory->proc[indexMenor].order = -1; Mmemory->LMemory->quantity = Mmemory->LMemory->quantity - 1; LBlock->proc[LBlock->quantity] = Mmemory->LMemory->proc[indexMenor]; LBlock->quantity = LBlock->quantity + 1; } else if (fimExec == 1){//se o valor de timeexec[0] for da mesma execução FICA NA MEMÓRIA Mmemory->LMemory->proc[indexMenor].order = (Mmemory->LMemory->proc[indexMaior].order) + 1; Mmemory->mOrder++; } } else{//Não tem mais tempo de IO, mas ainda tem tempo de Execucao continua na memoria, mas sai da execucao Mmemory->LMemory->proc[indexMenor].order = (Mmemory->LMemory->proc[indexMaior].order) + 1; Mmemory->mOrder++; } } else if ((CheckList(LReady) == 1 && CheckList(LBlock) == -1) || ((CheckList(LReady) == 1 && CheckList(LBlock) == 1))){//Caso a Lista de Prontos tenha pelo menos um elemento e a lista de bloqueado tambem.. if (Mmemory->LMemory->proc[indexMenor].TimeExec[0] == 0 && Mmemory->LMemory->proc[indexMenor].TimeIO[0] == 0){//SAI DA MEMORIA E DA CPU ->>>>Acabou tempo de Exec e IO -> Vai para Terminados LFinished->proc[LFinished->quantity] = Mmemory->LMemory->proc[indexMenor]; LFinished->quantity = LFinished->quantity + 1; Mmemory->LMemory->quantity = Mmemory->LMemory->quantity - 1; Mmemory->LMemory->proc[indexMenor].order = -1; } else if (Mmemory->LMemory->proc[indexMenor].TimeExec[0] > 0 && Mmemory->LMemory->proc[indexMenor].TimeIO[0] > 0){//SAIR DA CPU E DA MEMORIA, TEM PROCESSO PRA ENTRAR!-> LOGO SE TIVER TIMEEXEC > 0 e TIMEIO > 0 , entra em IO.. if (fimExec == 0){ LBlock->proc[LBlock->quantity] = Mmemory->LMemory->proc[indexMenor]; LBlock->quantity = LBlock->quantity + 1; Mmemory->LMemory->quantity = Mmemory->LMemory->quantity - 1; Mmemory->LMemory->proc[indexMenor].order = -1; } else if (fimExec == 1){ LReady->proc[LReady->quantity] = Mmemory->LMemory->proc[indexMenor]; LReady->quantity = LReady->quantity + 1; Mmemory->LMemory->proc[indexMenor].order = -1; Mmemory->LMemory->quantity = Mmemory->LMemory->quantity - 1; } } else{//Não tem mais tempo de IO, mas ainda tem tempo de Execucao continua na memoria, mas sai da execucao e da memoria , vai pra prontos!!! LReady->proc[LReady->quantity] = Mmemory->LMemory->proc[indexMenor]; LReady->quantity = LReady->quantity + 1; Mmemory->LMemory->quantity = Mmemory->LMemory->quantity - 1; Mmemory->LMemory->proc[indexMenor].order = -1; } } }