Пример #1
0
static dbus_bool_t
parse_section_start (BusDesktopFileParser *parser, DBusError *error)
{
  int line_end, eol_len;
  char *section_name;

  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
    
  if (!_dbus_string_find_eol (&parser->data, parser->pos, &line_end, &eol_len))
    line_end = parser->len;
  
  if (line_end - parser->pos <= 2 ||
      _dbus_string_get_byte (&parser->data, line_end - 1) != ']')
    {
      report_error (parser, "Invalid syntax for section header", BUS_DESKTOP_PARSE_ERROR_INVALID_SYNTAX, error);
      parser_free (parser);
      return FALSE;
    }

  section_name = unescape_string (parser,
                                  &parser->data, parser->pos + 1, line_end - 1,
                                  error);

  if (section_name == NULL)
    {
      parser_free (parser);
      return FALSE;
    }

  if (!is_valid_section_name (section_name))
    {
      report_error (parser, "Invalid characters in section name", BUS_DESKTOP_PARSE_ERROR_INVALID_CHARS, error);
      parser_free (parser);
      dbus_free (section_name);
      return FALSE;
    }

  if (open_section (parser, section_name) == NULL)
    {
      dbus_free (section_name);
      parser_free (parser);
      BUS_SET_OOM (error);
      return FALSE;
    }

  if (line_end == parser->len)
    parser->pos = parser->len;
  else
    parser->pos = line_end + eol_len;
  
  parser->line_num += 1;

  dbus_free (section_name);
  
  return TRUE;
}
Пример #2
0
static void subst_list_eval_funcs__(const subst_list_type * subst_list , buffer_type * buffer) {
  parser_type     * parser     = parser_alloc( "," , "\"\'" , NULL , " \t" , NULL , NULL );

  subst_list_eval_funcs____( subst_list , parser , buffer );

  parser_free( parser );
}
Пример #3
0
int config_load_file(FILE *config_file, struct Config *dest) {
    char *rdbuf = malloc(CONFIG_CHUNK_SIZE);
    int ret = -1;
    xmpp_ctx_t *ctx = xmpp_ctx_new(NULL, NULL);
    parser_t *parser = parser_new(ctx,
        NULL,
        NULL,
        config_parse_stanza,
        dest);

    size_t read_bytes;
    do {
        read_bytes = fread(rdbuf, 1, CONFIG_CHUNK_SIZE, config_file);
        if (!parser_feed(parser, rdbuf, read_bytes)) {
            ret = 2;
            goto __cleanup__;
        }
    } while (read_bytes == CONFIG_CHUNK_SIZE);
    if (errno != 0) {
        ret = 1;
    } else {
        ret = 0;
    }

__cleanup__:
    free(rdbuf);
    parser_free(parser);
    xmpp_ctx_free(ctx);
    return ret;
}
Пример #4
0
void
test_message (const struct message *message)
{
  parser_init(message->type);

  size_t read;

  read = parse(message->raw, strlen(message->raw));
  if (read != strlen(message->raw)) {
    print_error(message->raw, read);
    exit(1);
  }

  read = parse(NULL, 0);
  if (read != 0) {
    print_error(message->raw, read);
    exit(1);
  }

  if (num_messages != 1) {
    printf("\n*** num_messages != 1 after testing '%s' ***\n\n", message->name);
    exit(1);
  }

  if(!message_eq(0, message)) exit(1);

  parser_free();
}
Пример #5
0
END_TEST

