Example #1
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;
}
Example #2
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);
}
Example #3
0
/** 
 * @brief Open given path-file and read data from it to member variables.
 * @param [in] path Path to project file.
 * @param [out] sError Error string if error happened.
 * @return TRUE if reading succeeded, FALSE if error happened.
 */
BOOL ProjectFile::Read(LPCTSTR path, String *sError)
{
	BOOL loaded = FALSE;
    scew_tree* tree = NULL;
    scew_parser* parser = NULL;

    parser = scew_parser_create();
    scew_parser_ignore_whitespaces(parser, 1);

	scew_reader *reader = NULL;
	FILE * fp = _tfopen(path, _T("r"));
	if (fp)
	{
		reader = scew_reader_fp_create(fp);
		if (reader)
		{
			tree = scew_parser_load (parser, reader);

			if (tree)
			{
				scew_element * root = GetRootElement(tree);
				if (root)
				{
					// Currently our content is paths, so expect
					// having paths in valid project file!
					if (GetPathsData(root))
						loaded = TRUE;
				};
			}
		}

		scew_tree_free(tree);
		scew_reader_free(reader);

		/* Frees the SCEW parser */
		scew_parser_free(parser);
		fclose(fp);
	}
	return loaded;
}
Example #4
0
int
main (int argc, char *argv[])
{
  scew_reader *reader = NULL;
  scew_parser *parser = NULL;
  scew_tree *tree = NULL;
  scew_writer *writer = NULL;
  scew_printer *printer = NULL;

#if defined(_MSC_VER) && defined(XML_UNICODE_WCHAR_T)
  /* Change stdout to Unicode before writing anything. */
  _setmode(_fileno(stdout), _O_U16TEXT);
#endif /* _MSC_VER && XML_UNICODE_WCHAR_T */

  if (argc < 2)
    {
      scew_printf (_XT("Usage: scew_print file.xml\n"));
      return EXIT_FAILURE;
    }

  /* Creates an SCEW parser. This is the first function to call. */
  parser = scew_parser_create ();

  scew_parser_ignore_whitespaces (parser, SCEW_TRUE);

  /* Loads an XML file. */
  reader = scew_reader_file_create (argv[1]);
  if (reader == NULL)
    {
      scew_error code = scew_error_code ();
      scew_printf (_XT("Unable to load file (error #%d: %s)\n"),
                   code, scew_error_string (code));
      return EXIT_FAILURE;
    }

  tree = scew_parser_load (parser, reader);
  if (tree == NULL)
    {
      scew_error code = scew_error_code ();
      scew_printf (_XT("Unable to parse file (error #%d: %s)\n"),
                   code, scew_error_string (code));
      if (code == scew_error_expat)
        {
          enum XML_Error expat_code = scew_error_expat_code (parser);
          scew_printf (_XT("Expat error #%d (line %d, column %d): %s\n"),
                       expat_code,
                       scew_error_expat_line (parser),
                       scew_error_expat_column (parser),
                       scew_error_expat_string (expat_code));
        }

      /* Frees the SCEW parser and reader. */
      scew_reader_free (reader);
      scew_parser_free (parser);

      return EXIT_FAILURE;
    }

  /* Prints full tree. */
  scew_printf (_XT("\n*** Manual print:\n\n"));
  print_element (scew_tree_root (tree), 0);

  /* Prints full tree using SCEW writer. */
  scew_printf (_XT("\n\n*** SCEW writer (stdout) print:\n\n"));

  writer = scew_writer_fp_create (stdout);
  printer = scew_printer_create (writer);
  scew_printer_print_tree (printer, tree);
  scew_printf (_XT("\n"));

  /* Remember to free tree (scew_parser_free does not free it). */
  scew_tree_free (tree);

  /* Also free the printer and writer. */
  scew_writer_free (writer);
  scew_printer_free (printer);

  /* Frees the SCEW parser and reader. */
  scew_reader_free (reader);
  scew_parser_free (parser);

  return 0;
}