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