START_TEST (absolute_multi_step)
{
    char *expression = "$.foo.baz..yobble.thingum";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_success(expression, context, path, ABSOLUTE_PATH, 5);
    assert_root_step(path);
    assert_single_name_step(path, 1, "foo");
    assert_single_name_step(path, 2, "baz");
    assert_recursive_name_step(path, 3, "yobble");
    assert_single_name_step(path, 4, "thingum");
    assert_no_predicate(path, 1);
    assert_no_predicate(path, 2);
    assert_no_predicate(path, 3);
    assert_no_predicate(path, 4);

    path_free(path);    
    parser_free(context);
}
Пример #6
0
void config_load( )
{
    char file_name[512];
    PData *pd, *sub; 
    /* set to defaults */
    config_check_dir();
    config_reset();
    /* load config */
    sprintf( file_name, "%s/%s", config.dir_name, CONFIG_FILE_NAME );
    if ( ( pd = parser_read_file( "config", file_name ) ) == 0 ) {
        fprintf( stderr, "%s\n", parser_get_error() );
        return;
    }
    /* parse config */
    parser_get_int( pd, "gametype", &config.gametype );
    parser_get_int( pd, "starting_level", &config.starting_level );
    if (config.starting_level > 9 || config.starting_level < 0) {
	    config.starting_level = 0;
    }
    parser_get_int( pd, "preview", &config.preview );
    parser_get_int( pd, "help", &config.help );
    parser_get_int( pd, "expert", &config.expert );
    parser_get_int( pd, "center_preview", &config.center_preview );
    parser_get_int( pd, "holes", &config.holes );
    parser_get_int( pd, "rand_holes", &config.rand_holes );
    parser_get_int( pd, "send_all", &config.send_all );
    parser_get_int( pd, "send_tetris", &config.send_tetris );
    if ( parser_get_pdata( pd, "player1", &sub ) )
        parse_player( sub, &config.player1 );
    if ( parser_get_pdata( pd, "player2", &sub ) )
        parse_player( sub, &config.player2 );
    if ( parser_get_pdata( pd, "player3", &sub ) )
        parse_player( sub, &config.player3 );
    parser_get_int( pd, "clear_keystate", &config.clear_keystate );
    parser_get_int( pd, "cpu_aggr", &config.cpu_aggr );
    parser_get_int( pd, "cpu_delay", &config.cpu_delay );
    parser_get_int( pd, "cpu_rot_delay", &config.cpu_rot_delay );
    parser_get_int( pd, "sound", &config.sound );
    parser_get_int( pd, "volume", &config.volume );
    parser_get_int( pd, "transparency", &config.trp );
    parser_get_int( pd, "animations", &config.anim );
    parser_get_int( pd, "fullscreen", &config.fullscreen );
    parser_get_int( pd, "fading", &config.fade );
    parser_get_int( pd, "fps", &config.fps );
    parser_get_int( pd, "background", &config.bkgnd );
    parser_get_int( pd, "static_background", &config.keep_bkgnd );
    parser_get_int( pd, "smooth_hori", &config.smooth_hori );
    parser_get_int( pd, "hori_delay", &config.hori_delay );
    parser_get_int( pd, "vert_delay", &config.vert_delay );
    parser_get_int( pd, "pause_key", &config.pause_key );
    parser_get_int( pd, "block_by_block", &config.block_by_block );
    parser_get_int( pd, "motion_mod", &config.motion_mod );
    parser_get_int( pd, "relative_motion", &config.rel_motion );
    parser_get_int( pd, "grap_input", &config.grab );
    parser_get_int( pd, "invert_mouse", &config.invert );
    parser_get_int( pd, "quick_help", &config.quick_help );
    parser_get_int( pd, "async_collision_check", &config.async_col_check );
    parser_free( &pd );
}
Пример #7
0
void cartdb_kill()
{
	if(cartxml) {
		parser_free(cartxml);
		parser_verifymemory();
	}
	cartxml = 0;
}
Пример #8
0
char * parser_fread_alloc_file_content(const char * filename , const char * quote_set , const char * delete_set , const char * comment_start , const char * comment_end) {
  parser_type * parser = parser_alloc( NULL , quote_set , NULL , delete_set , comment_start , comment_end);
  char * buffer              = util_fread_alloc_file_content( filename , NULL);
  
  parser_strip_buffer( parser , &buffer );
  parser_free( parser );
  return buffer;
}
Пример #9
0
/* test the parser and visualize the results                             */
void parser_test(char* input)
{
	cmds* cmd = NULL;
	printf("input:  %s\n",input);
	cmd = parser_parse(input);
	printf("result: %s @ %d:%d\n",parser_message,error_line,error_column);
	printf("---\n");
	parser_print(cmd);
	printf("---\n \n");
	parser_free(cmd);
}
Пример #10
0
PData* parser_read_file( const char *tree_name, const char *fname )
{
    int size;
    char magic = 0;
    ParserState state = { fname, 0, 1, 0 };
    ParserState *st = &state;
    PData *top = 0;
    /* open file */
    if ( ( state.file = fopen( fname, "rb" ) ) == 0 ) {
        sprintf( parser_error, tr("%s: file not found"), fname );
        return 0;
    }
    /* create common tree data */
    st->ctd = common_tree_data_create(fname);
    /* create top level pdata */
    top = parser_create_pdata(strdup( tree_name ), 0, st->lineno, st->ctd);
    top->entries = list_create( LIST_NO_AUTO_DELETE, LIST_NO_CALLBACK );
    /* parse */
    FILE_READCHAR( st, st->ch );
    magic = st->ch;
    if ( magic == '@' ) {
        /* get the whole contents -- 1 and CBUFFER_SIZE are switched */
        fseek( st->file, 0, SEEK_END ); size = ftell( st->file ) - 2;
        if ( size >= CBUFFER_SIZE ) {
            fprintf( stderr, tr("%s: file's too big to fit the compact buffer (%dKB)\n"), fname, CBUFFER_SIZE / 1024 );
            size = CBUFFER_SIZE - 1;
        }
        fseek( st->file, 2, SEEK_SET );
        _fread( cbuffer, 1, size, st->file );
        cbuffer[size] = 0;
        /* set indicator to beginning of text */
        cbuffer_pos = cbuffer;
        /* parse cbuffer */
        if ( !parser_read_file_compact( st, top ) ) {
            parser_set_parse_error( st, parser_sub_error );
            goto failure;
        }
    }
    else {
        parser_read_token(st);
        if ( !parser_read_file_full( st, top ) ) {
            parser_set_parse_error( st, parser_sub_error );
            goto failure;
        }
    }
    /* finalize */
    fclose( st->file );
    return top;
failure:
    fclose( st->file );
    parser_free( &top );
    return 0;
}
Пример #11
0
/* a long jump.                                                          */
static void raise_error(enum parser_errors code)
{
	parser_status = code;
	parser_message = messages[code];
	if (code>=PARSER_INVALID_STATE)
	{
		error_line=line;
		error_column=col;
	}
	/* cleanup before returning                                          */
	parser_free(root);
	longjmp(error_env,1);
}
Пример #12
0
END_TEST

