예제 #1
0
int GrPlotIncludeStart(char *name,int atnum,char **atname,char **atval,
		    char *buf,int sze,void *data) {
 
  struct GrPlotBlock *blk;
  struct GrPlotInclude *ptr;

  blk=(struct GrPlotBlock *) data;
  if (blk==NULL) return -1;
  ptr=(struct GrPlotInclude *) blk->data;
  if (ptr==NULL) return -1;
 
  if (strcmp(name,blk->name)==0) {
    return 0;
  }

  if (strcmp(name,"name")==0) {
    struct GrPlotString *str;
    str=malloc(sizeof(struct GrPlotString));
    str->inc=ptr->inc;
    str->txt=&ptr->name;
    blk=GrPlotSave(blk->xml,"name",str);
    XMLSetStart(blk->xml,GrPlotStringStart,blk);
    XMLSetText(blk->xml,GrPlotStringText,blk);
    XMLSetEnd(blk->xml,GrPlotStringEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"include")==0) {
    struct GrPlotInclude *inc;
    inc=malloc(sizeof(struct GrPlotInclude));
    inc->inc=ptr->inc;
    blk=GrPlotSave(blk->xml,name,inc);
    XMLSetStart(blk->xml,GrPlotIncludeStart,blk);
    XMLSetEnd(blk->xml,GrPlotIncludeEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"ignore")==0) {
    blk=GrPlotSave(blk->xml,name,NULL);
    XMLSetStart(blk->xml,GrPlotIgnoreStart,blk);
    XMLSetText(blk->xml,GrPlotIgnoreText,blk);
    XMLSetEnd(blk->xml,GrPlotIgnoreEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }


  return 0;
}
예제 #2
0
int main(int argc,char *argv[]) {
 
  FILE *outp=stdout;
  char lbuf[256];

  char *atname[]={"width","height"};
  char *atval[]={"100","200"};

  struct XMLdata *xmldata;
 


  xmldata=XMLMake();

  XMLSetStart(xmldata,start,outp);
  XMLSetEnd(xmldata,end,outp);
  XMLSetText(xmldata,text,outp);

  sprintf(lbuf,"dummy contents.");

  XMLCallStart(xmldata,"table",2,atname,atval,"table",strlen("table"));

  XMLDecode(xmldata,lbuf,strlen(lbuf));

  XMLCallEnd(xmldata,"table","/table",strlen("/table"));

  XMLFree(xmldata);

  return 0;

}
예제 #3
0
int XMLDBPeerStart(char *name,int atnum,char **atname,char **atval,
                char *buf,int sze,void *data) {

  
  struct XMLDBdata *x;
  struct XMLDBelement *e;


  x=(struct XMLDBdata *) data;
  x->depth++;

  e=XMLDBMakeElement(name,atnum,atname,atval,100);
  if (e==NULL) return -1;
  if (x->table==NULL) x->table=XMLDBMakeTable();
 
  if (x->table==NULL) {
     XMLDBFreeElement(e);
     return -1;
  }
  
  if (XMLDBAddTable(x->table,e) !=0) {
    XMLDBFreeElement(e);
    return -1;
  }
  x->buf=e->data;

  XMLSetStart(x->ptr,XMLDBElementStart,x);
  XMLSetEnd(x->ptr,XMLDBElementEnd,x);
  XMLSetText(x->ptr,XMLDBElementText,x);

  return 0;
}
예제 #4
0
파일: rplot.c 프로젝트: horit/RST2.10_stel
void loadxml(struct FrameBufferDB *imagedb,struct OptionText *xml) {
  struct FrameBuffer *img=NULL;
  struct XMLdata *xmldata=NULL;
  struct FrameBufferXML xmlimg;

  FILE *fp;
  char lbuf[256];
  int i;
  int s=0;

  if (xml==NULL) return;

  xmldata=XMLMake();
  xmlimg.xml=xmldata;
  xmlimg.img=&img;

  XMLSetStart(xmldata,FrameBufferXMLStart,&xmlimg);
  XMLSetEnd(xmldata,FrameBufferXMLEnd,&xmlimg);

  for (i=0;i<xml->num;i++) {
    fp=fopen(xml->txt[i],"r");
    if (fp==NULL) continue;
    while(fgets(lbuf,255,fp) !=NULL) {
      s=XMLDecode(xmldata,lbuf,strlen(lbuf));
      if (s !=0) break;
    }
    fclose(fp);
    if (s !=0) continue;
    if (img==NULL) continue;
    FrameBufferDBAdd(imagedb,img);
    img=NULL;
  }
  XMLFree(xmldata);
}
예제 #5
0
int XMLDBPeerEnd(char *name,char *buf,int sze,void *data) {

  int status=0;
  struct XMLDBdata *x;
  x=(struct XMLDBdata *) data;
  x->depth--; 
 
  if (x->depth<0) { 

    /* we have read in all the peers at this level */

    
    if ((x->text.user !=NULL)) 
      status=(x->text.user)(x->table,x->doc,x->text.data);
      
    XMLDBFreeTable(x->table);
    x->table=NULL;

    if (status !=0) return status;  
    XMLSetStart(x->ptr,XMLDBStart,x);
    XMLSetEnd(x->ptr,XMLDBEnd,x);
    status=XMLDBEnd(name,buf,sze,data);
  }
  return status;
}
예제 #6
0
int loadconfig(FILE *fp,struct xmldoc *ptr) {
  int s=0;
  char *epath="config";
  char edelim='/';

  struct XMLdata *xmldata;
  struct XMLDBdata *xmldbdata;
  struct XMLDBtree *tree;

  char lbuf[255];

  xmldata=XMLMake();
  xmldbdata=XMLDBMake(xmldata);
  tree=XMLDBMakeTree();

  XMLDBBuildTree(epath,edelim,tree);   
  XMLDBSetTree(xmldbdata,tree);

  XMLDBSetText(xmldbdata,xmldocbuild,ptr);
  
  XMLSetStart(xmldata,XMLDBStart,xmldbdata);
  XMLSetEnd(xmldata,XMLDBEnd,xmldbdata);
  
  while(fgets(lbuf,255,fp) !=NULL) {
    s=XMLDecode(xmldata,lbuf,strlen(lbuf)); 
    if (s !=0) break;
  
  }

  XMLFree(xmldata);
  XMLDBFree(xmldbdata);
  XMLDBFreeTree(tree);

  return 0;
}
예제 #7
0
int main(int argc,char *argv[]) {
 
  FILE *inp;
  FILE *outp=stdout;
  char lbuf[256];
  int s;

  struct XMLdata *xmldata;
 
  if (argc>1) {
    inp=fopen(argv[1],"r");
    if (inp==NULL) {
      fprintf(stderr,"File not found.\n");
    }
  } else inp=stdin;

  xmldata=XMLMake();

  XMLSetStart(xmldata,start,outp);
  XMLSetEnd(xmldata,end,outp);
  XMLSetText(xmldata,text,outp);

  while(fgets(lbuf,255,inp) !=NULL) {
    s=XMLDecode(xmldata,lbuf,strlen(lbuf));
    if (s !=0) return -1;
  }
  XMLFree(xmldata);

  return 0;

}
예제 #8
0
int XMLDBElementEnd(char *name,char *buf,int sze,void *data) {
  int status=0;
  struct XMLDBdata *x;
  struct XMLDBbuffer *b;
  x=(struct XMLDBdata *) data;
  x->depth--;
  b=x->buf;

  if (x->depth==0) { /* reset the userr */
    x->depth++; 
    XMLSetStart(x->ptr,XMLDBPeerStart,x);
    XMLSetEnd(x->ptr,XMLDBPeerEnd,x);
    XMLSetText(x->ptr,NULL,NULL);
    status=XMLDBPeerEnd(name,buf,sze,data);
    return status;

  }
  
  status=XMLDBAddBuffer(b,"</",2);
  if (status !=0) return status;
  status=XMLDBAddBuffer(b,name,strlen(name));
  if (status !=0) return status;
  status=XMLDBAddBuffer(b,">",1);
  return status;
 
}
예제 #9
0
int main(int argc,char *argv[]) {
  
  int s=0;
  int arg=0;
  FILE *fp;
  char lbuf[256];
  struct FrameBuffer *img=NULL;
  struct XMLdata *xmldata=NULL;
  struct FrameBufferXML xmlimg;
 

  unsigned char help=0;
  unsigned char option=0;

 
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);
  

  arg=OptionProcess(1,argc,argv,&opt,NULL);   

  if (help==1) {
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  }

  if (option==1) {
    OptionDump(stdout,&opt);
    exit(0);
  }

  xmldata=XMLMake();
  xmlimg.xml=xmldata;
  xmlimg.img=&img;

  XMLSetStart(xmldata,FrameBufferXMLStart,&xmlimg);
  XMLSetEnd(xmldata,FrameBufferXMLEnd,&xmlimg);

  if (arg<argc) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  while(fgets(lbuf,255,fp) !=NULL) {
    s=XMLDecode(xmldata,lbuf,strlen(lbuf));
    if (s !=0) break;
  }
  if (s !=0) {
    fprintf(stderr,"Error decoding image.\n");
    exit(-1);
  }
  if (arg<argc) fclose(fp);

  if (img !=NULL) FrameBufferSavePPMX(img,stdout);
  return 0;
}
예제 #10
0
int FrameBufferXMLBufferEnd(char *name,char *buf,int sze,void *data) {
  struct FrameBufferXMLBuffer *ptr;
  ptr=(struct FrameBufferXMLBuffer *) data;
  if (ptr->off !=ptr->sze) return -1;
   XMLSetText(ptr->xml,NULL,NULL);
   XMLSetEnd(ptr->xml,FrameBufferXMLEnd,ptr->data);
  if (data !=NULL) free(data);
  return 0;
}
예제 #11
0
파일: tagdb.c 프로젝트: ajribeiro/VT_RST3
struct TagDBdata *TagDBMake(struct TagDBtable *tagdb) {
  struct TagDBdata *ptr=NULL;

