char *skip_token(char *ptr)
{
  ptr = skip_white(ptr);
  ptr = skip_not_white(ptr);
  ptr = skip_white(ptr);
  return (ptr);
}
Beispiel #2
0
static void parse_comment( char* in, M3u_Playlist::info_t& info, bool first )
{
	in = skip_white( in + 1 );
	const char* field = in;
	while ( *in && *in != ':' )
		in++;
	
	if ( *in == ':' )
	{
		const char* text = skip_white( in + 1 );
		if ( *text )
		{
			*in = 0;
			     if ( !strcmp( "Composer", field ) ) info.composer = text;
			else if ( !strcmp( "Engineer", field ) ) info.engineer = text;
			else if ( !strcmp( "Ripping" , field ) ) info.ripping  = text;
			else if ( !strcmp( "Tagging" , field ) ) info.tagging  = text;
			else
				text = 0;
			if ( text )
				return;
			*in = ':';
		}
	}
	
	if ( first )
		info.title = field;
}
Beispiel #3
0
static void
read_lisp_symbol (FILE *infile, char *buffer)
{
  char c;
  char *fillp = buffer;

  skip_white (infile);
  while (1)
    {
      c = getc (infile);
      if (c == '\\')
	*(++fillp) = getc (infile);
      else if (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '(' || c == ')')
	{
	  ungetc (c, infile);
	  *fillp = 0;
	  break;
	}
      else
	*fillp++ = c;
    }

  if (! buffer[0])
    fprintf (stderr, "## expected a symbol, got '%c'\n", c);

  skip_white (infile);
}
Beispiel #4
0
Datei: lbind.c Projekt: ifzz/nui
static int parse_mask(lbind_Enum *et, const char *s, int *penum, lua_State *L) {
  *penum = 0;
  while (*s != '\0') {
    const char *e;
    int inversion = 0;
    lbind_EnumItem *item;
    s = skip_white(s);
    if (*s == '~') {
      inversion = 1;
      s = skip_white(s+1);
    }
    if (*s == '\0') break;
    e = skip_ident(s);
    if (e == s || (item = lbind_findenum(et, s, e-s)) == NULL) {
      if (L == NULL) return 0;
      if (e == s)
        return luaL_error(L, "unexpected token '%c' in %s", *s, et->name);
      else {
        lua_pushlstring(L, s, e-s);
        return luaL_error(L, "unexpected mask '%s' in %s", lua_tostring(L, -1), et->name);
      }
    }
    s = e;
    if (inversion)
      *penum &= ~item->value;
    else
      *penum |= item->value;
  }
  return 1;
}
Beispiel #5
0
pdf_obj *parse_pdf_array (char **start, char *end)
{
  pdf_obj *result, *tmp1;
#ifdef MEM_DEBUG
MEM_START
#endif
  skip_white(start, end);
  if (*((*start)++) != '[')
    return NULL;
  result = pdf_new_array ();
  skip_white(start, end);
  while (*start < end &&
	 **start != ']') {
    if ((tmp1 = parse_pdf_object (start, end)) == NULL) {
      pdf_release_obj (result);
      return NULL;
    };
    pdf_add_array (result, tmp1);
    skip_white(start, end);
  }
  if (*start >= end) {
    pdf_release_obj (result);
    fprintf (stderr, "\nArray ended prematurely\n");
    return NULL;
  }
  (*start)++;
#ifdef MEM_DEBUG
MEM_END
#endif
  return result;
}
Beispiel #6
0
char *
jump_etc(char *op)
{	char *p = op;

	/* try to get the type separated from the name */

	p = skip_white(p);	/* initial white space */

	if (strncmp(p, "enum", strlen("enum")) == 0) /* special case: a two-part typename */
	{	p += strlen("enum")+1;
		p = skip_white(p);
	}
	p = skip_nonwhite(p);	/* type name */
	p = skip_white(p);	/* white space */
	while (*p == '*') p++;	/* decorations */
	p = skip_white(p);	/* white space */

	if (*p == '\0')
		fatal("c_state format (%s)", op);

	if (strchr(p, '[')
	&&  !strchr(p, '{'))
	{	non_fatal("array initialization error, c_state (%s)", p);
		return (char *) 0;
	}

	return p;
}
Beispiel #7
0
NODE*
parse_any(SCANNER *s, int mode) {
  NODE *x = NULL;
  int c;

  skip_white(s);
  if (s_eof(s)) return raise(s, "unexpected end of file");

  c = s_peek(s);

  if (c == '(') {
    s_getc(s);
    x = parse_paren(s, mode);
    if (x == NULL) return NULL;
    if (s_eof(s)) {
      return raise(s, "unexpected end of file");
    }
    skip_white(s);
    if (s_getc(s) != ')') {
      return invalid_token(s);
    }
  } else if (c == '\'')
    x = parse_quote(s);
  else if (c == '`')
    return parse_bquote(s);
  else if (c == '"')
    x = parse_string(s);
  else if (isalnum((int)c) || strchr(SYMBOL_CHARS, c))
    x = parse_primitive(s);
  else
    return invalid_token(s);

  return x;
}
// Get next token.
static parse_ptr get_token(parse_ptr src, token_info & token, const char * path, int & line)
{
  src = skip_white(src, path, line);
  switch (*src) {
    case '{': case '}': case ',':
      // Simple token
      token.type = *src; token.line = line;
      ++src;
      break;

    case '"':
      // String constant
      token.type = '"'; token.line = line;
      token.value = "";
      do {
        for (++src; *src != '"'; ++src) {
          char c = *src;
          if (!c || c == '\n' || (c == '\\' && !src[1])) {
            pout("%s(%d): Missing terminating '\"'\n", path, line);
            token.type = '?'; token.line = line;
            return src;
          }
          if (c == '\\') {
            c = *++src;
            switch (c) {
              case 'n' : c = '\n'; break;
              case '\n': ++line; break;
              case '\\': case '"': break;
              default:
                pout("%s(%d): Unknown escape sequence '\\%c'\n", path, line, c);
                token.type = '?'; token.line = line;
                continue;
            }
          }
          token.value += c;
        }
        // Lookahead to detect string constant concatentation
        src = skip_white(++src, path, line);
      } while (*src == '"');
      break;

    case 0:
      // EOF
      token.type = 0; token.line = line;
      break;

    default:
      pout("%s(%d): Syntax error, invalid char '%c'\n", path, line, *src);
      token.type = '?'; token.line = line;
      while (*src && *src != '\n')
        ++src;
      break;
  }

  return src;
}
Beispiel #9
0
// Parse next letter/number pair.
// Returns the remaining line or NULL if end reached.
static const char *gcodep_parse_pair_with_linenumber(int line_num,
                                                     const char *line,
                                                     char *letter, float *value,
                                                     FILE *err_stream) {
  // TODO: error callback when we have errors with messages.
  if (line == NULL)
    return NULL;
  line = skip_white(line);

  if (*line == '\0' || *line == ';' || *line == '%')
    return NULL;

  if (*line == '(') {  // Comment between words; e.g. G0(move) X1(this axis)
    while (*line && *line != ')')
      line++;
    line = skip_white(line + 1);
    if (*line == '\0') return NULL;
  }

  *letter = toupper(*line++);
  if (*line == '\0') {
    fprintf(err_stream ? err_stream : stderr,
	    "// Line %d G-Code Syntax Error: expected value after '%c'\n",
            line_num, *letter);
    return NULL;
  }
  // If this line has a checksum, we ignore it. In fact, the line is done.
  if (*letter == '*')
    return NULL;
  while (*line && isspace(*line))
    line++;

  // Parsing with strtof() can be problematic if the line does
  // not contain spaces, and strof() sees the sequence 0X... as it treats that
  // as hex value. E.g. G0X1. Unlikely, but let's do a nasty workaround:
  char *repair_x = (*(line+1) == 'x' || *(line+1) == 'X') ? (char*)line+1 : NULL;
  if (repair_x) *repair_x = '\0';  // pretend that is the end of number.

  char *endptr;
  *value = strtof(line, &endptr);

  if (repair_x) *repair_x = 'X';  // Put the 'X' back.

  if (line == endptr) {
    fprintf(err_stream ? err_stream : stderr, "// Line %d G-Code Syntax Error:"
	    " Letter '%c' is not followed by a number `%s`.\n",
            line_num, *letter, line);
    return NULL;
  }
  line = endptr;

  line = skip_white(line); // Makes the line better to deal with.
  return line;  // We parsed something; return whatever is remaining.
}
char *
has_ident(const char *name,
	  char *first,
	  char *last)
{
    char *base;
    char *s, *t, *d, c;

    name = leaf_of(name);

    s = first;
    while ((t = base = strchr(s, '$')) != 0 && (t < last)) {
	t++;
	if ((s = exact(skip_camel(t), "Id")) != 0
	    || (s = exact(t, "Header")) != 0) {
	    if (*s == '$') {
		return base;
	    } else if ((*s == ':')
		       && is_inline(t, '$')) {
		/* RCS identifier can have pathname prepended */
		s = skip_white(s + 1);
		d = skip_text(s);
		c = *d;
		*d = EOS;
		while (is_inline(s, '/'))
		    s++;
		*d = c;
		if ((s = same_name(s, name)) != 0
		    && (s = exact(s, ",v")) != 0
		    && isspace(*s))
		    return base;
	    }
	}
	s = t;
    }

    s = first;
    while ((t = base = strchr(s, '@')) != 0 && (t < last)) {
	t++;
	if ((s = exact(t, "(#)")) != NULL) {
	    t = s;
	    /* some versions of SCCS don't do module-name */
	    if ((s = same_name(t, name)) != NULL)
		return base;

	    t = skip_text(t);	/* module-name, if any */
	    t = skip_white(t);
	    if ((s = same_name(t, name)) != NULL)
		return base;
	}
	s = t;
    }
    return 0;
}
Beispiel #11
0
NODE*
parse_paren(SCANNER *s, int mode) {
  NODE *head, *node, *x;

  skip_white(s);
  if (s_eof(s)) return raise(s, "unexpected end of file");

  head = node = new_node();
  node->t = NODE_CELL;
  while (!s_eof(s) && s_peek(s) != ')') {
    NODE *child;
    char q = s_peek(s) == ',';
    if (q) s_getc(s);

    child = parse_any(s, PARSE_ANY);
    if (child == NULL) return NULL;

    if ((mode & PARSE_BQUOTE) != 0 && !q) {
      NODE *r = new_node();
      r->t = NODE_QUOTE;
      r->car = child;
      child = r;
    }

    if (child->t == NODE_IDENT && !strcmp(".", child->s)) {
      if (!head->car) {
        free_node(child);
        return raise(s, "illegal dot operation");
      }
      free_node(child);

      child = parse_any(s, PARSE_ANY);
      if (child == NULL) return NULL;
      node->cdr = child;
      break;
    } else {
      if (head->car) {
        x = new_node();
        x->t = NODE_CELL;
        node->cdr = x;
        node = x;
      }
      node->car = child;
    }

    skip_white(s);
  }

  if (!head->car && !head->cdr)
    head->t = NODE_NIL;

  return head;
}
Beispiel #12
0
pdf_obj *parse_pdf_dict (char **start, char *end)
{
  pdf_obj *result, *tmp1, *tmp2;
  char *save = *start;
  skip_white(start, end);
  if (*((*start)++) != '<' ||
      *((*start)++) != '<') {
    *start = save;
    dump (*start, end);
    return NULL;
  }
  result = pdf_new_dict ();
    skip_white(start, end);
  while (*start < end &&
	 **start != '>') {
    if ((tmp1 = parse_pdf_name (start, end)) == NULL) {
      pdf_release_obj (result); 
      {
	*start = save;
	dump (*start, end);
	return NULL;
      }
    };
    if ((tmp2 = parse_pdf_object (start, end)) == NULL) {
      pdf_release_obj (result);
      pdf_release_obj (tmp1); 
      {
	*start = save;
	dump (*start, end);
	return NULL;
      }
    }
    pdf_add_dict (result, tmp1, tmp2);
    skip_white(start, end);
  }
  if (*start >= end) {
    pdf_release_obj (result);
    *start = save;
    dump (*start, end);
    return NULL;
  }
  if (*((*start)++) == '>' &&
      *((*start)++) == '>') {
    return result;
  } else {
    pdf_release_obj (result);
    fprintf (stderr, "\nDictionary object ended prematurely\n");
    *start = save;
    dump (*start, end);
    return NULL;
  }
}
Beispiel #13
0
void
proc_parse_config(const char *token, char *cptr)
{
    char            tmpname[STRMAX];
    struct myproc **procp = &procwatch;

    /*
     * don't allow two entries with the same name 
     */
    copy_nword(cptr, tmpname, sizeof(tmpname));
    if (get_proc_by_name(tmpname) != NULL) {
        config_perror("Already have an entry for this process.");
        return;
    }

    /*
     * skip past used ones 
     */
    while (*procp != NULL)
        procp = &((*procp)->next);

    (*procp) = (struct myproc *) calloc(1, sizeof(struct myproc));
    if (*procp == NULL)
        return;                 /* memory alloc error */
    numprocs++;
    /*
     * not blank and not a comment 
     */
    copy_nword(cptr, (*procp)->name, sizeof((*procp)->name));
    cptr = skip_not_white(cptr);
    if ((cptr = skip_white(cptr))) {
        (*procp)->max = atoi(cptr);
        cptr = skip_not_white(cptr);
        if ((cptr = skip_white(cptr)))
            (*procp)->min = atoi(cptr);
        else
            (*procp)->min = 0;
    } else {
        /* Default to asssume that we require at least one
         *  such process to be running, but no upper limit */
        (*procp)->max = 0;
        (*procp)->min = 1;
        /* This frees "proc <procname> 0 0" to monitor
         * processes that should _not_ be running. */
    }
#ifdef NETSNMP_PROCFIXCMD
    sprintf((*procp)->fixcmd, NETSNMP_PROCFIXCMD, (*procp)->name);
#endif
    DEBUGMSGTL(("ucd-snmp/proc", "Read:  %s (%d) (%d)\n",
                (*procp)->name, (*procp)->max, (*procp)->min));
}
Beispiel #14
0
static void parse_fmtargs(parse_info *info, int *wide, int *count) {
    skip_white(info->fmt);
    parse_optint(&info->fmt, wide);
    skip_white(info->fmt);
    if (*info->fmt == '*') {
        ++info->fmt;
        skip_white(info->fmt);
        parse_optint(&info->fmt, count);
    }
    else if (*info->fmt == '$') {
        ++info->fmt;
        *count = -1;
    }
    skip_white(info->fmt);
}
Beispiel #15
0
static int parse_html_tag (char **start, char *end)
{
  int result = -1;
  char *token = NULL;
  int closing = 0;
  skip_white(start, end);
  if (*start < end) {
    if (**start == '/') {
      (*start)++;
      closing = 1;
    }
    if (*start < end && (token = parse_ident (start, end))) {
      downcase (token);
      {
	int i;
	for (i=0; i<sizeof(tags)/sizeof(tags[0]); i++) {
	  if (!strcmp (token, tags[i])) {
	    result = i;
	    if (closing) 
	      result += sizeof(tags)/sizeof(tags[0]);
	  }
	  break;
	}
	if (i>=sizeof(tags)/sizeof(tags[0]))
	  result = -1;
      }
      RELEASE (token);
    }
  }
  return result;
}
Beispiel #16
0
/**
 * @internal
 * parse mode: save everything
 */
