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