コード例 #1
0
ファイル: xml2recipe.c プロジェクト: Azizou/smac
int xmlToRecipe(char *xmltext,int size,char *formname,char *formversion,
		char *recipetext,int *recipeLen,
		char *templatetext,int *templateLen)
{
  XML_Parser parser;
  int i ;
  
  //ParserCreation
  parser = XML_ParserCreate(NULL);
  if (parser == NULL) {
    fprintf(stderr, "Parser not created\n");
    return (1);
  }
    
  // Tell expat to use functions start() and end() each times it encounters the start or end of an element.
  XML_SetElementHandler(parser, start, end);    
  // Tell expat to use function characterData()
  XML_SetCharacterDataHandler(parser,characterdata);
  
  //Parse Xml Text
  if (XML_Parse(parser, xmltext, strlen(xmltext), XML_TRUE) ==
      XML_STATUS_ERROR) {
    fprintf(stderr,
	    "Cannot parse , file may be too large or not well-formed XML\n");
    return (1);
  }
  
  // Build recipe output
  int recipeMaxLen=*recipeLen;
  *recipeLen=0;
  
  for(i=0;i<xml2recipeLen;i++){
    if (appendto(recipetext,recipeLen,recipeMaxLen,xml2recipe[i])) return -1;
    if (appendto(recipetext,recipeLen,recipeMaxLen,"\n")) return -1;
  }
  for(i=0;i<selectsLen;i++){
    if (appendto(recipetext,recipeLen,recipeMaxLen,selects[i])) return -1;
    if (appendto(recipetext,recipeLen,recipeMaxLen,"\n")) return -1;
  }
  
  int templateMaxLen=*templateLen;
  *templateLen=0;
  for(i=0;i<xml2templateLen;i++){
    if (appendto(templatetext,templateLen,templateMaxLen,xml2template[i]))
      return -1;
    if (appendto(templatetext,templateLen,templateMaxLen,"\n")) return -1;
  }

  snprintf(formname,1024,"%s",formName);
  snprintf(formversion,1024,"%s",formVersion);
  
  XML_ParserFree(parser);
  fprintf(stderr, "\n\nSuccessfully parsed %i characters !\n", (int)size);
  fprintf(stderr,"formName=%s, formVersion=%s\n",
	  formName,formVersion);
  return (0);
}
コード例 #2
0
ファイル: setup.c プロジェクト: Logout22/Escape
uintptr_t load_setupProg(int binFd,A_UNUSED uintptr_t a,A_UNUSED uintptr_t b,A_UNUSED size_t c,
	int argc,char **argv) {
#else
uintptr_t load_setupProg(int binFd,int argc,char **argv) {
#endif
	sSharedLib *prog;
	uintptr_t entryPoint;

	/* create entry for program */
	prog = (sSharedLib*)malloc(sizeof(sSharedLib));
	if(!prog)
		load_error("Not enough mem!");
	prog->isDSO = false;
	prog->relocated = false;
	prog->initialized = false;
	prog->dynstrtbl = NULL;
	prog->dyn = NULL;
	prog->name = "-Main-";
	prog->deps = NULL;
	appendto(&libs,prog);

	/* load program including shared libraries into linked list */
	load_doLoad(binFd,prog);

	/* load segments into memory */
	entryPoint = load_addSegments();

#if PRINT_LOADADDR
	for(sSharedLib *l = libs; l != NULL; l = l->next) {
		uintptr_t addr;
		lookup_byName(NULL,"_start",&addr);
		debugf("[%d] Loaded %s @ %p .. %p (text @ %p) with deps: ",
				getpid(),l->name,l->loadAddr,l->loadAddr + l->textSize,addr);
		for(sDep *dl = l->deps; dl != NULL; dl = dl->next)
			debugf("%s ",dl->lib->name);
		debugf("\n");
	}
#endif

	/* relocate everything we need so that the program can start */
	load_reloc();

	/* call global constructors */
	load_init(argc,argv);

	return entryPoint;
}