Exemple #1
0
tree
xml_html_parser::parse_doctype () {
  s += 9;
  tree dt= tuple ("doctype");
  skip_space ();
  dt << parse_name ();
  skip_space ();
  if (test (s, "SYSTEM")) dt << parse_system ();
  else if (test (s, "PUBLIC")) dt << parse_public ();
  skip_space ();

  if (test (s, "[")) {
    s += 1;
    while (s) {
      skip_space ();
      if (test (s, "]")) { s += 1; break; }
      else if (test (s, "<!ELEMENT")) dt << parse_element ();
      else if (test (s, "<!ATTLIST")) dt << parse_cdata ();
      else if (test (s, "<!ENTITY")) parse_entity_decl ();
      else if (test (s, "<!NOTATION")) a << parse_notation ();
      else if (test (s, "<?")) dt << parse_pi ();
      else if (test (s, "<!--")) dt << parse_comment ();
      else if (s[0] == '&' || s[0] == '%') (void) parse_entity ();
      else s += 1;
    }
  }

  skip_space ();
  if (test (s, ">")) s += 1;
  return dt;
}
Exemple #2
0
blargg_err_t M3u_Playlist::parse_()
{
	info_.title    = "";
	info_.composer = "";
	info_.engineer = "";
	info_.ripping  = "";
	info_.tagging  = "";
	
	int const CR = 13;
	int const LF = 10;
	
	data.end() [-1] = LF; // terminate input
	
	first_error_ = 0;
	bool first_comment = true;
	int line  = 0;
	int count = 0;
	char* in  = data.begin();
	while ( in < data.end() )
	{
		// find end of line and terminate it
		line++;
		char* begin = in;
		while ( *in != CR && *in != LF )
		{
			if ( !*in )
				return "Not an m3u playlist";
			in++;
		}
		if ( in [0] == CR && in [1] == LF ) // treat CR,LF as a single line
			*in++ = 0;
		*in++ = 0;
		
		// parse line
		if ( *begin == '#' )
		{
			parse_comment( begin, info_, first_comment );
			first_comment = false;
		}
		else if ( *begin )
		{
			if ( (int) entries.size() <= count )
				RETURN_ERR( entries.resize( count * 2 + 64 ) );
			
			if ( !parse_line( begin, entries [count] ) )
				count++;
			else if ( !first_error_ )
				first_error_ = line;
			first_comment = false;
		}
	}
	if ( count <= 0 )
		return "Not an m3u playlist";
	
	if ( !(info_.composer [0] | info_.engineer [0] | info_.ripping [0] | info_.tagging [0]) )
		info_.title = "";
	
	return entries.resize( count );
}
Exemple #3
0
closure *parse_null(FILE *file, closure *accum)
{
    //printf("parse null\n");
    wchar_t c = fgetwc(file);
    if(iswspace(c)){
	return parse_null(file, nil());
    } else if(c == L'$'){
	return parse_character(file, nil());
    } else if(c == L'#'){
	parse_comment(file, nil());
	return parse_null(file, accum);
    } else if(c == L'\"'){
	return parse_string(file, nil());
    } else if(c == L'\''){
	wchar_t c = fgetwc(file);
	if (!iswspace(c)){
	    ungetwc(c, file);
	    closure *boo = parse_null(file, nil());
	    if (boo != NULL) return quote(boo);
	}
	return symbol(QUOTE);
    } else if(c == L'@'){
	wchar_t c = fgetwc(file);
	if (!iswspace(c)){
	    ungetwc(c, file);
	    closure *boo = parse_null(file, nil());
	    if (boo != NULL) return list(2, symbol(ATPEND), boo);
	}
	return symbol(ATPEND);
    } else if(c == L','){
	wchar_t c = fgetwc(file);
	if (!iswspace(c)){
	    ungetwc(c, file);
	    closure *boo = parse_null(file, nil());
	    if (boo != NULL) return list(2, symbol(COMMA), boo);
	}
	return symbol(COMMA);
    } else if(c == L'*'){
	wchar_t c = fgetwc(file);
	if (!iswspace(c)){
	    ungetwc(c, file);
	    closure *boo = parse_null(file, nil());
	    if (boo != NULL) return list(2, symbol(ASTERIX), boo);
	}
	return symbol(ASTERIX);
    } else if(iswdigit(c)){
	ungetwc(c, file);
	return parse_number(file, nil());
    } else if(c == L'('){
	return parse_list(file, nil());
    } else if(c == L')'){
	ungetwc(c, file);
	return NULL;
    } else if(c == WEOF || c == EOF){
	return NULL;
    } else {
	return parse_symbol(file, cons(character(c), nil()));
    }
}
Exemple #4
0
void parse()
{
    ncomments = nchars = 0;
    p = line;
    line[0] = 0;

    for (next_char(); c > 0; next_char()) {
        while (c == ' ' || c == '\n') next_char();

        if (c == '/') parse_comment();
        else if (c == '"') parse_string();
        else parse_literal();
    }
}
static bool
end_vernac_command (string s, int i) {
  int n= N(s);
  if (!(i<n && s[i] == '.')) return false;
  i++;
  while (i<n) {
   if (is_spacing (s[i]))
     i++;
   else if (start_comment (s, i))
     parse_comment (s, i);
   else
     break;
  }
  return i >= n || s[i] == '\n';
}
Exemple #6
0
/** ignore tab space '\n comment */
void preprocess(){
    while(1){
        if(ch == ' ' || ch == '\t' || ch == '\r')
            skip_white_space();
        else if(ch == '/'){
                        ///向前多看一个字符来判断是否为注释,若不是在放回缓冲区中
            getch();
            if(ch=='*')
                parse_comment();
            else{
                ungetc(ch,fin);///rollback char
                ch = '/';
                break;
            }
        }else
            break;
    }
}
static array<string>
split_command (string s) {
  int start= 0, i=0, n= N(s);
  array<string> r;
  while (i<n) {
    if (s[i] == '.' && i+1<n && is_spacing (s[i+1])) {
      r << s(start, ++i);
      while (i<n && is_spacing (s[i])) i++;
      start= i;
    }
    else if (start_comment (s, i))
      parse_comment (s, i);
    else
      i++;
  }
  if (start < n)
    r << s(start, n);
  return r;
}
Exemple #8
0
/** разобрать "выражение"
	выражение: последовательность слов разделённых пробелами
**/
int
parse_expression(char *text,char **endptr,Tag *toptag) {
	char *s,*p;
	Tag *tag;
	int comma;
	TRACE("");
	if (!text) return 0;
	s=text;
	tag=NULL;
	comma=1;
	if (toptag) tag=mark(EXPR,text,text,toptag);
	while(*s) {
		p=s;
		mark_ctype(NULL,isblank,s,&s,tag);
		if (s[0]==',') {
			/* слова в выражении разделены , */
			if (comma) {
				mark(NIL,s,s,tag);
			}
			mark_len(NULL,1,s,&s,tag);	// отметить ,
			mark_ctype(NULL,isspace,s,&s,tag); // после , разрешён \n
			comma=1;
			continue;
		} else {
			comma=0;
		}
		if (s[0]=='#' && s[1]=='!') parse_comment(s,&s,tag);
		if (s[0]=='#' && s[1]=='?' && s[2]=='>') parse_print(s,&s,tag);
		if (strchr(EXPTERM,*s)) break;
		if ('('==*s) {
			parse_tuple(s,&s,tag);
		} else
			parse_word(s,&s,tag);
		if (p==s) break;
	}
	if (comma) {
		mark(NIL,s,s,tag);
		s++;
	}
	if (endptr) *endptr=s;
	return 0;
}
Exemple #9
0
void parser::parse_text( std::istream &in )
{
	while ( !in.eof() && in )
	{
		int c = in.get();
		if ( std::char_traits<char>::not_eof( c ) )
		{
			if ( c == '[' )
			{
				switch ( in.peek() )
				{
					case '[':
						_func.push_text();
						parse_expr( in );
						break;

					case '%':
						_func.push_text( true );
						parse_code( in );
						break;

					case '#':
						_func.push_text( true );
						parse_directive( in );
						break;

					case '/':
						_func.push_text( true );
						parse_comment( in );
						break;

					default:
						_func.add( static_cast<char>( c ) );
						break;
				}
			}
			else
				_func.add( static_cast<char>( c ) );
		}
	}
	_func.push_text();
}
Exemple #10
0
void
xml_html_parser::parse () {
  string r;
  while (s) {
    if (s[0] == '<') {
      if (N(r) != 0) { a << tree (r); }
      if (test (s, "</")) a << parse_closing ();
      else if (test (s, "<?")) a << parse_pi ();
      else if (test (s, "<!--")) a << parse_comment ();
      else if (test (s, "<![CDATA[")) a << parse_cdata ();
      else if (test (s, "<!DOCTYPE")) a << parse_doctype ();
      else if (test (s, "<!")) a << parse_misc ();
      else a << parse_opening ();
      r= "";
    }
    else if (s[0] == '&') r << parse_entity ();
    else r << s->read (1);
  }
  if (N(r) != 0) a << tree (r);
}
Exemple #11
0
static const char *
next_token (const char *s, char *token, size_t *tokenlen, size_t tokenmax)
{
        if (*s == '(')
                return (parse_comment (s + 1, token, tokenlen, tokenmax));
        if (*s == '"')
                return (parse_quote (s + 1, token, tokenlen, tokenmax));
        if (is_special (*s)) {
                if (*tokenlen < tokenmax)
                        token[(*tokenlen)++] = *s;
                return (s + 1);
        }
        while (*s) {
                if (is_email_wsp(*s) || is_special (*s))
                        break;
                if (*tokenlen < tokenmax)
                        token[(*tokenlen)++] = *s;
                s++;
        }
        return s;
}
int			parse_name_comment(t_bin *bin, t_parser *p)
{
	if (!bin->has_name && ft_strstr(p->line, NAME_CMD_STRING) == p->line)
	{
		p->i += ft_strlen(NAME_CMD_STRING);
		parse_name(bin, p);
		bin->has_name = 1;
		return (1);
	}
	else if (!bin->has_comment
			&& ft_strstr(p->line, COMMENT_CMD_STRING) == p->line)
	{
		p->i += ft_strlen(COMMENT_CMD_STRING);
		parse_comment(bin, p);
		bin->has_comment = 1;
		return (1);
	}
	else
		parse_error(p, "Expected file name or comment");
	return (0);
}
Exemple #13
0
static int
comment_parse(int c, char **argv, int invert, unsigned int *flags,
              const void *entry, struct xt_entry_match **match)
{
	struct xt_comment_info *commentinfo = (struct xt_comment_info *)(*match)->data;

	switch (c) {
	case '1':
		xtables_check_inverse(argv[optind-1], &invert, &optind, 0);
		if (invert) {
			xtables_error(PARAMETER_PROBLEM,
					"Sorry, you can't have an inverted comment");
		}
		parse_comment(argv[optind-1], commentinfo);
		*flags = 1;
		break;

	default:
		return 0;
	}
	return 1;
}
Exemple #14
0
int parse_commit(struct commit_node* n, FILE *f)
{
        char lbuf[MAX_LBUF_SIZE];

        fgets(lbuf, MAX_LBUF_SIZE, f);
        if (begins_with(lbuf, COMMIT_TOKEN)) 
               memcpy(n->hash, lbuf + strlen(COMMIT_TOKEN), COMMIT_HASH_SIZE);
        else
               return 0;
        while (strcmp(fgets(lbuf, MAX_LBUF_SIZE, f), "")
               &&  strcmp(lbuf, "\n")) 
        {
                if (begins_with(lbuf, AUTHOR_TOKEN))
                        n->author = new_str_after_token(lbuf, AUTHOR_TOKEN);
                if (begins_with(lbuf, DATE_TOKEN)) 
                        n->date = new_str_after_token(lbuf, DATE_TOKEN);
               
        }
        parse_comment(n, lbuf, f);

        return 1;
}
Exemple #15
0
// comment = "(" *( ctext | quoted-pair | comment ) ")"
const char* parse_comment(unsigned char **p)
{
	if (parse_char(p, '('))
		return ERR;

	if (!parse_char(p, ')'))
		return NULL;

	int len = 0;

	while(0 != (char)**p)
	{
		if (!parse_ctext(p))
		{
			len++;
			continue;
		}
		else if (!parse_quoted_pair(p))
		{
			len++;
			continue;
		}
		else if (!parse_comment(p))
		{
			len++;
			continue;
		}
		else
		{
			break;
		}
	}

	if (!parse_char(p, ')'))
		return NULL;
	else
		return ERR;
}
Exemple #16
0
LPCSTR next_token( LPCSTR s, LPSTR token, size_t * tokenlen, size_t tokenmax )
{
  if (*s == '(')
    return ( parse_comment(s + 1, token, tokenlen, tokenmax ) );
  if (*s == '"')
    return ( parse_quote( s + 1, token, tokenlen, tokenmax ) );

  if ( is_special( *s ) )
  {
    if (*tokenlen < tokenmax)
      token[(*tokenlen)++] = *s;
    return (s + 1);
  }
  while (*s)
  {
    if ( isspace( (unsigned char)*s ) || is_special( *s ) )
      break;
    if ( *tokenlen < tokenmax )
      token[ (*tokenlen)++ ] = *s;
    s++;
  }
  return s;
}
Exemple #17
0
static tree
parse_subcommand (string s, bool wrap= false) {
  int start= 0, i= 0, n= N(s);
  tree r= "";
  while (i<n) {
    if (start_comment (s, i)) {
      append_commands (r,
          indent_subcommand (from_verbatim (s(start, i), wrap)));
      if (start_coqdoc (s, i))
        append_commands (r, parse_coqdoc (s, i));
      else
        append_commands (r, parse_comment (s, i));
      start= i;
    }
    else
      i++;
  }
  if (start < n)
    append_commands (r, indent_subcommand (from_verbatim (s(start, i), wrap)));
  if ((is_concat (r) || is_document (r)) && N(r) == 1)
    r= r[0];
  return r;
}
Exemple #18
0
static tree
parse_coqdoc_hide_show (string s, int &i) {
  tree beg= parse_coqdoc_hide_show_comment (s, i);
  int cnt= 1, n= N(s), start= i, stop= i;
  while (i<n && cnt > 0) {
    if (start_comment (s, i)) {
      if (is_hide_or_show (s, i)) {
        stop= i;
        tree tmp= parse_coqdoc_hide_show_comment (s, i);
        if (N(tmp) != 1);
        else if (tmp == beg)
          cnt++;
        else if (is_func (tmp, END, 1) && tmp[0] == beg[0])
          cnt--;
      }
      else
        parse_comment (s, i);
    }
    else
      i++;
  }
  tree body;
  if (cnt == 0)
    body= parse_raw_coq (s(start, stop));
  else
    body= parse_raw_coq (s(start, n));
  string lbl, msg;
  if (as_string (beg[0]) == "hide") {
    lbl= "folded";
    msg= "(* hidden *)";
  }
  else {
    lbl= "unfolded";
    msg= "(* shown *)";
  }
  return compound (lbl, msg, body);
}
Exemple #19
0
/** разобрать код
		последовательность выражений разделённых ';' '\n'

**/
int
parse_code(char *text,char **endptr,Tag *toptag) {
	char *s,*p;
	Tag *tag;
	tag=NULL;
	if (toptag) tag=mark(CODE,text,text,toptag);
	s=text;
	while(*s) {
		p=s;
		mark_ctype(NULL,isspace,s,&s,tag); // лидирующие пробелы
		if (s[0]=='#' && s[1]=='!' ) {		// комментарии пропускаются
			parse_comment(s,&s,tag);
			continue;
		}
		parse_expression(s,&s,tag); // выражения
		if (s[0]==';' || s[0]=='\n') {	// разделяемые ; или \n
			mark_len(NULL,1,s,&s,tag);
			continue;
		}
		if (p==s) break;	// зацикливание
	}
	if (endptr) *endptr=s;
	return 0;
}
Exemple #20
0
static tree
parse_raw_coq (string s) {
  tree doc (DOCUMENT), proof (DOCUMENT);
  tree *r= &doc;
  int i= 0, startcmd= 0, n= N(s), indent_level=-1;
  bool in_cmd= false;
  while (i<n) {
    if (!in_cmd && start_comment (s, i)) {
      if (start_coqdoc (s, i))
        *r << parse_coqdoc (s, i);
      else if (is_hide_or_show (s, i))
        *r << parse_coqdoc_hide_show (s, i);
      else
        *r << parse_comment (s, i);
    }
    else if (start_comment (s, i)) {
      if (is_hide_or_show (s, i))
        *r << parse_coqdoc_hide_show (s, i);
      else
        parse_comment (s, i);
    }
    else if (end_vernac_command (s, i)) {
      string body= s (startcmd, ++i);
      if (is_enunciation (body)) {
        *r << parse_enunciation (body);
        r= &proof;
      }
      else if (is_definition (body)) {
        *r << parse_enunciation (body);
      }
      else {
        tree tmp= parse_vernac_command (body);
        if (begin_proof (tmp) && end_proof (tmp)) {
          proof << parse_vernac_proof (body);
          doc << format_proof (proof);
          proof= tree (DOCUMENT);
          r= &doc;
        }
        else if (r == &proof) {
          if (end_proof (tmp)) {
            proof << tmp;
            doc << format_proof (proof);
            proof= tree (DOCUMENT);
            r= &doc;
          }
          else if (begin_proof (tmp)) {
            r= &proof;
            *r << parse_vernac_proof (body);
          }
          else
            *r << tmp;
        }
        else if (begin_proof (tmp)) {
          r= &proof;
          *r << parse_vernac_proof (body);
        }
        else
          *r << tmp;
      }
      in_cmd= false;
    }
    else if (!in_cmd && s[i] == '\n') {
      i++;
      int tmp= parse_indent (s, i);
      if (tmp >= 0 && tmp != indent_level) {
        *r << compound ("coq-indent", as_string (tmp));
        indent_level= tmp;
      }
      else if (i < n && s[i] == '\n') {
        *r << "";
        while (i+1 < n && s[i+1] == '\n') i++;
      }
    }
    else {
      if (!in_cmd && !is_blank (s[i])) {
        in_cmd= true;
        startcmd= i;
      }
      i++;
    }
  }
  if (N(proof) > 0)
    doc << format_proof (proof);
  if (in_cmd)
    doc << parse_vernac_command (s (startcmd, n));
  return doc;
}
Exemple #21
0
machine_t *prelude__parse_comment(machine_t *machine) {
    return parse_comment(machine);
}
Exemple #22
0
/**
 * Skips the next bit of whatever and returns the type of block.
 *
 * pc.str is the input text.
 * pc.len in the output length.
 * pc.type is the output type
 * pc.column is output column
 *
 * @param pc      The structure to update, str is an input.
 * @return        true/false - whether anything was parsed
 */
