Esempio n. 1
0
void IrcSessionPrivate::_q_readData()
{
    buffer += socket->readAll();
    // try reading RFC compliant message lines first
    readLines("\r\n");
    // fall back to RFC incompliant lines...
    readLines("\n");
}
Esempio n. 2
0
void
do_ed(int argc, const char ** argv)
{
	if (!initEdit())
		return;

	if (argc > 1)
	{
		fileName = strdup(argv[1]);

		if (fileName == NULL)
		{
			fprintf(stderr, "No memory\n");
			termEdit();

			return;
		}

		if (!readLines(fileName, 1))
		{
			termEdit();

			return;
		}

		if (lastNum)
			setCurNum(1);

		dirty = FALSE;
	}

	doCommands();

	termEdit();
}
Esempio n. 3
0
int ed_main(int argc, char **argv)
{
	if (!initEdit())
		return EXIT_FAILURE;

	if (argc > 1) {
		fileName = strdup(argv[1]);

		if (fileName == NULL) {
			bb_error_msg("no memory");
			termEdit();
			return EXIT_SUCCESS;
		}

		if (!readLines(fileName, 1)) {
			termEdit();
			return EXIT_SUCCESS;
		}

		if (lastNum)
			setCurNum(1);

		dirty = FALSE;
	}

	doCommands();

	termEdit();
	return EXIT_SUCCESS;
}
int main(int argc, char ** argv){
	char * x[MAX_LINES];
	int lines = readLines(x, MAX_LINES);
	printf("\nprintout the input:\n");
	qsort(x,0,lines-1);
	printLines(x,lines);
}
Esempio n. 5
0
int TFileSource::next_tau_e()
{
  ++cl;
  d0 = d1; t0 = t1;

  if( cl >= ncl ) {
    readLines( greed );
  }
  if( ncl < 1 ) {
    d1 = d0; t1 = tau_e = 1e100;
    d_c.reset();
    return 0;
  }


  d1 = pv[cl];
  if( time_col >=0 && time_col < max_col ) {
    t1 = d1.v[time_col];
    tau_e = t1 - t0;
  } else {
    t1 += tau_e;
  }

  // qDebug() << "Next: cl= " << cl << " t0= " << t0 << " t1=" << t1 << NWHE;

  for( int i=0; i<rnc; ++i ) { // may be not need in 'step' case
    d_c.v[i] = ( d1.v[i] - d0.v[i] ) / tau_e;
  }

  return 1;
}
Esempio n. 6
0
void parseFile(char* filename) {
    char**      array    = NULL;    /* Array of read lines */
    FILE*       file     = NULL;    /* File to read lines from */
    int         i;                  /* Loop index */
    int         line_count;         /* Total number of read lines */

    file = fopen(filename, "rt");
    if (file == NULL) {
        printf("Can't open file %s.\n", filename);
    }

    /* Read lines from file. */
    array = readLines(file, &line_count);

    double test;
    test = getKeyDouble   ("Run", 50, array);
    printf("%lf", test);

    /* Just for test, print out the read lines. */
    for (i = 0; i < line_count; i++) {
        printf("[%d]:\t %s\n", (i+1), array[i]);
    }

    /* Cleanup. */
    fclose(file);
    for (i = 0; i < line_count; i++) {
        free(array[i]);
    }
    free(array);
    array = NULL;
}
Esempio n. 7
0
void generateKwic(std::istream &in, std::ostream &out)
{
	std::vector<std::vector<Word>> lines {readLines(in)};
	std::vector<std::vector<Word>> preparedLines {prepareLines(lines)};

	printLines(preparedLines, out);
}
int main(int argc, char** argv) {
  init(argc, argv);
  std::string index_tracks_file = argv[1];
  std::string features_format = argv[2];
  std::string views_file = argv[3];
  // TODO: Use number of frames instead of reading until failure.
  //int num_frames = boost::lexical_cast<int>(argv[4]);
  std::string feature_tracks_file = argv[5];

  // Load names of views.
  std::vector<std::string> views;
  bool ok = readLines(views_file, views);

  MultiviewTrackList<IndexSet> index_multitracks;

  if (FLAGS_input_multitracks) {
    // Load multi-tracks from file.
    DefaultReader<int> index_reader;
    VectorReader<int> reader(index_reader);
    ok = loadMultiviewTrackList(index_tracks_file, index_multitracks, reader);
    CHECK(ok) << "Could not load multi-tracks";
  } else {
    // Load tracks from file.
    MultiviewTrackList<int> tracks;
    DefaultReader<int> reader;
    ok = loadMultiviewTrackList(index_tracks_file, tracks, reader);
    CHECK(ok) << "Could not load tracks";

    // Convert to multitracks.
    tracksToMultitracks(tracks, index_multitracks);
  }

  MultiviewTrackList<FeatureSet> multitracks;

  // Convert to multitracks of features for reconstructing/visualizing.
  if (FLAGS_input_keypoints) {
    ok = loadKeypoints(index_multitracks, features_format, views, multitracks);
    CHECK(ok) << "Could not load keypoints";
  } else {
    ok = loadTracks(index_multitracks, features_format, views, multitracks);
    CHECK(ok) << "Could not load feature tracks";
  }

  if (!FLAGS_input_multitracks && FLAGS_input_keypoints) {
    // If we input valid tracks and used keypoints not tracks,
    // then we can write out valid tracks.
    MultiviewTrackList<SiftPosition> tracks;
    multitracksToTracks(multitracks, tracks);

    SiftPositionWriter writer;
    saveMultiviewTrackList(feature_tracks_file, tracks, writer);
  } else {
    // Save multitracks.
    SiftPositionWriter feature_writer;
    VectorWriter<SiftPosition> writer(feature_writer);
    saveMultiviewTrackList(feature_tracks_file, multitracks, writer);
  }

  return 0;
}
Esempio n. 9
0
TEST_F(LogTest, create_and_write) {
    AgentServerLog *logger = new AgentServerLog(log_file_name);

    // Enable
    logger->enable();
    EXPECT_EQ(2, readLines(log_file_name));

    // Normal message
    logger->log("Print first line");
    EXPECT_EQ(3, readLines(log_file_name));

    // With filter - matching
    logger->logfilter("Print second line", "line");
    EXPECT_EQ(4, readLines(log_file_name));

    // With filter - not matching
    logger->logfilter("Do not print third line", "lineX");
    EXPECT_EQ(4, readLines(log_file_name));

    // Raw message
    logger->log("Print fourth raw line", true);
    EXPECT_EQ(5, readLines(log_file_name));

    // Disable
    logger->disable();
    EXPECT_EQ(7, readLines(log_file_name));

    // Normal message
    logger->log("Do not print fifth line");
    EXPECT_EQ(7, readLines(log_file_name));

    delete logger;
}
Esempio n. 10
0
// main function
int main(int argc, char* argv[]) {
  // read lines from standard input
  char** lines = readLines();

  // execute each command on the command line
  executeCommands(lines, map, argv+1);

  // exit with "success"
  return EXIT_SUCCESS;
}
Esempio n. 11
0
//========================================================================
bool NDLocalXmlString::LoadLoginString()
{
	string strFile = NDEngine::NDPath::GetResPath("Login.strings");
	vector<string> vecLines;
	if (readLines( strFile, vecLines ) )
	{
		parseLines( vecLines );
		return true;
	}
	return false;
}
void
ColladaGeometry::readMesh(domMesh *mesh)
{
    readSources(mesh->getSource_array());

    const domLines_Array &linesArray = mesh->getLines_array();

    for(UInt32 i = 0; i < linesArray.getCount(); ++i)
    {
        readLines(mesh, linesArray[i]);
    }

    const domLinestrips_Array &lineStripsArray = mesh->getLinestrips_array();

    for(UInt32 i = 0; i < lineStripsArray.getCount(); ++i)
    {
        readLineStrips(mesh, lineStripsArray[i]);
    }

    const domPolygons_Array &polygonsArray = mesh->getPolygons_array();

    for(UInt32 i = 0; i < polygonsArray.getCount(); ++i)
    {
        readPolygons(mesh, polygonsArray[i]);
    }
    const domPolylist_Array &polyListArray = mesh->getPolylist_array();

    for(UInt32 i = 0; i < polyListArray.getCount(); ++i)
    {
        readPolyList(mesh, polyListArray[i]);
    }

    const domTriangles_Array &triArray = mesh->getTriangles_array();

    for(UInt32 i = 0; i < triArray.getCount(); ++i)
    {
        readTriangles(mesh, triArray[i]);
    }

    const domTrifans_Array &triFansArray = mesh->getTrifans_array();

    for(UInt32 i = 0; i < triFansArray.getCount(); ++i)
    {
        readTriFans(mesh, triFansArray[i]);
    }

    const domTristrips_Array &triStripsArray = mesh->getTristrips_array();

    for(UInt32 i = 0; i < triStripsArray.getCount(); ++i)
    {
        readTriStrips(mesh, triStripsArray[i]);
    }
}
Esempio n. 13
0
TEST_F(LogTest, create_default_file) {
    AgentServerLog *logger = new AgentServerLog();

    // Enable
    logger->enable();
    EXPECT_EQ(2, readLines(AGENTSERVER_LOGFILE));

    // delete file
    std::remove(AGENTSERVER_LOGFILE);

    delete logger;
}
Esempio n. 14
0
int TFileSource::do_startLoop( int /*acnx*/, int /*acny*/ )
{
  if( asProc.cval() ) {
    p_fi = popen( filename.c_str(), "r" );
    if( ! p_fi ) {
      qWarning() << "Fail to start program " << filename << NWHE;
      return 0;
    }
    if( ! file.open( p_fi, QIODevice::ReadOnly | QIODevice::Text ) ) {
      qWarning() << "Fail to open data stream " << filename << NWHE;
      return 0;
    }

  } else {
    if( ! file.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
      qWarning() << "Fail to open data file " << file.fileName() << NWHE;
      return 0;
    }
  }

  wasEOF = false;
  n_ofs = ncl = cl = 0;
  int rl_first = ( greed > 1 ) ? greed : 2;
  readLines( rl_first );
  if( ncl < 1 ) {
    qWarning() << "No data found in file " << filename << NWHE;
    return 0;
  }

  // qDebug() << "Start: ncl= " << ncl << NWHE;

  d0 = pv[0]; t0 = 0;
  if( ncl > 1 ) {
    d1 = pv[1];
    if( time_col >=0 ) {
      t1 = d1.v[time_col]; tau_e = t1 - t0;
    } else {
      t1 = t0 + tau_e;
    }
  } else {   // degenerated case -- the only line
    d1 = d0; t1 = tau_e = 1e100;
  }

  for( int i=0; i<rnc; ++i ) { // may be not need in 'step' case
    d_c.v[i] = ( d1.v[i] - d0.v[i] ) / tau_e;
  }
  return 1;
}
Esempio n. 15
0
int main(int argc, char **argv)
{
	autoList_t *paths = readLines(FOUNDLISTFILE);
	char *path;
	uint index;
	char *outDir = makeFreeDir();

	foreach(paths, path, index)
	{
		char *outPath = toCreatablePath(combine(outDir, getLocal(path)), getCount(paths) + 10);

		cout("< %s\n", path);
		cout("> %s\n", outPath);

		copyPath(path, outPath);
		memFree(outPath);
	}
Esempio n. 16
0
void FieldDimensions::load()
{
  int* const valuesInt[]={
    &xPosOpponentFieldBorder, &xPosOpponentGoal, &xPosOpponentGoalpost,
    &xPosOpponentGroundline, &xPosOpponentSideCorner, &xPosOpponentPenaltyArea, &xPosHalfWayLine,
    &xPosOwnPenaltyArea, &xPosOwnSideCorner, &xPosOwnGroundline, &xPosOwnGoalpost,
    &xPosOwnGoal, &xPosOwnFieldBorder,
    &yPosLeftFieldBorder, &yPosLeftSideline, &yPosLeftGroundline,
    &yPosLeftPenaltyArea, &yPosLeftGoal, &yPosCenterGoal, &yPosRightGoal,
    &yPosRightPenaltyArea, &yPosRightGroundline, &yPosRightSideline, &yPosRightFieldBorder,
    &centerCircleRadius, &goalHeight, &fieldLinesWidth, &goalPostRadius, 
    &xPosThrowInPointOpponentHalf, &xPosThrowInPointCenter, 
    &xPosThrowInPointOwnHalf, &ballRadius, &ballFriction
  };
  const char* const namesInt[]={
    "xPosOpponentFieldBorder", "xPosOpponentGoal", "xPosOpponentGoalpost",
    "xPosOpponentGroundline", "xPosOpponentSideCorner", "xPosOpponentPenaltyArea", "xPosHalfWayLine",
    "xPosOwnPenaltyArea", "xPosOwnSideCorner", "xPosOwnGroundline", "xPosOwnGoalpost",
    "xPosOwnGoal", "xPosOwnFieldBorder",
    "yPosLeftFieldBorder", "yPosLeftSideline", "yPosLeftGroundline",
    "yPosLeftPenaltyArea", "yPosLeftGoal", "yPosCenterGoal", "yPosRightGoal",
    "yPosRightPenaltyArea", "yPosRightGroundline", "yPosRightSideline", "yPosRightFieldBorder",
    "centerCircleRadius",
    "goalHeight", "fieldLinesWidth", "goalPostRadius",
    "xPosThrowInPointOpponentHalf", "xPosThrowInPointCenter", 
    "xPosThrowInPointOwnHalf", "ballRadius", "ballFriction"
  };

  const int numOfValuesInt = sizeof(valuesInt)/sizeof(int*);
  ASSERT(sizeof(namesInt)/sizeof(char*) == numOfValuesInt);

  bool initializedInt[numOfValuesInt];

  for (int i = 0; i < numOfValuesInt; initializedInt[i++] = false);

  readDimensions(valuesInt, namesInt, initializedInt, numOfValuesInt);
  readLines(valuesInt, namesInt, initializedInt, numOfValuesInt);
  readCorners(valuesInt, namesInt, initializedInt, numOfValuesInt);

  add(Vector2<double>(xPosOpponentFieldBorder,yPosLeftFieldBorder));
  add(Vector2<double>(xPosOwnFieldBorder,yPosRightFieldBorder));
}
Esempio n. 17
0
int main(void)
{
	if( (lines = readLines(nLinesData)) <= MAXLINES)
	{
		printf("The original:\n");
		printLines(nLinesData);

		sort(nLinesData);

		printf("The result:\n");
		printLines(nLinesData);

		return 0;
	}
	else
	{
		printf("error Too many lines input.\n");
		return 1;
	}
}
Esempio n. 18
0
void MainWindow::on_goButton_clicked()
{
    linecount=0;
    //create output file
    qint64 linecountPos; //position to write linecount to
    outFileName = songName+".PTB";
    QFile outputFile(outFileName);
    if (outputFile.open(QIODevice::ReadWrite)) {
        stream.setDevice(&outputFile);
        stream << tempo << endl;
        linecountPos = stream.pos();
        stream <<  "     " << endl;
        linecount+=2;
    }


    //Find beginning of tabs
    QFile parseFile(fileName);
    parseFile.open(QIODevice::ReadOnly);
    parseIn.setDevice(&parseFile);


    //start parse
    while(!doneParsing){

        readLines();
        int count = 0;

        while(count<noteLengthLine.length()){
            parseColumn(count);
            count++;
        }
    }
    qint64 endfile = stream.pos();
    stream.seek(linecountPos);
    stream << linecount;
    outputFile.resize(endfile-2);
    outputFile.close();
    parseFile.close();

}
Esempio n. 19
0
QImage Rotater::RotateWithCornerFilling(const QImage image)
{
    QImage destImage = QImage( image);
    QImage origImage = QImage( image);

    vector<Form> lines;

    readLines(destImage, &lines);
//    m_line_detector->print(lines, LineFacts, -1);

    for (int quater=1; quater<=4; quater++)
    {
        get_shift_values(quater, lines.at(quater-1));
//        if (quater != 1) continue;
//        destImage = markOnImage( destImage, m_dx[0], m_dy[0], 1); // TEST
//        destImage = markOnImage( destImage, m_dx[5], m_dy[5], 0); // TEST
    }
    destImage = shiftImage( destImage);

    destImage = RotateImage( destImage, origImage);

    return destImage;
}
Esempio n. 20
0
int ed_main(int argc UNUSED_PARAM, char **argv)
{
	INIT_G();

	bufSize = INITBUF_SIZE;
	bufBase = xmalloc(bufSize);
	bufPtr = bufBase;
	lines.next = &lines;
	lines.prev = &lines;

	if (argv[1]) {
		fileName = xstrdup(argv[1]);
		if (!readLines(fileName, 1)) {
			return EXIT_SUCCESS;
		}
		if (lastNum)
			setCurNum(1);
		dirty = FALSE;
	}

	doCommands();
	return EXIT_SUCCESS;
}
Esempio n. 21
0
static void AddModule(char *module)
{
	char *projFile;
	char *srcFile;
	char *hdrFile;
	autoList_t *lines;
	char *line;
	uint index;

	errorCase(!lineExp("<__09AZaz>", module));

	projFile = GetProjFile();
	srcFile = changeExt(module, "cpp");
	hdrFile = changeExt(module, "h");

	errorCase(existPath(srcFile));
	errorCase(existPath(hdrFile));

	lines = readLines(projFile);

	index = FindIndex(lines, 0, "<\t\t  >Name=\"ソース ファイル\"");
	index = FindIndex(lines, index + 1, "<\t\t  >>");
	insertElement(lines, index + 1, (uint)xcout("<File RelativePath=\".\\%s\"></File>", srcFile));

	index = FindIndex(lines, 0, "<\t\t  >Name=\"ヘッダー ファイル\"");
	index = FindIndex(lines, index + 1, "<\t\t  >>");
	insertElement(lines, index + 1, (uint)xcout("<File RelativePath=\".\\%s\"></File>", hdrFile));

	writeLines_xx(projFile, lines);
	addLine2File_cx("all.h", xcout("#include \"%s\"", hdrFile));
	writeOneLine(srcFile, "#include \"all.h\"");
	createFile(hdrFile); // "all" ならここで all.h は空のファイルになる。

	memFree(srcFile);
	memFree(hdrFile);
}
void LineAssembler::push_chunk(QString input){
    QByteArray array(input.toStdString().c_str());
    raw->push_back(array);
    readLines();
}
Esempio n. 23
0
/*
	srcFile
		読み込み元ファイル

	destFile
		出力先ファイル
		srcFile と同じパスであっても良い。

	textMode
		真のとき -> テキストモード
		偽のとき -> バイナリーモード

	uint readElement(FILE *fp)
		1レコード読み込む。
		これ以上レコードが無いときは 0 を返すこと。

	void writeElement_x(FILE *fp, uint element)
		1レコード書き込む。
		必要であれば element を開放すること。

	sint compElement(uint element1, uint element2)
		element1 と element2 を比較した結果を strcmp() 的に返す。

	partSize
		メモリに一度期に読み込める「レコードの合計バイト数」の最大値の目安
		srcFile のシーク位置の変化をバイトに換算しているだけ。
		0 のときは常に1レコードずつになる。
		各パートのレコード数が partSize / 100 を超えないようにする。
*/
void MergeSort(
	char *srcFile,
	char *destFile,
	int textMode,
	uint (*readElement)(FILE *fp),
	void (*writeElement_x)(FILE *fp, uint element),
	sint (*compElement)(uint element1, uint element2),
	uint partSize
	)
{
	autoList_t *partFiles = newList();
	autoList_t *elements = NULL;
	char *rMode;
	char *wMode;
	FILE *fp;
	uint64 startPos = 0;

	if(textMode)
	{
		rMode = "rt";
		wMode = "wt";
	}
	else
	{
		rMode = "rb";
		wMode = "wb";
	}
	fp = fileOpen(srcFile, rMode);

	for(; ; )
	{
		uint element = readElement(fp);
		uint64 currPos;

		if(!element)
			break;

		if(!elements)
			elements = createAutoList(partSize / 100 + 1);

		addElement(elements, element);

		currPos = _ftelli64(fp);
		errorCase(currPos < 0);

		if(startPos + partSize <= currPos || partSize / 100 < getCount(elements))
		{
			CommitPart(partFiles, wMode, writeElement_x, compElement, elements);
			elements = NULL;
			startPos = currPos;

			// メモリのデフラグ?
			{
				char *wkFile = makeTempPath("work");

				writeLines_cx(wkFile, partFiles);
				partFiles = readLines(wkFile);

				removeFile(wkFile);
				memFree(wkFile);
			}
		}
	}
	if(elements)
		CommitPart(partFiles, wMode, writeElement_x, compElement, elements);

	fileClose(fp);

	while(2 < getCount(partFiles))
	{
		char *partFile1 = (char *)unaddElement(partFiles);
		char *partFile2 = (char *)unaddElement(partFiles);
		char *partFile3 = makeTempPath("part");

		MergePart(partFile1, partFile2, partFile3, rMode, wMode, readElement, writeElement_x, compElement);

		memFree(partFile1);
		memFree(partFile2);

		insertElement(partFiles, 0, (uint)partFile3);
	}
	switch(getCount(partFiles))
	{
	case 2:
		MergePart(getLine(partFiles, 0), getLine(partFiles, 1), destFile, rMode, wMode, readElement, writeElement_x, compElement);
		break;

	case 1:
		removeFileIfExist(destFile);
		moveFile(getLine(partFiles, 0), destFile);
		break;

	case 0:
		createFile(destFile);
		break;

	default:
		error();
	}
	releaseDim(partFiles, 1);
}
Esempio n. 24
0
/*
 * Read commands until we are told to stop.
 */
static void doCommands(void)
{
	const char *cp;
	char *endbuf, buf[USERSIZE];
	int len, num1, num2;
	smallint have1, have2;

	while (TRUE) {
		/* Returns:
		 * -1 on read errors or EOF, or on bare Ctrl-D.
		 * 0  on ctrl-C,
		 * >0 length of input string, including terminating '\n'
		 */
		len = read_line_input(NULL, ": ", buf, sizeof(buf), /*timeout*/ -1);
		if (len <= 0)
			return;
		endbuf = &buf[len - 1];
		while ((endbuf > buf) && isblank(endbuf[-1]))
			endbuf--;
		*endbuf = '\0';

		cp = skip_blank(buf);
		have1 = FALSE;
		have2 = FALSE;

		if ((curNum == 0) && (lastNum > 0)) {
			curNum = 1;
			curLine = lines.next;
		}

		if (!getNum(&cp, &have1, &num1))
			continue;

		cp = skip_blank(cp);

		if (*cp == ',') {
			cp++;
			if (!getNum(&cp, &have2, &num2))
				continue;
			if (!have1)
				num1 = 1;
			if (!have2)
				num2 = lastNum;
			have1 = TRUE;
			have2 = TRUE;
		}
		if (!have1)
			num1 = curNum;
		if (!have2)
			num2 = num1;

		switch (*cp++) {
		case 'a':
			addLines(num1 + 1);
			break;

		case 'c':
			deleteLines(num1, num2);
			addLines(num1);
			break;

		case 'd':
			deleteLines(num1, num2);
			break;

		case 'f':
			if (*cp && !isblank(*cp)) {
				bb_error_msg("bad file command");
				break;
			}
			cp = skip_blank(cp);
			if (*cp == '\0') {
				if (fileName)
					printf("\"%s\"\n", fileName);
				else
					puts("No file name");
				break;
			}
			free(fileName);
			fileName = xstrdup(cp);
			break;

		case 'i':
			addLines(num1);
			break;

		case 'k':
			cp = skip_blank(cp);
			if ((*cp < 'a') || (*cp > 'z') || cp[1]) {
				bb_error_msg("bad mark name");
				break;
			}
			marks[*cp - 'a'] = num2;
			break;

		case 'l':
			printLines(num1, num2, TRUE);
			break;

		case 'p':
			printLines(num1, num2, FALSE);
			break;

		case 'q':
			cp = skip_blank(cp);
			if (have1 || *cp) {
				bb_error_msg("bad quit command");
				break;
			}
			if (!dirty)
				return;
			len = read_line_input(NULL, "Really quit? ", buf, 16, /*timeout*/ -1);
			/* read error/EOF - no way to continue */
			if (len < 0)
				return;
			cp = skip_blank(buf);
			if ((*cp | 0x20) == 'y') /* Y or y */
				return;
			break;

		case 'r':
			if (*cp && !isblank(*cp)) {
				bb_error_msg("bad read command");
				break;
			}
			cp = skip_blank(cp);
			if (*cp == '\0') {
				bb_error_msg("no file name");
				break;
			}
			if (!have1)
				num1 = lastNum;
			if (readLines(cp, num1 + 1))
				break;
			if (fileName == NULL)
				fileName = xstrdup(cp);
			break;

		case 's':
			subCommand(cp, num1, num2);
			break;

		case 'w':
			if (*cp && !isblank(*cp)) {
				bb_error_msg("bad write command");
				break;
			}
			cp = skip_blank(cp);
			if (!have1) {
				num1 = 1;
				num2 = lastNum;
			}
			if (*cp == '\0')
				cp = fileName;
			if (cp == NULL) {
				bb_error_msg("no file name specified");
				break;
			}
			writeLines(cp, num1, num2);
			break;

		case 'z':
			switch (*cp) {
			case '-':
				printLines(curNum - 21, curNum, FALSE);
				break;
			case '.':
				printLines(curNum - 11, curNum + 10, FALSE);
				break;
			default:
				printLines(curNum, curNum + 21, FALSE);
				break;
			}
			break;

		case '.':
			if (have1) {
				bb_error_msg("no arguments allowed");
				break;
			}
			printLines(curNum, curNum, FALSE);
			break;

		case '-':
			if (setCurNum(curNum - 1))
				printLines(curNum, curNum, FALSE);
			break;

		case '=':
			printf("%d\n", num1);
			break;
		case '\0':
			if (have1) {
				printLines(num2, num2, FALSE);
				break;
			}
			if (setCurNum(curNum + 1))
				printLines(curNum, curNum, FALSE);
			break;

		default:
			bb_error_msg("unimplemented command");
			break;
		}
	}
}
int main(int argc, char** argv) {
  init(argc, argv);

  std::string descriptor_tracks_file = argv[1];
  std::string image_format = argv[2];
  std::string fund_mat_format = argv[3];
  std::string intrinsics_format = argv[4];
  std::string views_file = argv[5];
  int view1 = boost::lexical_cast<int>(argv[6]);
  int time = boost::lexical_cast<int>(argv[7]);
  std::string examples_file = argv[8];

  // Load descriptors tracks.
  TrackList<SiftFeature> features;
  SiftFeatureReader feature_reader;
  bool ok = loadTrackList(descriptor_tracks_file, features, feature_reader);
  CHECK(ok) << "Could not load descriptor tracks";
  LOG(INFO) << "Loaded " << features.size() << " features";

  // Load names of views.
  std::vector<std::string> view_names;
  ok = readLines(views_file, view_names);
  CHECK(ok) << "Could not load view names";
  int num_views = view_names.size();

  // Load intrinsics for main camera.
  CameraProperties camera1;
  std::string camera_file1 = makeViewFilename(intrinsics_format,
      view_names[view1]);
  CameraPropertiesReader camera_reader;
  ok = load(camera_file1, camera1, camera_reader);
  CHECK(ok) << "Could not load intrinsics for main camera";

  // For each view.
  for (int view2 = 0; view2 < num_views; view2 += 1) {
    if (view2 != view1) {
      // Load fundamental matrix.
      cv::Mat F;
      int i = view1;
      int j = view2;
      bool swap = false;
      if (view2 < view1) {
        std::swap(i, j);
        swap = true;
      }
      std::string fund_mat_file = makeViewPairFilename(fund_mat_format,
          view_names[i], view_names[j]);
      MatrixReader matrix_reader;
      ok = load(fund_mat_file, F, matrix_reader);
      CHECK(ok) << "Could not load fundamental matrix";
      if (swap) {
        F = F.t();
      }

      // Load camera properties.
      CameraProperties camera2;
      std::string camera_file2 = makeViewFilename(intrinsics_format,
          view_names[view2]);
      ok = load(camera_file2, camera2, camera_reader);
      CHECK(ok) << "Could not load intrinsics for second camera";

      std::vector<double> scales;
      scales.push_back(4);
      scales.push_back(8);
      scales.push_back(16);
      scales.push_back(32);
      scales.push_back(64);

      std::vector<double> angles;
      angles.push_back(0 * M_PI / 4.);
      angles.push_back(1 * M_PI / 4.);
      angles.push_back(2 * M_PI / 4.);
      angles.push_back(3 * M_PI / 4.);
      angles.push_back(4 * M_PI / 4.);
      angles.push_back(5 * M_PI / 4.);
      angles.push_back(6 * M_PI / 4.);
      angles.push_back(7 * M_PI / 4.);

      extractExamplesForView(features, F, camera1, camera2, image_format,
          view_names[view2], time, scales, angles);
    }
  }

  return 0;
}
int main(int argc, char** argv) {
  bool ok;

  init(argc, argv);
  int main_view = boost::lexical_cast<int>(argv[1]);
  std::string input_tracks_file = argv[2];
  std::string image_format = argv[3];
  std::string extrinsics_format = argv[4];
  std::string intrinsics_format = argv[5];
  std::string views_file = argv[6];
  int num_frames = boost::lexical_cast<int>(argv[7]);
  std::string multiview_tracks_file = argv[8];

  // Load tracks.
  TrackList<cv::Point2d> input_tracks;
  ImagePointReader<double> point_reader;
  ok = loadTrackList(input_tracks_file, input_tracks, point_reader);
  CHECK(ok) << "Could not load tracks";
  LOG(INFO) << "Loaded " << input_tracks.size() << " single-view tracks";

  // Load names of views.
  std::vector<std::string> view_names;
  ok = readLines(views_file, view_names);
  CHECK(ok) << "Could not load view names";
  int num_views = view_names.size();
  LOG(INFO) << "Matching to " << num_views << " views";

  CHECK(main_view >= 0);
  CHECK(main_view < num_views);

  // Load properties of each view.
  std::vector<Camera> cameras;

  CameraPoseReader extrinsics_reader;
  CameraPropertiesReader intrinsics_reader;

  for (int view = 0; view < num_views; view += 1) {
    const std::string& name = view_names[view];

    // Load cameras for all views.
    CameraProperties intrinsics;
    std::string intrinsics_file = makeViewFilename(intrinsics_format, name);
    ok = load(intrinsics_file, intrinsics, intrinsics_reader);
    CHECK(ok) << "Could not load intrinsics";

    CameraPose extrinsics;
    std::string extrinsics_file = makeViewFilename(extrinsics_format, name);
    ok = load(extrinsics_file, extrinsics, extrinsics_reader);
    CHECK(ok) << "Could not load extrinsics";

    cameras.push_back(Camera(intrinsics, extrinsics));
  }

  // Find multiview tracks.
  MultiviewTrackList<cv::Point2d> multiview_tracks;
  findMultiviewTracks(input_tracks, cameras, main_view, multiview_tracks, 1, 1);

  // Save points and tracks out.
  ImagePointWriter<double> point_writer;
  ok = saveMultiviewTrackList(multiview_tracks_file, multiview_tracks,
      point_writer);
  CHECK(ok) << "Could not save tracks";

  return 0;
}
Esempio n. 27
0
/* MapPreviewCanvas::openMap
 * Opens a map from a mapdesc_t
 *******************************************************************/
bool MapPreviewCanvas::openMap(Archive::mapdesc_t map)
{
	// All errors = invalid map
	Global::error = "Invalid map";

	// Check if this map is a pk3 map
	bool map_archive = false;
	if (map.archive)
	{
		map_archive = true;

		// Attempt to open entry as wad archive
		temp_archive = new WadArchive();
		if (!temp_archive->open(map.head))
		{
			delete temp_archive;
			return false;
		}

		// Detect maps
		vector<Archive::mapdesc_t> maps = temp_archive->detectMaps();

		// Set map if there are any in the archive
		if (maps.size() > 0)
			map = maps[0];
		else
			return false;
	}

	// Parse UDMF map
	if (map.format == MAP_UDMF)
	{
		ArchiveEntry* udmfdata = NULL;
		for (ArchiveEntry* mapentry = map.head; mapentry != map.end; mapentry = mapentry->nextEntry())
		{
			// Check entry type
			if (mapentry->getType() == EntryType::getType("udmf_textmap"))
			{
				udmfdata = mapentry;
				break;
			}
		}
		if (udmfdata == NULL)
			return false;

		// Start parsing
		Tokenizer tz;
		tz.openMem(udmfdata->getData(), udmfdata->getSize(), map.head->getName());

		// Get first token
		string token = tz.getToken();
		size_t vertcounter = 0, linecounter = 0, thingcounter = 0;
		while (!token.IsEmpty())
		{
			if (!token.CmpNoCase("namespace"))
			{
				//  skip till we reach the ';'
				do { token = tz.getToken(); }
				while (token.Cmp(";"));
			}
			else if (!token.CmpNoCase("vertex"))
			{
				// Get X and Y properties
				bool gotx = false;
				bool goty = false;
				double x = 0.;
				double y = 0.;
				do
				{
					token = tz.getToken();
					if (!token.CmpNoCase("x") || !token.CmpNoCase("y"))
					{
						bool isx = !token.CmpNoCase("x");
						token = tz.getToken();
						if (token.Cmp("="))
						{
							wxLogMessage("Bad syntax for vertex %i in UDMF map data", vertcounter);
							return false;
						}
						if (isx) x = tz.getDouble(), gotx = true;
						else y = tz.getDouble(), goty = true;
						// skip to end of declaration after each key
						do { token = tz.getToken(); }
						while (token.Cmp(";"));
					}
				}
				while (token.Cmp("}"));
				if (gotx && goty)
					addVertex(x, y);
				else
				{
					wxLogMessage("Wrong vertex %i in UDMF map data", vertcounter);
					return false;
				}
				vertcounter++;
			}
			else if (!token.CmpNoCase("linedef"))
			{
				bool special = false;
				bool twosided = false;
				bool gotv1 = false, gotv2 = false;
				size_t v1 = 0, v2 = 0;
				do
				{
					token = tz.getToken();
					if (!token.CmpNoCase("v1") || !token.CmpNoCase("v2"))
					{
						bool isv1 = !token.CmpNoCase("v1");
						token = tz.getToken();
						if (token.Cmp("="))
						{
							wxLogMessage("Bad syntax for linedef %i in UDMF map data", linecounter);
							return false;
						}
						if (isv1) v1 = tz.getInteger(), gotv1 = true;
						else v2 = tz.getInteger(), gotv2 = true;
						// skip to end of declaration after each key
						do { token = tz.getToken(); }
						while (token.Cmp(";"));
					}
					else if (!token.CmpNoCase("special"))
					{
						special = true;
						// skip to end of declaration after each key
						do { token = tz.getToken(); }
						while (token.Cmp(";"));
					}
					else if (!token.CmpNoCase("sideback"))
					{
						twosided = true;
						// skip to end of declaration after each key
						do { token = tz.getToken(); }
						while (token.Cmp(";"));
					}
				}
				while (token.Cmp("}"));
				if (gotv1 && gotv2)
					addLine(v1, v2, twosided, special);
				else
				{
					wxLogMessage("Wrong line %i in UDMF map data", linecounter);
					return false;
				}
				linecounter++;
			}
			else if (S_CMPNOCASE(token, "thing"))
			{
				// Get X and Y properties
				bool gotx = false;
				bool goty = false;
				double x = 0.;
				double y = 0.;
				do
				{
					token = tz.getToken();
					if (!token.CmpNoCase("x") || !token.CmpNoCase("y"))
					{
						bool isx = !token.CmpNoCase("x");
						token = tz.getToken();
						if (token.Cmp("="))
						{
							wxLogMessage("Bad syntax for thing %i in UDMF map data", vertcounter);
							return false;
						}
						if (isx) x = tz.getDouble(), gotx = true;
						else y = tz.getDouble(), goty = true;
						// skip to end of declaration after each key
						do { token = tz.getToken(); } while (token.Cmp(";"));
					}
				} while (token.Cmp("}"));
				if (gotx && goty)
					addThing(x, y);
				else
				{
					wxLogMessage("Wrong thing %i in UDMF map data", vertcounter);
					return false;
				}
				vertcounter++;
			}
			else
			{
				// Check for side or sector definition (increase counts)
				if (S_CMPNOCASE(token, "sidedef"))
					n_sides++;
				else if (S_CMPNOCASE(token, "sector"))
					n_sectors++;

				// map preview ignores sidedefs, sectors, comments,
				// unknown fields, etc. so skip to end of block
				do { token = tz.getToken(); }
				while (token.Cmp("}"));
			}
			// Iterate to next token
			token = tz.getToken();
		}
	}

	// Non-UDMF map
	if (map.format != MAP_UDMF)
	{
		// Read vertices (required)
		if (!readVertices(map.head, map.end, map.format))
			return false;

		// Read linedefs (required)
		if (!readLines(map.head, map.end, map.format))
			return false;

		// Read things
		if (map.format != MAP_UDMF)
			readThings(map.head, map.end, map.format);

		// Read sides & sectors (count only)
		ArchiveEntry* sidedefs = NULL;
		ArchiveEntry* sectors = NULL;
		while (map.head)
		{
			// Check entry type
			if (map.head->getType() == EntryType::getType("map_sidedefs"))
				sidedefs = map.head;
			if (map.head->getType() == EntryType::getType("map_sectors"))
				sectors = map.head;

			// Exit loop if we've reached the end of the map entries
			if (map.head == map.end)
				break;
			else
				map.head = map.head->nextEntry();
		}
		if (sidedefs && sectors)
		{
			// Doom64 map
			if (map.format != MAP_DOOM64)
			{
				n_sides = sidedefs->getSize() / 30;
				n_sectors = sectors->getSize() / 26;
			}

			// Doom/Hexen map
			else
			{
				n_sides = sidedefs->getSize() / 12;
				n_sectors = sectors->getSize() / 16;
			}
		}
	}

	// Clean up
	if (map_archive)
	{
		temp_archive->close();
		delete temp_archive;
		temp_archive = NULL;
	}

	// Refresh map
	Refresh();

	return true;
}
void LineAssembler::push_chunk(char* input){
    raw->push_back(input);
    readLines();
}
void LineAssembler::push_chunk(QByteArray input){
    raw->push_back(input);
    readLines();
}
Esempio n. 30
0
int main(int argc, char *argv[])
{
	FILE *fp;
	int ii;

	if (argc > 1)
	{
		// Open given file for reading
		fp = fopen(argv[1], "r");
		if(fp == NULL)
		{
			fprintf(stderr, "Error reading file: %s\n", strerror(errno));
			exit(1);
		}
	}
	else
	{
		// Set fp to stdin if nothing specified
		fp = stdin;
	}
	
	char *line;
	while ((line = readLines(fp)) != NULL && !feof(fp))
	{
		// Line is a comment. Ignore it.
		if(line[0] == '#')
			continue;

		char *word;
		char **args = NULL;
		int numSpaces = 0;

		word = strtok(line, " ");
		while(word != NULL)
		{
			numSpaces++;
			args = realloc(args, sizeof(char*) * numSpaces);
			if(args == NULL)
			{
				fprintf(stderr, "Error allocating memory.\n");
				exit(1);
			}
			args[numSpaces-1] = word;
			word = strtok(NULL, " ");
		}

		//Set end of args to null
		args = realloc(args, sizeof(char*) * (numSpaces+1));
		args[numSpaces] = NULL;

		pid_t pid;
		struct rusage ru;
		int status;
		int flag = 0;;

		switch (pid=fork())
		{
			case -1:
				perror("Fork failed.");
				exit(1);
				break;
			case 0:
				if(numSpaces > 1)
				{
					char* path = NULL;
					int oldfd, newfd;

					if(strstr(args[numSpaces-1], "<"))
					{
						path = strstr(args[numSpaces-1], "<");
						path++;
						oldfd = open(path, O_RDONLY);
						// redirect to stdin
						newfd = 0;
						flag = -1;
					}
					else
					{
						if(strstr(args[numSpaces-1], "2>>"))
						{
							path = strstr(args[numSpaces-1], "2>>");
							path++;
							path++;
							path++;
							oldfd = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IREAD | S_IWRITE);
							// redirect to stderr
							newfd = 2;
							flag = -1;
						}
						else if(strstr(args[numSpaces-1], ">>"))
						{
							path = strstr(args[numSpaces-1], ">>");
							path++;
							path++;
							oldfd = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IREAD | S_IWRITE);
							// redirect to stdout
							newfd = 1;
							flag = -1;
						}
						else if(strstr(args[numSpaces-1], "2>"))
						{
							path = strstr(args[numSpaces-1], "2>");
							path++;
							path++;
							oldfd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
							// redirect to stderr
							newfd = 2;
							flag = -1;
						}
						else if(strstr(args[numSpaces-1], ">"))
						{
							path = strstr(args[numSpaces-1], ">");
							path++;
							oldfd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
							// redirect to stdout
							newfd = 1;
							flag = -1;
						}
					}

					if (oldfd < 0 || newfd < 0)
					{
						fprintf(stderr, "Error opening file: %s\n", strerror(errno));
						exit(1);
					}
					else
					{
						dup2(oldfd, newfd);
						close(oldfd);
						if (flag == -1)
							args[numSpaces-1] = '\0';
					}
				}

				fprintf(stderr, "Executing command %s", args[0]);

				if(numSpaces != 1)
					fprintf(stderr, " with arguments ");

				for(ii = 1; args[ii] != NULL; ii++)
					fprintf(stderr, "\"%s\" ", args[ii]);

				fprintf(stderr, "\n");

				if(execvp(args[0], args) == -1)
				{
					fprintf(stderr, "Error executing file: %s\n", strerror(errno));
					exit(1);
				}
				break;
			default:
				if(wait3(&status,0,&ru) == -1)
				{
					perror("wait3");
				}
				else
				{
					fprintf(stderr, "Child process %d returned with return code %d,\nconsuming %ld.%.6d real seconds, %ld.%.6d user, %ld.%.6d system\n", 
								pid,
								status,
								ru.ru_utime.tv_sec + ru.ru_stime.tv_sec,
								ru.ru_utime.tv_usec + ru.ru_stime.tv_usec,
								ru.ru_utime.tv_sec,
								ru.ru_utime.tv_usec,
								ru.ru_stime.tv_sec,
								ru.ru_stime.tv_usec);
				}
				break;
			free(line);
			free(args);
		}
	}

	exit(0);
}