Subversion Repositories wimsdev

Rev

Rev 17584 | Rev 17587 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
  2.  *
  3.  *  This program is free software; you can redistribute it and/or modify
  4.  *  it under the terms of the GNU General Public License as published by
  5.  *  the Free Software Foundation; either version 2 of the License, or
  6.  *  (at your option) any later version.
  7.  *
  8.  *  This program is distributed in the hope that it will be useful,
  9.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  *  GNU General Public License for more details.
  12.  *
  13.  *  You should have received a copy of the GNU General Public License
  14.  *  along with this program; if not, write to the Free Software
  15.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17.  
  18. #include <errno.h>
  19. #include "flydraw.h"
  20.  
  21. /* Tikz things */
  22. /* the_tiled,gdTiled , int the_tiled*/
  23. static char *tikz_options (int the_color, int the_fill)
  24. {
  25.   static char buf[100];
  26.   if (the_color == gdBrushed)
  27.     the_color = tikz_brushColor;
  28.   int r=gdImageRed(image,the_color);
  29.   int g=gdImageGreen(image,the_color);
  30.   int b=gdImageBlue(image,the_color);
  31.   sprintf(buf, "draw={rgb,255:red,%i;green,%i;blue,%i},cap=round",r,g,b);
  32.   if (the_color != tikz_brushColor) strcat(buf, ",thin");
  33.   if (the_fill == -1) strcat(buf, ",dashed");
  34.   if (the_fill == 1)
  35.     sprintf(buf+strlen(buf), ",fill={rgb,255:red,%i;green,%i;blue,%i}",r,g,b);
  36.   return buf;
  37. }
  38.  
  39. #define flip(y) (sizey-(y))
  40.  
  41. /* bug in gdImageFillToBorder */
  42.  
  43. void patchgdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
  44. {
  45.   if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
  46.   gdImageFillToBorder(im,x,y,border,color);
  47. }
  48.  
  49. void patchgdImageFill (gdImagePtr im, int x, int y, int color)
  50. {
  51.   if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
  52.   gdImageFill(im,x,y,color);
  53. }
  54.  
  55.  
  56. #define DASHPIXELS 8
  57.  
  58. void myDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color){
  59.   /**
  60.    * emulates gdImageDashedLine with gdImageSetStyle and gdImageLine
  61.    * GK: As gdImageDashedLine is slightly broken in latest libgd libraries,
  62.    * GK: I implemented an emulation named "myDashedLine"
  63.    **/
  64.  
  65.   int styleDashed[DASHPIXELS],i;
  66.   for (i=0; i< DASHPIXELS/2; i++) styleDashed[i]=color;
  67.   for (; i< DASHPIXELS; i++) styleDashed[i]=gdTransparent;
  68.   gdImageSetStyle(im, styleDashed, DASHPIXELS);
  69.   gdImageLine(im, x1, y1, x2, y2, gdStyled);
  70. }
  71.  
  72.  
  73. /* File opening: with security */
  74. FILE *open4read(char *n)
  75. {
  76.   char *p, *p1, *p2, namebuf[2048];
  77.   int t;
  78.   FILE *f;
  79.   n=find_word_start(n);
  80.   if(*n==0) return NULL;
  81.   p=getenv("flydraw_filebase");
  82.   p1=n+strlen(n)-4;if(p1<n || strcasecmp(p1,".gif")!=0) t=1; else t=0;
  83.   if(p!=NULL && *p!=0) {
  84.     char pbuf[MAX_LINELEN+1];
  85.     snprintf(pbuf,sizeof(pbuf),"%s",p);
  86.     p=find_word_start(pbuf); if(strstr(p,"..")!=NULL) return NULL;
  87.     if(*n=='/' || strstr(n,"..")!=NULL) return NULL;
  88.     /* prohibit unusual file/dir names */
  89.     for(p1=p;*p1;p1++)
  90.       if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL)
  91.         return NULL;
  92.     for(p1=n;*p1;p1++)
  93.       if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL)
  94.         return NULL;
  95.     f=NULL;
  96.     for(p1=p; *p1; p1=find_word_start(p2)) {
  97.       p2=find_word_end(p1);
  98.       if(*p2) *p2++=0;
  99.       snprintf(namebuf,sizeof(namebuf),"%s/%s",p1,n);
  100.       f=fopen(namebuf,"r"); if(f!=NULL) goto imgtype;
  101.     }
  102.     p1=getenv("w_wims_session");
  103.     if(p1!=NULL && strncmp(n,"insert",6)==0) {
  104.       snprintf(namebuf,sizeof(namebuf),"../s2/%s/%s",p1,n);
  105.       f=fopen(namebuf,"r");
  106.     }
  107.   }
  108.   else {
  109.     snprintf(namebuf,sizeof(namebuf),"%s",n);
  110.     f=fopen(namebuf,"r");
  111.   }
  112.   imgtype:
  113.   if(t && f!=NULL) {
  114.     char tbuf[1024],sbuf[4096];
  115.     fclose(f); f=NULL;
  116.     p1=getenv("TMPDIR"); if(p1==NULL || *p1==0) p1=".";
  117.     snprintf(tbuf,sizeof(tbuf),"%s/drawfile_.gif",p1);
  118.     snprintf(sbuf,sizeof(sbuf),"convert %s %s",namebuf,tbuf);
  119.     if (system(sbuf)) fly_error("system_failed");
  120.       f=fopen(tbuf,"r");
  121.   }
  122.   return f;
  123. }
  124.  
  125. /* Does nothing; just a comment. */
  126. void obj_comment(objparm *pm)
  127. {
  128.   return;
  129. }
  130.  
  131. /* define image size */
  132. void obj_size(objparm *pm)
  133. {
  134.   sizex=rint(pm->pd[0]); sizey=rint(pm->pd[1]);
  135.   if(sizex<0 || sizey<0 || sizex>MAX_SIZE || sizey>MAX_SIZE) {
  136.     fly_error("bad_size"); return;
  137.   }
  138.   if(image!=NULL) {
  139.     fly_error("size_already_defined"); return;
  140.   }
  141.   image=gdImageCreate(sizex,sizey);
  142.   if(tikz_file) fprintf(tikz_file,"\\clip (0,0) rectangle (%i, %i);\n", sizex, sizey);
  143.   if(image==NULL) fly_error("image_creation_failure");
  144.   else {
  145.     color_white=gdImageColorAllocate(image,255,255,255);
  146.     color_black=gdImageColorAllocate(image,0,0,0);
  147.     color_bounder=gdImageColorAllocate(image,1,2,3);
  148.     color_frame=gdImageColorAllocate(image,254,254,254);
  149.   }
  150. }
  151.  
  152. /* new image */
  153. void obj_new(objparm *pm)
  154. {
  155.   if(image) {
  156.     gdImageDestroy(image);image=NULL;
  157.   }
  158.   if(pm->pcnt>=2) { obj_size(pm); gdImageRectangle(image,0,0,sizex-1,sizey-1,color_frame);}
  159.   else sizex=sizey=0;
  160.   saved=0;
  161. }
  162.  
  163. /* new image */
  164. void obj_existing(objparm *pm)
  165. {
  166.   FILE *inf;
  167.   char *pp;
  168.  
  169.   if(image) {
  170.     gdImageDestroy(image);image=NULL;
  171.   }
  172.   pp=find_word_start(pm->str);*find_word_end(pp)=0;
  173.   inf=open4read(pp);
  174.   if(inf==NULL) {
  175.     fly_error("file_not_exist"); return;
  176.   }
  177.   image=gdImageCreateFromGif(inf); fclose(inf);
  178.   if(image==NULL) {
  179.     fly_error("bad_gif"); return;
  180.   }
  181.   sizex=image->sx; sizey=image->sy;
  182.   saved=0;
  183. }
  184.  
  185. /* solid line */
  186. void obj_line(objparm *pm)
  187. {
  188.   scale(pm->pd,pm->p,2);
  189.   gdImageLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],pm->color[0]);
  190.   if (tikz_file)
  191.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  192.       tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3]));
  193.   if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]);
  194. }
  195.  
  196. void _obj_arrow(objparm *pm, int twoside)
  197. {
  198.   int l,xx,yy;
  199.   gdPoint ii[3];
  200.   double dx,dy,length,dd[6];
  201.   scale(pm->pd,pm->p,2);
  202.   xx=ii[0].x=pm->p[2];yy=ii[0].y=pm->p[3];
  203.   l=pm->pd[4];if(l<0) l=0; if(l>200) l=200;
  204.   scale2(pm->pd[0]-pm->pd[2],pm->pd[1]-pm->pd[3],&dx,&dy);
  205.   length=sqrt(dx*dx+dy*dy);
  206.   if(length<3 || l<5) goto stem;
  207.   dd[0]=l*dx/length; dd[1]=l*dy/length;
  208.   #define fat 0.27
  209.   dd[2]=dd[0]+dd[1]*fat; dd[3]=dd[1]-dd[0]*fat;
  210.   dd[4]=dd[0]-dd[1]*fat; dd[5]=dd[1]+dd[0]*fat;
  211.   ii[1].x=rint(dd[2])+ii[0].x; ii[1].y=rint(dd[3])+ii[0].y;
  212.   ii[2].x=rint(dd[4])+ii[0].x; ii[2].y=rint(dd[5])+ii[0].y;
  213.   gdImageFilledPolygon(image, ii,3,pm->color[0]);
  214.   if(tikz_file)
  215.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) -- (%i, %i) -- cycle;\n",
  216.       tikz_options(pm->color[0],1),ii[0].x,flip(ii[0].y),ii[1].x,flip(ii[1].y),ii[2].x,flip(ii[2].y));
  217.   if(vimg_enable) vimg_polyline(scale_buf,3,1);
  218.   xx=rint(dd[0])+ii[0].x;yy=rint(dd[1])+ii[0].y;
  219.   if(twoside) {
  220.     ii[0].x=pm->p[0]; ii[0].y=pm->p[1];
  221.     ii[1].x=-rint(dd[2])+ii[0].x; ii[1].y=-rint(dd[3])+ii[0].y;
  222.     ii[2].x=-rint(dd[4])+ii[0].x; ii[2].y=-rint(dd[5])+ii[0].y;
  223.     gdImageFilledPolygon(image, ii,3,pm->color[0]);
  224.   if(tikz_file)
  225.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) -- (%i, %i) -- cycle;\n",
  226.       tikz_options(pm->color[0],1),ii[0].x,flip(ii[0].y),ii[1].x,flip(ii[1].y),ii[2].x,flip(ii[2].y));
  227.   }
  228.   stem: if(pm->fill)
  229.     myDashedLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]);
  230.   else
  231.     gdImageLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]);
  232.   if(tikz_file)
  233.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  234.       tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),xx,flip(yy));
  235.   if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]);
  236. }
  237.  
  238. /* Arrow */
  239. void obj_arrow(objparm *pm)
  240. {
  241.   _obj_arrow(pm,0);
  242. }
  243.  
  244. /* 2-sided arrow */
  245. void obj_arrow2(objparm *pm)
  246. {
  247.    _obj_arrow(pm,1);
  248. }
  249.  
  250. /* horizontal line */
  251. void obj_hline(objparm *pm)
  252. {
  253.   scale(pm->pd,pm->p,1);
  254.   if(pm->fill)
  255.     myDashedLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]);
  256.   else
  257.     gdImageLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]);
  258.   if (tikz_file)
  259.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  260.       tikz_options(pm->color[0],pm->fill),0,flip(pm->p[1]),sizex,flip(pm->p[1]));
  261. }
  262.  
  263. /* tikzfile */
  264. void obj_tikzfile(objparm *pm)
  265. {
  266.   char *p;
  267.   if(tikz_file){
  268.     fprintf(tikz_file,"\\end{tikzpicture}\n\\end{document}\n");
  269.     fclose(tikz_file);
  270.   }
  271.   p=find_word_start(pm->str); *find_word_end(p)=0;
  272.   snprintf(tikzfilename,sizeof(tikzfilename),"%s",p);
  273.   tikz_file=fopen(tikzfilename,"w");
  274.   if(!tikz_file)
  275.     fly_error("tikz_nopen");
  276.   fprintf(tikz_file,"\\documentclass\[11pt]{article}\n\\usepackage{tikz}\n\\begin{document}\n\\begin{tikzpicture}\[scale=0.0254]\n");
  277. }
  278.  
  279. /* vertical line */
  280. void obj_vline(objparm *pm)
  281. {
  282.   scale(pm->pd,pm->p,1);
  283.   if(pm->fill)
  284.     myDashedLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]);
  285.   else
  286.     gdImageLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]);
  287.   if (tikz_file)
  288.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  289.       tikz_options(pm->color[0],pm->fill),pm->p[0],0,pm->p[0],sizey);
  290. }
  291.  
  292. /* dashed line */
  293. void obj_dline(objparm *pm)
  294. {
  295.   scale(pm->pd,pm->p,2);
  296.   myDashedLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], pm->color[0]);
  297.   if (tikz_file)
  298.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  299.       tikz_options(pm->color[0],-1),
  300.       pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3]));
  301. }
  302.  
  303. /* parallel lines.
  304.  * x1,y1,x2,y2,xv,yv,n,color */
  305. void obj_parallel(objparm *pm)
  306. {
  307.   int i, n, xi,yi;
  308.   double xv,yv;
  309.   n=pm->pd[6]; if(n<0) return; if(n>256) n=256;
  310.   scale(pm->pd,pm->p,3);
  311.   scale2(pm->pd[4],pm->pd[5],&xv,&yv);
  312.   for(i=0;i<n;i++) {
  313.     xi=rint(i*xv); yi=rint(i*yv);
  314.     gdImageLine(image,pm->p[0]+xi,pm->p[1]+yi,pm->p[2]+xi,pm->p[3]+yi,
  315.               pm->color[0]);
  316.     if (tikz_file)
  317.       fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  318.         tikz_options(pm->color[0],pm->fill),
  319.         pm->p[0]+xi,flip(pm->p[1]+yi),pm->p[2]+xi,flip(pm->p[3]+yi));
  320.     if(vimg_enable) vimg_line(scale_buf[0]+i*(scale_buf[4]-transx),
  321.         scale_buf[1]+i*(scale_buf[5]-transy),
  322.         scale_buf[2]+i*(scale_buf[4]-transx),
  323.         scale_buf[3]+i*(scale_buf[5]-transy));
  324.   }
  325. }
  326.  
  327. /* rectangle */
  328. void obj_rect(objparm *pm)
  329. {
  330.   int x1,y1,x2,y2;
  331.   scale(pm->pd,pm->p,2);
  332.   x1=min(pm->p[0],pm->p[2]); x2=max(pm->p[0],pm->p[2]);
  333.   y1=min(pm->p[1],pm->p[3]); y2=max(pm->p[1],pm->p[3]);
  334.   if(pm->fill)
  335.     gdImageFilledRectangle(image,x1,y1,x2,y2,pm->color[0]);
  336.   else
  337.     gdImageRectangle(image,x1,y1,x2,y2,pm->color[0]);
  338.   if(tikz_file)
  339.     fprintf(tikz_file,
  340.       "\\draw\[%s] (%i,%i) rectangle (%i,%i);\n",
  341.       tikz_options(pm->color[0],pm->fill),x1,flip(y1),x2,flip(y2));
  342.   if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]);
  343. }
  344.  
  345. /* square */
  346. void obj_square(objparm *pm)
  347. {
  348.   int w,h;
  349.   scale(pm->pd,pm->p,1);
  350.   w=rint(pm->pd[2]); h=rint(pm->pd[2]);
  351.   if(pm->fill)
  352.     gdImageFilledRectangle(image,pm->p[0],pm->p[1],
  353.                pm->p[0]+w,pm->p[1]+h,pm->color[0]);
  354.   else
  355.     gdImageRectangle(image,pm->p[0],pm->p[1],
  356.                pm->p[0]+w,pm->p[1]+h,pm->color[0]);
  357.   if(tikz_file){
  358.     fprintf(tikz_file,
  359.       "\\draw\[%s] (%i,%i) rectangle (%i,%i);\n",
  360.       tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),
  361.       pm->p[0]+w,flip(pm->p[1]+h));
  362.   }
  363.   if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],
  364.                       scale_buf[0]+pm->pd[2],scale_buf[1]+pm->pd[2]);
  365. }
  366.  
  367. /* triangle */
  368. void obj_triangle(objparm *pm)
  369. {
  370.   scale(pm->pd,pm->p,3);
  371.   if(pm->fill)
  372.     gdImageFilledPolygon(image,(gdPointPtr) pm->p,3,pm->color[0]);
  373.   else
  374.     gdImagePolygon(image,(gdPointPtr) pm->p,3,pm->color[0]);
  375.   if (tikz_file)
  376.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i) -- (%i, %i) -- cycle;\n",
  377.       tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2],flip(pm->p[3]),pm->p[4],flip(pm->p[5]));
  378.   if(vimg_enable) vimg_polyline(scale_buf,3,1);
  379. }
  380.  
  381. /* polygon */
  382. void obj_poly(objparm *pm)
  383. {
  384.   int cnt,i;
  385.   cnt=(pm->pcnt)/2;
  386.   scale(pm->pd,pm->p,cnt);
  387.   if(pm->fill)
  388.     gdImageFilledPolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]);
  389.   else
  390.     gdImagePolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]);
  391.     if(tikz_file)
  392.       for (i= 0; i<cnt; i++)
  393.         fprintf(tikz_file,"\\draw\[%s] (%i,%i)--(%i,%i);\n",
  394.         tikz_options(pm->color[0],pm->fill),
  395.         pm->p[2*i],flip(pm->p[2*i+1]),
  396.         pm->p[2*((i+1)%cnt)],flip(pm->p[2*((i+1)%cnt)+1]));
  397.   if(vimg_enable) vimg_polyline(scale_buf,cnt,1);
  398. }
  399.  
  400. /* rays */
  401. void obj_rays(objparm *pm)
  402. {
  403.   int i, n;
  404.   n=(pm->pcnt)/2;
  405.   scale(pm->pd,pm->p,n);
  406.   for(i=2;i<2*n;i+=2) {
  407.     gdImageLine(image,pm->p[0],pm->p[1],pm->p[i],pm->p[i+1],pm->color[0]);
  408.     if (tikz_file)
  409.       fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  410.         tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[i],flip(pm->p[i+1]));
  411.     if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],
  412.                         scale_buf[i],scale_buf[i+1]);
  413.   }
  414. }
  415. /* crosshair */
  416. void obj_crosshair(objparm *pm)
  417. {
  418.   scale(pm->pd,pm->p,2);
  419.   gdImageLine(image,pm->p[0]+width2,pm->p[1]+width2,pm->p[0]-width2,pm->p[1]-width2,pm->color[0]);
  420.   gdImageLine(image,pm->p[0]-width2,pm->p[1]+width2,pm->p[0]+width2,pm->p[1]-width2,pm->color[0]);
  421.   if (tikz_file){
  422.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  423.       tikz_options(pm->color[0],pm->fill),pm->p[0]+width2,flip(pm->p[1]+width2),pm->p[0]-width2,flip(pm->p[1]-width2));
  424.     fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  425.       tikz_options(pm->color[0],pm->fill),pm->p[0]-width2,flip(pm->p[1]+width2),pm->p[0]+width2,flip(pm->p[1]-width2));
  426.   }
  427. }
  428. /* crosshairs */
  429.  
  430. void obj_crosshairs(objparm *pm)
  431. {
  432.   int i, n;
  433.   n=(pm->pcnt)/2;
  434.   scale(pm->pd,pm->p,n);
  435.   for(i=0;i<2*n;i+=2) {
  436.     gdImageLine(image,pm->p[i]+width2,pm->p[i+1]+width2,pm->p[i]-width2,pm->p[i+1]-width2,pm->color[0]);
  437.     gdImageLine(image,pm->p[i]-width2,pm->p[i+1]+width2,pm->p[i]+width2,pm->p[i+1]-width2,pm->color[0]);
  438.     if (tikz_file){
  439.       fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  440.         tikz_options(pm->color[0],pm->fill),pm->p[i]+width2,flip(pm->p[i+1]+width2),pm->p[i]-width2,flip(pm->p[i+1]-width2));
  441.       fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  442.         tikz_options(pm->color[0],pm->fill),pm->p[i]-width2,flip(pm->p[i+1]+width2),pm->p[i]+width2,flip(pm->p[i+1]-width2));
  443.     }
  444.   }
  445. }
  446.  
  447.  
  448. /* segments */
  449. void obj_lines(objparm *pm)
  450. {
  451.   int i, n;
  452.   n=(pm->pcnt)/2;
  453.   scale(pm->pd,pm->p,n);
  454.   for(i=2;i<2*n;i+=2){
  455.     gdImageLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]);
  456.     if (tikz_file){
  457.       fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  458.         tikz_options(pm->color[0],pm->fill),pm->p[i-2],flip(pm->p[i-1]),pm->p[i],flip(pm->p[i+1]));
  459.     }
  460.     if(vimg_enable) vimg_polyline(scale_buf,n,0);
  461.   }
  462. }
  463. /*segments from x1,y1 to x2,y2, x3,y3 to x4,y4, etc */
  464. void obj_segments(objparm *pm)
  465. {
  466.   int i, n;
  467.   n=(pm->pcnt)/4;
  468.   scale(pm->pd,pm->p,2*n);
  469.   for(i=0;i<4*n;i+=4){
  470.     gdImageLine(image,pm->p[i],pm->p[i+1],pm->p[i+2],pm->p[i+3],pm->color[0]);
  471.     if (tikz_file){
  472.       fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  473.         tikz_options(pm->color[0],pm->fill),pm->p[i],flip(pm->p[i+1]),pm->p[i+2],flip(pm->p[i+3]));
  474.     }
  475.   }
  476. }
  477. /* segments */
  478. void obj_dlines(objparm *pm)
  479. {
  480.   int i, n;
  481.   n=(pm->pcnt)/2;
  482.   scale(pm->pd,pm->p,n);
  483.   for(i=2;i<2*n;i+=2)
  484.     myDashedLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]);
  485.     if (tikz_file){
  486.       fprintf(tikz_file, "\\draw\[%s] (%i, %i) -- (%i, %i);\n",
  487.         tikz_options(pm->color[0],pm->fill),pm->p[i-2],flip(pm->p[i-1]),pm->p[i],flip(pm->p[i+1]));
  488.     }
  489.   if(vimg_enable) vimg_polyline(scale_buf,n,0);
  490. }
  491.  
  492. /* points */
  493. void obj_points(objparm *pm)
  494. {
  495.   int i, n;
  496.   n=(pm->pcnt)/2;
  497.   scale(pm->pd,pm->p,n);
  498.   for(i=0;i<2*n;i+=2){
  499.     gdImageSetPixel(image,pm->p[i],pm->p[i+1],pm->color[0]);
  500.     if(tikz_file) fprintf(tikz_file, "\\draw\[%s] (%i, %i) circle (0pt);\n",
  501.       tikz_options(pm->color[0],pm->fill),pm->p[i],flip(pm->p[i+1]));
  502.   }
  503. }
  504.  
  505. /* lattice.
  506.  * x0,y0,xv1,yv1,xv2,yv2,n1,n2,color */
  507. void obj_lattice(objparm *pm)
  508. {
  509.   int n1,n2,i1,i2,xi1,yi1,xi2,yi2;
  510.   double xv1,xv2,yv1,yv2;
  511.   n1=pm->pd[6];n2=pm->pd[7]; if(n1<0 || n2<0) return;
  512.   if(n1>256) n1=256;
  513.   if(n2>256) n2=256;
  514.   scale(pm->pd,pm->p,1);
  515.   scale2(pm->pd[2],pm->pd[3],&xv1,&yv1);
  516.   scale2(pm->pd[4],pm->pd[5],&xv2,&yv2);
  517.   for(i1=0;i1<n1;i1++) {
  518.     xi1=rint(i1*xv1)+pm->p[0]; yi1=rint(i1*yv1)+pm->p[1];
  519.     for(i2=0;i2<n2;i2++) {
  520.       xi2=i2*xv2+xi1;yi2=i2*yv2+yi1;
  521.       gdImageSetPixel(image,xi2,yi2,pm->color[0]);
  522.       if(tikz_file) fprintf(tikz_file,"\\draw[%s] (%i,%i) circle (0pt);\n",
  523.         tikz_options(pm->color[0],0),xi2,flip(yi2));
  524.     }
  525.   }
  526. }
  527.  
  528. /* arc */
  529. void obj_arc(objparm *pm)
  530. {
  531.   scale(pm->pd,pm->p,1);
  532.   pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale);
  533.   gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],
  534.            pm->pd[4],pm->pd[5],pm->color[0]);
  535.   if(tikz_file) {
  536.       fprintf(tikz_file,
  537.     "\\draw\[%s, domain=%f:%f] plot ({%i+%f*cos(\\x)}, {%i+%f*sin(\\x)});\n",
  538.     tikz_options(pm->color[0],pm->fill),
  539.       pm->pd[4],pm->pd[5],pm->p[0],pm->p[2]*0.5,flip(pm->p[1]),pm->p[3]*(-0.5));
  540.   }
  541.   /*FIXME echelle mauvaise*/
  542.   if(vimg_enable) vimg_arc(scale_buf[0],scale_buf[1],
  543.                      0.5*pm->pd[2],0.5*pm->pd[3],pm->pd[4],pm->pd[5]);
  544. }
  545.  
  546. /* Ellipse: centre 0,1, width 2, hight 3, color 4,5,6 */
  547. void obj_ellipse(objparm *pm)
  548. {
  549.   scale(pm->pd,pm->p,1);
  550.   pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale);
  551.   if(pm->fill) {
  552.     gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,
  553.              color_bounder);
  554.     patchgdImageFillToBorder(image,pm->p[0],pm->p[1],
  555.                     color_bounder,pm->color[0]);
  556.   }
  557.   gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]);
  558.   if(tikz_file) fprintf(tikz_file,"\\draw\[%s] (%i,%i) ellipse (%f and %f);\n\n",
  559.     tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2]/2.,pm->p[3]/2.);
  560.   if(vimg_enable) vimg_ellipse(scale_buf[0],scale_buf[1],0.5*pm->pd[2],0.5*pm->pd[3]);
  561. }
  562.  
  563. /* Circle */
  564. void obj_circle(objparm *pm)
  565. {
  566.   scale(pm->pd,pm->p,1);
  567.   pm->p[2]=rint(pm->pd[2]); pm->p[3]=rint(pm->pd[2]);
  568.   if(pm->fill) {
  569.     gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,
  570.              color_bounder);
  571.     patchgdImageFillToBorder(image,pm->p[0],pm->p[1],
  572.                     color_bounder,pm->color[0]);
  573.   }
  574.   gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]);
  575.   if(tikz_file) fprintf(tikz_file, "\\draw\[%s] (%i, %i) circle (%f);\n",
  576.       tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),pm->p[2]/2.);
  577. }
  578.  
  579. /* flood fill */
  580. void obj_fill(objparm *pm)
  581. {
  582.   scale(pm->pd,pm->p,1);
  583.   patchgdImageFill(image,pm->p[0],pm->p[1],pm->color[0]);
  584. }
  585.  
  586. /* flood fill to border*/
  587. void obj_fillb(objparm *pm)
  588. {
  589.   scale(pm->pd,pm->p,1);
  590.   patchgdImageFillToBorder(image,pm->p[0],pm->p[1],pm->color[0],pm->color[1]);
  591. }
  592.  
  593. gdImagePtr himg;
  594.  
  595. int makehatchimage(int x, int y, int px, int py, int col)
  596. {
  597.   int c1,c2,r,g,b;
  598.   gdImagePtr saveimg;
  599.   himg=gdImageCreate(x,y);
  600.   c1=gdImageGetPixel(image,px,py);
  601.   r=gdImageRed(image,c1); g=gdImageGreen(image,c1); b=gdImageBlue(image,c1);
  602.   if(r>=255) r--; else r++; if(g>=255) g--; else g++; if(b>=255) b--; else b++;
  603.   c1=gdImageColorAllocate(himg,r,g,b);
  604.   r=gdImageRed(image,col); g=gdImageGreen(image,col); b=gdImageBlue(image,col);
  605.   c2=gdImageColorAllocate(himg,r,g,b);
  606.   if(width>1) {
  607.     savew=-1; saveimg=image;
  608.     image=himg; c2=widthcolor(width,c2); image=saveimg;
  609.     c2=gdBrushed; savew=-1;
  610.   }
  611.   return c2;
  612. }
  613.  
  614. /* flood fill with hatching */
  615. void obj_hatchfill(objparm *pm)
  616. {
  617.   int nx,ny,ax,ay, dir, c;
  618.   scale(pm->pd,pm->p,1);
  619.   nx=pm->pd[2]; ny=pm->pd[3]; ax=abs(nx); ay=abs(ny);
  620.   if(nx==0 && ny==0) {fly_error("bad displacement vector"); return;}
  621.   if((nx>0 && ny>0) || (nx<0 && ny<0)) dir=1; else dir=-1;
  622.   if(ax==0) {ax=100; dir=2;}
  623.   if(ay==0) {ay=100; dir=3;}
  624.   c=makehatchimage(ax,ay,pm->p[0],pm->p[1],pm->color[0]);
  625.   switch(dir) {
  626.     case -1: {
  627.       gdImageLine(himg,0,ay-1,ax-1,0,c);
  628.       if(width>1) {
  629.         gdImageLine(himg,-ax,ay-1,-1,0,c);
  630.         gdImageLine(himg,ax,ay-1,2*ax-1,0,c);
  631.         gdImageLine(himg,0,-1,ax-1,-ay,c);
  632.         gdImageLine(himg,0,2*ay-1,ax-1,ay,c);
  633.       }
  634.       break;
  635.     }
  636.     case 1: {
  637.       gdImageLine(himg,0,0,ax-1,ay-1,c);
  638.       if(width>1) {
  639.         gdImageLine(himg,-ax,0,-1,ay-1,c);
  640.         gdImageLine(himg,ax,0,2*ax-1,ay-1,c);
  641.         gdImageLine(himg,0,-ay,ax-1,-1,c);
  642.         gdImageLine(himg,0,ay,ax-1,2*ay-1,c);
  643.       }
  644.       break;
  645.     }
  646.     case 2: gdImageLine(himg,0,ay/2,ax-1,ay/2,c); break;
  647.     case 3: gdImageLine(himg,ax/2,0,ax/2,ay-1,c); break;
  648.   }
  649.   gdImageSetTile(image,himg);
  650.   patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
  651.   gdImageDestroy(himg);
  652.   if(tiled) gdImageSetTile(image,tileimg);
  653. }
  654.  
  655. /* flood fill with grid */
  656. void obj_gridfill(objparm *pm)
  657. {
  658.   int nx,ny, c;
  659.   scale(pm->pd,pm->p,1);
  660.   nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny);
  661.   if(nx==0 && ny==0) {fly_error("bad grid size"); return;}
  662.   c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]);
  663.   gdImageLine(himg,0,ny/2,nx-1,ny/2,c); gdImageLine(himg,nx/2,0,nx/2,ny-1,c);
  664.   gdImageSetTile(image,himg);
  665.   patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
  666.   gdImageDestroy(himg);
  667.   if(tiled) gdImageSetTile(image,tileimg);
  668. }
  669.  
  670. /* flood fill with double hatching */
  671. void obj_diafill(objparm *pm)
  672. {
  673.   int nx,ny, c;
  674.   scale(pm->pd,pm->p,1);
  675.   nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny);
  676.   if(nx==0 && ny==0) {fly_error("bad grid size"); return;}
  677.   c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]);
  678.   gdImageLine(himg,0,0,nx-1,ny-1,c); gdImageLine(himg,0,ny-1,nx-1,0,c);
  679.   gdImageSetTile(image,himg);
  680.   patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
  681.   gdImageDestroy(himg);
  682.   if(tiled) gdImageSetTile(image,tileimg);
  683. }
  684.  
  685. /* flood fill with double hatching */
  686. void obj_dotfill(objparm *pm)
  687. {
  688.   int nx,ny, c;
  689.   scale(pm->pd,pm->p,1);
  690.   nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny);
  691.   if(nx==0 && ny==0) {fly_error("bad grid size"); return;}
  692.   c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]);
  693.   gdImageSetPixel(himg,nx/2,ny/2,c);
  694.   gdImageSetTile(image,himg);
  695.   patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
  696.   gdImageDestroy(himg);
  697.   if(tiled) gdImageSetTile(image,tileimg);
  698. }
  699.  
  700. struct {
  701.   char *name;
  702.   gdFontPtr *fpt;
  703. } fonttab[]={
  704.   {"tiny",      &gdFontTiny},
  705.   {"small",      &gdFontSmall},
  706.   {"medium",&gdFontMediumBold},
  707.   {"large",      &gdFontLarge},
  708.   {"giant",      &gdFontGiant},
  709.   {"huge",      &gdFontGiant}
  710. };
  711.  
  712. #define fonttab_no (sizeof(fonttab)/sizeof(fonttab[0]))
  713.  
  714. /* string */
  715. void obj_string(objparm *pm)
  716. {
  717.   char *pp, *pe, *p2;
  718.   int i;
  719.   pp=pm->str; pe=strchr(pp,','); if(pe==NULL) {
  720.     fly_error("too_few_parms"); return;
  721.   }
  722.   *pe++=0; pp=find_word_start(pp); *find_word_end(pp)=0;
  723.   pe=find_word_start(pe); strip_trailing_spaces(pe);
  724.   if(*pp) {
  725.     for(i=0;i<fonttab_no && strcmp(pp,fonttab[i].name)!=0; i++);
  726.     if(i>=fonttab_no) i=1;
  727.   }
  728.   else i=1;
  729.   scale(pm->pd,pm->p,1);
  730.   if(*pe=='"') {
  731.     p2=strchr(pe+1,'"');
  732.     if(p2 && *(p2+1)==0) {*p2=0; pe++;}
  733.   }
  734.   if(pm->fill){
  735.     gdImageStringUp(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
  736.         pm->color[0]);
  737.     if(tikz_file) fprintf(tikz_file,"\\draw[%s] (%i,%i) node[font=\\%s,rotate=90] {%s};\n",
  738.       tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),fonttab[i].name,(unsigned char*) pe);
  739.   }
  740.   else {
  741.     gdImageString(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
  742.         pm->color[0]);
  743.     if(tikz_file) fprintf(tikz_file,"\\draw[%s] (%i,%i) node[font=\\%s] {%s};\n",
  744.       tikz_options(pm->color[0],pm->fill),pm->p[0],flip(pm->p[1]),fonttab[i].name,(unsigned char*) pe);
  745.   }
  746. }
  747. /*FIXME; giant does not exist in tikz and ... samething as huge */
  748. /* point */
  749. void obj_point(objparm *pm)
  750. {
  751.   scale(pm->pd,pm->p,1);
  752.   gdImageSetPixel(image,pm->p[0],pm->p[1],pm->color[0]);
  753.   if(tikz_file) fprintf(tikz_file,"\\draw[%s] (%i,%i) circle (0pt);\n",
  754.     tikz_options(pm->color[0],0),pm->p[0],flip(pm->p[1]));
  755. }
  756.  
  757. /* copy an image file */
  758. void obj_copy(objparm *pm)
  759. {
  760.   char *pp;
  761.   FILE *inf;
  762.   gdImagePtr insimg;
  763.  
  764.   pp=find_word_start(pm->str);*find_word_end(pp)=0;
  765.   inf=open4read(pp);
  766.   if(inf==NULL) {
  767.     fly_error("file_not_exist"); return;
  768.   }
  769.   insimg=gdImageCreateFromGif(inf); fclose(inf);
  770.   if(insimg==NULL) {
  771.     fly_error("bad_gif"); return;
  772.   }
  773.   scale(pm->pd,pm->p,1);
  774.   if(pm->pd[2]<0 && pm->pd[3]<0 && pm->pd[4]<0 && pm->pd[5]<0)
  775.     gdImageCopy(image,insimg,pm->p[0],pm->p[1],0,0,
  776.             insimg->sx,insimg->sy);
  777.   else
  778.     gdImageCopy(image,insimg,pm->p[0],pm->p[1],pm->pd[2],pm->pd[3],
  779.             pm->pd[4]-pm->pd[2],pm->pd[5]-pm->pd[3]);
  780.   gdImageDestroy(insimg);
  781. }
  782.  
  783. /* copy an image file, with resizing */
  784. void obj_copyresize(objparm *pm)
  785. {
  786.   char *pp;
  787.   FILE *inf;
  788.   gdImagePtr insimg;
  789.  
  790.   pp=find_word_start(pm->str);*find_word_end(pp)=0;
  791.   inf=open4read(pp);
  792.   if(inf==NULL) {
  793.     fly_error("file_not_found"); return;
  794.   }
  795.   insimg=gdImageCreateFromGif(inf); fclose(inf);
  796.   if(insimg==NULL) {
  797.     fly_error("bad_gif"); return;
  798.   }
  799.   scale(pm->pd+4,pm->p+4,2);
  800.   if(pm->pd[0]<0 && pm->pd[1]<0 && pm->pd[2]<0 && pm->pd[3]<0)
  801.     gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],0,0,
  802.                  pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1,
  803.                  insimg->sx,insimg->sy);
  804.   else
  805.     gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],pm->pd[0],pm->pd[1],
  806.                  pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1,
  807.                  pm->pd[2]-pm->pd[0]+1,pm->pd[3]-pm->pd[1]+1);
  808.   gdImageDestroy(insimg);
  809. }
  810.  
  811. /* set brush or tile */
  812. void obj_setbrush(objparm *pm)
  813. {
  814.   char *pp;
  815.   FILE *inf;
  816.   gdImagePtr insimg;
  817.  
  818.   pp=find_word_start(pm->str); *find_word_end(pp)=0;
  819.   inf=open4read(pp); if(inf==NULL) {
  820.     fly_error("file_not_found"); return;
  821.   }
  822.   insimg=gdImageCreateFromGif(inf); fclose(inf);
  823.   if(insimg==NULL) {
  824.     fly_error("bad_gif"); return;
  825.   }
  826.   if(pm->fill) {
  827.     gdImageSetTile(image,insimg); tiled=1; tileimg=insimg;
  828.   }
  829.   else {
  830.     gdImageSetBrush(image,insimg);brushed=1; brushimg=insimg;
  831.   }
  832. }
  833.  
  834. /* kill brush */
  835. void obj_killbrush(objparm *pm)
  836. {
  837.   if(brushimg) gdImageDestroy(brushimg);
  838.   brushed=0; brushimg=NULL;
  839. }
  840.  
  841. /* kill tile */
  842. void obj_killtile(objparm *pm)
  843. {
  844.   if(tileimg) gdImageDestroy(tileimg);
  845.   tiled=0; tileimg=NULL;
  846. }
  847.  
  848. /* set style */
  849. void obj_setstyle(objparm *pm)
  850. {
  851.   int i,t;
  852.   t=pm->pcnt/3; if(t<=0) {
  853.     fly_error("too_few_parms"); return;
  854.   }
  855.   for(i=0;i<t;i++) {
  856.     if(pm->pd[3*i]<0 || pm->pd[3*i+1]<0 || pm->pd[3*i+2]<0)
  857.       pm->p[i]=gdTransparent;
  858.     else
  859.       pm->p[i]=getcolor(pm->pd[3*i],pm->pd[3*i+1],pm->pd[3*i+2]);
  860.   }
  861.   gdImageSetStyle(image,pm->p,t); styled=1;
  862. }
  863.  
  864. /* kill style */
  865. void obj_killstyle(objparm *pm)
  866. {
  867.   styled=0;
  868. }
  869.  
  870. /* set transparent */
  871. void obj_transp(objparm *pm)
  872. {
  873.   gdImageColorTransparent(image,pm->color[0]);
  874. }
  875.  
  876. /* set interlace */
  877. void obj_interlace(objparm *pm)
  878. {
  879.   gdImageInterlace(image,1);
  880. }
  881.  
  882. /* set linewidth */
  883. void obj_linewidth(objparm *pm)
  884. {
  885.   if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms");
  886.   width=pm->pd[0];
  887.   if(tikz_file) fprintf(tikz_file,"\\pgfsetlinewidth{%f}\n",width*0.7);
  888. }
  889.  
  890. /* set crosshairsize */
  891. void obj_crosshairsize(objparm *pm)
  892. {
  893.   if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms");
  894.   else width2=pm->pd[0];
  895. }
  896.  
  897. /* set x range */
  898. void obj_xrange(objparm *pm)
  899. {
  900.   double dd;
  901.   dd=pm->pd[1]-pm->pd[0];
  902.   xstart=pm->pd[0]; xscale=sizex/dd;
  903. }
  904.  
  905. /* set y range */
  906. void obj_yrange(objparm *pm)
  907. {
  908.   double dd;
  909.   dd=pm->pd[1]-pm->pd[0];
  910.   ystart=pm->pd[1]; yscale=-sizey/dd;
  911. }
  912.  
  913. /* set x et y range */
  914. void obj_range(objparm *pm)
  915. {
  916.   double d1,d2;
  917.   d1=pm->pd[1]-pm->pd[0]; d2=pm->pd[3]-pm->pd[2];
  918.   xstart=pm->pd[0]; xscale=(sizex-1)/d1;
  919.   ystart=pm->pd[3]; yscale=-(sizey-1)/d2;
  920. }
  921.  
  922. /* set t range */
  923. void obj_trange(objparm *pm)
  924. {
  925.   /*double dd;
  926.   dd=pm->pd[1]-pm->pd[0];*/
  927.   tstart=pm->pd[0]; tend=pm->pd[1];
  928.   tranged=1;
  929. }
  930.  
  931. /* set tstep (plotting step) */
  932. void obj_tstep(objparm *pm)
  933. {
  934.   int dd;
  935.   dd=pm->pd[0];
  936.   if(dd<3) {
  937.     fly_error("bad_step"); return;
  938.   }
  939.   if(dd>2000) dd=2000;
  940.   tstep=dd;
  941. }
  942.  
  943. /* set plotjump (plot jump break threashold) */
  944. void obj_plotjump(objparm *pm)
  945. {
  946.   int dd;
  947.   dd=pm->pd[0];
  948.   if(dd<3) dd=3;
  949.   if(dd>MAX_SIZE) dd=MAX_SIZE;
  950.   plotjump=dd;
  951. }
  952.  
  953. /* plot a curve, either parametric or explicit */
  954. void _obj_plot(objparm *pm,int dash)
  955. {
  956.   int i,j,n,dist,xx,yy,varpos;
  957.   char p1[MAX_LINELEN+1], p2[MAX_LINELEN+1];
  958.   char *varn, *pp;
  959.   double dc[2],t,v;
  960.   int ic[2],oc[2];
  961.  
  962.   n=itemnum(pm->str);
  963.   if(n<1) {
  964.     fly_error("bad_parms"); return;
  965.   }
  966.   fnd_item(pm->str,1,p1); fnd_item(pm->str,2,p2);
  967.   if(n==1 && !tranged) v=sizex/xscale/tstep;
  968.   else v=(tend-tstart)/tstep;
  969.   if(n==1) varn="x"; else varn="t";
  970.   for(pp=varchr(p1,varn); pp; pp=varchr(pp,varn)) {
  971.     string_modify(p1,pp,pp+strlen(varn),EV_T);
  972.     pp+=strlen(EV_T);
  973.   }
  974.   for(pp=varchr(p2,varn); pp; pp=varchr(pp,varn)) {
  975.     string_modify(p2,pp,pp+strlen(varn),EV_T);
  976.       pp+=strlen(EV_T);
  977.   }
  978.   varpos=eval_getpos(EV_T);
  979.   if(varpos<0) return; /* unknown error */
  980.   evalue_compile(p1); evalue_compile(p2);
  981.   if(vimg_enable) vimg_plotstart();
  982.   for(i=j=0;i<=tstep;i++) {
  983.     if(n==1) {
  984.       if(tranged) t=tstart+i*v; else t=xstart+i*v;
  985.       eval_setval(varpos,t); dc[0]=t; dc[1]=strevalue(p1);
  986.     }
  987.       else {
  988.         t=tstart+i*v; eval_setval(varpos,t);
  989.         dc[0]=strevalue(p1); dc[1]=strevalue(p2);
  990.     }
  991.       if(!isfinite(dc[0]) || !isfinite(dc[1])) ic[0]=ic[1]=-BOUND;
  992.       else scale(dc,ic,1);
  993.       if(vimg_enable) vimg_plot1 (scale_buf[0],scale_buf[1]);
  994.       if(j==0) {
  995.         gdImageSetPixel(image,ic[0],ic[1],pm->color[0]); j++;
  996.         if (tikz_file)
  997.           fprintf(tikz_file,
  998.             "\\draw\[%s] (%i,%i) rectangle (%i,%i);\n",
  999.             tikz_options(pm->color[0],1),ic[0],flip(ic[1]),ic[0]+1,flip(ic[1]+1));
  1000.        }
  1001.       else {
  1002.         xx=ic[0]-oc[0]; yy=ic[1]-oc[1];
  1003.         dist=sqrt(xx*xx+yy*yy);
  1004.         if(dist>0){
  1005.           if(dist>plotjump || dist==1) {
  1006.             gdImageSetPixel(image,ic[0],ic[1],pm->color[0]);
  1007.             if (tikz_file)
  1008.               fprintf(tikz_file,
  1009.                 "\\draw\[%s] (%i,%i) rectangle (%i,%i);\n",
  1010.                 tikz_options(pm->color[0],1),ic[0],flip(ic[1]),ic[0]+1,flip(ic[1]+1));
  1011.           }
  1012.           }
  1013.           else {
  1014.             if ( dash==1)
  1015.               gdImageDashedLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]);
  1016.             else
  1017.               gdImageLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]);
  1018.             if (tikz_file)
  1019.               fprintf(tikz_file,
  1020.                 "\\draw\[%s] (%i,%i) -- (%i,%i);\n",
  1021.                 tikz_options(pm->color[0],dash),oc[0],flip(oc[1]),ic[0],flip(ic[1]));
  1022.  
  1023.           }
  1024.         }
  1025.     memmove(oc,ic,sizeof(oc));
  1026.   }
  1027.   if(vimg_enable) vimg_plotend();
  1028. }
  1029.  
  1030. void obj_plot(objparm *pm) { _obj_plot( pm,0) ;}
  1031. void obj_dplot(objparm *pm) { _obj_plot( pm,1) ; }
  1032.  
  1033. /* set levelcurve granularity */
  1034. void obj_levelstep(objparm *pm)
  1035. {
  1036.   int dd;
  1037.   dd=pm->pd[0];
  1038.   if(dd<1) return;
  1039.   if(dd>16) dd=16;
  1040.   lstep=dd;
  1041. }
  1042.  
  1043. /* level curve */
  1044. void obj_levelcurve(objparm *pm)
  1045. {
  1046.   char fn[MAX_LINELEN+1],tc[MAX_LINELEN+1];
  1047.   int n,i;
  1048.   double d;
  1049.   leveldata *ld;
  1050.  
  1051.   ld=xmalloc(sizeof(leveldata)+16);
  1052.   ld->xname="x"; ld->yname="y";
  1053.   ld->xsize=sizex; ld->ysize=sizey; ld->datacnt=0;
  1054.   ld->xrange[0]=xstart; ld->xrange[1]=sizex/xscale+xstart;
  1055.   ld->yrange[0]=sizey/yscale+ystart; ld->yrange[1]=ystart;
  1056.   ld->grain=lstep;
  1057.   fnd_item(pm->str,1,fn); ld->fn=fn;
  1058.   n=itemnum(pm->str);
  1059.   if(n<=1) {ld->levelcnt=1; ld->levels[0]=0;}
  1060.   else {
  1061.     if(n>LEVEL_LIM+1) n=LEVEL_LIM+1;
  1062.     for(i=0;i<n-1;i++) {
  1063.       fnd_item(pm->str,i+2,tc);
  1064.       d=strevalue(tc);
  1065.       if(isfinite(d)) ld->levels[i]=d; else ld->levels[i]=0;
  1066.     }
  1067.     ld->levelcnt=n-1;
  1068.   }
  1069.   levelcurve(ld);
  1070.   for(i=0;i<ld->datacnt;i++) {
  1071.     gdImageSetPixel(image,ld->xdata[i],ld->ydata[i],pm->color[0]);
  1072.     if (tikz_file)
  1073.       fprintf(tikz_file,
  1074.         "\\draw\[%s] (%i,%i) rectangle (%i,%i);\n",
  1075.         tikz_options(pm->color[0],1),ld->xdata[i],flip(ld->ydata[i]),ld->xdata[i]+1,flip(ld->ydata[i]+1));
  1076.   }
  1077.   free(ld);
  1078. }
  1079.  
  1080. /* set animation step */
  1081. void obj_animstep(objparm *pm)
  1082. {
  1083.   animstep=pm->pd[0];
  1084.   setvar("animstep",pm->pd[0]);
  1085. }
  1086.  
  1087. /* Starts a line counting */
  1088. void obj_linecount(objparm *pm)
  1089. {
  1090.   linecnt=pm->pd[0];
  1091. }
  1092.  
  1093. /* marks end of execution */
  1094. void obj_end(objparm *pm)
  1095. {
  1096.   fly_error("successful_end_of_execution");
  1097. }
  1098.  
  1099. /* output */
  1100. void obj_output(objparm *pm)
  1101. {
  1102.   char *p, namebuf[1024];
  1103.   p=find_word_start(pm->str); *find_word_end(p)=0;
  1104.   snprintf(namebuf,sizeof(namebuf),"%s",imagefilename);
  1105.   snprintf(imagefilename,sizeof(imagefilename),"%s",p);
  1106.   output();
  1107.   snprintf(imagefilename,sizeof(imagefilename),"%s",namebuf);
  1108. }
  1109.  
  1110. /* vimgfile */
  1111. void obj_vimgfile(objparm *pm)
  1112. {
  1113.   char *p;
  1114.   p=find_word_start(pm->str); *find_word_end(p)=0;
  1115.   snprintf(vimgfilename,sizeof(vimgfilename),"%s",p);
  1116.   if(vimg_ready) vimg_close();
  1117. }
  1118.  
  1119. /* vimg enable/disable */
  1120. void obj_vimg(objparm *pm)
  1121. {
  1122.   vimg_enable=pm->pd[0];
  1123.   if(vimg_enable>0 && vimg_ready==0) vimg_init();
  1124. }
  1125.  
  1126. /* Set affine transformation */
  1127. void obj_affine(objparm *pm)
  1128. {
  1129.   int i;
  1130.   for(i=0;i<4;i++) matrix[i]=pm->pd[i];
  1131.   transx=pm->pd[4]; transy=pm->pd[5];
  1132.   transform=1;
  1133. }
  1134.  
  1135. /* Set affine transformation */
  1136. void obj_rotation(objparm *pm)
  1137. {
  1138.   double r;
  1139.   r=M_PI*pm->pd[0]/180;
  1140.   matrix[0]=matrix[3]=cos(r);
  1141.   matrix[1]=-sin(r); matrix[2]=sin(r);
  1142.   transform=1;
  1143. }
  1144.  
  1145. /* Set linear transformation */
  1146. void obj_linear(objparm *pm)
  1147. {
  1148.   int i;
  1149.   for(i=0;i<4;i++) matrix[i]=pm->pd[i];
  1150.   transform=1;
  1151. }
  1152.  
  1153. /* Set translation transformation */
  1154. void obj_translation(objparm *pm)
  1155. {
  1156.   transx=pm->pd[0]; transy=pm->pd[1];
  1157. }
  1158.  
  1159. /* kill affine transformation */
  1160. void obj_killaffine(objparm *pm)
  1161. {
  1162.   matrix[0]=matrix[3]=1;
  1163.   matrix[1]=matrix[2]=transx=transy=0;
  1164.   transform=0;
  1165. }
  1166.  
  1167. /* kill affine transformation */
  1168. void obj_killlinear(objparm *pm)
  1169. {
  1170.   matrix[0]=matrix[3]=1;
  1171.   matrix[1]=matrix[2]=0;
  1172.   transform=0;
  1173. }
  1174.  
  1175. /* kill affine transformation */
  1176. void obj_killtranslation(objparm *pm)
  1177. {
  1178.   transx=transy=0;
  1179. }
  1180.  
  1181. /***** Les modifs de Jean-Christophe Leger Fev 2006 *****/
  1182.  
  1183. /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES, une liste de 4 nombres reels pour la matrice */
  1184. void obj_setmatrix(objparm *pm)
  1185. {
  1186.   int nummatrix = (int) (pm->pd[0]);
  1187.   if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
  1188.     fly_error("bad_matrix_number");
  1189.     return;
  1190.   }
  1191.   matrices_pavage[nummatrix][0] = pm->pd[1];
  1192.   matrices_pavage[nummatrix][1] = pm->pd[2];
  1193.   matrices_pavage[nummatrix][2] = pm->pd[3];
  1194.   matrices_pavage[nummatrix][3] = pm->pd[4];
  1195. }
  1196.  
  1197. /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */
  1198. void obj_resetmatrix(objparm *pm)
  1199. {
  1200.   int nummatrix = (int) (pm->pd[0]);
  1201.   if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
  1202.     fly_error("bad_matrix_number");
  1203.     return;
  1204.   }
  1205.   matrices_pavage[nummatrix][0] = 1;
  1206.   matrices_pavage[nummatrix][1] = 0;
  1207.   matrices_pavage[nummatrix][2] = 0;
  1208.   matrices_pavage[nummatrix][3] = 1;
  1209.  
  1210. }
  1211. /* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 2 nombres reels pour le vecteur */
  1212. void obj_setvector(objparm *pm)
  1213. {
  1214.   int nummatrix = (int) (pm->pd[0]);
  1215.   if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
  1216.     fly_error("bad_vector_number");
  1217.     return;
  1218.   }
  1219.   vecteurs_pavage[nummatrix][0] = pm->pd[1];
  1220.   vecteurs_pavage[nummatrix][1] = pm->pd[2];
  1221. }
  1222.  
  1223. /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */
  1224. void obj_resetvector(objparm *pm)
  1225. {
  1226.   int nummatrix = (int) (pm->pd[0]);
  1227.   if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
  1228.     fly_error("bad_vector_number");
  1229.     return;
  1230.   }
  1231.   vecteurs_pavage[nummatrix][0] = 0;
  1232.   vecteurs_pavage[nummatrix][1] = 0;
  1233. }
  1234.  
  1235. /* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 6 nombres reels pour la matrice et le vecteur */
  1236. void obj_settransform(objparm *pm)
  1237. {
  1238.   int nummatrix = (int) (pm->pd[0]);
  1239.   if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
  1240.     fly_error("bad_vector_number");
  1241.     return;
  1242.   }
  1243.   matrices_pavage[nummatrix][0] = pm->pd[1];
  1244.   matrices_pavage[nummatrix][1] = pm->pd[2];
  1245.   matrices_pavage[nummatrix][2] = pm->pd[3];
  1246.   matrices_pavage[nummatrix][3] = pm->pd[4];
  1247.   vecteurs_pavage[nummatrix][0] = pm->pd[5];
  1248.   vecteurs_pavage[nummatrix][1] = pm->pd[6];
  1249. }
  1250.  
  1251.  
  1252. /* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */
  1253. void obj_resettransform(objparm *pm)
  1254. {
  1255.   int nummatrix = (int) (pm->pd[0]);
  1256.   if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
  1257.     fly_error("bad_vector_number");
  1258.     return;
  1259.   }
  1260.   vecteurs_pavage[nummatrix][0] = 0;
  1261.   vecteurs_pavage[nummatrix][1] = 0;
  1262.   matrices_pavage[nummatrix][0] = 1;
  1263.   matrices_pavage[nummatrix][1] = 0;
  1264.   matrices_pavage[nummatrix][2] = 0;
  1265.   matrices_pavage[nummatrix][3] = 1;
  1266. }
  1267.  
  1268. /* arguments: une liste de 6 nombres reels pour les coordonnees de l'origine et des vecteurs de base */
  1269. void obj_setparallelogram(objparm *pm)
  1270. {
  1271.   int i;
  1272.   for(i=0;i<6;i++)  parallogram_fonda[i]=pm->pd[i];
  1273. }
  1274.  
  1275. /* arguments :aucun */
  1276. void obj_resetparallelogram(objparm *pm)
  1277. {
  1278.   parallogram_fonda[0]=0;
  1279.   parallogram_fonda[1]=0;
  1280.   parallogram_fonda[2]=100;
  1281.   parallogram_fonda[3]=0;
  1282.   parallogram_fonda[4]=0;
  1283.   parallogram_fonda[5]=100;
  1284. }
  1285.  
  1286. /* argument : la liste des numeros des matrices a faire agir, le nom du fichier de l'image a inclure */
  1287. void obj_multicopy(objparm *pm)
  1288. {
  1289.   char *pp,*pe,*cptr;
  1290.   FILE *inf;
  1291.   gdImagePtr insimg;
  1292.   int i,j;
  1293.   int imax,jmax;
  1294.   int c; /* la couleur reperee */
  1295.   int mat;
  1296.   int nummatrices[JC_NB_MATRICES];
  1297.   double pt[2]; /* les coordonnees math. du point repere dans le parallelogramme */
  1298.   double ptr[2]; /* les coordonnees math. du point transforme */
  1299.   int pti[2]; /* les coordonnees img du point a placer sur le canevas */
  1300.   int t;
  1301.   /* gestion palette de couleur de l'image a inserer */
  1302.   int colorMap[gdMaxColors];
  1303.   int comptmat=0; /* combien de matrices en tout ? */
  1304.  
  1305.   for (i=0; (i<gdMaxColors); i++) {
  1306.     colorMap[i] = (-1);
  1307.   }
  1308.  
  1309.   /* Gestion des parametres la liste est censee finir avec le nom du fichier */
  1310.   t=pm->pcnt-1; /* il faut enlever le nom de fichier ! c'est le nombre de parametres en plus */
  1311.   pp=find_word_start(pm->str);
  1312.   /* visiblement find_word_start n'arrive pas a trouver le dernier mot dans un contexte ou le nombre de parameters est variable
  1313.      * on cherche donc l'emplacement de la derniere virgule:
  1314.      * il y en a une car t>0, on retrouve ensuite le debut de mot
  1315.      */
  1316.   for(pe=pp;*pe!=0;pe++);/* trouve la fin de la chaine */
  1317.   if(t>0){
  1318.     for(cptr = pe; cptr > pp && *cptr != ','; cptr--);
  1319.     pp=find_word_start(cptr+1);
  1320.   }
  1321.   pe=find_word_end(pp);*pe=0; /* strip junk final */
  1322.   //      printf("pp contient %s\n",pp);
  1323.  
  1324.  
  1325.   inf=open4read(pp);
  1326.   if(inf==NULL) {
  1327.     fly_error("file_not_exist"); return;
  1328.   }
  1329.   insimg=gdImageCreateFromGif(inf); fclose(inf);
  1330.   if(insimg==NULL) {
  1331.     fly_error("bad_gif"); return;
  1332.   }
  1333.  
  1334.   /* On recupere les numeros des matrices/vecteurs a faire agir,
  1335.     * s'il n'y en a pas, on les fait toutes agir
  1336.   */
  1337.   for(i=0;i<t && i< JC_NB_MATRICES;i++) {
  1338.     if(pm->pd[i]>=1 && pm->pd[i]<=JC_NB_MATRICES){
  1339.       nummatrices[comptmat] = pm->pd[i];
  1340.       comptmat++;
  1341.     }
  1342.   }
  1343.   if(t<=0){
  1344.     for(i=0;i<JC_NB_MATRICES;i++) {
  1345.       nummatrices[i] = i+1;
  1346.     }
  1347.     comptmat=JC_NB_MATRICES;
  1348.   }
  1349.  
  1350.  
  1351.   imax = gdImageSX(insimg);
  1352.   jmax = gdImageSY(insimg);
  1353.  
  1354.   for(i=0;i<imax;i++){
  1355.     for(j=0;j<jmax;j++){
  1356.       int nc;
  1357.       c=gdImageGetPixel(insimg,i,j);
  1358.       /* Le code suivant est une copie du code dans gdImageCopy  Added 7/24/95: support transparent copies */
  1359.       if (gdImageGetTransparent(insimg) != c) {
  1360.         /* Have we established a mapping for this color? */
  1361.         if (colorMap[c] == (-1)) {
  1362.           /* If it's the same image, mapping is trivial, dans notre cas ca n'arrive jamais... */
  1363.           if (image == insimg) {
  1364.             nc = c;
  1365.           } else {
  1366.             /* First look for an exact match */
  1367.             nc = gdImageColorExact(image,
  1368.                    insimg->red[c], insimg->green[c],
  1369.                            insimg->blue[c]);
  1370.           }
  1371.           if (nc == (-1)) {
  1372.           /* No, so try to allocate it */
  1373.             nc = gdImageColorAllocate(image,
  1374.                              insimg->red[c], insimg->green[c],
  1375.                              insimg->blue[c]);
  1376.              /* If we're out of colors, go for the closest color */
  1377.             if (nc == (-1)) {
  1378.               nc = gdImageColorClosest(image,
  1379.                               insimg->red[c], insimg->green[c],
  1380.                               insimg->blue[c]);
  1381.             }
  1382.           }
  1383.           colorMap[c] = nc;
  1384.         }
  1385.  
  1386.         pt[0]= i*(parallogram_fonda[2])/(imax-1)+(jmax-j)*(parallogram_fonda[4])/(jmax-1)+parallogram_fonda[0];
  1387.         pt[1]= i*(parallogram_fonda[3])/(imax-1)+(jmax-j)*(parallogram_fonda[5])/(jmax-1)+parallogram_fonda[1];
  1388.         for(mat=0;mat<comptmat;mat++){
  1389.           double *matricecourante = matrices_pavage[nummatrices[mat]];
  1390.           double *vecteurcourant = vecteurs_pavage[nummatrices[mat]];
  1391.           ptr[0] = matricecourante[0]*pt[0]+matricecourante[1]*pt[1]+vecteurcourant[0];
  1392.           ptr[1] = matricecourante[2]*pt[0]+matricecourante[3]*pt[1]+vecteurcourant[1];
  1393.           scale(ptr,pti,1);
  1394.           gdImageSetPixel(image,pti[0],pti[1],colorMap[c]);
  1395.         }
  1396.       }
  1397.     }
  1398.   }
  1399.   gdImageDestroy(insimg);
  1400. }
  1401.  
  1402. /**** Fin modifs JC Fev 06 ******/
  1403.  
  1404. /* get color from value */
  1405. int calc_color(char *p, struct objtab *o)
  1406. {
  1407.   int k, cc[3];
  1408.   char buf[MAX_LINELEN+1];
  1409.   for(k=0;k<3;k++) {
  1410.     fnd_item(p,k+1,buf);
  1411.     cc[k]=strevalue(buf);
  1412.   }
  1413.   collapse_item(p,3);
  1414.   if(cc[0]==-1 && cc[1]==-1 && cc[2]==-255) {
  1415.  
  1416.     if(brushed && o->subst&1) return gdBrushed;
  1417.     else return color_black;
  1418.   }
  1419.   if(cc[0]==-1 && cc[1]==-255 && cc[2]==-1) {
  1420.     if(styled && o->subst&2)  return gdStyled;
  1421.     else return color_black;
  1422.   }
  1423.   if(cc[0]==-255 && cc[1]==-1 && cc[2]==-1) {
  1424.     if(tiled && o->fill_tag==1)  return gdTiled;
  1425.     else return color_black;
  1426.   }
  1427.   return getcolor(cc[0],cc[1],cc[2]);
  1428. }
  1429.  
  1430. /* Routine to parse parameters */
  1431. int parse_parms(char *p,objparm *pm,struct objtab *o)
  1432. {
  1433.   char buf[MAX_LINELEN+1];
  1434.   char *p1, *p2;
  1435.   int j,t,c,c1,c2;
  1436.  
  1437.   c=o->color_pos;c1=c2=0;
  1438.   pm->color[0]=pm->color[1]=0;
  1439.   if(c>0) c1=c;
  1440.   if(c<0) c2=-c;
  1441.   c=c1+c2;
  1442.   t=itemnum(p);if(t<o->required_parms+3*c) return -1;
  1443.   if(c1>0 && t>o->required_parms+3*c) t=o->required_parms+3*c;
  1444.   pm->pcnt=t-3*c;
  1445.   if(pm->pcnt>MAX_PARMS) pm->pcnt=MAX_PARMS;
  1446.   if(c2>0) {
  1447.     for(j=0;j<2 && j<c2; j++) pm->color[j]=calc_color(p,o);
  1448.   }
  1449.   snprintf(buf,sizeof(buf),"%s",p);
  1450.   for(j=0, p1=buf; j<pm->pcnt; j++, p1=p2) {
  1451.     p2=find_item_end(p1); if(*p2) *p2++=0;
  1452.     p1=find_word_start(p1);
  1453.     if(*p1) pm->pd[j]=strevalue(p1); else pm->pd[j]=0;
  1454.     if(!isfinite(pm->pd[j])) {
  1455.         if(j<o->required_parms) return -1;
  1456.         else {pm->pd[j]=0;break;}
  1457.     }
  1458.   }
  1459.   collapse_item(p,o->required_parms);
  1460.   if(c1>0) {
  1461.     for(j=0;j<c1 && j<2; j++) pm->color[j]=calc_color(p,o);
  1462.   }
  1463.   if(width>1 && o->subst&1 && pm->color[0]!=gdBrushed
  1464.       && pm->color[0]!=gdStyled && pm->color[0]!=gdTiled) {
  1465.     pm->color[1]=pm->color[0];
  1466.     pm->color[0]=widthcolor(width,pm->color[0]);
  1467.   }
  1468.   pm->fill=o->fill_tag;
  1469.   ovlstrcpy(pm->str,p); return 0;
  1470. }
  1471.  
  1472. /* Create the struct objparm pm corresponding to the objparm p
  1473.  * Execute a command. Returns 0 if OK.
  1474.  */
  1475. int obj_main(char *p)
  1476. {
  1477.   int i;
  1478.   char *pp,*name,*pt;
  1479.   char tbuf2[MAX_LINELEN+1];
  1480.   struct objparm pm;
  1481.  
  1482.   p=find_word_start(p);
  1483.   if(*p==exec_prefix_char || *p==0) return 0; /* comment */
  1484.   name=p;
  1485.   pp=find_name_end(p);
  1486.   pt=find_word_start(pp); if(*pt=='=') *pt=' ';
  1487.   if(*pt==':' && *(pt+1)=='=') *pt=*(pt+1)=' ';
  1488.   pp=find_word_end(p);
  1489.   if(*pp!=0) {
  1490.     *(pp++)=0; pp=find_word_start(pp);
  1491.   }
  1492.   if(strlen(p)==1 || (strlen(p)==2 && isdigit(*(p+1)))) {
  1493.     setvar(p,strevalue(pp)); return 0;
  1494.   }
  1495.   /* search the number of the object */
  1496.   i=search_list(objtab,obj_no,sizeof(objtab[0]),name);
  1497.   if(i<0) {
  1498.     fly_error("bad_cmd"); return 1;
  1499.   }
  1500.   if(image==NULL && (objtab[i].color_pos || objtab[i].required_parms>2)) {
  1501.     fly_error("image_not_defined"); return 1;
  1502.   }
  1503.   ovlstrcpy(tbuf2,pp);
  1504.   if(objtab[i].color_pos || objtab[i].routine==obj_setstyle) {
  1505.     substit(tbuf2);
  1506.   }
  1507.   if(parse_parms(tbuf2,&pm,objtab+i)!=0) fly_error("bad_parms");
  1508.   else objtab[i].routine(&pm);
  1509.   return 0;
  1510. }
  1511.