예제 #1
0
파일: ktb_list.c 프로젝트: Feechka/UOBP
static int
putCharacters (ListGenerationData *lgd, const wchar_t *characters, size_t count) {
  size_t newLength = lgd->lineLength + count;

  if (lgd->sectionTitle) {
    if (!handleLine(lgd, WS_C(""))) return 0;
    if (!handleLine(lgd, lgd->sectionTitle)) return 0;
    lgd->sectionTitle = NULL;
  }

  if (newLength > lgd->lineSize) {
    size_t newSize = (newLength | 0X3F) + 1;
    wchar_t *newCharacters = realloc(lgd->lineCharacters, ARRAY_SIZE(newCharacters, newSize));

    if (!newCharacters) {
      logSystemError("realloc");
      return 0;
    }

    lgd->lineCharacters = newCharacters;
    lgd->lineSize = newSize;
  }

  wmemcpy(&lgd->lineCharacters[lgd->lineLength], characters, count);
  lgd->lineLength = newLength;
  return 1;
}
예제 #2
0
void POExtractor::extract(const QString& filePath, FileMetaData& m)
{
    std::ifstream fstream(QFile::encodeName(filePath));
    if (!fstream.is_open()) {
        return;
    }

    state = WHITESPACE;
    messages = 0;
    untranslated = 0;
    fuzzy = 0;
    isFuzzy = false;
    isTranslated = false;

    std::string line;
    int lines = 0;
    while (std::getline(fstream, line)) {
        //TODO add a parsed text of translation units
        //QByteArray arr = QByteArray::fromRawData(line.c_str(), line.size());
        //result->append(QString::fromUtf8(arr));

        handleLine(line.c_str(), line.size());
        lines++;

        if (messages <= 1 && state == MSGSTR)
        {
            // handle special values in the first messsage
            // assumption is that value takes up only one line
            if (strncmp("\"POT-Creation-Date: ", line.c_str(), 20) == 0) {
                m.sourceDate=QByteArray(line.c_str() + 20, line.size() - 21 - 2 );
            } else if (strncmp("\"PO-Revision-Date: ", line.c_str(), 19) == 0) {
                m.translationDate=QByteArray(line.c_str() + 19, line.size() - 20 - 2);
            } else if (strncmp("\"Last-Translator: ", line.c_str(), 18) == 0) {
                m.lastTranslator=QString::fromUtf8(QByteArray::fromRawData(line.c_str() + 18, line.size() - 19 - 2));
            }
            fuzzy = 0;
        }
    }
    handleLine("", 0); //for files with non-empty last line
    messages--;//cause header does not count

/*
    result->add(Property::TranslationUnitsTotal, messages);
    result->add(Property::TranslationUnitsWithTranslation, messages-untranslated);
    result->add(Property::TranslationUnitsWithDraftTranslation, fuzzy);
    result->add(Property::LineCount, lines);
*/

    //TODO WordCount
    m.fuzzy      = fuzzy;
    m.translated = messages-untranslated-fuzzy;
    m.untranslated=untranslated;
    m.filePath = filePath;

    Q_ASSERT(messages>=0 && fuzzy>=0 && untranslated>=0);

    //TODO
    m.translated_approver=m.translated_reviewer=m.translated;
    m.fuzzy_approver=m.fuzzy_reviewer=m.fuzzy; 
}
예제 #3
0
//! \brief	Initializes the SoBkgCreditScroll for use
//!
//! \param a_This	this pointer
//! \param a_Bkg	background to use for display
//! \param a_LineCnt number of entries in a_Lines[]
//! \param a_Lines	command & text definitions for scrolling display
//!
void SoBkgCreditScrollInit(SoBkgCreditScroll *a_This, u16 a_Bkg, u16 a_LineCnt, const SoBkgCreditLine *a_Lines)
{
	u16 row;

	a_This->m_Bkg     = a_Bkg;
	a_This->m_LineCnt = a_LineCnt;
	a_This->m_Lines   = a_Lines;

	a_This->m_LineNum   = 0;
	a_This->m_ScrollPos = 0;
	a_This->m_LineArg   = 0;
	a_This->m_UpdSpeed  = 1;
	a_This->m_FrameCnt  = 0;

	SoBkgFill(a_This->m_Bkg, 0);

	// pre-load the screen
	row = 0;
	while(a_This->m_LineNum < a_LineCnt && row < (SO_SCREEN_HEIGHT-1)>>3)
	{
		// pause automatically stops copy
		if(a_This->m_Lines[a_This->m_LineNum].m_Code == SO_CREDIT_CODE_PAUSE)
			break;

		if(handleLine(a_This))
		{
			++row;
			a_This->m_ScrollPos += 8;
		}
	}
	SoBkgSetOffset(a_This->m_Bkg, 0, a_This->m_ScrollPos & 0xff);
}
예제 #4
0
파일: Config.c 프로젝트: punktniklas/NiKom
void readConfigFile(char *filename, int (*handleLine)(char *, BPTR)) {
  BPTR fh;
  char buffer[200], *tmp;
  int len;

  printf("Reading %s\n", filename);

  if(!(fh = Open(filename, MODE_OLDFILE))) {
    cleanup(EXIT_ERROR, "Could not open config file.");
  }

  for(;;) {
    if(!FGets(fh, buffer, 199)) {
      Close(fh);
      return;
    }
    if(buffer[0] == '#' || buffer[0] == '*') {
      continue;
    }
    if(IzSpace(buffer[0])) {
      for(tmp = buffer; *tmp != '\0' && IzSpace(*tmp); tmp++);
      if(*tmp == '\0') {
        continue; // The line is all white space
      }
    }
    len = strlen(buffer);
    if(buffer[len - 1] == '\n') {
      buffer[len - 1] = '\0';
    }
    if(!handleLine(buffer, fh)) {
      Close(fh);
      cleanup(EXIT_ERROR, "Invalid config file.");
    }
  }
}
예제 #5
0
int main(int argc, char* argv[])
{
    std::string line;

    std::string pid = argv[1];

    std::string proc_path = "maps";
    //std::string proc_path = "/proc/"+pid+"/maps";

    std::ifstream in(proc_path.c_str(), std::ifstream::in);

    if (!in)
    {
        std::cerr << "open '" << proc_path << "' failed!" << std::endl;
        return -1;
    }

    while (getline(in, line))
    {
        handleLine(line);
    }

    std::cout << "=====> totalLen: " 
              << std::dec << total_len << ":" << total_len/1024 << "K:0x" << std::hex << total_len 
              << "<===========" << std::endl;

    return 0;
}
예제 #6
0
bool CAssembler::assemble(QFile &in, QFile &out)
{
   QTextStream ins(&in);
   QString s;
   int line_number = 0;
   bool error = false;

   _currentPC = FIRST_ADDRESS;
   _firstPass = true;
   _assembledProgram.clear();


   while (!ins.atEnd())
   {
      s = ins.readLine();
      if (!handleLine(s, ++line_number))
	 error = true;
   }
   if (error)
   {
      std::cerr << (const char *) tr("assembly failed").toAscii() <<std::endl;
      return false;
   }

   // first pass has been done
   // lets done the second one so that all the labels are ok
   _firstPass = false;
   error = false;
   _currentPC = FIRST_ADDRESS;
   line_number = 0;
   _assembledProgram.clear();
   ins.seek(0);
   while (!ins.atEnd())
   {
      s = ins.readLine();
      if (!handleLine(s, ++line_number))
	 error = true;
   }
   if (error)
   {
      std::cerr << (const char *) tr("assembly failed in second pass... something weired happened").toAscii() << std::endl;
      return false;
   }
   out.write(_assembledProgram);
   return true;
}
예제 #7
0
파일: ktb_list.c 프로젝트: Feechka/UOBP
static int
endLine (ListGenerationData *lgd) {
  if (!putCharacter(lgd, 0)) return 0;
  if (!handleLine(lgd, lgd->lineCharacters)) return 0;

  lgd->lineLength = 0;
  return 1;
}
예제 #8
0
void CccModule::rls(const Frame8 *frame)
{
    uint32_t y;
    Qval eof(0, 0, 0, 0xffff);

    for (y=1; y<(uint32_t)frame->m_height; y+=2)
        handleLine(frame->m_pixels+y*frame->m_width, frame->m_width);

    // indicate end of frame
    m_qq->enqueue(&eof);
}
예제 #9
0
파일: Connection.cpp 프로젝트: ddddzzzz/mws
void Connection::parse(char *buffer, ssize_t len, ev::io &w) {
    ssize_t buffer_pos = 0;
    while (buffer_pos < len) {
        if (!isspace(buffer[buffer_pos])) {
            if (lastWordLen == BUFFER_SIZE - 1) {
                lastWord[BUFFER_SIZE-1] = '\0';
                log_file << "The word is too long: " << lastWord <<
                            buffer[buffer_pos] << std::endl;
                badRequest(w);
                return;
            }
            lastWord[lastWordLen++] = buffer[buffer_pos++];
        } else {
            if (lastWordLen) {
                lastWord[lastWordLen] = '\0';
                parseWord(w);
            }
            lastWordLen = 0;
            if (buffer[buffer_pos] == '\n') {
                buffer_pos++;
                handleLine(w);
                continue;
            } else if (buffer[buffer_pos] == '\r') {
                buffer_pos++;
                if (buffer_pos < len && buffer[buffer_pos] == '\n') {
                    buffer_pos++;
                }
                handleLine(w);
                continue;
            } else {
                while (buffer_pos < len &&
                       (buffer[buffer_pos] == ' ' || buffer[buffer_pos] == '\t')) {
                    buffer_pos++;
                }
            }
        }
    }
}
예제 #10
0
void Level::drawLevel()
{
	string line;
	map<int, string>::iterator iter;
	for(int y = 0; y <= lineCount; ++y)
	{
		iter = text.find(y);
		line = iter->second;
		handleLine(line, y);
	}
	pacman->cacheScreen();
	pacman->move();
	pacman->show();
}
예제 #11
0
  int
  BrepHandler::extractLine(const DirectoryEntry* de, const ParameterData& params)
  {
    point_t start, end;
    start[X] = params.getReal(1);
    start[Y] = params.getReal(2);
    start[Z] = params.getReal(3);
    end[X] = params.getReal(4);
    end[Y] = params.getReal(5);
    end[Z] = params.getReal(6);

    // probably need to transform this line?

    return handleLine(start, end);
  }
