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