/*-----------------------------------------------------------------------------------------------------------------------*/
static int32_t load_transport_protocol(FIXProtocolDescr* prot, xmlNode* parentRoot, char const* parentFile, FIXError** error)
{
   int32_t res = FIX_SUCCESS;
   xmlDoc* doc = NULL;
   char const* transpFile = get_attr(parentRoot, "transport", parentFile);
   if(!strcmp(transpFile, parentFile)) // transport is the same as protocol
   {
      prot->transportVersion = _strdup(prot->version);
      goto ok;
   }
   char path[PATH_MAX] = {};
   if (FIX_FAILED == fix_utils_make_path(parentFile, transpFile, path, PATH_MAX))
   {
      goto err;
   }
   doc = xmlParseFile(path);
   if (!doc)
   {
      *error = fix_error_create(FIX_ERROR_PROTOCOL_XML_LOAD_FAILED, xmlGetLastError()->message);
      goto err;
   }
   if (xml_validate(doc, error) == FIX_FAILED)
   {
      goto err;
   }
   xmlNode* root = xmlDocGetRootElement(doc);
   prot->transportVersion = _strdup(get_attr(root, "version", NULL));
   if (!strcmp(prot->version, prot->transportVersion)) // versions are the same, no need to process transport protocol
   {
      goto ok;
   }
   if (!root)
   {
      *error = fix_error_create(FIX_ERROR_PROTOCOL_XML_LOAD_FAILED, xmlGetLastError()->message);
      goto err;
   }
   if (load_field_types(&prot->transport_field_types, root, error) == FIX_FAILED)
   {
      goto err;
   }
   if (load_messages(prot, &prot->transport_field_types, root, error) == FIX_FAILED)
   {
      goto err;
   }
   goto ok;
err:
   res = FIX_FAILED;
ok:
   if (doc)
   {
      xmlFreeDoc(doc);
   }
   return res;
}
/*-----------------------------------------------------------------------------------------------------------------------*/
FIXProtocolDescr const* fix_protocol_descr_create(char const* file, FIXError** error)
{
   FIXProtocolDescr* prot = NULL;
   initLibXml(error);
   xmlDoc* doc = xmlParseFile(file);
   if (!doc)
   {
      *error = fix_error_create(FIX_ERROR_PROTOCOL_XML_LOAD_FAILED, xmlGetLastError()->message);
      goto err;
   }
   if (xml_validate(doc, error) == FIX_FAILED)
   {
      goto err;
   }
   xmlNode* root = xmlDocGetRootElement(doc);
   if (!root)
   {
      *error = fix_error_create(FIX_ERROR_PROTOCOL_XML_LOAD_FAILED, xmlGetLastError()->message);
      goto err;
   }
   prot = (FIXProtocolDescr*)calloc(1, sizeof(FIXProtocolDescr));
   prot->version = _strdup(get_attr(root, "version", NULL));
   if (prot && load_transport_protocol(prot, root, file, error) == FIX_FAILED)
   {
      goto err;
   }
   else if (load_field_types(&prot->field_types, root, error) == FIX_FAILED)
   {
      goto err;
   }
   else if (load_messages(prot, &prot->field_types, root, error) == FIX_FAILED)
   {
      goto err;
   }
   goto ok;
err:
   if (prot)
   {
      free(prot);
      prot = NULL;
   }
ok:
   if (doc)
   {
      xmlFreeDoc(doc);
   }
   return prot;
}
Exemple #3
0
void JsonLoader::load_messages(
    const std::string& jsons,
    std::deque<google::protobuf::Message*>* out_msgs) {
    JsonLoader::Reader ctx(jsons);
    load_messages(&ctx, out_msgs);
}
Exemple #4
0
void JsonLoader::load_messages(
    int fd,
    std::deque<google::protobuf::Message*>* out_msgs) {
    JsonLoader::Reader ctx(fd);
    load_messages(&ctx, out_msgs);
}
Exemple #5
0
int					/* O - Exit status */
main(int  argc,				/* I - Number of command-line arguments */
     char *argv[])			/* I - Command-line arguments */
{
  int	i;				/* Looping var */


  if (argc < 3 ||
      (strcmp(argv[2], "scan") && strcmp(argv[2], "prune") &&
       strcmp(argv[2], "compile") && strcmp(argv[2], "translate")))
  {
    puts("Usage:");
    puts("");
    puts("    espmsg filename.po compile");
    puts("    espmsg filename.po prune filename1 filename2 ... filenameN");
    puts("    espmsg filename.po scan filename1 filename2 ... filenameN");
    puts("    espmsg filename.po translate {de,es,fr,it,pt}");
    return (1);
  }

  load_messages(argv[1]);

  if (!strcmp(argv[2], "compile"))
  {
   /*
    * Compile the message catalog...
    */

    compile_messages(argv[1]);
  }
  else if (!strcmp(argv[2], "translate"))
  {
   /*
    * Translate using google...
    */

    if (argc != 4)
    {
      puts("Usage: espmsg filename.po translate {de,es,fr,it,pt}");
      return (1);
    }

#ifdef HAVE_LIBCUPS
    translate_messages(argv[3]);
    save_messages(argv[1]);
#else
    puts("Sorry, the translate command was not compiled into espmsg!");
    return (1);
#endif /* HAVE_LIBCUPS */
  }
  else
  {
   /*
    * Scan or prune...
    */

    for (i = 3; i < argc; i ++)
      scan_file(argv[i]);

    if (strcmp(argv[2], "prune") == 0)
      prune_messages();

    save_messages(argv[1]);
  }

  return (0);
}
Exemple #6
0
static SDL_bool load_config(session *s, game_state *gs, json_t *game, char const *root)
{
	json_t *entities, *fnt, *level;
	char const *file, *path;

	/* load config */
	fnt = json_object_get(game, "font");
	path = set_path("%s/%s/%s", root, ASSET_DIR, json_string_value(json_object_get(fnt, "resource")));
	int fnt_siz = json_integer_value(json_object_get(fnt, "size"));
	TTF_Font *font = TTF_OpenFont(path, fnt_siz);
	if (!font) {
		fprintf(stderr, "error: could not load font %s: %s\n", path, TTF_GetError());
		return SDL_FALSE;
	}

	if (!gs->debug.font) {
		gs->debug.font = TTF_OpenFont("debug_font.ttf", 14);
	}

	SDL_bool ok;
	ok = load_finish(s, game, font, fnt_siz);
	if (!ok) { return SDL_FALSE; }

	ok = load_messages(s, game, font, fnt_siz, root);
	if (!ok) { return SDL_FALSE; }
	TTF_CloseFont(font);

	level = json_object_get(game, "level");
	if (!ok) { return SDL_FALSE; }
	path = set_path("%s/%s/%s", root, CONF_DIR, json_string_value(level));
	json_error_t e;
	level = json_load_file(path, 0, &e);
	if (*e.text != 0) {
		fprintf(stderr, "Error at %s:%d: %s\n", path, e.line, e.text);
		return SDL_FALSE;
	}

	s->level.background = load_asset_tex(level, root, s->r, "resource");
	if (!s->level.background) { return SDL_FALSE; }

	load_collisions(&s->level, level);
	json_decref(level);

	entity_rule *e_rules;
	SDL_Texture **e_texs;
	entities = json_object_get(game, "entities");
	if (!entities) {
		fprintf(stderr, "Error: No entities defined, need player\n");
		return SDL_FALSE;
	}

	file = json_string_value(json_object_get(entities, "resource"));
	path = set_path("%s/%s/%s", root, CONF_DIR, file);
	entities = load_entities(root, path, s->r, &e_texs, &e_rules);
	if (!entities) {
		fprintf(stderr, "Error: Could not load entities\n");
		return SDL_FALSE;
	}

	init_group(&gs->entities[GROUP_PLAYER ], game, entities, "players", e_texs, e_rules, ST_IDLE);
	init_group(&gs->entities[GROUP_OBJECTS], game, entities, "objects", e_texs, e_rules, ST_IDLE);
	init_group(&gs->entities[GROUP_ENEMIES], game, entities, "enemies", e_texs, e_rules, ST_WALK);

	load_intro(&gs->logo, s, entities, "logo", e_rules, e_texs);
	load_intro(&gs->intro, s, entities, "intro", e_rules, e_texs);

	/* all texture pointers are copied by value, no need to hold onto the
	 * e_texs buffer */
	free(e_texs);

	json_decref(entities);
	json_decref(game);

	return SDL_TRUE;
}