static bool parse_next(tok_ctx& ctx, chunk_t& pc)
{
   const chunk_tag_t *punc;
   int               ch, ch1;

   if (!ctx.more())
   {
      //fprintf(stderr, "All done!\n");
      return(false);
   }

   /* Save off the current column */
   pc.orig_line = ctx.c.row;
   pc.column    = ctx.c.col;
   pc.orig_col  = ctx.c.col;
   pc.type      = CT_NONE;
   pc.nl_count  = 0;
   pc.flags     = 0;

   /* If it is turned off, we put everything except newlines into CT_UNKNOWN */
   if (cpd.unc_off)
   {
      if (parse_ignored(ctx, pc))
      {
         return(true);
      }
   }

   /**
    * Parse whitespace
    */
   if (parse_whitespace(ctx, pc))
   {
      return(true);
   }

   /**
    * Handle unknown/unhandled preprocessors
    */
   if ((cpd.in_preproc > CT_PP_BODYCHUNK) &&
       (cpd.in_preproc <= CT_PP_OTHER))
   {
      pc.str.clear();
      tok_info ss;
      ctx.save(ss);
      /* Chunk to a newline or comment */
      pc.type = CT_PREPROC_BODY;
      int last = 0;
      while (ctx.more())
      {
         int ch = ctx.peek();

         if ((ch == '\n') || (ch == '\r'))
         {
            /* Back off if this is an escaped newline */
            if (last == '\\')
            {
               ctx.restore(ss);
               pc.str.pop_back();
            }
            break;
         }

         /* Quit on a C++ comment start */
         if ((ch == '/') && (ctx.peek(1) == '/'))
         {
            break;
         }
         last = ch;
         ctx.save(ss);

         pc.str.append(ctx.get());
      }
      if (pc.str.size() > 0)
      {
         return(true);
      }
   }

   /**
    * Detect backslash-newline
    */
   if ((ctx.peek() == '\\') && parse_bs_newline(ctx, pc))
   {
      return(true);
   }

   /**
    * Parse comments
    */
   if (parse_comment(ctx, pc))
   {
      return(true);
   }

   /* Parse code placeholders */
   if (parse_code_placeholder(ctx, pc))
   {
      return(true);
   }

   /* Check for C# literal strings, ie @"hello" and identifiers @for*/
   if ((cpd.lang_flags & LANG_CS) && (ctx.peek() == '@'))
   {
      if (ctx.peek(1) == '"')
      {
         parse_cs_string(ctx, pc);
         return(true);
      }
      /* check for non-keyword identifiers such as @if @switch, etc */
      if (CharTable::IsKw1(ctx.peek(1)))
      {
         parse_word(ctx, pc, true);
         return(true);
      }
   }

   /* Check for C# Interpolated strings */
   if ((cpd.lang_flags & LANG_CS) && (ctx.peek() == '$') && (ctx.peek(1) == '"'))
   {
      parse_cs_interpolated_string(ctx, pc);
      return(true);
   }

   /* handle VALA """ strings """ */
   if ((cpd.lang_flags & LANG_VALA) &&
       (ctx.peek() == '"') &&
       (ctx.peek(1) == '"') &&
       (ctx.peek(2) == '"'))
   {
      parse_verbatim_string(ctx, pc);
      return(true);
   }

   /* handle C++0x strings u8"x" u"x" U"x" R"x" u8R"XXX(I'm a "raw UTF-8" string.)XXX" */
   ch = ctx.peek();
   if ((cpd.lang_flags & LANG_CPP) &&
       ((ch == 'u') || (ch == 'U') || (ch == 'R')))
   {
      int  idx     = 0;
      bool is_real = false;

      if ((ch == 'u') && (ctx.peek(1) == '8'))
      {
         idx = 2;
      }
      else if (unc_tolower(ch) == 'u')
      {
         idx++;
      }

      if (ctx.peek(idx) == 'R')
      {
         idx++;
         is_real = true;
      }
      if (ctx.peek(idx) == '"')
      {
         if (is_real)
         {
            if (parse_cr_string(ctx, pc, idx))
            {
               return(true);
            }
         }
         else
         {
            if (parse_string(ctx, pc, idx, true))
            {
               parse_suffix(ctx, pc, true);
               return(true);
            }
         }
      }
   }

   /* PAWN specific stuff */
   if (cpd.lang_flags & LANG_PAWN)
   {
      if ((cpd.preproc_ncnl_count == 1) &&
          ((cpd.in_preproc == CT_PP_DEFINE) ||
           (cpd.in_preproc == CT_PP_EMIT)))
      {
         parse_pawn_pattern(ctx, pc, CT_MACRO);
         return(true);
      }
      /* Check for PAWN strings: \"hi" or !"hi" or !\"hi" or \!"hi" */
      if ((ctx.peek() == '\\') || (ctx.peek() == '!'))
      {
         if (ctx.peek(1) == '"')
         {
            parse_string(ctx, pc, 1, (ctx.peek() == '!'));
            return(true);
         }
         else if (((ctx.peek(1) == '\\') || (ctx.peek(1) == '!')) &&
                  (ctx.peek(2) == '"'))
         {
            parse_string(ctx, pc, 2, false);
            return(true);
         }
      }

      /* handle PAWN preprocessor args %0 .. %9 */
      if ((cpd.in_preproc == CT_PP_DEFINE) &&
          (ctx.peek() == '%') &&
          unc_isdigit(ctx.peek(1)))
      {
         pc.str.clear();
         pc.str.append(ctx.get());
         pc.str.append(ctx.get());
         pc.type = CT_WORD;
         return(true);
      }
   }

   /**
    * Parse strings and character constants
    */

   if (parse_number(ctx, pc))
   {
      return(true);
   }

   if (cpd.lang_flags & LANG_D)
   {
      /* D specific stuff */
      if (d_parse_string(ctx, pc))
      {
         return(true);
      }
   }
   else
   {
      /* Not D stuff */

      /* Check for L'a', L"abc", 'a', "abc", <abc> strings */
      ch  = ctx.peek();
      ch1 = ctx.peek(1);
      if ((((ch == 'L') || (ch == 'S')) &&
           ((ch1 == '"') || (ch1 == '\''))) ||
          (ch == '"') ||
          (ch == '\'') ||
          ((ch == '<') && (cpd.in_preproc == CT_PP_INCLUDE)))
      {
         parse_string(ctx, pc, unc_isalpha(ch) ? 1 : 0, true);
         return(true);
      }

      if ((ch == '<') && (cpd.in_preproc == CT_PP_DEFINE))
      {
         if (chunk_get_tail()->type == CT_MACRO)
         {
            /* We have "#define XXX <", assume '<' starts an include string */
            parse_string(ctx, pc, 0, false);
            return(true);
         }
      }
   }

   /* Check for Objective C literals and VALA identifiers ('@1', '@if')*/
   if ((cpd.lang_flags & (LANG_OC | LANG_VALA)) && (ctx.peek() == '@'))
   {
      int nc = ctx.peek(1);
      if ((nc == '"') || (nc == '\''))
      {
         /* literal string */
         parse_string(ctx, pc, 1, true);
         return(true);
      }
      else if ((nc >= '0') && (nc <= '9'))
      {
         /* literal number */
         pc.str.append(ctx.get());  /* store the '@' */
         parse_number(ctx, pc);
         return(true);
      }
   }

   /* Check for pawn/ObjectiveC/Java and normal identifiers */
   if (CharTable::IsKw1(ctx.peek()) ||
       ((ctx.peek() == '@') && CharTable::IsKw1(ctx.peek(1))))
   {
      parse_word(ctx, pc, false);
      return(true);
   }

   /* see if we have a punctuator */
   char punc_txt[4];
   punc_txt[0] = ctx.peek();
   punc_txt[1] = ctx.peek(1);
   punc_txt[2] = ctx.peek(2);
   punc_txt[3] = ctx.peek(3);
   if ((punc = find_punctuator(punc_txt, cpd.lang_flags)) != NULL)
   {
      int cnt = strlen(punc->tag);
      while (cnt--)
      {
         pc.str.append(ctx.get());
      }
      pc.type   = punc->type;
      pc.flags |= PCF_PUNCTUATOR;
      return(true);
   }

   /* throw away this character */
   pc.type = CT_UNKNOWN;
   pc.str.append(ctx.get());

   LOG_FMT(LWARN, "%s:%d Garbage in col %d: %x\n",
           cpd.filename, pc.orig_line, (int)ctx.c.col, pc.str[0]);
   cpd.error_count++;
   return(true);
} // parse_next
Exemple #23
0
static bool parse_ignored(tok_ctx& ctx, chunk_t& pc)
{
   int nl_count = 0;

   /* Parse off newlines/blank lines */
   while (parse_newline(ctx))
   {
      nl_count++;
   }
   if (nl_count > 0)
   {
      pc.nl_count = nl_count;
      pc.type     = CT_NEWLINE;
      return(true);
   }

   /* See if the UO_enable_processing_cmt text is on this line */
   ctx.save();
   pc.str.clear();
   while (ctx.more() &&
          (ctx.peek() != '\r') &&
          (ctx.peek() != '\n'))
   {
      pc.str.append(ctx.get());
   }
   if (pc.str.size() == 0)
   {
      /* end of file? */
      return(false);
   }
   /* Note that we aren't actually making sure this is in a comment, yet */
   const char *ontext = cpd.settings[UO_enable_processing_cmt].str;
   if (ontext == NULL)
   {
      ontext = UNCRUSTIFY_ON_TEXT;
   }
   if (pc.str.find(ontext) < 0)
   {
      pc.type = CT_IGNORED;
      return(true);
   }
   ctx.restore();

   /* parse off whitespace leading to the comment */
   if (parse_whitespace(ctx, pc))
   {
      pc.type = CT_IGNORED;
      return(true);
   }

   /* Look for the ending comment and let it pass */
   if (parse_comment(ctx, pc) && !cpd.unc_off)
   {
      return(true);
   }

   /* Reset the chunk & scan to until a newline */
   pc.str.clear();
   while (ctx.more() &&
          (ctx.peek() != '\r') &&
          (ctx.peek() != '\n'))
   {
      pc.str.append(ctx.get());
   }
   if (pc.str.size() > 0)
   {
      pc.type = CT_IGNORED;
      return(true);
   }
   return(false);
} // parse_ignored
Exemple #24
0
iterator &iterator::next( void )
{
	_type = TOK_UNKNOWN;
	_value.clear();

	// Skip any whitespace
	while ( utf::is_pattern_whitespace( _c ) && _utf )
		next_utf();

	_whitespace.swap( _value );
	_type = TOK_UNKNOWN;
	_value.clear();

	if ( !_utf )
		return *this;

	_start.set( _utf );

	if ( _c == '{' )
	{
		// Code block
		_type = TOK_BLOCK_START;
		next_utf();
	}
	else if ( _c == '}' )
	{
		// Code block
		_type = TOK_BLOCK_END;
		next_utf();
	}
	else if ( _c == '(' )
	{
		// Expression ordering
		_type = TOK_PAREN_START;
		next_utf();
	}
	else if ( _c == ')' )
	{
		// Expression ordering
		_type = TOK_PAREN_END;
		next_utf();
	}
	else if ( _c == '[' )
	{
		// Expression ordering
		_type = TOK_MOD_START;
		next_utf();
	}
	else if ( _c == ']' )
	{
		// Expression ordering
		_type = TOK_MOD_END;
		next_utf();
	}
	else if ( _c == ',' )
	{
		// Argument separator
		_type = TOK_COMMA;
		next_utf();
	}
	else if ( _c == ';' )
	{
		// Statement terminator
		_type = TOK_EXPRESSION_END;
		next_utf();
	}
	else if ( _c == ':' )
	{
		// Separator
		_type = TOK_SEPARATOR;
		next_utf();
	}
	else if ( _c == '\"' )
		parse_string();
	else if ( _c == '\'' )
		parse_char();
	else if ( _c == 0x2AFD || _c == '#' ) // Double slash character or hash
	{
		_whitespace.push_back( _c );
		parse_comment();
	}
	else if ( _c == '/' || _c == 0x29F8 || _c == 0xFF0F || _c == 0x2044 ) // Slash, big slash, and fullwidth slash, fraction slash
	{
		char32_t comment_start = _c;
		skip_utf();
		if ( _c == comment_start || _c == U'*' )
			parse_comment();
		else
		{
			_value += comment_start;
			parse_operator();
		}
	}
	else if ( utf::is_identifier_start( _c ) )
		parse_identifier();
	else if ( utf::is_pattern_syntax( _c ) )
		parse_operator();
	else if ( utf::is_number_decimal( _c ) )
		parse_number();
	else
		next_utf();

	utf::nfc( _whitespace );
	utf::nfc( _value );

	_end.set( _utf );

	return *this;
}
Exemple #25
0
static GwyContainer*
zeiss_load_tiff(const GwyTIFF *tiff, GError **error)
{
    GwyContainer *container = NULL, *meta = NULL;
    GwyDataField *dfield;
    GwySIUnit *siunit;
    GwyTIFFImageReader *reader = NULL;
    GHashTable *hash = NULL;
    gint i, power10;
    gchar *value, *end, *comment = NULL;
    gdouble *data;
    gboolean new_file;
    double factor, dx;

    /* Comment with parameters is common for all data fields */
    if (!gwy_tiff_get_string0(tiff, ZEISS_HEADER_TAG, &comment)) {
        err_FILE_TYPE(error, "Carl Zeiss SEM");
        goto fail;
    }

    if (strstr(comment, MAGIC_COMMENT))
        new_file = TRUE;
    else if (g_str_has_prefix(comment, SOMEWHAT_LESS_MAGIC_COMMENT))
        new_file = FALSE;
    else {
        err_FILE_TYPE(error, "Carl Zeiss SEM");
        goto fail;
    }

    /* Read the comment header. */
    if (new_file) {
        hash = parse_comment(comment);
        if ((value = g_hash_table_lookup(hash, "Image Pixel Size"))) {
            gwy_debug("Using dx from Image Pixel Size: %s", value);
        }
        else if ((value = g_hash_table_lookup(hash, "Pixel Size"))) {
            gwy_debug("Using dx from Pixel Size: %s", value);
        }
        else {
            err_MISSING_FIELD(error, "Pixel Size");
            goto fail;
        }
    }
    else {
        /* The first thing is the pixel size, apparently. */
        value = comment + strlen(SOMEWHAT_LESS_MAGIC_COMMENT);
        gwy_debug("Using dx from old-style comment: %s", value);
    }

    dx = g_ascii_strtod(value, &end);
    /* Use negated positive conditions to catch NaNs */
    if (!((dx = fabs(dx)) > 0)) {
        g_warning("Real pixel size is 0.0, fixing to 1.0");
        dx = 1.0;
    }
    if (!new_file)
        end = "m";

    /* Request a reader, this ensures dimensions and stuff are defined.
     * NB: Newer versions store the image as RGB.  Not useful here; just
     * average the channels.  */
    if (!(reader = gwy_tiff_get_image_reader(tiff, 0, 3, error)))
        goto fail;

    siunit = gwy_si_unit_new_parse(end, &power10);
    factor = pow10(power10);
    dfield = gwy_data_field_new(reader->width, reader->height,
                                reader->width * factor * dx,
                                reader->height * factor * dx,
                                FALSE);
    gwy_data_field_set_si_unit_xy(dfield, siunit);
    g_object_unref(siunit);

    data = gwy_data_field_get_data(dfield);
    if (reader->samples_per_pixel > 1) {
        gdouble *datarow = g_new(gdouble, reader->width);
        gint ch, j, spp = reader->samples_per_pixel;

        gwy_data_field_clear(dfield);
        for (i = 0; i < reader->height; i++) {
            for (ch = 0; ch < spp; ch++) {
                gwy_tiff_read_image_row(tiff, reader, 0, i, 1.0, 0.0, datarow);
                for (j = 0; j < reader->width; j++)
                    data[i*reader->width + j] += datarow[j];
            }
        }
        g_free(datarow);
        gwy_data_field_multiply(dfield, 1.0/spp);
        gwy_data_field_invalidate(dfield);
    }
    else {
        for (i = 0; i < reader->height; i++)
            gwy_tiff_read_image_row(tiff, reader, 0, i, 1.0, 0.0,
                                    data + i*reader->width);
    }

    container = gwy_container_new();
    gwy_container_set_object_by_name(container, "/0/data", dfield);
    g_object_unref(dfield);
    gwy_container_set_string_by_name(container, "/0/data/title",
                                     g_strdup("Secondary electron count"));

    if (new_file) {
        meta = gwy_container_new();
        g_hash_table_foreach(hash, add_meta, meta);
        if (gwy_container_get_n_items(meta))
            gwy_container_set_object_by_name(container, "/0/meta", meta);
        g_object_unref(meta);
    }

fail:
    if (hash)
        g_hash_table_destroy(hash);
    g_free(comment);

    return container;
}
Exemple #26
0
static int parse_fields (char *msg)
{
	char stemp[MAX_MSG_LEN+1];
	char *e;
	char *save;

	strcpy (stemp, msg);
	e = strtok_r (stemp, "*#", &save);
	while (e != NULL) {

	  switch (*e) {

	    case 'A': 
	      
	      switch (e[1]) {
	        case 'A':
	          parse_object_name (e);
	          break;
	        case 'B':
	          parse_symbol (e);
	          break;
	        case 'C':
	          /*
	           * New in 1.2: test for 10 digit callsign.
	           */
	          if (tt_call10_to_text(e+2,1,stemp) == 0) {
	             strcpy(m_callsign, stemp);
	          }
	          break;
	        default:
	          parse_callsign (e);
	          break;
	      }
	      break;

	    case 'B': 
	      parse_location (e);
	      break;

	    case 'C': 
	      parse_comment (e);
	      break;

	    case '0': 
	    case '1': 
	    case '2': 
	    case '3': 
	    case '4': 
	    case '5': 
	    case '6': 
	    case '7': 
	    case '8': 
	    case '9': 
	      expand_macro (e);
	      break;

	    case '\0':
	      /* Empty field.  Just ignore it. */
	      /* This would happen if someone uses a leading *. */
	      break;

	    default:

	      text_color_set(DW_COLOR_ERROR);
	      dw_printf ("Entry does not start with A, B, C, or digit: \"%s\"\n", msg);
	      return (TT_ERROR_D_MSG);

	  }
	
	  e = strtok_r (NULL, "*#", &save);
	}

	return (0);

} /* end parse_fields */
Exemple #27
0
void rrd_graph_script(
    int argc,
    char *argv[],
    image_desc_t *const im,
    int optno)
{
    int       i;

    /* and now handle the things*/
    parsedargs_t pa;
    initParsedArguments(&pa);

    /* loop arguments */
    for (i = optno; i < argc; i++) {
	/* release parsed args - avoiding late cleanups*/
	freeParsedArguments(&pa);
	/* processed parsed args */
	if (parseArguments(argv[i],&pa)) {
	  return; }

        /* dumpArguments(&pa); */
	/* now let us handle the field based on the first command or cmd=...*/
	char*cmd=NULL;
	/* and try to get via cmd */
	char* t=getKeyValueArgument("cmd",255,&pa);
	if (t) {
	  cmd=t;
	} else if ((t=getKeyValueArgument("pos0",255,&pa))) {
	  cmd=t;
	} else {
	  rrd_set_error("no command set in argument %s",pa.arg_orig);
	  freeParsedArguments(&pa);
	  return;
	}

	/* convert to enum but handling LINE special*/
	enum gf_en gf = (enum gf_en) -1;
	gf=gf_conv(cmd);
	if ((int)gf == -1) {
	  if (strncmp("LINE",cmd,4)==0) {
	    gf=GF_LINE;
	    addToArguments(&pa,NULL,"linewidth",cmd+4,0);
	  } else {
	    rrd_set_error("'%s' is not a valid function name in %s", cmd,pa.arg_orig );
	    return;
	  }
	}
	/* now we can handle the commands */
	int r=0;
	switch (gf) {
	case GF_XAXIS:     r=parse_axis(gf,&pa,im); break;
	case GF_YAXIS:     r=parse_axis(gf,&pa,im); break;
	case GF_DEF:       r=parse_def(gf,&pa,im); break;
	case GF_CDEF:      r=parse_cvdef(gf,&pa,im); break;
	case GF_VDEF:      r=parse_cvdef(gf,&pa,im); break;
	case GF_LINE:      r=parse_line(gf,&pa,im); break;
	case GF_AREA:      r=parse_area(gf,&pa,im); break;
	case GF_PRINT:     r=parse_gprint(gf,&pa,im); break;
	case GF_GPRINT:    r=parse_gprint(gf,&pa,im); break;
	case GF_COMMENT:   r=parse_comment(gf,&pa,im); break;
	case GF_HRULE:     r=parse_hvrule(gf,&pa,im); break;
	case GF_VRULE:     r=parse_hvrule(gf,&pa,im); break;
	case GF_STACK:     r=parse_stack(gf,&pa,im); break;
	case GF_TICK:      r=parse_tick(gf,&pa,im); break;
	case GF_TEXTALIGN: r=parse_textalign(gf,&pa,im); break;
	case GF_SHIFT:     r=parse_shift(gf,&pa,im); break;
	case GF_XPORT:     r=parse_xport(gf,&pa,im); break;
	  /* unsupported types right now */
  }
	/* handle the return error case */
	if (r) { freeParsedArguments(&pa); return;}
	/* check for unprocessed keyvalue args */
	char *s;
	if ((s=checkUnusedValues(&pa))) {
	  /* set error message */
	  rrd_set_error("Unused Arguments \"%s\" in command : %s",s,pa.arg_orig);
	  free(s);
	  /* exit early */
	  freeParsedArguments(&pa);
	  return;
	}
    }
    /* finally free arguments */
    freeParsedArguments(&pa);
}
Exemple #28
0
Tuple *flac_probe_for_tuple(const char *filename, VFSFile *fd)
{
    AUDDBG("Probe for tuple.\n");

    Tuple *tuple = NULL;
    FLAC__Metadata_Iterator *iter;
    FLAC__Metadata_Chain *chain;
    FLAC__StreamMetadata *metadata = NULL;
    FLAC__Metadata_ChainStatus status;
    FLAC__StreamMetadata_VorbisComment_Entry *entry;
    char *key;
    char *value;

    tuple = tuple_new_from_filename(filename);

    tuple_set_str(tuple, FIELD_CODEC, NULL, "Free Lossless Audio Codec (FLAC)");
    tuple_set_str(tuple, FIELD_QUALITY, NULL, _("lossless"));

    chain = FLAC__metadata_chain_new();

    if (!FLAC__metadata_chain_read_with_callbacks(chain, fd, io_callbacks))
        goto ERR;

    iter = FLAC__metadata_iterator_new();

    FLAC__metadata_iterator_init(iter, chain);

    do
    {
        switch (FLAC__metadata_iterator_get_block_type(iter))
        {
            case FLAC__METADATA_TYPE_VORBIS_COMMENT:

                if (FLAC__metadata_iterator_get_block_type(iter) == FLAC__METADATA_TYPE_VORBIS_COMMENT)
                {
                    metadata = FLAC__metadata_iterator_get_block(iter);

                    AUDDBG("Vorbis comment contains %d fields\n", metadata->data.vorbis_comment.num_comments);
                    AUDDBG("Vendor string: %s\n", metadata->data.vorbis_comment.vendor_string.entry);

                    entry = metadata->data.vorbis_comment.comments;

                    for (int i = 0; i < metadata->data.vorbis_comment.num_comments; i++, entry++)
                    {
                        if (FLAC__metadata_object_vorbiscomment_entry_to_name_value_pair(*entry, &key, &value) == false)
                            AUDDBG("Could not parse comment\n");
                        else
                        {
                            parse_comment(tuple, key, value);
                            free(key);
                            free(value);
                        }
                    }
                }
                break;

            case FLAC__METADATA_TYPE_STREAMINFO:
                metadata = FLAC__metadata_iterator_get_block(iter);

                /* Calculate the stream length (milliseconds) */
                if (metadata->data.stream_info.sample_rate == 0)
                {
                    FLACNG_ERROR("Invalid sample rate for stream!\n");
                    tuple_set_int(tuple, FIELD_LENGTH, NULL, -1);
                }
                else
                {
                    tuple_set_int(tuple, FIELD_LENGTH, NULL,
                        (metadata->data.stream_info.total_samples / metadata->data.stream_info.sample_rate) * 1000);
                    AUDDBG("Stream length: %d seconds\n", tuple_get_int(tuple, FIELD_LENGTH, NULL));
                }

                int64_t size = vfs_fsize(fd);

                if (size == -1 || metadata->data.stream_info.total_samples == 0)
                    tuple_set_int(tuple, FIELD_BITRATE, NULL, 0);
                else
                {
                    int bitrate = 8 * size *
                        (int64_t) metadata->data.stream_info.sample_rate / metadata->data.stream_info.total_samples;

                    tuple_set_int(tuple, FIELD_BITRATE, NULL, (bitrate + 500) / 1000);
                }
                break;

            default:
                ;
        }
    } while (FLAC__metadata_iterator_next(iter));

    FLAC__metadata_iterator_delete(iter);
    FLAC__metadata_chain_delete(chain);

    return tuple;

ERR:
    status = FLAC__metadata_chain_status(chain);
    FLAC__metadata_chain_delete(chain);

    FLACNG_ERROR("An error occured: %s\n", FLAC__Metadata_ChainStatusString[status]);
    return tuple;
}
Exemple #29
0
blargg_err_t M3u_Playlist::parse_()
{
	info_.title     = "";
	info_.artist    = "";
	info_.date      = "";
	info_.composer  = "";
	info_.sequencer = "";
	info_.engineer  = "";
	info_.ripping   = "";
	info_.tagging   = "";
	info_.copyright = "";
	
	int const CR = 13;
	int const LF = 10;
	
	data.end() [-1] = LF; // terminate input
	
	first_error_ = 0;
	bool first_comment = true;
	int line  = 0;
	int count = 0;
	char* in  = data.begin();
	char* last_comment_value = 0;
	while ( in < data.end() )
	{
		// find end of line and terminate it
		line++;
		char* begin = in;
		while ( *in != CR && *in != LF )
		{
			if ( !*in )
				return blargg_err_file_type;
			in++;
		}
		if ( in [0] == CR && in [1] == LF ) // treat CR,LF as a single line
			*in++ = 0;
		*in++ = 0;
		
		// parse line
		if ( *begin == '#' )
		{
			parse_comment( begin, info_, last_comment_value, first_comment );
			first_comment = false;
		}
		else if ( *begin )
		{
			if ( (int) entries.size() <= count )
				RETURN_ERR( entries.resize( count * 2 + 64 ) );
			
			if ( !parse_line( begin, entries [count] ) )
				count++;
			else if ( !first_error_ )
				first_error_ = line;
			first_comment = false;
		}
		else last_comment_value = 0;
	}
	if ( count <= 0 )
		return blargg_err_file_type;
	
	// Treat first comment as title only if another field is also specified
	if ( !(info_.artist [0] | info_.composer [0] | info_.date [0] | info_.engineer [0] | info_.ripping [0] | info_.sequencer [0] | info_.tagging [0] | info_.copyright[0]) )
		info_.title = "";
	
	return entries.resize( count );
}
Exemple #30
0
void FLUX::GCodeParser::parse_command(const char* linep, size_t size) {
    int cmd_offset = 0;
    if(!move_to_next_char(linep, 0, size, &cmd_offset)) { return; }

    char cmdprefix = linep[cmd_offset];
    int cmdid;
    cmd_offset = parse_command_int(linep, cmd_offset, size, &cmdid);

    switch(cmdprefix) {
        case 'G':
            switch(cmdid) {
                case 0:
                case 1:
                    cmd_offset = handle_g0g1(linep, cmd_offset, size);
                    break;
                case 4:
                    cmd_offset = handle_g4(linep, cmd_offset, size);
                    break;
                case 20:
                    from_inch = true;
                    break;
                case 21:
                    from_inch = false;
                    break;
                case 28:
                    cmd_offset = handle_g28(linep, cmd_offset, size);
                    break;
                case 90:
                    absolute = true;
                    break;
                case 91:
                    absolute = false;
                    break;
                case 92:
                    cmd_offset = handle_g92(linep, cmd_offset, size);
                    break;
                default:
                    on_error(handler, true, "BAD_COMMAND %.*s", size, linep);
                    break;
            }
            break;
        case 'M':
            switch(cmdid) {
                case 17:
                    cmd_offset = handle_m17(linep, cmd_offset, size);
                    break;
                case 18:
                case 84:
                    cmd_offset = handle_m18m84(linep, cmd_offset, size);
                    break;
                case 24:
                case 25:
                case 226:
                    cmd_offset = handle_m24m25m226(linep, cmd_offset, size);
                    break;
                case 104:
                    cmd_offset = handle_m104m109(linep, cmd_offset, size, false);
                    break;
                case 107:
                    cmd_offset = handle_m107(linep, cmd_offset, size);
                    break;
                case 109:
                    cmd_offset = handle_m104m109(linep, cmd_offset, size, true);
                    break;
                case 106:
                    cmd_offset = handle_m106(linep, cmd_offset, size);
                    break;
                default:
                    on_error(handler, true, "BAD_COMMAND %.*s", size, linep);
                    break;
            }
            break;
        case 'T':
            if(cmdid >= 0 && cmdid <= 3) {
                T = cmdid;
            } else {
                on_error(handler, true, "BAD_COMMAND %.*s", size, linep);
            }
            break;
        case 'X':
            if(cmdid == 2) {
                cmd_offset = handle_x2(linep, cmd_offset, size);
            } else {
                on_error(handler, true, "BAD_COMMAND %.*s", size, linep);
            }
            break;
        case ';':
            parse_comment(linep, 0, size);
            return;
        case '\n':
            return;
        default:
            on_error(handler, true, "BAD_COMMAND %.*s", size, linep);
            break;
    }
    parse_comment(linep, cmd_offset, size);
}