START_TEST (zero_length)
{
    char *expression = "";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, 0);
    assert_not_null(context);
    assert_errno(EINVAL);

    assert_parser_failure(expression, context, NULL, ERR_ZERO_LENGTH, 0);
    parser_free(context);
}
Пример #13
0
ecl_unit_enum ecl_util_get_unit_set(const char * data_file) {
  ecl_unit_enum units = ECL_METRIC_UNITS;
  parser_type * parser = parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  FILE * stream = util_fopen(data_file , "r");

  if (parser_fseek_string( parser , stream , "FIELD" , true , true)) {  /* Seeks case insensitive. */
    units = ECL_FIELD_UNITS;
  } else if (parser_fseek_string( parser , stream , "LAB" , true , true)) {  /* Seeks case insensitive. */
    units = ECL_LAB_UNITS;
  }

  parser_free( parser );
  fclose(stream);
  return units;
}
static gboolean
parse_section_start (AnjutaPluginDescriptionParser *parser, GError **error)
{
  gchar *line_end;
  gchar *section_name;

  line_end = strchr (parser->line, '\n');
  if (line_end == NULL)
    line_end = parser->line + strlen (parser->line);

  if (line_end - parser->line <= 2 ||
      line_end[-1] != ']')
    {
      report_error (parser, "Invalid syntax for section header", ANJUTA_PLUGIN_DESCRIPTION_PARSE_ERROR_INVALID_SYNTAX, error);
      parser_free (parser);
      return FALSE;
    }

  section_name = unescape_string (parser->line + 1, line_end - parser->line - 2);

  if (section_name == NULL)
    {
      report_error (parser, "Invalid escaping in section name", ANJUTA_PLUGIN_DESCRIPTION_PARSE_ERROR_INVALID_ESCAPES, error);
      parser_free (parser);
      return FALSE;
    }

  open_section (parser, section_name);
  
  parser->line = (line_end) ? line_end + 1 : NULL;
  parser->line_nr++;

  g_free (section_name);
  
  return TRUE;
}
Пример #15
0
static gboolean
parse_section_start (GnomeThemeFileParser *parser, GError **error)
{
  gchar *line_end;
  gchar *section_name;

  line_end = strchr (parser->line, '\n');
  if (line_end == NULL)
    line_end = parser->line + strlen (parser->line);

  if (line_end - parser->line <= 2 ||
      line_end[-1] != ']')
    {
      report_error (parser, "Invalid syntax for section header", GNOME_THEME_FILE_PARSE_ERROR_INVALID_SYNTAX, error);
      parser_free (parser);
      return FALSE;
    }

  section_name = unescape_string (parser->line + 1, line_end - parser->line - 2);

  if (section_name == NULL)
    {
      report_error (parser, "Invalid escaping in section name", GNOME_THEME_FILE_PARSE_ERROR_INVALID_ESCAPES, error);
      parser_free (parser);
      return FALSE;
    }

  open_section (parser, section_name);
  
  parser->line = (line_end) ? line_end + 1 : NULL;
  parser->line_nr++;

  g_free (section_name);
  
  return TRUE;
}
Пример #16
0
/*
====================================================================
This function frees a PData tree struct.
====================================================================
*/
void parser_free( PData **pdata )
{
    PData *entry = 0;
    if ( (*pdata) == 0 ) return;
    if ( (*pdata)->entries ) {
        list_reset( (*pdata)->entries );
        while ( ( entry = list_next( (*pdata)->entries ) ) )
            parser_free( &entry );
        list_delete( (*pdata)->entries );
    }
    if ( (*pdata)->name ) free( (*pdata)->name );
    if ( (*pdata)->values ) list_delete( (*pdata)->values );
    common_tree_data_deref((*pdata)->ctd);
    free( *pdata ); *pdata = 0;
}
Пример #17
0
END_TEST

