• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Fopen函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Fopen函数的典型用法代码示例。如果您正苦于以下问题:C++ Fopen函数的具体用法?C++ Fopen怎么用?C++ Fopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Fopen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: store

// puts file from client into memory and directory
int store(rio_t *rio, int connfd)
{
	size_t num; 
	char nameBuf[NAME_SIZE]; 
	char FileName[NAME_SIZE]; 
	char FileSize[4];
	unsigned int filesize, netOrder, stat, replySize; 
	char data_in_file[FILE_SIZE];
	char  *data, *reply; 
	FILE *file; 
	unsigned int maxBytes = 4; 

	if((num = Rio_readnb(rio, nameBuf, NAME_SIZE)) == NAME_SIZE) 
	{
        memcpy(&FileName, &nameBuf, NAME_SIZE);
        printf("Filename  = %s\n", FileName);
    } 
    else 
    {
        printf("Filename  = NONE\n");
        stat = -1;
    }

    if((num = Rio_readnb(rio,FileSize,maxBytes)) == maxBytes)
    {
    	memcpy(&netOrder,&FileSize,maxBytes);
    	filesize = ntohl(netOrder); 
    }
    else
    {
    	stat = -1; 
    }

    if((num = Rio_readnb(rio,data_in_file,filesize)) == filesize)
    {
    	data = (char*) malloc(sizeof(char)*filesize); 

    	if(data == NULL)
    	{
    		fprintf(stderr, "Memory Error\n"); 
    		return -1; 
    	}

    	memcpy(data,&data_in_file,filesize);
    }
    else
    {
    	stat = -1; 
    }

    if((file = Fopen(nameBuf,"w")) != NULL)
    {
    	Fwrite(data, sizeof(char), filesize, file);
    	Fclose(file); 

    	if(addFileList(FileName) == 0)
    	{
    		stat = 0; 
    	} 
    	else
    	{
    		stat = -1; 
    	}
    }
    else
    {
    	stat = -1; 
    }

    free(data); 
    unsigned int currStat = 4; 
    replySize = currStat;

    reply = (char*) malloc (sizeof(char*)*replySize);
    if(reply == NULL) { fprintf(stderr, "Memory Error\n"); return -1; }
    char *replyBuf = reply;

    
    netOrder = htonl(stat);
    memcpy(replyBuf, &netOrder, currStat);
    replyBuf += currStat;

    Rio_writen(connfd, reply, replySize);
    free(reply);

    return stat;

}
开发者ID:Mnho229,项目名称:cs485project5,代码行数:89,代码来源:server.c


示例2: edstop

/*
 * Terminate an editing session by attempting to write out the user's
 * file from the temporary.  Save any new stuff appended to the file.
 */
