home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / xdme1820.lha / XDME / main.c < prev    next >
C/C++ Source or Header  |  1993-03-09  |  26KB  |  1,230 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     main.c
  5.  
  6.     DESCRIPTION
  7.  
  8.     NOTES
  9.  
  10.     BUGS
  11.  
  12.     TODO
  13.  
  14.     EXAMPLES
  15.  
  16.     SEE ALSO
  17.  
  18.     INDEX
  19.  
  20.     HISTORY
  21.     28. Nov 1992    ada created
  22.  
  23. ******************************************************************************/
  24.  
  25. /**************************************
  26.         Includes
  27. **************************************/
  28. #include "defs.h"
  29. #include <dos/dostags.h>
  30. #define MYDEBUG     1
  31. #include "debug.h"
  32. #undef DEBUG
  33. //#define DEBUG
  34.  
  35.  
  36. /**************************************
  37.         Globale Variable
  38. **************************************/
  39. Prototype int  main      (int, char **);
  40. Prototype void do_tomouse (void);
  41. Prototype void exiterr      (char *);
  42. Prototype int  breakcheck (void);
  43. Prototype void breakreset (void);
  44. Prototype int  ops      (char **);
  45. Prototype Bool loadfile   (BPTR, char *);
  46.  
  47. Prototype struct MsgPort  * Sharedport;
  48. Prototype char            MShowTitle;
  49. Prototype char            noadj;
  50. Prototype struct GfxBase  * GfxBase;
  51. Prototype struct __XDMEArgs XDMEArgs;
  52.  
  53. struct MsgPort * Sharedport;        /* Port for all Windows */
  54. char         MShowTitle;        /* Should DME refresh the title ? */
  55. char         noadj;         /* for blocking software adj. of prop gad
  56.                        when intuition (user) already did it */
  57.  
  58. struct IntuitionBase * IntuitionBase;
  59. struct GfxBase         * GfxBase;
  60. struct Library         * IconBase;
  61. struct Library         * AslBase;
  62.  
  63.  
  64. /**************************************
  65.            Typedefs
  66. **************************************/
  67. typedef struct WBStartup    WBS;
  68. typedef struct DiskObject   DISKOBJ;
  69.  
  70.  
  71. /**************************************
  72.         Interne Variable
  73. **************************************/
  74. static short     Mx, My;        /* Mouse-Coords */
  75. static short     oMx, oMy;        /* starting coords */
  76. static ULONG     newxdme;        /* force new xdme */
  77.  
  78. static const char default_startupfile[] = ".edrc";
  79. static const char default_projectfile[] = "XDME_Project_File";
  80.  
  81. static const char tmplate[] = "Files/M,"
  82.                   "Startup=-S/K,"
  83.                   "New=-N/S,"
  84.                   "Iconify=-I/S,"
  85.                   "Autoload=-A/S,"
  86.                   "PubScreen=-PS/K,"
  87.                   "ProjectFile=-PF/K";
  88.  
  89. struct __XDMEArgs XDMEArgs =
  90. {
  91.     NULL,        /* Files */
  92.     NULL,        /* Startup-Filename */
  93.     FALSE,        /* NEW */
  94.     FALSE,        /* Iconify */
  95.     FALSE,        /* Autoload */
  96.     NULL,        /* PublicScreen */
  97.     NULL,        /* ProjectFile */
  98.     /* ... */
  99. };
  100.  
  101.  
  102. static const struct Config startup_config =
  103. {
  104.     -1,     /* wwcol */
  105.  
  106.     0, 0,    /* winx, winy           */
  107.     640, 200,    /* winwidth, winheight */
  108.  
  109.     0, 11,    /* iwinx, iwiny */
  110.  
  111.     0, 0,    /* aslleft/top       */
  112.     400, 200,    /* aslwidth/height */
  113.  
  114.     4,        /* tabstop */
  115.     75,     /* margin  */
  116.  
  117.     1,        /* fgpen */
  118.     0,        /* bgpen */
  119.     2,        /* hgpen */
  120.     0,        /* tpen  */
  121.     1,        /* bbpen */
  122.  
  123.     1,        /* insertmode    */
  124.     0,        /* ignorecase    */
  125.     0,        /* wordwrap    */
  126.     0,        /* autosplit    */
  127.     1,        /* autoindent    */
  128.     1,        /* autounblock    */
  129. };
  130.  
  131.  
  132. /**************************************
  133.        Interne Prototypes
  134. **************************************/
  135.  
  136.  
  137. #ifdef UNUSED
  138. void PrintCWD (void)
  139. {
  140.     static char puffer[256];
  141.     PROC * proc = (PROC *)FindTask (NULL);
  142.  
  143.     NameFromLock (proc->pr_CurrentDir, puffer, sizeof(puffer));
  144.  
  145.     kprintf ("CWD: `%s'\n", puffer);
  146. }
  147. #endif
  148.  
  149.  
  150. int wbmain(WBS * wbs)
  151. {
  152.     return (main (0, (char **)wbs));
  153. } /* wbmain */
  154.  
  155.  
  156. int main (int mac, char ** mav)
  157. {
  158.     ULONG  nf;            /* # files on command line       */
  159.     Bool   iawm        = 0; /* overide mouse buttons       */
  160.     Bool   dontwait    = 0; /* don't wait for a message    */
  161.     Bool   LeftArea    = 0; /* has mouse after buttonpress moved a certain
  162.                    distance */
  163.     short  i;            /* temp. counter           */
  164.     short  Code;        /* IDCMP->Code           */
  165.     ULONG  Qualifier;        /* IDCMP->Qualifier        */
  166.     PROC * proc        = (PROC *)FindTask(NULL);   /* our Task    */
  167.     BPTR   origlock;        /* Start-Lock           */
  168.     ULONG  wait_ret;        /* HD Result of Wait       */
  169.     ULONG  Mask        = 0; /* Mask for Wait()             */
  170.     Bool   gad_active  = 0; /* Is any gadget active ?       */
  171.     USHORT gad_id;        /* Which one ?           */
  172.     short  mqual;        /* Qualifiers for mmove       */
  173.     Bool   mmove       = 0; /* Mousemove           */
  174.     int    show_cursor;     /* shall I redraw the cursor ? */
  175.  
  176. /*#if MYDEBUG
  177.     D(bug("------------- Hallo, hier ist XDME ----------------\n"));
  178. #endif // */
  179.  
  180.     /* Detach from CLI */
  181.     fclose (stdin);
  182.     fclose (stdout);        /*  debugging output needs kprintf ! */
  183.     fclose (stderr);        /*  close stderr & console ref. */
  184.  
  185.     /* cd to dir of shell */
  186.     origlock = CurrentDir (DupLock (proc->pr_CurrentDir));
  187.  
  188.     /* Init lists */
  189.     NewList ((LIST *)&DBase);
  190.     NewList ((LIST *)&PBase);
  191.     init_macros ();
  192.     init_variables ();
  193.  
  194.     IntuitionBase = (struct IntuitionBase *)OpenLibrary ("intuition.library", 37L);
  195.     GfxBase      = (struct GfxBase       *)OpenLibrary ("graphics.library",  37L);
  196.     if (!IntuitionBase || !GfxBase)
  197.     exiterr ("cannot open intuition or graphics library");
  198.  
  199.     AslBase = OpenLibrary ("asl.library", 37L);
  200.     ReqToolsBase = (struct ReqToolsBase *)OpenLibrary ("reqtools.library", 37);
  201.  
  202.     PageJump = 80;        /* 80% of page for Propgad & pageup/down */
  203.  
  204.     String = NULL;        /*    initialize scanf variable   */
  205.  
  206.     ActualBlock.ep = NULL;    /* No block */
  207.  
  208.     /* making a default-ed-config */
  209.     movmem (&startup_config, &default_config, CONFIG_SIZE);
  210.  
  211.     /* setting default flags */
  212.     globalflags.Wdisable = 1;
  213.     globalflags.ActivateToFront = 1;
  214.     globalflags.Windowcycling = 1;
  215.     globalflags.Showtitle = 1;
  216.  
  217.     if (mac == 0)
  218.     {          /*  WORKBENCH STARTUP   */
  219.     globalflags.Wdisable = 0;        /*    allow icon save     */
  220.     Wbs = (WBS *)mav;
  221.  
  222.     if (!(IconBase = OpenLibrary ("icon.library", 0)) )
  223.         exiterr ("unable to open icon library");
  224.     }
  225.  
  226.     /* Init AREXX */
  227.     mountrequest (0);
  228.     openrexx ();     /*   do this after the last possible call to exiterr() */
  229.     mountrequest (1);
  230.  
  231.     /* Init Keyboard */
  232.     // resethash (currenthash());          /* PATCH_NULL [25 Jan 1993] : added currenthash() */
  233.     init_structures ();                 /* PATCH_NULL [28 Jan 1993] : added */
  234.  
  235.     {
  236.     struct MsgPort * mp;
  237.  
  238.     Forbid ();
  239.     mp = FindPort ("XDME.1");
  240.     Permit ();
  241.  
  242.     newxdme = (!strcmp (RexxPortName, "XDME.1") || !mp);
  243.     }
  244.  
  245.     nf = 0;
  246.     /* Here we have to set the names BEFORE the parsing since none of the
  247.        Arg-Parsers does set them (we make copies later) */
  248.     XDMEArgs.projectfilename = default_projectfile; /* no strdup() here ! */
  249.     XDMEArgs.startupfile     = default_startupfile; /* no strdup() here ! */
  250.  
  251.     /* WB-Startup or CLI ? */
  252.     if (Wbs)
  253.     {
  254.     /* Work on TOOLTypes */
  255.     if (Wbs->sm_ArgList[0].wa_Lock)
  256.     {
  257.         DISKOBJ     * dobj;    /* For WB-Startup */
  258.         struct WBArg * wbarg;
  259.         BPTR       current;
  260.  
  261.         for (i=0; i<Wbs->sm_NumArgs; i++)
  262.         {
  263.         wbarg = &Wbs->sm_ArgList[i];
  264.  
  265.         UnLock (CurrentDir (current = DupLock (wbarg->wa_Lock)));
  266.  
  267.         if (dobj = GetDiskObject (wbarg->wa_Name))
  268.         {
  269.             /* Only process names for ToolTypes, not for the the
  270.                program itself ! */
  271.  
  272.             ops (dobj->do_ToolTypes);
  273.  
  274.             if (i)
  275.             {
  276.             if (loadfile (wbarg->wa_Lock, wbarg->wa_Name))
  277.                 nf ++;
  278.             }
  279.  
  280.             FreeDiskObject (dobj);
  281.         }
  282.         }
  283.  
  284.         /* CD to new base-dir */
  285.         UnLock (CurrentDir (DupLock (Wbs->sm_ArgList[0].wa_Lock)));
  286.     }
  287.     } else
  288.     {
  289.     XDMEArgs.newxdme = newxdme;
  290.  
  291.     /* Parse CLI-args */
  292.     if ((XDMEArgs.ra = ReadArgs (tmplate, (LONG *)&XDMEArgs, NULL))
  293.         && XDMEArgs.files)
  294.     {
  295. #ifdef DEBUG
  296.         USHORT count = 0;
  297. #endif
  298.         char ** nameptr;
  299.  
  300.         for (nameptr=XDMEArgs.files; *nameptr; nameptr ++)
  301.         {
  302. #ifdef DEBUG
  303.         D(bug("Loading %ld %s ...\n", count ++, *nameptr));
  304. #endif
  305.  
  306.         if (loadfile (origlock, *nameptr))
  307.             nf ++;
  308.         }
  309.     }
  310.     }
  311.  
  312. #ifdef DEBUG
  313.     D(bug("Parsed ARGS\n"));
  314. #endif
  315.  
  316.     if (XDMEArgs.startupfile)
  317.     XDMEArgs.startupfile = strdup (XDMEArgs.startupfile);
  318.     else
  319.     {
  320. #ifdef DEBUG
  321.     D(bug("ERROR: XDMEArgs.startupfile == NULL <<<------------\n"));
  322. #endif
  323.     XDMEArgs.startupfile = strdup (default_startupfile);
  324.     }
  325.  
  326. #ifdef DEBUG
  327.     D(bug("Startup-file : \"%s\"\n", XDMEArgs.startupfile));
  328. #endif
  329.  
  330.     if (XDMEArgs.projectfilename)
  331.     XDMEArgs.projectfilename = strdup (XDMEArgs.projectfilename);
  332.     else
  333.     {
  334. #ifdef DEBUG
  335.     D(bug("ERROR: XDMEArgs.projectfilename == NULL <<<------------\n"));
  336. #endif
  337.     XDMEArgs.projectfilename = strdup (default_projectfile);
  338.     }
  339.  
  340. #ifdef DEBUG
  341.     D(bug("Projectfile : \"%s\"\n", XDMEArgs.projectfilename));
  342. #endif
  343.  
  344.     if (XDMEArgs.publicscreenname)
  345.     XDMEArgs.publicscreenname = strdup (XDMEArgs.publicscreenname);
  346.  
  347. #ifdef DEBUG
  348.     D(bug("Screen : \"%s\"\n", XDMEArgs.publicscreenname ?
  349.         XDMEArgs.publicscreenname : "WBench"));
  350. #endif
  351.  
  352.     /* Free args */
  353.     if (XDMEArgs.ra)
  354.     FreeArgs (XDMEArgs.ra);
  355.  
  356.     if (!nf)
  357.     {  /* no files to edit: Open simple empty window */
  358.     if (XDMEArgs.newxdme || newxdme)
  359.     {
  360.         do_newwindow ();
  361.  
  362.         if (XDMEArgs.iconify)
  363.         do_iconify ();
  364.     } else
  365.     {
  366.         if (XDMEArgs.iconify)
  367.         {
  368.         do_rexx ("XDME.1", "newwindow iconify");
  369.         } else
  370.         {
  371.         do_rexx ("XDME.1", "newwindow");
  372.         }
  373.     }
  374.     } /* No files */
  375.  
  376.     if (!XDMEArgs.newxdme) /* All done, quit */
  377.     goto quit_dme;
  378.  
  379.     /* Read main .edrc file */
  380.     mountrequest (0);
  381.     av[0] = "source";
  382.     av[1] = (ubyte *)"s:.edrc";
  383.     do_source (TRUE);   /* Display error */
  384.  
  385.     /* Read other file (if possible) */
  386.     if (NameFromLock (origlock, tmp_buffer, sizeof(tmp_buffer)))
  387.     {
  388.     AddPart (tmp_buffer, XDMEArgs.startupfile, sizeof(tmp_buffer));
  389.     av[1] = tmp_buffer;
  390.     do_source (FALSE); /* Not */
  391.     }
  392.     mountrequest (1);
  393.  
  394.     /* Initialize certain fields in structure */
  395.     {
  396.     ED * ep;
  397.     ED * eb = GetHead ((LIST *)&DBase);
  398.     USHORT ix, iy;
  399.  
  400.     for (ep = eb; ep = GetSucc(&ep->node); )
  401.     {
  402.         ix = ep->beginconfig.iwinx;
  403.         iy = ep->beginconfig.iwiny;
  404.  
  405.         movmem (&eb->beginconfig, &ep->beginconfig, CONFIG_SIZE);
  406.  
  407.         ep->beginconfig.iwinx = ix;
  408.         ep->beginconfig.iwiny = iy;
  409.  
  410.         if (eb->font)
  411.         {
  412.         ep->font = eb->font;
  413.         eb->font->tf_Accessors ++;
  414.         } /* if font */
  415.     } /* for ed */
  416.     }
  417.  
  418.     /* Get Wait()-Mask */
  419.     Mask |= 1 << Sharedport->mp_SigBit;
  420.     wait_ret = 0;
  421.  
  422. loop:
  423.     if (!Ep->iconmode)  /* Display cursor ? */
  424.     text_cursor (1);
  425.  
  426.     for ( ; !globalflags.Quitflag; )
  427.     {
  428.  
  429.     if (!Ep->iconmode)
  430.         window_title ();
  431.  
  432.     if (dontwait)
  433.     {
  434.         dontwait --;
  435.     } else
  436.     {
  437.         wait_ret = Wait (Mask | RexxMask); /* HD für AREXX externes AREXX Command */
  438.     }
  439.  
  440.     show_cursor = 0;    /* don't update cursor */
  441.  
  442.     /*
  443.      *  NOTE: due to operation of breakcheck(), the userport signal
  444.      *  may not be set even if there are messages pending.
  445.      */
  446.     if (wait_ret & RexxMask)          /* HD RexxMessage */
  447.     {
  448.        text_cursor (0);
  449.  
  450.        extern_rexx_command ();       /* process HD rexxcommand */
  451.  
  452.        show_cursor ++;
  453.     }
  454.  
  455.     if (wait_ret & Mask)              /* HD IntuiMessage */
  456.     {
  457.         IMESS * im;
  458.  
  459.         while (im = (IMESS *)GetMsg(Ep->win->UserPort))
  460.         {
  461.         globalflags.Abortcommand = 0;
  462.         globalflags.Msgchk     = 1;
  463.  
  464.         Code         = im->Code;
  465.         Qualifier    = im->Qualifier;
  466.  
  467.         clearbreaks ();
  468.  
  469.         if (im->IDCMPWindow != Ep->win)
  470.         {
  471.             globalflags.Overide = 0;
  472.  
  473.             if (globalflags.Comlinemode)
  474.             escapecomlinemode ();
  475.  
  476.             text_sync ();
  477.  
  478.             MShowTitle = 0;
  479.  
  480.             if (!Ep->iconmode)
  481.             window_title ();
  482.  
  483.             if (text_switch (im->IDCMPWindow) == 0)
  484.             {
  485.             ReplyMsg ((MSG *)im);
  486.             continue;
  487.             }
  488.         }
  489.  
  490.         Mx = im->MouseX;
  491.         My = im->MouseY;
  492.  
  493.         switch(im->Class)
  494.         {
  495.             case IDCMP_NEWSIZE:
  496.             {
  497.             struct Window * win = Ep->win;
  498.             short        wid;
  499.             short        hei;
  500.  
  501.             /* Only works if uniconified */
  502.             if (!Ep->iconmode)
  503.             {
  504.                 /* Leave Comlinemode if neccessary */
  505.                 if (globalflags.Comlinemode)
  506.                 escapecomlinemode ();
  507.  
  508.                 /* Set new window-parameters */
  509.                 set_window_params ();
  510.  
  511.                 /* Erase if neccessary */
  512.                 wid = win->Width - win->BorderRight - 1;
  513.                 hei = win->Height - win->BorderBottom - 1;
  514.  
  515.                 SetAPen (win->RPort, TEXT_BPEN);
  516.                 SetWrMsk (win->RPort, BLOCK_MASK);
  517.  
  518.                 if (wid > Xpixs)
  519.                 {
  520.                 RectFill (win->RPort, Xpixs+1, Ybase,
  521.                     wid, hei);
  522.                 }
  523.  
  524.                 if (hei > Ypixs)
  525.                 {
  526.                 RectFill (win->RPort, Xbase, Ypixs+1,
  527.                     Xpixs, hei);
  528.                 }
  529.  
  530.                 /* Update Text */
  531.                 text_adjust (TRUE);
  532.                 show_cursor ++;
  533.             }
  534.             } break; /* NEWSIZE */
  535.  
  536.             case IDCMP_REFRESHWINDOW:
  537.             BeginRefresh (Ep->win);
  538.  
  539.             text_redisplay ();
  540.             text_cursor (1);
  541.  
  542.             EndRefresh (Ep->win, TRUE);
  543.             break; /* REFRESHWINDOW */
  544.  
  545.             case IDCMP_MOUSEBUTTONS:
  546.             {
  547.             static short  lastCode = 0;
  548.             static ULONG  lastSeconds;
  549.             static ULONG  lastMicros;
  550.             ULONG          Seconds;
  551.             ULONG          Micros;
  552.  
  553.             /* get time of message */
  554.             Seconds = im->Seconds;
  555.             Micros = im->Micros;
  556.  
  557.             /* Avoid Crashing if Window is closed during keyctl() */
  558.             ReplyMsg ((struct Message *)im);
  559.             im = NULL;
  560.  
  561.             switch(Code)
  562.             {
  563.                 case MENUDOWN:
  564.                 if (Ep->iconmode)
  565.                     break;
  566.  
  567.                 case MIDDLEDOWN:
  568.                 case SELECTDOWN:
  569.                 /* if we only activated the window with a
  570.                    buttonpress, ignore it */
  571.                 if (iawm)
  572.                     break;
  573.  
  574.                 /* if there was no click yet or
  575.                    the button changed or this is no
  576.                    double-click anymore, then clear
  577.                    the number of clicks and use the new code */
  578.                 if (!NumClicks          ||
  579.                     lastCode != Code    ||
  580.                     !DoubleClick (lastSeconds, lastMicros,
  581.                         Seconds, Micros))
  582.                 {
  583.                     lastCode    = Code;   /* new code */
  584.                     NumClicks    = 0;      /* button changed */
  585.                 }
  586.  
  587.                 /* remember the time of this click */
  588.                 lastSeconds = Seconds;
  589.                 lastMicros  = Micros;
  590.                 /* increase the number of clicks */
  591.                 NumClicks ++;
  592.  
  593.                 ReportMouse (TRUE, Ep->win);
  594.                 ModifyIDCMP (Ep->win, Ep->win->IDCMPFlags |
  595.                     IDCMP_INTUITICKS);
  596.  
  597.                 oMx = Mx;
  598.                 oMy = My;
  599.                 LeftArea = FALSE;
  600.                 break;
  601.  
  602.                 case SELECTUP:
  603.                 case MENUUP:
  604.                 case MIDDLEUP:
  605.                 ReportMouse (FALSE, Ep->win);
  606.                 ModifyIDCMP (Ep->win, Ep->win->IDCMPFlags &
  607.                     ~IDCMP_INTUITICKS);
  608.                 break;
  609.  
  610.             }
  611.  
  612.             if (Code == MENUDOWN && Ep->iconmode)
  613.             {
  614.                 uniconify ();
  615.                 show_cursor ++;
  616.             } else if (!iawm)
  617.             {
  618. #ifdef NOT_DEF /* PATCH_NULL [15 Feb 1993] : added */
  619.                 if (MacroRecord) {
  620.                 sprintf (tmp_buffer, "setptr %d %d", Mx, My);
  621.                 add_record (tmp_buffer);
  622.                 } /* if */
  623. #endif
  624.                 text_cursor (0);
  625.                 show_cursor ++;
  626.                 keyctl (NULL, Code, Qualifier);
  627.             } else
  628.                 iawm = FALSE;
  629.             } break; /* IDCMP_MOUSEBUTTONS */
  630.  
  631.             case IDCMP_RAWKEY:
  632.             {
  633.             IMESS    copy;
  634.  
  635.             /* Prevent crashing in do_iconify()->
  636.                closesharedwindow */
  637.  
  638.             memcpy (©, im, sizeof (IMESS));
  639.             ReplyMsg ((struct Message *)im);
  640.             im = NULL;
  641.  
  642.             text_cursor (0);
  643.             show_cursor ++;
  644.             keyctl (©, Code, Qualifier);
  645.             break; } /* IDCMP_RAWKEY */
  646.  
  647.             case IDCMP_MENUPICK:
  648.             {
  649.             char * str = menu_cmd (im);
  650.  
  651.             ReplyMsg ((struct Message *)im);
  652.             im = NULL;
  653.  
  654.             if (str)
  655.             {
  656.                 /* Generate a copy of the string */
  657.                 str = strdup (str);
  658.  
  659.                 if (str)
  660.                 {
  661.                 /* Cursor off */
  662.                 text_cursor (0);
  663.                 show_cursor ++;
  664.  
  665.                 do_command (str);   /* Do command */
  666.                 free (str);
  667.                 }
  668.             }
  669.             break; } /* IDCMP_MENUPICK */
  670.  
  671.             case IDCMP_CLOSEWINDOW:
  672.             if (globalflags.Comlinemode)
  673.                 escapecomlinemode ();
  674.  
  675.             text_sync ();
  676.             globalflags.Quitflag = TRUE;
  677.             show_cursor = 0;
  678.             break; /* IDCMP_CLOSEWINDOW */
  679.  
  680.             case IDCMP_ACTIVEWINDOW:
  681.             if (!Ep->iconmode)
  682.                 iawm = TRUE;
  683.             break; /* IDCMP_ACTIVEWINDOW */
  684.  
  685.             case IDCMP_MOUSEMOVE:
  686.             if (gad_active)
  687.             {
  688.                 int newtop = new_top ();
  689.  
  690.                 if (newtop != Ep->topline)
  691.                 {
  692.                 text_sync ();
  693.  
  694.                 newtop -= Ep->topline;
  695.  
  696.                 text_cursor (0); /* Cursor off */
  697.                 show_cursor ++;
  698.  
  699.                 Ep->line    += newtop;
  700.                 Ep->topline += newtop;
  701.  
  702.                 text_load ();
  703.  
  704.                 scroll_display (0, newtop, 0, Ep->topline,
  705.                     MAXLINELEN, Ep->topline + Lines);
  706.                 }
  707.             } else
  708.             {
  709.                 /* Process these after all messages have been
  710.                    processed */
  711.                 if (!LeftArea)
  712.                 {
  713.                 if (((Mx > oMx) ? Mx-oMx>4 : oMx-Mx>4) ||
  714.                     ((My > oMy) ? My-oMy>4 : oMy-My>4) )
  715.                     LeftArea = TRUE;
  716.                 }
  717.  
  718.                 if (LeftArea)
  719.                 {
  720.                 mmove = 1;
  721.                 mqual = Qualifier;
  722.                 }
  723.             }
  724.             break; /* IDCMP_MOUSEMOVE */
  725.  
  726.             case IDCMP_GADGETDOWN:
  727.             if (globalflags.Comlinemode)
  728.                 escapecomlinemode ();
  729.  
  730.             gad_id = ((struct Gadget *)im->IAddress)->GadgetID;
  731.  
  732.             if (!gad_id)
  733.             {
  734.                 noadj = 1;      /* block software prop refresh */
  735.             } else
  736.             {
  737.                 text_cursor (0);
  738.                 show_cursor ++;
  739.  
  740.                 if (gad_id == 1)
  741.                 do_scrollup ();
  742.                 else
  743.                 do_scrolldown ();
  744.             }
  745.  
  746.             if (gad_id)
  747.                 ModifyIDCMP (Ep->win, Ep->win->IDCMPFlags |
  748.                     IDCMP_INTUITICKS);
  749.             else
  750.                 text_adjust (FALSE);
  751.  
  752.             gad_active = TRUE;
  753.             break;
  754.  
  755.             case IDCMP_GADGETUP:
  756.             {
  757.             if (gad_id == 0)
  758.             {
  759.                 int newtop = new_top ();
  760.  
  761.                 if (newtop != Ep->topline)
  762.                 { /* Make sure we don't miss a jump */
  763.                 text_sync ();
  764.  
  765.                 newtop -= Ep->topline;
  766.  
  767.                 text_cursor (0); /* Cursor off */
  768.                 show_cursor ++;
  769.  
  770.                 Ep->line    += newtop;
  771.                 Ep->topline += newtop;
  772.  
  773.                 text_load ();
  774.  
  775.                 scroll_display (0, newtop, 0, Ep->topline,
  776.                     MAXLINELEN, Ep->topline + Lines);
  777.                 }
  778.             } else
  779.                 ModifyIDCMP (Ep->win, Ep->win->IDCMPFlags &
  780.                     ~IDCMP_INTUITICKS);
  781.  
  782.             gad_active = FALSE;
  783.  
  784.             noadj = 0;        /* reallow software prop refresh */
  785.             break; }
  786.  
  787.             case IDCMP_INTUITICKS:
  788.             if (gad_active && gad_id)
  789.             {
  790.                 text_cursor (0);
  791.                 show_cursor ++;
  792.  
  793.                 if (gad_id == 1)
  794.                 do_scrollup ();
  795.                 else
  796.                 do_scrolldown ();
  797.             } else if (LeftArea)
  798.             {
  799.                 mmove = 1;
  800.                 mqual = Qualifier;
  801.             }
  802.             break; /* IDCMP_INTUITICKS */
  803.         } /* switch (class) */
  804.  
  805.         if (im)
  806.             ReplyMsg ((MSG *)im);
  807.  
  808.         if (globalflags.Quitflag)
  809.         {
  810.             dontwait = 2;
  811.             goto boom;
  812.         } /* if (Quitflag) */
  813.         } /* While IntuiMessage */
  814.  
  815.     } /* if (Wait & Mask) */
  816.  
  817.     /* no more iawm */
  818.     iawm = FALSE;
  819.  
  820.     if (mmove && !Ep->iconmode)
  821.     {
  822.         mmove = 0;
  823.  
  824. #ifdef NOT_DEF        /* PATCH_NULL [15 Feb 1993] : added */
  825.         if (MacroRecord) {
  826.         sprintf (tmp_buffer, "setptr %d %d", Mx, My);
  827.         add_record (tmp_buffer);
  828.         } /* if */
  829. #endif
  830.  
  831.         text_cursor (0);
  832.         show_cursor ++;
  833.         keyctl (NULL, QMOVE, mqual);
  834.     } /* if (mmove) */
  835.  
  836.     if (show_cursor && !Ep->iconmode)
  837.         text_cursor (1);
  838.  
  839.     } /* for ( ; !Quitflag; ) */
  840.  
  841. boom:
  842.     text_sync ();
  843.  
  844.     /* Close window(s) */
  845.     {
  846.     WIN          * win;
  847.     struct Gadget * gadget;
  848.     int        result;
  849.  
  850.     do
  851.     {
  852.         if (Ep->modified)
  853.         {
  854.         uniconify ();
  855.         text_cursor (1);
  856.  
  857.         result = getyn ("XDME Warning",
  858.             "The file `%s' has been modified.\n"
  859.             "Do you want to quit anyway (and loose all\n"
  860.             "your work) ?",
  861.             "Quit|Save & Quit|Cancel", Ep->name);
  862.  
  863.         switch (result)
  864.         {
  865.             case 0:
  866.             globalflags.Quitflag = 0;
  867.             goto loop;
  868.             break;
  869.  
  870.             case 2:
  871.             if (!do_save ())
  872.             {
  873.                 globalflags.Quitflag = 0;
  874.                 goto loop;
  875.             }
  876.             break;
  877.         }
  878.         }
  879.  
  880.         win    = Ep->win;
  881.         gadget = Ep->propgad;
  882.  
  883.         text_uninit ();
  884.         closesharedwindow (win);
  885.  
  886.         if (gadget)
  887.         free_prop ((struct PropGadget *)gadget);
  888.     } while (globalflags.QuitAll && Ep);
  889.     }
  890.  
  891.     /* If we have another window left */
  892.     if (Ep)
  893.     {
  894.     globalflags.Quitflag = 0;
  895.  
  896.     if (!Ep->iconmode)
  897.         set_window_params ();
  898.  
  899.     text_load ();
  900.  
  901.     MShowTitle = 0;
  902.     goto loop;
  903.     }
  904.  
  905. quit_dme:
  906.     /* Close AREXX */
  907.     closerexx ();
  908.  
  909.     /* Close Port after ARexx */
  910.     if (Sharedport)
  911.     {
  912.     DeletePort (Sharedport);
  913.     Sharedport = NULL;
  914.     }
  915.  
  916.     /* Free Lock */
  917.     UnLock (CurrentDir (origlock));
  918.  
  919.     /* Free memory */
  920.     // dealloc_hash (currenthash());        /* PATCH_NULL [25 Jan 1993] : added currenthash */
  921.     check_stack (NULL);
  922.  
  923.     if (XDMEArgs.startupfile)
  924.     free (XDMEArgs.startupfile);
  925.  
  926.     if (XDMEArgs.projectfilename)
  927.     free (XDMEArgs.projectfilename);
  928.  
  929.     if (XDMEArgs.publicscreenname)
  930.     free (XDMEArgs.publicscreenname);
  931.  
  932. #ifdef DEBUG_MEM_H
  933.     _debug_FreeAllMem ();
  934. #endif /* DEBUG_MEM_H */
  935.  
  936.     /* All OK. */
  937.     exiterr (NULL);
  938. } /* main */
  939.  
  940.  
  941. void do_tomouse (void)
  942. {
  943.     short cx, cy;
  944.     short minx, miny, maxx, maxy;
  945.  
  946.     if (Columns < 2 || Lines < 2)
  947.     return;
  948.  
  949.     cx = (Mx-Xbase);
  950.     if (cx >= 0)
  951.     {
  952.     if (cx < Xpixs)
  953.         cx /= Xsize;
  954.     else
  955.         cx = Lines;
  956.     } else
  957.     cx = -1;
  958.  
  959.     cy = (My-Ybase);
  960.     if (cy >= 0)
  961.     {
  962.     if (cy < Ypixs)
  963.         cy /= Ysize;
  964.     else
  965.         cy = Columns;
  966.     } else
  967.     cy = -1;
  968.  
  969.     minx = 0;            /* Scroll when MOUSE left window */
  970.     miny = 0;
  971.     maxx = Columns;
  972.     maxy = Lines;
  973.  
  974.     if (cx < minx)
  975.     { /* to the left */
  976.     do_scroll (SCROLL_LEFT);
  977.  
  978.     if (cy < miny)
  979.     { /* Also up */
  980.         do_scrollup ();
  981.     } else if (cy >= maxy)
  982.     { /* also down */
  983.         do_scrolldown ();
  984.     }
  985.     } else if (cx >= maxx)
  986.     { /* dito to the right */
  987.     do_scroll (SCROLL_RIGHT);
  988.  
  989.     if (cy < miny)
  990.     {
  991.         do_scrollup ();
  992.     } else if (cy >= maxy)
  993.     {
  994.         do_scrolldown ();
  995.     }
  996.     } else
  997.     { /* x is ok, check y */
  998.     if (cy < miny)
  999.     { /* up */
  1000.         do_scrollup ();
  1001.     } else if (cy >= maxy)
  1002.     { /* down */
  1003.         do_scrolldown ();
  1004.     } else
  1005.         text_position (cx, cy); /* Just reposition cursor */
  1006.     }
  1007. } /* do_tomouse */
  1008.  
  1009.  
  1010. void exiterr (char * str)
  1011. {
  1012.     if (str)
  1013.     {
  1014.     if (Output ())
  1015.     {
  1016.         Write (Output (), str, strlen (str));
  1017.         Write (Output (), "\n", 1);
  1018.     } else
  1019.     {
  1020.         if (IntuitionBase)
  1021.         error (str);
  1022.     }
  1023.     }
  1024.  
  1025.     if (IconBase)
  1026.     {
  1027.     CloseLibrary (IconBase);
  1028.     IconBase = NULL;
  1029.     }
  1030.  
  1031.     if (ReqToolsBase)
  1032.     {
  1033.     if (RFReq)
  1034.     {
  1035.         rtFreeRequest (RFReq);
  1036.  
  1037.         RFReq = NULL;
  1038.     }
  1039.  
  1040.     CloseLibrary ((struct Library *)ReqToolsBase);
  1041.     ReqToolsBase = NULL;
  1042.     }
  1043.  
  1044.     if (AslBase)
  1045.     {
  1046.     if (FReq)
  1047.     {
  1048.         FreeAslRequest (FReq);
  1049.  
  1050.         FReq = NULL;
  1051.     }
  1052.  
  1053.     CloseLibrary (AslBase);
  1054.     AslBase = NULL;
  1055.     }
  1056.  
  1057.     if (GfxBase)
  1058.     {
  1059.     CloseLibrary ((struct Library *)GfxBase);
  1060.     GfxBase = NULL;
  1061.     }
  1062.  
  1063.     if (IntuitionBase)
  1064.     {
  1065.     CloseLibrary ((struct Library *)IntuitionBase);
  1066.     IntuitionBase = NULL;
  1067.     }
  1068.  
  1069.     if (str)
  1070.     exit (1);
  1071.  
  1072.     exit (0);
  1073. } /* exiterr */
  1074.  
  1075.  
  1076. /*
  1077.  *  Check break by scanning pending messages in the Inputstream for a ^C.
  1078.  *  Msgchk forces a check, else the check is only made if the signal is
  1079.  *  set in the Inputstream (the signal is reset).
  1080.  */
  1081.  
  1082. int breakcheck (void)
  1083. {
  1084.     IMESS    * im;
  1085.     WIN     * win  = Ep->win;
  1086.     struct List * list = &win->UserPort->mp_MsgList;
  1087.  
  1088.     ULONG sigs = SetSignal(0,0);                                    /* PATCH_NULL [14 Feb 1993] : that mode slows looping not markably down */
  1089.  
  1090.     if ((sigs & SIGBREAKF_CTRL_C) != 0) {                           /* PATCH_NULL [14 Feb 1993] : These lines are   */
  1091.     return(1);                                                  /* PATCH_NULL [14 Feb 1993] : intended to allow */
  1092.     }
  1093.     else if (globalflags.Msgchk || (sigs & (1<<win->UserPort->mp_SigBit)))    /* PATCH_NULL [14 Feb 1993] : external breaking */
  1094.     {
  1095.     globalflags.Msgchk = 0;
  1096.     SetSignal (0,1<<win->UserPort->mp_SigBit);
  1097.  
  1098.     im = (IMESS *)list->lh_Head;
  1099.     Forbid();
  1100.  
  1101.     for ( ; im != (IMESS *)&list->lh_Tail;
  1102.         im = (IMESS *)im->ExecMessage.mn_Node.ln_Succ)
  1103.         {
  1104.         if (im->Class == RAWKEY && (im->Qualifier & 0xFB) == 0x08 &&
  1105.         im->Code == CtlC)
  1106.         {
  1107.  
  1108.         Permit ();
  1109.         SetSignal (SIGBREAKF_CTRL_C,SIGBREAKF_CTRL_C);
  1110.         return (1);
  1111.         }
  1112.     } /* for IMESS */
  1113.  
  1114.     Permit ();
  1115.     }
  1116.  
  1117.     return (0);
  1118. } /* breakcheck */
  1119.  
  1120.  
  1121. void breakreset (void)
  1122. {
  1123.     SetSignal(0, SIGBREAKF_CTRL_C);
  1124. }
  1125.  
  1126.  
  1127. /* Parse WB-ToolTypes */
  1128.  
  1129. int ops (char ** toolarray)
  1130. {
  1131.     char * tooltype;
  1132.  
  1133.     if (tooltype = FindToolType (toolarray, "ICONIFY"))
  1134.     XDMEArgs.iconify = MatchToolValue (tooltype, "YES");
  1135.     else
  1136.     XDMEArgs.iconify = FALSE;
  1137.  
  1138.     if (tooltype = FindToolType (toolarray, "NEW"))
  1139.     XDMEArgs.newxdme = MatchToolValue (tooltype, "YES") | newxdme;
  1140.     else
  1141.     XDMEArgs.newxdme = newxdme;
  1142.  
  1143.     if (tooltype = FindToolType (toolarray, "AUTOLOAD"))
  1144.     XDMEArgs.autoload = MatchToolValue (tooltype, "YES");
  1145.     else
  1146.     XDMEArgs.autoload = FALSE;
  1147.  
  1148.     if (tooltype = FindToolType (toolarray, "PUBSCREEN"))
  1149.     XDMEArgs.publicscreenname = tooltype;    /* no strdup() here ! */
  1150.  
  1151.     if (tooltype = FindToolType (toolarray, "PROJECTFILE"))
  1152.     XDMEArgs.projectfilename = tooltype;   /* no strdup() here ! */
  1153.  
  1154.     if (tooltype = FindToolType (toolarray, "STARTUP"))
  1155.     XDMEArgs.startupfile = tooltype;   /* no strdup() here ! */
  1156.  
  1157. #ifdef DEBUG
  1158.     D(bug("sfile: %s\nnew %ld\niconify %ld\nauto %ld\n"
  1159.         "PSName: `%s'\npf: `%s'\n", XDMEArgs.startupfile,
  1160.         XDMEArgs.newxdme, XDMEArgs.iconify, XDMEArgs.autoload,
  1161.         XDMEArgs.publicscreenname ? XDMEArgs.publicscreenname : "(nul)",
  1162.         XDMEArgs.projectfilename ? XDMEArgs.projectfilename : "(nul)"));
  1163. #endif
  1164. } /* ops */
  1165.  
  1166.  
  1167. Bool loadfile (BPTR lock, char * name)
  1168. {
  1169.     char buf[512];
  1170.  
  1171.     /* Load project ? */
  1172.     if (!stricmp (name, XDMEArgs.projectfilename))
  1173.     {
  1174.     if (XDMEArgs.newxdme)
  1175.     {
  1176.         return (load_project ());
  1177.     } else
  1178.     {
  1179.         strcpy (buf, "cd `");
  1180.  
  1181.         if (NameFromLock (lock, buf + 4, sizeof (buf) - 4))
  1182.         {
  1183.         strcat (buf, "' projectload");
  1184.  
  1185.         do_rexx ("XDME.1", buf);
  1186.         }
  1187.     }
  1188.     } else
  1189.     {
  1190.     if (XDMEArgs.newxdme)
  1191.     {
  1192.         /* Normal file. Open new window */
  1193.         do_newwindow ();
  1194.  
  1195.         /* Load file for editing */
  1196.         av[0] = (ubyte *)"newfile";
  1197.         av[1] = (ubyte *)name;
  1198.  
  1199.         UnLock (Ep->dirlock);
  1200.         Ep->dirlock = DupLock (lock);
  1201.  
  1202.         do_edit ();
  1203.  
  1204.         /* Show title */
  1205.         globalflags.MForceTitle = 1;
  1206.         window_title ();
  1207.  
  1208.         if (XDMEArgs.iconify)
  1209.         do_iconify ();
  1210.     } else
  1211.     { /* Use AREXX */
  1212.         strcpy (buf, "newwindow cd `");
  1213.  
  1214.         if (NameFromLock (lock, buf + 14, sizeof (buf) - 14))
  1215.         {
  1216.         sprintf (buf + strlen (buf), "' newfile `%s'%s",
  1217.             name, (XDMEArgs.iconify ? " iconify" : ""));
  1218.         do_rexx ("XDME.1", buf);
  1219.         }
  1220.     }
  1221.     } /* No PROJECTFILE */
  1222.  
  1223.     return (TRUE);
  1224. } /* loadfile */
  1225.  
  1226.  
  1227. /******************************************************************************
  1228. *****  ENDE main.c
  1229. ******************************************************************************/
  1230.