home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / YADME10.LHA / YADME10 / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-19  |  36.3 KB  |  1,322 lines

  1. #include <stdio.h>
  2. /*
  3.  * MAIN.C
  4.  *
  5.  *      (C)Copyright 1987 by Matthew Dillon, All Rights Reserved.
  6.  *
  7.  */
  8.  
  9. #include "defs.h"
  10. #include <workbench/startup.h>
  11. #include <workbench/workbench.h>
  12. #include <libraries/asl.h>
  13. #include <clib/asl_protos.h>
  14. #include <graphics/gfxbase.h>
  15. #include <graphics/rastport.h>
  16. #include <reqtools/reqtools.h>
  17.  
  18.  
  19. extern struct FileRequester *FReq;
  20.  
  21.  
  22. typedef struct Process      PROC;
  23. typedef struct WBStartup    WBS;
  24. typedef struct DiskObject   DISKOBJ;
  25.  
  26. #define IDCMPFLAGS CLOSEWINDOW|NEWSIZE|RAWKEY|MOUSEBUTTONS|ACTIVEWINDOW|MOUSEMOVE|MENUPICK|GADGETDOWN|GADGETUP|INTUITICKS
  27.  
  28. struct NewWindow Nw = {
  29.    0, 1, 0  , 0  , -1, -1,  /*  width, height filled in by program */
  30.    IDCMPFLAGS,
  31.    ACTIVATE|WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|NOCAREREFRESH|RMBTRAP,
  32.    NULL, NULL, (ubyte *)"   WAIT   ",
  33.    NULL, NULL,
  34.    32, 32, -1, -1,
  35.    WBENCHSCREEN
  36. };
  37.  
  38. /* prop gadget stuff (TJM) */
  39. #ifndef max
  40. #define max(a,b) ((a)>(b)?(a):(b))
  41. #endif
  42. #ifndef min
  43. #define min(a,b) ((a)<(b)?(a):(b))
  44. #endif
  45.  
  46. /* so we can malloc it all at once ... */
  47. struct PropGadget {
  48.     struct Gadget g;
  49.     struct PropInfo p;
  50.     struct Image i;
  51. } PropTemp = {
  52.   { NULL, -13, 0, 10, 0, GFLG_RELRIGHT|GFLG_RELHEIGHT,
  53.     GACT_RIGHTBORDER|GACT_RELVERIFY|GACT_IMMEDIATE,
  54.     GTYP_PROPGADGET
  55.   },
  56. } ;
  57.  
  58. static char noadj;      /* for blocking software adj. of prop gad when intuition (user) already did it */
  59.  
  60. static ULONG LCurrentSecs, LLastSecs, LCurrentMicros, LLastMicros;
  61.  
  62. /* end of Prop stuff */
  63.  
  64. static char DoIconify;
  65. int prop_pressed = 0;
  66.  
  67. short Sharedrefs;
  68. short Oldtlen = 999;      /*  Old Title Length    */
  69. struct MsgPort *Sharedport;
  70. struct FileRequester *FReq;
  71. static DISKOBJ *Do;
  72. WBS     *Wbs;
  73.  
  74. short Xsize,  Ysize;            /* font character sizes        */
  75. short Rows,  Columns;           /* character rows/cols available       */
  76. short Xbase,  Ybase;            /* offset pixel base for display       */
  77. short XTbase,YTbase;            /* used for text display               */
  78. short Xpixs,  Ypixs;            /* actual # X/Y pixels available       */
  79. short Mx, My;
  80.  
  81. ubyte *av[8];
  82. char Quitflag;
  83. char Overide;
  84. char Wdisable = 1;              /* Disable icon save                   */
  85. char MShowTitle, MForceTitle;
  86.  
  87. #ifdef NOTDEF
  88. PORT *IPCPort;
  89.  
  90. PORT *IPCRPort;
  91. #endif
  92.  
  93. long Mask,RMask;
  94.  
  95. struct IntuitionBase *IntuitionBase;
  96. struct GfxBase *GfxBase;
  97. struct Library *IconBase;
  98. struct Library *AslBase;
  99. struct Library *GadToolsBase = NULL;
  100.  
  101. extern int Enable_Abort;
  102.  
  103. #include <rexx/rxslib.h>
  104.  
  105. extern short InRxCmd;
  106. extern struct MsgPort *RexxPort;
  107. extern struct RxsLib *RexxSysBase;
  108.  
  109.  
  110. static char *Ffile;
  111.  
  112. int main(int, char **);
  113.  
  114. int wbmain(WBS *wbs)
  115. {
  116.     return(main(0, (char **)wbs));
  117. }
  118.  
  119. int main(int mac, char **mav)
  120. {
  121.     ULONG lastclass = 0;    /* Added by KL to prevent redrawing of the window title */
  122.                             /* If an INTUITICKS event ocurred */
  123.  
  124.     char nf, ni;            /*  # files on command line     */
  125.     char notdone;           /*  for endless loop            */
  126.     char iawm = 0;          /*  overide mouse buttons       */
  127.     char dontwait = 0;      /*  don't wait for a message    */
  128.     short i;
  129.     PROC *proc = (PROC *)FindTask(NULL);
  130.     BPTR origlock, oldlock;
  131.     BPTR flushlock;
  132.  
  133.     fclose(stdin);
  134.     /*fclose(stdout);*/     /*  assume person will run >nil:    */
  135.     fclose(stderr);         /*  close stderr & console ref. */
  136.     origlock = CurrentDir(DupLock((BPTR)proc->pr_CurrentDir));
  137.     NewDME = 0;
  138.  
  139.     NewList((LIST *)&DBase);
  140.     NewList((LIST *)&PBase);
  141.     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
  142.     GfxBase =       (struct GfxBase *)OpenLibrary("graphics.library", 0);
  143.     GadToolsBase = OpenLibrary("gadtools.library", 0);
  144.     if (IntuitionBase == NULL || GfxBase == NULL)
  145.         exiterr("cannot open intuition || graphics library");
  146.  
  147.     if (AslBase = OpenLibrary("asl.library", 0))
  148.         FReq = AllocAslRequest(ASL_FileRequest, NULL);
  149.  
  150.     if (ReqToolsBase = (struct ReqToolsBase *)OpenLibrary("reqtools.library",37))
  151.         RFReq = rtAllocRequestA (RT_FILEREQ, NULL);
  152.  
  153.     init_command();
  154.  
  155.     /* If there is the command C:Flush we will use it after freeing memory */
  156.     if (flushlock = Lock("C:Flush", SHARED_LOCK))
  157.     {
  158.        UnLock(flushlock);
  159.        FlushMem = 1;
  160.     }
  161.  
  162.  
  163.     Pagejump = 80;          /* for Propgad & pageup/down */
  164.  
  165.     DoIconify = 0;
  166.  
  167.     String  = (char *)malloc(1);        /*  initialize scanf variable   */
  168.     *String = 0;
  169.  
  170.     if (mac == 0) {             /*  WORKBENCH STARTUP   */
  171.         Wdisable = 0;           /*  allow icon save     */
  172.         Wbs = (WBS *)mav;
  173.         IconBase = OpenLibrary("icon.library", 0);
  174.         if (IconBase == NULL) {
  175.             if(FReq)
  176.                 FreeAslRequest(FReq);
  177.             if(AslBase)
  178.                 CloseLibrary(AslBase);
  179.             if(RFReq)
  180.                 rtFreeRequest(RFReq);
  181.             if(ReqToolsBase)
  182.                 CloseLibrary((struct Library *)ReqToolsBase);
  183.             if (GadToolsBase)
  184.                 CloseLibrary(GadToolsBase);
  185.            exiterr("unable to open icon library");
  186.         }
  187.     }
  188.     resethash();
  189.  
  190.     if (Wbs) {
  191.         if (Wbs->sm_ArgList[0].wa_Lock) {
  192.             BPTR savelock = CurrentDir((BPTR)Wbs->sm_ArgList[0].wa_Lock);
  193.             if (Do = GetDiskObject(Wbs->sm_ArgList[0].wa_Name)) {
  194.                 ops(Do->do_ToolTypes, 1);
  195.                 FreeDiskObject(Do);
  196.             }
  197.             CurrentDir(savelock);
  198.         }
  199.         nf = Wbs->sm_NumArgs - 1;
  200.         mac = 99;
  201.     } else {
  202.         nf = ops(mav+1, 0);
  203.     }
  204.  
  205.     {
  206.         mountrequest(0);
  207.         openrexx();     /*   do this after the last possible call to exiterr() */
  208.         mountrequest(1);
  209.     }
  210.  
  211.     for (ni = 0, i = 1; i < mac; ++i) {
  212.         char *str;
  213.         DISKOBJ *dso;
  214.         if (Wbs) {
  215.             if (i > nf)
  216.                 break;
  217.             str = Wbs->sm_ArgList[i].wa_Name;
  218.             UnLock(CurrentDir(DupLock((BPTR)Wbs->sm_ArgList[i].wa_Lock)));
  219.             if (dso = GetDiskObject(Wbs->sm_ArgList[i].wa_Name)) {
  220.                 ops(dso->do_ToolTypes, 1);
  221.                 FreeDiskObject(dso);
  222.             }
  223.         } else {
  224.             str = mav[i];
  225.             if (*str == '-')
  226.                 continue;
  227.         }
  228.         if(NewDME) {
  229.             do_newwindow();
  230.             ++ni;
  231.             av[0] = (ubyte *)"newfile";
  232.             av[1] = (ubyte *)str;
  233.             do_edit();
  234.             MForceTitle = 1;
  235.             window_title();
  236.             if(DoIconify && i + 1 < mac)
  237.                 do_iconify();
  238.         }
  239.         else {
  240.             CurrentDir(oldlock = CurrentDir(NULL));
  241.             if (!getpathto(oldlock,"",Deline))
  242.                 strcpy(Deline,"SYS:");
  243.             sprintf(Current,"\"'newwindow cd (%s) newfile (%s)%s'\"",Deline,str,DoIconify?" iconify":"");
  244.             do_rrexx(Current);
  245.         }
  246.     }
  247.     if (nf == 0) {                  /* no files to edit */
  248.         if(NewDME)
  249.             do_newwindow();
  250.         else {
  251.             if(DoIconify)
  252.                 do_rrexx("\"'newwindow iconify'\"");
  253.             else
  254.                 do_rrexx("\"'newwindow'\"");
  255.         }
  256.     }
  257.     if(NewDME && Ep) {
  258.         mountrequest(0);
  259.         av[0] = NULL;
  260.         av[1] = (ubyte *)"s:.edrc";
  261.         do_source();
  262.         av[0] = NULL;
  263.         av[1] = (ubyte *)((Ffile) ? Ffile : ".edrc");
  264.         do_source();
  265.         mountrequest(1);
  266.         {                       /*  1.29c   */
  267.             ED *ep;
  268.             ED *eb = Ep;
  269.             if (eb) {
  270.                 for (ep = (ED *)eb->Node.mln_Succ; ep->Node.mln_Succ; ep = (ED *)ep->Node.mln_Succ) {
  271.                     ep->Tabstop = eb->Tabstop;
  272.                     ep->Margin  = eb->Margin;
  273.                     ep->Insertmode = eb->Insertmode;
  274.                     ep->IgnoreCase = eb->IgnoreCase;
  275.                     ep->Wordwrap   = eb->Wordwrap;
  276.                     if (eb->Font) {
  277.                         ep->Font = eb->Font;
  278.                         ++eb->Font->tf_Accessors;
  279.                     }
  280.                 }
  281.             }
  282.         }
  283.         if(DoIconify)
  284.             do_iconify();
  285.         title("DME V1.46 \251Copyright 1988-1990 by Matthew Dillon,  All Rights Reserved             ");
  286.         Mask |= 1 << Ep->Win->UserPort->mp_SigBit;
  287.         if(RexxSysBase)
  288.             RMask = 1 << RexxPort->mp_SigBit;
  289. loop:
  290.         if (!Ep->iconmode)
  291.             text_cursor(1);
  292.         for (notdone = 1; RxBlock || (!Quitflag && notdone);) {
  293.             char mmove = 0;
  294.             short mqual;
  295.             unsigned long waitwas;
  296.  
  297.             if (!Ep->iconmode && (lastclass != INTUITICKS))  /* changed by KL */
  298.                 window_title();
  299.             if (dontwait) {
  300.                 --dontwait;
  301.             } else {
  302.                 if(Comlinemode)
  303.                     waitwas = Wait(Mask);
  304.                 else if(!RxBlock)
  305.                     waitwas = Wait(Mask|RMask);
  306.                 else
  307.                     waitwas = Wait(RMask);
  308.             }
  309.  
  310.             /*
  311.             *  NOTE: due to operation of breakcheck(), the userport signal
  312.             *  may not be set even if there are messages pending.
  313.             */
  314.  
  315.             if(waitwas & Mask) {
  316.                 IMESS *im, pm;
  317.  
  318.                 while (im = (IMESS *)GetMsg(Ep->Win->UserPort)) {
  319.                     Msgchk = 1;
  320.                     Abortcommand = 0;
  321.                     memcpy(&pm,im,sizeof(pm));
  322.                     Mx = im->MouseX;
  323.                     My = im->MouseY;
  324.  
  325.                     ReplyMsg((MSG *)im); /* moved up here to prevent crashing */
  326.  
  327.                     if (pm.IDCMPWindow != Ep->Win) {
  328.                         Overide = 0;
  329.                         if (Comlinemode)
  330.                             escapecomlinemode();
  331.                         text_sync();
  332.                         MShowTitle = 0;
  333.                         if (!Ep->iconmode)
  334.                             window_title();
  335.                         if (text_switch(pm.IDCMPWindow) == 0) {
  336.                             continue;
  337.                         }
  338.                     }
  339.                     lastclass = pm.Class;       /* added KL */
  340.                     switch(pm.Class) {
  341.                     case NEWSIZE:
  342.                         if (!Ep->iconmode) {
  343.                             if (Comlinemode)
  344.                                 escapecomlinemode();
  345.                             set_window_params();
  346.                             clear_window();
  347.                             if (!text_sync())
  348.                                 text_redisplay();
  349.                             text_cursor(1);
  350.                         }
  351.                         break;
  352.                     case MOUSEBUTTONS:
  353.                         switch(pm.Code) {
  354.                         case SELECTDOWN:
  355.                             LLastSecs = LCurrentSecs;
  356.                             LLastMicros = LCurrentMicros;
  357.                             LCurrentSecs = pm.Seconds;
  358.                             LCurrentMicros = pm.Micros;
  359.                         case MENUDOWN:
  360.                         case MIDDLEDOWN:
  361.                             if (Ep->iconmode || iawm) {
  362.                                 uniconify();
  363.                                 text_cursor(1);
  364.                                 break;
  365.                             }
  366.                             Forbid();
  367.                             Ep->Win->Flags |= REPORTMOUSE;
  368.                             Permit();
  369.                             uniconify();
  370.                             text_cursor(0);
  371.                             keyctl(NULL, pm.Code|0x80, pm.Qualifier);
  372.                             text_cursor(1);
  373.                             break;
  374.                         case SELECTUP:
  375.                         case MENUUP:
  376.                         case MIDDLEUP:
  377.                             Forbid();
  378.                             Ep->Win->Flags &= ~REPORTMOUSE;
  379.                             Permit();
  380.                             text_cursor(0);
  381.                             keyctl(NULL, pm.Code, pm.Qualifier); /* up == |0x80 */
  382.                             text_cursor(1);
  383.                             break;
  384.                         }
  385.                         break;
  386.                     case RAWKEY:
  387.                         if ((pm.Code & 0x80) == 0) {
  388.                             /*  Handled in command interpreter.
  389.                             if (Ep->iconmode) {
  390.                                 uniconify();
  391.                                 break;
  392.                             }
  393.                             */
  394.                             text_cursor(0);
  395.                             keyctl(&pm, pm.Code, pm.Qualifier);
  396.                             text_cursor(1);
  397.                         }
  398.                         break;
  399.                     case MENUPICK:
  400.                         {
  401.                             char *str = menu_cmd(pm.Code);
  402.                             if (str) {
  403.                                 str = strcpy(malloc(strlen(str)+1), str);
  404.                                 text_cursor(0);
  405.                                 do_command(str);
  406.                                 free(str);
  407.                                 text_cursor(1);
  408.                             }
  409.                         }
  410.                         break;
  411.                     case CLOSEWINDOW:
  412.                         if (Comlinemode)
  413.                             escapecomlinemode();
  414.                         text_sync();
  415.                         notdone = 0;
  416.                         break;
  417.                     case ACTIVEWINDOW:
  418.                         break;
  419.                     case MOUSEMOVE:
  420.                         mmove = 1;
  421.                         mqual = pm.Qualifier;
  422.                         break;
  423.                     case GADGETDOWN:
  424.                         prop_pressed = 1;
  425.                         break;
  426.                     case GADGETUP:
  427.                         prop_pressed = 0;
  428. gadup:                  if (!Ep->iconmode)
  429.                         {
  430.                             int newtop = new_top();
  431.  
  432.                             noadj = 1;              /* block software prop refresh */
  433.                             if (Comlinemode)
  434.                                 escapecomlinemode();
  435.                             scroll_jump(newtop);
  436.                             noadj = 0;              /* reallow software prop refresh */
  437.                             if (!prop_pressed)
  438.                             {
  439.                                char cbuf[20];
  440.                                strcpy(cbuf, "if r (last)");
  441.                                text_cursor(0);
  442.                                do_command(cbuf);
  443.                             }
  444.                             text_cursor(1);
  445.                         }
  446.                         break;
  447.                     case INTUITICKS:
  448.                         if (prop_pressed)
  449.                            goto gadup;
  450.                         break;
  451.                     }
  452.                     if (!RxBlock && (notdone == 0 || Quitflag)) {
  453.                         dontwait = 2;
  454.                         goto boom;
  455.                     }
  456.                 }
  457.             }
  458.  
  459.             if(RexxSysBase && (waitwas & RMask)) {
  460.                 text_cursor(0);
  461.                 Process_Rexx();
  462.                 text_cursor(1);
  463.                 if (Quitflag && !RxBlock) {
  464.                     dontwait = 2;
  465.                     goto boom;
  466.                 }
  467.             }
  468.  
  469.             iawm = 0;
  470.             if (mmove) {
  471.                 uniconify();
  472.                 mmove = 0;
  473.                 text_cursor(0);
  474.                 keyctl(NULL, QMOVE, mqual);
  475.                 text_cursor(1);
  476.             }
  477. #ifdef NOTDEF
  478.             closesharedwindow(NULL);  /* removed by TJM */
  479. #endif
  480.         }
  481. boom:
  482.         text_sync();
  483.         if (Ep->Modified && !Overide) {
  484.             uniconify();
  485.             if (! getyn("Quit without saving changes?"))
  486.             {
  487.                Quitflag = 0;
  488.                goto loop;
  489.             }
  490.         }
  491.         SetWindowTitles(Ep->Win, "", (char *)-1);
  492.         {
  493.             WIN *win = Ep->Win;
  494.             struct Gadget *g = Ep->PropGad;
  495.  
  496.             /* text_uninit(); */
  497.             if ((Ep->Node.mln_Succ == (MinNode *)&DBase.mlh_Tail) &&
  498.                 (Ep->Node.mln_Pred == (MinNode *)&DBase.mlh_Head))
  499.                ProgressWindow = 0;
  500.  
  501.             closesharedwindow(win);
  502.             text_uninit(); /* Changed order by KL */
  503.  
  504.             if(g)
  505.                 free(g);
  506.         }
  507.         if (Ep) {
  508.             Quitflag = 0;
  509.             if (!Ep->iconmode)
  510.                 set_window_params();
  511.             text_load();
  512.             MShowTitle = 0;
  513.             goto loop;
  514.         }
  515.     }
  516. #ifdef NOTDEF
  517.     closesharedwindow(NULL); /* removed TJM */
  518. #endif
  519.     closerexx();
  520.     UnLock(CurrentDir(origlock));
  521. #ifdef NOTDEF
  522.     if (IPCRPort) /* no IPC port to begin with ... */
  523.         DeletePort(IPCRPort);
  524. #endif
  525.     if (IconBase)
  526.         CloseLibrary((void *)IconBase);
  527.     if (FReq)
  528.         FreeAslRequest(FReq);
  529.     if (AslBase)
  530.         CloseLibrary(AslBase);
  531.     if (GadToolsBase)
  532.         CloseLibrary(GadToolsBase);
  533.     if(RFReq)
  534.         rtFreeRequest(RFReq);
  535.     if(ReqToolsBase)
  536.         CloseLibrary((struct Library *)ReqToolsBase);
  537.     if (GfxBase)
  538.         CloseLibrary((struct Library *)GfxBase);
  539.     if (IntuitionBase)
  540.         CloseLibrary((struct Library *)IntuitionBase);
  541.  
  542.     IconBase = NULL;
  543.     GfxBase = NULL;
  544.     IntuitionBase = NULL;
  545.     GadToolsBase = NULL;
  546.  
  547.     dealloc_hash();
  548.     /* at this point, exiterr("no mem") would be nice if windows weren't opened.. */
  549.     return(0);
  550. }
  551.  
  552. void do_iconify(void)
  553. {
  554.     text_sync();
  555.     if (!Comlinemode)
  556.         iconify();
  557. }
  558.  
  559. int last_was_double = 0;
  560.  
  561. void do_tomouse(void)
  562. {
  563.     int i;
  564.  
  565.     text_position((Mx-Xbase)/Xsize, (My-Ybase)/Ysize);
  566.     if (DoubleClick(LLastSecs, LLastMicros, LCurrentSecs, LCurrentMicros))
  567.     {
  568.        text_sync();
  569.        if (Current[Ep->Column])
  570.        {
  571.           BEp = Ep;
  572.           Blockempty = Marking = 0;
  573.           BSline = BEline = initialBSline = Ep->Line;
  574.           if (Blocktype == BLOCK_CHARACTER)
  575.           {
  576.              if (last_was_double)
  577.              {
  578.                 BSchar = 0;
  579.                 BEchar = strlen(Current);
  580.              }
  581.              else
  582.              {
  583.                 i = Ep->Column;
  584.                 while (i && Current[i] != ' ')
  585.                    i--;
  586.                 if (i) i++;
  587.                 BSchar = initialBSchar = i;
  588.                 i = Ep->Column;
  589.                 while ((i < 256) && (Current[i] != ' ') && (Current[i]))
  590.                    i++;
  591.                 BEchar = i - 1;
  592.              }
  593.           }
  594.           text_redrawblock(1);
  595.        }
  596.        last_was_double = 1;
  597.     }
  598.     else
  599.        last_was_double = 0;
  600. }
  601.  
  602. /*
  603.  *  New iconify() routine by fgk.
  604.  */
  605.  
  606. void iconify(void)
  607. {
  608.     WIN *newwin;
  609.     ED *ep = Ep;
  610.     WIN *win = ep->Win;
  611.  
  612.     struct IntuiText itxt;              /* To find width of prop fonts */
  613.  
  614.     itxt.ITextFont = Ep->Win->WScreen->Font;    /* Init */
  615.     itxt.NextText = NULL;
  616.  
  617.     if (!ep->iconmode) {
  618.         ep->Winx      = win->LeftEdge;
  619.         ep->Winy      = win->TopEdge;
  620.         ep->Winwidth  = win->Width;
  621.         ep->Winheight = win->Height;
  622.  
  623.         /*Nw.Height = win->RPort->TxHeight + 3;*/
  624.  
  625.  
  626.         if(Ep->Win->WScreen->Font != NULL)
  627.             Nw.Height = Ep->Win->WScreen->Font->ta_YSize + 3;   /* height */
  628.         else
  629.             Nw.Height = GfxBase->DefaultFont->tf_YSize + 3;
  630.  
  631.         /*Nw.Width  = 20 + 5*8 + strlen(ep->Name) * (win->RPort->TxWidth + win->RPort->TxSpacing);*/
  632.  
  633.         itxt.IText = ep->Name;
  634.  
  635.         /* pretending spaces are always 8 */
  636.         Nw.Width  = 20 + 5*8 + IntuiTextLength(&itxt);          /* width */
  637.  
  638.  
  639.         Nw.LeftEdge= ep->IWinx;
  640.         Nw.TopEdge = ep->IWiny;
  641.  
  642.         if (Nw.LeftEdge + Nw.Width > win->WScreen->Width)   /* keep in bounds */
  643.             Nw.LeftEdge = win->WScreen->Width - Nw.Width;
  644.  
  645.         if (Nw.TopEdge + Nw.Height > win->WScreen->Height)
  646.             Nw.TopEdge = win->WScreen->Height - Nw.Height;
  647.  
  648.         Nw.Title = ep->Wtitle;
  649.  
  650.         Nw.Flags &= ~(WINDOWSIZING|WINDOWDEPTH|ACTIVATE);
  651.  
  652.         if (ep->Modified) {     /* no CLOSE */
  653.             Nw.Width -= 3*8;
  654.             Nw.Flags &= ~WINDOWCLOSE;
  655.         }
  656.  
  657.        /******* Nw.Flags |= BORDERLESS;*******/
  658.  
  659.         Nw.DetailPen = ep->BGPen;
  660.         Nw.BlockPen  = ep->FGPen;
  661.         if (win->Flags & WINDOWACTIVE)      /*  KTS */
  662.             Nw.Flags |= ACTIVATE;
  663.         sprintf(ep->Wtitle, "%s     ", ep->Name);
  664.  
  665.         if (newwin = opensharedwindow(&Nw)) {
  666.             closesharedwindow(win);
  667.             Nw.BlockPen = -1;
  668.             ep->iconmode = 1;
  669.             ep->Win = newwin;
  670.         }
  671.  
  672.         Nw.Flags |= WINDOWSIZING|WINDOWDEPTH|WINDOWCLOSE|ACTIVATE;
  673.  
  674.         Nw.Flags &= ~BORDERLESS;
  675.     }
  676. }
  677.  
  678. void uniconify(void)
  679. {
  680.     ED *ep = Ep;
  681.     WIN *win = ep->Win;
  682.     WIN *newwin;
  683.     RP *rp;
  684.  
  685.     if (ep->iconmode) {
  686.         ep->IWinx = win->LeftEdge;
  687.         ep->IWiny = win->TopEdge;
  688.         Nw.LeftEdge = ep->Winx;
  689.         Nw.TopEdge  = ep->Winy;
  690.         Nw.Width    = ep->Winwidth;
  691.         Nw.Height   = ep->Winheight;
  692.         Nw.Title    = ep->Wtitle;
  693.         Nw.DetailPen = ep->BGPen;
  694.         Nw.BlockPen  = ep->FGPen;
  695.  
  696.         if (newwin = opensharedwindow(&Nw)) {
  697.             closesharedwindow(win);
  698.             win= ep->Win = newwin;
  699.             rp = win->RPort;
  700.  
  701.             menu_strip(win);
  702.             if (ep->Font)
  703.                 SetFont(rp, ep->Font);
  704.             set_window_params();
  705.             rest_prop(ep);
  706.             if (!text_sync())
  707.                 text_redisplay();
  708.             /** text_cursor(1); **/
  709.             MShowTitle = 0;
  710.             window_title();
  711.             ep->iconmode = 0;
  712.         }
  713.     }
  714. }
  715.  
  716.  
  717. void do_newwindow(void)
  718. {
  719.     WIN *win;
  720.  
  721.     if (Ep)
  722.         text_sync();
  723.     Nw.Title = (ubyte *)"    OK    ";
  724.  
  725.     if (text_init(Ep, NULL, &Nw)) {
  726.         if (win = opensharedwindow(&Nw)) {
  727.             menu_strip(win);
  728.             Ep->Win = win;
  729.  
  730.             if (Ep->Fontsize > 0 && Ep->Fontname[0])
  731.             {
  732.                char buf[10];
  733.                sprintf(buf, "%ld", Ep->Fontsize);
  734.                av[1] = Ep->Fontname;
  735.                av[2] = buf;
  736.                do_setfont();
  737.             }
  738.             set_window_params();
  739.             Ep->PropGad = add_prop(win);
  740.             text_load();
  741.         } else {
  742.             text_uninit();
  743.         }
  744.     }
  745. }
  746.  
  747. /*
  748.  *  openwindow with geometry specification.  Negative number specify
  749.  *  relative-right / relative-left (leftedge & topedge), or relative-width /
  750.  *  relative height (width & height).
  751.  *
  752.  *      <leftedge><topedge><width><height>
  753.  *
  754.  *  Example:    +10+10-20-20    Open window centered on screen 10 pixels
  755.  *                              from the border on all sides.
  756.  */
  757.  
  758. void do_openwindow(void)
  759. {
  760.     WIN *win;
  761.  
  762.     if (Ep)
  763.         text_sync();
  764.     Nw.Title = (ubyte *)"    OK    ";
  765.  
  766.     if (text_init(Ep, NULL, &Nw)) {
  767.         GeometryToNW(av[1], &Nw);
  768.         if (win = opensharedwindow(&Nw)) {
  769.             menu_strip(win);
  770.             Ep->Win = win;
  771.             set_window_params();
  772.             Ep->PropGad = add_prop(win);
  773.             text_load();
  774.         } else {
  775.             text_uninit();
  776.         }
  777.     }
  778. }
  779.  
  780.  
  781. WIN *TOpenWindow(struct NewWindow *nw)
  782. {
  783.     WIN *win;
  784.  
  785.     while ((win = OpenWindow(nw)) == NULL) {
  786.         if (nw->Width < 50 && nw->Height < 50)
  787.             break;
  788.         if(nw->Width >= 50)
  789.             nw->Width -= 10;
  790.         if(nw->Height >= 50)
  791.             nw->Height-= 10;
  792.     }
  793.     return(win);
  794. }
  795.  
  796.  
  797. WIN *opensharedwindow(struct NewWindow *nw)
  798. {
  799.     WIN *win;
  800.  
  801.     if (Sharedport)
  802.         nw->IDCMPFlags = NULL;
  803.     else
  804.         nw->IDCMPFlags = IDCMPFLAGS;
  805.     win = TOpenWindow(nw);
  806.     if (win) {
  807.         long xend = win->Width - win->BorderRight - 1;
  808.         long yend = win->Height- win->BorderBottom - 1;
  809.         if (Sharedport) {
  810.             win->UserPort = Sharedport;
  811.             ModifyIDCMP(win, IDCMPFLAGS);
  812.         } else {
  813.             Sharedport = win->UserPort;
  814.         }
  815.         ++Sharedrefs;
  816.         if (xend > win->BorderLeft && yend > win->BorderTop) {
  817.             SetAPen(win->RPort, nw->DetailPen);
  818.             RectFill(win->RPort, win->BorderLeft, win->BorderTop, xend, yend);
  819.             SetAPen(win->RPort, nw->BlockPen);
  820.         }
  821.     }
  822.     return(win);
  823. }
  824.  
  825. /* the following function straight from RKM by TJM */
  826. static void StripIntuiMessages(struct MsgPort *, struct Window *);
  827.  
  828. static void StripIntuiMessages(struct MsgPort *mp, struct Window  *win)
  829. {
  830.     struct IntuiMessage *msg, *succ;
  831.  
  832.     msg = (struct IntuiMessage *)(mp->mp_MsgList.lh_Head);
  833.  
  834.     while(succ = (struct IntuiMessage *)(msg->ExecMessage.mn_Node.ln_Succ))
  835.     {
  836.         if(msg->IDCMPWindow == win)
  837.         {
  838.             Remove((struct Node *)msg);
  839.             ReplyMsg((struct Message *)msg);
  840.         }
  841.         msg = succ;
  842.     }
  843. }
  844.  
  845. /* modifed TJM to close win's immediately using CloseWindowSafely from RKM */
  846. void closesharedwindow(WIN *win)
  847. {
  848.     if (win) {
  849.         SetWindowTitles(win, "", (char *)-1);
  850.         ClearMenuStrip(win);
  851.  
  852.         Forbid();
  853.  
  854.         StripIntuiMessages(win->UserPort,win);
  855.         if(--Sharedrefs)
  856.             win->UserPort = NULL;
  857.         else
  858.             Sharedport = NULL;
  859.         ModifyIDCMP(win,0);
  860.  
  861.         Permit();
  862.  
  863.         CloseWindow(win);
  864.  
  865.     } /* else something is very wrong.. */
  866. }
  867. #ifdef NOTDEF
  868. void closesharedwindow(WIN *win)
  869. {
  870.     static WIN *wunlink = NULL;
  871.     char notoktoclosenow = 0; /* a very odd and apparently useless variable... TJM */
  872.  
  873.     if (win) {
  874.         SetWindowTitles(win, "", (char *)-1);
  875.         ClearMenuStrip(win);
  876.         Forbid();
  877.         win->UserPort = NULL;
  878.         ModifyIDCMP(win, REQCLEAR);     /* NEVER occurs -- I think (TJM)  changed from GADGETUP which could be from prop.*/
  879.  
  880.         notoktoclosenow = 1;
  881.  
  882.         Permit();
  883.         if (notoktoclosenow) {
  884.             win->UserData = (char *)wunlink;
  885.             wunlink = win;
  886.         } else {
  887.             /* the following copied from RKM by TJM */
  888.             Forbid();
  889.             StripIntuiMessages(win->UserPort,win);
  890.             win->UserPort = NULL;
  891.             ModifyIDCMP(win,0);
  892.             Permit();
  893.  
  894.             CloseWindow(win);
  895.         }
  896.         --Sharedrefs;
  897.     } else {
  898.         if (Sharedrefs == 0 && Sharedport) {
  899.             DeletePort(Sharedport);
  900.             Sharedport = NULL;
  901.         }
  902.         for (win = wunlink; win; win = wunlink) {
  903.             wunlink = (WIN *)win->UserData;
  904.  
  905.             /* the following copied from RKM by TJM */
  906.             Forbid();
  907.             StripIntuiMessages(win->UserPort,win);
  908.             win->UserPort = NULL;
  909.             ModifyIDCMP(win,0);
  910.             Permit();
  911.  
  912.             CloseWindow(win);
  913.         }
  914.         wunlink = NULL;
  915.     }
  916. }
  917. #endif
  918.  
  919.  
  920. int getyn(char *text)
  921. {
  922.     if (ReqToolsBase)        /* reqtools part added by Karl Lukas 06/94 */
  923.     {
  924.        char buf[70];
  925.        TagItem tagitem[] =
  926.        {
  927.           RTEZ_ReqTitle, (ULONG)buf,
  928.           RT_Window, (ULONG)Ep->Win,
  929.           RT_WaitPointer, TRUE,
  930.           RTEZ_Flags, EZREQF_NORETURNKEY,
  931.           TAG_END, 0
  932.        };
  933.        sprintf(buf, "DME warning: %s", Ep->Name);
  934.        return rtEZRequestA(text, "OK|Cancel", NULL, NULL, tagitem);
  935.     }
  936.     else
  937.     {
  938.        int result;
  939.        ITEXT *body, *pos, *neg;
  940.  
  941.        body = (ITEXT *)AllocMem(sizeof(ITEXT), 0);
  942.        pos  = (ITEXT *)AllocMem(sizeof(ITEXT), 0);
  943.        neg  = (ITEXT *)AllocMem(sizeof(ITEXT), 0);
  944.        clrmem(body, sizeof(ITEXT));
  945.        clrmem(pos , sizeof(ITEXT));
  946.        clrmem(neg , sizeof(ITEXT));
  947.        body->BackPen = pos->BackPen = neg->BackPen = 1;
  948.        body->DrawMode= pos->DrawMode= neg->DrawMode= AUTODRAWMODE;
  949.        body->LeftEdge = 10;
  950.        body->TopEdge  = 12;
  951.        body->IText    = (ubyte *)text;
  952.        pos->LeftEdge = AUTOLEFTEDGE;
  953.        pos->TopEdge = AUTOTOPEDGE;
  954.        pos->IText = (ubyte *)"OK";
  955.        neg->LeftEdge = AUTOLEFTEDGE;
  956.        neg->TopEdge = AUTOTOPEDGE;
  957.        neg->IText = (ubyte *)"CANCEL";
  958.        result = AutoRequest(Ep->Win,body,pos,neg,0,0,320,58);
  959.        FreeMem(body, sizeof(ITEXT));
  960.        FreeMem(pos , sizeof(ITEXT));
  961.        FreeMem(neg , sizeof(ITEXT));
  962.        return(result);
  963.     }
  964. }
  965.  
  966. void title(char *buf)
  967. {
  968.     SetWindowTitles(Ep->Win, buf, (char *)-1);
  969.     Oldtlen = 999;
  970.     MShowTitle = 3;
  971. }
  972.  
  973. void window_title(void)
  974. {
  975.     int len, maxlen;
  976.  
  977.     if (memoryfail) {
  978.         title(" -- NO MEMORY -- ");
  979.         memoryfail = 0;
  980.         text_redisplay();
  981.     }
  982.     if (MForceTitle) {
  983.         MShowTitle = 0;
  984.         MForceTitle = 0;
  985.     }
  986.     if (MShowTitle) {
  987.         --MShowTitle;
  988.         return;
  989.     }
  990.     {
  991.         char *mod;
  992.         FONT *oldfont;
  993.         ED *ep = Ep;
  994.         WIN *win = ep->Win;
  995.         RP *rp = win->RPort;
  996.  
  997.         mod = (ep->Modified) ? " (modified)" : "          ";
  998.         sprintf(ep->Wtitle, "%3ld/%-3ld %3ld %s%s  ", text_lineno(), text_lines(), text_colno()+1, text_name(), mod);
  999.         if (!text_imode())
  1000.             strcat(ep->Wtitle, "Ovr ");
  1001.         len = strlen(ep->Wtitle);
  1002.         if (len < Columns && Columns < 128) {
  1003.             setmem(ep->Wtitle+len, Columns - len + 1, ' ');
  1004.             ep->Wtitle[Columns + 1] = 0;
  1005.         }
  1006.  
  1007.         /*
  1008.          *  Update title
  1009.          */
  1010.  
  1011.         if (IntuitionBase->LibNode.lib_Version >= 36) {
  1012.             SetWindowTitles(win, ep->Wtitle, (char *)-1);
  1013.         } else {
  1014.             oldfont = win->RPort->Font;
  1015.             SetFont(rp, win->WScreen->RastPort.Font);
  1016.  
  1017.             win->Title = ep->Wtitle;
  1018.             SetAPen(rp, ep->FGPen);
  1019.             SetBPen(rp, ep->TPen);
  1020.             Move(rp, 30, rp->Font->tf_Baseline+1);
  1021.             maxlen = (win->Width-96)/rp->Font->tf_XSize;
  1022.             if (maxlen < 0)
  1023.                 maxlen = 0;
  1024.             if (len > maxlen)
  1025.                 len = Oldtlen = maxlen;
  1026.             if (Oldtlen > maxlen)
  1027.                 Oldtlen = maxlen;
  1028.             Text(rp, ep->Wtitle, len);      /*  No flash                    */
  1029.             while (Oldtlen - len >= (int)sizeof(Space)) {
  1030.                 Text(rp, Space, sizeof(Space));
  1031.                 Oldtlen -= sizeof(Space);
  1032.             }
  1033.             if (Oldtlen - len > 0)
  1034.                 Text(rp, Space, Oldtlen - len);
  1035.             Oldtlen = len;                  /*  Oldtlen might have been <   */
  1036.             SetAPen(rp, ep->FGPen);
  1037.             SetBPen(rp, ep->BGPen);
  1038.             SetFont(rp, oldfont);
  1039.         }
  1040.     }
  1041. }
  1042.  
  1043.  
  1044. void set_window_params(void)
  1045. {
  1046.     ED *ep = Ep;
  1047.     WIN *win = ep->Win;
  1048.     RP  *rp = win->RPort;
  1049.  
  1050.     Xsize = rp->Font->tf_XSize;
  1051.     Ysize = rp->Font->tf_YSize;
  1052.     Xbase = win->BorderLeft;
  1053.     Ybase = win->BorderTop;
  1054.     Xpixs   = win->Width - win->BorderRight - Xbase;
  1055.     Ypixs   = win->Height- win->BorderBottom- Ybase;
  1056.     Columns = Xpixs / Xsize;
  1057.     Rows    = Ypixs / Ysize;
  1058.     if (Columns <= 0)
  1059.         Columns = 1;
  1060.     if (Rows <= 0)
  1061.         Rows = 1;
  1062.     XTbase  =  Xbase;
  1063.     YTbase  =  Ybase + rp->Font->tf_Baseline;
  1064.     SetAPen(rp, ep->FGPen);
  1065.     SetBPen(rp, ep->BGPen);
  1066. }
  1067.  
  1068. void exiterr(char *str)
  1069. {
  1070.     if (Output()) {
  1071.         Write(Output(),str,strlen(str));
  1072.         Write(Output(),"\n",1);
  1073.     }
  1074.     exit(1);
  1075. }
  1076.  
  1077.  
  1078. /*
  1079.  *  Check break by scanning pending messages in the I stream for a ^C.
  1080.  *  Msgchk forces a check, else the check is only made if the signal is
  1081.  *  set in the I stream (the signal is reset).
  1082.  */
  1083.  
  1084. int breakcheck(void)
  1085. {
  1086.     IMESS *im;
  1087.     WIN *win = Ep->Win;
  1088.     struct List *list = &win->UserPort->mp_MsgList;
  1089.  
  1090.     if (Msgchk || (SetSignal(0,0) & (1<<win->UserPort->mp_SigBit))) {
  1091.         Msgchk = 0;
  1092.         SetSignal(0,1<<win->UserPort->mp_SigBit);
  1093.  
  1094.         im = (IMESS *)list->lh_Head;
  1095.         Forbid();
  1096.         for (; im != (IMESS *)&list->lh_Tail; im = (IMESS *)im->ExecMessage.mn_Node.ln_Succ) {
  1097.             if (im->Class == RAWKEY && (im->Qualifier & 0xFB) == 0x08 &&
  1098.                 im->Code == CtlC) {
  1099.  
  1100.                 Permit();
  1101.                 SetSignal(SIGBREAKF_CTRL_C,SIGBREAKF_CTRL_C);
  1102.                 return(1);
  1103.             }
  1104.         }
  1105.         Permit();
  1106.     }
  1107.     return(0);
  1108. }
  1109.  
  1110. void breakreset(void)
  1111. {
  1112.     SetSignal(0, SIGBREAKF_CTRL_C);
  1113. }
  1114.  
  1115. /*
  1116.  *  resize cols rows
  1117.  */
  1118.  
  1119. void do_resize(void)
  1120. {
  1121.     WIN *win = Ep->Win;
  1122.     int cols = atoi(av[1]);
  1123.     int rows = atoi(av[2]);
  1124.     short width = (cols*win->RPort->Font->tf_XSize) + win->BorderLeft + win->BorderRight;
  1125.     short height= (rows*win->RPort->Font->tf_YSize) + win->BorderTop + win->BorderBottom;
  1126.  
  1127.     if (width < 16 || height < 16 ||
  1128.     width > win->WScreen->Width - win->LeftEdge ||
  1129.     height > win->WScreen->Height - win->TopEdge) {
  1130.         title ("window too big (try moving to upper left corner and retrying)");
  1131.         return;
  1132.     }
  1133.     SizeWindow(win, width - win->Width, height - win->Height);
  1134.     Delay(50*2);    /* wait 2 seconds */
  1135. }
  1136.  
  1137. int ops(char **av, int iswb)
  1138. {
  1139.     short nonops;
  1140.     short i;
  1141.     long val;
  1142.     char *str;
  1143.  
  1144.     for (i = nonops = 0; str = av[i]; ++i) {
  1145.         if (iswb) {
  1146.             if (strncmp(str, "ARG", 3) == 0) {
  1147.                 while (*str && *str != '-')
  1148.                     ++str;
  1149.             }
  1150.         }
  1151.         if (*str == '-') {
  1152.             val = atoi(str+2);
  1153.             switch(str[1]) {
  1154.             case 'f':
  1155.                 Ffile = str+2;
  1156.                 break;
  1157.             case 'n':
  1158.                 NewDME = 1;
  1159.                 break;
  1160.             case 'b':
  1161.                 /*SizeOveride = 1;*/
  1162.                 break;
  1163.             case 't':
  1164.                 /*Nwtopedge = val;*/
  1165.                 break;
  1166.             case 'l':
  1167.                 /*Nwleftedge= val;*/
  1168.                 break;
  1169.             case 'w':
  1170.                 /*SizeOveride = 1;*/
  1171.                 /*Nwwidth   = val;*/
  1172.                 break;
  1173.             case 'h':
  1174.                 /*SizeOveride = 1;*/
  1175.                 /*Nwheight  = val;*/
  1176.                 break;
  1177.             case 'i':
  1178.                 DoIconify = 1;
  1179.                 break;
  1180.             }
  1181.         } else {
  1182.             ++nonops;
  1183.         }
  1184.     }
  1185.     return((int)nonops);
  1186. }
  1187.  
  1188. /*
  1189.  *  Convert geometry to nw params.
  1190.  */
  1191.  
  1192. char *geoskip(char *ptr, int *pval, int *psgn)
  1193. {
  1194.     if (*ptr == '-')
  1195.         *psgn = -1;
  1196.     else
  1197.         *psgn = 1;
  1198.     if (*ptr == '-' || *ptr == '+')
  1199.         ++ptr;
  1200.     *pval = atoi(ptr);
  1201.     while (*ptr >= '0' && *ptr <= '9')
  1202.         ++ptr;
  1203.     return(ptr);
  1204. }
  1205.  
  1206. void GeometryToNW(char *geo, struct NewWindow *nw)
  1207. {
  1208.     int n;
  1209.     int sign;
  1210.     struct Screen scr;
  1211.  
  1212.     GetScreenData(&scr, sizeof(scr), WBENCHSCREEN, NULL);
  1213.  
  1214.     if (*geo) {
  1215.         geo = geoskip(geo, &n, &sign);
  1216.         if (sign > 0)
  1217.             nw->LeftEdge = n;
  1218.         else
  1219.             nw->LeftEdge = scr.Width - n;
  1220.     }
  1221.     if (*geo) {
  1222.         geo = geoskip(geo, &n, &sign);
  1223.         if (sign > 0)
  1224.             nw->TopEdge = n;
  1225.         else
  1226.             nw->TopEdge = scr.Height - n;
  1227.     }
  1228.     if (*geo) {
  1229.         geo = geoskip(geo, &n, &sign);
  1230.         if (sign > 0)
  1231.             nw->Width = n;
  1232.         else
  1233.             nw->Width = scr.Width - nw->LeftEdge - n;
  1234.     }
  1235.     if (*geo) {
  1236.         geo = geoskip(geo, &n, &sign);
  1237.         if (sign > 0)
  1238.             nw->Height = n;
  1239.         else
  1240.             nw->Height = scr.Height - nw->TopEdge - n;
  1241.     }
  1242. }
  1243.  
  1244. /* prop gadget stuff (TJM) */
  1245.  
  1246. void rest_prop(ED *ep)
  1247. {
  1248.     if(!ep->PropGad)
  1249.         return;
  1250.     AddGadget(ep->Win,ep->PropGad,0);
  1251.     RefreshGList(ep->PropGad,ep->Win,NULL,1);
  1252. }
  1253.  
  1254. struct Gadget *add_prop(struct Window *win)
  1255. {
  1256.     struct PropGadget *pg;
  1257.  
  1258.     if(!(pg = (struct PropGadget *)malloc(sizeof(*pg))))
  1259.         return NULL;
  1260.  
  1261.     memcpy(pg,&PropTemp,sizeof(PropTemp));
  1262.     pg->g.TopEdge = win->BorderTop + 1;
  1263.     pg->g.Height = -(win->BorderTop + 12);
  1264.     pg->p.Flags = AUTOKNOB|FREEVERT|PROPNEWLOOK;      /* PROPNEWLOOK is 2.0-dependent -- it == 0x0010 if you don't have 2.0 incl's */
  1265.     pg->p.HorizPot = pg->p.VertPot = pg->p.HorizBody = pg->p.VertBody = -1;
  1266.     pg->g.SpecialInfo = (APTR)&pg->p;
  1267.     pg->g.GadgetRender = &pg->i;
  1268.  
  1269.     AddGadget(win,&pg->g,0);
  1270.     RefreshGList(&pg->g,win,NULL,1);
  1271.     noadj = 0;      /* allow scroller refreshing */
  1272.  
  1273.     return &pg->g;
  1274. }
  1275.  
  1276.  
  1277. void prop_adj(void)
  1278. {
  1279.     ULONG hidden = max(Ep->Lines - Rows, 0);
  1280.     ULONG VertBody, VertPot;
  1281.     ULONG topLine = min(Ep->Topline,hidden);
  1282.     ULONG Overlap = (Rows * (100 - Pagejump)) / 100;
  1283.  
  1284.     if(!Ep->PropGad || noadj)       /* block adjustment when already set by prop gad */
  1285.         return;
  1286.  
  1287.     /* all these damn castings... */
  1288.     if(hidden > 0) {
  1289.         VertBody = ((Rows - Overlap) * MAXBODY) / (Ep->Lines - Overlap);
  1290.         VertPot = (topLine * MAXPOT) / hidden;
  1291.     }
  1292.     else {
  1293.         VertBody = MAXBODY;
  1294.         VertPot = 0;
  1295.     }
  1296.     NewModifyProp(Ep->PropGad,Ep->Win,NULL,AUTOKNOB|FREEVERT|PROPNEWLOOK,MAXPOT,VertPot,MAXBODY,VertBody,1);
  1297. }
  1298.  
  1299. int new_top(void)
  1300. {
  1301.     struct PropInfo *Prop;
  1302.     int hidden = max(Ep->Lines - Rows, 0);
  1303.  
  1304.     Prop = (struct PropInfo *)(Ep->PropGad->SpecialInfo);
  1305.  
  1306.     return ((hidden * Prop->VertPot + MAXPOT/2) / MAXPOT);
  1307. }
  1308.  
  1309. void clear_window(void)
  1310. {
  1311.    struct Window *win = Ep->Win;
  1312.    struct RastPort *rp = win->RPort;
  1313.  
  1314.    SetAPen(rp, Ep->BGPen);
  1315.    RectFill(rp, win->BorderLeft,
  1316.                 win->Height - win->BorderBottom - rp->Font->tf_YSize,
  1317.                 win->Width - win->BorderRight - 1,
  1318.                 win->Height - win->BorderBottom - 1);
  1319.    SetAPen(rp, Ep->FGPen);
  1320. }
  1321.  
  1322.