コード例 #1
0
ファイル: rdf_raptor.c プロジェクト: arleincho/librdf
static unsigned char*
librdf_raptor_generate_id_handler(void *user_data,
                                  unsigned char *user_bnodeid)
{
  librdf_world* world = (librdf_world*)user_data;

  if(user_bnodeid && world->bnode_hash) {
    unsigned char *mapped_id;

    mapped_id = (unsigned char*)librdf_hash_get(world->bnode_hash,
                                                (const char*)user_bnodeid);
    if(!mapped_id) {
      mapped_id = librdf_world_get_genid(world);

      if(mapped_id &&
         librdf_hash_put_strings(world->bnode_hash,
                                 (char*)user_bnodeid, (char*)mapped_id)) {
        /* error -> free mapped_id and return NULL */
        LIBRDF_FREE(char*, mapped_id);
        mapped_id = NULL;
      }
    }
    /* always free passed in bnodeid */
    raptor_free_memory(user_bnodeid);

    return mapped_id;
  } else
    return librdf_world_get_genid(world);
}
コード例 #2
0
ファイル: rdf_init.c プロジェクト: njh/librdf
int
main(int argc, char *argv[]) 
{
  librdf_world *world;
  unsigned char* id;
  const char *program=librdf_basename((const char*)argv[0]);

  /* Minimal setup-cleanup test without opening the world */
  fprintf(stdout, "%s: Creating new world\n", program);
  world = librdf_new_world();
  if(!world) {
    fprintf(stderr, "%s: librdf_new_world failed\n", program);
    return 1;
  }
  fprintf(stdout, "%s: Deleting world\n", program);
  librdf_free_world(world);

  /* Test id generation */
  fprintf(stdout, "%s: Creating new world\n", program);
  world = librdf_new_world();
  if(!world) {
    fprintf(stderr, "%s: librdf_new_world failed\n", program);
    return 1;
  }

  fprintf(stdout, "%s: Generating an identifier\n", program);
  id = librdf_world_get_genid(world);
  if(id == NULL || strlen(id) < 6) {
    fprintf(stderr, "%s: librdf_world_get_genid failed\n", program);
    return 1;
  }
  fprintf(stdout, "%s: New identifier is: '%s'\n", program, id);
  LIBRDF_FREE(cstring, id);

  fprintf(stdout, "%s: Deleting world\n", program);
  librdf_free_world(world);

  /* keep gcc -Wall happy */
  return(0);
}