Exemplo n.º 1
0
static void step_predicate_parser(parser_context *context)
{
    enter_state(context, ST_PREDICATE);

    skip_ws(context);
    if('[' == get_char(context))
    {
        consume_char(context);
        if(!look_for(context, "]"))
        {
            context->result.code = ERR_UNBALANCED_PRED_DELIM;
            return;
        }
        skip_ws(context);
        if(']' == get_char(context))
        {
            context->result.code = ERR_EMPTY_PREDICATE;
            return;
        }

        try_predicate_parser(wildcard_predicate);
        try_predicate_parser(subscript_predicate);
        try_predicate_parser(slice_predicate);

        if(JSONPATH_SUCCESS != context->result.code && ERR_PARSER_OUT_OF_MEMORY != context->result.code)
        {
            context->result.code = ERR_UNSUPPORTED_PRED_TYPE;
        }
    }
    else
    {
        unexpected_value(context, '[');
    }
}
Exemplo n.º 2
0
/*
 * shop = addop << addop
 *      | addop >> addop
 *      | addop
 */
int
parse_shop(char **p)
{
    int val1, val2;
    int done = 0;

    skip_ws(p);
    
    val1 = parse_addop(p);

    do {
	skip_ws(p);

	if (*(*p) == '>' && *(*p+1) == '>') {
      (*p) += 2;	/* skip >> */
	    val2 = parse_addop(p);
	    if (val2 < 0)
		error("negative shift count");
	    val1 = val1 >> val2;

	} else if (*(*p) == '<' && *(*p+1) == '<') {
      (*p) += 2;	/* skip >> */
	    val2 = parse_addop(p);
	    if (val2 < 0)
		error("negative shift count");
	    val1 = val1 << val2;

	} else
	    done = 1;

    } while (!done);
Exemplo n.º 3
0
/* extract_range()
 *
 * Handle input strings like:
 *
 * "1-15"
 * " 1 - 15 "
 * " 1000--- 1500"
 * " 1 <<em-dash>> 10"
 * " 107 111"
 */
static void
extract_range( newstr *input, newstr *begin, newstr *end )
{
	/* -30 is the first character of a UTF8 em-dash and en-dash */
	const char terminators[] = { ' ', '-', '\t', '\r', '\n', -30, '\0' };
	char *p;

	newstr_empty( begin );
	newstr_empty( end );

	if ( input->len==0 ) return;

	p = skip_ws( input->data );
	while ( *p && !strchr( terminators, *p ) )
		newstr_addchar( begin, *p++ );

	p = skip_ws( p );

	while ( *p=='-' ) p++;
	while ( utf8_is_emdash( p ) ) p+=3;
	while ( utf8_is_endash( p ) ) p+=3;

	p = skip_ws( p );

	while ( *p && !strchr( terminators, *p ) )
		newstr_addchar( end, *p++ );
}
Exemplo n.º 4
0
static char *
bibtex_tag( char *p, newstr *tag )
{
	p = newstr_cpytodelim( tag, skip_ws( p ), "= \t\r\n", 0 );
	if ( newstr_memerr( tag ) ) return NULL;
	return skip_ws( p );
}
Exemplo n.º 5
0
/*            <MedlineDate>2003 Jan-Feb</MedlineDate> */
static int
medin_medlinedate( fields *info, char *p, int level )
{
	int fstatus;
	newstr tmp;

	newstr_init( &tmp );

	p = newstr_cpytodelim( &tmp, skip_ws( p ), " \t\n\r", 0 );
	if ( newstr_memerr( &tmp ) ) return BIBL_ERR_MEMERR;
	if ( tmp.len > 0 ) {
		fstatus = fields_add( info, "PARTYEAR", tmp.data, level );
		if ( fstatus!=FIELDS_OK ) return BIBL_ERR_MEMERR;
	}

	p = newstr_cpytodelim( &tmp, skip_ws( p ), " \t\n\r", 0 );
	if ( newstr_memerr( &tmp ) ) return BIBL_ERR_MEMERR;
	if ( tmp.len > 0 ) {
		newstr_findreplace( &tmp, "-", "/" );
		fstatus = fields_add( info, "PARTMONTH", tmp.data, level );
		if ( fstatus!=FIELDS_OK ) return BIBL_ERR_MEMERR;
	}

	p = newstr_cpytodelim( &tmp, skip_ws( p ), " \t\n\r", 0 );
	if ( newstr_memerr( &tmp ) ) return BIBL_ERR_MEMERR;
	if ( tmp.len > 0 ) {
		fstatus = fields_add( info, "PARTDAY", tmp.data, level );
		if ( fstatus!=FIELDS_OK ) return BIBL_ERR_MEMERR;
	}

	newstr_free( &tmp );

	return BIBL_OK;
}
Exemplo n.º 6
0
static int
parse_comp(const char *s, int strict,
	   VALUE *num)
{
    char *buf, *b;
    VALUE tmp;
    int ret = 1;

    buf = ALLOCV_N(char, tmp, strlen(s) + 1);
    b = buf;

    skip_ws(&s);
    if (!read_comp(&s, strict, num, &b)) {
	ret = 0;
    }
    else {
	skip_ws(&s);

	if (strict)
	    if (*s != '\0')
		ret = 0;
    }
    ALLOCV_END(tmp);

    return ret;
}
Exemplo n.º 7
0
static char *get_value(char **pos, config_file_t *cf, char *skipped)
{
	char *p = *pos;
	char *q;
	char *start;

	*skipped = '\0';
	if (*p == '"')
	{
		p++;
		start = p;
		q = p;
		while (*p != '\0' && *p != '\r' && *p != '\n' && *p != '"')
		{
			if (*p == '\\' && (p[1] == '"' || p[1] == '\\'))
				p++;
			*q++ = *p++;
		}
		if (*p == '\0')
		{
			config_file_error(cf, "File ends inside quoted string");
			return NULL;
		}
		if (*p == '\r' || *p == '\n')
		{
			config_file_error(cf, "Newline inside quoted string");
			return NULL;
		}
		if (*p != '"')
		{
			config_file_error(cf, "Weird character terminating quoted string (BUG)");
			return NULL;
		}
		p++;
		*q = '\0';
		*pos = p;
		skip_ws(pos, cf);
		return start;
	}
	else
	{
		start = p;
		while (*p != '\0' && *p != '\t' && *p != '\r' && *p != '\n' &&
				*p != ' ' && *p != '/' && *p != '#' &&
				*p != ';' && *p != '{' && *p != '}')
			p++;
		if (p == start)
			return NULL;
		*pos = p;
		skip_ws(pos, cf);
		if (p == *pos)
			*skipped = *p;
		*p = '\0';
		if (p == *pos)
			(*pos)++;
		return start;
	}
}
Exemplo n.º 8
0
static const gchar* read_reg(const gchar *s, guint8 *r, int *line, GError **error)
{
	guint num = 0;

	s = skip_ws(s, line);
	if (!s || !*s) {
		g_set_error(error, ROBOT_ERROR, ROBOT_ERROR_SYNTAX, "Waiting for register name at line %d", *line);
		return NULL;
	}

	/* Special case: const */
	if (g_ascii_isxdigit(*s) && g_ascii_isxdigit(s[1]) && (s[2] == 0 || g_ascii_isspace(s[2]))) {
		num = g_ascii_xdigit_value(s[0]) * 16 + g_ascii_xdigit_value(s[1]);
		*r = num;
		s += 2;

		return skip_ws(s, line);
	}

	if (*s != 'r' && *s != 'R') {
		g_set_error(error, ROBOT_ERROR, ROBOT_ERROR_SYNTAX, "Waiting for register name at line %d", *line);
		return NULL;
	}

	++s;
	if (!g_ascii_isdigit(*s)) {
		g_set_error(error, ROBOT_ERROR, ROBOT_ERROR_SYNTAX, "Waiting for register name at line %d", *line);
		return NULL;
	}

	num = g_ascii_digit_value(*s);
	++s;
	if (g_ascii_isdigit(*s)) {
		num = num * 10 + g_ascii_digit_value(*s);
		++s;
		if (!*s || g_ascii_isspace(*s)) {
			*r = num;
			if (num > 31) {
				g_set_error(error, ROBOT_ERROR, ROBOT_ERROR_SYNTAX, "We've got only 32 registers (at line %d)", *line);
				return NULL;
			}
			return skip_ws(s, line);
		} else {
			g_set_error(error, ROBOT_ERROR, ROBOT_ERROR_SYNTAX, "Waiting for register name at line %d", *line);
			return NULL;
		}
	} else if (!*s || g_ascii_isspace(*s)) {
		*r = num;
		return skip_ws(s, line);
	} else {
		g_set_error(error, ROBOT_ERROR, ROBOT_ERROR_SYNTAX, "Waiting for register name at line %d", *line);
		return NULL;
	}

	return NULL;
}
Exemplo n.º 9
0
/** suche den beginn des nächsten wortes 
 */
int next_id( int line, int *p)
{
  if( skip_ws(line,p) ) return -1;
  while( *p < m_len(line) )
    {
      if( isspace( CHAR(line,*p)) ) return skip_ws(line,p);
      (*p)++;
    }
  return -1;
}
Exemplo n.º 10
0
static int parse_header_line( char* line, char** pkey, char** pvalue )
{
	char* s;
	char* end;
	char* key_end;
	char c;

	s = prepare_line( line, &end );
	if( *s == '\0' )
	{
		return 1;
	}

	*pkey = s;
	while( ( c = *s ) != '=' && c != ' ' && c != '\t' )
	{
		if( c == '\0' )
		{
			fprintf( stderr, "kum error: invalid header format.\n" );
			exit( 1 );			
		}

		++s;
	}

	key_end = s;
	s = (char*) skip_ws( s );
	if( key_end == *pkey || *s != '=' )
	{
		fprintf( stderr, "kum error: invalid header format.\n" );
		exit( 1 );			
	}

	*key_end = '\0';
	++s;

	s = (char*) skip_ws( s );

	if( *s != '\"' && *s != '\'' )
	{
		*pvalue = s;
	}
	else
	{
		/* Removing quotes */
		*pvalue = s + 1;
		
		if( end > *pvalue && *(end - 1) == *s )
		{
			*--end = '\0';
		}
	}
	
	return 1;
}
Exemplo n.º 11
0
/*
 * mulop = unop * unop
 *       | unop / unop
 *       | unop % unop
 *       | unop
 */
int
parse_mulop(char **p)
{
    int val1, val2;
    int done = 0;

    skip_ws(p);
    
    val1 = parse_unop(p);

    do {
	skip_ws(p);

	switch (**p) {

	case '*':
	    (*p)++;	/* skip * */
	    val2 = parse_unop(p);
	    val1 = val1 * val2;
	    break;

	case '/':
        (*p)++;	/* skip /  */
	    val2 = parse_unop(p);
	    if (val2 == 0) {
		if (g_pass == 2)
		    error("division by zero");
		done = 1;
		break;
	    }
	    val1 = val1 / val2;
	    break;

	case '%':
        (*p)++;	/* skip / */
	    val2 = parse_unop(p);
	    if (val2 == 0) {
		if (g_pass == 2)
		    error("modulus of zero");
		done = 1;
		break;
	    }
	    val1 = val1 % val2;
	    break;

	default:
	    done = 1;
	    break;
	}
    } while (!done);

    return val1;
}
Exemplo n.º 12
0
static BOOL
seta_assignment ( LPCTSTR* p_, INT* result )
{
	LPCTSTR p = *p_;
	LPTSTR ident;
	TCHAR op = 0;
	INT identlen, exprval;

	PARSE_IDENT(ident,identlen,p);
	if ( identlen )
	{
		p = skip_ws(p);
		if ( *p == _T('=') )
			op = *p, p = skip_ws(p+1);
		else if ( _tcschr ( _T("*/%+-&^|"), *p ) && p[1] == _T('=') )
			op = *p, p = skip_ws(p+2);
		else if ( _tcschr ( _T("<>"), *p ) && *p == p[1] && p[2] == _T('=') )
			op = *p, p = skip_ws(p+3);
	}

	/* allow to chain multiple assignments, such as: a=b=1 */
	if ( ident && op )
	{
		INT identval;
		LPTSTR buf;

		if ( !seta_assignment ( &p, &exprval ) )
			return FALSE;

		if ( !seta_identval ( ident, &identval ) )
			identval = 0;
		switch ( op )
		{
		case '=':
			identval = exprval;
			break;
		case '<':
			identval <<= exprval;
			break;
		case '>':
			identval >>= exprval;
			break;
		default:
			if ( !calc ( &identval, op, exprval ) )
				return FALSE;
		}
		buf = (LPTSTR)alloca ( 32 * sizeof(TCHAR) );
		_sntprintf ( buf, 32, _T("%i"), identval );
		SetEnvironmentVariable ( ident, buf ); // TODO FIXME - check return value
		exprval = identval;
	}
Exemplo n.º 13
0
static const gchar* read_data(const gchar *s, GByteArray *data, int *line, GError **error)
{
	unsigned char c;
	const gchar *p;

	++s;

	while (*s) {
		s = skip_ws(s, line);

		if (*s == '}') {
			++s;
			return s;
		}

		if (!g_ascii_isxdigit(*s)) {
			g_set_error(error, ROBOT_ERROR, ROBOT_ERROR_SYNTAX, "Invalid symbol at line %d `%16s'", *line, s);
			return NULL;
		}

		c = g_ascii_xdigit_value(*s) * 16;
		++s;

		if (!g_ascii_isxdigit(*s)) {
			g_set_error(error, ROBOT_ERROR, ROBOT_ERROR_SYNTAX, "Invalid symbol at line %d `%16s'", *line, s);
			return NULL;
		}

		c += g_ascii_xdigit_value(*s);
		++s;

		g_byte_array_append(data, &c, 1);

		p = skip_ws(s, line);
		if (p == s && *s != '}') {
			g_set_error(error, ROBOT_ERROR, ROBOT_ERROR_SYNTAX, "Invalid symbol at line %d `%16s'", *line, s);
			return NULL;
		}

		s = p;
	}

	c = 0;
	while (data->len % 4 != 0)
		g_byte_array_append(data, &c, 1);

	return NULL;
}
Exemplo n.º 14
0
static BOOL
seta_bitAndTerm ( LPCTSTR* p_, INT* result )
{
	LPCTSTR p = *p_;
	INT lval;
	if ( !seta_logShiftTerm ( &p, &lval ) )
		return FALSE;
	while ( *p && _tcschr(_T("<>"),*p) && p[0] == p[1] )
	{
		INT rval;
		TCHAR op = *p;

		p = skip_ws ( p+2 );

		if ( !seta_logShiftTerm ( &p, &rval ) )
			return FALSE;

		switch ( op )
		{
		case '<':
			lval <<= rval;
			break;
		case '>':
			lval >>= rval;
			break;
		default:
			ConErrResPuts ( STRING_INVALID_OPERAND );
			return FALSE;
		}
	}

	*result = lval;
	*p_ = p;
	return TRUE;
}
Exemplo n.º 15
0
static BOOL
seta_ltorTerm ( LPCTSTR* p_, INT* result, LPCTSTR ops, BOOL (*subTerm)(LPCTSTR*,INT*) )
{
	LPCTSTR p = *p_;
	INT lval;
	if ( !subTerm ( &p, &lval ) )
		return FALSE;
	while ( *p && _tcschr(ops,*p) )
	{
		INT rval;
		TCHAR op = *p;

		p = skip_ws ( p+1 );

		if ( !subTerm ( &p, &rval ) )
			return FALSE;

		if ( !calc ( &lval, op, rval ) )
			return FALSE;
	}

	*result = lval;
	*p_ = p;
	return TRUE;
}
Exemplo n.º 16
0
static BOOL
seta_mulTerm ( LPCTSTR* p_, INT* result )
{
	LPCTSTR p = *p_;
	TCHAR op = 0;
	INT rval;
	if ( _tcschr(_T("!~-"),*p) )
	{
		op = *p;
		p = skip_ws ( p + 1 );
	}
	if ( !seta_unaryTerm ( &p, &rval ) )
		return FALSE;
	switch ( op )
	{
	case '!':
		rval = !rval;
		break;
	case '~':
		rval = ~rval;
		break;
	case '-':
		rval = -rval;
		break;
	}

	*result = rval;
	*p_ = p;
	return TRUE;
}
Exemplo n.º 17
0
static char *
process_bibtexline( char *p, newstr *tag, newstr *data )
{
	p = skip_ws( p );
	p = bibtex_item( p, tag );
	p = skip_ws( p );
	if ( *p=='=' ) {
		p++;
		p = skip_ws( p );
		p = bibtex_item( p, data );
		p = skip_ws( p );
	}
	if ( *p==',' || *p=='}' || *p==')' ) p++;
	p = skip_ws( p );
	return p;
}
Exemplo n.º 18
0
const char* SkParse::FindHex(const char str[], uint32_t* value)
{
    SkASSERT(str);
    str = skip_ws(str);

    if (!is_hex(*str))
        return NULL;

    uint32_t n = 0;
    int max_digits = 8;
    int digit;

    while ((digit = to_hex(*str)) >= 0)
    {
        if (--max_digits < 0)
            return NULL;
        n = (n << 4) | digit;
        str += 1;
    }

    if (*str == 0 || is_ws(*str))
    {
        if (value)
            *value = n;
        return str;
    }
    return NULL;
}
Exemplo n.º 19
0
static int
get_line(char *src, char *dst, int len)
{
	char *p;

	if (src == NULL) {
		return -1;
	}
	if (dst == NULL) {
		return -1;
	}
	if (len < 0) {
		return -1;
	}

	p = skip_ws(src); /* ignore headding spaces */

	if (p == NULL)
		return 0;

	while (*p != '\n' && *p != '\0') {
		*dst =  *p;
		dst++; p++;
	}
	*dst = '\0';

	return (p - src);
}
Exemplo n.º 20
0
/* get reference name */
static char*
process_bibtexid( char *p, newstr *data )
{
	newstr tmp;
	char *start_p = p;
	newstr_init( &tmp );
	newstr_empty( data );

	while ( *p && *p!=',' ) newstr_addchar( &tmp, *p++ );
	if ( *p==',' ) p++;
	p = skip_ws( p ); /* skip ending newline/carriage return */

	if ( tmp.len ) {
		if ( strchr( tmp.data, '=' ) ) {
			/* Endnote writes bibtex files w/o fields, try to
			 * distinguish via presence of an equal sign.... if
			 * it's there, assume that it's a tag/data pair instead
			 * and roll back.
			 */
			p = start_p;
		} else {
			/* add '{' and '}' to protect from string expansion */
			newstr_addchar( data, '{' );
			newstr_strcat( data, tmp.data );
			newstr_addchar( data, '}' );
		}
	}

	newstr_free( &tmp );
	return p;
}
Exemplo n.º 21
0
static char*
process_bibtexid( char *p, newstr *id )
{
	char *start_p = p;
	newstr tmp;

	newstr_init( &tmp );
	p = newstr_cpytodelim( &tmp, p, ",", 1 );

	if ( tmp.len ) {
		if ( strchr( tmp.data, '=' ) ) {
			/* Endnote writes bibtex files w/o fields, try to
			 * distinguish via presence of an equal sign.... if
			 * it's there, assume that it's a tag/data pair instead
			 * and roll back.
			 */
			p = start_p;
			newstr_empty( id );
		} else {
			newstr_strcpy( id, tmp.data );
		}
	} else {
		newstr_empty( id );
	}

	newstr_free( &tmp );
	return skip_ws( p );
}
Exemplo n.º 22
0
/* Split keywords="" with semicolons.
 * Commas are also frequently used, but will break
 * entries like:
 *       keywords="Microscopy, Confocal"
 * Returns BIBL_OK or BIBL_ERR_MEMERR
 */
static int
process_keywords( fields *info, newstr *d, int level )
{
	int fstatus, status = BIBL_OK;
	newstr keyword;
	char *p;

	if ( !d || d->len==0 ) return BIBL_OK;

	p = d->data;
	newstr_init( &keyword );

	while ( *p ) {
		p = newstr_cpytodelim( &keyword, skip_ws( p ), ";", 1 );
		newstr_trimendingws( &keyword );
		if ( newstr_memerr( &keyword ) ) {
			status = BIBL_ERR_MEMERR;
			goto out;
		}
		if ( keyword.len ) {
			fstatus = fields_add( info, "KEYWORD", keyword.data, level );
			if ( fstatus!=FIELDS_OK ) {
				status = BIBL_ERR_MEMERR;
				goto out;
			}
		}
	}
out:
	newstr_free( &keyword );
	return status;
}
Exemplo n.º 23
0
static void do_addr(const char* line, uint8_t len)
{
  uint16_t tmp;

  skip_ws(&line, &len);

  if (len == 0)
  {
    /* get address value */
    write_ok();
    uart_write((const uint8_t*)uint16_to_string(mem_addr), 4);
    write_eol();
  }
  else
  {
    /* set address value */
    if (string_to_uint16(line, &tmp)) goto on_error;
    mem_addr = tmp;
    write_ok();
  }

  return ;

 on_error:
  write_ko();
  return ;
}
Exemplo n.º 24
0
void
name_add( fields *info, char *tag, char *q, int level, list *asis, list *corps )
{
	newstr inname;
	char *p, *start, *end;

	if ( !q ) return;

	newstr_init( &inname );

	while ( *q ) {

		start = q = skip_ws( q );

		/* strip tailing whitespace and commas */
		while ( *q && *q!='|' ) q++;
		end = q;
		while ( is_ws( *end ) || *end==',' || *end=='|' || *end=='\0' )
			end--;

		for ( p=start; p<=end; p++ )
			newstr_addchar( &inname, *p );

		/* keep "names" like " , " from coredumping program */
		if ( inname.len ) {
			name_process( info, tag, level, &inname, asis, corps );
			newstr_empty( &inname );
		}

		if ( *q=='|' ) q++;
	}
	newstr_free( &inname );
}
Exemplo n.º 25
0
const char* SkParse::FindS32(const char str[], int32_t* value)
{
    SkASSERT(str);
    str = skip_ws(str);

    int sign = 0;
    if (*str == '-')
    {
        sign = -1;
        str += 1;
    }

    if (!is_digit(*str))
        return NULL;

    int n = 0;
    while (is_digit(*str))
    {
        n = 10*n + *str - '0';
        str += 1;
    }
    if (value)
        *value = (n ^ sign) - sign;
    return str;
}
Exemplo n.º 26
0
Arquivo: graf.c Projeto: imr/ngspice
double *
readtics(char *string)
{
    int k;
    char *words, *worde;
    double *tics, *ticsk;

    tics = TMALLOC(double, MAXTICS);
    ticsk = tics;
    words = string;

    for (k = 0; *words && k < MAXTICS; words = worde) {

        words = skip_ws(words);

        worde = words;
        while (isalpha_c(*worde) || isdigit_c(*worde))
            worde++;

        if (*worde)
            *worde++ = '\0';

        sscanf(words, "%lf", ticsk++);

        k++;

    }
    *ticsk = HUGE;
    return (tics);
}
Exemplo n.º 27
0
/* process_string()
 *
 * Handle lines like:
 *
 * '@STRING{TL = {Tetrahedron Lett.}}'
 *
 * p should point to just after '@STRING'
 *
 * In BibTeX, if a string is defined several times, the last one is kept.
 *
 */
static int
process_string( char *p )
{
	int n, status = BIBL_OK;
	newstr s1, s2, *t;
	newstrs_init( &s1, &s2, NULL );
	while ( *p && *p!='{' && *p!='(' ) p++;
	if ( *p=='{' || *p=='(' ) p++;
	p = process_bibtexline( skip_ws( p ), &s1, &s2, 0, NULL );
	if ( p==NULL ) { status = BIBL_ERR_MEMERR; goto out; }
	if ( s2.data ) {
		newstr_findreplace( &s2, "\\ ", " " );
	}
	if ( s1.data ) {
		n = list_find( &find, s1.data );
		if ( n==-1 ) {
			t = list_add( &find, &s1 );
			if ( t==NULL ) { status = BIBL_ERR_MEMERR; goto out; }
			if ( s2.data ) t = list_add( &replace, &s2 );
			else t = list_addc( &replace, "" );
			if ( t==NULL ) { status = BIBL_ERR_MEMERR; goto out; }
		} else {
			if ( s2.data ) t = list_set( &replace, n, &s2 );
			else t = list_setc( &replace, n, "" );
			if ( t==NULL ) { status = BIBL_ERR_MEMERR; goto out; }
		}
	}
out:
	newstrs_free( &s1, &s2, NULL );
	return status;
}
Exemplo n.º 28
0
/*
 * readf()
 *
 * returns zero if cannot get reference and hit end of-file
 * returns 1 if last reference in file, 2 if reference within file
 */
int
bibtexin_readf( FILE *fp, char *buf, int bufsize, int *bufpos, newstr *line, newstr *reference, int *fcharset )
{
	int haveref = 0;
	char *p;
	*fcharset = CHARSET_UNKNOWN;
	while ( haveref!=2 && readmore( fp, buf, bufsize, bufpos, line ) ) {
		if ( line->len == 0 ) continue; /* blank line */
		p = &(line->data[0]);
		/* Recognize UTF8 BOM */
		if ( line->len > 2 && 
				(unsigned char)(p[0])==0xEF &&
				(unsigned char)(p[1])==0xBB &&
				(unsigned char)(p[2])==0xBF ) {
			*fcharset = CHARSET_UNICODE;
			p += 3;
		}
		p = skip_ws( p );
		if ( *p == '%' ) { /* commented out line */
			newstr_empty( line );
			continue;
		}
		if ( *p == '@' ) haveref++;
		if ( haveref && haveref<2 ) {
			newstr_strcat( reference, p );
			newstr_addchar( reference, '\n' );
			newstr_empty( line );
		} else if ( !haveref ) newstr_empty( line );
	
	}
	return haveref;
}
Exemplo n.º 29
0
static struct Code *parse_macro_args(struct TestFile *tf, int *error)
{
    struct Code *code;

    if (!split_macro_arg(tf)) {
        *error = 1;
        return NULL;
    }

    code = NEW0(struct Code);
    code->type = ARG_CODE;
    code->lineno = tf->lineno;
    code->u.c.str = tf->read_pos;
    code->u.c.len = tf->next_pos - tf->read_pos;
    tf->read_pos = tf->next_pos + 1;
    if (*tf->next_pos == ',') {
        tf->next_pos++;
        skip_ws(tf);
        code->next = parse_macro_args(tf, error);
        if (*error) {
            free(code);
            return NULL;
        }
    }
    assert(*tf->next_pos == ')');
    return code;
}
Exemplo n.º 30
0
int
copacin_processf( fields *copacin, char *p, char *filename, long nref )
{
	newstr tag, data;
	int status;
	newstr_init( &tag );
	newstr_init( &data );
	while ( *p ) {
		p = skip_ws( p );
		if ( copacin_istag( p ) ) {
			p = copacin_addtag2( p, &tag, &data );
			/* don't add empty strings */
			if ( tag.len && data.len ) {
				status = fields_add( copacin, tag.data, data.data, 0 );
				if ( status!=FIELDS_OK ) return 0;
			}
			newstr_empty( &tag );
			newstr_empty( &data );
		}
		else p = copacin_nextline( p );
	}
	newstr_free( &tag );
	newstr_free( &data );
	return 1;
}