Esempio n. 1
0
int runOS(OS* opSys, SimpleTimer* sysTime){
    //variables
    pcbQueue readyQ;
    PCB running;
    insQueue q;
    char* elapTime;
    char* outBuff; 
    float f = 0.0;

    //constructions
    constructQueue(&q);
    constructPcbQueue(&readyQ, 10);
    alloStr(&elapTime, 10);
    alloStr(&outBuff, 50);

    stop(sysTime);

    getElapsedTime(&elapTime, sysTime);

    f += atof(elapTime);

    strcat(outBuff, elapTime);
    strcat(outBuff, " - Simulator Program Starting");

    outputHandler(opSys, outBuff);


    start(sysTime);
    //begin processing
    processmdf(opSys, &readyQ); 
    
    stop(sysTime);

    getElapsedTime(&elapTime, sysTime);

    f += atof(elapTime);

    start(sysTime);

    heapsort(opSys, &readyQ);

    while(pcbq_dequeue(&readyQ, &running))
       {
        runPCB(opSys, &running, &f);
       }

    stop(sysTime);

    getElapsedTime(&elapTime, sysTime);

    f += atof(elapTime);
    
    clearStr(&outBuff);
    strcat(outBuff, elapTime);
    strcat(outBuff, " - Simulator Program Ending");

    outputHandler(opSys, outBuff);
}
Esempio n. 2
0
int identifyKeywords () {
	FILE *fp;

	fp = fopen("input.tmp", "r");
	if (fp == NULL) {
		printf("Could not open input file.\n");
		return 1;
	}

	char str[1000];
	char c;
	int nextIsNew = true;
	while ((c = getc(fp)) != EOF) {
		if (nextIsNew) clearStr(str);
	
		int counter = 0;

		bool withinString = false;

		while (true) {
			char prevChar = '\0';
			if (c == '"') {
				while (true) {
					prevChar = c;
					c = getc(fp);
					if (c == '"' && prevChar != '\\') {
						break;
					} else {
						continue;
					}
				}
				break;
			}

			if (!isDigit(c) && !isAlpha(c) && c != '_') {
				break;
			} else {
				str[counter++] = c;
				c = getc(fp);
			}
		}

		if (isKeyword(str)) {
			printf("%s\n", str);
		}
	}

	fclose(fp);

	return 0;

}
Esempio n. 3
0
/**
 * \brief       Parse a buffer and generate a xPL_Message
 * \details	  Line based xPL parser
 * \param    _xPLMessage    the result xPL message
 * \param    _message         the buffer
 */
void xPL::Parse(xPL_Message* _xPLMessage, char* _buffer)
{
    int len = strlen(_buffer);

    byte j=0;
    byte line=0;
    int result=0;
    char lineBuffer[XPL_LINE_MESSAGE_BUFFER_MAX+1];

    // read each character of the message
    for(byte i = 0; i < len; i++)
    {
        // load byte by byte in 'line' buffer, until '\n' is detected
        if(_buffer[i] == XPL_END_OF_LINE) // is it a linefeed (ASCII: 10 decimal)
        {
            ++line;
            lineBuffer[j]='\0';	// add the end of string id

            if(line <= XPL_OPEN_SCHEMA)
            {
                // first part: header and schema determination
            	// we analyse the line, function of the line number in the xpl message
                result = AnalyseHeaderLine(_xPLMessage, lineBuffer ,line);
            }

            if(line > XPL_OPEN_SCHEMA)
            {
                // second part: command line
            	// we analyse the specific command line, function of the line number in the xpl message
                result = AnalyseCommandLine(_xPLMessage, lineBuffer, line-9, j);

                if(result == _xPLMessage->command_count+1)
                    break;
            }

            if (result < 0) break;

            j = 0; // reset the buffer pointer
            clearStr(lineBuffer); // clear the buffer
        }
        else
        {
            // next character
        	lineBuffer[j++] = _buffer[i];
        }
    }
}
/*!
    Adds all pending keyboard input to the internal buffer.   The
    implementation uses ReadConsoleInput() which is a non-blocking function.
    All non-keyboard events are ignored.
 */
void ConsoleInputBuffer::AddPendingInputToBuffer() {
  //
  // Read pending events
  //
  DWORD dwRead;
  INPUT_RECORD inRecords[128];
  ::ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &inRecords[0], 128, &dwRead);
  //
  // Process the events
  //
  for (unsigned int i = 0; i < dwRead; ++i) {
    if (inRecords[i].EventType == KEY_EVENT) {
      // Key events include non-character keys like SHIFT.  Filter
      // these out.
      const KEY_EVENT_RECORD& evt = inRecords[i].Event.KeyEvent;
      const char c = evt.uChar.AsciiChar;
      if (evt.bKeyDown) {
        if (c != 0) {
          // Unfortunately since keyboard input is being handled manually
          // behavior such as backspace needs to be manually emulated.
          if (c == '\b') {
            // Do not let the prompt be erased
            if (buffer_.empty())
              continue;

            // Emulate the default behavior by echoing the typed characters
            std::cout << c;

            HANDLE hStdOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
            CONSOLE_SCREEN_BUFFER_INFO info;
            DWORD dwWritten;
            ::GetConsoleScreenBufferInfo(hStdOut, &info);
            ::WriteConsoleOutputCharacter(hStdOut, L" ", 1,
                info.dwCursorPosition, &dwWritten);
            buffer_.pop_back(); // pop the last character
          } else {
            // Emulate the default behavior by echoing the typed characters
            std::cout << c;

            // Add to the buffer
            buffer_ += c;
          }
        } else if (evt.wVirtualKeyCode == VK_UP ||
                   evt.wVirtualKeyCode == VK_DOWN) {
          // Move up/down the history
          bool up = (evt.wVirtualKeyCode == VK_UP);
          if (up) {
            if (history_index_ == 0)
              history_index_ = history_.size();
            else
              --history_index_;
          } else {
            if (history_index_ >= history_.size())
              history_index_ = 0;
            else
              ++history_index_;
          }
          std::string new_command;
          if (history_index_ < history_.size())
            new_command = history_[history_index_];
          // else empty string
          
          HANDLE hStdOut = ::GetStdHandle(STD_OUTPUT_HANDLE);
          CONSOLE_SCREEN_BUFFER_INFO info;
          ::GetConsoleScreenBufferInfo(hStdOut, &info);
          // Clear first
          std::wstring clearStr(buffer_.size(), L' ');
          COORD pos = info.dwCursorPosition;
          pos.X -= static_cast<short>(clearStr.size());
          DWORD dwWritten;
          ::WriteConsoleOutputCharacter(hStdOut, clearStr.c_str(),
                                        static_cast<DWORD>(clearStr.size()),
                                        pos, &dwWritten);
          // Set cursor to the beginning
          SetConsoleCursorPosition(hStdOut, pos);
          // Write the new line
          std::cout << new_command;
          buffer_ = new_command;
        }
      }
    }
  }
}