示例#1
0
int readpopx(char *pname, char ***plists, int npops)  
// reads lists of npops pops on a line
{
 FILE *fff ; 
 char line[MAXSTR+1], c ;
 char *spt[MAXFF], *sx  ;
 char **pp ;
 int nsplit,  t, num = 0  ;

 openit(pname, &fff, "r") ;
 line[MAXSTR] = '\0' ;
 while (fgets(line, MAXSTR, fff) != NULL)  {
   nsplit = splitup(line, spt, MAXFF) ;
   if (nsplit == 0) continue ;
   sx = spt[0] ; 
   if (sx[0] == '#')  {  
    freeup(spt, nsplit) ;
    continue ;
   }
   if (nsplit < npops) fatalx("length mismatch %s\n", line) ;
   ZALLOC(plists[num], npops+1, char *) ;
   plists[num][npops] == NULL ;
   pp = plists[num] ;
   for (t=0; t<npops; ++t) {  
    pp[t] = strdup(spt[t]) ;
   }
   striptrail(line, '\n') ;
   lines[num] = strdup(line) ; 
   ++num ; 
   freeup(spt, nsplit) ;
  }
  fclose(fff) ;
  return num ;
}
示例#2
0
文件: nodeio.c 项目: MarcNo/lifelines
/*================================================================
 * buffer_to_line -- Get GEDCOM line from buffer with <= 1 newline
 *
 *  p:      [in]  buffer
 *  plev:   [out] level number
 *  pxref:  [out] xref
 *  ptag:   [out] tag
 *  pval:   [out] value
 *  pmsg:   [out] error msg (in static buffer)
 *==============================================================*/
static BOOLEAN
buffer_to_line (STRING p, INT *plev, STRING *pxref
	, STRING *ptag, STRING *pval, STRING *pmsg)
{
	INT lev;
	static char scratch[MAXLINELEN+40];

	*pmsg = *pxref = *pval = 0;
	if (!p || *p == 0) {
		sprintf(scratch, _(qSreremp), flineno);
		*pmsg = scratch;
		return ERROR;
	}
	striptrail(p);
	if (strlen(p) > MAXLINELEN) {
		sprintf(scratch, _(qSrerlng), flineno);
		*pmsg = scratch;
		return ERROR;
	}

/* Get level number */
	skipws(&p);
	if (chartype((uchar)*p) != DIGIT) {
		sprintf(scratch, _(qSrernlv), flineno);
		*pmsg = scratch;
		return ERROR;
	}
	lev = (uchar)*p++ - (uchar)'0';
	while (chartype((uchar)*p) == DIGIT)
		lev = lev*10 + (uchar)*p++ - (uchar)'0';
	*plev = lev;

/* Get cross reference, if there */
	skipws(&p);
	if (*p == 0) {
		sprintf(scratch, _(qSrerinc), flineno);
		*pmsg = scratch;
		return ERROR;
	}
	if (*p != '@') goto gettag;
	*pxref = p++;
	if (*p == '@') {
		sprintf(scratch, _(qSrerbln), flineno);
		*pmsg = scratch;
		return ERROR;
	}
	while (*p != '@') p++;
	p++;
	if (*p == 0) {
		sprintf(scratch, _(qSrerinc), flineno);
		*pmsg = scratch;
		return ERROR;
	}
	if (!iswhite((uchar)*p)) {
		sprintf(scratch, _(qSrernwt), flineno);
		*pmsg = scratch;
		return ERROR;
	}
	*p++ = 0;

/* Get tag field */
gettag:
	skipws(&p);
	if (*p == 0) {
		sprintf(scratch, _(qSrerinc), flineno);
		*pmsg = scratch;
		return ERROR;
	}
	*ptag = p++;
	while (!iswhite((uchar)*p) && *p != 0) p++;
	if (*p == 0) return OKAY;
	*p++ = 0;

/* Get the value field */
	skipws(&p);
	*pval = p;
	return OKAY;
}