Exemplo n.º 1
0
int main()
{
    Mat rgb1,rgb2,depth1,depth2;
    fileread(rgb1,rgb2,depth1,depth2);

    CAMERA_INTRINSIC_PARAMETERS C;
    C.cx = 325.5;
    C.cy = 253.5;
    C.fx = 518.0;
    C.fy = 519.0;
    C.scale = 1000.0;

    //feature detector and descriptor compute
    Eigen::Isometry3d T = transformEstimation(rgb1,rgb2,depth1,depth2,C);

    PointCloud::Ptr cloud1 = image2PointCloud(rgb1,depth1,C);
    PointCloud::Ptr cloud2 = image2PointCloud(rgb2,depth2,C);

    //pcl::io::savePCDFile("1.pcd", *cloud1);
    //pcl::io::savePCDFile("2.pcd", *cloud2);

    cout<<"combining clouds"<<endl;
    PointCloud::Ptr output (new PointCloud());
    pcl::transformPointCloud( *cloud2, *output, T.matrix());
    *cloud1 += *output;
    pcl::io::savePCDFile("result.pcd", *cloud1);
    cout<<"Final result saved."<<endl;
    return 0;
}
Exemplo n.º 2
0
/* Read the header bytes of the given solution file. flags receives
 * the option bytes (bytes 5-6). extra receives any bytes in the
 * header that this code doesn't recognize.
 */
static int readsolutionheader(fileinfo *file, int ruleset, int *flags,
			      int *extrasize, unsigned char *extra)
{
    uint32_t		sig;
    uint16_t		f;
    uint8_t		n;

    if (!filereadint32(file, &sig, "not a valid solution file"))
	return FALSE;
    if (sig != CSSIG)
	return fileerr(file, "not a valid solution file");
    if (!filereadint8(file, &n, "not a valid solution file"))
	return FALSE;
    if (n != ruleset)
	return fileerr(file, "solution file is for a different ruleset"
			     " than the level set file");
    if (!filereadint16(file, &f, "not a valid solution file"))
	return FALSE;
    *flags = (int)f;

    if (!filereadint8(file, &n, "not a valid solution file"))
	return FALSE;
    *extrasize = n;
    if (n)
	if (!fileread(file, extra, *extrasize, "not a valid solution file"))
	    return FALSE;

    return TRUE;
}
Exemplo n.º 3
0
int
do_read(int fd, void *src, u32 cnt)
{
    if (fd < 0 || fd >= NOFILE || !fs_current->ofile[fd])
        return -1;
    return fileread(fs_current->ofile[fd], src, cnt);
}
Exemplo n.º 4
0
int
sys_read(struct file *f, char *p, int n)
{
  if(argfd(0, 0, &f) < 0 || argint(2, &n) < 0 || argptr(1, &p, n) < 0)
    return -1;
  return fileread(f, p, n);
}
Exemplo n.º 5
0
void GameInit() {
	GameTextures::Init();
	GameMeshes::Init();

	torus = GameMeshes::Get( "torus" );
	bunny = GameMeshes::Get( "bunny" );
	monkey = GameMeshes::Get( "monkey" );
	rocks = GameMeshes::Get( "rocks" );
	wall = GameMeshes::Get( "wall" );
	well = GameMeshes::Get( "well" );
	sword = GameMeshes::Get( "sword" );
	floortile = GameMeshes::Get( "floor" );

	cube = new BadMesh();
	cube->SetAsCube();
	cube->UVsFromBB();

	// now test running some javascript
	js = new CTinyJS();
	registerFunctions(js);
	js->addNative("function print(text)", &js_print, 0);
	try {
		char *buf = fileread("test.js");
		js->execute(buf);
		free( buf );
	} catch (CScriptException *e) {
		printf("ERROR: %s\n", e->text.c_str());
  }
}
Exemplo n.º 6
0
//Done
int
sys_read(int fd ,char *p,int n)
{
  struct file *f;;

  f = fdlookup(fd);
  return fileread(f, p, n);
}
Exemplo n.º 7
0
int init_module()
{
  char *filename="/root/test1.c";

  printk("<1>read file from kernel.\n");
  fileread(filename);
  filewrite(filename, "kernel write test\n");
  return 0;
}
Exemplo n.º 8
0
TEST(CXFAFileRead, NoStreams) {
  std::vector<CPDF_Stream*> streams;
  UniqueFileRead fileread(new CXFA_FileRead(streams));

  uint8_t output_buffer[16];
  memset(output_buffer, 0xbd, sizeof(output_buffer));
  EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0));
  EXPECT_EQ(0xbd, output_buffer[0]);
}
Exemplo n.º 9
0
TEST(CXFAFileRead, EmptyStreams) {
  std::vector<CPDF_Stream*> streams;
  std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>();
  streams.push_back(stream1.get());
  UniqueFileRead fileread(new CXFA_FileRead(streams));

  uint8_t output_buffer[16];
  memset(output_buffer, 0xbd, sizeof(output_buffer));
  EXPECT_FALSE(fileread->ReadBlock(output_buffer, 0, 0));
  EXPECT_EQ(0xbd, output_buffer[0]);
}
Exemplo n.º 10
0
void 
swapIn(struct proc* p)
{
  //read from file
  char filename[9]; 
  struct file* f;
  uint i;
  char* buff;
  pte_t* pte;
  //cprintf("swapin %s %d\n", p->name, p->pid);
  getSwapFileName(p, filename);
  release(&ptable.lock);
  f = openKernelFile(filename, O_RDWR);
  //cprintf("1");
  acquire(&ptable.lock);
  if(f == 0)
    panic("swapin: file open error\n");
  f->off = 0;
  
  //p->pgdir = setupkvm();
  if (!p->pgdir)
    panic("swapin: setupkvm failed\n");
  
  int recovered = 0;
  for (i = 0; i < p->sz; i += PGSIZE) {
    if((pte = walkpgdir(p->pgdir, (char*) i, 0)) == 0){
      //cprintf("skip");
      //continue;
    }
     if(*pte != 0)
       continue;
    if (!(buff = kalloc()))
      panic("swapin: kalloc failed\n");
    release(&ptable.lock);
    fileread(f, buff, PGSIZE);
    acquire(&ptable.lock);
    //cprintf("(%s)", buff);
    if (mappages(p->pgdir, (void*) i, PGSIZE, v2p(buff), PTE_W | PTE_U) < 0)
      panic("swapin: mappages failed\n");
    recovered++;
  }
  //cprintf("swapin recovered %d\n", recovered);
  release(&ptable.lock);
  fileclose(f);
  //cprintf("swapin2");
  //unlinkKernelFile(filename);
  acquire(&ptable.lock);
  //cprintf("swapin3");
}
Exemplo n.º 11
0
TEST(CXFAFileRead, NormalStreams) {
  std::vector<CPDF_Stream*> streams;
  std::unique_ptr<CPDF_Stream> stream1 = pdfium::MakeUnique<CPDF_Stream>();
  std::unique_ptr<CPDF_Stream> stream2 = pdfium::MakeUnique<CPDF_Stream>();
  std::unique_ptr<CPDF_Stream> stream3 = pdfium::MakeUnique<CPDF_Stream>();

  // 16 chars total.
  stream1->InitStream(reinterpret_cast<const uint8_t*>("one t"), 5,
                      new CPDF_Dictionary());
  stream2->InitStream(reinterpret_cast<const uint8_t*>("wo "), 3,
                      new CPDF_Dictionary());
  stream3->InitStream(reinterpret_cast<const uint8_t*>("three!!!"), 8,
                      new CPDF_Dictionary());

  streams.push_back(stream1.get());
  streams.push_back(stream2.get());
  streams.push_back(stream3.get());
  UniqueFileRead fileread(new CXFA_FileRead(streams));

  uint8_t output_buffer[16];
  memset(output_buffer, 0xbd, sizeof(output_buffer));
  EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 0));
  EXPECT_EQ(0xbd, output_buffer[0]);

  memset(output_buffer, 0xbd, sizeof(output_buffer));
  EXPECT_TRUE(fileread->ReadBlock(output_buffer, 1, 0));
  EXPECT_EQ(0xbd, output_buffer[0]);

  memset(output_buffer, 0xbd, sizeof(output_buffer));
  EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, 1));
  EXPECT_EQ(0, memcmp(output_buffer, "o", 1));
  EXPECT_EQ(0xbd, output_buffer[1]);

  memset(output_buffer, 0xbd, sizeof(output_buffer));
  EXPECT_TRUE(fileread->ReadBlock(output_buffer, 0, sizeof(output_buffer)));
  EXPECT_EQ(0, memcmp(output_buffer, "one two three!!!", 16));

  memset(output_buffer, 0xbd, sizeof(output_buffer));
  EXPECT_TRUE(fileread->ReadBlock(output_buffer, 2, 10));
  EXPECT_EQ(0, memcmp(output_buffer, "e two thre", 10));
  EXPECT_EQ(0xbd, output_buffer[11]);

  memset(output_buffer, 0xbd, sizeof(output_buffer));
  EXPECT_FALSE(fileread->ReadBlock(output_buffer, 1, sizeof(output_buffer)));
  EXPECT_EQ(0, memcmp(output_buffer, "ne two three!!!", 15));
  EXPECT_EQ(0xbd, output_buffer[15]);
}
Exemplo n.º 12
0
int filenext(f,n)
{	int s;
	extern int gargi,gargc;
	extern char **gargv;

	if (filesave(f,n) == FALSE)	/* save current file		*/
		return FALSE;
	if (gargi < gargc)		/* if more files on command line */
	{
		s = readin(gargv[gargi]);
		gargi++;
	}
	else				/* get file name from user	*/
		s = fileread(f,n);
	makename(curbp->b_bname,curbp->b_fname);
	return s;
}
Exemplo n.º 13
0
//for the http://xxx.xxx.xxx.xxx:8081 server
void Widget::updateServer()
{
    QFile fileread("/usr/share/matrix-gui-2.0/apps/qt_tstat/remotecont");
    if (!fileread.open(QIODevice::ReadOnly | QIODevice::Text))
             return;
    QTextStream in( &fileread );
    QString templine;
    QString newfansetting;
    templine = in.readLine();
    newfansetting = in.readLine();
    if (templine != "")
    {
        thesetpointfloat = templine.toInt();
        ui->scrollWheel->setValue(thesetpointfloat);

        if ( newfansetting != "")
        {
            fanstate = newfansetting;
            qDebug() << "the new fanstate is : " << newfansetting;
            FanSettingHandler();
        }
        fileread.close();
        system(" echo '' > /usr/share/matrix-gui-2.0/apps/qt_tstat/remotecont");


    }
    else
    {
        fileread.close();
    }

    QFile file("/usr/share/matrix-gui-2.0/apps/qt_tstat/thetemp");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
             return;

    QTextStream out(&file);
    out << ui->dateLabel->text() << "\n";
    out << ui->timeLabel->text() << "\n";
    out << StringOfTempinF << "\n";
    out << ui->setpointlcdNumber->value() << "\n";
    out << fanstate << "\n";
    file.close();
}
Exemplo n.º 14
0
//==============================================================================
// Shader
//------------------------------------------------------------------------------
unsigned int Shader::createPixShader(const char * file) {
  HRESULT hr;
  auto pDevice = _renderer->getDevice();
  PixShader* pixelShader = new PixShader();

  if(!isfile((kBaceShaderFolder + file).c_str())) {
    MessageBoxA(NULL,"そんなファイルネェ","error",MB_OK);
    App::instance().exit();
    return 0;
  }

  DWORD* shader = fileread((kBaceShaderFolder + file).c_str());

  // constTable取得
  hr = D3DXGetShaderConstantTable(shader, &pixelShader->_constTable);
  if(FAILED(hr)) {
    MessageBoxA(NULL,"よくわからんけどエラー",("D3DXGetShaderConstantTable"),MB_OK);
    App::instance().exit();
    SafeDeleteArray(shader);
    return 0;
  }

  // ピクセルシェーダ生成
  hr = pDevice->CreatePixelShader(shader, &pixelShader->_shader);
  if(FAILED(hr)) {
    MessageBox(NULL,TEXT("PixelShaderFailed"),TEXT("CreatePixelShader"),MB_OK);
    App::instance().exit();
    SafeDeleteArray(shader);
    return 0;
  }

  pixelShader->filename = file;

  // インサート
  _pixShaderList.push_back(pixelShader);
  _pixShaderMap.insert(std::pair<std::string,unsigned int>(file,_pixShaderList.size() - 1));

  SafeDeleteArray(shader);

  return _pixShaderList.size() - 1;
}
Exemplo n.º 15
0
/*
 *  write back a file
 */