void
_pm_save_everything(FILE *f, netsnmp_container *cin, int flags)
{
    char               line[STRINGMAX], *ptr;
    size_t             len;

    netsnmp_assert(NULL != f);
    netsnmp_assert(NULL != cin);

    while (fgets(line, sizeof(line), f) != NULL) {

        ptr = line;
        len = strlen(line) - 1;
        if (line[len] == '\n')
            line[len] = 0;

        /*
         * save blank line or comment?
         */
        if (flags & PM_FLAG_SKIP_WHITESPACE) {
            if (NULL == (ptr = skip_white(ptr)))
                continue;
        }

        ptr = strdup(line);
        if (NULL == ptr) {
            snmp_log(LOG_ERR,"malloc failed\n");
            break;
        }

        CONTAINER_INSERT(cin,ptr);
    }
}
Beispiel #17
0
Bool	
str_to_bool(
    char  *ptr,
    Bool  def_val
)
{
    if (!ptr || !*ptr)	return def_val;
    skip_white(ptr);

    switch (*ptr) {		/* true/false , 1/0 , yes/no , on/off */
	case '1':
	case 'T': case 't':
	case 'Y': case 'y':
		def_val = True; break;

	case '0':
	case 'F': case 'f':
	case 'N': case 'n':
		def_val = False; break;

	case 'O': case 'o':
		if (ptr[1] == 'N' || ptr[1] == 'n')
		    def_val = True;
		else if (ptr[1] == 'F' || ptr[1] == 'f')
		    def_val = False;
		break;
    }
    return def_val;
}
Beispiel #18
0
/* Read a single double in ascii (not locale) encoding.
 *
 * Return the char that caused failure on fail (EOF or \n).
 */
