home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Applications / Mathematiques / Kurve.lha / Kurve / funkrequest.c < prev    next >
C/C++ Source or Header  |  1992-12-06  |  52KB  |  1,832 lines

  1. /*  kurvemake  */
  2. /* this is the name of the makefile */
  3. /*******************************************************************/
  4. /*                                                                 */
  5. /*                         funkrequest                             */
  6. /*                                                                 */
  7. /*                       Modul zu  Kurve                           */
  8. /*                                                                 */
  9. /*                       Kurvendiskusion                           */
  10. /*                                                                 */
  11. /*                  ⌐ 90-92 by Henning  Rink                       */
  12. /*                                                                 */
  13. /*                     more info in Kurve.c                        */
  14. /*                                                                 */
  15. /* copyright notes -> see ReadMe                                   */
  16. /*******************************************************************/
  17.  
  18.  
  19. /*******************************************************************/
  20. /*                                                                 */
  21. /* see detailed list of changes in kurve.c                         */
  22. /*                                                                 */
  23. /*******************************************************************/
  24.  
  25.  
  26. extern  long     ys,xs,xn,yn,xmouse,ymouse;/* Startendkoordinaten fⁿr Zoombox */
  27. extern  short    flag;
  28. extern  struct   RastPort  *rp;
  29. extern  struct   Window    *FirstWindow;
  30. extern  struct   NewWindow ThirdNewWindow;
  31. extern  struct   Window    *ThirdWindow;
  32. extern  struct   IntuiMessage  *message;
  33. extern  long     xnull,ynull;
  34. extern  double   xmin,xmax,ymin,ymax,xe,ye;
  35. extern  UBYTE    UndoBuffer[],minx[],maxx[];
  36. extern  UBYTE    miny[],maxy[];
  37. extern  unsigned char funktion[],funktion1[],funktion2[];
  38. extern  short    fehler;
  39. extern  short    array[];
  40. extern  struct   TextAttr NormalAttr;
  41.  
  42. extern  struct   NewWindow ReqNewWindow,FuncReqNewWindow;
  43. extern  struct   IntuiText PatternBoxText;
  44.  
  45. extern  struct   FuncNode  *FirstFunc,*activeFunc;
  46. extern  struct   Image UpImage,DownImage;
  47. extern  UWORD    UpData[],DownData[];
  48. extern  struct   Gadget    FuncUpGadget,FuncDownGadget,FuncPropGadget;
  49. extern  struct   Border    ListBorderW;
  50. extern  struct   PropInfo  FuncProp;
  51. extern  UWORD    *mousemem;
  52.  
  53.  
  54.  
  55. extern APTR     ScreenVI;
  56. extern struct   NewGadget  NewOKGadget;
  57. extern struct   NewGadget  NewCancelGadget;
  58. extern struct   Gadget     *nullgadget;
  59. extern struct   NewGadget  NewPatternGadget;
  60. extern struct   NewGadget  NewFGadget,NewF1Gadget,NewF2Gadget;
  61.  
  62. extern struct   NewGadget  NewResetGadget,NewmaxyGadget,NewmaxxGadget;
  63. extern struct   NewGadget  NewminyGadget,NewminxGadget;
  64. extern struct   IntuiText  Intervall2Text;
  65.  
  66. extern  short    ShowErr(short,BOOL);
  67. extern  void     NeueP(void);
  68. extern  void     scan(unsigned char *,short *);
  69. extern  void     Clear(void);
  70. extern  void     DrawFunc(double (*)(double),long);
  71. extern  double   f(double),fa(double),fa2(double);
  72. extern  double   (*numb)(void),(*numb1)(void),(*numb2)(void);
  73. extern  BOOL     writefunclist(BPTR,BOOL);
  74. extern  void     handlesave(void);
  75. extern  void     handleload(long *,long *);
  76. extern  void     MouseCenterWin(struct NewWindow *,short,short);
  77.  
  78.  
  79. /*******************************************************************/
  80. /*                                                                 */
  81. /*                 list of functions in this modul                 */
  82. /*                                                                 */
  83. /*******************************************************************/
  84.  
  85. void    drawbox(void);
  86. void    ZoomBox(USHORT p);
  87. void    UnZoom(void);
  88. void    printpara(unsigned char *,double);
  89. void    checkstring(unsigned char *);
  90.  
  91. void    changeintervall(void);
  92.  
  93. BOOL    addfuncnode(void);
  94. BOOL    changefuncnode(struct FuncNode *);
  95. void    deletefuncnode(struct FuncNode *);
  96. BOOL    myallocfunc(APTR *,ULONG *,char *);
  97. void    delallfuncs(void);
  98. void    clearfuncnode(struct FuncNode *);
  99.  
  100. void    FuncReq(void);
  101. void    handlefuncreq(void);
  102. void    printactivefunc(void);
  103. void    printonefunc(long,struct FuncNode *);
  104. void    updatedisplay(long);
  105. BOOL    handlenew(long *,long *);
  106. BOOL    hitdisplay(long num,long total);
  107. void    handleprop(long *,long);
  108. void    handleupdown(long,long);
  109. void    handledelete(long *,long *);
  110. void    handleedit(long);
  111. void    activatefunc(struct FuncNode *);
  112. void    ReDrawFuncs(void);
  113. void    stripstr( char * s);
  114. void    handlepattern(void);
  115. void    handleprint(void);
  116. void    enablemessages(void);
  117. void    disablemessages(void);
  118. short   checkfuncs(void);
  119.  
  120. struct  RastPort        *rpreq,*funcreqrp;
  121. struct  Window          *ReqWindow,*FuncReqWindow;
  122. UWORD   DrawPattern=0xff;
  123.  
  124.  
  125. /* 12.01.1992 */
  126. void FuncReq(void)
  127. {
  128.  UWORD  *dataptr,*dataptr2;
  129.  struct TextFont  *oldtextfont,*newtextfont;
  130.  extern struct TextAttr BigAttr;
  131.  
  132.  dataptr=AllocMem(12L,(long)MEMF_CHIP);
  133.  dataptr2=AllocMem(12L,(long)MEMF_CHIP);
  134.  
  135.  if(!((ULONG)dataptr|(ULONG)dataptr2)) /* got I any CHIPMEM  ? */
  136.   {
  137.    ShowErr(14,FALSE);
  138.    if(dataptr)
  139.      FreeMem(dataptr,12L);
  140.  
  141.    if(dataptr2)
  142.      FreeMem(dataptr2,12L);
  143.  
  144.    return();
  145.   }
  146.  
  147.  CopyMem((char *)&UpData[0],(char *)dataptr,12L); /* copy Image Data */
  148.  UpImage.ImageData=dataptr;                       /* to CHIPMEM      */
  149.  CopyMem((char *)&DownData[0],(char *)dataptr2,12L);
  150.  DownImage.ImageData=dataptr2;
  151.  
  152.  MouseCenterWin(&FuncReqNewWindow,0,0);
  153.  if(FuncReqWindow = OpenWindow(&FuncReqNewWindow))
  154.   {
  155.    funcreqrp=FuncReqWindow->RPort;
  156.  
  157.    DrawBorder(funcreqrp,&ListBorderW,0L,0L);
  158.    DrawImage(funcreqrp,&UpImage,FuncUpGadget.LeftEdge+4L,FuncUpGadget.TopEdge+1L);
  159.    DrawImage(funcreqrp,&DownImage,FuncDownGadget.LeftEdge+4L,FuncDownGadget.TopEdge+1L);
  160.  
  161.    SetAPen(funcreqrp,1L);
  162.    SetBPen(funcreqrp,0L);
  163.    oldtextfont=funcreqrp->Font;
  164.    newtextfont=OpenFont(&BigAttr);
  165.    SetFont(funcreqrp,newtextfont);
  166.  
  167.    printactivefunc();
  168.    updatedisplay(0L);
  169.    handlefuncreq();
  170.  
  171.    SetFont(funcreqrp,oldtextfont);
  172.    CloseFont(newtextfont);
  173.    CloseWindow(FuncReqWindow);
  174.   }
  175.  else
  176.   ShowErr(13,FALSE);
  177.  
  178.  FreeMem(dataptr,12L);
  179.  FreeMem(dataptr2,12L);
  180. }
  181.  
  182.  
  183. /* 13.01.1992 */
  184. void printactivefunc(void)
  185. {
  186.  char buf[37];
  187.  
  188.  sprintf(buf,"%-35.35s",activeFunc->Func);
  189.  Move(funcreqrp,22L,110L);
  190.  Text(funcreqrp,(STRPTR)buf,35L);
  191. }
  192.  
  193.  
  194. /* 13.01.1992 */
  195. void printonefunc(long num,struct FuncNode *nodeptr)
  196. {
  197.  long base;
  198.  char buf[35];
  199.  
  200.  base=20+num*10;
  201.  
  202. if(!nodeptr) /* so it can be used to clear if there's no function */
  203.  {
  204.   SetAPen(funcreqrp,0L);
  205.   RectFill(funcreqrp,22L,base,349L,base+9L);
  206.   SetAPen(funcreqrp,1L);
  207.  }
  208. else
  209.  {
  210.    sprintf(buf,"%-32.32s",nodeptr->Func);
  211.    Move(funcreqrp,23L,base+7L);
  212.    Text(funcreqrp,(STRPTR)buf,32L);
  213.   }
  214. }
  215.  
  216.  
  217. /* 14.01.1992 */
  218. void updatedisplay(long firstone)
  219. {
  220.   long num=0;
  221.   struct FuncNode *nodeptr;
  222.  
  223.   nodeptr=FirstFunc;
  224.  
  225.   while(num!=firstone)
  226.    {
  227.      nodeptr=nodeptr->Next;
  228.      num++;
  229.    }
  230.  
  231.  
  232. for(num=0;num<8;num++)
  233.  {
  234.   printonefunc(num,nodeptr);
  235.   if(nodeptr)/* so print..() may get a NULL pointer and so clear this position */
  236.    nodeptr=nodeptr->Next;
  237.  }
  238. }
  239.  
  240. /* 13.01.1992 */
  241. void handlefuncreq(void)
  242. {
  243.  ULONG  MessageClass;
  244.  USHORT code;
  245.  struct Gadget *GadgetPTR;
  246.  SHORT  GadgetID=0,count;
  247.  struct FuncNode  *nodeptr;
  248.  long   numfunc,topfunc;
  249.  long   vertbody,vertpot,startsec,startmic,endsec,endmic;
  250.  
  251.  nodeptr=FirstFunc;
  252.  
  253.  numfunc=topfunc=startsec=startmic=vertpot=0;
  254.  
  255.  do
  256.   {
  257.    numfunc++;
  258.   }while(nodeptr=nodeptr->Next);
  259.  
  260.  
  261.  if(numfunc>8)
  262.   vertbody=(MAXBODY*8L)/(numfunc);
  263.  else
  264.   vertbody=MAXBODY;
  265.  
  266. NewModifyProp(&FuncPropGadget,FuncReqWindow,NULL,(long)AUTOKNOB|
  267.            FREEVERT|PROPBORDERLESS,NULL,vertpot,NULL,vertbody,1L);
  268.  
  269.  
  270. FOREVER
  271.  {
  272.    Wait(1L << FuncReqWindow->UserPort->mp_SigBit);
  273.     while(message=(struct IntuiMessage *)GetMsg(FuncReqWindow->UserPort))
  274.        {
  275.            MessageClass=message->Class;
  276.            code=message->Code;
  277.            if(MessageClass&(GADGETUP|GADGETDOWN))
  278.              {
  279.                GadgetPTR=(struct Gadget *)message->IAddress;
  280.                GadgetID=GadgetPTR->GadgetID;
  281.  
  282.              if(GadgetID>20)
  283.               {
  284.                endmic=message->Micros;
  285.                endsec=message->Seconds;
  286.               }
  287.              }
  288.            ReplyMsg((struct Message *)message);
  289.            switch(MessageClass)
  290.             {
  291.                 case GADGETDOWN:
  292.                   switch(GadgetID)
  293.                    {
  294.                      case 11:
  295.                       count=0;
  296.                       if(topfunc>0)
  297.                        {
  298.                         topfunc--;
  299.                         handleupdown(topfunc,numfunc);
  300.                        }
  301.                       break;
  302.                      case 12:
  303.                        count=0;
  304.                        if((numfunc-topfunc)>8)
  305.                         {
  306.                           topfunc++;
  307.                           handleupdown(topfunc,numfunc);
  308.                         }
  309.                        break;
  310.                    }
  311.                   break;
  312.                 case GADGETUP:
  313.                   switch(GadgetID)
  314.                    {
  315.                      case 1:
  316.                        handledelete(&numfunc,&topfunc);
  317.                        break;
  318.                      case 13:
  319.                      case 2:
  320.                        disablemessages();
  321.                        handleedit(topfunc);
  322.                        enablemessages();
  323.                        break;
  324.                      case 3:
  325.                        handlenew(&numfunc,&topfunc);
  326.                        break;
  327.                      case 4:
  328.                        disablemessages();
  329.                        handleload(&numfunc,&topfunc);
  330.                        enablemessages();
  331.                        break;
  332.                      case 5:
  333.                        disablemessages();
  334.                        handlesave();
  335.                        enablemessages();
  336.                        break;
  337.                      case 7:
  338.                        handleprint();
  339.                        break;
  340.                      case 8:
  341.                        disablemessages();
  342.                        handlepattern();
  343.                        enablemessages();
  344.                        break;
  345.                      case 10:
  346.                        GadgetID=0;
  347.                        if(numfunc>8)
  348.                          handleprop(&topfunc,numfunc);
  349.                        break;
  350.                      case 11:
  351.                      case 12:
  352.                         GadgetID=0;
  353.                         break;
  354.  
  355.                      default:
  356.                       if(GadgetID>20)
  357.                        {
  358.                         if(hitdisplay((GadgetID-20L+topfunc),numfunc))
  359.                           if(DoubleClick(startsec,startmic,endsec,endmic))
  360.                             GadgetID=6;
  361.                         startsec=endsec;
  362.                         startmic=endmic;
  363.                        }
  364.                       break;
  365.                    }
  366.                   break;
  367.  
  368.                 case INTUITICKS:
  369.                    if((FuncDownGadget.Flags&SELECTED)||(FuncUpGadget.Flags&SELECTED))
  370.                      {
  371.                       if(count++<2)
  372.                         break;
  373.                       if(GadgetID==12&&((numfunc-topfunc)>8))
  374.                        {
  375.                           topfunc++;
  376.                           handleupdown(topfunc,numfunc);
  377.                        }
  378.                       else
  379.                        {
  380.                         if(GadgetID==11&&topfunc>0)
  381.                          {
  382.                           topfunc--;
  383.                           handleupdown(topfunc,numfunc);
  384.                          }
  385.                        }
  386.                      }
  387.                    break;
  388.  
  389.                   case MOUSEMOVE:
  390.                      if(GadgetID==10&&numfunc>8)
  391.                         handleprop(&topfunc,numfunc);
  392.                       break;
  393.             }
  394.        }
  395.  
  396.      if( GadgetID == 6  )
  397.        break;
  398.   }
  399. }
  400.  
  401.  
  402. /* If you call ModifyIDCMP  with Flags=NULL then Intuition */
  403. /* will close the IDCMP Port completely -> free mem......  */
  404. /* and then create a new port if turning flags on          */
  405. /* so you have to check for success!!!                     */
  406. /* 26.01.1992 */
  407. void disablemessages(void)
  408. {
  409.    ModifyIDCMP(FuncReqWindow,(long)INTUITICKS);
  410. }
  411.  
  412. void enablemessages(void)
  413. {
  414.   ModifyIDCMP(FuncReqWindow,(long)INTUITICKS|MOUSEMOVE|GADGETUP|GADGETDOWN);
  415. }
  416.  
  417.  
  418. /*******************************************************************/
  419. /*                                                                 */
  420. /*       handleupdown() handles clicking the UP DOWN gadgets       */
  421. /*               with the mouse      done 14.01.1992               */
  422. /*                                                                 */
  423. /*******************************************************************/
  424.  
  425. void handleupdown(long top,long count)
  426. {
  427.  
  428.   FuncProp.VertPot=(MAXBODY*top)/(count-8L);
  429.  
  430.   RefreshGList(&FuncPropGadget,FuncReqWindow,NULL,1L);
  431.  
  432.   updatedisplay(top);
  433. }
  434.  
  435.  
  436. /*******************************************************************/
  437. /*                                                                 */
  438. /*           handleprop() handels moving the prop gadget           */
  439. /*            with the mouse by calling updatedisplay()            */
  440. /* done 14.01.1992                                                 */
  441. /*                                                                 */
  442. /*******************************************************************/
  443.  
  444. void handleprop(long *top,long count)
  445. {
  446.  long temptop;
  447.  
  448. temptop=(FuncProp.VertPot*(count-8L)/MAXBODY);
  449. if(temptop!=*top)
  450.  {
  451.     *top=temptop;
  452.     updatedisplay(temptop);
  453.  }
  454. }
  455.  
  456.  
  457. /*******************************************************************/
  458. /*                                                                 */
  459. /*            handlenew() inserts a new funtion to the             */
  460. /*            end of the functionslist  done 14.01.1992            */
  461. /*                                                                 */
  462. /*******************************************************************/
  463.  
  464. BOOL handlenew(long *count,long *top)
  465. {
  466.  long vertb;
  467.  
  468.  sprintf((char *)funktion,"sin(x)+%ld",(*count)+1L);
  469.  strcpy((char *)funktion1,"cos(x)");
  470.  strcpy((char *)funktion2,"-sin(x)");
  471.  
  472.  if(!addfuncnode())
  473.    return(FALSE);
  474.  
  475.  (*count)++;
  476.  
  477.  if((*count)>8)
  478.   {
  479.      vertb=(MAXBODY*8L)/(*count);
  480.      *top=(*count)-8L;   /* if 9 functions display from 2 to 9  */
  481.  
  482.      NewModifyProp(&FuncPropGadget,FuncReqWindow,NULL,(long)AUTOKNOB|
  483.       FREEVERT|PROPBORDERLESS,NULL,(long)MAXBODY,NULL,vertb,1L);
  484.   }
  485.  
  486.   printactivefunc();
  487.   updatedisplay(*top);
  488.  
  489.   return(TRUE);
  490. }
  491.  
  492.  
  493. /*******************************************************************/
  494. /*                                                                 */
  495. /*         handledelete() deletes the active function and          */
  496. /*          activates a new onw           done 15.01.1992          */
  497. /*                                                                 */
  498. /*******************************************************************/
  499.  
  500. void handledelete(long *count,long *top)
  501. {
  502.  struct FuncNode *nodeptr;
  503.  long vertp,vertb;
  504.  
  505.  if(*count==1)
  506.    return();
  507.  
  508.  if(activeFunc->Next)
  509.    nodeptr=activeFunc->Next;
  510.  else
  511.    nodeptr=activeFunc->Prev;
  512.  
  513.  deletefuncnode(activeFunc);
  514.   (*count)--;
  515.  
  516.  activatefunc(nodeptr);
  517.  printactivefunc();
  518.  
  519.  if(( (*count)-8L-(*top)<0L) && (*top)>0)
  520.    (*top)--;
  521.  
  522.  updatedisplay(*top);
  523.  
  524. if((*count)>8)
  525.  {
  526.   vertb=(MAXBODY*8L)/(*count);
  527.   vertp=(MAXBODY*(*top))/((*count)-8L);
  528.  }
  529. else
  530.  {
  531.    vertb=MAXBODY;
  532.    vertp=0L;
  533.  }
  534.  
  535.  NewModifyProp(&FuncPropGadget,FuncReqWindow,NULL,(long)AUTOKNOB|
  536.    FREEVERT|PROPBORDERLESS,NULL,vertp,NULL,vertb,1L);
  537.  
  538. }
  539.  
  540.  
  541. /*******************************************************************/
  542. /*                                                                 */
  543. /*           hitdisplay() handles clicking into the list           */
  544. /*            of the displayed functions and activates             */
  545. /*             the choosen function    done 14.01.1992             */
  546. /*                                                                 */
  547. /*******************************************************************/
  548.  
  549. BOOL hitdisplay(long num,long total)
  550. {
  551.  long active=1;
  552.  struct FuncNode *nodeptr;
  553.  
  554.  if(num>total)
  555.    return(FALSE);
  556.  
  557.  nodeptr=FirstFunc;
  558.  
  559.  while(active!=num)
  560.   {
  561.    nodeptr=nodeptr->Next;
  562.    active++;
  563.   }
  564.  
  565.  activatefunc(nodeptr);
  566.  printactivefunc();
  567.  return(TRUE);
  568. }
  569.  
  570.  
  571. void handleedit(long top)  /* done 16.01.1992 */
  572. {
  573.  ULONG   MessageClass;
  574.  USHORT  code,qualifier;
  575.  struct  Gadget *GadgetPTR,*firstgadget,*gad[3];
  576.  SHORT   GadgetID=0;
  577.  struct  IntuiMessage  *emessage;
  578.  short   error;
  579.  
  580.  strcpy((char *)funktion,activeFunc->Func);
  581.  strcpy((char *)funktion1,activeFunc->Func1);
  582.  strcpy((char *)funktion2,activeFunc->Func2);
  583.  
  584.  
  585.  NewOKGadget.ng_LeftEdge          =24;      /* GadTools Gadgets from */
  586.  NewCancelGadget.ng_LeftEdge      =506;      /*      05.08.1992       */
  587.  
  588.  NewCancelGadget.ng_TopEdge       = NewOKGadget.ng_TopEdge = 114;
  589.  
  590.  NewFGadget.ng_VisualInfo=NewF1Gadget.ng_VisualInfo=
  591.  NewF2Gadget.ng_VisualInfo=ScreenVI;
  592.  
  593.  GadgetPTR=CreateContext((struct Gadget **)&firstgadget);
  594.  GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,&NewOKGadget,
  595.          GT_Underscore,(ULONG)'_',TAG_DONE);
  596.  GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,
  597.           &NewCancelGadget,GT_Underscore,(ULONG)'_',TAG_DONE);
  598.  
  599. gad[0]=GadgetPTR=CreateGadget((ULONG)STRING_KIND,GadgetPTR,&NewFGadget,
  600.    GTST_String,funktion,GTST_MaxChars,254L,GT_Underscore,(ULONG)'_',TAG_DONE);
  601.  GadgetPTR->Activation |=GACT_STRINGCENTER;
  602.  
  603. gad[1]=GadgetPTR=CreateGadget((ULONG)STRING_KIND,GadgetPTR,&NewF1Gadget,
  604.    GTST_String,funktion1,GTST_MaxChars,254L,GT_Underscore,(ULONG)'_',TAG_DONE);
  605.  GadgetPTR->Activation |=GACT_STRINGCENTER;
  606.  
  607. gad[2]= GadgetPTR=CreateGadget((ULONG)STRING_KIND,GadgetPTR,&NewF2Gadget,
  608.    GTST_String,funktion2,GTST_MaxChars,254L,GT_Underscore,(ULONG)'_',TAG_DONE);
  609.  GadgetPTR->Activation |=GACT_STRINGCENTER;
  610.  
  611.  ReqNewWindow.FirstGadget=firstgadget;
  612.  
  613.  MouseCenterWin(&ReqNewWindow,0,0);
  614.  
  615.  if (!(ReqWindow = OpenWindow(&ReqNewWindow)))
  616.   {
  617.     FreeGadgets(firstgadget);
  618.     ShowErr(13,FALSE);
  619.     return();
  620.   }
  621.  
  622.   rpreq=ReqWindow->RPort;
  623.   GT_RefreshWindow(ReqWindow,NULL);
  624.   ActivateGadget(gad[0],ReqWindow,NULL);
  625.  
  626. errlabel:
  627.  
  628. FOREVER
  629.  {
  630.    Wait(1L << ReqWindow->UserPort->mp_SigBit);
  631.     while(emessage=(struct IntuiMessage *)GT_GetIMsg(ReqWindow->UserPort))
  632.        {
  633.            MessageClass=emessage->Class;
  634.            code=emessage->Code;
  635.            qualifier=emessage->Qualifier;
  636.            if(MessageClass&(GADGETUP|GADGETDOWN))
  637.              {
  638.                GadgetPTR=(struct Gadget *)emessage->IAddress;
  639.                GadgetID=GadgetPTR->GadgetID;
  640.  
  641.              }
  642.            GT_ReplyIMsg(emessage);
  643.            switch(MessageClass)
  644.             {
  645.                 case IDCMP_REFRESHWINDOW:   /*  refreshing 05.08.1992 */
  646.                   GT_BeginRefresh(ReqWindow);
  647.                     GT_RefreshWindow(ReqWindow,NULL);
  648.                   GT_EndRefresh(ReqWindow,(LONG)TRUE);
  649.                   break;
  650.  
  651.                 case VANILLAKEY:
  652.                   switch(code)
  653.                    {
  654.                      case 'f':  /* 05.08.1992 */
  655.                      case 'F':
  656.                        ActivateGadget(gad[0],ReqWindow,NULL);
  657.                        break;
  658.                     case '1':
  659.                        ActivateGadget(gad[1],ReqWindow,NULL);
  660.                        break;
  661.                     case '2':
  662.                        ActivateGadget(gad[2],ReqWindow,NULL);
  663.                        break;
  664.  
  665.                      case 'v':
  666.                      if(!(qualifier&IEQUALIFIER_LCOMMAND))
  667.                         break;
  668.                      case 'O':
  669.                      case 'o':
  670.                       GadgetID=7;
  671.                       break;
  672.  
  673.                      case 'b':
  674.                      if(!(qualifier&IEQUALIFIER_LCOMMAND))
  675.                         break;
  676.                      case 'C':
  677.                      case 'c':
  678.                      case 27:
  679.                       GadgetID=6;
  680.                       break;
  681.  
  682.                     }
  683.                    break;
  684.  
  685.                 case GADGETUP:
  686.                   switch (GadgetID)
  687.                    {
  688.                       case 1:
  689.                          ActivateGadget(gad[1],ReqWindow,NULL);
  690.                          break;
  691.                       case 2:
  692.                          ActivateGadget(gad[2],ReqWindow,NULL);
  693.                          break;
  694.                       default :
  695.                          break;
  696.                    }
  697.                default :
  698.                   break;
  699.             }
  700.        }
  701.  
  702.      if( GadgetID == 6 || GadgetID == 7 )
  703.        break;
  704.   }
  705.  
  706.  
  707.  if(GadgetID==7)
  708.   {
  709.    strcpy((char *)funktion,(char *)((struct StringInfo *)gad[0]->SpecialInfo)->Buffer);
  710.    strcpy((char *)funktion1,(char *)((struct StringInfo *)gad[1]->SpecialInfo)->Buffer);
  711.    strcpy((char *)funktion2,(char *)((struct StringInfo *)gad[2]->SpecialInfo)->Buffer);
  712.  
  713.      error=checkfuncs();  /* changed 01.02.1992  */
  714.  
  715.      if(error)
  716.       ShowErr(fehler,FALSE);
  717.  
  718.      switch(error)
  719.         {
  720.            case 1:
  721.             ActivateGadget(gad[0],ReqWindow,NULL);
  722.             break;
  723.            case 2:
  724.             ActivateGadget(gad[1],ReqWindow,NULL);
  725.             break;
  726.            case 3:
  727.             ActivateGadget(gad[2],ReqWindow,NULL);
  728.             break;
  729.         }
  730.  
  731.      if(error)
  732.       {
  733.          GadgetID=0;  /* got an endless loop because GadgetID=7 */
  734.                       /* and Intuition sends a refreshwindow    */
  735.                       /* so the programm didn't stop at WAIT()  */
  736.          goto errlabel;  /* my first and only goto!!  */
  737.       }                  /* jumps to FOREVER          */
  738.  
  739.      changefuncnode(activeFunc);
  740.      activatefunc(activeFunc);  /* necessary for numb(),num1(),numb2() */
  741.      printactivefunc();
  742.      updatedisplay(top);
  743.   }
  744.  
  745.  CloseWindow(ReqWindow);
  746.  FreeGadgets(firstgadget);
  747. }
  748.  
  749.  
  750. /*******************************************************************/
  751. /*                                                                 */
  752. /*           handlepattern() displays a window where the           */
  753. /*            user can choose a pattern for drawing the            */
  754. /*            function                  done 25.01.1992            */
  755. /*         changed for Kick 2.0   04.08.1992 and 05.08.1992        */
  756. /*                                                                 */
  757. /*******************************************************************/
  758.  
  759. void handlepattern(void)
  760. {
  761.  ULONG    MessageClass;
  762.  USHORT   code,qualifier;
  763.  struct   Gadget *GadgetPTR,*firstgadget,*gad[16];
  764.  SHORT    GadgetID=0;
  765.  struct   IntuiMessage  *emessage;
  766.  USHORT   i;
  767.  
  768.  
  769.  
  770.  NewOKGadget.ng_LeftEdge          =24;      /* GadTools Gadgets from */
  771.  NewCancelGadget.ng_LeftEdge      =286;     /*      04.08.1992       */
  772.  
  773.  NewCancelGadget.ng_TopEdge   =  NewOKGadget.ng_TopEdge   = 94;
  774.  
  775.  NewPatternGadget.ng_VisualInfo=ScreenVI;
  776.  
  777.  GadgetPTR=CreateContext((struct Gadget **)&firstgadget);
  778.  GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,&NewOKGadget,
  779.          GT_Underscore,(ULONG)'_',TAG_DONE);
  780.  GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,
  781.           &NewCancelGadget,GT_Underscore,(ULONG)'_',TAG_DONE);
  782.  
  783.  
  784. for(i=0;i<16;i++)  /* pattern gadgets from 05.08.1992 */
  785. {
  786.  NewPatternGadget.ng_LeftEdge=24+i*22;
  787.  NewPatternGadget.ng_GadgetID=10+i;
  788.  
  789.  gad[i]=GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,
  790.                 &NewPatternGadget,TAG_DONE);
  791.  
  792.  GadgetPTR->Activation |=GACT_TOGGLESELECT;
  793.  
  794.  if(activeFunc->FuncPattern&(1<<i))
  795.    GadgetPTR->Flags|=SELECTED;
  796.  else
  797.    GadgetPTR->Flags&=~SELECTED;
  798. }
  799.  
  800.  ThirdNewWindow.FirstGadget=firstgadget;
  801.  
  802.  MouseCenterWin(&ThirdNewWindow,0,0);
  803.  
  804.  if (!(ReqWindow = OpenWindow(&ThirdNewWindow)))
  805.   {
  806.     FreeGadgets(firstgadget);
  807.     ShowErr(13,FALSE);
  808.     return();
  809.   }
  810.  
  811.   rpreq=ReqWindow->RPort;
  812.   PrintIText(rpreq,&PatternBoxText,0L,0L);
  813.  
  814.   GT_RefreshWindow(ReqWindow,NULL);
  815.  
  816. FOREVER
  817.  {
  818.    Wait(1L << ReqWindow->UserPort->mp_SigBit);
  819.     while(emessage=(struct IntuiMessage *)GT_GetIMsg(ReqWindow->UserPort))
  820.        {
  821.            MessageClass=emessage->Class;
  822.            code=emessage->Code;
  823.            qualifier=emessage->Qualifier;
  824.            if(MessageClass&(GADGETUP|GADGETDOWN))
  825.              {
  826.                GadgetPTR=(struct Gadget *)emessage->IAddress;
  827.                GadgetID=GadgetPTR->GadgetID;
  828.  
  829.              }
  830.  
  831.            GT_ReplyIMsg(emessage);
  832.  
  833.            switch(MessageClass)
  834.             {
  835.                 case IDCMP_REFRESHWINDOW:   /*  refreshing 04.08.1992 */
  836.                   GT_BeginRefresh(ReqWindow);
  837.                     PrintIText(rpreq,&PatternBoxText,0L,0L);
  838.                     GT_RefreshWindow(ReqWindow,NULL);
  839.                   GT_EndRefresh(ReqWindow,(LONG)TRUE);
  840.                   break;
  841.  
  842.                 case VANILLAKEY:
  843.                   switch(code)
  844.                    {
  845.                      case 'v':
  846.                      if(!(qualifier&IEQUALIFIER_LCOMMAND))
  847.                         break;
  848.                      case 'O':
  849.                      case 'o':
  850.                       GadgetID=7;
  851.                       break;
  852.  
  853.                      case 'b':
  854.                      if(!(qualifier&IEQUALIFIER_LCOMMAND))
  855.                         break;
  856.                      case 'C':
  857.                      case 'c':
  858.                      case 27:
  859.                       GadgetID=6;
  860.                       break;
  861.                     }
  862.                    break;
  863.  
  864.                default :
  865.                   break;
  866.             }
  867.        }
  868.  
  869.      if( GadgetID == 6 || GadgetID == 7 )
  870.        break;
  871.   }
  872.  
  873. if(GadgetID==7)
  874.  {
  875.    for(i=0;i<16;i++)
  876.     {
  877.      if(gad[i]->Flags&SELECTED)
  878.       activeFunc->FuncPattern|=(1<<i);
  879.      else
  880.       activeFunc->FuncPattern&=~(1<<i);
  881.     }
  882.  }
  883.  
  884.  CloseWindow(ReqWindow);
  885.  FreeGadgets(firstgadget);
  886.  
  887.  
  888. }
  889.  
  890. void handleprint(void)
  891. {
  892.   BPTR fp;
  893.  
  894.   if(ShowErr(16,TRUE))
  895.   {
  896.    if(fp=Open((UBYTE *)"prt:",(long)MODE_NEWFILE))
  897.     {
  898.       SetPointer(FuncReqWindow,mousemem,16L,16L,0L,0L);
  899.       writefunclist(fp,TRUE);
  900.       Close(fp);
  901.       ClearPointer(FuncReqWindow);
  902.     }
  903.    }
  904. }
  905.  
  906.  
  907.  
  908. /*******************************************************************/
  909. /*                                                                 */
  910. /*        changeintervall() displays a window where you can        */
  911. /*         change the intervall limits xmin,xmax,ymin,ymax         */
  912. /*                         done 19.01.1992                         */
  913. /*                                                                 */
  914. /*******************************************************************/
  915.  
  916. void changeintervall(void)
  917. {
  918.  ULONG    MessageClass;
  919.  USHORT   code,qualifier;
  920.  struct   Gadget *GadgetPTR,*firstgadget,*resgad,*gad[4];
  921.  SHORT    GadgetID=0;
  922.  struct   IntuiMessage  *emessage;
  923.  
  924.  NewOKGadget.ng_LeftEdge          =24;      /* GadTools Gadgets from */
  925.  NewCancelGadget.ng_LeftEdge      =286;     /* 05. to 06.08.1992     */
  926.  
  927.  NewCancelGadget.ng_TopEdge   =  NewOKGadget.ng_TopEdge   = 94;
  928.  
  929.  
  930.  NewResetGadget.ng_VisualInfo=NewmaxxGadget.ng_VisualInfo=
  931.  NewminxGadget.ng_VisualInfo=
  932.  NewmaxyGadget.ng_VisualInfo=NewminyGadget.ng_VisualInfo=ScreenVI;
  933.  
  934.  GadgetPTR=CreateContext((struct Gadget **)&firstgadget);
  935.  GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,&NewOKGadget,
  936.          GT_Underscore,(ULONG)'_',TAG_DONE);
  937.  GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,
  938.           &NewCancelGadget,GT_Underscore,(ULONG)'_',TAG_DONE);
  939.  
  940.  resgad=GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,
  941.           &NewResetGadget,GT_Underscore,(ULONG)'_',TAG_DONE);
  942.  
  943.  gad[0]=GadgetPTR=CreateGadget((ULONG)STRING_KIND,GadgetPTR,&NewminxGadget,
  944.    GTST_String,minx,GTST_MaxChars,19L,GT_Underscore,(ULONG)'_',TAG_DONE);
  945.  GadgetPTR->Activation |=GACT_STRINGCENTER;
  946.  
  947.  gad[1]=GadgetPTR=CreateGadget((ULONG)STRING_KIND,GadgetPTR,&NewmaxxGadget,
  948.    GTST_String,maxx,GTST_MaxChars,19L,TAG_DONE);
  949.  GadgetPTR->Activation |=GACT_STRINGCENTER;
  950.  
  951.  gad[2]=GadgetPTR=CreateGadget((ULONG)STRING_KIND,GadgetPTR,&NewminyGadget,
  952.    GTST_String,miny,GTST_MaxChars,19L,TAG_DONE);
  953.  GadgetPTR->Activation |=GACT_STRINGCENTER;
  954.  
  955.  gad[3]=GadgetPTR=CreateGadget((ULONG)STRING_KIND,GadgetPTR,&NewmaxyGadget,
  956.    GTST_String,maxy,GTST_MaxChars,19L,TAG_DONE);
  957.  GadgetPTR->Activation |=GACT_STRINGCENTER;
  958.  
  959.  
  960.  
  961.  
  962.  ThirdNewWindow.FirstGadget=firstgadget;
  963.  
  964.  MouseCenterWin(&ThirdNewWindow,0,0);
  965.  
  966.  if (!(ReqWindow = OpenWindow(&ThirdNewWindow)))
  967.   {
  968.     FreeGadgets(firstgadget);
  969.     ShowErr(13,FALSE);
  970.     return();
  971.   }
  972.  
  973.   rpreq=ReqWindow->RPort;
  974.   PrintIText(rpreq,&Intervall2Text,0L,0L);
  975.   GT_RefreshWindow(ReqWindow,NULL);
  976.   ActivateGadget(gad[0],ReqWindow,NULL);
  977.  
  978. FOREVER
  979.  {
  980.    Wait(1L << ReqWindow->UserPort->mp_SigBit);
  981.     while(emessage=(struct IntuiMessage *)GT_GetIMsg(ReqWindow->UserPort))
  982.        {
  983.            MessageClass=emessage->Class;
  984.            code=emessage->Code;
  985.            qualifier=emessage->Qualifier;
  986.            if(MessageClass&(GADGETUP|GADGETDOWN))
  987.              {
  988.                GadgetPTR=(struct Gadget *)emessage->IAddress;
  989.                GadgetID=GadgetPTR->GadgetID;
  990.  
  991.              }
  992.            GT_ReplyIMsg(emessage);
  993.            switch(MessageClass)
  994.             {
  995.                case IDCMP_REFRESHWINDOW:   /*  refreshing 06.08.1992 */
  996.                  GT_BeginRefresh(ReqWindow);
  997.                     PrintIText(rpreq,&Intervall2Text,0L,0L);
  998.                     GT_RefreshWindow(ReqWindow,NULL);
  999.                   GT_EndRefresh(ReqWindow,(LONG)TRUE);
  1000.                   break;
  1001.  
  1002.                 case VANILLAKEY:
  1003.                   switch(code)
  1004.                    {
  1005.  
  1006.                      case 'X':
  1007.                      case 'x':
  1008.                         ActivateGadget(gad[0],ReqWindow,NULL);
  1009.                         break;
  1010.                      
  1011.                      case 'v':
  1012.                      if(!(qualifier&IEQUALIFIER_LCOMMAND))
  1013.                         break;
  1014.                      case 'O':
  1015.                      case 'o':
  1016.                       GadgetID=7;
  1017.                       break;
  1018.  
  1019.                      case 'b':
  1020.                      if(!(qualifier&IEQUALIFIER_LCOMMAND))
  1021.                         break;
  1022.                      case 'C':
  1023.                      case 'c':
  1024.                      case 27:
  1025.                       GadgetID=6;
  1026.                       break;
  1027.  
  1028.                      case 'R':  /*  23.01.1992  */
  1029.                      case 'r':
  1030.                       GadgetID=5;
  1031.                       break;
  1032.  
  1033.                     }
  1034.                    break;
  1035.  
  1036.                 case GADGETUP:
  1037.                   switch (GadgetID)
  1038.                    {
  1039.                       case 1:
  1040.                            ActivateGadget(gad[1],ReqWindow,NULL);
  1041.                            break;
  1042.                       case 2:
  1043.                            ActivateGadget(gad[2],ReqWindow,NULL);
  1044.                            break;
  1045.                       case 3:
  1046.                            ActivateGadget(gad[3],ReqWindow,NULL);
  1047.                            break;
  1048.                     }
  1049.                    break;
  1050.  
  1051.                default :
  1052.                   break;
  1053.             }
  1054.        }
  1055.  
  1056.   if(GadgetID==5) /* 23.01.1992 , 06.08.1992 */
  1057.    {
  1058.     strcpy((char *)((struct StringInfo *)gad[0]->SpecialInfo)->Buffer,"-10");
  1059.     strcpy((char *)((struct StringInfo *)gad[1]->SpecialInfo)->Buffer,"10");
  1060.     strcpy((char *)((struct StringInfo *)gad[2]->SpecialInfo)->Buffer,"-10");
  1061.     strcpy((char *)((struct StringInfo *)gad[3]->SpecialInfo)->Buffer,"10");
  1062.  
  1063.     RefreshGList(gad[0],ReqWindow,NULL,4L);
  1064.     ActivateGadget(gad[0],ReqWindow,NULL);
  1065.    }
  1066.  
  1067.  
  1068.   if(GadgetID==7) /* 06.08.1992 */
  1069.    {
  1070.     strcpy((char *)minx,(char *)((struct StringInfo *)gad[0]->SpecialInfo)->Buffer);
  1071.     strcpy((char *)maxx,(char *)((struct StringInfo *)gad[1]->SpecialInfo)->Buffer);
  1072.     strcpy((char *)miny,(char *)((struct StringInfo *)gad[2]->SpecialInfo)->Buffer);
  1073.     strcpy((char *)maxy,(char *)((struct StringInfo *)gad[3]->SpecialInfo)->Buffer);
  1074.     break;
  1075.    }
  1076.  
  1077.   if( GadgetID == 6)
  1078.     break;
  1079.  }
  1080.  
  1081.  CloseWindow(ReqWindow);
  1082.  FreeGadgets(firstgadget);
  1083.  
  1084.  if(GadgetID==7) /* OK */
  1085.   {
  1086.     NeueP();
  1087.     Clear();
  1088.     ReDrawFuncs();
  1089.   }
  1090.  
  1091. }
  1092.  
  1093.  
  1094.  
  1095.  
  1096. /************************************************/
  1097. /*                                              */
  1098. /*          Rechteck im Complement Modus        */
  1099. /*            fⁿr Rubberband Effekt             */
  1100. /*                                              */
  1101. /************************************************/
  1102.  
  1103. void ZoomBox(USHORT p)
  1104. {
  1105. struct RastPort *rp3;
  1106. ULONG  MessageClass;
  1107. double fys,fxs,fyn,fxn;
  1108. char   puffer[60];
  1109. SHORT  GadgetID=0;
  1110. long   help;
  1111. USHORT code,qualifier;
  1112. struct Gadget *GadgetPTR;
  1113.  
  1114.     if(p==1)  /* MouseButton gedrⁿckt   */
  1115.       {
  1116.        if(flag)
  1117.          {
  1118.            drawbox();       /* altes Rechteck l÷schen  */
  1119.  
  1120. /* BIT cycling added 24.09.1991 */
  1121. #asm
  1122.         MOVE.W   _DrawPattern,d0
  1123.         ROR.W    #3,d0
  1124.         MOVE.W   d0,_DrawPattern
  1125. #endasm
  1126.  
  1127.            SetDrPt(rp,DrawPattern);
  1128.  
  1129.            xn=xmouse;
  1130.            yn=ymouse;
  1131.            drawbox();      /* neues Rechteck Zeichnen   */
  1132.          }
  1133.        else
  1134.         {
  1135.           SetDrPt(rp,DrawPattern);
  1136.           flag=1;
  1137.           xn=xmouse;
  1138.           yn=ymouse;
  1139.           drawbox();       /* neues Rechteck Zeichnen */
  1140.         }
  1141.      }
  1142.  
  1143.   else    /* !p Button nicht mehr gedrⁿckt   */
  1144.    {
  1145.      flag=0;
  1146.      drawbox();         /* altes Recheck l÷schen  */
  1147.      SetDrPt(rp,0xffff);
  1148.      if(p==2)
  1149.        return();
  1150.  
  1151.      if(xn<xs)   /* Werte tauschen */
  1152.       {
  1153.         help=xs;
  1154.         xs=xn;
  1155.         xn=help;
  1156.       }
  1157.     if(yn<ys)
  1158.      {
  1159.        help=ys;
  1160.        ys=yn;
  1161.        yn=help;
  1162.      }
  1163.  
  1164.      if((xn-xs)<5 || (yn-ys)<5) /*  inserted 10.03.1991          */
  1165.          return();              /*  no smaller box than 5 points */
  1166.  
  1167.     NewOKGadget.ng_LeftEdge          =24;      /* GadTools Gadgets from */
  1168.     NewCancelGadget.ng_LeftEdge      =286;     /*     03.08.1992        */
  1169.  
  1170.     NewCancelGadget.ng_TopEdge  = NewOKGadget.ng_TopEdge    = 94;
  1171.  
  1172.     GadgetPTR=CreateContext((struct Gadget **)&nullgadget);
  1173.     GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,&NewOKGadget,
  1174.            GT_Underscore,(ULONG)'_',TAG_DONE);
  1175.     GadgetPTR=CreateGadget((ULONG)BUTTON_KIND,GadgetPTR,&NewCancelGadget,
  1176.            GT_Underscore,(ULONG)'_',TAG_DONE);
  1177.  
  1178.     ThirdNewWindow.FirstGadget=nullgadget;
  1179.  
  1180.      fys=(ynull-yn)/ye;  /* NOTE: float start != integer start */
  1181.      fyn=(ynull-ys)/ye;  /* so  fys = f(yn) ; fyn = f(ys)      */
  1182.      fxs=(xs-xnull)/xe;  /* but fxs = f(xs) ; fxn = f(xn);     */
  1183.      fxn=(xn-xnull)/xe;
  1184.  
  1185.      printpara(minx,fxs);
  1186.      printpara(miny,fys);
  1187.      printpara(maxx,fxn);
  1188.      printpara(maxy,fyn);
  1189.  
  1190.       /* same value should not occur 10.08.1991 */
  1191.  
  1192.      if(!(strcmp((char *)minx,(char *)maxx)))
  1193.        {
  1194.          fxs=xmin;
  1195.          fxn=xmax;
  1196.          printpara(minx,xmin);
  1197.          printpara(maxx,xmax);
  1198.        }
  1199.  
  1200.      if(!(strcmp((char *)miny,(char *)maxy)))
  1201.        {
  1202.          fys=ymin;
  1203.          fyn=ymax;
  1204.          printpara(miny,ymin);
  1205.          printpara(maxy,ymax);
  1206.        }
  1207.  
  1208.      MouseCenterWin(&ThirdNewWindow,-110,-40); /* 03.08.1992 */
  1209.      if (!(ThirdWindow = OpenWindow(&ThirdNewWindow)))
  1210.        {
  1211.         FreeGadgets(nullgadget);
  1212.         ShowErr(9,FALSE);
  1213.        }
  1214.     else
  1215.       {
  1216.  
  1217.        rp3=ThirdWindow->RPort;
  1218.        GT_RefreshWindow(ThirdWindow,NULL);
  1219.        SetDrMd(rp3,(long)JAM1);
  1220.        SetAPen(rp3,1L);
  1221.  
  1222.        Move(rp3,52L,17L);
  1223.        Text(rp3,(UBYTE *)"Do you want to use the new intervall",36L);
  1224.        Move(rp3,96L,33L);
  1225.        Text(rp3,(UBYTE *)"for further calculations ?",26L);
  1226.  
  1227.        sprintf(puffer,"Xmin:  %s",minx);
  1228.        Move(rp3,25L,55L);
  1229.        Text(rp3,(UBYTE *)puffer,(long)strlen(puffer));
  1230.        sprintf(puffer,"Ymin:  %s",miny);
  1231.        Move(rp3,25L,72L);
  1232.        Text(rp3,(UBYTE *)puffer,(long)strlen(puffer));
  1233.  
  1234.        sprintf(puffer,"Xmax:  %s",maxx);
  1235.        Move(rp3,225L,55L);
  1236.        Text(rp3,(UBYTE *)puffer,(long)strlen(puffer));
  1237.        sprintf(puffer,"Ymax:  %s",maxy);
  1238.        Move(rp3,225L,72L);
  1239.        Text(rp3,(UBYTE *)puffer,(long)strlen(puffer));
  1240.  
  1241.        FOREVER
  1242.          {
  1243.            Wait(1L << ThirdWindow->UserPort->mp_SigBit);
  1244.            while(message=(struct IntuiMessage *)GT_GetIMsg(ThirdWindow->UserPort))
  1245.            {
  1246.              MessageClass=message->Class;
  1247.              code=message->Code;
  1248.              qualifier=message->Qualifier;
  1249.              if(MessageClass&(GADGETUP|GADGETDOWN))
  1250.               {
  1251.                GadgetPTR=(struct Gadget *)message->IAddress;
  1252.                GadgetID=GadgetPTR->GadgetID;
  1253.                }
  1254.              GT_ReplyIMsg(message);
  1255.  
  1256.              switch(MessageClass)
  1257.                {
  1258.                 case IDCMP_REFRESHWINDOW: /* sorry no refreshing 04.08.1992 */
  1259.                   GT_BeginRefresh(ThirdWindow);
  1260.                   GT_EndRefresh(ThirdWindow,(LONG)TRUE);
  1261.                   break;
  1262.  
  1263.                 case VANILLAKEY: /* 17. and 18.11.1991 */
  1264.                   switch(code)   /* think this hole function needs some improvement!!*/
  1265.                    {
  1266.                      case 'v':
  1267.                      if(!(qualifier&IEQUALIFIER_LCOMMAND))
  1268.                         break;
  1269.                      case 'O':
  1270.                      case 'o':
  1271.                       GadgetID=7;
  1272.                       break;
  1273.  
  1274.                      case 'b':
  1275.                      if(!(qualifier&IEQUALIFIER_LCOMMAND))
  1276.                         break;
  1277.                      case 'C':
  1278.                      case 'c':
  1279.                      case 27:
  1280.                       GadgetID=6;
  1281.                       break;
  1282.  
  1283.                     }
  1284.                    break;
  1285.                 case GADGETUP:
  1286.                      break;
  1287.                }
  1288.            }
  1289.  
  1290.          if(GadgetID==6 || GadgetID==7)
  1291.          break;
  1292.  
  1293.          }/* FOREVER */
  1294.        CloseWindow(ThirdWindow);
  1295.        FreeGadgets(nullgadget);
  1296.        if(GadgetID==7)
  1297.         {
  1298.           SetDrMd(rp,(long)JAM1);
  1299.           NeueP();
  1300.           Clear();
  1301.           ReDrawFuncs();
  1302.           SetDrMd(rp,(long)JAM1|COMPLEMENT);
  1303.         }
  1304.        else /* CANCEL */
  1305.         {
  1306.          printpara(minx,xmin);
  1307.          printpara(miny,ymin);
  1308.          printpara(maxx,xmax);
  1309.          printpara(maxy,ymax);
  1310.         }
  1311.       }
  1312.    }
  1313. }
  1314.  
  1315.  
  1316. /************************************************/
  1317. /*                                              */
  1318. /*               Rechteck zeichnen              */
  1319. /*                                              */
  1320. /************************************************/
  1321.  
  1322. void drawbox(void)
  1323. {
  1324. register  long startx,endx,starty,endy;
  1325.  
  1326.    if(xs>xn)  /* changed 24.09.1991 */
  1327.     {
  1328.       startx=xn;
  1329.       endx=xs;
  1330.     }
  1331.    else
  1332.     {
  1333.       startx=xs;
  1334.       endx=xn;
  1335.     }
  1336.  
  1337.    if(ys>yn)
  1338.     {
  1339.       starty=yn;
  1340.       endy=ys;
  1341.     }
  1342.    else
  1343.     {
  1344.       starty=ys;
  1345.       endy=yn;
  1346.     }
  1347.  
  1348.    if(startx==endx)
  1349.     {
  1350.       Move(rp,startx,endy);
  1351.       Draw(rp,endx,starty);
  1352.     }
  1353.    else
  1354.     {
  1355.       Move(rp,startx,starty);
  1356.       if(starty==endy)
  1357.          Draw(rp,endx,endy);
  1358.       else
  1359.        {
  1360.          Draw(rp,endx,starty);
  1361.          Draw(rp,endx,endy);
  1362.          Draw(rp,startx,endy);
  1363.          Draw(rp,startx,starty);
  1364.        }
  1365.     }
  1366. }
  1367.  
  1368.  
  1369. /*******************************************************************/
  1370. /*                                                                 */
  1371. /*                             UnZoom                              */
  1372. /* Einfaches herauszoomen aus dem momentan gewΣhlten Ausschnitt    */
  1373. /*                                                                 */
  1374. /*******************************************************************/
  1375.  
  1376. void UnZoom(void)
  1377. {
  1378. register double xdelta,ydelta;
  1379.  
  1380.  xdelta=(xmax-xmin)*0.5;
  1381.  ydelta=(ymax-ymin)*0.5;
  1382.  
  1383. /*
  1384.     (xmax-xmin)*sqrt(2.0)-(xmax-xmin)
  1385.     --------------------------------- = (dx)*0.207
  1386.                   2.0
  1387.  
  1388. diese Formel fⁿhrt zur FlΣchenverdoppelung, bei (xmax-xmin)/2 vervierfacht
  1389. sich die abgebildete FlΣche
  1390. */
  1391.  
  1392.  xmax+=xdelta;
  1393.  xmin-=xdelta;
  1394.  ymax+=ydelta;
  1395.  ymin-=ydelta;
  1396.  
  1397.  printpara(minx,xmin);
  1398.  printpara(miny,ymin);
  1399.  printpara(maxx,xmax);
  1400.  printpara(maxy,ymax);
  1401.  
  1402.  SetDrMd(rp,(long)JAM1);
  1403.  NeueP();
  1404.  Clear();
  1405.  ReDrawFuncs();
  1406.  SetDrMd(rp,(long)JAM1|COMPLEMENT);
  1407.  
  1408. }
  1409.  
  1410.  
  1411. /*******************************************************************/
  1412. /*                                                                 */
  1413. /*                           printpara()                           */
  1414. /*                      parameter to strings                       */
  1415. /*                           25.07.1991                            */
  1416. /*                                                                 */
  1417. /*******************************************************************/
  1418.  
  1419. void printpara(unsigned char *s,double a)
  1420. {
  1421.  sprintf((char *)s,"%-14.7g",a);
  1422.  checkstring(s);
  1423.  
  1424. }
  1425.  
  1426. /*******************************************************************/
  1427. /*                                                                 */
  1428. /*                   checkstring()  18.08.1991                     */
  1429. /*                                                                 */
  1430. /* added because the MANX 5.0a,d format() routine losses 0 at the  */
  1431. /* end of strings if formated with g format                        */
  1432. /* 1e10 is printed as 1e1 !!!!!!!                                  */
  1433. /*                                                                 */
  1434. /* Aztec 3.6a losses "0" in the mantisse while turning from        */
  1435. /* f in e format, so I printed with %14.7e                         */
  1436. /*                                                                 */
  1437. /* AztecC5.0b,c not tested ->didn't get them                       */
  1438. /* Version 5.2a works well     24.12.1991                          */
  1439. /*                                                                 */
  1440. /*******************************************************************/
  1441.  
  1442.  
  1443. void checkstring(unsigned char *zahl)
  1444. {
  1445.  
  1446. #ifdef AztecVERSION500
  1447. register  short j;
  1448. register  long i;
  1449. #endif
  1450.  
  1451. stripstr((char *)zahl); /* cut spaces */
  1452.  
  1453. #ifdef AztecVERSION500                /* 24.12.1991 */
  1454.    i=strcspn((const char *)zahl,"e");
  1455.    if(i)
  1456.     {
  1457.       j=strlen((const char *)zahl);
  1458.       switch((j-i))
  1459.          {
  1460.           case 4:
  1461.             strcat((char *)zahl,"0");
  1462.             break;
  1463.           case 3:
  1464.             strcat((char *)zahl,"00");
  1465.             break;
  1466.          }
  1467.     }
  1468. #endif
  1469. }
  1470.  
  1471.  
  1472. /*******************************************************************/
  1473. /*                                                                 */
  1474. /*     myallocfunc() compiles the given function via scan and      */
  1475. /*           allocates memory for the compiled function            */
  1476. /*                         done 29.12.1991                         */
  1477. /*                                                                 */
  1478. /*******************************************************************/
  1479.  
  1480. BOOL myallocfunc(APTR *memblck,ULONG *len, char *funcstr)
  1481. {
  1482.  ULONG lenofCFunc;
  1483.  extern short *point;
  1484.  
  1485.  scan((unsigned char *)funcstr,array);
  1486.  
  1487.  lenofCFunc=(ULONG)point-(ULONG)array;
  1488.  
  1489.  if(!(*memblck=AllocMem(lenofCFunc,MEMF_PUBLIC)))
  1490.   {
  1491.    ShowErr(14,FALSE);
  1492.    return(FALSE);
  1493.   }
  1494.  else
  1495.   *len=lenofCFunc;
  1496.  
  1497.   CopyMem(array,*memblck,*len); /* moving code -> so flush cache */
  1498.  
  1499. /* 06.02.1992 */
  1500. #asm 
  1501.      xref      _SysBase     /* do it with inline assembler, so              */
  1502.      move.l    a6,-(sp)     /* it compiles with old Kick1.3 too             */
  1503.      movea.l   _SysBase,a6  /* need to clear data cache 68030 ?, 68040 sure */
  1504.      cmpi.w    #37,$14(a6)  /* only 2.0 kickstart                           */
  1505.      bcs.s     weiter       /* !! makes no sense to test for 68030 or 68040 */
  1506.      jsr       -636(a6)     /* kickstart can do it for me                   */
  1507. weiter: movea.l   (sp)+,a6  /* CacheClearU(); routine                       */
  1508. #endasm
  1509.  
  1510.   return(TRUE);
  1511. }
  1512.  
  1513.  
  1514. /*******************************************************************/
  1515. /*                                                                 */
  1516. /*    addfuncnode() allocates memory for a FuncNode adds it to     */
  1517. /*     the end of all other FuncNodes and the calls change..()     */
  1518. /*     to alloc memory for the rest            done 29.12.1991     */
  1519. /*                                                                 */
  1520. /*******************************************************************/
  1521.  
  1522. BOOL  addfuncnode(void)
  1523. {
  1524.  struct FuncNode *lastnode,*nodeptr;
  1525.  
  1526.  if(FirstFunc)
  1527.   {
  1528.    lastnode=FirstFunc;
  1529.    while(lastnode->Next)
  1530.      lastnode=lastnode->Next;
  1531.   }
  1532.  
  1533.   if(!(nodeptr=AllocMem(sizeof(struct FuncNode),MEMF_CLEAR)))
  1534.    {                         /* memory have to be cleared for */
  1535.     ShowErr(14,FALSE);       /* sanity checks with pointers   */
  1536.     return(FALSE);
  1537.    }
  1538.  
  1539.  if(FirstFunc)
  1540.   {
  1541.    lastnode->Next=nodeptr;
  1542.    nodeptr->Prev=lastnode;
  1543.   }
  1544.  else
  1545.    FirstFunc=nodeptr;
  1546.  
  1547.  
  1548. changefuncnode(nodeptr);
  1549. activatefunc(nodeptr);
  1550.  
  1551. nodeptr->FuncPattern=0xffff;
  1552.  
  1553. return(TRUE);
  1554. }
  1555.  
  1556.  
  1557. /*******************************************************************/
  1558. /*                                                                 */
  1559. /*        deletefuncnode() deletes a funcnode via clear..()        */
  1560. /*            and then freeing mem from struct Funcnode            */
  1561. /*                         done 29.12.1991                         */
  1562. /*                                                                 */
  1563. /*******************************************************************/
  1564.  
  1565. void  deletefuncnode(struct FuncNode *oldnode)
  1566. {
  1567.   struct FuncNode *prevnode,*nextnode;
  1568.  
  1569.   prevnode=oldnode->Prev;
  1570.   nextnode=oldnode->Next;
  1571.  
  1572.  if(prevnode)
  1573.    prevnode->Next=nextnode;
  1574.  else
  1575.    FirstFunc=nextnode;
  1576.  
  1577.  if(nextnode)
  1578.    nextnode->Prev=prevnode;
  1579.  
  1580.   clearfuncnode(oldnode);
  1581.   FreeMem(oldnode,sizeof(struct FuncNode));
  1582. }
  1583.  
  1584.  
  1585. /*******************************************************************/
  1586. /*                                                                 */
  1587. /*           clearfuncnode() frees the FuncNode from all           */
  1588. /*             function strings and comiled functions              */
  1589. /*                         done 29.12.1991                         */
  1590. /*                                                                 */
  1591. /*******************************************************************/
  1592.  
  1593. void clearfuncnode(struct FuncNode *oldnode)
  1594. {
  1595.   ULONG  *lenptr;
  1596.   APTR   *CFuncptr;
  1597.   char   **Funcptr;
  1598.   short i;
  1599.  
  1600.   lenptr=&oldnode->LenCFunc;
  1601.   CFuncptr=&oldnode->CFunc;
  1602.   Funcptr=&oldnode->Func;
  1603.  
  1604.   oldnode->isdrawn=0;  /* note I'm not changing FuncPattern 20.01.1992 */
  1605.  
  1606.   for(i=0;i<3;i++)  /* free memory from compiled func  */
  1607.    {
  1608.     if(*lenptr) /* is there a compiled function? */
  1609.       FreeMem(*CFuncptr,*lenptr);
  1610.     *lenptr++=NULL;
  1611.     *CFuncptr++=NULL;
  1612.    }
  1613.  
  1614.   for(i=0;i<3;i++) /* free memory from functionstrings  */
  1615.    {
  1616.      if(*Funcptr) /* is there a string ? */
  1617.        FreeMem(*Funcptr,strlen((const char *)*Funcptr)+1L);
  1618.      *Funcptr++=NULL;
  1619.    }
  1620. }
  1621.  
  1622.  
  1623. /********************************************************************/
  1624. /*                                                                  */
  1625. /* changefuncnode() deletes all strings and compiled functions      */
  1626. /* via clearfuncnode() and then allocates mem for the new function- */
  1627. /* strings and compiles the function with myallocfunc()             */
  1628. /* done 29.12.1991                                                  */
  1629. /********************************************************************/
  1630.  
  1631. BOOL changefuncnode(struct FuncNode *oldnode)
  1632. {
  1633.   ULONG len,len1,len2;
  1634.  
  1635.   len=strlen((const char *)funktion);
  1636.   len1=strlen((const char *)funktion1);
  1637.   len2=strlen((const char *)funktion2);
  1638.  
  1639.   if(!len)          /* 06.02.1992 */
  1640.    return(FALSE);
  1641.  
  1642.   clearfuncnode(oldnode);
  1643.  
  1644.   if(!(oldnode->Func=AllocMem(len+1L,MEMF_PUBLIC)))
  1645.    {
  1646.      ShowErr(14,FALSE);
  1647.      return(FALSE);
  1648.    }
  1649.   else
  1650.    strcpy(oldnode->Func,(const char *)funktion);
  1651.  
  1652.   if(len1)
  1653.    {
  1654.     if(!(oldnode->Func1=AllocMem(len1+1L,MEMF_PUBLIC)))
  1655.      {
  1656.        ShowErr(14,FALSE);
  1657.        return(FALSE);
  1658.      }
  1659.     else
  1660.      strcpy(oldnode->Func1,(const char *)funktion1);
  1661.    }
  1662.   else
  1663.     oldnode->Func1=NULL;
  1664.  
  1665.   if(len2)
  1666.    {
  1667.     if(!(oldnode->Func2=AllocMem(len2+1L,MEMF_PUBLIC)))
  1668.      {
  1669.       ShowErr(14,FALSE);
  1670.       return(FALSE);
  1671.      }
  1672.     else
  1673.      strcpy(oldnode->Func2,(const char *)funktion2);
  1674.    }
  1675.    else
  1676.     oldnode->Func2=NULL;
  1677.  
  1678. /* compiling of functions and allocation via myallocfunc */
  1679.  
  1680.   if(!myallocfunc(&oldnode->CFunc,&oldnode->LenCFunc,oldnode->Func))
  1681.      return(FALSE);
  1682.  
  1683.  
  1684.   if(oldnode->Func1) /* is there anything ? */
  1685.     if(!myallocfunc(&oldnode->CFunc1,&oldnode->LenCFunc1,oldnode->Func1)) /* 30.12.1991 */
  1686.       return(FALSE);
  1687.  
  1688.   if(oldnode->Func2)/* is there anything ? */
  1689.     if(!myallocfunc(&oldnode->CFunc2,&oldnode->LenCFunc2,oldnode->Func2))/* 30.12.1991 */
  1690.        return(FALSE);
  1691.  
  1692.  return(TRUE);
  1693. }
  1694.  
  1695.  
  1696. /*******************************************************************/
  1697. /*                                                                 */
  1698. /*         delallfuncs() deletes the complete functionlist         */
  1699. /*         pointed by FirstFunc           done 29.12.1991          */
  1700. /*                                                                 */
  1701. /*******************************************************************/
  1702.  
  1703. void delallfuncs(void)
  1704. {
  1705.  while(FirstFunc)
  1706.     deletefuncnode(FirstFunc);
  1707.  activeFunc=NULL;
  1708. }
  1709.  
  1710.  
  1711. /*******************************************************************/
  1712. /*                                                                 */
  1713. /*            ReDrawFuncs() redraws all functions after            */
  1714. /*              changing screenmode, intervall, etc..              */
  1715. /*                         done 20.01.1992                         */
  1716. /*                                                                 */
  1717. /*******************************************************************/
  1718.  
  1719. void ReDrawFuncs(void)
  1720. {
  1721.   struct FuncNode *nodeptr,*oldactfunc;
  1722.  
  1723.  nodeptr=FirstFunc;
  1724.  oldactfunc=activeFunc;
  1725.  SetDrMd(rp,(long)JAM1);
  1726.  do
  1727.   {
  1728.     if(nodeptr->isdrawn)
  1729.      {
  1730.        activatefunc(nodeptr);
  1731.  
  1732.        if(nodeptr->isdrawn&0x01)
  1733.          DrawFunc(f,1L);
  1734.  
  1735.        if(nodeptr->isdrawn&0x02)
  1736.          DrawFunc(fa,4L);
  1737.  
  1738.        if(nodeptr->isdrawn&0x04)
  1739.          DrawFunc(fa2,5L);
  1740.      }
  1741.  
  1742.   }while(nodeptr=nodeptr->Next);
  1743.  
  1744.  activatefunc(oldactfunc);
  1745.  SetDrMd(rp,(long)JAM1|COMPLEMENT);
  1746. }
  1747.  
  1748.  
  1749. /*******************************************************************/
  1750. /*                                                                 */
  1751. /*            activatefunc() activates a given FuncNode            */
  1752. /*                         done 20.01.1992                         */
  1753. /*                                                                 */
  1754. /*******************************************************************/
  1755.  
  1756. void activatefunc(struct FuncNode *nodeptr)
  1757. {
  1758.   activeFunc=nodeptr;
  1759.   numb=(void *)activeFunc->CFunc;
  1760.   numb1=(void *)activeFunc->CFunc1;
  1761.   numb2=(void *)activeFunc->CFunc2;
  1762. }
  1763.  
  1764.  
  1765. /*******************************************************************/
  1766. /*                                                                 */
  1767. /*             stripstr() removes blanks from a string             */
  1768. /*              and converts the string to lower case              */
  1769. /*                        done 25.01.1992                          */
  1770. /*                                                                 */
  1771. /*******************************************************************/
  1772.  
  1773. void stripstr( char * s)
  1774. {
  1775.  char *st;
  1776. long i;
  1777.  
  1778.  st=s;
  1779.  strlwr(s);
  1780.  
  1781.  while(*st==' ')/* cut leading spaces */
  1782.   st++;
  1783.  
  1784.  i=strcspn((const char *)st," "); /* cut following spaces */
  1785.  st[i]=0;
  1786.  
  1787.   if(!(s==st))
  1788.    {
  1789.      do
  1790.       {
  1791.         *s++=*st++;
  1792.       }while(*st);
  1793.  
  1794.      *s=0;
  1795.    }
  1796.  
  1797. }
  1798.  
  1799.  
  1800. /*******************************************************************/
  1801. /*                                                                 */
  1802. /*        checkfuncs() checks via scan the integrity of the        */
  1803. /*        function given in funktion?      done 01.02.1992         */
  1804. /*                                                                 */
  1805. /*******************************************************************/
  1806.  
  1807. short checkfuncs(void)
  1808. {
  1809.      stripstr((char *)funktion);
  1810.      stripstr((char *)funktion1);
  1811.      stripstr((char *)funktion2);
  1812.  
  1813.      scan((unsigned char *)funktion,array);
  1814.      if(fehler)
  1815.        return(1);
  1816.  
  1817.      if(strlen((char *)funktion1))
  1818.       {
  1819.        scan((unsigned char *)funktion1,array);
  1820.         if(fehler)
  1821.          return(2);
  1822.       }
  1823.  
  1824.      if(strlen((char *)funktion2))
  1825.       {
  1826.         scan((unsigned char *)funktion2,array);
  1827.         if(fehler)
  1828.          return(3);
  1829.       }
  1830.   return(0);
  1831. }
  1832.