void
edstop(void)
{
	int gotcha, c;
	struct message *mp;
	FILE *obuf, *ibuf, *readstat;
	struct stat statb;
	char tempname[PATHSIZE];

	if (readonly)
		return;
	holdsigs();
	if (Tflag != NULL) {
		if ((readstat = Fopen(Tflag, "w")) == NULL)
			Tflag = NULL;
	}
	for (mp = &message[0], gotcha = 0; mp < &message[msgCount]; mp++) {
		if (mp->m_flag & MNEW) {
			mp->m_flag &= ~MNEW;
			mp->m_flag |= MSTATUS;
		}
		if (mp->m_flag & (MODIFY|MDELETED|MSTATUS))
			gotcha++;
		if (Tflag != NULL && (mp->m_flag & (MREAD|MDELETED)) != 0) {
			char *id;

			if ((id = hfield("article-id", mp)) != NULL)
				fprintf(readstat, "%s\n", id);
		}
	}
	if (Tflag != NULL)
		(void)Fclose(readstat);
	if (!gotcha || Tflag != NULL)
		goto done;
	ibuf = NULL;
	if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) {
		int fd;

		(void)snprintf(tempname, sizeof(tempname),
		    "%s/mbox.XXXXXXXXXX", tmpdir);
		if ((fd = mkstemp(tempname)) == -1 ||
		    (obuf = Fdopen(fd, "w")) == NULL) {
			warn("%s", tempname);
			relsesigs();
			reset(0);
		}
		if ((ibuf = Fopen(mailname, "r")) == NULL) {
			warn("%s", mailname);
			(void)Fclose(obuf);
			(void)rm(tempname);
			relsesigs();
			reset(0);
		}
		(void)fseeko(ibuf, mailsize, SEEK_SET);
		while ((c = getc(ibuf)) != EOF)
			(void)putc(c, obuf);
		(void)Fclose(ibuf);
		(void)Fclose(obuf);
		if ((ibuf = Fopen(tempname, "r")) == NULL) {
			warn("%s", tempname);
			(void)rm(tempname);
			relsesigs();
			reset(0);
		}
		(void)rm(tempname);
	}
	printf("\"%s\" ", mailname);
	(void)fflush(stdout);
	if ((obuf = Fopen(mailname, "r+")) == NULL) {
		warn("%s", mailname);
		relsesigs();
		reset(0);
	}
	trunc(obuf);
	c = 0;
	for (mp = &message[0]; mp < &message[msgCount]; mp++) {
		if ((mp->m_flag & MDELETED) != 0)
			continue;
		c++;
		if (sendmessage(mp, obuf, NULL, NULL) < 0) {
			warnx("%s", mailname);
			relsesigs();
			reset(0);
		}
	}
	gotcha = (c == 0 && ibuf == NULL);
	if (ibuf != NULL) {
		while ((c = getc(ibuf)) != EOF)
			(void)putc(c, obuf);
		(void)Fclose(ibuf);
	}
	(void)fflush(obuf);
	if (ferror(obuf)) {
		warn("%s", mailname);
		relsesigs();
		reset(0);
//.........这里部分代码省略.........
开发者ID:mulichao,项目名称:freebsd,代码行数:101,代码来源:quit.c


示例3: Fopen

int GModel::readSTL(const std::string &name, double tolerance)
{
  FILE *fp = Fopen(name.c_str(), "rb");
  if(!fp){
    Msg::Error("Unable to open file '%s'", name.c_str());
    return 0;
  }

  // store triplets of points for each solid found in the file
  std::vector<std::vector<SPoint3> > points;
  SBoundingBox3d bbox;

  // "solid", or binary data header
  char buffer[256];
  if(!fgets(buffer, sizeof(buffer), fp)){ fclose(fp); return 0; }

  bool binary = strncmp(buffer, "solid", 5) && strncmp(buffer, "SOLID", 5);

  // ASCII STL
  if(!binary){
    points.resize(1);
    while(!feof(fp)) {
      // "facet normal x y z" or "endsolid"
      if(!fgets(buffer, sizeof(buffer), fp)) break;
      if(!strncmp(buffer, "endsolid", 8) ||
         !strncmp(buffer, "ENDSOLID", 8)){
        // "solid"
        if(!fgets(buffer, sizeof(buffer), fp)) break;
        if(!strncmp(buffer, "solid", 5) ||
           !strncmp(buffer, "SOLID", 5)){
          points.resize(points.size() + 1);
          // "facet normal x y z"
          if(!fgets(buffer, sizeof(buffer), fp)) break;
        }
      }
      // "outer loop"
      if(!fgets(buffer, sizeof(buffer), fp)) break;
      // "vertex x y z"
      for(int i = 0; i < 3; i++){
        if(!fgets(buffer, sizeof(buffer), fp)) break;
        char s1[256];
        double x, y, z;
        if(sscanf(buffer, "%s %lf %lf %lf", s1, &x, &y, &z) != 4) break;
        SPoint3 p(x, y, z);
        points.back().push_back(p);
        bbox += p;
      }
      // "endloop"
      if(!fgets(buffer, sizeof(buffer), fp)) break;
      // "endfacet"
      if(!fgets(buffer, sizeof(buffer), fp)) break;
    }
   }

  // check if we could parse something
  bool empty = true;
  for(unsigned int i = 0; i < points.size(); i++){
    if(points[i].size()){
      empty = false;
      break;
    }
  }
  if(empty) points.clear();

  // binary STL (we also try to read in binary mode if the header told
  // us the format was ASCII but we could not read any vertices)
  if(binary || empty){
    if(binary)
      Msg::Info("Mesh is in binary format");
    else
      Msg::Info("Wrong ASCII header or empty file: trying binary read");
    rewind(fp);
    while(!feof(fp)) {
      char header[80];
      if(!fread(header, sizeof(char), 80, fp)) break;
      unsigned int nfacets = 0;
      size_t ret = fread(&nfacets, sizeof(unsigned int), 1, fp);
      bool swap = false;
      if(nfacets > 100000000){
        Msg::Info("Swapping bytes from binary file");
        swap = true;
        SwapBytes((char*)&nfacets, sizeof(unsigned int), 1);
      }
      if(ret && nfacets){
        points.resize(points.size() + 1);
        char *data = new char[nfacets * 50 * sizeof(char)];
        ret = fread(data, sizeof(char), nfacets * 50, fp);
        if(ret == nfacets * 50){
          for(unsigned int i = 0; i < nfacets; i++) {
            float *xyz = (float *)&data[i * 50 * sizeof(char)];
            if(swap) SwapBytes((char*)xyz, sizeof(float), 12);
            for(int j = 0; j < 3; j++){
              SPoint3 p(xyz[3 + 3 * j], xyz[3 + 3 * j + 1], xyz[3 + 3 * j + 2]);
              points.back().push_back(p);
              bbox += p;
            }
          }
        }
        delete [] data;
      }
//.........这里部分代码省略.........
开发者ID:feelpp,项目名称:debian-gmsh,代码行数:101,代码来源:GModelIO_STL.cpp


示例4: Fopen

void elasticitySolver::readInputFile(const std::string &fn)
{
  FILE *f = Fopen(fn.c_str(), "r");
  if(!f) {
    Msg::Error("Could not open file '%s'", fn.c_str());
    return;
  }
  char what[256];
  while(!feof(f)) {
    if(fscanf(f, "%s", what) != 1) {
      fclose(f);
      return;
    }
    if(what[0] == '#') {
      char buffer[1024];
      if(fgets(buffer, sizeof(buffer), f) == NULL)
        Msg::Error("Cannot read line.");
    }
    else if(!strcmp(what, "ElasticDomain")) {
      elasticField field;
      int physical;
      if(fscanf(f, "%d %lf %lf", &physical, &field._e, &field._nu) != 3) {
        fclose(f);
        return;
      }
      field._tag = _tag;
      field.g = new groupOfElements(_dim, physical);
      elasticFields.push_back(field);
    }
    else if(!strcmp(what, "LagrangeMultipliers")) {
      LagrangeMultiplierField field;
      int physical;
      double d1, d2, d3, val;
      if(fscanf(f, "%d %lf %lf %lf %lf %lf %d", &physical, &field._tau, &d1,
                &d2, &d3, &val, &field._tag) != 7) {
        fclose(f);
        return;
      }
      SVector3 sv(d1, d2, d3);
      field._d = sv.unit();
      field._f = new simpleFunction<double>(val);
      field.g = new groupOfElements(_dim - 1, physical);
      LagrangeMultiplierFields.push_back(field);
      LagrangeMultiplierSpaces.push_back(
        new ScalarLagrangeFunctionSpaceOfElement(field._tag));
    }
    else if(!strcmp(what, "Void")) {
      elasticField field;
      int physical;
      if(fscanf(f, "%d", &physical) != 1) {
        fclose(f);
        return;
      }
      field._e = field._nu = 0;
      field.g = new groupOfElements(_dim, physical);
      field._tag = 0;
      elasticFields.push_back(field);
    }
    else if(!strcmp(what, "NodeDisplacement")) {
      double val;
      int node, comp;
      if(fscanf(f, "%d %d %lf", &node, &comp, &val) != 3) {
        fclose(f);
        return;
      }
      dirichletBC diri;
      diri.g = new groupOfElements(0, node);
      diri._f = new simpleFunction<double>(val);
      diri._comp = comp;
      diri._tag = node;
      diri.onWhat = BoundaryCondition::ON_VERTEX;
      allDirichlet.push_back(diri);
    }
    else if(!strcmp(what, "EdgeDisplacement")) {
      double val;
      int edge, comp;
      if(fscanf(f, "%d %d %lf", &edge, &comp, &val) != 3) {
        fclose(f);
        return;
      }
      dirichletBC diri;
      diri.g = new groupOfElements(1, edge);
      diri._f = new simpleFunction<double>(val);
      diri._comp = comp;
      diri._tag = edge;
      diri.onWhat = BoundaryCondition::ON_EDGE;
      allDirichlet.push_back(diri);
    }
    else if(!strcmp(what, "FaceDisplacement")) {
      double val;
      int face, comp;
      if(fscanf(f, "%d %d %lf", &face, &comp, &val) != 3) {
        fclose(f);
        return;
      }
      dirichletBC diri;
      diri.g = new groupOfElements(2, face);
      diri._f = new simpleFunction<double>(val);
      diri._comp = comp;
      diri._tag = face;
//.........这里部分代码省略.........
开发者ID:live-clones,项目名称:gmsh,代码行数:101,代码来源:elasticitySolver.cpp


示例5: replaceCommaByDot

int GModel::readPLY(const std::string &name)
{
  // this is crazy!?
  replaceCommaByDot(name);

  FILE *fp = Fopen(name.c_str(), "r");
  if(!fp){
    Msg::Error("Unable to open file '%s'", name.c_str());
    return 0;
  }

  std::vector<MVertex*> vertexVector;
  std::map<int, std::vector<MElement*> > elements[5];
  std::map<int, std::vector<double> > properties;

  char buffer[256], str[256], str2[256], str3[256];
  std::string s1;
  int elementary = getMaxElementaryNumber(-1) + 1;
  int nbv, nbf;
  int nbprop = 0;
  int nbView = 0;
  std::vector<std::string> propName;
  while(!feof(fp)) {
    if(!fgets(buffer, sizeof(buffer), fp)) break;
    if(buffer[0] != '#'){ // skip comments
      sscanf(buffer, "%s %s", str, str2);
      if(!strcmp(str, "element") && !strcmp(str2, "vertex")){
	sscanf(buffer, "%s %s %d", str, str2, &nbv);
      }
      if(!strcmp(str, "format") && strcmp(str2, "ascii")){
	Msg::Error("Only reading of ascii PLY files implemented");
        fclose(fp);
	return 0;
      }
      if(!strcmp(str, "property") && strcmp(str2, "list")){
	nbprop++;
	sscanf(buffer, "%s %s %s", str, str2, str3);
	if (nbprop > 3) propName.push_back(s1+str3);
      }
      if(!strcmp(str, "element") && !strcmp(str2, "face")){
	sscanf(buffer, "%s %s %d", str, str2, &nbf);
      }
      if(!strcmp(str, "end_header")){
	nbView = nbprop -3;
	Msg::Info("%d elements", nbv);
	Msg::Info("%d triangles", nbf);
	Msg::Info("%d properties", nbView);

	vertexVector.resize(nbv);
	for(int i = 0; i < nbv; i++) {
	  double x,y,z;
	  char line[10000], *pEnd, *pEnd2, *pEnd3;
	  if(!fgets(line, sizeof(line), fp)){ fclose(fp); return 0; }
	  x = strtod(line, &pEnd);
	  y = strtod(pEnd, &pEnd2);
	  z = strtod(pEnd2, &pEnd3);
	  vertexVector[i] = new MVertex(x, y, z);

	  pEnd = pEnd3;
          std::vector<double> prop(nbView);
	  for (int k = 0; k < nbView; k++){
	    prop[k]=strtod(pEnd, &pEnd2);
	    pEnd = pEnd2;
	    properties[k].push_back(prop[k]);
	  }
	}

	for(int i = 0; i < nbf; i++) {
	  if(!fgets(buffer, sizeof(buffer), fp)) break;
	  int n[3], nbe;
	  sscanf(buffer, "%d %d %d %d", &nbe, &n[0], &n[1], &n[2]);
	  std::vector<MVertex*> vertices;
	  if(!getVertices(3, n, vertexVector, vertices)){ fclose(fp); return 0; }
	  elements[0][elementary].push_back(new MTriangle(vertices));
	}

      }

    }
  }

  for(int i = 0; i < (int)(sizeof(elements) / sizeof(elements[0])); i++)
    _storeElementsInEntities(elements[i]);
  _associateEntityWithMeshVertices();
  _storeVerticesInEntities(vertexVector);

#if defined(HAVE_POST)
  // create PViews here
  std::vector<GEntity*> _entities;
  getEntities(_entities);
  for (int iV=0; iV< nbView; iV++){
    PView *view = new PView();
    PViewDataList *data = dynamic_cast<PViewDataList*>(view->getData());
    for(unsigned int ii = 0; ii < _entities.size(); ii++){
	for(unsigned int i = 0; i < _entities[ii]->getNumMeshElements(); i++){
	  MElement *e = _entities[ii]->getMeshElement(i);
	  int numNodes = e->getNumVertices();
	  std::vector<double> x(numNodes), y(numNodes), z(numNodes);
	  std::vector<double> *out = data->incrementList(1, e->getType());
	  for(int nod = 0; nod < numNodes; nod++) out->push_back((e->getVertex(nod))->x());
//.........这里部分代码省略.........
开发者ID:fmach,项目名称:agros2d,代码行数:101,代码来源:GModelIO_PLY.cpp


示例6: LoadSrcModule

/*
	Load a source module
*/
short LoadSrcModule(short module)
{
	FILE *f;
	char *lp;
	int l,n,lc=0;
	short handle;

	if (cur_module==module)
		return TRUE;
		
	if (src_buf)
	{
		free(src_buf);
		src_buf=NULL;
	}

	if (src)
	{
		free(src);
		src=NULL;
	}
	
	f=fopen(dtab[module].full_path,"r");
	if (!f)
	{
		printf("**source file not found %s\n",dtab[module].full_path);
		return FALSE;
	}
	fseek(f,0L,2);		/* get file size */
	l=ftell(f);
	fseek(f,0L,0);
	fclose(f);
	
	src_buf=(char*)malloc(l*2);
	if (!src_buf)
	{
		printf("**error, out of memory\n");
		return NULL;
	}
	
	handle=(short)Fopen(dtab[module].full_path,O_RDONLY);
	Fread(handle,l,src_buf);
	Fclose(handle);
	
	for(n=0; n<l+1; n++)	
	{
		if(src_buf[n]=='\n')
			lc++;
	}
	
	src_lc=lc;
	src=(char**)malloc(sizeof(char**)*lc);

	n=0; lc=0;
	for(lp=src_buf; n<l+1; n++)
	{
		if(src_buf[n]=='\n')
		{
			src[lc]=lp;
			src_buf[n]='\0';
			lp=src_buf+n+1;			
			lc++;
			if (*lp=='\r')
				lp++;
		}
	}
	
	cur_module=module;
	
	fclose(f);
	
	return TRUE;	
}
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:76,代码来源:DEBUG.C


示例7: Fopen

int GModel::readMESH(const std::string &name)
{
  FILE *fp = Fopen(name.c_str(), "r");
  if(!fp){
    Msg::Error("Unable to open file '%s'", name.c_str());
    return 0;
  }

  char buffer[256];
  if(!fgets(buffer, sizeof(buffer), fp)){ fclose(fp); return 0; }

  char str[256];
  int format;
  sscanf(buffer, "%s %d", str, &format);
  if(format == 3){
    Msg::Error("Medit mesh import only available for ASCII files");
    fclose(fp);
    return 0;
  }

  std::vector<MVertex*> vertexVector;
  std::map<int, std::vector<MElement*> > elements[5];

  while(!feof(fp)) {
    if(!fgets(buffer, 256, fp)) break;
    if(buffer[0] != '#'){ // skip comments and empty lines
      str[0]='\0';
      sscanf(buffer, "%s", str);
      if(!strncmp(buffer, "Dimension 3", 11)){
        // alternative single-line 'Dimension' field used by CGAL
      }
      else if(!strcmp(str, "Dimension")){
        if(!fgets(buffer, sizeof(buffer), fp)) break;
      }
      else if(!strcmp(str, "Vertices")){
        if(!fgets(buffer, sizeof(buffer), fp)) break;
        int nbv;
        sscanf(buffer, "%d", &nbv);
        Msg::Info("%d vertices", nbv);
        vertexVector.resize(nbv);
        for(int i = 0; i < nbv; i++) {
          if(!fgets(buffer, sizeof(buffer), fp)) break;
          int dum;
          double x, y, z;
          sscanf(buffer, "%lf %lf %lf %d", &x, &y, &z, &dum);
          vertexVector[i] = new MVertex(x, y, z);
        }
      }
      else if(!strcmp(str, "Edges")){
        if(!fgets(buffer, sizeof(buffer), fp)) break;
        int nbe;
        sscanf(buffer, "%d", &nbe);
        Msg::Info("%d edges", nbe);
        for(int i = 0; i < nbe; i++) {
          if(!fgets(buffer, sizeof(buffer), fp)) break;
          int n[2], cl;
          sscanf(buffer, "%d %d %d", &n[0], &n[1], &cl);
          for(int j = 0; j < 2; j++) n[j]--;
          std::vector<MVertex*> vertices;
          if(!getVertices(2, n, vertexVector, vertices)){ fclose(fp); return 0; }
          elements[0][cl].push_back(new MLine(vertices));
        }
      }
      else if(!strcmp(str, "EdgesP2")){
        if(!fgets(buffer, sizeof(buffer), fp)) break;
        int nbe;
        sscanf(buffer, "%d", &nbe);
        Msg::Info("%d edges", nbe);
        for(int i = 0; i < nbe; i++) {
          if(!fgets(buffer, sizeof(buffer), fp)) break;
          int n[3], cl;
          sscanf(buffer, "%d %d %d %d", &n[0], &n[1], &n[2], &cl);
          for(int j = 0; j < 3; j++) n[j]--;
          std::vector<MVertex*> vertices;
          if(!getVertices(3, n, vertexVector, vertices)){ fclose(fp); return 0; }
          elements[0][cl].push_back(new MLine3(vertices));
        }
      }
      else if(!strcmp(str, "Triangles")){
        if(!fgets(buffer, sizeof(buffer), fp)) break;
        int nbe;
        sscanf(buffer, "%d", &nbe);
        Msg::Info("%d triangles", nbe);
        for(int i = 0; i < nbe; i++) {
          if(!fgets(buffer, sizeof(buffer), fp)) break;
          int n[3], cl;
          sscanf(buffer, "%d %d %d %d", &n[0], &n[1], &n[2], &cl);
          for(int j = 0; j < 3; j++) n[j]--;
          std::vector<MVertex*> vertices;
          if(!getVertices(3, n, vertexVector, vertices)){ fclose(fp); return 0; }
          elements[1][cl].push_back(new MTriangle(vertices));
        }
      }
      else if(!strcmp(str, "TrianglesP2")){
        if(!fgets(buffer, sizeof(buffer), fp)) break;
        int nbe;
        sscanf(buffer, "%d", &nbe);
        Msg::Info("%d triangles", nbe);
        for(int i = 0; i < nbe; i++) {
          if(!fgets(buffer, sizeof(buffer), fp)) break;
//.........这里部分代码省略.........
开发者ID:feelpp,项目名称:debian-gmsh,代码行数:101,代码来源:GModelIO_MESH.cpp


示例8: Fopen

bool PView::readPOS(const std::string &fileName, int fileIndex)
{
  FILE *fp = Fopen(fileName.c_str(), "rb");
  if(!fp){
    Msg::Error("Unable to open file '%s'", fileName.c_str());
    return false;
  }

  char str[256] = "XXX";
  double version = -1.;
  int format = -1, size = -1, index = -1;

  while(1) {

    while(str[0] != '$'){
      if(!fgets(str, sizeof(str), fp) || feof(fp))
        break;
    }

    if(feof(fp))
      break;

    if(!strncmp(&str[1], "PostFormat", 10)) {

      if(!fscanf(fp, "%lf %d %d\n", &version, &format, &size)){
        Msg::Error("Read error");
        fclose(fp);
        return false;
      }
      if(version < 1.0) {
        Msg::Error("Post-processing file too old (ver. %g < 1.0)", version);
        fclose(fp);
        return false;
      }
      if(size == sizeof(double))
        Msg::Debug("Data is in double precision format (size==%d)", size);
      else {
        Msg::Error("Unknown data size (%d) in post-processing file", size);
        fclose(fp);
        return false;
      }

    }
    else if(!strncmp(&str[1], "View", 4)){
      index++;
      if(fileIndex < 0 || fileIndex == index){
        PViewDataList *d = new PViewDataList();
        if(!d->readPOS(fp, version, format ? true : false)){
          Msg::Error("Could not read data in list format");
          delete d;
          fclose(fp);
          return false;
        }
        else{
          d->setFileName(fileName);
          d->setFileIndex(index);
          new PView(d);
        }
      }

    }

    do {
      if(!fgets(str, sizeof(str), fp) || feof(fp))
        break;
    } while(str[0] != '$');

  }

  fclose(fp);
  return true;
}
开发者ID:kevinr2763,项目名称:gmsh,代码行数:72,代码来源:PViewIO.cpp


示例9: Save_Data

/* Save_Data()
 * ======================================================================
 */
BOOLEAN
Save_Data( void )
{
    DTA  thedta, *saved;
    int  fd;
    int  *DataPtr;
    long EndIndex;
    BOOLEAN flag;

    flag = FALSE;
    saved = Fgetdta();
    Fsetdta( &thedta );
    if( Fsfirst( FPath, 0 ) <= -1 ) /* Can't find the file... */
    {
        Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
        form_alert( 1, alert2 );
    }
    else
    {
        DataBuf = calloc( 1, thedta.d_length * 2L );

        if( DataBuf )
        {
            fd = Fopen( FPath, 0 );
            if( fd <= 0 )
            {
                form_alert( 1, alert1 );
            }
            else
            {
                Buffer = ( long )DataBuf;
                Buffer = ( Buffer + 15L ) & 0xFFFFFFF0L;
                DataHdr = ( int *)Buffer;

                Fread( fd, thedta.d_length, DataHdr );
                Fclose( fd );

                EndIndex = thedta.d_length;
                DataPtr  = FindString( DataHdr, DataHdr + EndIndex - 8 );
                if( DataPtr )
                {
                    hdr = ( HEADER *)DataPtr;

                    hdr_buffer.quality    = Menu[ MQUALITY ].curvalue;
                    hdr_buffer.nplanes    = Menu[ MCOLOR ].curvalue + 1;
                    hdr_buffer.PageSize   = Menu[ MPAGESIZE ].curvalue;
                    hdr_buffer.xres       = xres_value;
                    hdr_buffer.yres       = yres_value;
                    hdr_buffer.port       = Menu[ MPORT ].curvalue;
                    hdr_buffer.paper_feed = Menu[ MTRAY ].curvalue;

                    *hdr = hdr_buffer;

                    flag = TRUE;
                    fd = Fcreate( FPath, 0 );
                    Fwrite( fd, thedta.d_length, DataHdr );
                    Fclose( fd );
                }
                else
                {
                    Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
                    form_alert( 1, alert3 );
                }
                free( DataBuf );
            }
        }
        else
            form_alert( 1, alert4 );
    }
    Fsetdta( saved );
    return( flag );
}
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:75,代码来源:FILEIO.C


示例10: GetCDrivers

/* GetCDrivers()
 * ====================================================================
 * Go thru the list of .sys files and try to load them.
 * Those that we can load, get the header and see if they are of the
 * new driver type. Get the filenames of those that are printer drivers
 * and store them in cdriver. Store their index into the driver array
 * into our cdriver array position.
 */
void
GetCDrivers( void )
{
    DTA  thedta, *saved;
    int  fd;
    int  *DataPtr;
    long EndIndex;
    int  error;

    saved = Fgetdta();
    Fsetdta( &thedta );

    cdriver_count =  0;

    get_bitpath();
    strcpy( FPath, epath );
    strcat( FPath, "\\*.SYS");

    error = Fsfirst( FPath, 0 );	/* Normal file search for 1st file */
    if( error != E_OK )  	/* No such files! */
    {
        return;
    }

    do
    {
        sprintf( line_buf, "%s\\%s", epath, thedta.d_fname );
        DataBuf = calloc( 1, thedta.d_length * 2L );

        if( DataBuf )
        {
            fd = Fopen( line_buf, 0 );
            if( fd > 0 )
            {
                Buffer = ( long )DataBuf;
                Buffer = ( Buffer + 15L ) & 0xFFFFFFF0L;
                DataHdr = ( int *)Buffer;

                Fread( fd, thedta.d_length, DataHdr );
                Fclose( fd );
                EndIndex = thedta.d_length;
                DataPtr  = FindString( DataHdr, DataHdr + EndIndex - 8 );
                if( DataPtr )	/* Look only for new drivers with headers*/
                {
                    hdr = ( HEADER *)DataPtr;
                    hdr_buffer = ( HEADER )*hdr;
                    hdr = &hdr_buffer;

                    /* want only those drivers with real page sizes */
                    if( hdr->config_map & 0x3E )
                    {
                        /* then get the name...*/
                        strcpy( cdrivers[ cdriver_count ], hdr->fname );
                        strcpy( drivers[ cdriver_count ], thedta.d_fname );
                        cdriver_count++;
                    }
                }
            }
            free( DataBuf );
        }
        else
        {
            /* memory error - break out of loop and exit routine */
            form_alert( 1, alert4 );
            break;
        }
    } while ( ( Fsnext() == E_OK ) && ( cdriver_count < MAX_DRIVERS ) );
    SortCDriverNames();
    Fsetdta( saved );
}
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:78,代码来源:FILEIO.C


示例11: Read_Data

/* Read_Data()
 * ================================================================
 */
BOOLEAN
Read_Data( void )
{
    DTA  thedta, *saved;
    int  fd;
    int  *DataPtr;
    long EndIndex;
    BOOLEAN flag;

    flag = FALSE;
    saved = Fgetdta();
    Fsetdta( &thedta );
    if( Fsfirst( FPath, 0 ) <= -1 ) /* Can't find the file... */
    {
        Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
        form_alert( 1, alert2 );
    }
    else
    {
        DataBuf = calloc( 1, thedta.d_length * 2L );

        if( DataBuf )
        {
            fd = Fopen( FPath, 0 );
            if( fd <= 0 )
            {
                form_alert( 1, alert1 );
            }
            else
            {
                Buffer = ( long )DataBuf;
                Buffer = ( Buffer + 15L ) & 0xFFFFFFF0L;
                DataHdr = ( int *)Buffer;

                Fread( fd, thedta.d_length, DataHdr );
                Fclose( fd );

                EndIndex = thedta.d_length;
                DataPtr  = FindString( DataHdr, DataHdr + EndIndex - 8 );
                if( DataPtr )
                {
                    hdr = ( HEADER *)DataPtr;
                    hdr_buffer = ( HEADER )*hdr;
                    hdr = &hdr_buffer;
                    strcpy( title, hdr->fname );
                    flag = TRUE;
                }
                else
                {
                    Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
                    form_alert( 1, alert3 );
                }
                free( DataBuf );
            }
        }
        else
            form_alert( 1, alert4 );
    }
    Fsetdta( saved );
    return( flag );
}
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:64,代码来源:FILEIO.C


示例12: get_bitpath

/* get_bitpath()
 * ====================================================================
 * Get the font path from the ASSIGN.SYS
 * If there is NO ASSIGN.SYS, we substitute C: or A: instead.
 *
 */
void
get_bitpath( void )
{
    int  i, sys_file;
    long j;
    int  error;
    char *fname;
    int  alen;

    olddma = Fgetdta();
    Fsetdta( &newdma );		/* Point to OUR buffer */

    strcpy( epath, "C:\\ASSIGN.SYS" );
    epath[0] = GetBaseDrive();

    bufptr     = 0L;
    BufferSize = 0L;

    error = Fsfirst( epath, 0 );	/* Normal file search for 1st file */
    if( error == 0 )
    {   /* found it! */
        bufptr = calloc( 1, newdma.d_length * 2L );
        if( bufptr )
        {
            BufferSize = newdma.d_length;

            if( (sys_file = Fopen( epath, 0 )) < 0)
            {
                Fsetdta( olddma );		/* Point to OLD buffer */
                if( bufptr )
                {
                    free( bufptr );
                    bufptr = 0L;
                }
                form_alert( 1, alert1 );
                return;
            }

            path_found = FALSE;
            do
            {
                i = 0;
                alen = (int)Fread( sys_file, BufferSize, bufptr );
                do
                {
                    if( !strncmp( &bufptr[i], "path", 4) ||
                            !strncmp( &bufptr[i], "PATH", 4) )
                    {
                        strcpy( epath, extract_path( &i, alen ) );
                        path_found = TRUE;
                        goto done;
                    }
                    else
                    {
                        while(( bufptr[i] != '\n' ) && ( i < alen )) {
                            ++i;    /* Skip to newline */
                        }
                        ++i;
                    }
                } while( i < alen );
            } while( alen == BufferSize );
done:
            Fclose( sys_file );

            if( bufptr )
            {
                free( bufptr );
                bufptr = 0L;
            }
            j = strlen( epath );
            if( epath[ j - 1 ] == '\\' )
                epath[ j - 1 ] = '\0';
        }
        else
            form_alert( 1, alert1 );
    }
    Fsetdta( olddma );		/* Point to OLD buffer */

    fname = &epath[0];
    fname = strupr( fname );
}
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:87,代码来源:FILEIO.C


示例13: memcpy

/* Note: Need condition handler to clean-up allocated structures and close intput file in the event of an error */
struct extcall_package_list *exttab_parse(mval *package)
{
	int		parameter_alloc_values[MAX_ACTUALS], parameter_count, ret_pre_alloc_val, i, fclose_res;
	int		len, keywordlen;
	boolean_t	is_input[MAX_ACTUALS], is_output[MAX_ACTUALS], got_status;
	mstr		callnam, rtnnam, clnuprtn;
	mstr 		val, trans;
	void_ptr_t	pakhandle;
	enum gtm_types	ret_tok, parameter_types[MAX_ACTUALS], pr;
	char		str_buffer[MAX_TABLINE_LEN], *tbp, *end;
	char		str_temp_buffer[MAX_TABLINE_LEN];
	FILE		*ext_table_file_handle;
	struct extcall_package_list	*pak;
	struct extcall_entry_list	*entry_ptr;

	/* First, construct package name environment variable */
	memcpy(str_buffer, PACKAGE_ENV_PREFIX, SIZEOF(PACKAGE_ENV_PREFIX));
	tbp = &str_buffer[SIZEOF(PACKAGE_ENV_PREFIX) - 1];
	if (package->str.len)
	{
		/* guaranteed by compiler */
		assert(package->str.len < MAX_NAME_LENGTH - SIZEOF(PACKAGE_ENV_PREFIX) - 1);
		*tbp++ = '_';
		memcpy(tbp, package->str.addr, package->str.len);
		tbp += package->str.len;
	}
	*tbp = 0;
	/* Now we have the environment name, lookup file name */
	ext_table_file_name = GETENV(str_buffer);
	if (NULL == ext_table_file_name)
	{
		/* Environment variable for the package not found */
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_ZCCTENV, 2, LEN_AND_STR(str_buffer));
	}
	Fopen(ext_table_file_handle, ext_table_file_name, "r");
	if (NULL == ext_table_file_handle)
	{
		/* Package's external call table could not be found */
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_ZCCTOPN, 2, LEN_AND_STR(ext_table_file_name));
	}
	ext_source_line_num = 0;
	/* Pick-up name of shareable library */
	tbp = read_table(LIT_AND_LEN(str_buffer), ext_table_file_handle);
	if (NULL == tbp)
	{
		/* External call table is a null file */
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_ZCCTNULLF, 2, package->str.len, package->str.addr);
	}
	STRNCPY_STR(str_temp_buffer, str_buffer, MAX_TABLINE_LEN);
	val.addr = str_temp_buffer;
	val.len = STRLEN(str_temp_buffer);
	/* Need to copy the str_buffer into another temp variable since
	 * TRANS_LOG_NAME requires input and output buffers to be different.
	 * If there is an env variable present in the pathname, TRANS_LOG_NAME
	 * expands it and return SS_NORMAL. Else it returns SS_NOLOGNAM.
	 * Instead of checking 2 return values, better to check against SS_LOG2LONG
	 * which occurs if the pathname is too long after any kind of expansion.
 	 */
	if (SS_LOG2LONG == TRANS_LOG_NAME(&val, &trans, str_buffer, SIZEOF(str_buffer), dont_sendmsg_on_log2long))
	{
		/* Env variable expansion in the pathname caused buffer overflow */
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(5) ERR_LOGTOOLONG, 3, val.len, val.addr, SIZEOF(str_buffer) - 1);
	}
	pakhandle = fgn_getpak(str_buffer, INFO);
	if (NULL == pakhandle)
	{
		/* Unable to obtain handle to the shared library */
		rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_ZCUNAVAIL, 2, package->str.len, package->str.addr);
	}
	pak = get_memory(SIZEOF(*pak));
	pak->first_entry = 0;
	put_mstr(&package->str, &pak->package_name);
	pak->package_handle = pakhandle;
	pak->package_clnup_rtn = NULL;
	len = STRLEN("GTMSHLIBEXIT");
	/* At this point, we have a valid package, pointed to by pak */
#	ifdef DEBUG_EXTCALL
	FPRINTF(stderr, "GT.M external call opened package name: %s\n", pak->package_name.addr);
#	endif
	for (;;)
	{
		star_found = FALSE;
		tbp = read_table(LIT_AND_LEN(str_buffer), ext_table_file_handle);
		if (NULL == tbp)
			break;
		tbp = exttab_scan_space(str_buffer);
		/* Empty line? */
		if (!*tbp)
			continue;
		/* No, must be entryref or keyword */
		end = scan_ident(tbp);
		if (!end)
			ext_stx_error(ERR_ZCENTNAME, ext_table_file_name);
		keywordlen = end - tbp;
		end = exttab_scan_space(end);
		if ('=' == *end)
		{	/* Keyword before '=' has a string of size == STRLEN("GTMSHLIBEXIT") */
			if (keywordlen == len)
			{
//.........这里部分代码省略.........
开发者ID:shabiel,项目名称:fis-gtm,代码行数:101,代码来源:exttab_parse.c


示例14: explodeRPM

/*
 * explode source RPM into the current directory
 * use filters to skip packages and files we do not need
 */
int explodeRPM(const char *source,
        filterfunc filter,
        dependencyfunc provides,
        dependencyfunc deps,
        void* userptr)
{
    char buffer[BUFFERSIZE+1]; /* make space for trailing \0 */
    FD_t fdi;
    Header h;
    char * rpmio_flags = NULL;
    rpmRC rc;
    FD_t gzdi;
    struct archive *cpio;
    struct archive_entry *cpio_entry;
    struct cpio_mydata cpio_mydata;

    rpmts ts;
    rpmVSFlags vsflags;
    const char *compr;

    if (strcmp(source, "-") == 0)
        fdi = fdDup(STDIN_FILENO);
    else
        fdi = Fopen(source, "r.ufdio");

    if (Ferror(fdi)) {
        const char *srcname = (strcmp(source, "-") == 0) ? "<stdin>" : source;
        logMessage(ERROR, "%s: %s\n", srcname, Fstrerror(fdi));
        return EXIT_FAILURE;
    }
    rpmReadConfigFiles(NULL, NULL);

    /* Initialize RPM transaction */
    ts = rpmtsCreate();
    vsflags = 0;

    /* Do not check digests, signatures or headers */
    vsflags |= _RPMVSF_NODIGESTS;
    vsflags |= _RPMVSF_NOSIGNATURES;
    vsflags |= RPMVSF_NOHDRCHK;
    (void) rpmtsSetVSFlags(ts, vsflags);

    rc = rpmReadPackageFile(ts, fdi, "rpm2dir", &h);

    ts = rpmtsFree(ts);

    switch (rc) {
        case RPMRC_OK:
        case RPMRC_NOKEY:
        case RPMRC_NOTTRUSTED:
            break;
        case RPMRC_NOTFOUND:
            logMessage(ERROR, "%s is not an RPM package", source);
            return EXIT_FAILURE;
            break;
        case RPMRC_FAIL:
        default:
            logMessage(ERROR, "error reading header from %s package\n", source);
            return EXIT_FAILURE;
            break;
    }

    /* Retrieve all dependencies and run them through deps function */
    while (deps) {
        struct rpmtd_s td;
        const char *depname;

        if (!headerGet(h, RPMTAG_REQUIRENAME, &td, HEADERGET_MINMEM))
            break;

        /* iterator */
        while ((depname = rpmtdNextString(&td))) {
            if (deps(depname, userptr)) {
                Fclose(fdi);
                return EXIT_BADDEPS;
            }
        }
        rpmtdFreeData(&td);
        break;
    }

    /* Retrieve all provides and run them through provides function */
    while (provides) {
        struct rpmtd_s td;
        const char *depname;
        int found = 0;

        if (!headerGet(h, RPMTAG_PROVIDES, &td, HEADERGET_MINMEM))
            break;

        /* iterator */
        while ((depname = rpmtdNextString(&td))) {
            if (!provides(depname, userptr)) {
                found++;
            }
        }
//.........这里部分代码省略.........
开发者ID:BGS,项目名称:rogentos-anaconda,代码行数:101,代码来源:rpmextract.c


示例15: lprPrintfile

void lprPrintfile(
	JOBDEF* pjd,
	char* oriFileName,
	char* spoolFileFullName,
	int16 cnId,
	void (*meter)(long totLen, long accumLen, long actLen) )
{
	char fileBuff[FILEBUFFSIZE];
	long fileLength;
	long lenData = 0;
	long lenSent = 0;    
	char o_str[100];
	int	fin;
	char rc;
	char *eM;

	if ( (fin=Fopen(spoolFileFullName, FO_READ)) < 0) {
		eM = "cannot open spool file for read"; goto errExit;
	}

	fileLength = Fseek(0, fin, 2);	/* position to end */
	Fseek(0, fin, 0);

	/* start the lprd protocol for this file */

/* command 0x02 "receive  printer job" */

	o_str[0] = 0x02;
	o_str[1] = '\0';
	strcat(o_str, pjd->rmPrinter);
	strcat(o_str, "\n");
	output(cnId, o_str, (int)strlen(o_str));

	if ( getResponse(cnId) != 0x00 ) {
		uiPrintf(uiH, uiPrERR, "unknown queue|>%s<|on remote host", pjd->rmPrinter);
		return;
	}



/* subcommand 0x02 "receive control file" */

	/* build the control file */
	strcpy(fileBuff,   "H");
	strcat(fileBuff, pjd->hostName);	/* mandatory */
	strcat(fileBuff, "\nP");
	strcat(fileBuff, pjd->userName);	/* mandatory */
	strcat(fileBuff, "\nN");
	strcat(fileBuff, oriFileName);		/* mandatory */
	strcat(fileBuff, "\n");

	if (pjd->optSendMail) {
		strcat(fileBuff,   "M");
		strcat(fileBuff, pjd->userName);
		strcat(fileBuff, "\n");
	}

	if (!pjd->optNoBanner) {
		strcat(fileBuff,   "C");
		strcat(fileBuff, pjd->hostName);	/* class for banner */
		strcat(fileBuff, "\nJ");
		strcat(fileBuff, oriFileName);		/* job name for banner */
		strcat(fileBuff, "\nL");
		strcat(fileBuff, pjd->userName);	/* banner */
		strcat(fileBuff, "\n");
	}

#if 0	/* not supported */
	strcat(fileBuff,   "U");
	strcat(fileBuff, spoolFileName);	/* unlink data file */
	strcat(fileBuff, "\n");
#endif

	if (pjd->optNCopies) {
		strcat(fileBuff,   "#");
		strcat(fileBuff, pjd->optNCopies);
		strcat(fileBuff, "\n");
	}

	if (pjd->optNIndent) {
		strcat(fileBuff,   "I");
		strcat(fileBuff, pjd->optNIndent);
		strcat(fileBuff, "\n");
	}

	if (pjd->optNWidth) {
		strcat(fileBuff,   "W");
		strcat(fileBuff, pjd->optNWidth);
		strcat(fileBuff, "\n");
	}

	if (pjd->optTitle) {
		strcat(fileBuff,   "T");
		strcat(fileBuff, pjd->optTitle);
		strcat(fileBuff, "\n");
	}

	strcat(fileBuff, pjd->optFormat);
	strcat(fileBuff, pjd->spoolFile);
	strcat(fileBuff, "\n");
//.........这里部分代码省略.........
开发者ID:daemqn,项目名称:Atari_ST_Sources,代码行数:101,代码来源:LPRAUX.C


示例16: writeRPM

/*
 * This is more than just a little insane:
 * In order to write the signature, we need to know the size and
 * the size and digests of the header and payload, which are located
 * after the signature on disk. We also need a digest of the compressed
 * payload for the main header, and of course the payload is after the
 * header on disk. So we need to create placeholders for both the
 * signature and main header that exactly match the final sizes, calculate
 * the payload digest, then generate and write the real main header to
 * be able to FINALLY calculate the digests we need for the signature
 * header. In other words, we need to write things in the exact opposite
 * order to how the RPM format is laid on disk.
 */
static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
		      const char *fileName, char **cookie)
{
    FD_t fd = NULL;
    char * rpmio_flags = NULL;
    char * SHA1 = NULL;
    char * SHA256 = NULL;
    uint8_t * MD5 = NULL;
    char * pld = NULL;
    uint32_t pld_algo = PGPHASHALGO_SHA256; /* TODO: macro configuration */
    rpmRC rc = RPMRC_FAIL; /* assume failure */
    rpm_loff_t archiveSize = 0;
    off_t sigStart, hdrStart, payloadStart, payloadEnd;

    if (pkgidp)
	*pkgidp = NULL;

    rpmio_flags = getIOFlags(pkg);
    if (!rpmio_flags)
	goto exit;

    finalizeDeps(pkg);

    /* Create and add the cookie */
    if (cookie) {
	rasprintf(cookie, "%s %d", buildHost(), (int) (*getBuildTime()));
	headerPutString(pkg->header, RPMTAG_COOKIE, *cookie);
    }

    /* Create a dummy payload digest to get the header size right */
    pld = nullDigest(pld_algo, 1);
    headerPutUint32(pkg->header, RPMTAG_PAYLOADDIGESTALGO, &pld_algo, 1);
    headerPutString(pkg->header, RPMTAG_PAYLOADDIGEST, pld);
    pld = _free(pld);
    
    /* Check for UTF-8 encoding of string tags, add encoding tag if all good */
    if (checkForEncoding(pkg->header, 1))
	goto exit;

    /* Open the output file */
    fd = Fopen(fileName, "w+.ufdio");
    if (fd == NULL || Ferror(fd)) {
	rpmlog(RPMLOG_ERR, _("Could not open %s: %s\n"),
		fileName, Fstrerror(fd));
	goto exit;
    }

    /* Write the lead section into the package. */
    if (rp 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ForEachItemIn函数代码示例发布时间:2022-05-30
下一篇:
C++ Foo函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap