예제 #1
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_pinseq(NOTUSED char id,jed_ctx *c)
{
	int i,k;
	unsigned j;
	if(c->num_pins==0)
		return 1;
	if(c->pinseq==NULL)
		c->pinseq=calloc(sizeof(uint8_t),c->num_pins);
	if(c->pinseq==NULL)
		return 1;
	for(j=0;j<c->num_pins;j++)
	{
		k=get_num_sx(c->f,&i);
		if(k==5)
		{
			c->pinseq[j]=i;
			return 0;
		}
		if(100<=k)
			return 1;
		if(i>255)
			return 1;
		c->pinseq[j]=i;
	}
	skip_field(c->f);
	return 0;
}
예제 #2
0
파일: strutil.c 프로젝트: harski/procwait
int get_next_field (FILE * fd, char * str, const size_t len)
{
	int success;
	int i;

	for (i = 0; ; ++i) {
		int tmp_char = fgetc(fd);

		if (tmp_char == EOF) {
			str[i] = '\0';
			success = STRUTIL_EXIT_EOF;
			break;
		} else if (is_whitespace((char) tmp_char)) {
			str[i] = '\0';
			success = STRUTIL_EXIT_SUCCESS;
			break;
		} else if (i == (int) len -1) {
			/* No more room for characters, and tmp_char is
			 * non-whitespace. terminate string and
			 * fast-forward until next whitespace. */
			str[i] = '\0';
			success = STRUTIL_EXIT_TRUNCATED;
			skip_field(fd);
			break;
		} else {
			str[i] = (char) tmp_char;
		}
	}

	return success;
}
예제 #3
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_secf(NOTUSED char id,jed_ctx *c)
{
	int v=fgetc(c->f);
	if(v=='0')
		c->secfuse=0;
	else if(v=='1')
		c->secfuse=1;
	else return 1;
	return skip_field(c->f);
}
예제 #4
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_chksum(NOTUSED char id,jed_ctx *c)
{
	char buf[5];
	buf[4]='\0';
	buf[0]=fgetc(c->f);
	buf[1]=fgetc(c->f);
	buf[2]=fgetc(c->f);
	buf[3]=fgetc(c->f);
	c->fusechk=strtol(buf,NULL,16);
	fprintf(stderr,"fuse checksum: %hx\n",c->fusechk);
	return skip_field(c->f);
}
예제 #5
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_defst(NOTUSED char id,jed_ctx *c)
{
	int v=fgetc(c->f);
	if(c->f_seen)
		return 1;
	if(v=='0')
		c->default_fuse=0;
	else if(v=='1')
		c->default_fuse=1;
	else return 1;
	
	if(c->num_fuses&&(c->flist!=NULL))//array was allocated
		if(init_fuses(c))
			return 1;
	c->f_seen=1;
	return skip_field(c->f);
}
예제 #6
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_defcon(NOTUSED char id,jed_ctx *c)
{
	int v;
	size_t i;
	v=fgetc(c->f);
	if((!isdigit(v))||(0==c->num_tvec)||(0==c->num_pins))
		return 1;

	if(NULL==c->testvec)
		c->testvec=calloc(sizeof(char),(c->num_pins+1)*c->num_tvec);
	if(NULL==c->testvec)
		return 1;

	for(i=0;i<c->num_tvec;i++)
	{
		size_t j;
		for(j=0;j<c->num_pins;j++)
		{
			c->testvec[(c->num_pins+1)*i+j]=v;
		}
	}
	return skip_field(c->f);
}
예제 #7
0
/* Reads 'n_vtcs' vertex points from the 'data' stream in binary/ascii format
 * and stores them in the 'vtcs' array. Zero is returned on success, or the
 * negative error code otherwise. If no error occurs the bounding box minium
 * and maximum are returned in 'bbox_min' and 'bbox_max'. The
 * 'n_v_prop' properties associated to the vertices are fed through
 * the 'v_prop' array. */
static int read_ply_vertices(vertex_t *vtcs, struct file_data *data,
                             const int is_bin, const int n_vtcs, 
                             vertex_t *bbox_min, vertex_t *bbox_max,
                             const int swap_bytes,
                             const struct ply_prop *v_prop, 
                             const int n_v_prop) 
{
  int rcode = 0;
  int i, j;
  vertex_t bbmin,bbmax;

  bbmin.x = bbmin.y = bbmin.z = FLT_MAX;
  bbmax.x = bbmax.y = bbmax.z = -FLT_MAX;

  for (i=0; i<n_vtcs && rcode>=0; i++) {
    for (j=0; j<n_v_prop && rcode>=0; j++) {
      switch (v_prop[j].prop) {
      case v_x:
			if (is_bin)
				rcode = read_ply_property(data, v_prop[j].type_prop, swap_bytes, &(vtcs[i].x));
			else {
				if (float_scanf(data, &(vtcs[i].x)) != 1)
				rcode = MESH_CORRUPTED;
			}
			if (rcode == 0) {
				if (vtcs[i].x < bbmin.x) bbmin.x = vtcs[i].x;
				if (vtcs[i].x > bbmax.x) bbmax.x = vtcs[i].x;
			}
        break;

      case v_y:
		if (is_bin)
			rcode = read_ply_property(data, v_prop[j].type_prop, swap_bytes, &(vtcs[i].y));
		else {
			if (float_scanf(data, &(vtcs[i].y)) != 1)
			rcode = MESH_CORRUPTED;
		}
        if (rcode == 0) {
          if (vtcs[i].y < bbmin.y) bbmin.y = vtcs[i].y;
          if (vtcs[i].y > bbmax.y) bbmax.y = vtcs[i].y;
        }
        break;
      case v_z:
		if (is_bin)
			rcode = read_ply_property(data, v_prop[j].type_prop, swap_bytes, &(vtcs[i].z));
		else {
		if (float_scanf(data, &(vtcs[i].z)) != 1)
			rcode = MESH_CORRUPTED;
		}
        if (rcode == 0) {
          if (vtcs[i].z < bbmin.z) bbmin.z = vtcs[i].z;
          if (vtcs[i].z > bbmax.z) bbmax.z = vtcs[i].z;
        }
        break;
      default:
		if (is_bin)
			rcode = skip_bytes(data, 
								ply_sizes[v_prop[j].type_prop]*sizeof(unsigned char));
		else 
			rcode = skip_field(data, v_prop[j].type_prop);
        break;
      }
    }
  }

  if (n_vtcs == 0) {
    memset(&bbmin,0,sizeof(bbmin));
    memset(&bbmax,0,sizeof(bbmax));
  }

  *bbox_min = bbmin;
  *bbox_max = bbmax;
  return rcode;
}
예제 #8
0
/* Read 'n_faces' faces of the model from a binary/ascii 'data' stream. 
 * Returns 0 if successful and a negative value in case of trouble. 
 * Non-triangular faces are NOT supported. Moreover, the face's vertex
 * indices have to be consistent with the number of vertices in the
 * model 'n_vtcs'. The 'n_f_prop' properties associated with the faces
 * are passed in the 'face_prop' array.*/
static int read_ply_faces(face_t *faces, struct file_data *data,
                          const int is_bin,
                          const int n_faces, const int n_vtcs,
                          const int swap_bytes,
                          const struct ply_prop *face_prop, 
                          const int n_f_prop) 
{
  int i, j, f0, f1, f2;
  int rcode=0;
  t_uint8 nvert=0;
  int tmp_int=0;

  for (i=0; i<n_faces && rcode >=0; i++) {
	for (j=0; j<n_f_prop && rcode >=0; j++) {
      if (face_prop[j].prop == v_idx) {
        if (!face_prop[j].is_list)
          rcode = MESH_CORRUPTED;
        else {
			if (is_bin)
				rcode = read_ply_property(data, face_prop[j].type_list, 
					      swap_bytes, &nvert);
			else {
				if (int_scanf(data, &tmp_int) != 1) {
					rcode = MESH_CORRUPTED;
					break;
				}
				nvert = (t_uint8)tmp_int;
			}
			if (nvert != 3) { /* Non triangular mesh -> bail out */
#ifdef DEBUG
				DEBUG_PRINT("found a %d face\n", nvert);
#endif
				rcode = MESH_NOT_TRIAG;
				break;
			}
			if (is_bin) {
				rcode = read_ply_property(data, face_prop[j].type_prop, swap_bytes,
						      &f0);
				rcode = read_ply_property(data, face_prop[j].type_prop, swap_bytes,
						      &f1);
				rcode = read_ply_property(data, face_prop[j].type_prop, swap_bytes,
						      &f2);
			} else {
				 if (int_scanf(data, &f0) != 1) {
					rcode = MESH_CORRUPTED;
					break;
				}
	     
				if (int_scanf(data, &f1) != 1) {
					rcode = MESH_CORRUPTED;
					break;
				}
	     
				if (int_scanf(data, &f2) != 1) {
					rcode = MESH_CORRUPTED;
					break;
				}

			}
			if (f0 < 0 || f1 < 0 || f2 < 0 || 
				f0 >= n_vtcs || f1 >= n_vtcs || f2 >= n_vtcs ) {
				rcode = MESH_MODEL_ERR;
				break;
		    }
			faces[i].f0 = f0;
			faces[i].f1 = f1;
			faces[i].f2 = f2;
          
		}
	  } else {
		if (is_bin)
			rcode = skip_bytes(data,  
				     ply_sizes[face_prop[j].type_prop]*
					 sizeof(unsigned char));
		else
			rcode = skip_field(data, face_prop[j].type_prop);
      }
    }
  }

  return rcode;
}
예제 #9
0
bool MEDITParser::parse(const std::string& filename) {
    std::ifstream fin(filename.c_str());
    if (!fin.is_open()) {
        std::stringstream err_msg;
        err_msg << "failed to open file \"" << filename << "\"";
        throw IOError(err_msg.str());
    }

    bool success = true;
    success &= parse_header(fin);
    if (!success) {
        throw IOError("Error parsing file header.");
    }

    const size_t LINE_SIZE = 256;
    char line[LINE_SIZE];
    while (!fin.eof()) {
        std::string elem_type;
        fin >> elem_type;
        if (elem_type.size() == 0) continue;
        if (elem_type[0] == '#') {
            fin.getline(line, LINE_SIZE);
            continue;
        }
        if (elem_type == "Vertices") {
            success &= parse_vertices(fin);
        } else if (elem_type == "Triangles") {
            m_vertex_per_face = 3;
            success &= parse_faces(fin);
        } else if (elem_type == "Quadrilaterals") {
            m_vertex_per_face = 4;
            success &= parse_faces(fin);
        } else if (elem_type == "Tetrahedra") {
            if (m_faces.size() == 0) {
                m_vertex_per_face = 3;
            } else if (m_vertex_per_face != 3){
                success = false;
            }
            m_vertex_per_voxel = 4;
            success &= parse_voxels(fin);
        } else if (elem_type == "Hexahedra") {
            if (m_faces.size() == 0) {
                m_vertex_per_face = 4;
            } else if (m_vertex_per_face != 4){
                success = false;
            }
            m_vertex_per_voxel = 8;
            success &= parse_voxels(fin);
        } else if (elem_type == "End") {
            break;
        } else {
            if (elem_type != "Edges" &&
                elem_type != "Corners" &&
                elem_type != "RequiredVertices" &&
                elem_type != "Ridges" &&
                elem_type != "RequiredEdges" &&
                elem_type != "Normals" &&
                elem_type != "Tangents" &&
                elem_type != "NormalAtVertices" &&
                elem_type != "NormalAtTriangleVertices" &&
                elem_type != "NormalAtQuadrilateralVertices" &&
                elem_type != "TangentAtEdges" &&
                elem_type != "End") {
                success = false;
            } else {
                std::cerr << "Warning: Skipping " << elem_type
                    << " field" << std::endl;
                success &= skip_field(fin);
            }
        }
        if (!success) {
            std::stringstream err_msg;
            err_msg << "Error parsing \"" << elem_type << "\" field in " <<
                filename;
            throw IOError(err_msg.str());
        }
    }

    fin.close();
    return success;
}
예제 #10
0
int linear_searcher::check_match(const char *buf, const char *bufend,
				 const char *match, int matchlen,
				 const char **cont, const char **start) const
{
  *cont = match + 1;
  // The user is required to supply only the first truncate_len characters
  // of the key.  If truncate_len <= 0, he must supply all the key.
  if ((truncate_len <= 0 || matchlen < truncate_len)
      && map[uchar(match[matchlen])] != '\0')
    return 0;

  // The character before the match must not be an alphanumeric
  // character (unless the alphanumeric character follows one or two
  // percent characters at the beginning of the line), nor must it be
  // a percent character at the beginning of a line, nor a percent
  // character following a percent character at the beginning of a
  // line.

  switch (match - buf) {
  case 0:
    break;
  case 1:
    if (match[-1] == '%' || map[uchar(match[-1])] != '\0')
      return 0;
    break;
  case 2:
    if (map[uchar(match[-1])] != '\0' && match[-2] != '%')
      return 0;
    if (match[-1] == '%'
	&& (match[-2] == '\n' || match[-2] == '%'))
      return 0;
    break;
  default:
    if (map[uchar(match[-1])] != '\0'
	&& !(match[-2] == '%'
	     && (match[-3] == '\n'
		 || (match[-3] == '%' && match[-4] == '\n'))))
      return 0;
    if (match[-1] == '%'
	&& (match[-2] == '\n'
	    || (match[-2] == '%' && match[-3] == '\n')))
      return 0;
  }
    
  const char *p = match;
  int had_percent = 0;
  for (;;) {
    if (*p == '\n') {
      if (!had_percent && p[1] == '%') {
	if (p[2] != '\0' && strchr(ignore_fields, p[2]) != 0) {
	  *cont = skip_field(bufend, match + matchlen);
	  return 0;
	}
	if (!start)
	  break;
	had_percent = 1;
      }
      if (p <= buf) {
	if (start)
	  *start = p + 1;
	return 1;
      }
      const char *q;
      for (q = p - 1; *q == ' ' || *q == '\t'; q--)
	;
      if (*q == '\n') {
	if (start)
	  *start = p + 1;
	break;
      }
      p = q;
    }
    p--;
  }
  return 1;
}
예제 #11
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int skip_jed_hdr(FILE * f)
{
	return skip_field(f);
}
예제 #12
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_invalid(NOTUSED char id,jed_ctx *c)
{
	fprintf(stderr,"Ignoring unknown field %c\n",id);
	skip_field(c->f);
	return 0;
}
예제 #13
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_tcyc(NOTUSED char id,jed_ctx *c)
{
	fprintf(stderr,"Ignoring tcyc field\n");//no Idea what this does..
	skip_field(c->f);
	return 0;
}
예제 #14
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_svect(NOTUSED char id,jed_ctx *c)//no Idea what this does..
{
	fprintf(stderr,"Ignoring svect field\n");
	skip_field(c->f);
	return 0;
}
예제 #15
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_note(NOTUSED char id,jed_ctx *c)
{
	fprintf(stderr,"Ignoring note field\n");
	skip_field(c->f);
	return 0;
}
예제 #16
0
파일: jedprs.c 프로젝트: klammerj/atfprog
static int fj_acc_time(NOTUSED char id,jed_ctx *c)
{
	fprintf(stderr,"Ignoring access time field\n");
	skip_field(c->f);
	return 0;
}