START_TEST (relative_path_begins_with_dot)
{
    char *expression = ".x";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, 2);
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EXPECTED_NAME_CHAR, 0);
    parser_free(context);
    path_free(path);
}
Пример #18
0
END_TEST

START_TEST (extra_junk_in_predicate)
{
    char *expression = "$.foo[ * quux].bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EXTRA_JUNK_AFTER_PREDICATE, 9);
    parser_free(context);
    path_free(path);
}
Пример #19
0
END_TEST

START_TEST (whitespace_predicate)
{
    char *expression = "$.foo[ \t ].bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EMPTY_PREDICATE, 9);
    parser_free(context);
    path_free(path);
}
Пример #20
0
END_TEST

START_TEST (bogus_predicate)
{
    char *expression = "$.foo[asdf].bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_UNSUPPORTED_PRED_TYPE, 6);
    parser_free(context);
    path_free(path);
}
Пример #21
0
int ecl_util_get_num_cpu(const char * data_file) { 
  int num_cpu = 1; 
  parser_type * parser = parser_alloc(" \t\r\n" , "\"\'" , NULL , NULL , "--" , "\n");
  FILE * stream = util_fopen(data_file , "r");
  
  if (parser_fseek_string( parser , stream , "PARALLEL" , true , true)) {  /* Seeks case insensitive. */
    num_cpu = ecl_util_get_num_parallel_cpu__(parser, stream, data_file); 
  } else if (parser_fseek_string( parser , stream , "SLAVES" , true , true)) {  /* Seeks case insensitive. */
    num_cpu = ecl_util_get_num_slave_cpu__(parser, stream, data_file) + 1; 
    fprintf(stderr, "Information: \"SLAVES\" option found, returning %d number of CPUs", num_cpu); 
  }

  parser_free( parser );
  fclose(stream);
  return num_cpu;
}
Пример #22
0
void ecl_config_set_data_file( ecl_config_type * ecl_config , const char * data_file) {
  ecl_config->data_file = util_realloc_string_copy( ecl_config->data_file , data_file );
  {
    FILE * stream        = util_fopen( ecl_config->data_file , "r");
    parser_type * parser = parser_alloc(NULL , NULL , NULL , NULL , "--" , "\n" );
    char * init_tag      = enkf_util_alloc_tagged_string( "INIT" );
    
    ecl_config->can_restart = parser_fseek_string( parser , stream , init_tag , false , true ); 
    
    free( init_tag );
    parser_free( parser );
    fclose( stream );
  }
  ecl_config->start_date = ecl_util_get_start_date( ecl_config->data_file );
  ecl_config->num_cpu    = ecl_util_get_num_cpu( ecl_config->data_file );
}
Пример #23
0
END_TEST

