Ejemplo n.º 1
0
// ---
bool cmp_ignore_spaces( const char* s1, const char* s2 ) {
  
  if ( !s1 || !*s1 ) 
    return !s2 || !*s2;
  else if ( !s2 || !*s2 )
    return false;

  ignore_spaces( s1 );
  ignore_spaces( s2 );
  while( *s1 && (*s1 == *s2) ) {
    ignore_spaces( ++s1 );
    ignore_spaces( ++s2 );
  }
  return (*s1 == 0) && (*s2 == 0);
}
Ejemplo n.º 2
0
// ---
bool cmp_ignore_spaces_no_comment( const char* s1, const char* s2 ) {

  if ( !s1 || !*s1 ) 
    return !s2 || !*s2;
  else if ( !s2 || !*s2 )
    return false;

  ignore_spaces( s1 );
  ignore_spaces( s2 );
  while( *s1 && (*s1 == *s2) && !is_comment(s1) && !is_comment(s2) ) {
    ignore_spaces( ++s1 );
    ignore_spaces( ++s2 );
  }
  return ((*s1 == 0) || (*s1 == '/')) && ((*s2 == 0) || (*s2 == '/'));
}
Ejemplo n.º 3
0
void parse_program_list(){
	ignore_spaces();
	parse_program_call();
	programs++;
	ignore_spaces();
	switch(peek_token()){
		case '|':
			shift_token();
			parse_program_list();
		case EOS:
			break;
		default:
			break;
	}
}
Ejemplo n.º 4
0
// ---
bool is_comment( const char* s ) {
  
  if ( !s || !*s ) 
    return false;

  ignore_spaces( s );
  return *s && (*s == '/') && *(s+1) && (*(s+1) == '/' );
}
Ejemplo n.º 5
0
/* Analyzes a string for the presence of a meta refresh type url.
 *
 * This function receives the value of the content attribute of a meta tag and
 * parses it in order to identify if a url is going to be present. This is the
 * format of such tag:
 *
 * <meta http-equiv="refresh" content="5; URL=http://www.google.com">
 *
 * Using a regular expression library would be the most obvious way to implement
 * this functionality, but introducing such a dependency is undesirable. We
 * opted instead to parse programmaticly since the expression is simple enough.
 *
 * For reference, this is the spec on the meta http refresh tag:
 * http://dev.w3.org/html5/spec/Overview.html#attr-meta-http-equiv-refresh
 *
 * If the value has no content after the expression, we know we are at the start
 * of the URL. Otherwise we are past the start of the URL.
 *
 *
 * Returns:
 *
 * This functions returns one of the following values:
 *   META_REDIRECT_TYPE_NONE - A url was not identified in the input string.
 *   META_REDIRECT_TYPE_URL_START - The input string ends exactly at the start
 *   of the url.
 *   META_REDIRECT_TYPE_URL - The input string ends somewhere in the middle or
 *   the end of the url.
 *
 * A few examples:
 *   "5"
 *   Returns META_REDIRECT_TYPE_NONE since we don't expect a url to follow.
 *
 *   "5; URL = "
 *   The function returns META_REDIRECT_TYPE_URL_START since we expect a url to
 *   follow.
 *
 *   "5; URL = http://www.google.com/?"
 *   Returns META_REDIRECT_TYPE_URL since the input value terminates in the
 *   middle or end of a url.
 *
 *
 * Caveats: We are only recording up to 256 characters of attribute values, so
 * our analysis is limited to that. This shouldn't be an issue in practice
 * though as it would be unexpected for the part of the string that we are
 * matching to be so long.
 */
enum meta_redirect_type_enum meta_redirect_type(const char *value) {

  if (value == NULL)
    return META_REDIRECT_TYPE_NONE;

  /* Match while [ \t\r\n0-9]* */
  value = ignore_spaces_or_digits(value);

  /* Verify that we got a semi-colon character */
  if (*value != ';')
    return META_REDIRECT_TYPE_NONE;
  value++;

  /* Match while [ \t\r\n]* */
  value = ignore_spaces(value);

  /* Validate that we have 'URL' */
  if (strncasecmp(value, "url", strlen("url")) != 0)
    return META_REDIRECT_TYPE_NONE;

  value += strlen("url");

  /* Match while [ \t\r\n]* */
  value = ignore_spaces(value);

  if (*value != '=')
    return META_REDIRECT_TYPE_NONE;
  value++;

  /* Match while [ \t\r\n]* */
  value = ignore_spaces(value);

  /* The HTML5 spec allows for the url to be quoted, so we skip a single or
   * double quote if we find one.
   */
  if (*value == '"' || *value == '\'')
    value++;

  if (*value == '\0')
    return META_REDIRECT_TYPE_URL_START;
  else
    return META_REDIRECT_TYPE_URL;
}
Ejemplo n.º 6
0
void parse_program_call(){
	set_parse_err(programs >= MAX_PROGRAMS,ETOOMANY);
	
	parse_name();
	ignore_spaces();
	
	argument_number = 1;
	parse_argument_list();

	program_call[programs]
		.arguments[argument_number] = NULL;
}
Ejemplo n.º 7
0
// ---
void uncomment( char* s ) {
	ignore_spaces( (const char*&)s );
	char* b = s;
	if ( (*((WORD*)s) != MAKEWORD('/','/')) )
		return;
	s += 2;
	if ( *s == '!' ) {
		s++;
		if ( *s == ' ' )
			s++;
	}
	::memmove( b, s, ::lstrlen(s)+1 );
}
Ejemplo n.º 8
0
void parse_argument_list(){
	set_parse_err(argument_number >= MAX_ARGS,EMANYARGS);
	ignore_spaces();
		
	if(reserved(peek_token()))
		return;
	
	char * arg = malloc(MAX_ARGLEN+1);
	program_call[programs]
		.arguments[argument_number] = arg;
	
	char c; int i;

	for(i = 0, c = next_token(); 
		i < MAX_ARGLEN && !reserved(c);
		i++, c = next_token() ){
		
		arg[i] = c;
	}
	set_parse_err(i >= MAX_ARGLEN,EARGLONG);
	
	arg[i] = '\0';
	argument_number++;
	ignore_spaces();
	
	switch(c = peek_token()){
		case EOS:
		case '|':
			break;	
		default:
			if(!reserved(c)){
				parse_argument_list();
			}else{
				set_parse_err(true,EINVCHAR);		
			}
			break;
	}
}
Ejemplo n.º 9
0
// ---
bool is_empty( const char* s ) {
  if ( !s || !*s )
    return true;
  ignore_spaces( s );
  return !s || !*s;
}