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

  1. /*  kurvemake  */
  2. /* this is the name of the makefile */
  3. /*******************************************************************/
  4. /*                                                                 */
  5. /*                        fileandscreen                            */
  6. /*                                                                 */
  7. /*                       Modul zu  Kurve                           */
  8. /*                                                                 */
  9. /*                       Kurvendiskusion                           */
  10. /*                                                                 */
  11. /*                   ⌐ 91-92 by Henning  Rink                      */
  12. /*                                                                 */
  13. /*     splited from Kurve.c and Funkrequest.c on 28.12.1991        */
  14. /*                                                                 */
  15. /*                     more info in Kurve.c                        */
  16. /*                                                                 */
  17. /* copyright notes -> see ReadMe                                   */
  18. /*******************************************************************/
  19.  
  20. #define NAMELEN 256L
  21.  
  22.  
  23. extern struct   Screen      *FirstScreen;
  24. extern struct   NewWindow   FirstNewWindow,SecondNewWindow;
  25. extern struct   NewWindow   ThirdNewWindow,FourthNewWindow;
  26. extern struct   NewScreen   FirstNewScreen; /* this is an ExtNewScreen !! */
  27. extern struct   Gadget      FuncPropGadget;
  28. extern struct   Border      PropBorderB;
  29. extern struct   ReqLib      *ReqBase;
  30. extern const    char        *coltoolname;
  31. extern struct   Window      *ThirdWindow,*FuncReqWindow;
  32. extern struct   IntuiMessage  *message;
  33. extern struct   TextAttr    NormalAttr;
  34. extern unsigned char        minx[],maxx[],miny[],maxy[];
  35. extern unsigned char        funktion[],funktion1[],funktion2[],UndoBuffer[];
  36. extern char                 mycolors[];
  37. extern struct   GfxBase     *GfxBase;
  38. extern char                 configpath[];
  39. extern double               xmin,xmax,ymin,ymax,xstep,xe,ye;
  40. extern long                 scrheight,scrwidth,winheightmax,scrmode;
  41. extern struct   FuncNode    *FirstFunc;
  42. extern struct   FuncNode    *activeFunc;
  43. extern char                  configfile[],configdir[];
  44. extern short    fehler;
  45. extern UWORD   *mousemem;
  46. extern char    LoadText[],SaveText[];
  47. extern struct Window *FirstWindow;
  48.  
  49.  
  50. /*  definitions for changescreenmode */
  51. extern struct Window *screenmodewin;
  52. extern struct NewWindow ScrModeNewWindow;
  53. extern struct Gadget *nullgadget;
  54. extern struct NewGadget modeuse,modecancel,defwidth,defheight;
  55. extern struct NewGadget scrwidthgadget,scrheightgadget,modelistview;
  56. extern char   monitordescript[4][32];
  57. extern struct NameInfo namebuffer;
  58. extern struct DimensionInfo dimensionbuffer;
  59. extern USHORT defscr;
  60. extern struct List monitorlist;
  61. extern struct Node l1mode,l2mode,l3mode,l4mode;
  62. extern struct IntuiText modeproptxt,vissizetxt2;
  63. extern char monitormaxsize[],monitorminsize[],monitorvissize[],colorstring[];
  64. /* end of changescrmode data defines */
  65.  
  66. extern void  printpara(unsigned char *,double);
  67. extern short ShowErr(short,BOOL);
  68. extern BOOL  addfuncnode(void);
  69. extern BOOL  changefuncnode(struct FuncNode *);
  70. extern void  NeueP(void);
  71. extern void  Open_WINS(void);
  72. extern void  Close_WINS(void);
  73. extern void  Clear(void);
  74. extern void  Maus(void);
  75. extern void  ReDrawFuncs(void);
  76. extern short checkfuncs(void);
  77. extern void  updatedisplay(long);
  78. extern void  printactivefunc(void);
  79. extern void  activatefunc(struct FuncNode *);
  80. extern void  delallfuncs(void);
  81. extern void  stripstr( char *);
  82.  
  83. /*******************************************************************/
  84. /*                                                                 */
  85. /*                 list of functions in this modul                 */
  86. /*                                                                 */
  87. /*******************************************************************/
  88.  
  89. /* BOOL    resfilemem(void); cleared 06.08.1992 */
  90. /* void    doreqreq(void);   */
  91.  
  92. void    extLoadConfig(void);
  93. void    extSaveConfig(void);
  94. void    clearfilemem(void);
  95. void    setscreenprefs(void);
  96. void    getscreenprefs(void);
  97. void    LoadConfig(char *);
  98. void    SaveConfig(char *);
  99. void    changecolor(void);
  100. void    setcolors(void);
  101. void    getcolors(void);
  102. BOOL    writefunclist(BPTR,BOOL);
  103. void    handlesave(void);
  104. void    handleload(long *,long *);
  105. long    filelength(UBYTE *);
  106. void    helpdruck(UBYTE **, long *);
  107. BOOL    readfunclist(FILE *);
  108. long    hextol(char *);
  109.  
  110. void    changescreenmode(void);
  111. void    FillSizeInfo(ULONG modeid);
  112. void    MouseCenterWin(struct NewWindow *,short,short);
  113.  
  114.  
  115. char     *funcdir="";               /* default path and name of the */
  116. char     *funcfile="functions.kur"; /* function list file           */
  117.  
  118. struct  FileRequester *myaslFileReq;  /* pointer to asl FileRequester  */
  119. char    *pathnamearray;
  120.  
  121.  
  122.  
  123. extern APTR ScreenVI;
  124.  
  125.  
  126.  
  127. /*******************************************************************/
  128. /*                                                                 */
  129. /*           Screenmode Requester like Prefs-Screenmode            */
  130. /*   03.08.1992                                                    */
  131. /*******************************************************************/
  132.  
  133. void changescreenmode(void)
  134. {
  135.   short  ntscavail,palavail,offs=0;
  136.   struct Gadget *gad,*heightgad,*widthgad;
  137.   long class;
  138.   USHORT code,GadgetID,endless=TRUE,defscr2,height,width;
  139.   struct IntuiMessage *modemessage;
  140.   struct RastPort *moderp;
  141.   ULONG vidmode,selected;
  142.  
  143.   defscr2=defscr;
  144.  
  145.  
  146.  
  147.   if(!ModeNotAvailable(NTSC_MONITOR_ID))
  148.     {
  149.      ntscavail=TRUE;
  150.      offs=2;
  151.      if(!(GetDisplayInfoData(NULL,(UBYTE *)&namebuffer,
  152.        sizeof(struct NameInfo),DTAG_NAME,NTSC_MONITOR_ID|HIRES_KEY)))
  153.         strcpy(&monitordescript[0][0],"NTSC: HIRES");
  154.      else
  155.        strcpy(&monitordescript[0][0],(char *)namebuffer.Name);
  156.  
  157.      if(!(GetDisplayInfoData(NULL,(UBYTE *)&namebuffer,
  158.        sizeof(struct NameInfo),DTAG_NAME,NTSC_MONITOR_ID|HIRESLACE_KEY)))
  159.         strcpy(&monitordescript[1][0],"NTSC: HIRES-LACE");
  160.      else
  161.        strcpy(&monitordescript[1][0],(char *)namebuffer.Name);
  162.  
  163.     }
  164.  
  165.   if(!ModeNotAvailable(PAL_MONITOR_ID))
  166.     {
  167.      palavail=TRUE;
  168.  
  169.      if(!(GetDisplayInfoData(NULL,(UBYTE *)&namebuffer,
  170.        sizeof(struct NameInfo),DTAG_NAME,PAL_MONITOR_ID|HIRES_KEY)))
  171.         strcpy(&monitordescript[offs][0],"PAL: HIRES");
  172.      else
  173.        strcpy(&monitordescript[offs][0],(char *)namebuffer.Name);
  174.  
  175.      if(!(GetDisplayInfoData(NULL,(UBYTE *)&namebuffer,
  176.        sizeof(struct NameInfo),DTAG_NAME,PAL_MONITOR_ID|HIRESLACE_KEY)))
  177.         strcpy(&monitordescript[1+offs][0],"PAL: HIRES-LACE");
  178.      else
  179.       strcpy(&monitordescript[1+offs][0],(char *)namebuffer.Name);
  180.  
  181.     }
  182.  
  183.  
  184.   NewList(&monitorlist);
  185.   AddHead(&monitorlist,&l1mode);
  186.   AddTail(&monitorlist,&l2mode);
  187.  
  188.  if(palavail&ntscavail) /* all 4 modes */
  189.   {
  190.    AddTail(&monitorlist,&l3mode);
  191.    AddTail(&monitorlist,&l4mode);
  192.   }
  193.  
  194. modeuse.ng_VisualInfo=modecancel.ng_VisualInfo=defwidth.ng_VisualInfo=
  195. defheight.ng_VisualInfo=scrwidthgadget.ng_VisualInfo=
  196. scrheightgadget.ng_VisualInfo=modelistview.ng_VisualInfo=ScreenVI;
  197.  
  198. vidmode=GetVPModeID(&FirstScreen->ViewPort);
  199.  
  200. if(!(vidmode&(PAL_MONITOR_ID|NTSC_MONITOR_ID)))/* I don't know how to get the  */
  201.   if(GfxBase->DisplayFlags&NTSC)             /* full monitor_id -> all I get */
  202.     vidmode|=NTSC_MONITOR_ID;                /* is the default monitorid     */
  203.   else                                       /* == no id,  so I have to ask  */
  204.     vidmode|=PAL_MONITOR_ID;                 /* GfxBase for default monitor  */
  205.  
  206.  
  207.  vidmode&=PAL_MONITOR_ID|NTSC_MONITOR_ID|HIRES_KEY|HIRESLACE_KEY;
  208.  
  209.   if(vidmode==(NTSC_MONITOR_ID|HIRES_KEY))
  210.     selected=0;
  211.   if(vidmode==(NTSC_MONITOR_ID|HIRESLACE_KEY))
  212.     selected=1;
  213.   if(vidmode==(PAL_MONITOR_ID|HIRES_KEY))
  214.     selected=offs;
  215.   if(vidmode==(PAL_MONITOR_ID|HIRESLACE_KEY))
  216.     selected=offs+1;
  217.  
  218. gad=CreateContext((struct Gadget **)&nullgadget);
  219.  
  220. gad=CreateGadget((ULONG)CHECKBOX_KIND,gad,&defwidth,
  221.                  GTCB_Checked,(ULONG)(defscr2&1),TAG_DONE);
  222. gad=CreateGadget((ULONG)CHECKBOX_KIND,gad,&defheight,
  223.                  GTCB_Checked,(ULONG)(defscr2&2),TAG_DONE);
  224. gad=CreateGadget((ULONG)BUTTON_KIND,gad,&modeuse,TAG_DONE);
  225. gad=CreateGadget((ULONG)BUTTON_KIND,gad,&modecancel,TAG_DONE);
  226.  
  227. widthgad=gad=CreateGadget((ULONG)INTEGER_KIND,gad,&scrwidthgadget,
  228.   GA_Disabled,(ULONG)(defscr2&1),GTIN_Number,scrwidth,GTIN_MaxChars,5L,TAG_DONE);
  229.  
  230. heightgad=gad=CreateGadget((ULONG)INTEGER_KIND,gad,&scrheightgadget,
  231.   GA_Disabled,(ULONG)(defscr2&2),GTIN_Number,scrheight,GTIN_MaxChars,5L,TAG_DONE);
  232.  
  233. gad=CreateGadget((ULONG)LISTVIEW_KIND,gad,&modelistview,GTLV_ScrollWidth,(ULONG)18,
  234.           GTLV_Labels,(void *)&monitorlist,LAYOUTA_Spacing,1L,
  235.           GTLV_Selected,selected,GTLV_ShowSelected,NULL,TAG_DONE);
  236.  
  237.  
  238. ScrModeNewWindow.Screen=FirstScreen;
  239. ScrModeNewWindow.FirstGadget=nullgadget;
  240. MouseCenterWin(&ScrModeNewWindow,0,0);
  241.  
  242. if(!(screenmodewin=OpenWindowTagList(&ScrModeNewWindow,NULL)))
  243.  {
  244.    if(nullgadget)     FreeGadgets(nullgadget);
  245.    ShowErr(9,FALSE);
  246.    return();
  247.  }
  248.  
  249. moderp=screenmodewin->RPort;
  250.  
  251. DrawBevelBox(moderp,310L,30L,298L,100L,GT_VisualInfo,(ULONG)ScreenVI,
  252.     GTBB_Recessed,(ULONG)TRUE,TAG_DONE);
  253.  
  254.  
  255.  FillSizeInfo(vidmode);
  256.  PrintIText(moderp,&modeproptxt,310L,30L); 
  257.  
  258.  
  259. GT_RefreshWindow(screenmodewin,NULL);
  260.  
  261. while(endless)
  262.  {
  263.    if(!(modemessage=GT_GetIMsg(screenmodewin->UserPort)))
  264.     {
  265.      Wait(1L<<screenmodewin->UserPort->mp_SigBit);
  266.       continue;
  267.     }
  268.  
  269.  class=modemessage->Class;
  270.  code=modemessage->Code;
  271.  
  272.  if(class&(GADGETUP|GADGETDOWN)) /* user clicked a Gadget */
  273.   {
  274.      gad=(struct Gadget *)modemessage->IAddress;
  275.      GadgetID=gad->GadgetID;
  276.   }
  277.  
  278.  
  279. switch(class)
  280. {
  281.   case IDCMP_REFRESHWINDOW:
  282.    GT_BeginRefresh(screenmodewin);
  283.    DrawBevelBox(moderp,310L,30L,298L,100L,GT_VisualInfo,(ULONG)ScreenVI,
  284.        GTBB_Recessed,(ULONG)TRUE,TAG_DONE);
  285.    PrintIText(moderp,&modeproptxt,310L,30L); 
  286.    GT_EndRefresh(screenmodewin,(LONG)TRUE);
  287.    break;
  288.  
  289.   case GADGETUP:
  290.    switch(GadgetID)
  291.     {
  292.      case 1:
  293.       endless=FALSE;
  294.       break;
  295.      case 2:
  296.       endless=FALSE;
  297.       break;
  298.  
  299.      case 3:
  300.       if(gad->Flags&SELECTED)
  301.        {
  302.         defscr2|=1;
  303.         GT_SetGadgetAttrs(widthgad,screenmodewin,NULL,GA_Disabled,(ULONG)TRUE,
  304.              GTIN_Number,(dimensionbuffer.TxtOScan.MaxX+1L),TAG_DONE);
  305.        }
  306.       else
  307.        {
  308.         defscr2&=~1;
  309.         GT_SetGadgetAttrs(widthgad,screenmodewin,NULL,GA_Disabled,(ULONG)FALSE,
  310.            TAG_DONE);
  311.        }
  312.      break;
  313.  
  314.      case 4:
  315.       if(gad->Flags&SELECTED)
  316.        {
  317.         defscr2|=2;
  318.         GT_SetGadgetAttrs(heightgad,screenmodewin,NULL,GA_Disabled,(ULONG)TRUE,
  319.             GTIN_Number,(dimensionbuffer.TxtOScan.MaxY+1L),TAG_DONE);
  320.        }
  321.       else
  322.        {
  323.         defscr2&=~2;
  324.         GT_SetGadgetAttrs(heightgad,screenmodewin,NULL,GA_Disabled,(ULONG)FALSE,
  325.            TAG_DONE);
  326.        }
  327.       break;
  328.  
  329.      case 5:  /* width */
  330.       if(((struct StringInfo *)widthgad->SpecialInfo)->LongInt<dimensionbuffer.MinRasterWidth||
  331.          ((struct StringInfo *)widthgad->SpecialInfo)->LongInt>dimensionbuffer.MaxRasterWidth)
  332.        {
  333.         GT_SetGadgetAttrs(widthgad,screenmodewin,NULL,
  334.             GTIN_Number,(dimensionbuffer.TxtOScan.MaxX+1L),TAG_DONE);
  335.         ActivateGadget(widthgad,screenmodewin,NULL);
  336.        }
  337.       else
  338.        if(!(heightgad->Flags&GFLG_DISABLED)) /* 12.09.1992 */
  339.         ActivateGadget(heightgad,screenmodewin,NULL);
  340.       break;
  341.  
  342.      case 6:  /* height */
  343.       if(((struct StringInfo *)heightgad->SpecialInfo)->LongInt<dimensionbuffer.MinRasterHeight||
  344.          ((struct StringInfo *)heightgad->SpecialInfo)->LongInt>dimensionbuffer.MaxRasterHeight)
  345.        {
  346.         GT_SetGadgetAttrs(heightgad,screenmodewin,NULL,
  347.             GTIN_Number,(dimensionbuffer.TxtOScan.MaxY+1L),TAG_DONE);
  348.         ActivateGadget(heightgad,screenmodewin,NULL);
  349.        }
  350.       else
  351.        if(!(widthgad->Flags&GFLG_DISABLED))/* 12.09.1992 */
  352.         ActivateGadget(widthgad,screenmodewin,NULL);
  353.       break;
  354.  
  355.      case 7:
  356.       selected=code;
  357.       switch(selected+2-offs) /* if only  pal -> offs=0 */
  358.        {
  359.          case 0:
  360.           vidmode=NTSC_MONITOR_ID|HIRES_KEY;
  361.           break;
  362.          case 1:
  363.           vidmode=NTSC_MONITOR_ID|HIRESLACE_KEY;
  364.           break;
  365.          case 2:
  366.           vidmode=PAL_MONITOR_ID|HIRES_KEY;
  367.           break;
  368.          case 3:
  369.           vidmode=PAL_MONITOR_ID|HIRESLACE_KEY;
  370.           break;
  371.        }
  372.       FillSizeInfo(vidmode);
  373.       PrintIText(moderp,&vissizetxt2,310L,30L);
  374.  
  375.       if((defscr2&2)||dimensionbuffer.MinRasterHeight>((struct StringInfo *)
  376.               heightgad->SpecialInfo)->LongInt)
  377.        {
  378.         GT_SetGadgetAttrs(heightgad,screenmodewin,NULL,GTIN_Number,
  379.                       (dimensionbuffer.TxtOScan.MaxY+1L));
  380.        }
  381.       if((defscr2&1)||dimensionbuffer.MinRasterWidth>((struct StringInfo *)
  382.               widthgad->SpecialInfo)->LongInt)
  383.        {
  384.         GT_SetGadgetAttrs(widthgad,screenmodewin,NULL,GTIN_Number,
  385.                       (dimensionbuffer.TxtOScan.MaxX+1L));
  386.        }
  387.      break;
  388.     }
  389.  
  390.  }
  391.  
  392.  GT_ReplyIMsg(modemessage);
  393. }
  394.  
  395.  width=((struct StringInfo *)widthgad->SpecialInfo)->LongInt;
  396.  height=((struct StringInfo *)heightgad->SpecialInfo)->LongInt;
  397.  
  398.  
  399. if(screenmodewin)  CloseWindow(screenmodewin);
  400. if(nullgadget)     FreeGadgets(nullgadget);
  401.  
  402.  
  403. if(GadgetID==1)
  404.  {
  405.   if(width<dimensionbuffer.MinRasterWidth||width>dimensionbuffer.MaxRasterWidth)
  406.     width=dimensionbuffer.TxtOScan.MaxX+1;
  407.   if(height<dimensionbuffer.MinRasterHeight||height>dimensionbuffer.MaxRasterHeight)
  408.     height=dimensionbuffer.TxtOScan.MaxY+1;
  409.  
  410.   if(vidmode!=scrmode||width!=scrwidth||height!=scrheight)
  411.    {
  412.     scrmode=vidmode;
  413.     scrheight=height;
  414.     scrwidth=width;
  415.     defscr=defscr2;
  416.     setscreenprefs(); /* set the NewScreen and NewWindow structures  */
  417.     NeueP();          /* new calculation of zero points              */
  418.  
  419.     Close_WINS();
  420.     Open_WINS();
  421.     ReDrawFuncs();
  422.    }
  423.   }
  424. }
  425.  
  426.  
  427. /*******************************************************************/
  428. /*                                                                 */
  429. /*             FillSizeInfo looks for dimensioninfo of             */
  430. /*                      the desired videomode                      */
  431. /*                         done 03.08.1992                         */
  432. /*                                                                 */
  433. /*******************************************************************/
  434.  
  435. void FillSizeInfo(ULONG modeid)
  436. {
  437.  GetDisplayInfoData(NULL,(UBYTE *)&dimensionbuffer,
  438.         sizeof(struct DimensionInfo),DTAG_DIMS,modeid);
  439.  
  440.  
  441.  if(dimensionbuffer.MinRasterWidth<640)
  442.   dimensionbuffer.MinRasterWidth=640;
  443.  
  444.  if(dimensionbuffer.MinRasterHeight<200)
  445.   dimensionbuffer.MinRasterHeight=200;
  446.  
  447.  
  448.  sprintf(monitormaxsize,"%5d  x  %5d",dimensionbuffer.MaxRasterWidth,
  449.                                     dimensionbuffer.MaxRasterHeight);
  450.  
  451.  sprintf(monitorminsize,"%5d  x  %5d",dimensionbuffer.MinRasterWidth,
  452.                                     dimensionbuffer.MinRasterHeight);
  453.  
  454.  sprintf(monitorvissize,"%5d  x  %5d",dimensionbuffer.TxtOScan.MaxX+1,
  455.                                     dimensionbuffer.TxtOScan.MaxY+1);
  456.  
  457.  strcpy(colorstring,"8");
  458. }
  459.  
  460.  
  461.  
  462. /*******************************************************************/
  463. /*                                                                 */
  464. /*             Center a window under the mousepointer              */
  465. /*                needs a lot of security checks!!!                */
  466. /*                 done 03.08.1992 and 04.08.1992                  */
  467. /*                                                                 */
  468. /*******************************************************************/
  469.  
  470. void MouseCenterWin(struct NewWindow *win,short xoffs, short yoffs)
  471. {
  472.  short middley,middlex;
  473.  
  474.  middley=FirstScreen->MouseY-win->Height/2+yoffs;
  475.  middlex=FirstScreen->MouseX-win->Width/2+yoffs;
  476.  
  477.  if(middley<(-FirstScreen->TopEdge))
  478.    middley=-FirstScreen->TopEdge;
  479.  
  480.  if(middley+win->Height>=dimensionbuffer.TxtOScan.MaxY+(-FirstScreen->TopEdge))
  481.     middley=-FirstScreen->TopEdge+dimensionbuffer.TxtOScan.MaxY-win->Height;
  482.  
  483. if(middley+win->Height>=scrheight)  /* still needed if screen is smaller */
  484.     middley=scrheight-win->Height;  /* than TxtOScan !!                  */
  485.  
  486.  
  487.  if(middlex<(-FirstScreen->LeftEdge))
  488.    middlex=-FirstScreen->LeftEdge;
  489.  
  490.  if(middlex+win->Width>=dimensionbuffer.TxtOScan.MaxX+(-FirstScreen->LeftEdge))
  491.     middlex=-FirstScreen->LeftEdge+dimensionbuffer.TxtOScan.MaxX-win->Width;
  492.  
  493.  if(middlex+win->Width>=scrwidth)
  494.     middlex=scrwidth-win->Width;
  495.  
  496.  if(middlex<0) middlex=0;
  497.  if(middley<0) middley=0;
  498.  
  499.  win->TopEdge=middley;
  500.  win->LeftEdge=middlex;
  501.  
  502. }
  503.  
  504.  
  505.  
  506.  
  507. /*******************************************************************/
  508. /*                                                                 */
  509. /*     changecolor() calls the color requester from req.libary     */
  510. /*            or the official color tool from workbench            */
  511. /*          default name for color tool is in globdata.c           */
  512. /* added 17.11.1991                                                */
  513. /*******************************************************************/
  514.  
  515. void changecolor(void)
  516. {
  517.   if(ReqBase)
  518.     ColorRequester(0L);
  519.   else
  520.     Execute((UBYTE *)coltoolname,NULL,NULL);
  521.  
  522.   getcolors();  /* read the new ColorMap from Viewport */
  523. }               /* and store it to mycolors[]          */
  524.  
  525.  
  526. /*******************************************************************/
  527. /*                                                                 */
  528. /*      setcolors() reads colortable mycolors[] and sets them      */
  529. /*                     to the screens ColorMap                     */
  530. /*                                                                 */
  531. /*******************************************************************/
  532.  
  533. void setcolors(void)
  534. {
  535.  short i;
  536.  
  537.  for(i=0;i<8;i++)
  538.   SetRGB4(&FirstScreen->ViewPort,(long)i,(long)mycolors[i*3],
  539.     (long)mycolors[i*3+1],(long)mycolors[i*3+2]);
  540. }
  541.  
  542.  
  543. /*******************************************************************/
  544. /*                                                                 */
  545. /*     getcolors() reads colors from ColorMap and cpoies them      */
  546. /*                          to mycolors[]                          */
  547. /*                                                                 */
  548. /*******************************************************************/
  549.  
  550. void getcolors(void)
  551. {
  552.   long color;
  553.   short i;
  554.  
  555.     for(i=0;i<8;i++)
  556.      {
  557.        color=GetRGB4(FirstScreen->ViewPort.ColorMap,(long)i);
  558.        mycolors[i*3]=(color>>8)&0xf;
  559.        mycolors[i*3+1]=(color>>4)&0xf;
  560.        mycolors[i*3+2]=color&0xf;
  561.      }
  562. }
  563.  
  564. /*******************************************************************/
  565. /*                                                                 */
  566. /*          setscreenprefs changes my screen and windows           */
  567. /*             to fit the size given in scrheight and              */
  568. /*         scrwidth (->getscreenprefs, ->changescreenmode)         */
  569. /*                                                                 */
  570. /*******************************************************************/
  571.  
  572.  
  573. void setscreenprefs(void)
  574. {
  575.  extern struct TagItem ExtDef[];
  576.  
  577.  ExtDef[0].ti_Data=scrmode;
  578.  
  579.  FillSizeInfo(scrmode); /* 03.08.1992 */
  580.  
  581.  FirstNewScreen.Height=scrheight;
  582.  FirstNewScreen.Width=scrwidth;
  583.  
  584.  FirstNewWindow.Height=scrheight-10;
  585.  winheightmax=scrheight-11;
  586.  FirstNewWindow.Width=scrwidth;
  587.  
  588.  SecondNewWindow.LeftEdge=scrwidth-SecondNewWindow.Width;
  589.  
  590.  FourthNewWindow.Height=scrheight-10;
  591.  
  592. }
  593.  
  594. /*******************************************************************/
  595. /*                                                                 */
  596. /*      getscreenprefs() reads Screensize values from GfxBase      */
  597. /*                                                                 */
  598. /*******************************************************************/
  599.  
  600. void getscreenprefs(void)
  601. {
  602.  defscr=3; /* default height and width */
  603.  
  604.  if(GfxBase->DisplayFlags&NTSC)
  605.    scrmode=NTSC_MONITOR_ID|HIRES_KEY;
  606.  else
  607.    scrmode=PAL_MONITOR_ID|HIRES_KEY;
  608.  
  609.  FillSizeInfo(scrmode); /* 03.08.1992 */
  610.  
  611.  scrheight=dimensionbuffer.TxtOScan.MaxY+1;
  612.  scrwidth=dimensionbuffer.TxtOScan.MaxX+1;
  613.  
  614. }
  615.  
  616.  
  617. /*******************************************************************/
  618. /*                                                                 */
  619. /* extLoadConfig() loads the configuration from a user choosen file*/
  620. /* if there is no req.library it loads the config from the default */
  621. /*                pathname as defined in globdata.c                */
  622. /*                                                                 */
  623. /*       all load and save functions from 19. and 20.11.1991       */
  624. /*       changed 06.08.1992 for asl filerequester                  */
  625. /*******************************************************************/
  626.  
  627. void extLoadConfig(void)
  628. {
  629.   long oldscrmode,oldscrwidth,oldscrheight;
  630.   short flag=FALSE;
  631.  
  632.   oldscrmode=scrmode;
  633.   oldscrwidth=scrwidth;
  634.   oldscrheight=scrheight;
  635.  
  636.  MouseCenterWin(&ThirdNewWindow,0,0); /* 27.09.1992 */
  637.  
  638.  myaslFileReq=AllocAslRequestTags((ULONG)ASL_FileRequest,ASL_Dir,&configdir[0],
  639.  ASL_Hail,LoadText,ASL_File,&configfile[0],ASL_Pattern,"#?.config",
  640.  ASL_Window,FirstWindow,ASL_LeftEdge,(long)ThirdNewWindow.LeftEdge,
  641.  ASL_TopEdge,(long)ThirdNewWindow.TopEdge,
  642.  ASL_FuncFlags,FILF_NEWIDCMP|FILF_PATGAD,TAG_DONE);
  643.  
  644.  pathnamearray=AllocMem(NAMELEN,MEMF_PUBLIC);
  645.  
  646.  
  647.  if(!pathnamearray||!myaslFileReq)/* did I get all the memory  ?  */
  648.    {                              /* no -> so clear it            */
  649.      clearfilemem();              /* show "Out of memory !"       */
  650.      ShowErr(14,FALSE); 
  651.      return();
  652.    }
  653.  
  654.    if(RequestFile(myaslFileReq))/* zero lenght if cancel request */
  655.     {
  656.     if (myaslFileReq->rf_Dir)
  657.      strncpy(pathnamearray,(void *)myaslFileReq->rf_Dir,NAMELEN);
  658.     else
  659.      pathnamearray[0]='\0';
  660.  
  661.     AddPart((UBYTE *)pathnamearray,(UBYTE *)myaslFileReq->rf_File,NAMELEN);
  662.  
  663.      LoadConfig(pathnamearray);
  664.      flag=TRUE;
  665.     }
  666.  
  667. clearfilemem();
  668.  
  669. if(flag) /* I load something */
  670.  {
  671.   if(scrmode!=oldscrmode||scrwidth!=oldscrwidth||scrheight!=oldscrheight)
  672.    {
  673.      Close_WINS();  /* screen settings have been changed      */
  674.      Open_WINS();   /* so close screen and open the new one   */
  675.      ReDrawFuncs(); /* needed changes in New.. structures are */
  676.    }                /* done from LoadConfig                   */
  677.   else /* I don't wanna check all fields  -> so always set them  */
  678.    {
  679.     setcolors(); /* if changed screen, Open_WINS() does this calls for me */
  680.     Clear();
  681.     Maus();
  682.     ReDrawFuncs();
  683.    }
  684.  }
  685. }
  686.  
  687.  
  688.  
  689. /*******************************************************************/
  690. /*                                                                 */
  691. /*     clearfilemem() frees all used memory for filerequester      */
  692. /*                                                                 */
  693. /*******************************************************************/
  694.  
  695. void  clearfilemem(void)
  696. {
  697.   if(myaslFileReq)   FreeAslRequest(myaslFileReq);
  698.   if(pathnamearray)  FreeMem(pathnamearray, (long)(REQ_DSIZE+REQ_FCHARS)+2L);
  699. }
  700.  
  701. /* BOOL resfilemem() {}  cleared 06.08.1992 */
  702.  
  703.  
  704.  
  705. /*******************************************************************/
  706. /*                                                                 */
  707. /*   doreqreq() sets some needed flags in the FileReq structure    */
  708. /*         and then pops up the req.library FileRequester          */
  709. /*                                                                 */
  710. /*******************************************************************/
  711.  
  712. /* void doreqreq(void) {}  cleared 06.08.1992 */
  713.  
  714.  
  715.  
  716. /*******************************************************************/
  717. /*                                                                 */
  718. /*   extSaveConfig() saves the configuration to a specific file    */
  719. /*           therefore it uses req.library FileRequester           */
  720. /*      if there is no req.library it saves to s:Kurve.config      */
  721. /*                     the default configfile                      */
  722. /* changed 06.08.1992                                              */
  723. /*******************************************************************/
  724.  
  725. void extSaveConfig(void)
  726. {
  727.  
  728.  MouseCenterWin(&ThirdNewWindow,0,0); /* 27.09.1992 */
  729.  
  730.  myaslFileReq=AllocAslRequestTags((ULONG)ASL_FileRequest,ASL_Dir,&configdir[0],
  731.  ASL_Hail,SaveText,ASL_File,&configfile[0],ASL_Pattern,"#?.config",ASL_Window,
  732.  FirstWindow,ASL_LeftEdge,(long)ThirdNewWindow.LeftEdge,
  733.  ASL_TopEdge,(long)ThirdNewWindow.TopEdge,
  734.  ASL_FuncFlags,FILF_SAVE|FILF_NEWIDCMP|FILF_PATGAD,TAG_DONE);
  735.  
  736.  pathnamearray=AllocMem(NAMELEN,MEMF_PUBLIC);
  737.  
  738.      if(!myaslFileReq||!pathnamearray) /* did I get all the memory  ?  */
  739.       {                                /* no -> so clear it            */
  740.        clearfilemem();                 /* show "Out of memory !"       */
  741.        ShowErr(14,FALSE);
  742.        return();
  743.       }
  744.  
  745.      if(RequestFile(myaslFileReq)) /*  zero if cancel request */
  746.       {
  747.         if (myaslFileReq->rf_Dir)
  748.           strncpy(pathnamearray,(void *)myaslFileReq->rf_Dir,NAMELEN);
  749.         else
  750.           pathnamearray[0]='\0';
  751.  
  752.         AddPart((UBYTE *)pathnamearray,(UBYTE *)myaslFileReq->rf_File,NAMELEN);
  753.  
  754.         SaveConfig(pathnamearray);
  755.       }
  756.     clearfilemem();           /* free the used memory */
  757. }
  758.  
  759.  
  760. /******************************************/
  761. /*                                        */
  762. /*     Configuration abspeichern          */
  763. /*                                        */
  764. /******************************************/
  765.  
  766. void SaveConfig(char * filename)
  767. {
  768.   short fd;
  769.  
  770.  if(!filename)
  771.    filename=&configpath[0];
  772.  
  773.  fd=open(filename,O_WRONLY+O_CREAT);
  774.  
  775.  if(fd != -1)
  776.   {
  777.      write(fd,activeFunc->Func,(size_t)255); /* changed from funktion to     */
  778.      write(fd,minx,(size_t)20);              /* activeFunc->Func  17.04.1992 */
  779.      write(fd,maxx,(size_t)20);
  780.      write(fd,miny,(size_t)20);
  781.      write(fd,maxy,(size_t)20);
  782.      write(fd,&scrmode,(size_t)4);
  783.      write(fd,&scrheight,(size_t)4);
  784.      write(fd,&scrwidth,(size_t)4);
  785.      write(fd,&mycolors[0],(size_t)24);
  786.      write(fd,&defscr,(size_t)2); /* 03.08.1992 */
  787.    
  788.      close(fd);
  789.   }
  790.  
  791. }
  792.  
  793.  
  794. /******************************************/
  795. /*                                        */
  796. /*          Configuration laden           */
  797. /*                                        */
  798. /******************************************/
  799.  
  800. void LoadConfig(char * filename)
  801. {
  802.  short fd;
  803.  
  804.  if(!filename)
  805.    filename=&configpath[0];
  806.  
  807.  fd=open(filename,O_RDONLY);
  808.  
  809.  if(fd != -1)
  810.   {
  811.      funktion1[0]=0;
  812.      funktion2[0]=0;
  813.      read(fd,funktion,(size_t)255);
  814.      read(fd,minx,(size_t)20);
  815.      read(fd,maxx,(size_t)20);
  816.      read(fd,miny,(size_t)20);
  817.      read(fd,maxy,(size_t)20);
  818.      if(read(fd,&scrmode,(size_t)4)) /* so it handels old Kurve.config too */
  819.       {                              /* 19.11.1991 */
  820.         read(fd,&scrheight,(size_t)4);
  821.         read(fd,&scrwidth,(size_t)4);
  822.         read(fd,&mycolors[0],(size_t)24);
  823.         if(!read(fd,&defscr,(size_t)2))
  824.            defscr=0;
  825.       }
  826.      else
  827.       getscreenprefs();
  828.      close(fd);
  829.   }
  830.  else
  831.   {
  832.     strcpy((char *)funktion,"sin(x)");
  833.     strcpy((char *)funktion1,"cos(x)");
  834.     strcpy((char *)funktion2,"-sin(x)");
  835.  
  836.     xmin=-5.0;
  837.     ymin=-10.0;
  838.     xmax=5.0;
  839.     ymax=10.0;
  840.  
  841.     printpara(minx,xmin);
  842.     printpara(miny,ymin);
  843.     printpara(maxx,xmax);
  844.     printpara(maxy,ymax);
  845.     getscreenprefs();
  846.   }
  847.  
  848.  
  849. if(!activeFunc)
  850.     addfuncnode();
  851.  else
  852.    changefuncnode(activeFunc);
  853.  
  854.  
  855.  NeueP();
  856.  setscreenprefs();
  857.  
  858. }
  859.  
  860.  
  861. /*******************************************************************/
  862. /*                                                                 */
  863. /*     handlesave() opens a file requester and then saves the      */
  864. /*      complete list of functions via writefunclist() to the      */
  865. /*      choosen file                          done 20.01.1992      */
  866. /*                                                                 */
  867. /*******************************************************************/
  868.  
  869. void handlesave(void)
  870. {
  871.   BPTR fp;
  872.  
  873.   MouseCenterWin(&ThirdNewWindow,-20,-90); /* 27.09.1992 */
  874.  
  875.  myaslFileReq=AllocAslRequestTags((ULONG)ASL_FileRequest,ASL_Dir,funcdir,
  876.  ASL_Hail,"Save functionlist",ASL_File,funcfile,ASL_Pattern,"#?.kur",
  877.  ASL_Window,FuncReqWindow,ASL_LeftEdge,(long)ThirdNewWindow.LeftEdge,
  878.  ASL_TopEdge,(long)ThirdNewWindow.TopEdge,ASL_FuncFlags,
  879.  FILF_SAVE|FILF_NEWIDCMP|FILF_PATGAD,TAG_DONE);
  880.  
  881.   pathnamearray=AllocMem(NAMELEN,MEMF_PUBLIC);
  882.  
  883.      if(!myaslFileReq||!pathnamearray) /* get memory for requester     */
  884.       {                                /* did I get all the memory  ?  */
  885.        clearfilemem();                 /* no -> so clear it            */
  886.        ShowErr(14,FALSE);              /* show "Out of memory !"       */
  887.        return();
  888.      }
  889.  
  890.      if(RequestFile(myaslFileReq))
  891.       {
  892.         if (myaslFileReq->rf_Dir)
  893.          strncpy(pathnamearray,(void *)myaslFileReq->rf_Dir,NAMELEN);
  894.         else
  895.          pathnamearray[0]='\0';
  896.  
  897.         AddPart((UBYTE *)pathnamearray,(UBYTE *)myaslFileReq->rf_File,NAMELEN);
  898.  
  899.         if(fp=Open((UBYTE *)pathnamearray,(long)MODE_NEWFILE))
  900.           {
  901.            SetPointer(FuncReqWindow,mousemem,16L,16L,0L,0L);
  902.            writefunclist(fp,TRUE);
  903.            Close(fp);
  904.            ClearPointer(FuncReqWindow);
  905.           }
  906.       }
  907.      clearfilemem();
  908. }
  909.  
  910.  
  911. /*******************************************************************/
  912. /*                                                                 */
  913. /*           handleload() open a file requester and then           */
  914. /*           tries to load a file via readfunclist with            */
  915. /*           a list of functions        done 01.02.1992            */
  916. /*                                                                 */
  917. /*******************************************************************/
  918.  
  919. void handleload(long *n,long *top)
  920. {
  921.   FILE *fp;
  922.   struct FuncNode *ptr1,*ptr2;
  923.   long vertb,count=1;
  924.  
  925.   ptr1=FirstFunc;
  926.   ptr2=activeFunc;
  927.  
  928.   MouseCenterWin(&ThirdNewWindow,-20,-80); /* 27.09.1992 */
  929.  
  930.   myaslFileReq=AllocAslRequestTags((ULONG)ASL_FileRequest,ASL_Hail,
  931.   "Load functionlist",ASL_File,funcfile,ASL_Dir,funcdir,ASL_Pattern,"#?.kur",
  932.   ASL_Window,FuncReqWindow,ASL_LeftEdge,(long)ThirdNewWindow.LeftEdge,
  933.   ASL_TopEdge,(long)ThirdNewWindow.TopEdge,
  934.   ASL_FuncFlags,FILF_NEWIDCMP|FILF_PATGAD,TAG_DONE);
  935.  
  936.   pathnamearray=AllocMem(NAMELEN,MEMF_PUBLIC);
  937.  
  938.      if(!myaslFileReq||!pathnamearray)/* get memory for requester     */
  939.       {                               /* did I get all the memory  ?  */
  940.        clearfilemem();                /* no -> so clear it            */
  941.        ShowErr(14,FALSE);             /* show "Out of memory !"       */
  942.        return();
  943.      }
  944.  
  945.  
  946.      if(RequestFile(myaslFileReq))
  947.       {
  948.         if (myaslFileReq->rf_Dir)
  949.          strncpy(pathnamearray,(void *)myaslFileReq->rf_Dir,NAMELEN);
  950.         else
  951.          pathnamearray[0]='\0';
  952.  
  953.         AddPart((UBYTE *)pathnamearray,(UBYTE *)myaslFileReq->rf_File,NAMELEN);
  954.  
  955.         if(fp=fopen((const char *)pathnamearray,"r"))
  956.           {
  957.            SetPointer(FuncReqWindow,mousemem,16L,16L,0L,0L);
  958.            FirstFunc=0;
  959.            if(!readfunclist(fp))
  960.             {
  961.              if(FirstFunc)
  962.                delallfuncs();
  963.              FirstFunc=ptr1;
  964.              activatefunc(ptr2);
  965.             }
  966.            else
  967.             {
  968.              ptr2=FirstFunc;
  969.              FirstFunc=ptr1;
  970.              delallfuncs();
  971.              FirstFunc=ptr2;
  972.              activatefunc(FirstFunc);
  973.              printactivefunc();
  974.              updatedisplay(0L);
  975.              Clear();  /* delete displayed old functions in FirstWindow */
  976.  
  977.             while(ptr2=ptr2->Next)
  978.               count++;
  979.  
  980.             if(count>8)
  981.              vertb=(MAXBODY*8L)/(count);
  982.             else
  983.              vertb=MAXBODY;
  984.  
  985.              *n=count;
  986.              *top=0;
  987.  
  988.              NewModifyProp(&FuncPropGadget,FuncReqWindow,NULL,(long)AUTOKNOB|
  989.               FREEVERT|PROPBORDERLESS,NULL,NULL,NULL,vertb,1L);
  990.             }
  991.            fclose(fp);
  992.            ClearPointer(FuncReqWindow);
  993.           }
  994.       }
  995.      clearfilemem();
  996. }
  997.  
  998.  
  999. /*******************************************************************/
  1000. /*                                                                 */
  1001. /*         readfunclist() reads the file pointed by fp and         */
  1002. /*         tries to alloc FuncNodes       done 01.02.1992          */
  1003. /*                                                                 */
  1004. /*******************************************************************/
  1005.  
  1006. BOOL readfunclist(FILE *fp)
  1007. {
  1008.   char *i;
  1009.   UWORD pattern;
  1010.   UndoBuffer[0]=0;
  1011.  
  1012.  
  1013.  do  /* read the overhead before first function */
  1014.   {
  1015.    if(!fgets((char *)UndoBuffer,280,fp)) /* 17.04.1992  old version */
  1016.     return(FALSE);                       /* reads only 256 bytes    */
  1017.   }
  1018.  while(strncmp((const char *)UndoBuffer,"Function",8L));
  1019.  
  1020. while(!feof(fp))
  1021.  {
  1022.    funktion[0] = funktion1[0]= funktion2[0] =0;
  1023.  
  1024.  do
  1025.   {
  1026.     UndoBuffer[0]=0;
  1027.  
  1028.    if(!fgets((char *)UndoBuffer,280,fp))  /* 17.04.1992 */
  1029.     break;            /* lets add the last function */
  1030.  
  1031.    i=strrchr((const char *)UndoBuffer,'=');
  1032.    if(i)
  1033.     {
  1034.      i++;
  1035.      i[strlen(i)-1L]=0;
  1036.     }
  1037.  
  1038.    if(!strncmp((const char *)UndoBuffer,"f ",2L))
  1039.      {
  1040.        if(!i)  /* there must be a '=' */
  1041.         continue;
  1042.  
  1043.        strcpy((char *)funktion,(const char *)i);
  1044.        continue;
  1045.      }
  1046.  
  1047.    if(!strncmp((const char *)UndoBuffer,"fa1",3L))
  1048.      {
  1049.        if(!i)  /* there must be a '=' */
  1050.         continue;
  1051.  
  1052.        strcpy((char *)funktion1,(const char *)i);
  1053.        continue;
  1054.      }
  1055.  
  1056.    if(!strncmp((const char *)UndoBuffer,"fa2",3L))
  1057.      {
  1058.        if(!i)  /* there must be a '=' */
  1059.         continue;
  1060.  
  1061.        strcpy((char *)funktion2,(const char *)i);
  1062.        continue;
  1063.      }
  1064.  
  1065.    if(!strncmp((const char *)UndoBuffer,"Pattern",7L))
  1066.      {
  1067.        if(!i)  /* there must be a '=' */
  1068.         continue;
  1069.  
  1070. /*       sscanf((const char *)i,"%hx",&pattern); */
  1071.  
  1072.        stripstr(i);  /* cut spaces and strlwr() */
  1073.  
  1074.        if(!strncmp((const char *)i,"0x",2L))
  1075.         {
  1076.          pattern=hextol(i);
  1077.          continue;
  1078.         }
  1079.        else
  1080.         continue;
  1081.      }  
  1082.   }while(strncmp((const char *)UndoBuffer,"Function",8L));
  1083.  
  1084.   if(checkfuncs())
  1085.    {
  1086.     fehler=0;
  1087.     return(FALSE);
  1088.    }
  1089.   
  1090.   if(!addfuncnode())
  1091.     return(FALSE);
  1092.  
  1093.   if(!pattern)
  1094.     pattern=0xffff;
  1095.  
  1096.    activeFunc->FuncPattern=pattern;
  1097.  }
  1098.  
  1099.  return(TRUE);
  1100. }
  1101.  
  1102.  
  1103. /*******************************************************************/
  1104. /*                                                                 */
  1105. /*          writefunclist() writes all or only displayed           */
  1106. /*             functions into the file pointed by fp               */
  1107. /*                        done 20.01.1992                          */
  1108. /*                                                                 */
  1109. /*******************************************************************/
  1110.  
  1111. BOOL writefunclist(BPTR fp,BOOL t)
  1112. {
  1113.   struct FuncNode *nodeptr;
  1114.   long i=1;
  1115.   char *memp;
  1116.  
  1117.   if(!(memp=AllocMem(300L,NULL)))
  1118.     {
  1119.        ShowErr(14,FALSE);
  1120.        return();
  1121.     }
  1122.  
  1123.   nodeptr=FirstFunc;
  1124.  
  1125.   if(t)
  1126.    strcpy(memp,"List of all functions stored in Kurve!\n\n");
  1127.   else
  1128.    strcpy(memp,"List of displayed functions!\n\n");
  1129.     if(Write(fp,memp,strlen(memp))==-1)
  1130.         return(FALSE);
  1131.  
  1132.  
  1133.   do
  1134.    {
  1135.     if((nodeptr->isdrawn&0x07)|t)  /* prints only if t=TRUE and one part of */
  1136.      {                             /* the function is drawn                 */
  1137.        sprintf(memp,"Function %ld:\n",i);
  1138.        if(Write(fp,memp,strlen(memp))==-1)
  1139.          return(FALSE);
  1140.      }
  1141.  
  1142.     if((nodeptr->isdrawn&0x01)|t) /* only if t and function is drawn  */
  1143.      {
  1144.        sprintf(memp,"f   = %s\n",nodeptr->Func);
  1145.        if(Write(fp,memp,strlen(memp))==-1)
  1146.          return(FALSE);
  1147.      }
  1148.  
  1149.     if((nodeptr->isdrawn&0x02)|t)/* only if t and 1st diff. is drawn  */
  1150.      {
  1151.        sprintf(memp,"fa1 = %s\n",nodeptr->Func1);
  1152.        if(Write(fp,memp,strlen(memp))==-1)
  1153.          return(FALSE);
  1154.      }
  1155.  
  1156.     if((nodeptr->isdrawn&0x03)|t)/* only if t and 2nd diff. is drawn  */
  1157.      {
  1158.        sprintf(memp,"fa2 = %s\n",nodeptr->Func2);
  1159.        if(Write(fp,memp,strlen(memp))==-1)
  1160.          return(FALSE);
  1161.      }
  1162.  
  1163.     if((nodeptr->isdrawn&0x07)|t)/* see above ^^^^ */
  1164.      {
  1165.       sprintf(memp,"Pattern = 0x%x\n\n",nodeptr->FuncPattern);
  1166.       if(Write(fp,memp,strlen(memp))==-1)
  1167.          return(FALSE);
  1168.      }
  1169.  
  1170.     i++;
  1171.    }while(nodeptr=nodeptr->Next);
  1172.  
  1173.  return(TRUE);
  1174. }
  1175.  
  1176.  
  1177. /*******************************************************************/
  1178. /*                                                                 */
  1179. /*         helpdruck() writes the displayed functions to a         */
  1180. /*          temporary file and then reload it into memory          */
  1181. /*         controlled by drucken()        done 28.01.1992          */
  1182. /*                                                                 */
  1183. /*******************************************************************/
  1184.  
  1185. void helpdruck(UBYTE **memblck, long *len)
  1186. {
  1187.   BPTR         fp;
  1188.   UBYTE        tempname[]="ram:Kurve.TMP";
  1189.  
  1190.   *len=0;
  1191.  
  1192.   if(fp=Open(tempname,(long)MODE_NEWFILE))
  1193.    {
  1194.      writefunclist(fp,FALSE);  /* write dispalyed functions  */
  1195.      Close(fp);
  1196.    }
  1197.   else
  1198.     return();
  1199.  
  1200.  
  1201.   if(!(*len=filelength(tempname))) /* get filelength */
  1202.    {
  1203.     DeleteFile(tempname);
  1204.     return();
  1205.    }
  1206.  
  1207.   if(*memblck=AllocMem(*len,NULL)) /* allocate mem and load temporary file */
  1208.    {
  1209.     if(fp=Open(tempname,(long)MODE_OLDFILE))
  1210.      {
  1211.       Read(fp,*memblck,*len);
  1212.       Close(fp);
  1213.     }
  1214.    }
  1215.   else
  1216.     *len=0;
  1217.  
  1218.    DeleteFile(tempname);
  1219.  
  1220. }
  1221.  
  1222.  
  1223. /*******************************************************************/
  1224. /*                                                                 */
  1225. /*           filelenght() returns the lenght of the file           */
  1226. /*           given with name            done 28.01.1992            */
  1227. /*                                                                 */
  1228. /*******************************************************************/
  1229.  
  1230. long filelength(UBYTE * name)
  1231. {
  1232.   struct FileInfoBlock  *fib;
  1233.   long   len;
  1234.   BPTR   fp;
  1235.  
  1236.  
  1237.      /* struct FileInfoBlock must be longword aligned !! */
  1238.   if(!(fib=AllocMem(sizeof(struct FileInfoBlock),(long)MEMF_CLEAR)))
  1239.     return(0L);
  1240.  
  1241.   if(fp=Lock(name,(long)ACCESS_READ))
  1242.    {
  1243.      Examine(fp,fib);  /* fill FileInfoBlock with information  */
  1244.      len=fib->fib_Size;
  1245.      UnLock(fp);
  1246.    }
  1247.   else
  1248.     len=0L;
  1249.  
  1250.   FreeMem(fib,sizeof(struct FileInfoBlock));
  1251.  
  1252.  return(len);
  1253.  
  1254. }
  1255.  
  1256.  
  1257. /*******************************************************************/
  1258. /*                                                                 */
  1259. /*              hextol() converts a hex string to a                */
  1260. /*                        signed long value                        */
  1261. /*            created 14.10.1990   inserted 02.02.1992             */
  1262. /*                                                                 */
  1263. /*******************************************************************/
  1264.  
  1265. long hextol(char *string)
  1266. {
  1267.   long i,n;
  1268.   long wert=0;
  1269.  
  1270.   string+=2L;  /* jump over leading '0x'   */
  1271.   n=strlen(string)-1L;
  1272.  
  1273.   for(i=0;i<=n;i++)
  1274.    {
  1275.      if(isxdigit(string[i]))
  1276.       {
  1277.         if(isdigit(string[i]))
  1278.            wert+=(1L<<((n-i)*4))*(string[i]-'0');
  1279.         else
  1280.            wert+=(1L<<((n-i)*4))*(toupper(string[i])-'7');
  1281.       }
  1282.      else
  1283.        return(0L);
  1284.    }
  1285.  return(wert);
  1286. }
  1287.  
  1288.