START_TEST (empty_type_test_name)
{
    char *expression = "$.foo.()";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EXPECTED_NODE_TYPE_TEST, 6);
    parser_free(context);
    path_free(path);
}
Пример #24
0
END_TEST

START_TEST (missing_recursive_step_test)
{
    char *expression = "$..";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, 3);
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_PREMATURE_END_OF_INPUT, 3);
    parser_free(context);
    path_free(path);
}
Пример #25
0
END_TEST

START_TEST (missing_dot)
{
    char *expression = "$x";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, 2);
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_UNEXPECTED_VALUE, 1);
    parser_free(context);
    path_free(path);
}
Пример #26
0
static int_vector_type * string_util_sscanf_alloc_active_list(const char * range_string ) {
  int_vector_type *active_list = NULL;
  bool valid = valid_characters( range_string );

  if (valid)
  {
    parser_type * parser = parser_alloc( ","   , /* No ordinary split characters. */
                                         NULL  , /* No quoters. */
                                         NULL  , /* No special split */
                                         " \t" , /* Removing ' ' and '\t' */
                                         NULL  , /* No comment */
                                         NULL  );
    stringlist_type * tokens;
    int item;
    active_list = int_vector_alloc(0,0);
    tokens = parser_tokenize_buffer( parser , range_string , true);
    
    for (item = 0; item < stringlist_get_size( tokens ); item++) {
      const char * string_item = stringlist_iget( tokens , item );
      char * pos_ptr = (char *) string_item;
      int value1 , value2;
      
      value1 = strtol( string_item , &pos_ptr , 10);
      if (*pos_ptr == '\0') 
        // The pos_ptr points to the end of the string, i.e. this was a single digit.
        value2 = value1;
      else {
        // OK - this is a range; skip spaces and the range dash '-'
        while (isspace(*pos_ptr) || *pos_ptr == '-')
          pos_ptr++;
        util_sscanf_int( pos_ptr , &value2);
      } 
      
      {
        int value;
        for (value = value1; value <= value2; value++) 
          int_vector_append( active_list , value );
      }
    }
    
    
    stringlist_free( tokens );
    parser_free( parser );
  }
  
  return active_list;
}
Пример #27
0
Файл: engine.c Проект: fizx/sit
void
engine_free(Engine *engine) {
  dictRelease(engine->queries);
  if(engine->data_dir) {
    pstring_free(engine->data_dir);
  }
  parser_free(engine->parser);
  ring_buffer_free(engine->stream);
  if(engine->auth) pstring_free(engine->auth);
  lrw_dict_free(engine->term_dictionary);
  plist_pool_free(engine->postings);
  if(engine->docs->on_evict)callback_free(engine->docs->on_evict);
  ring_buffer_free(engine->docs);
  dictRelease(engine->ints);
  if(engine->doc_set) dictRelease(engine->doc_set);
  free(engine);
}
Пример #28
0
static PARSER* parser_init(const char *file, FILE *io, int reload)
{
	PARSER *p = calloc(1, sizeof(PARSER));
	if (!p) {
		pgr_abort(ABORT_MEMFAIL);
	}

	p->backends = make_backend(NULL);
	p->f = parse_top;
	p->l = lexer_init(file, io);
	if (!p->l) {
		parser_free(p);
		return NULL;
	}

	return p;
}
Пример #29
0
END_TEST

START_TEST (negative_subscript_predicate)
{
    char *expression = "$.foo[ -3].bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    // xxx - fixme! this should be ERR_EXPECTED_INTEGER instead!
    assert_parser_failure(expression, context, path, ERR_UNSUPPORTED_PRED_TYPE, 7);
    path_free(path);
    parser_free(context);
}
Пример #30
0
END_TEST

START_TEST (quoted_empty_step)
{
    char *expression = "$.foo.''.bar";
    reset_errno();
    parser_context *context = make_parser((uint8_t *)expression, strlen(expression));
    assert_not_null(context);
    assert_noerr();

    jsonpath *path = parse(context);
    
    assert_parser_failure(expression, context, path, ERR_EXPECTED_NAME_CHAR, 7);
    
    parser_free(context);
    path_free(path);
}