예제 #12
0
/*
* readFile - Read an inverted index in from file and
* construct a new index, i.e. the original.
* @index: Hashtable to reconstruct
* @filename: Name of file to construct from
*/
void readFile(HashTable* index, char* filename)
{
  FILE* fp;

  fp = fopen(filename, "r");
  ssize_t read;
  size_t len = 0;
  char* line = NULL;
  // Read each line and parse
  while ((read = getline(&line, &len, fp)) != -1) {
    handleLine(index, line);
    free(line);
    line = NULL;
  }
  fclose(fp);
}
예제 #13
0
//----------------------------------------------------------------------------
void Input::defaultKeys()
{
    static string bindings[] = { "PauseGame", "CritterBoard",
        "MotionLeft", "MotionRight",  "MotionUp",    "MotionDown", "HyperSpace",
        "PrimaryFire","SecondaryFire","TertiaryFire","MegaBomb",   "Rocket" };
    static string keys[] = {     "P",         "TAB",
        "LEFT",       "RIGHT",        "UP",          "DOWN",       "H",
        "SPACE",      "LALT",         "LCTRL",       "D",          "F" };

    for (unsigned int i=0; i<sizeof(keys)/sizeof(string); ++i)
    {
        unbindKeys(bindings[i]);
        string line = "bind " + bindings[i] + " " + keys[i];
        handleLine(line);
    }
}
예제 #14
0
void
CommandEventHandler::handleEvent(PRPollDesc desc)
{
  // Make sure we drain all the data we can from the socket.
  while (!closed())
  {
    if (checkDataEventHandler(desc))
      break;

    if (desc.fd != mBufSocket.fd())
      break;
    if (!(desc.out_flags & PR_POLL_READ))
      break;

    bool noMoreToRead = false;
    while (!closed() && !mDataEventHandler)
    {
      std::stringstream buf;
      PRUint32 numRead = mBufSocket.readLine(buf);
      if (!numRead)
      {
        noMoreToRead = true;
        break;
      }
      std::string line(trim(buf.str()));
      handleLine(line);
    }

    if (noMoreToRead)
      break;
  }

  if (mBufSocket.recvClosed())
  {
    if (mDataEventHandler)
    {
      delete mDataEventHandler;
      mDataEventHandler = NULL;
    }
    close();
  }
}
예제 #15
0
void TProcess::genericRead(QByteArray buffer) {

    remaining_output += buffer;

    const char* start = remaining_output.constData();
    const char* end = start + remaining_output.size();
    const char* pos = EOL(start, end);

    while (pos < end) {
        if (pos > start) {
            QString line = bytesToString(start, pos - start);
            handleLine(line);
        }
        start = pos + 1;
        pos = EOL(start, end);
    }

    remaining_output = remaining_output.mid(start
                                            - remaining_output.constData());
}
예제 #16
0
//! \brief	Updates the scrolling display
//!
//! \param a_This	this pointer
//!
//! This function processes the commands in the scrolling credit definition
//! structure.  It should be called once per frame.  Returns true as long as
//! there is more data to be processed.
//!
bool SoBkgCreditScrollUpdate(SoBkgCreditScroll *a_This)
{
	u16 oldBottom, newBottom;

	if(SoBkgCreditScrollDone(a_This))
		return false;

	// handle speed
	if(++a_This->m_FrameCnt < a_This->m_UpdSpeed)
		return true;
	a_This->m_FrameCnt = 0;

	// handle pauses
	if(a_This->m_Lines[a_This->m_LineNum].m_Code == SO_CREDIT_CODE_PAUSE)
	{
		if(!a_This->m_LineArg)
		{
			if(!(a_This->m_LineArg = (u16)(u32)a_This->m_Lines[a_This->m_LineNum].m_Data))
				++a_This->m_LineNum;	// handle 0-count pause
		}
		else if(!(--a_This->m_LineArg))
			++a_This->m_LineNum;
		return true;
	}

	// calculate screen change
	oldBottom = (a_This->m_ScrollPos + SO_SCREEN_HEIGHT - 1) >> 3;
	++a_This->m_ScrollPos;
	newBottom = (a_This->m_ScrollPos + SO_SCREEN_HEIGHT - 1) >> 3;

	// load up about-to-be-exposed tiles
	if(newBottom > oldBottom)
	{
		handleLine(a_This);
	}

	// update the display offset to show the newly loaded tiles
	SoBkgSetOffset(a_This->m_Bkg, 0, a_This->m_ScrollPos & 0xff);

	return true;
}
예제 #17
0
파일: ntest.c 프로젝트: BCI-AR/NeuroServer
static void testCommandHandler(void)
{
  struct CommandHandler *ch;
  gotUnknown = 0;
  gotParm = NULL;
  ch = newCommandHandler();
  newClientStarted(ch, 3);
  handleLine(ch, "what", 3);
  enregisterCommand(ch, "unknown", handleUnknown);
  enregisterCommand(ch, "print", handlePrint);
  rassert(gotUnknown == 0);
  handleLine(ch, "what", 3);
  rassert(gotUnknown == 1);
  handleLine(ch, "print 0", 3);
  rassert(gotParm != NULL);
  rassert(strcmp(gotParm, "0") == 0);
  rassert(gotInt == 0);
  handleLine(ch, "print \"\"", 3);
  rassert(strcmp(gotParm, "") == 0);
  rassert(gotInt == 0);
  handleLine(ch, "print \\\"", 3);
  rassert(strcmp(gotParm, "\"") == 0);
  rassert(gotInt == 0);
  handleLine(ch, "print 87", 3);
  rassert(gotInt == 87);
  rassert(strcmp(gotParm, "87") == 0);
  rassert(strcmp(gotParm, "87") == 0);
  handleLine(ch, "print \"45\"", 3);
  handleLine(ch, "print \"48\" ", 3);
  handleLine(ch, "print    \"14\" ", 3);
  handleLine(ch, "print   11  ", 3);
  handleLine(ch, "print \"hi\"", 3);
  handleLine(ch, "print \" hi\"", 3);
  handleLine(ch, "print \"h i\"", 3);
  handleLine(ch, "print \"hi \"", 3);
  handleLine(ch, "print \"h\\\\i\"", 3);
  handleLine(ch, "print \"h\\\"i\"", 3);
  freeCommandHandler(ch);
}
	void expectCompletedLine(string text) {
		EXPECT_CALL(handler, handleLine(StrEq(text))).InSequence(sequence);
	}
