コード例 #1
0
ファイル: dev_planet.c プロジェクト: br0k3/naev
/**
 * @brief Saves all the star planets.
 *
 *    @return 0 on success.
 */
int dpl_saveAll (void)
{
    int i;
    /*char file[PATH_MAX];*/
    xmlDocPtr doc;
    xmlTextWriterPtr writer;
    int np;
    const Planet *p;
    const Planet **sorted_p;

    /* Create the writer. */
    writer = xmlNewTextWriterDoc(&doc, 0);
    if (writer == NULL) {
        WARN("testXmlwriterDoc: Error creating the xml writer");
        return -1;
    }

    /* Set the writer parameters. */
    xmlw_setParams( writer );

    /* Start writer. */
    xmlw_start(writer);
    xmlw_startElem( writer, "Assets" );

    /* Sort planets. */
    p        = planet_getAll( &np );
    sorted_p = malloc( sizeof(Planet*) * np );
    for (i=0; i<np; i++)
        sorted_p[i]  = &p[i];
    qsort( sorted_p, np, sizeof(Planet*), dpl_compPlanet );

    /* Write planets. */
    for (i=0; i<np; i++)
        dpl_savePlanet( writer, sorted_p[i] );

    /* Clean up sorted planet.s */
    free(sorted_p);

    /* End writer. */
    xmlw_endElem( writer ); /* "Assets" */
    xmlw_done( writer );

    /* No need for writer anymore. */
    xmlFreeTextWriter( writer );

    /* Write data. */
    xmlSaveFileEnc( "asset.xml", doc, "UTF-8" );

    /* Clean up. */
    xmlFreeDoc(doc);

    return 0;
}
コード例 #2
0
ファイル: nlua_planet.c プロジェクト: naev/naev
/**
 * @brief Gets all the planets.
 *    @luatreturn {Planet,...} An ordered list of all the planets.
 * @luafunc getAll()
 */
static int planetL_getAll( lua_State *L )
{
   Planet *p;
   int i, ind, n;

   lua_newtable(L);
   p = planet_getAll( &n );
   ind = 1;
   for (i=0; i<n; i++) {
      /* Ignore virtual assets. */
      if (p[i].real == ASSET_VIRTUAL)
         continue;
      lua_pushnumber( L, ind++ );
      lua_pushplanet( L, planet_index( &p[i] ) );
      lua_settable(   L, -3 );
   }
   return 1;
}