  ptr=malloc(sizeof(struct TagDBdata));
  if (ptr==NULL) return NULL;

  ptr->ptr=XMLMake();
  if (ptr->ptr==NULL) {
    free(ptr);
    return NULL;
  }

  
  ptr->tagdb=tagdb;  
  ptr->text.func=NULL;
  ptr->text.data=NULL;
  XMLSetStart(ptr->ptr,TagDBStart,ptr);
  XMLSetEnd(ptr->ptr,TagDBEnd,ptr);
  XMLSetText(ptr->ptr,TagDBText,ptr);
  return ptr;
}
예제 #12
0
int XMLDBStart(char *name,int atnum,char **atname,char **atval,
                char *buf,int sze,void *data) {
  int i=0;

  struct XMLDBdata *x;
  struct XMLDBtree *t;
  struct XMLDBtable *d;
  struct XMLDBelement *e;
 
  x=(struct XMLDBdata *) data;
  t=x->tree;
  d=x->doc;

  e=XMLDBMakeElement(name,atnum,atname,atval,10);
  if (e==NULL) return -1;
  
  if (XMLDBAddTable(d,e) !=0) {
    XMLDBFreeElement(e);
    return -1;
  }


  if (d->num==t->depth) {
    for (i=0;i<t->depth;i++) 
      if (strcmp(t->name[i],
                (d->element[i])->name) !=0) break;
  }

  if (i==t->depth) {
     /* we are now in the right depth */
      x->depth=0;
      XMLSetStart(x->ptr,XMLDBPeerStart,data);
      XMLSetEnd(x->ptr,XMLDBPeerEnd,data);
  }
  return 0;
 
}
예제 #13
0
int GrPlotSymbolDrawStart(char *name,int atnum,char **atname,char **atval,
		    char *buf,int sze,void *data) {
  
  struct GrPlotBlock *blk;
  struct GrPlotSymbolDraw *ptr;
  struct GrPlotData *plt;

  blk=(struct GrPlotBlock *) data;
  if (blk==NULL) return -1;
  ptr=(struct GrPlotSymbolDraw *) blk->data;
  if (ptr==NULL) return -1;
  plt=ptr->plt;
  if (plt==NULL) return -1;

  if (strcmp(name,blk->name)==0) {
    return 0;
  }

  if (strcmp(name,"line")==0) {
    struct GrPlotLine *lne;
    lne=malloc(sizeof(struct GrPlotLine));
    lne->plt=plt;
    lne->off=&ptr->off;
    lne->xmin=ptr->xmin;
    lne->ymin=ptr->ymin;
    lne->xmax=ptr->xmax;
    lne->ymax=ptr->ymax;
    lne->state=0x01;

    blk=GrPlotSave(plt->xml,name,lne);
    XMLSetStart(plt->xml,GrPlotLineStart,blk);
    XMLSetEnd(plt->xml,GrPlotLineEnd,blk);
    return XMLCallStart(plt->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"bezier")==0) {
    struct GrPlotBezier *bez;
    bez=malloc(sizeof(struct GrPlotBezier));
    bez->plt=plt;
    bez->off=&ptr->off;
    bez->xmin=ptr->xmin;
    bez->ymin=ptr->ymin;
    bez->xmax=ptr->xmax;
    bez->ymax=ptr->ymax;
    bez->state=0x01;

    blk=GrPlotSave(plt->xml,name,bez);
    XMLSetStart(plt->xml,GrPlotBezierStart,blk);
    XMLSetEnd(plt->xml,GrPlotBezierEnd,blk);
    return XMLCallStart(plt->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"ellipse")==0) {
    struct GrPlotShape *shp;
    shp=malloc(sizeof(struct GrPlotShape));
    shp->plt=plt;
    shp->off=&ptr->off;
    shp->xmin=ptr->xmin;
    shp->ymin=ptr->ymin;
    shp->xmax=ptr->xmax;
    shp->ymax=ptr->ymax;
    shp->state=0x01;
 
    blk=GrPlotSave(plt->xml,name,shp);
    XMLSetStart(plt->xml,GrPlotShapeStart,blk);
    XMLSetEnd(plt->xml,GrPlotShapeEnd,blk);
    return XMLCallStart(plt->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"rectangle")==0) {
    struct GrPlotShape *shp;
    shp=malloc(sizeof(struct GrPlotShape));
    shp->plt=plt;
    shp->off=&ptr->off;
    shp->xmin=ptr->xmin;
    shp->ymin=ptr->ymin;
    shp->xmax=ptr->xmax;
    shp->ymax=ptr->ymax;
    shp->state=0x01;
    blk=GrPlotSave(plt->xml,name,shp);
    XMLSetStart(plt->xml,GrPlotShapeStart,blk);
    XMLSetEnd(plt->xml,GrPlotShapeEnd,blk);
    return XMLCallStart(plt->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"polygon")==0) {
    struct GrPlotPolygon *pol;
    pol=malloc(sizeof(struct GrPlotPolygon));
    pol->plt=plt;
    pol->off=&ptr->off;
    pol->xmin=ptr->xmin;
    pol->ymin=ptr->ymin;
    pol->xmax=ptr->xmax;
    pol->ymax=ptr->ymax;
    pol->state=0x01;
    blk=GrPlotSave(plt->xml,name,pol);
    XMLSetStart(plt->xml,GrPlotPolygonStart,blk);
    XMLSetEnd(plt->xml,GrPlotPolygonEnd,blk);
    return XMLCallStart(plt->xml,name,atnum,atname,atval,buf,sze);
  }

 if (strcmp(name,"text")==0) {
    struct GrPlotText *txt;
    txt=malloc(sizeof(struct GrPlotText));
    txt->plt=plt;
    txt->off=&ptr->off;
    txt->xmin=ptr->xmin;
    txt->ymin=ptr->ymin;
    txt->xmax=ptr->xmax;
    txt->ymax=ptr->ymax;
    txt->state=0x01;
    blk=GrPlotSave(plt->xml,name,txt);
    XMLSetStart(plt->xml,GrPlotTextStart,blk);
    XMLSetEnd(plt->xml,GrPlotTextEnd,blk);
    return XMLCallStart(plt->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"image")==0) {
    struct GrPlotImage *img;
    img=malloc(sizeof(struct GrPlotImage));
    img->plt=plt;
    img->off=&ptr->off;
    img->xmin=ptr->xmin;
    img->ymin=ptr->ymin;
    img->xmax=ptr->xmax;
    img->ymax=ptr->ymax;
    img->state=0x01;
    blk=GrPlotSave(plt->xml,name,img);
    XMLSetStart(plt->xml,GrPlotImageStart,blk);
    XMLSetEnd(plt->xml,GrPlotImageEnd,blk);
    return XMLCallStart(plt->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"imagen")==0) {
    struct GrPlotImageName *img;
    img=malloc(sizeof(struct GrPlotImageName));
    img->plt=plt;
    img->plt=plt;
    img->off=&ptr->off;
    img->xmin=ptr->xmin;
    img->ymin=ptr->ymin;
    img->xmax=ptr->xmax;
    img->ymax=ptr->ymax;
    img->state=0x01;
    blk=GrPlotSave(plt->xml,name,img);
    XMLSetStart(plt->xml,GrPlotImageNameStart,blk);
    XMLSetEnd(plt->xml,GrPlotImageNameEnd,blk);
    return XMLCallStart(plt->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"include")==0) {
    struct GrPlotInclude *inc;
    inc=malloc(sizeof(struct GrPlotInclude));
    inc->inc=&plt->inc;
    blk=GrPlotSave(blk->xml,name,inc);
    XMLSetStart(blk->xml,GrPlotIncludeStart,blk);
    XMLSetEnd(blk->xml,GrPlotIncludeEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"ignore")==0) {
    blk=GrPlotSave(blk->xml,name,NULL);
    XMLSetStart(blk->xml,GrPlotIgnoreStart,blk);
    XMLSetText(blk->xml,GrPlotIgnoreText,blk);
    XMLSetEnd(blk->xml,GrPlotIgnoreEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }


  return 0;
}
예제 #14
0
int GrPlotShapeStart(char *name,int atnum,char **atname,char **atval,
		    char *buf,int sze,void *data) {
  int i;
  struct GrPlotBlock *blk;
  struct GrPlotShape *ptr;
  struct GrPlotData *plt;
  struct GrPlotConvert *cnv;

  blk=(struct GrPlotBlock *) data;
  if (blk==NULL) return -1;
  ptr=(struct GrPlotShape *) blk->data;
  if (ptr==NULL) return -1;
  plt=ptr->plt;
  if (plt==NULL) return -1;
  cnv=&plt->cnv;

  if (strcmp(name,blk->name)==0) {
    int s=0;
    char *xvalue=NULL;
    char *yvalue=NULL;
    char *xtype=NULL;
    char *ytype=NULL;
    unsigned int mask;
    char tmp[64];
    ptr->color=0;
    ptr->mask=0;
    ptr->fill=0;
    ptr->width=0;
    ptr->dash=NULL;
    ptr->matrix=NULL;
    ptr->x=0;
    ptr->y=0;
    for (i=0;i<atnum;i++) {
      if (strcmp(atname[i],"color")==0) {
        strcpy(tmp,"0x");
        strcat(tmp,atval[i]);
        sscanf(tmp,"%x",&ptr->color);
      } else if (strcmp(atname[i],"mask")==0) {
        strcpy(tmp,"0x");
        strcat(tmp,atval[i]);
        sscanf(tmp,"%x",&mask);
        ptr->mask=mask;
      } else if (strcmp(atname[i],"width")==0) ptr->width=atof(atval[i]);
      else if (strcmp(atname[i],"dash")==0)
        ptr->dash=RplotMakeDashString(atval[i]);
      else if (strcmp(atname[i],"fill")==0) ptr->fill=1;
      else if (strcmp(atname[i],"matrix")==0)
        ptr->matrix=RplotMatrixString(atval[i]);
      else if (strcmp(atname[i],"xvalue")==0) xvalue=atval[i];
      else if (strcmp(atname[i],"yvalue")==0) yvalue=atval[i];
      else if (strcmp(atname[i],"xpos")==0) xvalue=atval[i];
      else if (strcmp(atname[i],"ypot")==0) yvalue=atval[i];
      else if (strcmp(atname[i],"xtype")==0) xtype=atval[i];
      else if (strcmp(atname[i],"ytype")==0) ytype=atval[i];

    }
    if (xvalue !=NULL) {
      if (xtype==NULL) ptr->x=atof(xvalue);
      else if (cnv->user !=NULL)
        s=(cnv->user)(xtype,xvalue,&ptr->x,cnv->data);
      else ptr->x=0;
    }
    if (yvalue !=NULL) {
      if (ytype==NULL) ptr->y=atof(yvalue);
      else if (cnv->user !=NULL)
        s=(cnv->user)(xtype,yvalue,&ptr->y,cnv->data);
      else ptr->y=0;
    }
    return s;
  }

 
  if (strcmp(name,"extent")==0) {
    struct GrPlotExtent *ext;
    ext=malloc(sizeof(struct GrPlotExtent));
    ext->cnv=&plt->cnv;
    ext->inc=&plt->inc;
    ext->xmin=&ptr->xmin;
    ext->xmax=&ptr->xmax;
    ext->ymin=&ptr->ymin;
    ext->ymax=&ptr->ymax;
    ptr->state=ptr->state | 0x01;
    blk=GrPlotSave(blk->xml,"extent",ext);
    XMLSetStart(blk->xml,GrPlotExtentStart,blk);
    XMLSetEnd(blk->xml,GrPlotExtentEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"s")==0) {
    struct GrPlotDimension *dim;
    dim=malloc(sizeof(struct GrPlotDimension));
    dim->cnv=&plt->cnv;
    dim->inc=&plt->inc;
    dim->w=&ptr->w;
    dim->h=&ptr->h;
    ptr->state=ptr->state | 0x02;
    blk=GrPlotSave(blk->xml,"d",dim);
    XMLSetStart(blk->xml,GrPlotDimensionStart,blk);
    XMLSetEnd(blk->xml,GrPlotDimensionEnd,blk);
    return 0;
  }

  if (strcmp(name,"include")==0) {
    struct GrPlotInclude *inc;
    inc=malloc(sizeof(struct GrPlotInclude));
    inc->inc=&plt->inc;
    blk=GrPlotSave(blk->xml,name,inc);
    XMLSetStart(blk->xml,GrPlotIncludeStart,blk);
    XMLSetEnd(blk->xml,GrPlotIncludeEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"ignore")==0) {
    blk=GrPlotSave(blk->xml,name,NULL);
    XMLSetStart(blk->xml,GrPlotIgnoreStart,blk);
    XMLSetText(blk->xml,GrPlotIgnoreText,blk);
    XMLSetEnd(blk->xml,GrPlotIgnoreEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }


  return 0;
}
예제 #15
0
int FrameBufferXMLStart(char *name,int atnum,char **atname,char **atval,
			char *buf,int sze,void *data) {
  int i;
  int wdt=0,hgt=0,depth=0;
  struct FrameBufferXML *ptr;
  struct FrameBuffer *img;
  ptr=(struct FrameBufferXML *) data;

  if (ptr==NULL) return -1;
  
  if (strcmp(name,"img")==0) {
    int d=1,s=0;
    for (i=0;i<atnum;i++) {
      if ((strcmp(atname[i],"width")==0) && (atval[i] !=NULL))
	wdt=atoi(atval[i]);
      else if ((strcmp(atname[i],"height")==0) && (atval[i] !=NULL))
        hgt=atoi(atval[i]);
      else if ((strcmp(atname[i],"depth")==0) && (atval[i] !=NULL))
        depth=atoi(atval[i]);
    }

    *(ptr->img)=malloc(sizeof(struct FrameBuffer));
    img=*(ptr->img);
    if (img==NULL) return -1;

    img->name=NULL;
    img->wdt=wdt;
    img->hgt=hgt;
    img->depth=depth;
    img->user.pixel=NULL;
    img->user.data=NULL;

    if (depth !=8) d=3;
    if (s==0) img->img=malloc(wdt*hgt*d);
    if (img->img==NULL) s=-1;
    if (s==0) img->msk=malloc(wdt*hgt);
    if (img->msk==NULL) s=-1;

    if (s !=0) {
      if (img->img !=NULL) free(img->img);
      if (img->msk !=NULL) free(img->msk);
      free(img);
      return -1;
    }
    ptr->state=0;;
    return 0;
  } 
  img=*(ptr->img);
  if (img==NULL) return -1;
 
  if (strcmp(name,"name")==0) {
    if (img->name !=NULL) free(img->name);
    img->name=NULL;
    XMLSetText(ptr->xml,FrameBufferXMLNameText,&img->name);
    return 0;
  } 

  if (strcmp(name,"i")==0) {
    struct FrameBufferXMLBuffer *buf;
    int d=1;
    if (img->depth !=8) d=3;
    memset(img->img,0,d*img->wdt*img->hgt);
    buf=malloc(sizeof(struct FrameBufferXMLBuffer));
    buf->xml=ptr->xml;
    buf->data=data;
    buf->ptr=img->img;
    buf->off=0;
    buf->sze=d*img->wdt*img->hgt;
    buf->c=0;
    buf->num[0]='0';
    buf->num[1]='x';
    buf->num[4]=0;
    ptr->state=ptr->state | 0x01;
    XMLSetText(ptr->xml,FrameBufferXMLBufferText,buf);
    XMLSetEnd(ptr->xml,FrameBufferXMLBufferEnd,buf);
    return 0;
  }
  
  if (strcmp(name,"a")==0) {
    struct FrameBufferXMLBuffer *buf;
    memset(img->msk,0,img->wdt*img->hgt);
    buf=malloc(sizeof(struct FrameBufferXMLBuffer));
    buf->xml=ptr->xml;
    buf->data=data;
    buf->ptr=img->msk;
    buf->off=0;
    buf->sze=img->wdt*img->hgt;
    buf->c=0;
    buf->num[0]='0';
    buf->num[1]='x';
    buf->num[4]=0;
    ptr->state=ptr->state | 0x02;
    XMLSetText(ptr->xml,FrameBufferXMLBufferText,buf);
    XMLSetEnd(ptr->xml,FrameBufferXMLBufferEnd,buf);
    return 0;
  }  
  return 0;
}  
예제 #16
0
int GrPlotTickStart(char *name,int atnum,char **atname,char **atval,
		       char *buf,int sze,void *data) {

  struct GrPlotBlock *blk;
  struct GrPlotTick *ptr;

  blk=(struct GrPlotBlock *) data;
  if (blk==NULL) return -1;
  ptr=(struct GrPlotTick *) blk->data;
  if (ptr==NULL) return -1;

  if (strcmp(name,blk->name)==0) {

    return 0;
  }

  if (strcmp(name,"minor")==0) {
    struct GrPlotValue *val;
    val=malloc(sizeof(struct GrPlotValue));
    val->cnv=ptr->cnv;
    val->inc=ptr->inc;
    val->val=ptr->minor;
    blk=GrPlotSave(blk->xml,"minor",val);
    XMLSetStart(blk->xml,GrPlotValueStart,blk);
    XMLSetText(blk->xml,GrPlotValueText,blk);
    XMLSetEnd(blk->xml,GrPlotValueEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }
  
  if (strcmp(name,"major")==0) {
    struct GrPlotValue *val;
    val=malloc(sizeof(struct GrPlotValue));
    val->cnv=ptr->cnv;
    val->inc=ptr->inc;
    val->val=ptr->major;
    blk=GrPlotSave(blk->xml,"major",val);
    XMLSetStart(blk->xml,GrPlotValueStart,blk);
    XMLSetText(blk->xml,GrPlotValueText,blk);
    XMLSetEnd(blk->xml,GrPlotValueEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"include")==0) {
    struct GrPlotInclude *inc;
    inc=malloc(sizeof(struct GrPlotInclude));
    inc->inc=ptr->inc;
    blk=GrPlotSave(blk->xml,name,inc);
    XMLSetStart(blk->xml,GrPlotIncludeStart,blk);
    XMLSetEnd(blk->xml,GrPlotIncludeEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"ignore")==0) {
    blk=GrPlotSave(blk->xml,name,NULL);
    XMLSetStart(blk->xml,GrPlotIgnoreStart,blk);
    XMLSetText(blk->xml,GrPlotIgnoreText,blk);
    XMLSetEnd(blk->xml,GrPlotIgnoreEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }


  return 0;
}
예제 #17
0
int GrPlotBarPlotStart(char *name,int atnum,char **atname,char **atval,
		    char *buf,int sze,void *data) {
  int i;
  struct GrPlotBlock *blk;
  struct GrPlotBarPlot *ptr;
  struct GrPlotData *plt;


  blk=(struct GrPlotBlock *) data;
  if (blk==NULL) return -1;
  ptr=(struct GrPlotBarPlot *) blk->data;
  if (ptr==NULL) return -1;
  plt=ptr->plt;
  if (plt==NULL) return -1;

  if (strcmp(name,blk->name)==0) {
    unsigned int mask;
    char tmp[64];
    ptr->color=0;
    ptr->mask=0;
    ptr->width=0;
    ptr->dash=NULL;
    ptr->or=0;
    ptr->fill=0;
    ptr->w=0;
    ptr->o=0;
    ptr->state=0;
    ptr->xdmin=-HUGE_VAL;
    ptr->xdmax=HUGE_VAL;
    ptr->ydmin=-HUGE_VAL;
    ptr->ydmax=HUGE_VAL;
    ptr->name=NULL;
    ptr->encode=NULL;
    ptr->x=NULL;
    ptr->y=NULL;
 
    for (i=0;i<atnum;i++) {
      if (strcmp(atname[i],"color")==0) {
        strcpy(tmp,"0x");
        strcat(tmp,atval[i]);
        sscanf(tmp,"%x",&ptr->color);
      } else if (strcmp(atname[i],"mask")==0) {
        strcpy(tmp,"0x");
        strcat(tmp,atval[i]);
        sscanf(tmp,"%x",&mask);
        ptr->mask=mask;
      } else if (strcmp(atname[i],"width")==0) ptr->width=atof(atval[i]);
      else if (strcmp(atname[i],"fill")==0) ptr->fill=1;
      else if (strcmp(atname[i],"dash")==0)
        ptr->dash=RplotMakeDashString(atval[i]);
      else if (strcmp(atname[i],"or")==0) {
        strcpy(tmp,"0x");
        strcat(tmp,atval[i]);
        sscanf(tmp,"%x",&ptr->or);
      }
    }
    return 0;
  }

 
  if (strcmp(name,"extent")==0) {
    struct GrPlotExtent *ext;
    ext=malloc(sizeof(struct GrPlotExtent));
    ext->cnv=&plt->cnv;
    ext->inc=&plt->inc;
    ext->xmin=&ptr->xmin;
    ext->xmax=&ptr->xmax;
    ext->ymin=&ptr->ymin;
    ext->ymax=&ptr->ymax;
    ptr->state=ptr->state | 0x01;
    blk=GrPlotSave(blk->xml,"extent",ext);
    XMLSetStart(blk->xml,GrPlotExtentStart,blk);
    XMLSetEnd(blk->xml,GrPlotExtentEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"range")==0) {
    struct GrPlotExtent *ext;
    ext=malloc(sizeof(struct GrPlotExtent));
    ext->cnv=&plt->cnv;
    ext->inc=&plt->inc;
    ext->xmin=&ptr->xdmin;
    ext->xmax=&ptr->xdmax;
    ext->ymin=&ptr->ydmin;
    ext->ymax=&ptr->ydmax;
    ptr->state=ptr->state | 0x02;
    blk=GrPlotSave(blk->xml,"range",ext);
    XMLSetStart(blk->xml,GrPlotExtentStart,blk);
    XMLSetEnd(blk->xml,GrPlotExtentEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"name")==0) {
    struct GrPlotString *str;
    str=malloc(sizeof(struct GrPlotString));
    str->txt=&ptr->name;
    str->inc=&plt->inc;
    blk=GrPlotSave(blk->xml,"name",str);
    XMLSetStart(blk->xml,GrPlotStringStart,blk);
    XMLSetText(blk->xml,GrPlotStringText,blk);
    XMLSetEnd(blk->xml,GrPlotStringEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"index")==0) {
    struct GrPlotIndex *inx;
    inx=malloc(sizeof(struct GrPlotIndex));
    inx->inc=&plt->inc;
    inx->x=&ptr->x;
    inx->y=&ptr->y;
    blk=GrPlotSave(blk->xml,"index",inx);
    XMLSetStart(blk->xml,GrPlotIndexStart,blk);
    XMLSetEnd(blk->xml,GrPlotIndexEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"w")==0) {
    struct GrPlotValue *val;
    val=malloc(sizeof(struct GrPlotValue));
    val->cnv=&plt->cnv;
    val->inc=&plt->inc;
    val->val=&ptr->w;
    ptr->state=ptr->state | 0x04;
    blk=GrPlotSave(blk->xml,"w",val);
    XMLSetStart(blk->xml,GrPlotValueStart,blk);
    XMLSetText(blk->xml,GrPlotValueText,blk);
    XMLSetEnd(blk->xml,GrPlotValueEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"o")==0) {
    struct GrPlotValue *val;
    val=malloc(sizeof(struct GrPlotValue));
    val->cnv=&plt->cnv;
    val->inc=&plt->inc;
    val->val=&ptr->o;
    ptr->state=ptr->state | 0x08;
    blk=GrPlotSave(blk->xml,"o",val);
    XMLSetStart(blk->xml,GrPlotValueStart,blk);
    XMLSetText(blk->xml,GrPlotValueText,blk);
    XMLSetEnd(blk->xml,GrPlotValueEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }


  if (strcmp(name,"include")==0) {
    struct GrPlotInclude *inc;
    inc=malloc(sizeof(struct GrPlotInclude));
    inc->inc=&plt->inc;
    blk=GrPlotSave(blk->xml,name,inc);
    XMLSetStart(blk->xml,GrPlotIncludeStart,blk);
    XMLSetEnd(blk->xml,GrPlotIncludeEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"ignore")==0) {
    blk=GrPlotSave(blk->xml,name,NULL);
    XMLSetStart(blk->xml,GrPlotIgnoreStart,blk);
    XMLSetText(blk->xml,GrPlotIgnoreText,blk);
    XMLSetEnd(blk->xml,GrPlotIgnoreEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }


  return 0;
}
예제 #18
0
int main(int argc,char *argv[]) {
  char lbuf[256];
  int s=0;
  int arg=0;
  FILE *fp;
  struct FrameBuffer *src=NULL;
  struct FrameBuffer *dst=NULL;

  struct XMLdata *xmldata=NULL;
  struct FrameBufferXML xmlimg;

  unsigned int bgcolor=0;
  char *bgtxt=NULL;

  unsigned char alpha=0;

  unsigned char help=0;
  unsigned char option=0;

 
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

  OptionAdd(&opt,"bgcol",'t',&bgtxt);
  OptionAdd(&opt,"alpha",'x',&alpha);
   
  arg=OptionProcess(1,argc,argv,&opt,NULL);   

  if (help==1) {
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  }

  if (option==1) {
    OptionDump(stdout,&opt);
    exit(0);
  }

  xmldata=XMLMake();
  xmlimg.xml=xmldata;
  xmlimg.img=&src;

  XMLSetStart(xmldata,FrameBufferXMLStart,&xmlimg);
  XMLSetEnd(xmldata,FrameBufferXMLEnd,&xmlimg);

  if (arg<argc) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  while(fgets(lbuf,255,fp) !=NULL) {
    s=XMLDecode(xmldata,lbuf,strlen(lbuf));
    if (s !=0) break;
  }
  if (s !=0) {
    fprintf(stderr,"Error decoding image.\n");
    exit(-1);
  }
  if (arg<argc) fclose(fp);

  bgcolor=FrameBufferColor(0x00,0x00,0x00,0x00);


  if (bgtxt !=NULL) {
     sscanf(bgtxt,"%x",&bgcolor);
  }

  if (src==NULL) {
    fprintf(stderr,"Error decoding image.\n");
    exit(-1);
  }



  if (bgcolor !=0) {
    dst=FrameBufferMake(NULL,src->wdt,src->hgt,24);
    if (dst==NULL) {
      fprintf(stderr,"Error creating image.\n");
      exit(-1);
    }
    FrameBufferClear(dst,bgcolor,0x0f);
    FrameBufferImage(dst,NULL,src,0x0f,0,0,0,NULL);
    if (alpha==0) FrameBufferSavePPM(dst,stdout);
    else FrameBufferSavePPMAlpha(dst,stdout);
  } else {
    if (alpha==0)  FrameBufferSavePPM(src,stdout);
    else FrameBufferSavePPMAlpha(src,stdout);
  }


  



  return 0;
}
예제 #19
0
int GrPlotImageNameStart(char *name,int atnum,char **atname,char **atval,
		    char *buf,int sze,void *data) {
  int i;
  struct GrPlotBlock *blk;
  struct GrPlotImageName *ptr;
  struct GrPlotData *plt;
  struct GrPlotConvert *cnv;

  blk=(struct GrPlotBlock *) data;
  if (blk==NULL) return -1;
  ptr=(struct GrPlotImageName *) blk->data;
  if (ptr==NULL) return -1;
  plt=ptr->plt;
  if (plt==NULL) return -1;
  cnv=&plt->cnv;

  if (strcmp(name,blk->name)==0) {
    int s=0;
    unsigned int mask;
    char *xvalue=NULL;
    char *yvalue=NULL;
    char *xtype=NULL;
    char *ytype=NULL;

    char tmp[64];
    ptr->mask=0;
    ptr->name=NULL;
    ptr->matrix=NULL;
    ptr->dx=0;
    ptr->dy=0;
    ptr->x=0;
    ptr->y=0;
    for (i=0;i<atnum;i++) {
      if (strcmp(atname[i],"mask")==0) {
        strcpy(tmp,"0x");
        strcat(tmp,atval[i]);
        sscanf(tmp,"%x",&mask);
        ptr->mask=mask;
      } else if (strcmp(atname[i],"matrix")==0)
        ptr->matrix=RplotMatrixString(atval[i]);
      else if (strcmp(atname[i],"xvalue")==0) xvalue=atval[i];
      else if (strcmp(atname[i],"yvalue")==0) yvalue=atval[i];
      else if (strcmp(atname[i],"xpos")==0) xvalue=atval[i];
      else if (strcmp(atname[i],"ypos")==0) yvalue=atval[i];
      else if (strcmp(atname[i],"xtype")==0) xtype=atval[i];
      else if (strcmp(atname[i],"ytype")==0) ytype=atval[i];
      else if (strcmp(atname[i],"xoffset")==0) ptr->dx=atof(atval[i]);
      else if (strcmp(atname[i],"yoffset")==0) ptr->dy=atof(atval[i]);
    }
    if (xvalue !=NULL) {
      if (xtype==NULL) ptr->x=atof(xvalue);
      else if (cnv->user !=NULL)
        s=(cnv->user)(xtype,xvalue,&ptr->x,cnv->data);
      else ptr->x=0;
    }
    if (yvalue !=NULL) {
      if (ytype==NULL) ptr->y=atof(yvalue);
      else if (cnv->user !=NULL)
        s=(cnv->user)(xtype,yvalue,&ptr->y,cnv->data);
      else ptr->y=0;
    }
    return s;
  }

 
  if (strcmp(name,"extent")==0) {
    struct GrPlotExtent *ext;
    ext=malloc(sizeof(struct GrPlotExtent));
    ext->cnv=&plt->cnv;
    ext->inc=&plt->inc;
    ext->xmin=&ptr->xmin;
    ext->xmax=&ptr->xmax;
    ext->ymin=&ptr->ymin;
    ext->ymax=&ptr->ymax;
    ptr->state=ptr->state | 0x01;
    blk=GrPlotSave(blk->xml,"extent",ext);
    XMLSetStart(blk->xml,GrPlotExtentStart,blk);
    XMLSetEnd(blk->xml,GrPlotExtentEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"name")==0) {
    struct GrPlotString *str;
    str=malloc(sizeof(struct GrPlotString));
    str->txt=&ptr->name; 
    str->inc=&plt->inc;
    blk=GrPlotSave(blk->xml,"name",str);
    XMLSetStart(blk->xml,GrPlotStringStart,blk);
    XMLSetText(blk->xml,GrPlotStringText,blk);
    XMLSetEnd(blk->xml,GrPlotStringEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"include")==0) {
    struct GrPlotInclude *inc;
    inc=malloc(sizeof(struct GrPlotInclude));
    inc->inc=&plt->inc;
    blk=GrPlotSave(blk->xml,name,inc);
    XMLSetStart(blk->xml,GrPlotIncludeStart,blk);
    XMLSetEnd(blk->xml,GrPlotIncludeEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }


  return 0;
}
예제 #20
0
파일: rplot.c 프로젝트: horit/RST2.10_stel
int main(int argc,char *argv[]) {
 

#ifdef _XLIB_
  char *name="rplot";
  int xdf=0;
  int xd=0;
  struct XwinDisplay *dp;
  struct XwinWindow *win;
  char *display_name=NULL;
  int xdoff=-1;
  int ydoff=-1;
#endif


  int s=0;
  int arg=0;
  FILE *fp;
  char lbuf[256];
  struct FrameBuffer *img=NULL;
  struct FrameBufferRplot *fbplot=NULL;
  struct PostScriptRplot *psplot=NULL;
  struct PostScript *psdata=NULL;
  struct FrameBufferFontDB *fontdb=NULL;
  struct FrameBufferDB *imagedb=NULL;
  struct XMLdata *xmldata=NULL;
  struct RplotInPlot *rplotin=NULL;
  struct RplotRplot *rplotrplot=NULL;
  struct Rplot *rplot=NULL;
 
  unsigned char land=0;
  float xpoff=40,ypoff=40;
  
  char *fntdbfname=NULL;
  unsigned char psflg=0;
  unsigned char xmlflg=0;
  unsigned char ppmflg=0;
  unsigned char ppmxflg=0;

  unsigned char rflg=0;
  unsigned char gflg=0;
  unsigned char pflg=0;

  unsigned char help=0;
  unsigned char option=0;

 
  struct OptionText *ppmnme=NULL;
  struct OptionText *ppmxnme=NULL;
  struct OptionText *xmlnme=NULL;

  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

  OptionAdd(&opt,"ps",'x',&psflg);
  OptionAdd(&opt,"ppm",'x',&ppmflg);
  OptionAdd(&opt,"ppmx",'x',&ppmxflg);
  OptionAdd(&opt,"xml",'x',&xmlflg);
  OptionAdd(&opt,"land",'x',&land);
  OptionAdd(&opt,"xp",'f',&xpoff);
  OptionAdd(&opt,"yp",'f',&ypoff);

  OptionAdd(&opt,"ippm",'a',&ppmnme);
  OptionAdd(&opt,"ippmx",'a',&ppmxnme);
  OptionAdd(&opt,"ixml",'a',&xmlnme);
 
#ifdef _XLIB_ 
  OptionAdd(&opt,"x",'x',&xd);
  OptionAdd(&opt,"display",'t',&display_name);
  OptionAdd(&opt,"xoff",'i',&xdoff);
  OptionAdd(&opt,"yoff",'i',&ydoff);
#endif

  OptionAdd(&opt,"fdb",'t',&fntdbfname);

  arg=OptionProcess(1,argc,argv,&opt,NULL);   

  if (help==1) {
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  }

  if (option==1) {
    OptionDump(stdout,&opt);
    exit(0);
  }


  if (psflg) pflg=1;
  if (xmlflg) gflg=1; 
  if (ppmflg) gflg=1;
  if (ppmxflg) gflg=1;

#ifdef _XLIB_ 
   if (xd !=0) {
     pflg=0; 
     gflg=1;
   }
#endif
     
  if (pflg) gflg=0;

  if ((pflg==0) && (gflg==0)) rflg=1;

  if (gflg) {
    if (fntdbfname==NULL) fntdbfname=getenv("FONTDB");
    if (fntdbfname !=NULL) {
      fp=fopen(fntdbfname,"r");
      if (fp !=NULL) {
        fontdb=FrameBufferFontDBLoad(fp);
        fclose(fp);
      }
    }
    if (fontdb==NULL) {
      fprintf(stderr,"Could not load fonts.\n");
      exit(-1);
    }
  }
   
  imagedb=FrameBufferDBMake();
  loadxml(imagedb,xmlnme);
  loadppm(imagedb,ppmnme);
  loadppmx(imagedb,ppmxnme);

  xmldata=XMLMake();
  rplotin=RplotInMake(xmldata);

  if (gflg) {
      fbplot=FrameBufferRplotMake(fontdb,imagedb);
      FrameBufferRplotSetAll(rplotin,fbplot);
  }
  if (pflg) {
    psdata=PostScriptMake();
    PostScriptSetText(psdata,stream,stdout);
    psplot=PostScriptRplotMake(psdata,imagedb);
    PostScriptRplotSetAll(rplotin,psplot);
    psplot->land=land;
    psplot->xoff=xpoff;
    psplot->yoff=ypoff;
  }
  if (rflg) {
    rplot=RplotMake();
    RplotSetText(rplot,stream,stdout);
    rplotrplot=RplotRplotMake(rplot,imagedb);
    RplotRplotSetAll(rplotin,rplotrplot);
    RplotInSetPass(rplotin,clean_newline,stdout);
  }

  XMLSetStart(xmldata,RplotInStart,rplotin);
  XMLSetEnd(xmldata,RplotInEnd,rplotin);
  XMLSetText(xmldata,RplotInText,rplotin);

  if (arg<argc) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"Error opening file.\n");
      exit(-1);
    }
  } else fp=stdin;

  while(fgets(lbuf,255,fp) !=NULL) {
          
    s=XMLDecode(xmldata,lbuf,strlen(lbuf));
    if (s !=0) break;

  }
  if (s !=0) {
    fprintf(stderr,"Error parsing document.\n");
    exit(0);
  }
 
  if (arg<argc) fclose(fp);
  if (fbplot==NULL) exit(0);
  if (fbplot->img==NULL) {
    fprintf(stderr,"Nothing to plot.\n");
    exit(-1);
  }
  img=fbplot->img;

#ifdef _XLIB_
  if (xd !=0) {
    dp=XwinOpenDisplay(display_name,&xdf);
 
    if (dp==NULL) {
      fprintf(stderr,"Could not open display.\n");
      exit(-1);
    }

    if (xdoff==-1) xdoff=(dp->wdt-img->wdt)/2;
    if (ydoff==-1) ydoff=(dp->hgt-img->hgt)/2;


    win=XwinMakeWindow(xdoff,ydoff,img->wdt,img->hgt,0,
                       dp,name,
                       name,argv[0],name,argc,argv,&xdf);
    if (win==NULL) {
      fprintf(stderr,"Could not create window.\n");
      exit(-1);
    }

    XwinFrameBufferWindow(img,win);

    XwinShowWindow(win);

    XwinDisplayEvent(dp,1,&win,1,NULL);

    XwinFreeWindow(win);
    XwinCloseDisplay(dp);
  } else {
    if (xmlflg==1) FrameBufferSaveXML(img,stream,stdout);
    else if (ppmflg==1) FrameBufferSavePPM(img,stdout);
    else FrameBufferSavePPMX(img,stdout);
  }
  #else 
  if (xmlflg==1) FrameBufferSaveXML(img,stream,stdout);
  else if (ppmflg==1) FrameBufferSavePPM(img,stdout);
  else FrameBufferSavePPMX(img,stdout);
  #endif
  return 0;
}
예제 #21
0
int RplotInDimensionStart(char *name,int atnum,char **atname,char **atval,
		       char *buf,int sze,void *data) {

  struct RplotInBlock *blk;
  struct RplotInDimension *ptr;

  blk=(struct RplotInBlock *) data;
  if (blk==NULL) return -1;
  ptr=(struct RplotInDimension *) blk->data;
  if (ptr==NULL) return -1;

  if (strcmp(name,blk->name)==0) {
    ptr->state=0;
    return 0;
  }

  if (strcmp(name,"w")==0) {
    struct RplotInFloat *flt;
    flt=malloc(sizeof(struct RplotInFloat));
    flt->inc=ptr->inc;
    flt->val=ptr->w;
    ptr->state=ptr->state | 0x01;
    blk=RplotInSave(blk->xml,name,flt);
    XMLSetStart(blk->xml,RplotInFloatStart,blk);
    XMLSetText(blk->xml,RplotInFloatText,blk);
    XMLSetEnd(blk->xml,RplotInFloatEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }
  

  if (strcmp(name,"h")==0) {
    struct RplotInFloat *flt;
    flt=malloc(sizeof(struct RplotInFloat));
    flt->inc=ptr->inc;
    flt->val=ptr->h;
    ptr->state=ptr->state | 0x02;
    blk=RplotInSave(blk->xml,name,flt);
    XMLSetStart(blk->xml,RplotInFloatStart,blk);
    XMLSetText(blk->xml,RplotInFloatText,blk);
    XMLSetEnd(blk->xml,RplotInFloatEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"include")==0) {
    struct RplotInInclude *inc;
    inc=malloc(sizeof(struct RplotInInclude));
    inc->inc=ptr->inc;
    blk=RplotInSave(blk->xml,name,inc);
    XMLSetStart(blk->xml,RplotInIncludeStart,blk);
    XMLSetEnd(blk->xml,RplotInIncludeEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"ignore")==0) {
    blk=RplotInSave(blk->xml,name,NULL);
    XMLSetStart(blk->xml,RplotInIgnoreStart,blk);
    XMLSetText(blk->xml,RplotInIgnoreText,blk);
    XMLSetEnd(blk->xml,RplotInIgnoreEnd,blk);
    return 0;
  }

  return 0;
}
예제 #22
0
int GrPlotZeroStart(char *name,int atnum,char **atname,char **atval,
		    char *buf,int sze,void *data) {
  int i;
  struct GrPlotBlock *blk;
  struct GrPlotZero *ptr;
  struct GrPlotData *plt;

  blk=(struct GrPlotBlock *) data;
  if (blk==NULL) return -1;
  ptr=(struct GrPlotZero *) blk->data;
  if (ptr==NULL) return -1;
  plt=ptr->plt;
  if (plt==NULL) return -1;


  if (strcmp(name,blk->name)==0) {
    unsigned int mask;
    char tmp[64];
    ptr->color=0;
    ptr->mask=0;
    ptr->width=0;
    ptr->dash=NULL;
    ptr->state=0;
    for (i=0;i<atnum;i++) {
      if (strcmp(atname[i],"color")==0) {
        strcpy(tmp,"0x");
        strcat(tmp,atval[i]);
        sscanf(tmp,"%x",&ptr->color);
      } else if (strcmp(atname[i],"mask")==0) {
        strcpy(tmp,"0x");
        strcat(tmp,atval[i]);
        sscanf(tmp,"%x",&mask);
        ptr->mask=mask;
      } else if (strcmp(atname[i],"width")==0) ptr->width=atof(atval[i]);
      else if (strcmp(atname[i],"dash")==0) 
        ptr->dash=RplotMakeDashString(atval[i]);
    }
    return 0;
  }

  if (strcmp(name,"limit")==0) {
    struct GrPlotLimit *lmt;
    lmt=malloc(sizeof(struct GrPlotLimit));
    lmt->cnv=&plt->cnv;
    lmt->inc=&plt->inc;
    lmt->min=&ptr->min;
    lmt->max=&ptr->max;
    ptr->state=ptr->state | 0x01;
    blk=GrPlotSave(blk->xml,"limit",lmt);
    XMLSetStart(blk->xml,GrPlotLimitStart,blk);
    XMLSetEnd(blk->xml,GrPlotLimitEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"include")==0) {
    struct GrPlotInclude *inc;
    inc=malloc(sizeof(struct GrPlotInclude));
    inc->inc=&plt->inc;
    blk=GrPlotSave(blk->xml,name,inc);
    XMLSetStart(blk->xml,GrPlotIncludeStart,blk);
    XMLSetEnd(blk->xml,GrPlotIncludeEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }

  if (strcmp(name,"ignore")==0) {
    blk=GrPlotSave(blk->xml,name,NULL);
    XMLSetStart(blk->xml,GrPlotIgnoreStart,blk);
    XMLSetText(blk->xml,GrPlotIgnoreText,blk);
    XMLSetEnd(blk->xml,GrPlotIgnoreEnd,blk);
    return XMLCallStart(blk->xml,name,atnum,atname,atval,buf,sze);
  }


  return 0;
}
예제 #23
0
파일: xmldoc.c 프로젝트: ajribeiro/VT_RST3
int main(int argc,char *argv[]) {
  int s=0,m,n;
  FILE *fp;
  FILE *xmlfp;
  unsigned char help=0;
  unsigned char option=0;
  unsigned char ilf=0; 
  char *pathstr=NULL;
  char *scstr=NULL;
  int sctype=0;

  struct XMLDBbuffer *scbuf=NULL;  

  struct XMLdata *xmldata=NULL;
  struct XMLDBdata *xmldbdata=NULL;
  struct XMLDBtree *tree=NULL;

  char *symbol[]={"\"","\\","<",">","&",0};
  char *entity[]={"&quot;","&apos;","&lt;","&gt;","&amp;",0};
  struct Entitydata *entptr;

  struct OptionText *ignore=NULL;
  struct OptionText *remove=NULL;


  char lbuf[255];
  char zero[1]={0};

  entptr=EntityMake();
 
  EntityAddEntityStringArray(entptr,entity);
  EntityAddSymbolStringArray(entptr,symbol);
 
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

  OptionAdd(&opt,"ilf",'x',&ilf);

  OptionAdd(&opt,"i",'a',&ignore);
  OptionAdd(&opt,"r",'a',&remove);

  OptionAdd(&opt,"path",'t',&pathstr);
  OptionAdd(&opt,"script",'t',&scstr);
  OptionAdd(&opt,"sctype",'i',&sctype);

  arg=OptionProcess(1,argc,argv,&opt,NULL);   

  if (help==1) {
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  } 

  if (option==1) {
    OptionDump(stdout,&opt);
    exit(0);
  }
 

  if ((argc-arg)<3) {
    fprintf(stderr,"xmldoc pwd cfgfile xmldata\n");
    exit(-1);
  }
 
  xmlfp=fopen(argv[arg+2],"r");
  if (xmlfp==NULL) {
    fprintf(stderr,"file not found.\n");
    exit(-1);
  }

  chdir(argv[arg]);

  fp=fopen(argv[arg+1],"r");
  loadconfig(fp,&xmldoc);
  fclose(fp);

 
  if (argc>3) xmldoc.compare.data=argv[arg+3];
  else xmldoc.compare.data=NULL;

  xmldoc.compare.check=cmp;  

  xmldoc.map.iflg=-1;

  if (pathstr !=NULL) {
    free(xmldoc.tree.path);
    xmldoc.tree.path=pathstr;   
  }

  if (scstr !=NULL) {
    xmldoc.sc.type=sctype;
    scbuf=XMLDBMakeBuffer(64);
    XMLDBAddBuffer(scbuf,scstr,strlen(scstr));
    XMLDBFreeBuffer(xmldoc.sc.buf);

    if (sctype==1) {
      xmldoc.sc.buf=XMLDBCopyBuffer(scbuf);
      XMLDBAddBuffer(xmldoc.sc.buf,zero,1);
    } else xmldoc.sc.buf=EntityDecodeBuffer(entptr,scbuf);
    XMLDBFreeBuffer(scbuf);
  }
  
  xmldata=XMLMake();
  xmldbdata=XMLDBMake(xmldata);
  tree=XMLDBMakeTree();

  XMLDBBuildTree(xmldoc.tree.path,xmldoc.tree.delim,tree);
  XMLDBSetTree(xmldbdata,tree);
    
  /* Set the renderer to XMLrender */

  XMLDBSetText(xmldbdata,render,&xmldoc);

  XMLSetStart(xmldata,XMLDBStart,xmldbdata);
  XMLSetEnd(xmldata,XMLDBEnd,xmldbdata); 
  XMLSetComment(xmldata,redirect,xmldata);  

  xmldoc.script=ScriptMake();
  ScriptSetText(xmldoc.script,mapxml,&xmldoc);

  XMLdocSetText(xmldoc.doc,stream_output,stdout);

  if (remove !=NULL) {

    xmldoc.map.remove.num=remove->num;
    xmldoc.map.remove.txt=remove->txt;
  }

  if (ignore !=NULL) {
    xmldoc.map.ignore.num=ignore->num;
    xmldoc.map.ignore.txt=ignore->txt;
  }


  while(fgets(lbuf,255,xmlfp) !=NULL) {
    if (ilf) {
      m=0;
      for (n=0;(lbuf[n] !=0) && (n<256);n++) {
        if (lbuf[n]=='\n') continue;
        lbuf[m]=lbuf[n];
        m++;
      }    
      lbuf[m]=0;
    }
    s=XMLDecode(xmldata,lbuf,strlen(lbuf));
    if (s !=0) break;
  }

  XMLFree(xmldata);
  XMLDBFree(xmldbdata);
  XMLDBFreeTree(tree);
  ScriptFree(xmldoc.script);
  fclose(xmlfp); 
  fflush(stdout);  
  return 0;

}