예제 #19
0
void POExtractor::handleLine(const char* data, uint32_t length)
{
    if (state == ERROR) return;
    if (state == WHITESPACE) {
        if (length == 0) return;
        if (data[0] != '#') {
            state = COMMENT; //this allows PO files w/o comments
        } else {
            handleComment(data, length);
            return;
        }
    }
    if (state == COMMENT) {
        if (length == 0) {
            state = WHITESPACE;
        } else if (data[0] == '#') {
            handleComment(data, length);
        } else if (length > 7 && strncmp("msgctxt", data, 7) == 0) {
            state = MSGCTXT;
        } else if (length > 7 && strncmp("msgid \"", data, 7) == 0) {
            state = MSGID;
        } else {
            state = ERROR;
        }
        return;
    } else if (length > 1 && data[0] == '"' && data[length-1] == '"'
            && (state == MSGCTXT || state == MSGID || state == MSGSTR
                || state == MSGID_PLURAL)) {
        // continued text field
        isTranslated = state == MSGSTR && length > 2;
    } else if (state == MSGCTXT
            && length > 7 && strncmp("msgid \"", data, 7) == 0) {
        state = MSGID;
    } else if (state == MSGID
            && length > 14 && strncmp("msgid_plural \"", data, 14) == 0) {
        state = MSGID_PLURAL;
    } else if ((state == MSGID || state == MSGID_PLURAL || state == MSGSTR)
            && length > 8 && strncmp("msgstr", data, 6) == 0) {
        state = MSGSTR;
        isTranslated = strncmp(data+length-3, " \"\"", 3) != 0;
    } else if (state == MSGSTR) {
        if (length == 0) {
            endMessage();
        } else if (data[0]=='#' || data[0]=='m') { //allow PO without empty line between entries
            endMessage();
            state = COMMENT;
            handleLine(data, length);
        } else {
            state = ERROR;
        }
    } else {
        state = ERROR;
    }
#if 0
    if (messages > 1 || state != MSGSTR) return;

    // handle special values in the first messsage
    // assumption is that value takes up only one line
    if (strncmp("\"POT-Creation-Date: ", data, 20) == 0) {
        result->add(Property::TranslationTemplateDate, QByteArray(data + 20, length - 21));
    } else if (strncmp("\"PO-Revision-Date: ", data, 19) == 0) {
        result->add(Property::TranslationLastUpDate, QByteArray(data + 19, length - 20));
    } else if (strncmp("\"Last-Translator: ", data, 18) == 0) {
        result->add(Property::TranslationLastAuthor, QByteArray(data + 18, length - 19));
    }
#endif
}