static int
read_ascii_double( FILE *fp, const char whitemap[256], double *out )
{
	int ch;
	char buf[256];
	char *p;

	*out = 0.0;

	ch = skip_white( fp, whitemap );

	if( ch == EOF || 
		ch == '\n' ) 
		return( ch );

	fetch_nonwhite( fp, whitemap, buf, 256 );

	/* The str we fetched must contain at least 1 digit. This helps stop
	 * us trying to convert "MATLAB" (for example) to a number and 
	 * getting zero.
	 */
	for( p = buf; *p; p++ )
		if( isdigit( *p ) )
			break;
	if( !*p ) 
		return( *buf ); 

	*out = g_ascii_strtod( buf, NULL );

	return( 0 );
}
Beispiel #19
0
static char* parse_name( char* in )
{
	char* out = in;
	while ( 1 )
	{
		int c = *in;
		if ( !c ) break;
		in++;
		
		if ( c == ',' ) // commas in string
		{
			char* p = skip_white( in );
			if ( *p == ',' || *p == '-' || from_dec( *p ) <= 9 )
			{
				in = p;
				break;
			}
		}
		
		if ( c == '\\' ) // \ prefix for special characters
		{
			c = *in;
			if ( !c ) break;
			in++;
		}
		*out++ = (char) c;
	}
	*out = 0; // terminate string
	return in;
}
Beispiel #20
0
float factor() {
  float value;
  float sign = 1.0;

  if (*look == '-') {
    sign = -1;
  }

  if (*look == '(') {
    match('(');
    value = expression();
    match(')');
    return value;
  }
  else if (is_alpha(*look)) {
    switch (*look) {
    case 'x': {
      value = env.x;
    } break;
    case 'y': {
      value = env.y;
    } break;
    }
    get_char();
    skip_white();
  }
  else {
    value = get_num();
  }
  return sign*value;
}
Beispiel #21
0
void
se_read_conf(const char *word, char *cptr)
{
    int major, minor;
    int value;
    char *cp, *cp2;
    char e_name[BUFSIZ];
    char e_enum[  BUFSIZ];

    if (!cptr || *cptr=='\0')
        return;

    /*
     * Extract the first token
     *   (which should be the name of the list)
     */
    cp = copy_nword(cptr, e_name, sizeof(e_name));
    cp = skip_white(cp);
    if (!cp || *cp=='\0')
        return;


    /*
     * Add each remaining enumeration to the list,
     *   using the appropriate style interface
     */
    if (sscanf(e_name, "%d:%d", &major, &minor) == 2) {
        /*
         *  Numeric major/minor style
         */
        while (1) {
            cp = copy_nword(cp, e_enum, sizeof(e_enum));
            if (sscanf(e_enum, "%d:", &value) != 1) {
                break;
            }
            cp2 = e_enum;
            while (*(cp2++) != ':')
                ;
            se_add_pair(major, minor, strdup(cp2), value);
            if (!cp)
                break;
        }
    } else {
        /*
         *  Named enumeration
         */
        while (1) {
            cp = copy_nword(cp, e_enum, sizeof(e_enum));
            if (sscanf(e_enum, "%d:", &value) != 1) {
                break;
            }
            cp2 = e_enum;
            while (*(cp2++) != ':')
                ;
            se_add_pair_to_slist(e_name, strdup(cp2), value);
            if (!cp)
                break;
        }
    }
}
Beispiel #22
0
char *copy_word(char *from, char *to)
{
  char quote;
  if ( (*from == '\"') || (*from =='\'') ){
    quote = *(from++);
    while ( (*from != quote) && (*from != 0) ) {
      if ((*from == '\\') && (*(from+1) != 0)) {
	*to++ = *(from+1);
	from = from +2;
      }
      else  *to++ = *from++;
    }
    if (*from == 0) {
      DEBUGMSGTL(("read_config_copy_word",
                  "no end quote found in config string\n"));
    } else from++;
  }
  else {
    while (*from != 0 && !isspace(*from)) {
      if ((*from == '\\') && (*(from+1) != 0)) {
	*to++ = *(from+1);
	from = from +2;
      }
      else  *to++ = *from++;
    }
  }
  *to = 0;
  from = skip_white(from);
  return(from);
}  /* copy_word */
Beispiel #23
0
int	read_tag_line(
    FILE	*fp,
    char	**tagp, 
    char        **valp
)
{
    char	*lp, *lp2;

    while (fgets(lp = tag_linebuf, BUFSIZ, fp)) {
	tag_line_num++;
	skip_white(lp);		/* lp = trim_line(lp); */
	if (!*lp || *lp == '\n' || is_comment_char(*lp))
	    continue;
	if (!(lp2 = strchr(lp, TAG_END_CHAR))) {
	    continue;
	}
	*lp2++ = 0;
	lp2 = trim_line(lp2);

	*tagp = lp;
	*valp = *lp2 ? lp2 : 0;
	return tag_line_num;
    }
    *tagp = *valp = 0;

    return (ferror(fp)) ? -1 : 0;
}
Beispiel #24
0
char *parse_number (char **start, char *end)
{
  char *number, *save;
#ifdef MEM_DEBUG
MEM_START
#endif
  skip_white(start, end);
  save = *start;
  if (*start < end && (**start == '+' || **start == '-')) {
    *start += 1;
  }
  while (*start < end &&
	 isdigit(**start))
    (*start)++;
  if (*start < end && **start == '.') {
    (*start)++;
    while (*start < end &&
	   isdigit(**start))
      (*start)++;
  }
  if (*start > save) {
    number = NEW ((*start-save)+1, char);
    memcpy (number, save, (*start-save));
    number[*start-save] = 0;
    return number;
  }
Beispiel #25
0
void
loadave_parse_config(const char *token, char *cptr)
{
    int             i;

    if (strcmp(token, "pload") == 0) {
        if (laConfigSet < 0) {
            snmp_log(LOG_WARNING,
                     "ignoring attempted override of read-only load\n");
            return;
        } else {
            laConfigSet++;
        }
    } else {
        if (laConfigSet > 0) {
            snmp_log(LOG_WARNING,
                     "ignoring attempted override of read-only load\n");
            /*
             * Fall through and copy in this value.
             */
        }
        laConfigSet = -1;
    }

    for (i = 0; i <= 2; i++) {
        if (cptr != NULL)
            maxload[i] = atof(cptr);
        else
            maxload[i] = maxload[i - 1];
        cptr = skip_not_white(cptr);
        cptr = skip_white(cptr);
    }
}
void
proc_parse_config(const char *token, char *cptr)
{
    char            tmpname[STRMAX];
    struct myproc **procp = &procwatch;

    /*
     * don't allow two entries with the same name 
     */
    copy_nword(cptr, tmpname, sizeof(tmpname));
    if (get_proc_by_name(tmpname) != NULL) {
        config_perror("Already have an entry for this process.");
        return;
    }

    /*
     * skip past used ones 
     */
    while (*procp != NULL)
        procp = &((*procp)->next);

    (*procp) = (struct myproc *) calloc(1, sizeof(struct myproc));
    if (*procp == NULL)
        return;                 /* memory alloc error */
    numprocs++;
    /*
     * not blank and not a comment 
     */
    copy_nword(cptr, (*procp)->name, sizeof((*procp)->name));
    cptr = skip_not_white(cptr);
    if ((cptr = skip_white(cptr))) {
        (*procp)->max = atoi(cptr);
        cptr = skip_not_white(cptr);
        if ((cptr = skip_white(cptr)))
            (*procp)->min = atoi(cptr);
        else
            (*procp)->min = 0;
    } else {
        (*procp)->max = 0;
        (*procp)->min = 0;
    }
#ifdef NETSNMP_PROCFIXCMD
    sprintf((*procp)->fixcmd, NETSNMP_PROCFIXCMD, (*procp)->name);
#endif
    DEBUGMSGTL(("ucd-snmp/proc", "Read:  %s (%d) (%d)\n",
                (*procp)->name, (*procp)->max, (*procp)->min));
}
Beispiel #27
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 );
}
Beispiel #28
0
char get_name() {
  if (!is_alpha(*look))
    expected("name");
  char ret = *look;
  get_char();
  skip_white();
  return ret;
}
Beispiel #29
0
void parse_crap (char **start, char *end)
{
  skip_white(start, end);
  if (*start != end) {
    fprintf (stderr, "\nCrap left over after object!!\n");
    dump(*start, end);
  }
}
Beispiel #30
0
static int
trim_opening_comment(
			BFile	file,
			long	*funcOffPtr,
			long	*funcLenPtr,
			long	protoOff
)
{
#define funcOff (*funcOffPtr)
#define funcLen (*funcLenPtr)
    long	startOff = bfile_get_off(file);
    long	newCommentOff = -1;
    long	commentOff = -1;
    long		funcLenDiff = 0;
    long		newFuncOff = 0;
    COMMENT_TYPE	commentType;
    BOOL		done = FALSE;

    bfile_set_off(file, funcOff);
    bfile_forward(file);

    while (!done)
    {
        commentType = find_comment_start(file, &newCommentOff);
        if (   (commentType == COMMENT_UNDEF)
	    || (newCommentOff >= protoOff) )
	{
	    done = TRUE;
	}
	else
	{
	    commentOff = newCommentOff;
	    skip_comment(file, commentType);
	}
    }

    if (commentOff > 0)
    {
	funcLenDiff = (funcOff - commentOff);
	funcOff = commentOff;
	funcLen += funcLenDiff;
    }
	
    /* 
     * trim white space 
     */
    bfile_set_off(file, funcOff);
    skip_white(file);
    newFuncOff = bfile_get_off(file);
    funcLenDiff = (funcOff - newFuncOff);
    funcOff = newFuncOff;
    funcLen += funcLenDiff;

    bfile_set_off(file, startOff);
    return 0;
#undef funcOff
#undef funcLen
}