Esempio n. 1
0
File: sdew.c Progetto: naadsm/sdew
/*******************************************************************************
 *  TestParser
 *
 *  This is a test function to verify that the library is properly opening and
 *  reading xml files.
 ******************************************************************************/
DLLIMPORT void TestParser( char *Filename )
{

   scew_parser *parser;
   scew_element *params;
   int elementCount = 0;
   int i;
   char Buffer[1024];

   parser = scew_parser_create ();

   if (parser != NULL)
   {
      scew_parser_load_file (parser, Filename);
      params = scew_tree_root (scew_parser_tree (parser));

      elementCount = scew_element_count (params);

      sprintf(Buffer, "Root has %u children\n", elementCount);
      MessageBox( 0, Buffer, "Debugging", MB_ICONINFORMATION );

      for (i = 0; i < elementCount; i++)
      {
          scew_element *newParams = scew_element_by_index (params, i);
          sprintf(Buffer, "This child has %u subchildren\n", scew_element_count( newParams ));
          MessageBox( 0, Buffer, "Debugging", MB_ICONINFORMATION );
          sprintf(Buffer, "Child %i name='%s'\n", i, scew_element_name (scew_element_by_index (params, i)));
          MessageBox( 0, Buffer, "Debugging", MB_ICONINFORMATION );
      }
      scew_parser_free( parser );
   }
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    scew_parser *parser = NULL;
    if (init() != 0) {
        return 1;
    }

    if (argc == 2) {
        if (exists(argv[1])) {
            parser = scew_parser_create();
            scew_parser_ignore_whitespaces(parser, 1);
            scew_parser_load_file(parser, argv[1]);
            maptree = scew_parser_tree(parser);
        } else {
            allegro_message("Cannot load file: %s", argv[1]);
            close_program = 1;
        }
    } else if (argc == 4) {
        maptree = new_map(0, MAP_WIN.w / TILE_W, atoi(argv[1]), 1, argv[2]);
        map_offset = atoi(argv[1]) * TILE_H - EDITOR_WIN_H;
    } else {
        /* print usage */
        allegro_message
            ("Usage:\n\"editor.exe <filename>\" to load a file\n \"editor.exe <height_in_tiles> <default_tile_name> <newmapfile>\" to create a new map");

        close_program = 1;
    }

    while (!close_program) {
        /* get input */
        parse_mouse();
        get_grid_item();
        if (keypressed()) {
            parse_keyboard();
        }

        /* blit virtual screen */
        clear_to_color(vscreen, DEAD_COLOR);
        draw_select_lists(vscreen);
        draw_ctrl_box(vscreen);

        update_screen();
    }

    if (argc == 2) {
        write_map(argv[1], maptree);
        scew_parser_free(parser);
    } else if (argc == 4) {
        write_map(argv[3], maptree);
        scew_tree_free(maptree);
    }
    destroy_bitmap(vscreen);
    cleanup();
    return 0;
}
Esempio n. 3
0
/* load_sprite: load all the sprites in SPRITE_INDEX and their graphics */
void load_sprites(void)
{
    size_t i, y;
    char bmpname[NAME_LN];
    scew_tree *t = NULL;
    scew_parser *p = NULL;
    scew_element *e = NULL;
    scew_element *r = NULL;
    SPRITE *s = NULL;

    /* setup the parser */
    p = scew_parser_create();
    scew_parser_ignore_whitespaces(p, 1);
    if (!scew_parser_load_file(p, SPRITE_INDEX)) {
        printf("%s\n", scew_error_expat_string(scew_error_code()));
        return;
    }
    t = scew_parser_tree(p);
    r = scew_tree_root(t);
    s = create_sprite();

    /* read all the sprites from SPRITE_INDEX */
    /* parse the SPRITE_INDEX file and outline the list with their names */
    e = scew_element_next(r, e);
    while (e) {
        strncpy(s->long_name, (char *) scew_element_name(e), LONG_NAME_LN);
        s->x = s->y = 0;
        sprite_list = append_sprite_list(s, sprite_list, &sprite_list_sz);
        e = scew_element_next(r, e);
    }

    /* load all their graphics and the sprite data */
    gfx_list = complete_sprite_list(sprite_list, sprite_list_sz, gfx_list,
                                    &gfx_list_sz);

    /* create a list_element for each of them and put them in a list */
    y = SPRITE_WIN.y;
    for (i = 0; i < sprite_list_sz; i++) {
        sprintf(bmpname, "%s0", sprite_list[i].name);
        spr_elem_lst = add_list_element(rec(SPRITE_WIN.x, y, LIST_ELEM_W,
                                            LIST_ELEM_H), 0, DEFAULT_COLOR,
                                        SEL_COLOR, sprite_list[i].name,
                                        search_gfx_list(bmpname, gfx_list,
                                                        gfx_list_sz),
                                        spr_elem_lst, &spr_elem_lst_sz);
        y += LIST_ELEM_H;
    }

    /* cleanup */
    scew_element_free(r);
    destroy_sprite(s);
    scew_element_free(e);
    scew_parser_free(p);
}
Esempio n. 4
0
File: sdew.c Progetto: naadsm/sdew
/*******************************************************************************
 *  Function:  Create_Scew_Parser_From_File
 *
 *  This function returns a void * representing a pointer to a valid
 *  scew_element structure, which is the next child element of the _parent
 *  parameter, or if _parent is NULL, then the next sibling of the _element
 *  parameter.
 *
 *  Parameters:
 *    Filename:  A char * to a NULL terminated character array, which represents
 *               the filename of the XML file to open, and with which to
 *               initialize the parser created in this function.  This filename
 *               may also contain a path if necessary, otherwise the function
 *               will attempt to open a file by the name of the filename in the
 *               current directory of the currently running process.
 *
 *  Returns:
 *    void *:  Representing a pointer to a valid scew_parser structure, which
 *             meets the constraints of the input parameters, or NULL on error.
 *
 ******************************************************************************/
DLLIMPORT void *Create_Scew_Parser_From_File(char *Filename)
{
   scew_parser *parser;
   void *ret_val = NULL;

   parser = scew_parser_create ();

   if (parser != NULL)
   {
      if (scew_parser_load_file (parser, Filename) > 0 )
         ret_val = (void *)parser;
      else
      {
         scew_parser_free( parser );
         parser = NULL;
      }
   }

   return ret_val;
}