int
createfile1(Node *node)
{
	Biobuf *bp;
	char buf[4*1024];
	long off;
	int n;

	if(changedir(node->parent) < 0)
		return -1;

	if(data(OWRITE, &bp, "STOR", s_to_c(node->remname)) != Extra)
		return -1;
	for(off = 0; ; off += n){
		n = fileread(node, buf, off, sizeof(buf));
		if(n <= 0)
			break;
		write(Bfildes(bp), buf, n);
	}
	close(Bfildes(bp));
	if(getreply(&ctlin, msg, sizeof(msg), 0) != Success)
		return -1;
	return off;
}
Exemplo n.º 16
0
// packing: use RCO_DATA_COMPRESSION_* constants
uint8_t
write_rco (rRCOFile * rco, char *fn, writerco_options opts)
{
  uint32_t i;
  rRCOFile_writehelper rcoH;

  // delete file if exists
  if (file_exists (fn)) {
    if (remove (fn)) {
      error ("Unable to write to file %s", fn);
      return FALSE;
    }
  }

  rcoH.rco = rco;
  rcoH.fp = fopen (fn, "wb");
  if (!rcoH.fp) {
    error ("Unable to open file %s", fn);
    return FALSE;
  }

  PRFHeader header;

  header.signature = RCO_SIGNATURE;
  header.version =
      (opts.packHeader == RCO_DATA_COMPRESSION_RLZ ? 0x95 : opts.packHeader ==
      RCO_DATA_COMPRESSION_ZLIB ? 0x90 : 0x71);
  if (rco->verId) {		// we won't actually use specified value,
    // rather, we'll require using the minimum
    // version from above
    if (rco->verId > header.version)
      header.version = rco->verId;
  }
  header.null = 0;
  header.compression = (opts.packHeader << 4) | (rco->umdFlag & 0xF);

  header.pMainTable = 0xA4;	// pretty much always the case
  // set other sections to nothing for now
  header.pVSMXTable = header.pTextTable = header.pSoundTable =
      header.pModelTable = header.pImgTable = header.pObjTable =
      header.pAnimTable = RCO_NULL_PTR;
  header.pUnknown = header.pFontTable = RCO_NULL_PTR;

  // don't know positions of text/label/event data too, but we do know the
  // lengths for label/events
  // header.pTextData = header.pLabelData = header.pEventData = 0;
  header.lLabelData = rco->labelsLen;
  header.lEventData = rco->eventsLen;
  header.lTextData = 0;

  // set pointer sections to blank too
  header.pTextPtrs = header.pImgPtrs = header.pModelPtrs = header.pSoundPtrs =
      header.pObjPtrs = header.pAnimPtrs = RCO_NULL_PTR;

  header.lTextPtrs = header.lImgPtrs = header.lModelPtrs = header.lSoundPtrs =
      header.lObjPtrs = header.lAnimPtrs = 0;

  // also blank...
  header.pImgData = header.pSoundData = header.pModelData = RCO_NULL_PTR;
  header.lImgData = header.lSoundData = header.lModelData = 0;

  header.unknown[0] = header.unknown[1] = header.unknown[2] = 0xFFFFFFFF;

  // write resources to a separate file to get around the issue of unknown
  // packed size when writing the header (and you can't change it backed after
  // the header is packed...)
  FILE *fTmp = NULL;

  if ((rco->tblImage && rco->tblImage->numSubentries)
      || (rco->tblSound && rco->tblSound->numSubentries)
      || (rco->tblModel && rco->tblModel->numSubentries)) {
    uint32_t totalPackedLen = 0;
    rRCOEntry *rcoNode;

    fTmp = tmpfile ();

    if (rco->tblImage && rco->tblImage->numSubentries) {
      for (rcoNode = rco->tblImage->firstChild; rcoNode;
	  rcoNode = rcoNode->next) {
	// our compression decision thing
	uint32_t c = ((rRCOImgModelEntry *) (rcoNode->extra))->compression;

	if (((rRCOImgModelEntry *) (rcoNode->extra))->format < RCO_IMG_BMP) {
	  if (opts.packImgCompr != -1)
	    c = opts.packImgCompr;
	} else {
	  if (opts.packImg != -1)
	    c = opts.packImg;
	}

	if (rcoNode->srcLenUnpacked) {
	  rcoNode->srcLen = rco_write_resource (fTmp, rcoNode, c, &opts, rco);
	  if (!rcoNode->srcLen && rcoNode->labelOffset != RCO_NULL_PTR)
	    warning ("[resource] Can't write image resource '%s'!",
		rco->labels + rcoNode->labelOffset);
	}
	rcoNode->srcCompression = c;
	rcoNode->srcAddr = totalPackedLen;

	totalPackedLen +=
	    (rcoNode->srcLen % 4 ? (rcoNode->srcLen / 4) * 4 +
	    4 : rcoNode->srcLen);
      }
      header.lImgData = totalPackedLen;
    }

    totalPackedLen = 0;
    if (rco->tblSound && rco->tblSound->numSubentries) {
      for (rcoNode = rco->tblSound->firstChild; rcoNode;
	  rcoNode = rcoNode->next) {
	if (rcoNode->srcLenUnpacked) {
	  uint32_t packedLen = rco_write_resource (fTmp, rcoNode,
	      RCO_DATA_COMPRESSION_NONE,
	      &opts,
	      rco);

	  if (!packedLen && rcoNode->labelOffset != RCO_NULL_PTR)
	    warning ("[resource] Can't write sound resource '%s'!",
		rco->labels + rcoNode->labelOffset);
	  totalPackedLen += ALIGN_TO_4 (packedLen);
	  // if(totalPackedLen %4) totalPackedLen += 4-(totalPackedLen%4);
	}
      }
      header.lSoundData = totalPackedLen;
    }

    totalPackedLen = 0;
    if (rco->tblModel && rco->tblModel->numSubentries) {
      for (rcoNode = rco->tblModel->firstChild; rcoNode;
	  rcoNode = rcoNode->next) {
	uint32_t c = ((rRCOImgModelEntry *) (rcoNode->extra))->compression;

	if (opts.packModel != -1)
	  c = opts.packModel;

	if (rcoNode->srcLenUnpacked) {
	  rcoNode->srcLen = rco_write_resource (fTmp, rcoNode, c, &opts, rco);
	  if (!rcoNode->srcLen && rcoNode->labelOffset != RCO_NULL_PTR)
	    warning ("[resource] Can't write model resource '%s'!",
		rco->labels + rcoNode->labelOffset);
	}
	rcoNode->srcCompression = c;
	rcoNode->srcAddr = totalPackedLen;

	totalPackedLen +=
	    (rcoNode->srcLen % 4 ? (rcoNode->srcLen / 4) * 4 +
	    4 : rcoNode->srcLen);
      }
      header.lModelData = totalPackedLen;
    }

    rewind (fTmp);
  }

  filewrite (rcoH.fp, &header, sizeof (header));

  rcoH.tables = 0;

  // if compressing, write to memory
  if (opts.packHeader) {
    rcoH.tables = malloc (RCO_WRITE_MEM_BUFFER);
    rcoH.memPos = rcoH.tablesSize = 0;
    rcoH.tablesBuffered = RCO_WRITE_MEM_BUFFER;
    rcoH.memOffset = ftell (rcoH.fp);
  }

  rcoH.sizeImg = rcoH.sizeModel = rcoH.sizeSound = rcoH.sizeText = 0;
  rcoH.longestLangData = 0;

  write_entry (&rcoH, &(rco->tblMain), 0xA4	/* typically where the main
						 * table is written to */ , 0,
      TRUE);

  // fix up object/anim extra data
  {
    if (rco->tblObj)
      rco_write_fix_refs (rco->tblObj, &rcoH, rco, RCO_OBJ_EXTRA_LEN,
	  RCO_OBJ_EXTRA_LEN_NUM, TRUE);
    if (rco->tblAnim)
      rco_write_fix_refs (rco->tblAnim, &rcoH, rco, RCO_ANIM_EXTRA_LEN,
	  RCO_ANIM_EXTRA_LEN_NUM, FALSE);
  }

  {				// write hashtable data

    /* { // special case for text hashes if(rco->numPtrText) { header.pTextPtrs
     * = rcowrite_ftell(&rcoH); for(i=0; i<rco->numPtrText; i++) { uint32_t
     * writePtr = 0; if(rco->ptrText[i].textEntry && rco->ptrText[i].index)
     * writePtr = rco->ptrText[i].textEntry->offset + sizeof(RCOEntry) +
     * sizeof(RCOTextEntry) + (rco->ptrText[i].index -
     * ((rRCOTextEntry*)(rco->ptrText[i].textEntry->extra))->indexes)*sizeof(RCOTextIndex);
     * rco_fwrite(&rcoH, &writePtr, sizeof(uint32_t)); } } } */
    if (rco->tblText) {
      header.pTextPtrs = rcowrite_ftell (&rcoH);
      header.lTextPtrs = 0;

      // generate sorted list of text entries, sorted by languageID
      rRCOEntry **sList = make_sorted_list_of_subentries (rco->tblText,
	  text_hash_table_qsort);

      for (i = 0; i < rco->tblText->numSubentries; i++)
	header.lTextPtrs += write_text_hash_table (&rcoH, sList[i], rco);
      free (sList);

      header.lTextPtrs *= sizeof (uint32_t);
    }

    if (rco->tblImage) {
      header.pImgPtrs = rcowrite_ftell (&rcoH);
      header.lImgPtrs =
	  write_hash_table (&rcoH, rco->tblImage, rco) * sizeof (uint32_t);
    }
    if (rco->tblModel) {
      header.pModelPtrs = rcowrite_ftell (&rcoH);
      header.lModelPtrs =
	  write_hash_table (&rcoH, rco->tblModel, rco) * sizeof (uint32_t);
    }
    if (rco->tblSound) {
      header.pSoundPtrs = rcowrite_ftell (&rcoH);
      header.lSoundPtrs =
	  write_hash_table (&rcoH, rco->tblSound, rco) * sizeof (uint32_t);
    }
    if (rco->tblObj) {
      header.pObjPtrs = rcowrite_ftell (&rcoH);
      header.lObjPtrs =
	  write_hash_table (&rcoH, rco->tblObj, rco) * sizeof (uint32_t);
    }
    if (rco->tblAnim) {
      header.pAnimPtrs = rcowrite_ftell (&rcoH);
      header.lAnimPtrs =
	  write_hash_table (&rcoH, rco->tblAnim, rco) * sizeof (uint32_t);
    }
    /*
     * #define RCO_WRITERCO_WRITE_PTR_SECT(pd, pl, hp) { \ if(pl) { \ hp =
     * rcowrite_ftell(&rcoH); \ for(i=0; i<pl; i++) { \ if(pd[i]) \
     * rco_fwrite(&rcoH, &(((rRCOEntry*)(pd[i]))->offset), sizeof(uint32_t)); \
     * else { \ uint32_t zero = 0; \ rco_fwrite(&rcoH, &zero, sizeof(uint32_t)); \
     * } \ } \ } \ } //RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrText,
     * rco->numPtrText, header.pTextPtrs);
     * RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrImg, rco->numPtrImg,
     * header.pImgPtrs); RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrModel,
     * rco->numPtrModel, header.pModelPtrs);
     * RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrSound, rco->numPtrSound,
     * header.pSoundPtrs); RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrObj,
     * rco->numPtrObj, header.pObjPtrs);
     * RCO_WRITERCO_WRITE_PTR_SECT(rco->ptrAnim, rco->numPtrAnim,
     * header.pAnimPtrs); */
  }

  {				// write label/event data (and text if
    // applicable)

    // write text (note, old behaviour - newer RCOs have text written in a
    // different location)
    if (!opts.packText && rco->tblText && rco->tblText->numSubentries) {
      rRCOEntry *rcoNode;

      header.pTextData = rcowrite_ftell (&rcoH);
      header.lTextData = rcoH.sizeText;
      for (rcoNode = rco->tblText->firstChild; rcoNode; rcoNode = rcoNode->next) {
	rco_write_text_resource (&rcoH, rcoNode, RCO_DATA_COMPRESSION_NONE,
	    &opts, ((rRCOTextEntry *) (rcoNode->extra))->lang,
	    (rco->tblText->lastChild == rcoNode));
      }
    }
    // write label+event data
    header.pLabelData = rcowrite_ftell (&rcoH);
    if (rco->labelsLen)
      rco_fwrite (&rcoH, rco->labels, rco->labelsLen);
    header.pEventData = rcowrite_ftell (&rcoH);
    if (rco->eventsLen)
      rco_fwrite (&rcoH, rco->events, rco->eventsLen);
    else if (rco->tblObj || rco->tblAnim) {	// weird case: if there's
      // object entries, there will
      // be 4 bytes for events; I'll
      // assume this covers anim as
      // well (although there isn't
      // an RCO with anim that
      // doesn't have objects)
      uint32_t zero = 0;

      rco_fwrite (&rcoH, &zero, sizeof (zero));
      header.lEventData = sizeof (zero);
    }
    // the text pointer is weird in that if there's no text, it's set equal to
    // the label pointer; even weirder, some RCOs have a null pointer (for
    // FW5.00 all except lftv_* RCOs have null pointers for pTextData if
    // there's no text)
    // my theory: if compressing, it will be RCO_NULL_PTR, otherwise it'll =
    // header.pLabelData
    // if(!header.lTextData) header.pTextData = RCO_NULL_PTR;
    // if(!header.lTextData) header.pTextData = header.pLabelData;
    if (!header.lTextData)
      header.pTextData = (opts.packHeader ? RCO_NULL_PTR : header.pLabelData);
  }

  // flush compression stuff here
  HeaderComprInfo ci;

  if (opts.packHeader) {
    uint8_t *bufferOut = NULL;

    ci.lenLongestText = rcoH.longestLangData;
    ci.lenUnpacked = rcoH.tablesSize;
    ci.lenPacked = 0;

    if (opts.packHeader == RCO_DATA_COMPRESSION_ZLIB) {
      uint32_t bound = compressBound (rcoH.tablesSize);

      bufferOut = (uint8_t *) malloc (bound);
      ci.lenPacked =
	  zlib_compress (rcoH.tables, rcoH.tablesSize, bufferOut, bound,
	  opts.zlibLevel, opts.zlibMethod);
    } else if (opts.packHeader == RCO_DATA_COMPRESSION_RLZ) {
      bufferOut = (uint8_t *) malloc (rcoH.tablesSize);
      ci.lenPacked =
	  rlz_compress (rcoH.tables, rcoH.tablesSize, bufferOut,
	  rcoH.tablesSize, opts.rlzMode);
    } else {
      error ("lulwut?");
      exit (1);
    }
    int comprMisalign = ci.lenPacked % 4;
    uint32_t packedLen = ci.lenPacked;

    if (rco->eSwap)
      es_headerComprInfo (&ci);
    filewrite (rcoH.fp, &ci, sizeof (ci));
    filewrite (rcoH.fp, bufferOut, packedLen);
    free (bufferOut);

    if (comprMisalign) {	// 4 byte align
      uint32_t zero = 0;

      filewrite (rcoH.fp, &zero, 4 - comprMisalign);
    }
  }
  // write text if packing header
  if (opts.packText && rco->tblText && rco->tblText->numSubentries) {
    rRCOEntry *rcoNode;

    // header.pTextData = rcowrite_ftell(&rcoH);
    header.pTextData = ftell (rcoH.fp);
    header.lTextData = 0;	// rcoH.sizeText;
    for (rcoNode = rco->tblText->firstChild; rcoNode; rcoNode = rcoNode->next) {
      header.lTextData +=
	  rco_write_text_resource (&rcoH, rcoNode, opts.packHeader, &opts,
	  ((rRCOTextEntry *) (rcoNode->extra))->lang,
	  (rco->tblText->lastChild == rcoNode));
    }
  }
  // write resources
  /* { uint32_t totalPackedLen = 0; if(rco->tblImage) { header.pImgData =
   * rcowrite_ftell(&rcoH); header.lImgData = rcoH.sizeImg; // TOxDO: this
   * model actually won't work - we have to update the offsets of ALL the
   * entries after packing... for(i=0; i<rco->tblImage->numSubentries; i++) {
   * uint32_t packedSize = rco_write_resource(&rcoH,
   * &(rco->tblImage->subentries[i]), RCO_DATA_COMPRESSION_NONE); // TOxDO:
   * change this // TOxDO: update packed size value uint32_t curFpos =
   * rcowrite_ftell(rcoH.fp); totalPackedLen += (packedSize % 4 ?
   * (packedSize/4)*4+4 : packedSize); } header.lImgData = totalPackedLen; }
   * totalPackedLen = 0; if(rco->tblSound) { header.pSoundData =
   * rcowrite_ftell(&rcoH); header.lSoundData = rcoH.sizeSound; for(i=0;
   * i<rco->tblSound->numSubentries; i++) { totalPackedLen +=
   * rco_write_resource(&rcoH, &(rco->tblSound->subentries[i]),
   * RCO_DATA_COMPRESSION_NONE); if(totalPackedLen %4) totalPackedLen +=
   * 4-(totalPackedLen%4); } header.lSoundData = totalPackedLen; } // TOxDO:
   * write model resources } */

  if ((rco->tblImage && rco->tblImage->numSubentries)
      || (rco->tblSound && rco->tblSound->numSubentries)
      || (rco->tblModel && rco->tblModel->numSubentries)) {
    // update data pointers
    uint32_t pos = ftell (rcoH.fp);

    if (rco->tblImage && rco->tblImage->numSubentries) {
      header.pImgData = pos;
      pos += header.lImgData;
    }
    if (rco->tblSound && rco->tblSound->numSubentries) {
      header.pSoundData = pos;
      pos += header.lSoundData;
    }
    if (rco->tblModel && rco->tblModel->numSubentries) {
      header.pModelData = pos;
      pos += header.lModelData;
    }
    // copy contents of fTmp across (uses a simple buffered copy)
    uint32_t len = header.lImgData + header.lSoundData + header.lModelData;
    uint8_t buffer[65536];

    while (len) {
      uint32_t readAmt = (len > 65536 ? 65536 : len);

      fileread (fTmp, buffer, readAmt);
      filewrite (rcoH.fp, buffer, readAmt);
      len -= readAmt;
    }

    fclose (fTmp);		// this deletes our temp file
  }
  // fix header
  if (rco->tblVSMX)
    header.pVSMXTable = rco->tblVSMX->offset;
  if (rco->tblText)
    header.pTextTable = rco->tblText->offset;
  if (rco->tblSound)
    header.pSoundTable = rco->tblSound->offset;
  if (rco->tblModel)
    header.pModelTable = rco->tblModel->offset;
  if (rco->tblImage)
    header.pImgTable = rco->tblImage->offset;
  if (rco->tblFont)
    header.pFontTable = rco->tblFont->offset;
  if (rco->tblObj)
    header.pObjTable = rco->tblObj->offset;
  if (rco->tblAnim)
    header.pAnimTable = rco->tblAnim->offset;

  rewind (rcoH.fp);
  if (rco->eSwap)
    es_rcoHeader (&header);
  filewrite (rcoH.fp, &header, sizeof (header));

  // TODO: fix resource pointers?
  // TODO: tie things up etc??

  fclose (rcoH.fp);

  return TRUE;
}
Exemplo n.º 17
0
/**
 * Insert a file into the buffer at the point.
 * Leaves the point at the start of the inserted file.
 * @param buff The buffer to read the file into.
 * @param fname The file to read.
 * @param[out] compressed Was the file compressed? Only if ZLIB enabled. Can be NULL.
 * @return 0 on success, -1 on file error, 1 on zlib error.
 */
