Exemple #1
0
int
inifile_load(inifile_t *self, const char *path)
{
  int     err  = -1;
  FILE   *file = 0;
  size_t  size = 0;
  char   *data = 0;

  inisec_t *sec = 0;
  char     *key = 0;
  char     *val = 0;

  if( (file = fopen(path, "r")) == 0 )
  {
    log_debug("%s: iniload/open: %s\n", path, strerror(errno));
    goto cleanup;
  }

  while( getline(&data, &size, file) != -1 )
  {
    char *pos = xstrip(data);

    if( *pos == 0 ) continue;

    if( *pos == '#' ) continue;

    if( *pos == BRA )
    {
      char *name = xsplit(pos+1, 0, KET);
      sec = inifile_add_section(self, xstripall(name));
      continue;
    }

    key = xsplit(pos, &val, SEP);
    xstripall(key);
    xstrip(val);

    if( sec && *key )
    {
      inisec_set(sec, key, val);
    }
  }

  err = 0;

  cleanup:

  free(data);

  if( file != 0 && fclose(file) == EOF )
  {
    log_err("%s: iniload/close: %s\n", path, strerror(errno));
    err = -1;
  }

  return err;
}
Exemple #2
0
void show_xml(gfxdocument_t* pdf, char*filename)
{

	int pagenr;
	FILE*fo=0;

	if(infoname) {
		fo = fopen(infoname, "wb");
		if(!fo) {
			perror(infoname);exit(1);;
		}
	} else {
		fo = stdout;
	}

	int pn = 0;
	int w1, h1;
	for(pagenr = 1; pagenr <= pdf->num_pages; pagenr++)
	{
		gfxpage_t*page = pdf->getpage(pdf,pagenr);
		int w=page->width;
		int h=page->height;
		if(pagenr==1) {
			pn = 1;
			w1=w;
			h1=h;
			fprintf(fo,"<Document pages=\"%d\" w=\"%d\" h=\"%d\">\n", pdf->num_pages, w1, h1 );
		}
		if(is_in_range(pagenr, pagerange)) {
			int frame = pagenr%step;
			if(frame==0) frame = step;
			char buf[1024];
			sprintf(buf, outputname, 1+((pagenr-1)/step));
			if(h1==h && w1==w)
			fprintf(fo, "\t<p i=\"%d\" n=\"%s\" f=\"%d\"/>\n", pagenr, xstrip(buf), frame);
			else
			fprintf(fo, "\t<p i=\"%d\" w=\"%d\" h=\"%d\" n=\"%s\" f=\"%d\"/>\n",
			pagenr, w, h, xstrip(buf), frame);
		}
	}
	if(pn==0) fprintf(fo,"<Document/>");
	else fprintf(fo,"</Document>\n");
	fclose(fo);
}