Exemplo n.º 1
0
static int
index_parse(FILE *fp, char *name, char *pathto, char *prefix, char *comment, char *descr, char *maint, char *cats, char *rdeps, int *volume)
{
    char line[10240 + 2048 * 7];
    char junk[2048];
    char volstr[2048];
    char *cp;
    int i;

    i = readline(fp, line, sizeof line);
    if (i <= 0)
	return EOF;
    cp = line;
    cp += copy_to_sep(name, cp, '|');		/* package name */
    cp += copy_to_sep(pathto, cp, '|');		/* ports directory */
    cp += copy_to_sep(prefix, cp, '|');		/* prefix */
    cp += copy_to_sep(comment, cp, '|');	/* comment */
    cp += copy_to_sep(descr, cp, '|');		/* path to pkg-descr */
    cp += copy_to_sep(maint, cp, '|');		/* maintainer */
    cp += copy_to_sep(cats, cp, '|');		/* categories */
    cp += skip_to_sep(cp, '|');			/* build deps - not used */
    cp += copy_to_sep(rdeps, cp, '|');		/* run deps */
    if (index(cp, '|'))
        cp += skip_to_sep(cp, '|');		/* url - not used */
    else {
	strncpy(junk, cp, 1023);
	*volume = 0;
	return 0;
    }
    if (index(cp, '|'))
	cp += skip_to_sep(cp, '|');		/* extract deps - not used */
    if (index(cp, '|'))
	cp += skip_to_sep(cp, '|');		/* patch deps - not used */
    if (index(cp, '|'))
	cp += skip_to_sep(cp, '|');		/* fetch deps - not used */
    if (index(cp, '|'))
        cp += copy_to_sep(volstr, cp, '|');	/* media volume */
    else {
	strncpy(volstr, cp, 1023);
    }
    *volume = atoi(volstr);
    return 0;
}
Exemplo n.º 2
0
/* Read a single item. Syntax is:
 *
 * element : 
 * 	whitespace* item whitespace* [EOF|EOL|separator]
 *
 * item : 
 * 	double |
 * 	"anything" |
 * 	empty
 *
 * the anything in quotes can contain " escaped with \
 *
 * Return the char that caused failure on fail (EOF or \n).
 */
static int
read_double( FILE *fp, const char whitemap[256], const char sepmap[256],
	int lineno, int colno, double *out )
{
	int ch;

	/* The fscanf() may change this ... but all other cases need a zero.
	 */
	*out = 0;

	ch = skip_white( fp, whitemap );
	if( ch == EOF || 
		ch == '\n' ) 
		return( ch );

	if( ch == '"' ) {
		(void) fgetc( fp );
		(void) skip_to_quote( fp );
		ch = fgetc( fp );
	}
	else if( !sepmap[ch] && 
		fscanf( fp, "%lf", out ) != 1 ) {
		/* Only a warning, since (for example) exported spreadsheets
		 * will often have text or date fields.
		 */
		vips_warn( "csv2vips", 
			_( "error parsing number, line %d, column %d" ),
			lineno, colno );

		/* Step over the bad data to the next separator.
		 */
		ch = skip_to_sep( fp, sepmap );
	}

	/* Don't need to check result, we have read a field successfully.
	 */
	ch = skip_white( fp, whitemap );

	/* If it's a separator, we have to step over it. 
	 */
	if( ch != EOF && 
		sepmap[ch] ) 
		(void) fgetc( fp );

	return( 0 );
}