int breadfile(struct buff *buff, const char *fname, int *compressed)
{
	char buf[PGSIZE];
	struct mark start;
	int fd, len;

	fd = open(fname, O_RDONLY | O_BINARY);
	if (fd < 0)
		return -errno;

#if ZLIB
	gzFile gz = gzdopen(fd, "rb");

	if (!gz) {
		close(fd);
		return 1;
	}

	if (compressed)
		*compressed = gzdirect(gz) == 0;
#else
	if (compressed)
		*compressed = 0;
#endif

	/* Deal with point in the middle of a page. */
	if (curplen(buff) && buff->curchar < PGSIZE) {
		pagesplit(buff, buff->curchar);
		if (!newpage(buff->curpage))
			return -ENOMEM;
		makecur(buff, buff->curpage->nextp, 0);
	}

	bmrktopnt(buff, &start);

	while ((len = fileread(fd, buf, PGSIZE)) > 0) {
		if (curplen(buff)) {
			if (!newpage(buff->curpage)) {
				fileclose(fd);
				return -ENOMEM;
			}
			makecur(buff, buff->curpage->nextp, 0);
		}
		memcpy(buff->curcptr, buf, len);
		curplen(buff) = len;
	}
	fileclose(fd);

	bpnttomrk(buff, &start);

#if ZLIB
	/* Ubuntu 12.04 has a bug where zero length files are reported as
	 * compressed.
	 */
	if (compressed && curplen(buff) == 0)
		*compressed = 0;
#endif

	buff->bmodf = 0;

	return 0;
}
Exemplo n.º 18
0
/* *********************************************************************** */
edit_out()
{
	int		i,j;
	int		rdl;
	int		totins;			/* get total inserts */
	int		totdel;			/* get total deletes */
	unsigned char fmtwk[9];
	unsigned char timebuf[9];
	unsigned char *pnmwk;

	/* make sure we read the beginning */
	fileseek( Infile, (long)0 ) ;

	/* read into fci struct */
	if ( (rdl = fileread(Infile,&Fm,FCINSIZE) ) <=0)
	{
		disperr("COULD NOT READ %s",Pathbuf);
		return(-1);
	}
	
	charfill(&Bi,sizeof (Bi),' ');
	strncpy_s(Bi.drtdir, sizeof(Bi.drtdir), Fm.fc_drtdir, FILENMSZ);
	strncpy_s(Bi.dname, sizeof(Bi.dname), Fm.fc_dname, FILENMSZ);
	strncpy_s(Bi.dbtch, sizeof(Bi.dbtch), Fm.fc_dbtch, FILENMSZ);
	strncpy_s(Bi.frtdir, sizeof(Bi.frtdir), Fm.fc_frtdir, FILENMSZ);
	strncpy_s(Bi.fname, sizeof(Bi.fname), Fm.fc_fname, FILENMSZ);

	for( i=0 ; i < MAXMODES ; i++ )
	{
		Bi.stat[i] = Status[Fm.fc_stat[i]] ;
		Bi.dopen[i] = Fm.fc_dopen[i] ;
	}

	for( i=0 ; i < MAXIO ; i++ )
	{
		fmtstr(fmtwk,"%02d",Fm.fc_ioiter[i]);
		strncpy_s(Bi.ioiter[i], sizeof(Bi.ioiter[i]), fmtwk, 2);

		if( Fm.fc_iouid[i] > 0 )
		{
			fmtstr( fmtwk, "%03d", Fm.fc_iouid[i] ) ;
			strncpy_s(Bi.iouid[i], sizeof(Bi.iouid[i]), fmtwk, 3);
			if( ( pnmwk = getusrnam( Fm.fc_iouid[i] ) ) != (char *)ERRCODE )
			{
				strncpy_s(Bi.iouname[i], sizeof(Bi.iouname[i]), pnmwk, NMSZ);
			}
			else
			{
				charfill(Bi.iouname[i],NMSZ,'*');
			}
		}
		else
		{
			charfill(Bi.iouid[i],3,'*');
			charfill(Bi.iouname[i],NMSZ,'*');
		}
		Bi.iostatus[i] = Fm.fc_iostatus[i];
	}

	for (i=0; i< MAXMODES;i++)
	{
		fmtstr(fmtwk,"%05d",Fm.fc_rcntt[i]);
		strncpy_s(Bi.rcntt[i], sizeof(Bi.rcntt[i]), fmtwk, 5);

		fmtstr(fmtwk,"%05d",Fm.fc_dcntt[i]);
		strncpy_s(Bi.dcntt[i], sizeof(Bi.dcntt[i]), fmtwk, 5);

		fmtstr(fmtwk,"%08d",Fm.fc_kscntt[i]);
		strncpy_s(Bi.kscntt[i], sizeof(Bi.kscntt[i]), fmtwk, 8);

		fmtstr(fmtwk,"%08d",Fm.fc_kscnttf[i]);
		strncpy_s(Bi.kscnttf[i], sizeof(Bi.kscnttf[i]), fmtwk, 8);

		fmtstr(fmtwk,"%05d",Fm.fc_ercntt[i]);
		strncpy_s(Bi.ercntt[i], sizeof(Bi.ercntt[i]), fmtwk, 5);

		fmtstr(fmtwk,"%08d",Fm.fc_ekscntt[i]);
		strncpy_s(Bi.ekscntt[i],sizeof(Bi.ekscntt[i]) , fmtwk, 8);

		/* error k.s.count of function key */
		fmtstr(fmtwk,"%08d",Fm.fc_ekscnttf[i]);
		strncpy_s(Bi.ekscnttf[i], sizeof(Bi.ekscnttf[i]), fmtwk, 8);

		/* total flag count */
		fmtstr(fmtwk,"%05d",Fm.fc_flgcntt[i]);
		strncpy_s(Bi.flgcntt[i], sizeof(Bi.flgcntt[i]), fmtwk, 5);

		if (Fm.fc_fstime[i] == 0)
			charfill(Bi.fstime[i],24,'*');
		else
			timetostr(Fm.fc_fstime[i],Bi.fstime[i]);

		if (Fm.fc_strtime[i] == 0)
			charfill(Bi.strtime[i],24,'*');
		else
			timetostr(Fm.fc_strtime[i],Bi.strtime[i]);

		if (Fm.fc_lstime[i] == 0)
			charfill(Bi.lstime[i],24,'*');
		else
			timetostr(Fm.fc_lstime[i],Bi.lstime[i]);

		if (elapsed_time(i,timebuf) )   /* calculate total elapsed time */
			strncpy_s(Bi.eltimet[i], sizeof(Bi.eltimet[i]), timebuf, 8);
		else
			charfill(Bi.eltimet[i],8,'*');
	}

	/* # inserts, # deletes */
	totins = Fm.fc_mins[0] + Fm.fc_mins[1];	/* total inserts */
	totdel = Fm.fc_mdel[0] + Fm.fc_mdel[1];	/* total deletes */
	fmtstr(Bi.mins,"%05d",totins);
	fmtstr(Bi.mdel,"%05d",totdel);

	totins = Fm.fc_mdins[0] + Fm.fc_mdins[1];	/* total doc inserts */
	totdel = Fm.fc_mddel[0] + Fm.fc_mddel[1];	/* total doc deletes */
	fmtstr(Bi.mdins,"%05d",totins);
	fmtstr(Bi.mddel,"%05d",totdel);

	for (i=0; i< MAXMODES;i++)
	{
		for (j=0 ;j < MAXUSER;j++)
		{
			if (Fm.fc_muid[j][i] > 0)
		   {
			   fmtstr(fmtwk,"%03d",Fm.fc_muid[j][i]);
			   strncpy_s(Bi.muid[j][i], sizeof(Bi.muid[j][i]), fmtwk, 3);
			   if ( (pnmwk=getusrnam(Fm.fc_muid[j][i]) ) != (char *)ERRCODE)
				{
					strncpy_s(Bi.muidname[j][i], sizeof(Bi.muidname[j][i]), pnmwk, NMSZ);
				}
			     else
				{
					charfill(Bi.muidname[j][i],NMSZ,'*');
				}
			}
			else
			{
				charfill(Bi.muid[j][i],3,'*');
				charfill(Bi.muidname[j][i],NMSZ,'*');
			}
		}
	}

	Bi.sysfile = Fm.fc_sysfile;

	for (i=0; i< MAXMODES;i++)
	{
		fmtstr(fmtwk,"%05d",Fm.fc_iter[i]);
		strncpy_s(Bi.iter[i], sizeof(Bi.iter[i]), fmtwk, 5);
	}

	for (i=0; i< MAXIO;i++)
	{
		fmtstr(fmtwk,"%05d",Fm.fc_iositer[i]);
		strncpy_s(Bi.iositer[i], sizeof(Bi.iositer[i]), fmtwk, 5);

		fmtstr(fmtwk,"%05d",Fm.fc_iorcnt[i]);
		strncpy_s(Bi.iorcnt[i], sizeof(Bi.iorcnt[i]), fmtwk, 5);

		fmtstr(fmtwk,"%05d",Fm.fc_iodcnt[i]);
		strncpy_s(Bi.iodcnt[i], sizeof(Bi.iodcnt[i]), fmtwk, 5);

		if ( Fm.fc_iostime[i] == 0)
			charfill(Bi.iostime[i],24,'*');
		else
			timetostr(Fm.fc_iostime[i],Bi.iostime[i]);

		if (Fm.fc_ioetime[i] == 0)
			charfill(Bi.ioetime[i],24,'*');
		else
			timetostr(Fm.fc_ioetime[i],Bi.ioetime[i]);

		fmtstr(fmtwk,"%05d",Fm.fc_iopen[i]);
		strncpy_s(Bi.iopen[i], sizeof(Bi.iopen[i]), fmtwk, 5);
	}

	Bi.endmark= ' ';
	filewrite(BATCH_infof,&Bi,sizeof (Bi));
	filewrite(BATCH_infof,"\n",1);
	return( 0 ) ;
}
Exemplo n.º 19
0
/*Текст программы*/
int main(void)
{

OperationCode=accumulator=InstructionRegister=operand=0;
for (InstructionCounter=0; InstructionCounter<100; InstructionCounter++)
{
    memory[InstructionCounter][0]='+';
    for (i=1; i<5; i++)
    memory[InstructionCounter][i]='0';
}
n=0;
while (n!=5)
{
printf ("      \nПрограммная модель компьютера SC, выполняющего программы на языке SA \n\n");
printf ("\t\t\t   Выполнил: Красняков К.В. \n");
printf ("\t\t\t   Группа П-01, второй курс \n");
printf ("\t\t\t   Логин p01s11 \n\n\n");
printf ("[1] - Ввод данных с клавиатуры\n");
printf ("[2] - Ввод данных из файла\n");
printf ("[3] - Вывод дампа памяти на экран\n");
printf ("[4] - Вывод дампа памяти в файл\n");
printf ("[5] - Выход\n");
scanf ("%d", &n);

/*Ввод данных с клавиатуры*/
if (n==1)
{

   printf ("Введите значения: \n");
   for (InstructionCounter=0; InstructionCounter<100; InstructionCounter++)
   {
       input (InstructionCounter);
       if (memory[InstructionCounter][0]=='-' && memory[InstructionCounter][1]=='9' && memory[InstructionCounter][2]=='9' && memory[InstructionCounter][3]=='9' && memory[InstructionCounter][3]=='9')
       {
          printf ("Процесс ввода завершен \n");
          break;
       }
   }
}

/*Ввод данных из файла*/
if (n==2)
{
   printf ("Введите имя файла \n");
   scanf ("%s", &path);
   if ((f=fopen(path, "r"))==NULL)
    printf ("%s","Can't open file");
 else
 {
     for (InstructionCounter=0; InstructionCounter<100; InstructionCounter++)
     {
         fileread (InstructionCounter);
         if (memory[InstructionCounter][0]=='-' && memory[InstructionCounter][1]=='9' && memory[InstructionCounter][2]=='9' && memory[InstructionCounter][3]=='9' && memory[InstructionCounter][3]=='9')
         {
            printf ("Процесс ввода завершен \n");
            break;
         }
     }
 }
}

/*Вывод дампа памяти*/
if (n==3)
{
   printf ("\nДамп памяти:\n");
   for (InstructionCounter=0; InstructionCounter<100; InstructionCounter++)
   {

        if (InstructionCounter%10==0)
           printf ("\n");
        for (i=0; i<5; i++)
            printf ("%c", memory[InstructionCounter][i]);
        printf (" ");
   }
}

/*Вывод дампа памяти в файл*/
if (n==4)
{
   printf ("Введите имя файла \n");
   scanf ("%s", &path);
   f1=fopen(path, "w");
   for (InstructionCounter=0; InstructionCounter<100; InstructionCounter++)
   {

        if (InstructionCounter%10==0)
           fprintf (f1,"\n");
        for (i=0; i<5; i++)
            fprintf (f1,"%c", memory[InstructionCounter][i]);
        fprintf (f1," ");
   }
   printf ("Готово! \n");
}
/*Выход из програмы*/
if (n==5)
{
   fcloseall();
   exit(0);
}

/*Обработка введенных данных*/
if (n==1 || n==2)
{
InstructionCounter=0;
while (InstructionCounter<100)
{
    char2int (InstructionCounter);
        if (OperationCode==READ)
        {
           printf ("\nВведите значения: \n");
           input (operand);
        }
        else
            if (OperationCode==WRITE)
            {
               printf ("\nСлово ячейки %d: ", operand);
               for (i=0; i<5; i++)
                   printf ("%c",memory[operand][i]);
            }
            else
                if (OperationCode==LOAD)
                   accumulator=char2int(operand);
                else
                    if (OperationCode==STORE)
                    {  int2char(accumulator);
                       for (i=0; i<5; i++)
                           memory[operand][i]=c[i];
                     }
                     else
                         if (OperationCode==ADD)
                            accumulator+=char2int(operand);
                         else
                             if (OperationCode==SUBTRACT)
                                accumulator-=char2int(operand);
                             else
                                 if (OperationCode==DIVIDE)
                                 {
                                     if (char2int(operand)==0)
                                     {
                                        printf ("\nОшибка: Деление на 0\n");
                                        break;
                                     }
                                     else
                                         accumulator/=char2int(operand);
                                 }
                                 else
                                     if (OperationCode==MULTIPLY)
                                        accumulator*=char2int(operand);
                                     else
                                         if (OperationCode==BRANCH)
                                            InstructionCounter=operand-1;
                                         else
                                             if (OperationCode==BRANCHNEG)
                                             {
                                                if (accumulator<0)
                                                   InstructionCounter=operand-1;
                                             }
                                             else
                                                 if (OperationCode==BRANCHZERO)
                                                 {
                                                    if (accumulator==0)
                                                       InstructionCounter=operand-1;
                                                 }
                                                 else
                                                     if (OperationCode==HALT)
                                                        break;
                                                     else
                                                         if (OperationCode==SHR)
                                                         {
                                                            accumulator=char2int(operand);
                                                            accumulator=accumulator%1000*10;
                                                         }
                                                         else
                                                             if (char2int(InstructionCounter)>0)
                                                                printf ("\nНеизвестная команда в строке %d, возможно данные программы \n", InstructionCounter);
    InstructionCounter++;
}

/*Вывод дампа памяти на экран*/
printf ("\nДамп памяти:\n");
for (InstructionCounter=0; InstructionCounter<100; InstructionCounter++)
{
    if (InstructionCounter%10==0)
       printf ("\n");
    for (i=0; i<5; i++)
        printf ("%c", memory[InstructionCounter][i]);
    printf (" ");
}

}
delay(2000);
}
return (0);
}
Exemplo n.º 20
0
int main(int argc, char **argv)
{
	struct parseinfo 		parseTBL;
	int 					ret;
	int						i,j,k;
	char					inputFile[256];
	char 					*inputBuf = NULL;
	int						nbytes;
	FILE 					*fp;


	ret = load(&parseTBL);

	if(ret)
	{
		printf("\n%s:%d  load() returned 1.",__FILE__,__LINE__);
		printf("\nPerhaps the file has been deleted, renamed or moved.\n");
		exit(EXIT_FAILURE);
	}

	/* Print the parsing table */
	printf("\n\n************************************** PARSE TABLE ******************************************\n");

	printf("%10s","");
	for(i=0;i<parseTBL.termcount;i++)
	{
		printf(" %10s ",parseTBL.terminals[i]);
	}

	printf("\n\n");

	for(j=0 ; j<parseTBL.varcount ; j++)
	{
		printf("%10s",parseTBL.variables[j]);

		for(k=0;k<parseTBL.termcount;k++)
		{
			printf(" %10s ",parseTBL.actions[j][k]);
		}
		printf("\n");
	}



	printf("\nEnter name of the file you wish to parse>>");
	scanf("%s",inputFile);
	fp = fopen(inputFile,"r");
	if(!fp)
	{
		printf("\n%s:%d  ",__FILE__,__LINE__);
		perror(inputFile);
		exit(EXIT_FAILURE);
	}

	/*
	 * @TODO: Implement incremental read from input file.
	 * Perhaps through double buffering.
	 */
	fileread(&inputBuf, inputFile , &nbytes );

	for(i=0 ; i< nbytes-1 ; i++)
	{
		if(inputBuf[i] == '\t' || inputBuf[i] == '\n' )
		{
			inputBuf[i] = ' ';
		}

		if(inputBuf[i] == '$')
		{
			inputBuf[i+1] = '\0';
		}
	}





	ret = parse(parseTBL,inputBuf);

	if(ret == 0)
	{
		printf("\nParsing completed successfully.");
	}

	else if(ret == 1)
	{
		printf("\n%s:%d  Function parse() returned %d.Parse could not complete",__FILE__,__LINE__,ret);
		exit(EXIT_FAILURE);
	}


	printf("\n*** HAPPY HAPPY JOY JOY! ***\n");
	exit(EXIT_SUCCESS);
}
Exemplo n.º 21
0
void interface::on_actionLoad_triggered()
{
    QString filename;
    QString fileopen=QFileDialog::getOpenFileName(this,"load data","","Gea Tuning data (*.gea)");
    if(fileopen.isEmpty()){return;}
    filename=fileopen;

    QFile filestream(filename);

    if(!filestream.open(QFile::ReadOnly|QFile::Text)){
        QMessageBox::critical(this,"Failed","File failed to open");
        return;
    }

    QTextStream fileread(&filestream);
    ui->txtCommData->clear();

    while(!fileread.atEnd()){
        QString received=fileread.readAll();
        ui->txtCommData->insertPlainText(received);
    }

    filestream.flush();
    filestream.close();

    QStringList datalines = ui->txtCommData->toPlainText().split("\n");

    QString tpsline= datalines[0];
    QStringList lsttpsline = tpsline.split(",");
    ui->txtTPSOff->setText(lsttpsline[0]);
    ui->txtTPSFull->setText(lsttpsline[1]);

    QString injecline = datalines[1];
    QStringList lstinjecline = injecline.split(",");
    ui->txtBaseMs->setText(lstinjecline[0]);
    ui->txtOpenMs->setText(lstinjecline[1]);

    int i,j;

    for(i=0;i<cdata;i++){
        QString injline = datalines[2+i];
        QStringList lstinjline = injline.split(",");
        for(j=0;j<cdata;j++){
            QTableWidgetItem* tbl_item = new QTableWidgetItem();
            tbl_item->setText(lstinjline[j]);
            ui->tblInj->setItem(i,j,tbl_item);
        }
    }

    for(i=0;i<cdata;i++){
        QString ignline = datalines[14+i];
        QStringList lstignline = ignline.split(",");
        for(j=0;j<cdata;j++){
            QTableWidgetItem* tbl_item = new QTableWidgetItem();
            tbl_item->setText(lstignline[j]);
            ui->tblIgn->setItem(i,j,tbl_item);
        }
    }

    ui->txtCommData->clear();
}
Exemplo n.º 22
0
int main (int argc, char **argv)
{

  /* DADA Logger */ 
  multilog_t* log = 0;

  /* Interface on which to listen for udp packets */
  char * interface = "any";

  /* port for control commands */
  int control_port = 0;

  /* port for incoming UDP packets */
  int inc_port = LEDA_DEFAULT_UDPDB_PORT;

  /* multilog output port */
  int l_port = LEDA_DEFAULT_PWC_LOGPORT;

  /* Flag set in daemon mode */
  char daemon = 0;

  /* Flag set in verbose mode */
  int verbose = 0;

  /* number of seconds/bytes to acquire for */
  unsigned nsecs = 0;

  /* actual struct with info */
  udpdb_t udpdb;

  /* custom header from a file, implies no controlling pwcc */
  char * header_file = NULL;

  /* Pointer to array of "read" data */
  char *src;

  /* Ignore dropped packets */
  unsigned ignore_dropped = 0;

  // default shared memory key
  key_t dada_key = DADA_DEFAULT_BLOCK_KEY;

  // DADA Header + Data unit
  dada_hdu_t * hdu = 0;

  int arg = 0;

  int cpu_core = -1;

  unsigned int num_inputs = 1;

  /* statistics thread */
  pthread_t stats_thread_id;

  /* control thread */
  pthread_t control_thread_id;

  /* receiving thread */
  pthread_t receiving_thread_id;

  while ((arg=getopt(argc,argv,"b:c:df:i:k:l:n:p:t:vh")) != -1) {
    switch (arg) {

    case 'b':
      cpu_core = atoi(optarg);
      break; 

    case 'c':
      control_port = atoi(optarg);
      break; 

    case 'd':
      daemon = 1;
      break; 

    case 'f':
      header_file = strdup(optarg);
      break; 

    case 'k':
      if (sscanf (optarg, "%x", &dada_key) != 1) {
        fprintf (stderr, "dada_db: could not parse key from %s\n", optarg);
        return -1;
      }
      break;

    case 'i':
      if (optarg)
        interface = optarg;
      break;
    
    case 'l':
      if (optarg) {
        l_port = atoi(optarg);
        break;
      } else {
        usage();
        return EXIT_FAILURE;
      }

    case 'n':
      num_inputs = atoi(optarg);
      break;

    case 'p':
      inc_port = atoi (optarg);
      break;

    case 't':
      nsecs = atoi (optarg);
      break;

    case 'v':
      verbose++;
      break;

    case 'h':
      usage();
      return 0;
      
    default:
      usage ();
      return 0;
      
    }
  }
  
  char * obs_header = 0;

  if (!control_port && !header_file)
  {
    fprintf(stderr, "ERROR: no control port or header file specified\n");
    usage();
    exit(EXIT_FAILURE);
  }

  // check the command line arguments
  if (header_file != NULL)
  {
    obs_header = (char *) malloc(sizeof(char) * DADA_DEFAULT_HEADER_SIZE);
    if (!obs_header)
    {
      fprintf (stderr, "could not allocate memory\n");
      return (EXIT_FAILURE);
    }
    
    // read the ASCII DADA header from the file
    if (fileread (header_file, obs_header, DADA_DEFAULT_HEADER_SIZE) < 0)
    {
      free (obs_header);
      fprintf (stderr, "ERROR: could not read ASCII header from %s\n", header_file);
      return (EXIT_FAILURE);
    }
  }
    

  int i = 0;
  int rval = 0;
  void* result = 0;

  log = multilog_open ("leda_udpdb_thread", 0);

  if (daemon)
    be_a_daemon ();
  else
    multilog_add (log, stderr);
  udpdb.log = log;

  // initialize the data structure
  multilog (log, LOG_INFO, "main: leda_udpdb_init_receiver()\n");
  if (leda_udpdb_init_receiver (&udpdb) < 0)
  {
    multilog (log, LOG_ERR, "could not initialize socket\n");
    return EXIT_FAILURE;
  }

  udpdb.verbose = verbose;
  udpdb.port = inc_port;
  udpdb.recv_core = cpu_core;
  udpdb.interface = strdup(interface);
  udpdb.control_port = control_port;
  udpdb.packets_per_buffer = 0;
  udpdb.bytes_to_acquire = -1;
  udpdb.num_inputs = num_inputs;

  multilog (log, LOG_INFO, "main: dada_create_hdu()\n");

  // create the HDU struct
  hdu = dada_hdu_create (log);

  // set the key to connecting to the HDU
  dada_hdu_set_key (hdu, dada_key);

  // connect to HDU
  if (dada_hdu_connect (hdu) < 0)
  {
    multilog (log, LOG_ERR, "could not connect to hdu\n");
    return EXIT_FAILURE;
  }
  udpdb.hdu = hdu;

  // determine block size of the data block
  udpdb.hdu_bufsz = ipcbuf_get_bufsz ((ipcbuf_t *) hdu->data_block);

  // determine number of packets per block, must 
  if (udpdb.hdu_bufsz % UDP_DATA != 0)
  {
    multilog (log, LOG_ERR, "data block size for [%"PRIu64"] was not "
              "a multiple of the UDP_DATA size [%d]\n", udpdb.hdu_bufsz, UDP_DATA);
    return EXIT_FAILURE;
  }
  udpdb.packets_per_buffer = udpdb.hdu_bufsz / UDP_DATA;
  if (udpdb.verbose)
    multilog (udpdb.log, LOG_INFO, "main: HDU bufsz=%"PRIu64", UDP_DATA=%d, packets_per_buffer=%"PRIu64"\n", 
                                  udpdb.hdu_bufsz, UDP_DATA, udpdb.packets_per_buffer);


  if (verbose)
    multilog(log, LOG_INFO, "main: leda_udpdb_prepare()\n");
  if (leda_udpdb_prepare (&udpdb) < 0)
  {
    multilog(log, LOG_ERR, "could allocate required resources\n");
    return EXIT_FAILURE;
  }

  signal(SIGINT, signal_handler);

  // start the control thread
  if (control_port) 
  {
    if (verbose)
      multilog(log, LOG_INFO, "starting control_thread()\n");
    rval = pthread_create (&control_thread_id, 0, (void *) control_thread, (void *) &udpdb);
    if (rval != 0) {
      multilog(log, LOG_INFO, "Error creating control_thread: %s\n", strerror(rval));
      return -1;
    }
  }

  if (verbose)
    multilog(log, LOG_INFO, "starting stats_thread()\n");
  rval = pthread_create (&stats_thread_id, 0, (void *) stats_thread, (void *) &udpdb);
  if (rval != 0) {
    multilog(log, LOG_INFO, "Error creating stats_thread: %s\n", strerror(rval));
    return -1;
  }

  // main control loop
  while (!quit_threads) 
  {
    if (verbose)
      multilog(log, LOG_INFO, "main: leda_udpdb_reset_receiver()\n");
    leda_udpdb_reset_receiver (&udpdb);

    // wait for a START command before initialising receivers
    while (!start_pending && !quit_threads && control_port) 
      usleep(100000);

    if (quit_threads)
      break;

    // if header was supplied via text file, begin immediately
    if (header_file)
    {
      if (verbose)
        multilog(log, LOG_INFO, "main: leda_udpdb_start()\n");
      time_t utc = leda_udpdb_start (&udpdb, obs_header);
      if (utc == -1 ) {
        multilog(log, LOG_ERR, "Could not run start function\n");
        return EXIT_FAILURE;
      }
    }

    /* set the total number of bytes to acquire */
    udpdb.bytes_to_acquire = 1600 * 1000 * 1000 * (int64_t) nsecs;

    if (verbose)
    { 
      if (udpdb.bytes_to_acquire) 
        multilog(log, LOG_INFO, "bytes_to_acquire = %"PRIu64" Million Bytes, nsecs=%d\n", udpdb.bytes_to_acquire/1000000, nsecs);
      else
        multilog(log, LOG_INFO, "Acquiring data indefinitely\n");
    }

    //rval = pthread_create (&receiving_thread_id, &recv_attr, (void *) leda_udpdb_receive_obs , (void *) &udpdb);
    if (verbose)
      multilog(log, LOG_INFO, "starting leda_udpdb_receive_obs thread\n");
    rval = pthread_create (&receiving_thread_id, 0, (void *) leda_udpdb_receive_obs , (void *) &udpdb);
    if (rval != 0) {
      multilog(log, LOG_INFO, "Error creating leda_udpdb_receive_obs thread: %s\n", strerror(rval));
      return -1;
    }

    if (verbose) 
      multilog(log, LOG_INFO, "joining leda_udpdb_receive_obs thread\n");
    pthread_join (receiving_thread_id, &result);

    if (verbose) 
      multilog(log, LOG_INFO, "udpdb_stop_function\n");
    if ( udpdb_stop_function(&udpdb) != 0)
      fprintf(stderr, "Error stopping acquisition");


    if (!control_port)
      quit_threads = 1;

  }

  if (control_port)
  {
    if (verbose)
      multilog(log, LOG_INFO, "joining control_thread\n");
    pthread_join (control_thread_id, &result);
  }

  if (verbose)
    multilog(log, LOG_INFO, "joining stats_thread\n");
  pthread_join (stats_thread_id, &result);

  // clean up memory 
  if ( leda_udpdb_destroy_receiver (&udpdb) < 0) 
    fprintf(stderr, "failed to clean up receivers\n");

  // disconnect from HDU
  if (dada_hdu_disconnect (hdu) < 0)
    multilog (log, LOG_ERR, "could not unlock write on hdu\n");

  return EXIT_SUCCESS;
}