home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / dme_441.lzh / Dme / src / main.c < prev    next >
C/C++ Source or Header  |  1991-01-24  |  20KB  |  949 lines

  1.  
  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.  
  13. Prototype short Xsize, Ysize;
  14. Prototype short XTbase, YTbase;
  15. Prototype short Rows, Columns;
  16. Prototype short Xbase, Ybase;
  17. Prototype short Xpixs, Ypixs;
  18.  
  19. Prototype ubyte *av[];
  20. Prototype char Wdisable;
  21.  
  22. Prototype void ipchandler (void);
  23. Prototype void initipc (void);
  24. Prototype void do_ipc (void);
  25. Prototype void do_iconify (void);
  26. Prototype void do_tomouse (void);
  27. Prototype void iconify (void);
  28. Prototype void uniconify (void);
  29. Prototype void do_newwindow ();
  30. Prototype void do_openwindow();
  31. Prototype struct Window *TOpenWindow (struct NewWindow *);
  32. Prototype struct Window *opensharedwindow (struct NewWindow *);
  33. Prototype void closesharedwindow (struct Window *);
  34. Prototype int getyn (char *);
  35. Prototype void title (char *);
  36. Prototype void window_title (void);
  37. Prototype void set_window_params (void);
  38. Prototype void exiterr (char *);
  39. Prototype int breakcheck (void);
  40. Prototype void breakreset (void);
  41. Prototype void do_resize (void);
  42. Prototype int ops (char **, int);
  43.  
  44. typedef struct Process        PROC;
  45. typedef struct WBStartup    WBS;
  46. typedef struct DiskObject   DISKOBJ;
  47.  
  48. #define IDCMPFLAGS   CLOSEWINDOW|NEWSIZE|RAWKEY|MOUSEBUTTONS|ACTIVEWINDOW|MOUSEMOVE|MENUPICK
  49.  
  50. extern void GeometryToNW(char *, struct NewWindow *);
  51. extern WIN *OpenWindow();
  52. extern void *OpenLibrary();
  53. extern void *GetDiskObject();
  54.  
  55. struct NewWindow Nw = {
  56.    0, 1, 0  , 0  , -1, -1,  /*    width, height filled in by program */
  57.    IDCMPFLAGS,
  58.    ACTIVATE|WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|NOCAREREFRESH|RMBTRAP,
  59.    NULL, NULL, (ubyte *)"   WAIT   ",
  60.    NULL, NULL,
  61.    32, 32, -1, -1,
  62.    WBENCHSCREEN
  63. };
  64.  
  65. short Sharedrefs;
  66. short Oldtlen = 999;      /*  Old Title Length      */
  67. struct MsgPort *Sharedport;
  68. static DISKOBJ *Do;
  69. WBS    *Wbs;
  70.  
  71. short Xsize,  Ysize;        /* font character sizes        */
  72. short Rows,  Columns;        /* character rows/cols available       */
  73. short Xbase,  Ybase;        /* offset pixel base for display       */
  74. short XTbase,YTbase;        /* used for text display           */
  75. short Xpixs,  Ypixs;        /* actual # X/Y pixels available       */
  76. short Mx, My;
  77.  
  78. ubyte *av[8];
  79. char Quitflag;
  80. char Overide;
  81. char Wdisable = 1;        /* Disable icon save               */
  82. char MShowTitle, MForceTitle;
  83.  
  84. #ifdef NOTDEF
  85. PORT *IPCPort;
  86. #endif
  87.  
  88. PORT *IPCRPort;
  89.  
  90. long Mask;
  91.  
  92. struct IntuitionBase *IntuitionBase;
  93. struct GfxBase *GfxBase;
  94. struct Library *IconBase;
  95.  
  96. extern int Enable_Abort;
  97.  
  98. static char *Ffile;
  99.  
  100. int main(int, char **);
  101.  
  102. int
  103. wbmain(wbs)
  104. WBS *wbs;
  105. {
  106.     return(main(0, wbs));
  107. }
  108.  
  109. int
  110. main(mac, mav)
  111. int mac;
  112. char **mav;
  113. {
  114.     char nf, ni;        /*    # files on command line     */
  115.     char notdone;        /*    for endless loop        */
  116.     char iawm = 0;        /*    overide mouse buttons        */
  117.     char dontwait = 0;        /*    don't wait for a message    */
  118.     short i;
  119.     short Code;
  120.     PROC *proc = (PROC *)FindTask(NULL);
  121.     BPTR origlock;
  122.  
  123.     fclose(stdin);
  124.     /*fclose(stdout);*/     /*  assume person will run >nil:    */
  125.     fclose(stderr);         /*  close stderr & console ref. */
  126.     origlock = CurrentDir(DupLock((BPTR)proc->pr_CurrentDir));
  127.  
  128.     NewList((LIST *)&DBase);
  129.     NewList((LIST *)&PBase);
  130.     IntuitionBase = OpenLibrary("intuition.library", 0);
  131.     GfxBase = OpenLibrary("graphics.library", 0);
  132.     if (IntuitionBase == (void *)NULL || GfxBase == (void *)NULL)
  133.     exiterr("cannot open intuition or graphics library");
  134.  
  135.     init_command();
  136.  
  137.     String  = (char *)malloc(1);        /*  initialize scanf variable   */
  138.     *String = 0;
  139.  
  140.     if (mac == 0) {             /*  WORKBENCH STARTUP   */
  141.     Wdisable = 0;        /*  allow icon save    */
  142.     Wbs = (WBS *)mav;
  143.     IconBase = OpenLibrary("icon.library", 0);
  144.     if (IconBase == NULL)
  145.         exiterr("unable to open icon library");
  146.     }
  147.  
  148. #if AREXX
  149.     {
  150.     mountrequest(0);
  151.     openrexx();     /*   do this after the last possible call to exiterr() */
  152.     mountrequest(1);
  153.     }
  154. #endif
  155.     resethash();
  156.  
  157.     if (Wbs) {
  158.     if (Wbs->sm_ArgList[0].wa_Lock) {
  159.         BPTR savelock = CurrentDir((BPTR)Wbs->sm_ArgList[0].wa_Lock);
  160.         if (Do = GetDiskObject(Wbs->sm_ArgList[0].wa_Name)) {
  161.         ops(Do->do_ToolTypes, 1);
  162.         FreeDiskObject(Do);
  163.         }
  164.         CurrentDir(savelock);
  165.     }
  166.     nf = Wbs->sm_NumArgs - 1;
  167.     mac = 99;
  168.     } else {
  169.     nf = ops(mav+1, 0);
  170.     }
  171.  
  172.     for (ni = 0, i = 1; i < mac; ++i) {
  173.     char *str;
  174.     DISKOBJ *dso;
  175.     if (Wbs) {
  176.         if (i > nf)
  177.         break;
  178.         str = Wbs->sm_ArgList[i].wa_Name;
  179.         UnLock(CurrentDir(DupLock((BPTR)Wbs->sm_ArgList[i].wa_Lock)));
  180.         if (dso = GetDiskObject(Wbs->sm_ArgList[i].wa_Name)) {
  181.         ops(dso->do_ToolTypes, 1);
  182.         FreeDiskObject(dso);
  183.         }
  184.     } else {
  185.         str = mav[i];
  186.         if (*str == '-')
  187.         continue;
  188.     }
  189.     do_newwindow();
  190.     ++ni;
  191.     av[0] = (ubyte *)"newfile";
  192.     av[1] = (ubyte *)str;
  193.     do_edit();
  194.     MForceTitle = 1;
  195.     window_title();
  196.     }
  197.     if (nf == 0)                    /* no files to edit */
  198.     do_newwindow();
  199.  
  200.     mountrequest(0);
  201.     av[0] = NULL;
  202.     av[1] = (ubyte *)"s:.edrc";
  203.     do_source();
  204.     av[0] = NULL;
  205.     av[1] = (ubyte *)((Ffile) ? Ffile : ".edrc");
  206.     do_source();
  207.     mountrequest(1);
  208.     {                /*    1.29c    */
  209.     ED *ep;
  210.     ED *eb = Ep;
  211.     if (eb) {
  212.         for (ep = (ED *)eb->Node.mln_Succ; ep->Node.mln_Succ; ep = (ED *)ep->Node.mln_Succ) {
  213.         ep->Tabstop = eb->Tabstop;
  214.         ep->Margin  = eb->Margin;
  215.         ep->Insertmode = eb->Insertmode;
  216.         ep->IgnoreCase = eb->IgnoreCase;
  217.         ep->Wordwrap   = eb->Wordwrap;
  218.         if (eb->Font) {
  219.             ep->Font = eb->Font;
  220.             ++eb->Font->tf_Accessors;
  221.         }
  222.         }
  223.     }
  224.     }
  225.     title("DME V1.43 \251Copyright 1988-1990 by Matthew Dillon,  All Rights Reserved             ");
  226.     Mask |= 1 << Ep->Win->UserPort->mp_SigBit;
  227. loop:
  228.     if (!Ep->iconmode)
  229.     text_cursor(1);
  230.     for (notdone = 1; !Quitflag && notdone;) {
  231.     char mmove = 0;
  232.     short mqual;
  233.  
  234.     if (!Ep->iconmode)
  235.         window_title();
  236.     if (dontwait) {
  237.         --dontwait;
  238.     } else {
  239.         Wait(Mask);
  240.     }
  241.  
  242.     /*
  243.      *  NOTE: due to operation of breakcheck(), the userport signal
  244.      *  may not be set even if there are messages pending.
  245.      */
  246.  
  247.     {
  248.         IMESS *im;
  249.         while (im = (IMESS *)GetMsg(Ep->Win->UserPort)) {
  250.         Msgchk = 1;
  251.         Abortcommand = 0;
  252.         Code = im->Code;
  253.         if (im->IDCMPWindow != Ep->Win) {
  254.             Overide = 0;
  255.             if (Comlinemode)
  256.             escapecomlinemode();
  257.             text_sync();
  258.             MShowTitle = 0;
  259.             if (!Ep->iconmode)
  260.             window_title();
  261.             if (text_switch(im->IDCMPWindow) == 0) {
  262.             ReplyMsg((MSG *)im);
  263.             continue;
  264.             }
  265.         }
  266.         Mx = im->MouseX;
  267.         My = im->MouseY;
  268.         switch(im->Class) {
  269.         case NEWSIZE:
  270.             if (!Ep->iconmode) {
  271.             if (Comlinemode)
  272.                 escapecomlinemode();
  273.             set_window_params();
  274.             if (!text_sync())
  275.                 text_redisplay();
  276.             text_cursor(1);
  277.             }
  278.             break;
  279.         case MOUSEBUTTONS:
  280.             switch(Code) {
  281.             case SELECTDOWN:
  282.             case MENUDOWN:
  283.             if (Ep->iconmode || iawm) {
  284.                 uniconify();
  285.                 break;
  286.             }
  287.             Forbid();
  288.             Ep->Win->Flags |= REPORTMOUSE;
  289.             Permit();
  290.             uniconify();
  291.             text_cursor(0);
  292.             keyctl(NULL, im->Code|0x80, im->Qualifier);
  293.             text_cursor(1);
  294.             break;
  295.             case SELECTUP:
  296.             case MENUUP:
  297.             Forbid();
  298.             Ep->Win->Flags &= ~REPORTMOUSE;
  299.             Permit();
  300.             break;
  301.             }
  302.             break;
  303.         case RAWKEY:
  304.             if ((im->Code & 0x80) == 0) {
  305.             /*  Handled in command interpreter.
  306.             if (Ep->iconmode) {
  307.                 uniconify();
  308.                 break;
  309.             }
  310.             */
  311.             text_cursor(0);
  312.             keyctl(im, im->Code, im->Qualifier);
  313.             text_cursor(1);
  314.             }
  315.             break;
  316.         case MENUPICK:
  317.             {
  318.             char *str = menu_cmd(im);
  319.             if (str) {
  320.                 str = strcpy(malloc(strlen(str)+1), str);
  321.                 text_cursor(0);
  322.                 do_command(str);
  323.                 free(str);
  324.                 text_cursor(1);
  325.             }
  326.             }
  327.             break;
  328.         case CLOSEWINDOW:
  329.             if (Comlinemode)
  330.             escapecomlinemode();
  331.             text_sync();
  332.             notdone = 0;
  333.             break;
  334.         case ACTIVEWINDOW:
  335.             if (!Ep->iconmode)
  336.             iawm = 1;
  337.             break;
  338.         case MOUSEMOVE:
  339.             mmove = 1;
  340.             mqual = im->Qualifier;
  341.             break;
  342.         }
  343.         if (im)
  344.             ReplyMsg((MSG *)im);
  345.         if (notdone == 0 || Quitflag) {
  346.             dontwait = 2;
  347.             goto boom;
  348.         }
  349.         }
  350.     }
  351.  
  352.     iawm = 0;
  353.     if (mmove) {
  354.         uniconify();
  355.         mmove = 0;
  356.         text_cursor(0);
  357.         keyctl(NULL, QMOVE, mqual);
  358.         text_cursor(1);
  359.     }
  360.     closesharedwindow(NULL);
  361.     }
  362. boom:
  363.     text_sync();
  364.     if (Ep->Modified && !Overide) {
  365.     uniconify();
  366.     Overide = 1;
  367.     title("*** File has been modified ***");
  368.     Quitflag = 0;
  369.     goto loop;
  370.     }
  371.     SetWindowTitles(Ep->Win, "", (char *)-1);
  372.     {
  373.     WIN *win = Ep->Win;
  374.     text_uninit();
  375.     closesharedwindow(win);
  376.     }
  377.     if (Ep) {
  378.     Quitflag = 0;
  379.     if (!Ep->iconmode)
  380.         set_window_params();
  381.     text_load();
  382.     MShowTitle = 0;
  383.     goto loop;
  384.     }
  385.     closesharedwindow(NULL);
  386. #if AREXX
  387.     closerexx();
  388. #endif
  389.     UnLock(CurrentDir(origlock));
  390.     if (IPCRPort)
  391.     DeletePort(IPCRPort);
  392.     if (IconBase)
  393.     CloseLibrary(IconBase);
  394.     if (GfxBase)
  395.     CloseLibrary(GfxBase);
  396.     if (IntuitionBase)
  397.     CloseLibrary(IntuitionBase);
  398.     IconBase = GfxBase = IntuitionBase = 0;
  399.     dealloc_hash();
  400.     return(0);
  401. }
  402.  
  403. void
  404. do_iconify()
  405. {
  406.     text_sync();
  407.     if (!Comlinemode)
  408.     iconify();
  409. }
  410.  
  411. void
  412. do_tomouse()
  413. {
  414.     text_position((Mx-Xbase)/Xsize, (My-Ybase)/Ysize);
  415. }
  416.  
  417. void
  418. iconify()
  419. {
  420.     WIN *newwin;
  421.     ED *ep = Ep;
  422.     WIN *win = ep->Win;
  423.  
  424.     if (!ep->iconmode) {
  425.     ep->Winx      = win->LeftEdge;
  426.     ep->Winy      = win->TopEdge;
  427.     ep->Winwidth  = win->Width;
  428.     ep->Winheight = win->Height;
  429.     Nw.Height = win->RPort->TxHeight + 3;
  430.     Nw.Width  = 20 + 5*8 + strlen(ep->Name) * (win->RPort->TxWidth + win->RPort->TxSpacing);
  431.     if (ep->Modified)
  432.         Nw.Width -= 3*8;
  433.     Nw.LeftEdge= ep->IWinx;
  434.     Nw.TopEdge = ep->IWiny;
  435.     if (Nw.LeftEdge + Nw.Width > win->WScreen->Width)
  436.         Nw.LeftEdge = win->WScreen->Width - Nw.Width;
  437.     if (Nw.TopEdge + Nw.Height > win->WScreen->Height)
  438.         Nw.TopEdge = win->WScreen->Height - Nw.Height;
  439.     Nw.Title = ep->Wtitle;
  440.     Nw.Flags &= ~(WINDOWSIZING|WINDOWDEPTH|ACTIVATE);
  441.     if (ep->Modified)
  442.         Nw.Flags &= ~WINDOWCLOSE;
  443.     Nw.Flags |= BORDERLESS;
  444.     Nw.DetailPen = ep->BGPen;
  445.     Nw.BlockPen  = ep->FGPen;
  446.     if (win->Flags & WINDOWACTIVE)      /*  KTS */
  447.         Nw.Flags |= ACTIVATE;
  448.     sprintf(ep->Wtitle, "%s     ", ep->Name);
  449.     if (newwin = opensharedwindow(&Nw)) {
  450.         closesharedwindow(win);
  451.         Nw.BlockPen = -1;
  452.         ep->iconmode = 1;
  453.         ep->Win = newwin;
  454.     }
  455.     Nw.Flags |= WINDOWSIZING|WINDOWDEPTH|WINDOWCLOSE|ACTIVATE;
  456.     Nw.Flags &= ~BORDERLESS;
  457.     }
  458. }
  459.  
  460. void
  461. uniconify()
  462. {
  463.     ED *ep = Ep;
  464.     WIN *win = ep->Win;
  465.     WIN *newwin;
  466.     RP *rp;
  467.  
  468.     if (ep->iconmode) {
  469.     ep->IWinx = win->LeftEdge;
  470.     ep->IWiny = win->TopEdge;
  471.     Nw.LeftEdge = ep->Winx;
  472.     Nw.TopEdge  = ep->Winy;
  473.     Nw.Width    = ep->Winwidth;
  474.     Nw.Height   = ep->Winheight;
  475.     Nw.Title    = ep->Wtitle;
  476.     Nw.DetailPen = ep->BGPen;
  477.     Nw.BlockPen  = ep->FGPen;
  478.  
  479.     if (newwin = opensharedwindow(&Nw)) {
  480.         closesharedwindow(win);
  481.         win= ep->Win = newwin;
  482.         rp = win->RPort;
  483.  
  484.         menu_strip(win);
  485.         if (ep->Font)
  486.         SetFont(rp, ep->Font);
  487.         set_window_params();
  488.         if (!text_sync())
  489.         text_redisplay();
  490.         text_cursor(1);
  491.         MShowTitle = 0;
  492.         window_title();
  493.         ep->iconmode = 0;
  494.     }
  495.     }
  496. }
  497.  
  498.  
  499. void
  500. do_newwindow()
  501. {
  502.     WIN *win;
  503.  
  504.     if (Ep)
  505.     text_sync();
  506.     Nw.Title = (ubyte *)"    OK    ";
  507.  
  508.     if (text_init(Ep, NULL, &Nw)) {
  509.     if (win = opensharedwindow(&Nw)) {
  510.         menu_strip(win);
  511.         Ep->Win = win;
  512.         set_window_params();
  513.         text_load();
  514.     } else {
  515.         text_uninit();
  516.     }
  517.     }
  518. }
  519.  
  520. /*
  521.  *  openwindow with geometry specification.  Negative number specify
  522.  *  relative-right / relative-left (leftedge & topedge), or relative-width /
  523.  *  relative height (width & height).
  524.  *
  525.  *    <leftedge><topedge><width><height>
  526.  *
  527.  *  Example:    +10+10-20-20    Open window centered on screen 10 pixels
  528.  *                from the border on all sides.
  529.  */
  530.  
  531. void
  532. do_openwindow()
  533. {
  534.     WIN *win;
  535.  
  536.     if (Ep)
  537.     text_sync();
  538.     Nw.Title = (ubyte *)"    OK    ";
  539.  
  540.     if (text_init(Ep, NULL, &Nw)) {
  541.     GeometryToNW(av[1], &Nw);
  542.     if (win = opensharedwindow(&Nw)) {
  543.         menu_strip(win);
  544.         Ep->Win = win;
  545.         set_window_params();
  546.         text_load();
  547.     } else {
  548.         text_uninit();
  549.     }
  550.     }
  551. }
  552.  
  553.  
  554. WIN *
  555. TOpenWindow(nw)
  556. struct NewWindow *nw;
  557. {
  558.     WIN *win;
  559.  
  560.     while ((win = OpenWindow(nw)) == NULL) {
  561.     if (nw->Width < 50 || nw->Height < 50)
  562.         break;
  563.     nw->Width -= 10;
  564.     nw->Height-= 10;
  565.     }
  566.     return(win);
  567. }
  568.  
  569.  
  570. WIN *
  571. opensharedwindow(nw)
  572. struct NewWindow *nw;
  573. {
  574.     WIN *win;
  575.  
  576.     if (Sharedport)
  577.     nw->IDCMPFlags = NULL;
  578.     else
  579.     nw->IDCMPFlags = IDCMPFLAGS;
  580.     win = TOpenWindow(nw);
  581.     if (win) {
  582.     long xend = win->Width - win->BorderRight - 1;
  583.     long yend = win->Height- win->BorderBottom - 1;
  584.     if (Sharedport) {
  585.         win->UserPort = Sharedport;
  586.         ModifyIDCMP(win, IDCMPFLAGS);
  587.     } else {
  588.         Sharedport = win->UserPort;
  589.     }
  590.     ++Sharedrefs;
  591.     if (xend > win->BorderLeft && yend > win->BorderTop) {
  592.         SetAPen(win->RPort, nw->DetailPen);
  593.         RectFill(win->RPort, win->BorderLeft, win->BorderTop, xend, yend);
  594.         SetAPen(win->RPort, nw->BlockPen);
  595.     }
  596.     }
  597.     return(win);
  598. }
  599.  
  600. void
  601. closesharedwindow(win)
  602. WIN *win;
  603. {
  604.     static WIN *wunlink;
  605.     char notoktoclosenow = 0;
  606.  
  607.     if (win) {
  608.     SetWindowTitles(win, "", (char *)-1);
  609.     ClearMenuStrip(win);
  610.     Forbid();
  611.     win->UserPort = NULL;
  612.     ModifyIDCMP(win, GADGETUP);     /* NEVER occurs */
  613.  
  614.     notoktoclosenow = 1;
  615.  
  616.     Permit();
  617.     if (notoktoclosenow) {
  618.         win->UserData = (char *)wunlink;
  619.         wunlink = win;
  620.     } else {
  621.         CloseWindow(win);
  622.     }
  623.     --Sharedrefs;
  624.     } else {
  625.     if (Sharedrefs == 0 && Sharedport) {
  626.         DeletePort(Sharedport);
  627.         Sharedport = NULL;
  628.     }
  629.     for (win = wunlink; win; win = wunlink) {
  630.         wunlink = (WIN *)win->UserData;
  631.         CloseWindow(win);
  632.     }
  633.     wunlink = NULL;
  634.     }
  635. }
  636.  
  637.  
  638. getyn(text)
  639. char *text;
  640. {
  641.     int result;
  642.     ITEXT *body, *pos, *neg;
  643.  
  644.     body = (ITEXT *)AllocMem(sizeof(ITEXT), 0);
  645.     pos  = (ITEXT *)AllocMem(sizeof(ITEXT), 0);
  646.     neg  = (ITEXT *)AllocMem(sizeof(ITEXT), 0);
  647.     clrmem(body, sizeof(ITEXT));
  648.     clrmem(pos , sizeof(ITEXT));
  649.     clrmem(neg , sizeof(ITEXT));
  650.     body->BackPen = pos->BackPen = neg->BackPen = 1;
  651.     body->DrawMode= pos->DrawMode= neg->DrawMode= AUTODRAWMODE;
  652.     body->LeftEdge = 10;
  653.     body->TopEdge  = 12;
  654.     body->IText    = (ubyte *)text;
  655.     pos->LeftEdge = AUTOLEFTEDGE;
  656.     pos->TopEdge = AUTOTOPEDGE;
  657.     pos->IText = (ubyte *)"OK";
  658.     neg->LeftEdge = AUTOLEFTEDGE;
  659.     neg->TopEdge = AUTOTOPEDGE;
  660.     neg->IText = (ubyte *)"CANCEL";
  661.     result = AutoRequest(Ep->Win,body,pos,neg,0,0,320,58);
  662.     FreeMem(body, sizeof(ITEXT));
  663.     FreeMem(pos , sizeof(ITEXT));
  664.     FreeMem(neg , sizeof(ITEXT));
  665.     return(result);
  666. }
  667.  
  668. void
  669. title(buf)
  670. char *buf;
  671. {
  672.     SetWindowTitles(Ep->Win, buf, (char *)-1);
  673.     Oldtlen = 999;
  674.     MShowTitle = 3;
  675. }
  676.  
  677. void
  678. window_title()
  679. {
  680.     int len, maxlen;
  681.  
  682.     if (memoryfail) {
  683.     title(" -- NO MEMORY -- ");
  684.     memoryfail = 0;
  685.     text_redisplay();
  686.     }
  687.     if (MForceTitle) {
  688.     MShowTitle = 0;
  689.     MForceTitle = 0;
  690.     }
  691.     if (MShowTitle) {
  692.     --MShowTitle;
  693.     return;
  694.     }
  695.     {
  696.     char *mod;
  697.     FONT *oldfont;
  698.     ED *ep = Ep;
  699.     WIN *win = ep->Win;
  700.     RP *rp = win->RPort;
  701.  
  702.     mod = (ep->Modified) ? " (modified)" : "          ";
  703.     sprintf(ep->Wtitle, "%3ld/%-3ld %3ld %s%s  ", text_lineno(), text_lines(), text_colno()+1, text_name(), mod);
  704.     if (!text_imode())
  705.         strcat(ep->Wtitle, "Ovr ");
  706.     len = strlen(ep->Wtitle);
  707.     if (len < Columns && Columns < 128) {
  708.         setmem(ep->Wtitle+len, Columns - len + 1, ' ');
  709.         ep->Wtitle[Columns + 1] = 0;
  710.     }
  711.  
  712.     /*
  713.      *  Update title
  714.      */
  715.  
  716.     oldfont = win->RPort->Font;
  717.     SetFont(rp, win->WScreen->RastPort.Font);
  718.  
  719.     win->Title = ep->Wtitle;
  720.     SetAPen(rp, ep->FGPen);
  721.     SetBPen(rp, ep->TPen);
  722.     Move(rp, 30, rp->Font->tf_Baseline+1);
  723.     maxlen = (win->Width-96)/rp->Font->tf_XSize;
  724.     if (maxlen < 0)
  725.         maxlen = 0;
  726.     if (len > maxlen)
  727.         len = Oldtlen = maxlen;
  728.     if (Oldtlen > maxlen)
  729.         Oldtlen = maxlen;
  730.     Text(rp, ep->Wtitle, len);      /*  No flash                    */
  731.     while (Oldtlen - len >= (int)sizeof(Space)) {
  732.         Text(rp, Space, sizeof(Space));
  733.         Oldtlen -= sizeof(Space);
  734.     }
  735.     if (Oldtlen - len > 0)
  736.         Text(rp, Space, Oldtlen - len);
  737.     Oldtlen = len;            /*  Oldtlen might have been <    */
  738.     SetAPen(rp, ep->FGPen);
  739.     SetBPen(rp, ep->BGPen);
  740.  
  741.     SetFont(rp, oldfont);
  742.     }
  743. }
  744.  
  745. void
  746. set_window_params()
  747. {
  748.     ED *ep = Ep;
  749.     WIN *win = ep->Win;
  750.     RP    *rp = win->RPort;
  751.  
  752.     Xsize = rp->Font->tf_XSize;
  753.     Ysize = rp->Font->tf_YSize;
  754.     Xbase = win->BorderLeft;
  755.     Ybase = win->BorderTop;
  756.     Xpixs   = win->Width - win->BorderRight - Xbase;
  757.     Ypixs   = win->Height- win->BorderBottom- Ybase;
  758.     Columns = Xpixs / Xsize;
  759.     Rows    = Ypixs / Ysize;
  760.     XTbase  =  Xbase;
  761.     YTbase  =  Ybase + rp->Font->tf_Baseline;
  762.     SetAPen(rp, ep->FGPen);
  763.     SetBPen(rp, ep->BGPen);
  764. }
  765.  
  766. void
  767. exiterr(str)
  768. char *str;
  769. {
  770.     if (Output()) {
  771.     Write(Output(),str,strlen(str));
  772.     Write(Output(),"\n",1);
  773.     }
  774.     exit(1);
  775. }
  776.  
  777.  
  778. /*
  779.  *  Check break by scanning pending messages in the I stream for a ^C.
  780.  *  Msgchk forces a check, else the check is only made if the signal is
  781.  *  set in the I stream (the signal is reset).
  782.  */
  783.  
  784. breakcheck()
  785. {
  786.     IMESS *im;
  787.     WIN *win = Ep->Win;
  788.     struct List *list = &win->UserPort->mp_MsgList;
  789.  
  790.     if (Msgchk || (SetSignal(0,0) & (1<<win->UserPort->mp_SigBit))) {
  791.     Msgchk = 0;
  792.     SetSignal(0,1<<win->UserPort->mp_SigBit);
  793.  
  794.     im = (IMESS *)list->lh_Head;
  795.     Forbid();
  796.     for (; im != (IMESS *)&list->lh_Tail; im = (IMESS *)im->ExecMessage.mn_Node.ln_Succ) {
  797.         if (im->Class == RAWKEY && (im->Qualifier & 0xFB) == 0x08 &&
  798.         im->Code == CtlC) {
  799.  
  800.         Permit();
  801.         SetSignal(SIGBREAKF_CTRL_C,SIGBREAKF_CTRL_C);
  802.         return(1);
  803.         }
  804.     }
  805.     Permit();
  806.     }
  807.     return(0);
  808. }
  809.  
  810. void
  811. breakreset()
  812. {
  813.     SetSignal(0, SIGBREAKF_CTRL_C);
  814. }
  815.  
  816. /*
  817.  *  resize cols rows
  818.  */
  819.  
  820. void
  821. do_resize()
  822. {
  823.     WIN *win = Ep->Win;
  824.     int cols = atoi(av[1]);
  825.     int rows = atoi(av[2]);
  826.     short width = (cols*win->RPort->Font->tf_XSize) + win->BorderLeft + win->BorderRight;
  827.     short height= (rows*win->RPort->Font->tf_YSize) + win->BorderTop + win->BorderBottom;
  828.  
  829.     if (width < 16 || height < 16 ||
  830.     width > win->WScreen->Width - win->LeftEdge ||
  831.     height > win->WScreen->Height - win->TopEdge) {
  832.     title ("window too big (try moving to upper left corner and retrying)");
  833.     return;
  834.     }
  835.     SizeWindow(win, width - win->Width, height - win->Height);
  836.     Delay(50*2);    /* wait 2 seconds */
  837. }
  838.  
  839. ops(av, iswb)
  840. char **av;
  841. {
  842.     short nonops;
  843.     short i;
  844.     long val;
  845.     char *str;
  846.  
  847.     for (i = nonops = 0; str = av[i]; ++i) {
  848.     if (iswb) {
  849.         if (strncmp(str, "ARG", 3) == 0) {
  850.         while (*str && *str != '-')
  851.             ++str;
  852.         }
  853.     }
  854.     if (*str == '-') {
  855.         val = atoi(str+2);
  856.         switch(str[1]) {
  857.         case 'f':
  858.         Ffile = str+2;
  859.         break;
  860.         case 'b':
  861.         /*SizeOveride = 1;*/
  862.         break;
  863.         case 't':
  864.         /*Nwtopedge = val;*/
  865.         break;
  866.         case 'l':
  867.         /*Nwleftedge= val;*/
  868.         break;
  869.         case 'w':
  870.         /*SizeOveride = 1;*/
  871.         /*Nwwidth   = val;*/
  872.         break;
  873.         case 'h':
  874.         /*SizeOveride = 1;*/
  875.         /*Nwheight  = val;*/
  876.         break;
  877.         }
  878.     } else {
  879.         ++nonops;
  880.     }
  881.     }
  882.     return((int)nonops);
  883. }
  884.  
  885. /*
  886.  *  Convert geometry to nw params.
  887.  */
  888.  
  889. char *
  890. geoskip(ptr, pval, psgn)
  891. char *ptr;
  892. int *pval;
  893. int *psgn;
  894. {
  895.     if (*ptr == '-')
  896.     *psgn = -1;
  897.     else
  898.     *psgn = 1;
  899.     if (*ptr == '-' || *ptr == '+')
  900.     ++ptr;
  901.     *pval = atoi(ptr);
  902.     while (*ptr >= '0' && *ptr <= '9')
  903.     ++ptr;
  904.     return(ptr);
  905. }
  906.  
  907. void
  908. GeometryToNW(geo, nw)
  909. char *geo;
  910. struct NewWindow *nw;
  911. {
  912.     int n;
  913.     int sign;
  914.     struct Screen scr;
  915.  
  916.     GetScreenData(&scr, sizeof(scr), WBENCHSCREEN, NULL);
  917.  
  918.     if (*geo) {
  919.     geo = geoskip(geo, &n, &sign);
  920.     if (sign > 0)
  921.         nw->LeftEdge = n;
  922.     else
  923.         nw->LeftEdge = scr.Width - n;
  924.     }
  925.     if (*geo) {
  926.     geo = geoskip(geo, &n, &sign);
  927.     if (sign > 0)
  928.         nw->TopEdge = n;
  929.     else
  930.         nw->TopEdge = scr.Height - n;
  931.     }
  932.     if (*geo) {
  933.     geo = geoskip(geo, &n, &sign);
  934.     if (sign > 0)
  935.         nw->Width = n;
  936.     else
  937.         nw->Width = scr.Width - nw->LeftEdge - n;
  938.     }
  939.     if (*geo) {
  940.     geo = geoskip(geo, &n, &sign);
  941.     if (sign > 0)
  942.         nw->Height = n;
  943.     else
  944.         nw->Height = scr.Height - nw->TopEdge - n;
  945.     }
  946. }
  947.  
  948.  
  949.