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