home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d165 / plotview.lha / PlotView / plotview.c < prev    next >
C/C++ Source or Header  |  1988-11-22  |  16KB  |  764 lines

  1. /*
  2.      plot2am.c : Plot Unix plot files on an Amiga HIRES Screen.
  3.  
  4.      By Joel Swank April, 1988
  5.  
  6.      */
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <exec/tasks.h>
  10. #include <intuition/intuition.h>
  11. #include <stdio.h>
  12. /*  The header files needed for gadget definitions  */ 
  13. #include <intuition/intuitionbase.h> 
  14. #include <libraries/dosextens.h> 
  15. #include <graphics/gfxbase.h> 
  16. #include <graphics/gfx.h> 
  17. #include <graphics/gfxmacros.h> 
  18. #include <graphics/display.h> 
  19.  
  20. #include <graphics/text.h> 
  21. #include <devices/printer.h> 
  22. #include <ctype.h> 
  23.  
  24. #include "plotview.h" 
  25. #include "fileio.h"
  26.  
  27. #ifdef NULL
  28. #undef NULL
  29. #endif
  30. #define NULL ((void *)0)
  31.  
  32. #define INTUITION_REV 1L
  33.  
  34. struct    TextAttr stdattr = {
  35.     (STRPTR)("topaz.font"),
  36.     8,
  37.     0,
  38.     FPB_DISKFONT};
  39. struct    TextFont *stdfont = NULL;
  40.  
  41. struct    TextAttr myattr = {
  42.     (STRPTR)("puny.font"),
  43.     7,
  44.     0,
  45.     FPB_DISKFONT};
  46. struct    TextFont *myfont = NULL;
  47.  
  48.  
  49. /*
  50.  * GLOBAL data definitions
  51.  */
  52. static struct Window    *Wind = NULL ;
  53. static struct Screen    *MyScreen = NULL ;
  54. struct FileIOSupport *FIOSupp = NULL;
  55. extern struct IntuitionBase    *IntuitionBase ;
  56. extern struct DosLibrary *DosBase ;
  57. extern struct GfxBase *GfxBase ;
  58. struct RastPort *rp;    /* Main window rastport */
  59. struct RastPort *Srp;    /* Scale window rastport */
  60. struct Library *DiskfontBase = NULL;
  61. FILE *input;    /* input file pointer */
  62.  
  63. struct MsgPort    *CreatePort() ;
  64. struct TextFont *OpenDiskFont() ;
  65. struct TextFont *OpenFont() ;
  66.  
  67. /* scaling factors */
  68.  
  69. long xscale, yscale;    /* width, height of output device */
  70. long xmult, ymult;      /* width, height on Amiga Screen */
  71. long xoff, yoff;        /* offset to lower left corner  */
  72. long xscaleu, yscaleu;  /* user specified width, height of output device */
  73. long xoffu, yoffu;        /* user specified offset to lower left corner  */
  74. int override = FALSE;   /* TRUE for use user specified */
  75.  
  76. /* linemode constants */
  77.  
  78. char *lmodestr[] = { "dotted",
  79.                      "solid",
  80.                      "longdashed",
  81.                      "shortdashed",
  82.                      "dotdashed" };
  83.  
  84. USHORT lmode[] = { 0xaaaa, 0xffff, 0xff00, 0xf0f0, 0xf2f2 };
  85.  
  86. char reqtitle[] = "Select an Input Plot File";
  87.  
  88. main(argc,argv)
  89. int argc;
  90. char *argv[];
  91. {
  92. long menunum;
  93. char *p;
  94.  
  95. struct IntuiMessage    *msg;
  96.  
  97. /*************************************************
  98.      Init defaults
  99. *************************************************/
  100.  
  101. xscaleu = 3120;
  102. yscaleu = 3120;
  103. xmult = 550;
  104. ymult = 400;
  105. xoffu = 0;
  106. yoffu = 0;
  107.  
  108.  
  109. /*************************************************
  110.      OPEN everything
  111. *************************************************/
  112.  
  113.  
  114. if ((IntuitionBase = (struct IntuitionBase *)
  115.     OpenLibrary("intuition.library", INTUITION_REV)) == NULL)
  116.     done(21);
  117.  
  118. GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", NULL);
  119. if (GfxBase == NULL) done(22);
  120.  
  121. DiskfontBase = (struct Library *)OpenLibrary("diskfont.library", NULL);
  122. if (DiskfontBase == NULL) {
  123.     fprintf(stderr,"plot2am:cannot open font library - using default font\n");
  124.     }
  125.  
  126. if ((DosBase = (struct DosLibrary *)OpenLibrary("dos.library", 0)) == NULL)
  127.     done(27);
  128.  
  129. if ((MyScreen = (struct Screen *) OpenScreen(&NewScreenStructure)) == NULL)
  130.     done(23);
  131.  
  132. New_Window.Screen = MyScreen;
  133.  
  134. if ((Wind = (struct Window *) OpenWindow(&New_Window)) == NULL)
  135.     done(25);
  136. rp = Wind->RPort;
  137.  
  138. if (DiskfontBase != NULL) {
  139.     if ((myfont = (struct TextFont *)OpenDiskFont(&myattr)) == NULL) {
  140.         fprintf(stderr,"plot2am:cannot find puny font - using default\n");
  141.     } else  SetFont(rp,myfont);
  142. }
  143.  
  144. if (NULL == (FIOSupp = GetFileIOSupport()))
  145.     done(26);
  146.  
  147.  
  148.  
  149. LoadRGB4(&(MyScreen->ViewPort),&Palette,PaletteColorCount);
  150.  
  151. /*************************************************
  152.      Interrogate command line 
  153. *************************************************/
  154.  
  155.  
  156.  
  157. while (argc > 1)
  158.     {
  159.     if ((input = fopen(argv[1],"r")) == NULL)
  160.         fprintf(stderr,"plot2am: %s: open failed\n",argv[1]);
  161.     else {
  162.         strcpy(filename,argv[1]);
  163.         draw_file(input);
  164.         }
  165.     argc--;
  166.     argv++;
  167.     }
  168.  
  169.  
  170. SetMenuStrip(Wind,&MenuList1);
  171.  
  172. /*************************************************
  173.      WAIT for Close Gadget or Menu Pick
  174. *************************************************/
  175.  
  176. while (1)
  177.     {
  178.     Wait( 1L << Wind->UserPort->mp_SigBit);    /* wait on mesg */
  179.     while(msg = (struct IntuiMessage *) GetMsg(Wind->UserPort)) {
  180.         switch(msg->Class) {
  181.             case MENUPICK:
  182.                 menunum = msg->Code;
  183.                 ReplyMsg(msg);
  184.                 if (menunum != MENUNULL) do_pick(menunum);
  185.                 continue;
  186.             case CLOSEWINDOW:
  187.                 ReplyMsg(msg);
  188.                 done(0);
  189.             }
  190.             ReplyMsg(msg);
  191.         }
  192.     }
  193. }
  194.  
  195. /*************************************************
  196.      Parameter input routines
  197. *************************************************/
  198.  
  199.  
  200. /*
  201.  * input a pair of 16 bit ints, scale
  202.  * and return them as longs
  203.  *
  204.  */
  205.  
  206. get_xy(x,y)
  207. register long *x, *y;
  208. {
  209.     get_int(x);
  210.     *x = (*x-xoff)*xmult/xscale;
  211.     get_int(y);
  212.     *y = (YSIZE-1)-(*y-yoff)*ymult/yscale;
  213. }
  214.  
  215. /*
  216.  * input a 16 bit int and return as a long
  217.  */
  218.  
  219. get_int(num)
  220. long *num;
  221. {
  222.     register long hi, lo;
  223.     lo = (long) getc(input);
  224.     hi = ( (long) getc(input)) << 8;
  225.     *num = lo + hi;
  226. }
  227.  
  228. /*
  229.  * input a text string delinited by newline,
  230.  * return to buffer delimited by a null.
  231.  */
  232.  
  233. get_txt(str)
  234. char *str;
  235. {
  236.     register int cmd;
  237.     while ((cmd = getc(input)) != '\n')
  238.         *str++ = cmd;
  239.     *str = '\0';
  240. }
  241.  
  242. /*
  243.  * done - just clean up that which is open, and then leave.
  244.  */
  245. done(how)
  246. int how;
  247.     {
  248.     if (Wind) CloseWindow(Wind) ;
  249.     if (MyScreen) CloseScreen(MyScreen) ;
  250.     if (IntuitionBase) CloseLibrary(IntuitionBase) ;
  251.     if (GfxBase) CloseLibrary(GfxBase) ;
  252.     if (DiskfontBase) CloseLibrary(DiskfontBase) ;
  253.     if (myfont   != NULL) CloseFont( myfont );
  254.  
  255.     OpenWorkBench() ;        /* As requested */
  256.     exit(how) ;
  257.     }
  258.  
  259. /*
  260.  * arc and integer sqrt routines.
  261.  * lifted from sunplot program by:
  262.  
  263. Sjoerd Mullender
  264. Dept. of Mathematics and Computer Science
  265. Free University
  266. Amsterdam
  267. Netherlands
  268.  
  269. Email: sjoerd@cs.vu.nl
  270. If this doesn't work, try ...!seismo!mcvax!cs.vu.nl!sjoerd or
  271. ...!seismo!mcvax!vu44!sjoerd or sjoerd%cs.vu.nl@seismo.css.gov.
  272.  
  273.  *
  274.  */
  275.  
  276. long
  277. isqrt(n)
  278. long n;
  279. {
  280.     long a, b, c;
  281.  
  282.     a = n;
  283.     b = n;
  284.     if (n > 1) {
  285.         while (a > 0) {
  286.             a = a >> 2;
  287.             b = b >> 1;
  288.         }
  289.         do {
  290.             a = b;
  291.             c = n / b;
  292.             b = (c + a) >> 1;
  293.         } while ((a - c) < -1 || (a - c) > 1);
  294.     }
  295.     return b;
  296. }
  297.  
  298.  
  299. #define setcir(x, y, a1, b1, c1, a2, b2, c2) \
  300.     {if (a1 * (y) - b1 * (x) >= c1 && a2 * (y) - b2 * (x) <= c2) \
  301.     WritePixel(rp,x, y);}
  302.  
  303. arc(x, y, x1, y1, x2, y2)
  304. long x, y, x1, y1, x2, y2;
  305. {
  306.     register long a1 = x1 - x, b1 = y1 - y, a2 = x2 - x, b2 = y2 - y;
  307.     register long c1 = a1 * y - b1 * x, c2 = a2 * y - b2 * x;
  308.     register long r2 = a1 * a1 + b1 * b1;
  309.     register long i, sqrt;
  310.  
  311.     for (i = isqrt(r2 >> 1); i >= 0; i -= 1) {
  312.         sqrt = isqrt(r2 - i * i);
  313.         setcir(x + i, y + sqrt, a1, b1, c1, a2, b2, c2);
  314.         setcir(x + i, y - sqrt, a1, b1, c1, a2, b2, c2);
  315.         setcir(x - i, y + sqrt, a1, b1, c1, a2, b2, c2);
  316.         setcir(x - i, y - sqrt, a1, b1, c1, a2, b2, c2);
  317.         setcir(x + sqrt, y + i, a1, b1, c1, a2, b2, c2);
  318.         setcir(x + sqrt, y - i, a1, b1, c1, a2, b2, c2);
  319.         setcir(x - sqrt, y + i, a1, b1, c1, a2, b2, c2);
  320.         setcir(x - sqrt, y - i, a1, b1, c1, a2, b2, c2);
  321.     }
  322. }
  323.  
  324.  
  325. /*
  326.  * do_print : dump the window to the printer
  327.  */
  328.  
  329. union printerIO {
  330.     struct IOStdReq ios;
  331.     struct IODRPReq iodrp;
  332.     struct IOPrtCmdReq iopc;
  333.     };
  334.  
  335. extern union printerIO *CreateExtIO();
  336. extern struct MsgPort *CreatePort();
  337.  
  338. do_print()
  339. {
  340. union printerIO *request;
  341. struct MsgPort *printerPort;
  342. struct ViewPort *vp;
  343. struct Screen *sc;
  344.  
  345.     ClearMenuStrip(Wind);
  346.     SetWaitPointer(Wind);
  347.  
  348.     /* set up for dump rastport request */
  349.     printerPort = CreatePort("myprport",0L);
  350.     request = CreateExtIO(printerPort, sizeof(union printerIO));
  351.     if (OpenDevice("printer.device",0L,request,0L) !=0)
  352.         {
  353.         AutoRequest(Wind,&prfailtxt,0L,&oktxt,0L,0L,300L,75L);
  354.         goto cleanup;
  355.         }
  356.  
  357.     request->iodrp.io_Command = PRD_DUMPRPORT;
  358.     request->iodrp.io_RastPort = rp;
  359.     sc = Wind->WScreen;
  360.     vp = &sc->ViewPort;
  361.     request->iodrp.io_ColorMap = vp->ColorMap;
  362.     request->iodrp.io_Modes = vp->Modes;
  363.     request->iodrp.io_RastPort = rp;
  364.     request->iodrp.io_SrcX= (UWORD) 0;
  365.     request->iodrp.io_SrcY= (UWORD) 0;
  366.     request->iodrp.io_SrcWidth= (UWORD) XSIZE;
  367.     request->iodrp.io_SrcHeight= (UWORD) YSIZE;
  368.     request->iodrp.io_DestCols=0L;
  369.     request->iodrp.io_DestRows=0L;
  370.     request->iodrp.io_Special=SPECIAL_ASPECT | SPECIAL_FULLCOLS;
  371.     DoIO(request);
  372.     CloseDevice(request);
  373.   cleanup:
  374.     DeleteExtIO(request, sizeof(union printerIO));
  375.     DeletePort(printerPort);
  376.     SetMenuStrip(Wind,&MenuList1);
  377.     ClearPointer(Wind);
  378. }
  379.  
  380. /*
  381.  * do_pick : handle chain of menu selections
  382.  */
  383.  
  384. do_pick(menunum)
  385. long menunum;
  386. {
  387. struct MenuItem *item, *ItemAddress();
  388.     while (menunum != MENUNULL)
  389.         {
  390.         switch(ITEMNUM(menunum))
  391.             {
  392.             case 0:
  393.                 get_file();
  394.                 break;
  395.             case 1:
  396.                 clr_grf();
  397.                 break;
  398.             case 2:
  399.                 set_xy();
  400.                 break;
  401.             case 3:
  402.                 do_print();
  403.                 break;
  404.             case 4:
  405.                 do_help();
  406.                 break;
  407.             case 5:
  408.                 DoColorWindow(MyScreen,100L,100L,0L,TRUE);
  409.                 break;
  410.             case 6:
  411.                 done(0);
  412.                 break;
  413.             }
  414.         item = ItemAddress(&MenuList1,menunum);
  415.         menunum = item->NextSelect;
  416.         }
  417. }
  418.  
  419. /*
  420.  * do_help - display help text
  421.  */
  422.  
  423. do_help()
  424. {
  425.     int i;
  426.     clr_grf();
  427.  
  428.     if (myfont)    /* if puny font in use, switch to topaz */
  429.         if ((stdfont = (struct TextFont *)OpenFont(&stdattr)) != NULL)
  430.             SetFont(rp,stdfont);
  431.  
  432.     for (i=0; i<40; i++)    /* dump the whole help text array */
  433.         {
  434.         if (!HelpText[i]) break;
  435.         Move(rp,50L,(long) (i+1)*9+20);
  436.         Text(rp,HelpText[i], (long) strlen(HelpText[i]));
  437.         }
  438.  
  439.     if (myfont)    
  440.         {
  441.         SetFont(rp,myfont); /* back to puny */
  442.         if (stdfont) CloseFont(stdfont);
  443.         }
  444. }
  445.  
  446. /*
  447.  * clr_grf - clear the grafics area
  448.  */
  449.  
  450. clr_grf()
  451. {
  452.     SetAPen(rp,0L);
  453.     RectFill(rp,0L,0L,(long) (XSIZE-1),(long) (YSIZE-1));
  454.     SetAPen(rp,1L);
  455. }
  456.  
  457. /*
  458.  * draw_file - read in a file and draw on screen
  459.  */
  460.  
  461. draw_file()
  462. {
  463. register short cmd, i;
  464. long x,y, r;
  465. long r1, r2;
  466. long x1,y1,x2,y2;
  467. char textbuf[100];
  468.  
  469. xscale = xscaleu;
  470. yscale = yscaleu;
  471. xoff = xoffu;
  472. yoff = yoffu;
  473.  
  474. /*************************************************
  475.      MAIN Drawing loop
  476. *************************************************/
  477.  
  478. while ((cmd = getc(input)) != EOF)
  479.     {
  480.     switch (cmd)
  481.         {
  482.         case 'm':    /* move x,y */
  483.             get_xy(&x,&y);
  484.             Move(rp,x,y);
  485.             break;
  486.         case 'n':    /* draw x,y */
  487.             get_xy(&x,&y);
  488.             Draw(rp,x,y);
  489.             break;
  490.         case 'p':    /* point x,y */
  491.             get_xy(&x,&y);
  492.             WritePixel(rp,x,y);
  493.             break;
  494.         case 'l':    /* line xs,ys, xe,ye */
  495.             get_xy(&x,&y);
  496.             Move(rp,x,y);
  497.             get_xy(&x,&y);
  498.             Draw(rp,x,y);
  499.             break;
  500.         case 'a':    /* arc xc,yc, xs,ys, xe,ye */
  501.             get_xy(&x,&y);    /* get center */
  502.             get_xy(&x2,&y2);  /* get end point */
  503.             get_xy(&x1,&y1);  /* get start point */
  504.             arc(x, y, x1, y1, x2, y2);  /* draw counterclockwise  */
  505.             Move(rp,x1,y1);
  506.             break;
  507.         case 't':    /* Text string\n   */
  508.             get_txt(textbuf);
  509.             if (rp->cp_y == 0) break;
  510.             Text(rp,textbuf, (long) strlen(textbuf));
  511.             break;
  512.         case 'c':    /* circle xc,yc, r */
  513.             get_xy(&x,&y);
  514.             get_int(&r);
  515.             r1 = r*xmult/xscale;
  516.             r2 = r*ymult/yscale;
  517.             DrawEllipse(rp,x,y,r1,r2);
  518.             break;
  519.         case 'f':    /* linemode string\n   */
  520.             get_txt(textbuf);
  521.             for (i=0; i<5; i++)
  522.                 {
  523.                 if (0 == strcmp(textbuf,lmodestr[i]))
  524.                     {
  525.                     SetDrPt(rp,lmode[i]);
  526.                     break;
  527.                     }
  528.                 }
  529.             break;
  530.         case 's':    /* space xlo,ylo, xhi,yhi */
  531.             get_int(&x1);
  532.             get_int(&y1);
  533.             get_int(&x2);
  534.             get_int(&y2);
  535.             if (!override) /* is user is not overriding */
  536.                 {
  537.                 xoff = x1;
  538.                 yoff = y1;
  539.                 xscale = x2;
  540.                 yscale = y2;
  541.                 xscale = xscale - xoff;
  542.                 yscale = yscale - yoff;
  543.                 }
  544.             break;
  545.         case 'e':    /* erase */
  546.             clr_grf();
  547.             break;
  548.         default:
  549.         AutoRequest(Wind,&ffmtmsg,0L,&oktxt,0L,0L,300L,75L);
  550.         goto getout;
  551.         }
  552.     }
  553.   getout:
  554.     fclose(input);
  555.  
  556. }
  557.  
  558. /*
  559.  * get_file - request a filename with fileio and draw it
  560.  */
  561.  
  562. get_file()
  563. {
  564. struct Window    *FWind = NULL ;
  565.  
  566.    FIOSupp->ReqTitle = (UBYTE *) reqtitle;
  567.    NewFileioWindow.Screen = MyScreen;
  568.    if ((FWind = (struct Window *) OpenWindow(&NewFileioWindow)) == NULL)
  569.     done(25);
  570.  
  571.    Retry:
  572.    if (GetFileIOName(FIOSupp,FWind))
  573.         BuildFileIOPathname(FIOSupp,filename);
  574.    else {
  575.        CloseWindow(FWind);
  576.        return;
  577.     }
  578.  
  579.    while ((input = fopen(filename,"r")) == NULL)
  580.         {
  581.         if (AutoRequest(Wind,&openfimsg,&retrytxt,&cantxt,0L,0L,300L,75L))
  582.             continue;
  583.         goto Retry;
  584.         }
  585.  
  586.    CloseWindow(FWind);
  587.  
  588.    SetWaitPointer(Wind);
  589.    draw_file();
  590.    ClearPointer(Wind);
  591. }
  592.  
  593. /*
  594.  * set_xy - get x/y scaling via string gadgets
  595.  */
  596.  
  597. set_xy()
  598. {
  599.     struct Window    *SWind = NULL ;
  600.     struct IntuiMessage    *msg;
  601.     UWORD code;
  602.     ULONG class;
  603.     APTR object;
  604.     long tmp;
  605.  
  606.     sprintf(XscaleGadSIBuff,"%ld",xscaleu);
  607.     sprintf(YscaleGadSIBuff,"%ld",yscaleu);
  608.     sprintf(XoffGadSIBuff,"%ld",xoffu);
  609.     sprintf(YoffGadSIBuff,"%ld",yoffu);
  610.  
  611.     NewScaleWindow.Screen = MyScreen;
  612.     if ((SWind = (struct Window *) OpenWindow(&NewScaleWindow)) == NULL)
  613.         done(25);
  614.     Srp = SWind->RPort;
  615.     PrintIText(Srp,&IWinText,0L,0L);
  616.  
  617.     while (1) {
  618.     Wait(1L<<SWind->UserPort->mp_SigBit );
  619.     while(msg = (struct IntuiMessage *) GetMsg(SWind->UserPort)) {
  620.         code = msg->Code;  /* MENUNUM */
  621.         object = msg->IAddress;  /* Gadget */
  622.         class = msg->Class;
  623.         switch(class) {
  624.             case CLOSEWINDOW:
  625.                 ReplyMsg(msg);
  626.                 done(0);
  627.             case GADGETUP:
  628.                 clr_msg();
  629.                 if (OverrideGad.Flags & SELECTED) override = TRUE;
  630.                     else override = FALSE;
  631.                 if (XoffGadSIBuff[0] == '\0') 
  632.                         {
  633.                         sprintf(XoffGadSIBuff,"%ld",xoffu);
  634.                         RefreshGadgets(SWind->FirstGadget,SWind,NULL);
  635.                         }
  636.                     else
  637.                     if ((tmp = val_off(XoffGadSIBuff)) == -1)
  638.                         {
  639.                         lite_msg();
  640.                         PrintIText(Srp,&ErrText3,0L,0L);
  641.                         break;
  642.                     }else 
  643.                         {
  644.                         xoffu = tmp;
  645.                         }
  646.                 if (YoffGadSIBuff[0] == '\0') 
  647.                         {
  648.                         sprintf(YoffGadSIBuff,"%ld",yoffu);
  649.                         RefreshGadgets(SWind->FirstGadget,SWind,NULL);
  650.                         }
  651.                     else
  652.                     if ((tmp = val_off(YoffGadSIBuff)) == -1)
  653.                         {
  654.                         lite_msg();
  655.                         PrintIText(Srp,&ErrText4,0L,0L);
  656.                         break;
  657.                     }else  {
  658.                         yoffu = tmp;
  659.                         }
  660.                 if (XscaleGadSIBuff[0] == '\0') 
  661.                         {
  662.                         sprintf(XscaleGadSIBuff,"%ld",xscaleu);
  663.                         RefreshGadgets(SWind->FirstGadget,SWind,NULL);
  664.                         }
  665.                     else
  666.                     if ((tmp = val_sc(XscaleGadSIBuff)) == -1)
  667.                         {
  668.                         lite_msg();
  669.                         PrintIText(Srp,&ErrText1,0L,0L);
  670.                         break;
  671.                     }else 
  672.                         {
  673.                         xscaleu = tmp;
  674.                         }
  675.                 if (YscaleGadSIBuff[0] == '\0') 
  676.                         {
  677.                         sprintf(YscaleGadSIBuff,"%ld",yscaleu);
  678.                         RefreshGadgets(SWind->FirstGadget,SWind,NULL);
  679.                         }
  680.                     else
  681.                     if ((tmp = val_sc(YscaleGadSIBuff)) == -1)
  682.                         {
  683.                         lite_msg();
  684.                         PrintIText(Srp,&ErrText2,0L,0L);
  685.                         break;
  686.                     }else  {
  687.                         yscaleu = tmp;
  688.                         }
  689.                 if (msg->IAddress == &OKGad) goto Dun;  /* OK button */
  690.             case REFRESHWINDOW:
  691.                 break;
  692.         }
  693.         ReplyMsg(msg);
  694.     }
  695.     }    /* end while(Wait())    */
  696.   Dun:
  697.     CloseWindow(SWind);
  698. }
  699.  
  700. /*
  701.  * val_off : validate an offset string gadget contents and return
  702.  *          -1 if invalid or offset if valid.
  703.  */
  704.  
  705. val_off(buffer)
  706. char *buffer;
  707. {
  708.     int sc;
  709.     char *bufp;
  710.     bufp = buffer;
  711.     while (*bufp != '\0')
  712.         {
  713.         if (!isdigit(*bufp) && *bufp != '-') return -1;
  714.         bufp++;
  715.         }
  716.     sc = atoi(buffer);
  717.     return sc;
  718. }
  719.  
  720. /*
  721.  * val_sc : validate a scale string gadget contents and return
  722.  *          -1 if invalid or scale if valid.
  723.  */
  724.  
  725. val_sc(buffer)
  726. char *buffer;
  727. {
  728.     int sc;
  729.     char *bufp;
  730.     bufp = buffer;
  731.     while (*bufp != '\0')
  732.         {
  733.         if (!isdigit(*bufp)) return -1;
  734.         bufp++;
  735.         }
  736.     sc = atoi(buffer);
  737.     if (sc >100 && sc < 10000) return sc;
  738.     return -1;
  739. }
  740.  
  741. /*
  742.  * lite_msg : Set the err-message area of the window to white
  743.  *
  744.  */
  745. lite_msg()
  746. {
  747.     SetAPen(Srp,1L);
  748.     RectFill(Srp, XOPT+4L, YOPT+3L,XOPT+140L,YOPT+13L);
  749.     SetAPen(Srp,3L);
  750.     DisplayBeep(MyScreen);
  751. }
  752.  
  753. /*
  754.  * clr_msg : clear the err-message area of the screen
  755.  *
  756.  */
  757. clr_msg()
  758. {
  759.     SetAPen(Srp,0L);
  760.     RectFill(Srp, XOPT+4L, YOPT+3L,XOPT+140L,YOPT+13L);
  761.     SetAPen(Srp,3L);
  762. }
  763.  
  764.