home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 204.lha / Wicon / wicon.c < prev    next >
C/C++ Source or Header  |  1996-02-14  |  18KB  |  723 lines

  1. /*************************************************************************
  2.  *
  3.  *    wicon.c - window iconifier (Right Mouse Button)         29-Dec-87
  4.  */
  5. char *Version =\
  6.    "Wicon 1.14 10-May-88 Copyright (c) 1987,88  Steven Sweeting - SMAUG";
  7. /*
  8.  *    Usage: wicon [ -b boxes ] [ -t ] [ -f | -!f ] [ -p priority ]
  9.  *             [ -q ] [ -s | -!s ]
  10.  *
  11.  *    use the Right Mouse Button (RMB) to iconify the Active window
  12.  *
  13.  *    Portions Copyright (c) 1987 Davide P. Cervone (Input Handler)
  14.  *
  15.  *    May be freely distributed, hacked etc. Please include wicon.doc
  16.  *    if the code hasn't changed too much.
  17.  *
  18.  *    I really like Matt Dillon's DME's iconifying windows, so I thought
  19.  *    there has to be a way of modifying Workbench to make it possible,
  20.  *    I tried doing things like moving other peoples windows from one
  21.  *    screen to another (SILENT) one. Then it hit me, and it was simple,
  22.  *    easy to program and even could be done without violating
  23.  *    all those Intuition laws (don't hold me to that). Try it out before
  24.  *    looking into the source code.
  25.  *
  26.  *    Even if you chuck this program away, please hang on to
  27.  *    UnSetFunction(), so that the hackers (the old meaning) can
  28.  *    no only co-exist peacefully, but die peacefully as well.
  29.  *
  30.  *    I urge others to use RMBTRAP to do the iconifying themselves
  31.  *
  32.  *************************************************************************/
  33.  
  34. #define WICON__C
  35.  
  36. #include "wicon.h"
  37. #include <sgs/arg.h>
  38. #include <stdio.h>
  39. #include <libraries/dos.h>
  40.  
  41. #ifdef DEBUG
  42. /* hence functions/variables externally available to db */
  43. #define Static
  44. #else  DEBUG
  45. #define Static static
  46. #endif DEBUG
  47.  
  48. #ifndef SMALLWICON
  49.  
  50. #define ERROR    char *
  51.  
  52. #define ERRIBASE    "Can't open intuition.library (V 33)"
  53. #define ERRGFXBASE  "Can't open graphics.library (V 33)"
  54. #define ERRLAYBASE  "Can't open layers.library (V 33)"
  55. #define ERRICONBASE "Can't open icon.library (V 33)"
  56. #define PROCSIGNAL  "\nProcess signalled\n"
  57. #define ERRPORT     "Can't open DeathPort"
  58. #define ERRWIND     "Can't open little window"
  59. #define ERRSIGNAL   "Couldn't allocate signal"
  60. #define ERRBACKDROP "OpenWindow: Can't open Backdrop Window"
  61. #define ERRSTDIO    "CreateStdIO: Couldn't create IO block"
  62. #define ERRINPUT    "OpenDevice: Couldn't open input.device"
  63. #define ERRDOIO1     "DoIo1: failed"
  64. #define ERRDOIO2     "DoIo2: failed"
  65. #define NONE        NULL
  66.  
  67. #else SMALLWICON
  68.  
  69. #define ERROR    short
  70.  
  71. #define ERRIBASE     1001
  72. #define ERRGFXBASE   1002
  73. #define ERRLAYBASE   1003
  74. #define ERRICONBASE  1004
  75. #define PROCSIGNAL   1005
  76. #define ERRPORT      1006
  77. #define ERRWIND      1007
  78. #define ERRSIGNAL    1008
  79. #define ERRBACKDROP  1009
  80. #define ERRSTDIO     1010
  81. #define ERRINPUT     1011
  82. #define ERRDOIO1     1012
  83. #define ERRDOIO2     1013
  84. #define NONE         0
  85. #endif
  86.  
  87. struct ArgList ArgList[] =
  88. {
  89.     { (void *)&Arg_AllScreens,    "ALLSCREENS",    1, 'a', ARGBOOL },
  90.     { (void *)&Arg_Boxes,         "BOXES",         1, 'b', ARGWORD },
  91.     { (void *)&Arg_Chars,         "CHARSACROSS",   1, 'c', ARGWORD },
  92.     { (void *)&Arg_Depth,         "DEPTHGADGETS",  1, 'd', ARGBOOL },
  93.     { (void *)&Arg_Execute,       "EXECUTE",       1, '&', ARGBOOL },
  94.     { (void *)&Arg_FirstScreen,   "FIRSTSCREEN",   1, 'f', ARGBOOL },
  95.     { (void *)&Arg_Iconify,       "ICONIFY",       1, 'i', ARGBOOL },
  96.     { (void *)&Arg_Lines,         "LINES",         1, 'l', ARGWORD },
  97.     { (void *)&Arg_Priority,      "PRIORITY",      1, 'p', ARGWORD },
  98.     { (void *)&Arg_Quiet,         "QUIET",         1, 'q', ARGBOOL },
  99.     { (void *)&Arg_RMBTRAP,       "RMBTRAP",       1, 'r', ARGBOOL },
  100.     { (void *)&Arg_Sticky,        "STICKY",        1, 's', ARGBOOL },
  101.     { (void *)&Arg_Testing,       "TESTING",       1, 't', ARGBOOL },
  102.     { (void *)&Arg_Window,        "WINDOW",        6, 'W', ARGSTRING },
  103.     { (void *)&Arg_WBWs,          "WBWINDOWS",     1, 'w', ARGBOOL },
  104.     { (void *)NULL }    /* End of Array Marker */
  105. };
  106.  
  107.  
  108. struct FileHandle *Open();
  109.  
  110. struct    NewWindow   WBWindow =
  111. {
  112.     1,1, 1,1,  -1,-1, NULL, NULL,
  113.     NULL, NULL, NULL,
  114.     NULL, NULL, 50,15, -1,-1,
  115.     WBENCHSCREEN
  116. };
  117.  
  118.  
  119. /*************************************************************************
  120.  *  WiconWait - does the hard stuff, waiting for two things
  121.  *
  122.  *        1 - PushMask - has a *Window been pushed to the back
  123.  *        2 - SuicideMask - has this process been oredered to die
  124.  *
  125.  *  This routine could easily be extended to wait on messages arriving
  126.  *  from the the Icon Windows - eg to pass on CLOSEWINDOW IntuiMessages
  127.  *
  128.  *                                   01-Jan-88
  129.  */
  130.  
  131. WiconWait()
  132. {
  133.     long        WaitMask=0;
  134.     struct  Window  *Window;
  135.     UWORD        *Flags;
  136.  
  137.  
  138.     while (! (WaitMask & SuicideMask) )
  139.     {
  140.     WaitMask = Wait( PushMask | SuicideMask );
  141.  
  142.     if (WaitMask & PushMask)
  143.     {
  144.         Window = PushedWindow;
  145.  
  146.         W_Push(Window);    /* Note: an Icon may want to PULL */
  147.     }
  148.     }
  149.     /* We have been sent a suicide signal */
  150.  
  151.     W_Cleanup();
  152. }
  153.  
  154.  
  155. /*************************************************************************
  156.  *  main - OPENS everything
  157.  *       calls WiconWait
  158.  *       CLOSES everything, calls error(NULL)
  159.  *                  10-Jan-88
  160.  */
  161. int
  162. main(argc,argv)
  163. int    argc;
  164. char    **argv;
  165. {
  166.     WORD    i;          /* Misc Counter */
  167.     LONG    Key;          /* Lock on IntuitionBase */
  168.  
  169. #ifndef SMALLWICON
  170.     extern char *GetArgs();
  171. #endif SMALLWICON
  172.     char    *errString;
  173.  
  174.     struct  Window *BWindow;
  175.     struct  Window *tmpWindow;
  176.  
  177.     static struct  BoxInfo MouseBox = {0,0,0,0};
  178.  
  179.     CWVector = NULL;
  180.     OWVector = NULL;
  181.  
  182.     if ( (IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 33L ))==NULL )
  183.     error(ERRIBASE);
  184.  
  185.     if ( (GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 33L ))==NULL )
  186.     error(ERRGFXBASE);
  187.  
  188.     if ( (LayersBase = (struct LayersBase *)OpenLibrary( "layers.library", 33L ))==NULL )
  189.     error(ERRLAYBASE);
  190.  
  191.     if ( (IconBase = (struct IconBase *)OpenLibrary( "icon.library", 33L ))==NULL )
  192.     error(ERRICONBASE);
  193.  
  194.  
  195.     /* If this program is running already, kill it and
  196.            exit ourselves                   */
  197.  
  198.     if (DeathPort = FindPort( "wicon.Death" ))
  199.     {
  200.     /* Tell the process to stop */
  201.  
  202.     Signal( DeathPort->mp_SigTask, (1L<<DeathPort->mp_SigBit) );
  203.  
  204.     DeathPort = 0;
  205.     error(PROCSIGNAL);
  206.     }
  207.     else
  208.     {
  209.     if ((DeathPort = CreatePort( "wicon.Death", 0L ))==NULL)
  210.         error(ERRPORT);
  211.  
  212.     SuicideMask = (1L<<DeathPort->mp_SigBit);
  213.     }
  214.  
  215. #ifndef SMALLWICON
  216.  
  217.     SetDefaults();
  218.  
  219.         /* Process arguments */
  220.  
  221.     if (errString = GetArgs(argc, argv))
  222.     {
  223.     FILE *errout=stderr;
  224.  
  225.     if (argc==0)    /* probably WB */
  226.     {
  227.         errout = fopen( Arg_Window, "w" );
  228.     }
  229.  
  230.     fputs(Version,stderr);
  231.     if (*errString)
  232.         fprintf(errout, "\nWicon: %s\n", errString );
  233.     else
  234.         fprintf(errout, "\nClick the Right Mouse Button quickly to iconify\n");
  235.     fprintf(errout, "uSage: \"Wicon ?\" for help (and list of defaults)\n" );
  236.  
  237.     if (argc==0)
  238.         Delay(5*50L);   /* wait 5 seconds */
  239.  
  240.     error(NONE);
  241.     }
  242.  
  243. #endif SMALLWICON
  244.  
  245.     if (!Arg_Quiet)
  246.     printf("%s\n", Version);
  247.  
  248.     if ((Arg_Execute)    /* fork another wicon wait for it then exit */
  249. #ifdef SMALLWICON
  250.      && (argc==1)    /* So we don't fork when we have -!& */
  251. #endif SMALLWICON
  252.       )
  253.     {
  254.     ExecuteWicon(argc, argv);
  255.     error(NONE);
  256.     }
  257.  
  258.     SetTaskPri( FindTask(0L), (LONG)Arg_Priority);
  259.  
  260.     /* This seems to be the only way to find the Workbench screen
  261.      * Other than doing weird things with GetScreenData()
  262.      */
  263.  
  264.     if ((tmpWindow = OpenWindow( &WBWindow )) == NULL)
  265.     error(ERRWIND);
  266.     WorkBenchScreen = tmpWindow->WScreen;
  267.     CloseWindow( tmpWindow );
  268.  
  269.     if (Arg_FirstScreen)
  270.     WiconScreen = IntuitionBase->FirstScreen;
  271.     else
  272.     WiconScreen = WorkBenchScreen;
  273.  
  274.  
  275.     if (Arg_Iconify)        /* TRUE by default */
  276.     {
  277.  
  278.         /* clear the array */
  279.  
  280.     for (i=0 ; i<MAXWINFO ; i++)
  281.         Winfo[i].Flags = 0;     /* Hence all ~WINFO_USED */
  282.     Winfos = 0;
  283.  
  284.  
  285.             /* Allocate a signal for our Handler to use
  286.                 to tell us to PUSH a window */
  287.  
  288.     WiconTask = FindTask(0L);
  289.     if ((PushSignal = AllocSignal( -1L )) == -1L)
  290.         error(ERRSIGNAL);
  291.  
  292.     PushMask = (1L << PushSignal);
  293.  
  294.  
  295.  
  296.         /* If there is no Backdrop window then create one */
  297.  
  298.     Key = LockIBase(0L);
  299.     {
  300.         BWindow = WiconScreen->FirstWindow;
  301.         while (BWindow)
  302.         if (BWindow->RPort->Layer->Flags & LAYERBACKDROP)
  303.             break;
  304.         else
  305.             BWindow = BWindow->NextWindow;
  306.     }
  307.     UnlockIBase(Key);
  308.  
  309.     if (BWindow==NULL)
  310.     {
  311.         NewBackdrop.Screen = WiconScreen;
  312.         NewBackdrop.Width  = WiconScreen->Width  - NewBackdrop.LeftEdge;
  313.         NewBackdrop.Height = WiconScreen->Height - NewBackdrop.TopEdge;
  314.         if ((BackdropWindow = OpenWindow( &NewBackdrop ))==NULL)
  315.         error(ERRBACKDROP);
  316.         SetWindowTitles( BackdropWindow, -1L, (UBYTE *)Version);
  317.     }
  318.  
  319.  
  320.  
  321.           /* Set up communication with the input.device */
  322.  
  323.     if ((InputDevPort = CreatePort(0L,0L)) == NULL)
  324.         error(ERRPORT);
  325.  
  326.     if ((InputRequestBlock = CreateStdIO(InputDevPort)) == NULL)
  327.         error(ERRSTDIO);
  328.  
  329.     InputDeviceOpen=(OpenDevice("input.device",0L,InputRequestBlock,0L)==0);
  330.  
  331.     if (InputDeviceOpen == NULL)
  332.         error(ERRINPUT);
  333.  
  334.  
  335.              /* Install the handler */
  336.  
  337.     WiconInterrupt.is_Code = (VOID (*)())WiconHandlerStub;
  338.     WiconInterrupt.is_Node.ln_Pri = 51;    /* priority above Intuition */
  339.  
  340.     InputRequestBlock->io_Command = (long) IND_ADDHANDLER;
  341.     InputRequestBlock->io_Data    = (APTR) &WiconInterrupt;
  342.  
  343.     if (DoIO(InputRequestBlock))
  344.         error(ERRDOIO1);
  345.     }
  346.  
  347.             /* Install the new functions */
  348.  
  349.     OWVector = SetFunction( IntuitionBase, LVOOpenWindow,  WiconOpenW );
  350.     CWVector = SetFunction( IntuitionBase, LVOCloseWindow, WiconCloseW );
  351.  
  352.     W_Init();   /* initialise the semaphore and other structures */
  353.  
  354.     if (Arg_Testing)
  355.     {
  356.     Test();             /* This just opens and closes a window */
  357.     }
  358.     else
  359.     {
  360.     if (argc==0)        /* Running from Workbench */
  361.     {
  362.         MouseBox.LeftEdge = WiconScreen->MouseX;
  363.         MouseBox.TopEdge  = WiconScreen->MouseY;
  364.         SizeRec( WiconScreen, &MouseBox, &WiconScreen->LeftEdge );
  365.     }
  366.  
  367.     WiconWait();        /* Do all the mumbo jumbo */
  368.  
  369.     if (argc==0)
  370.     {
  371.         MouseBox.LeftEdge = WiconScreen->MouseX;
  372.         MouseBox.TopEdge  = WiconScreen->MouseY;
  373.         SizeRec( WiconScreen, &WiconScreen->LeftEdge, &MouseBox );
  374.     }
  375.     }
  376.  
  377.  
  378.                 /* Remove the handler */
  379.  
  380.     if (Arg_Iconify)
  381.     {
  382.     InputRequestBlock->io_Command = (long) IND_REMHANDLER;
  383.     InputRequestBlock->io_Data    = (APTR) &WiconInterrupt;
  384.  
  385.     if (DoIO(InputRequestBlock))
  386.         error(ERRDOIO2);
  387.     }
  388.  
  389.     error(NONE);
  390. }
  391.  
  392. /*************************************************************************
  393.  * error - handles erroneous exits as well as the cleanup
  394.  *       if there is a Message, then print it as an error,
  395.  *       except if (*Message == '\0').
  396.  */
  397.  
  398. error(Message)
  399. ERROR    Message;
  400. {
  401. #ifndef SMALLWICON
  402.     if ((Message!=NULL) && *Message)
  403.     puts( Message );
  404. #else
  405.     if (Message!=0)
  406.     printf("Error status %d\n",Message);
  407. #endif
  408.  
  409.     if (OWVector)
  410.     UnSetFunction( IntuitionBase, LVOOpenWindow, OWVector, WiconOpenW );
  411.  
  412.     if (CWVector)
  413.     UnSetFunction( IntuitionBase, LVOCloseWindow, CWVector, WiconCloseW );
  414.  
  415.     if (BackdropWindow)
  416.     CloseWindow( BackdropWindow );
  417.  
  418.     if (InputDeviceOpen)
  419.     CloseDevice( InputRequestBlock );
  420.     if (InputRequestBlock)
  421.     DeleteStdIO( InputRequestBlock );
  422.     if (InputDevPort)
  423.     DeletePort(  InputDevPort );
  424.  
  425.     if (PushSignal)
  426.     FreeSignal( PushSignal );
  427.     if (DeathPort)
  428.     DeletePort( DeathPort );
  429.  
  430.     if (IconBase)
  431.     CloseLibrary( IconBase );
  432.     if (LayersBase)
  433.     CloseLibrary( LayersBase );
  434.     if (GfxBase)
  435.     CloseLibrary( GfxBase );
  436.     if (IntuitionBase)
  437.     CloseLibrary( IntuitionBase );
  438.  
  439.     exit(0);
  440. }
  441.  
  442.  
  443. /*=======================================================================*/
  444.  
  445. /* This routine is mostly (c) Davide Cervone's, although all the original shell
  446.  *  was originally based on his as well, thanks Davide!.
  447.  
  448. /*
  449.  *  Click-Handler.c    Input Handler for ClickUpFront, which brings a
  450.  *            window to the front when you double-click in it.
  451.  *
  452.  *        Copyright (c) 1987 by Davide P. Cervone
  453.  *  You may use this code provided this copyright notice is left intact.
  454.  */
  455.  
  456. /*************************************************************************
  457.  *  WiconHandler()
  458.  *
  459.  *  This is the input handler. The `self-documenting code :-)' explains what
  460.  *  it does better than I can.
  461.  *
  462.  *  Remember RMB events don't get passed to Intuition unless the RMB is
  463.  *  held down longer than DoubleClickTime(), or the mouse is moved, that is
  464.  *  if we are at all interested in the InutionBase->ActiveWindow.
  465.  */
  466.  
  467. struct InputEvent *WiconHandler(EventList,data)
  468. struct InputEvent *EventList;
  469. APTR data;
  470. {
  471.     struct InputEvent        *theEvent = EventList;
  472.     register struct Layer    *theLayer, *topLayer;
  473.     register struct Screen    *theScreen;
  474.  
  475.     static            LastSecs=0;
  476.     static            LastMics=0;
  477.  
  478.     struct Window        *Window;
  479.     struct InputEvent        **ThisEventPointer;
  480.  
  481.     WORD            SkipEvent;
  482.  
  483.     static struct InputEvent    PushDownEvent;
  484.     static WORD         WaitingForMenuUp = FALSE;
  485.  
  486.     ThisEventPointer = &EventList;  /* Keep track of the pointer to this event */
  487.  
  488.     Forbid();
  489.  
  490.     while(theEvent)
  491.     {
  492.     SkipEvent = FALSE;
  493.  
  494.     switch(theEvent->ie_Class)
  495.     {
  496.         case IECLASS_RAWMOUSE:
  497.  
  498.         if (theEvent->ie_Code == MENUUP)
  499.         {
  500.         if
  501.         (
  502.           WaitingForMenuUp
  503.         &&
  504.           DoubleClick(LastSecs,LastMics,
  505.             theEvent->ie_TimeStamp.tv_secs,
  506.             theEvent->ie_TimeStamp.tv_micro)
  507.         &&
  508.           (Window = IntuitionBase->ActiveWindow)
  509.         &&
  510.           (Window->WScreen == WiconScreen)
  511.         &&
  512.           (((Window->Flags & RMBTRAP) == 0) || Arg_RMBTRAP)
  513.         )
  514.         {
  515.             PushedWindow = Window;
  516.             Signal( WiconTask, PushMask );
  517.             SkipEvent = TRUE;        /* forget about this event */
  518.             WaitingForMenuUp = FALSE;    /* forget about the Menu down event too */
  519.  
  520.         }
  521.         else
  522.         {   /* Put back MENU DOWN event */
  523.             if (WaitingForMenuUp)
  524.             goto putmenudownback;
  525.         }
  526.         LastSecs = 0;
  527.         LastMics = 0;
  528.         }
  529.         else
  530.         {
  531.         if
  532.         (
  533.           theEvent->ie_Code == MENUDOWN
  534.         &&
  535.           (Window = IntuitionBase->ActiveWindow)
  536.         &&
  537.           Window->WScreen == WiconScreen
  538.         )
  539.         {
  540.             LastSecs = theEvent->ie_TimeStamp.tv_secs;
  541.             LastMics = theEvent->ie_TimeStamp.tv_micro;
  542.  
  543.             PushDownEvent = *theEvent;    /* Remember the event structure */
  544.             SkipEvent = TRUE;
  545.             WaitingForMenuUp = TRUE;
  546.         }
  547.         else
  548.         {   /* Put back MENU DOWN event */
  549.             if (WaitingForMenuUp)
  550.             goto putmenudownback;
  551.         }
  552.         }
  553.         break;
  554.  
  555.      case IECLASS_RAWKEY:
  556.         LastSecs = LastMics = 0;
  557.         if (WaitingForMenuUp)
  558.         goto putmenudownback;
  559.         break;
  560.  
  561.      case IECLASS_TIMER:
  562.         if (WaitingForMenuUp)       /* Do we give up waiting for a MENU up ? */
  563.         if (!DoubleClick(LastSecs, LastMics,
  564.             theEvent->ie_TimeStamp.tv_secs,
  565.             theEvent->ie_TimeStamp.tv_micro ))
  566.         {
  567.          putmenudownback:
  568.             LastSecs = 0;
  569.             LastMics = 0;
  570.             WaitingForMenuUp = FALSE;
  571.  
  572.             *ThisEventPointer = &PushDownEvent;
  573.             ThisEventPointer = &(PushDownEvent.ie_NextEvent);
  574.         }
  575.  
  576.         break;
  577.     }
  578.  
  579.     if (!SkipEvent)
  580.     {
  581.         *ThisEventPointer = theEvent;
  582.         ThisEventPointer  = &(theEvent->ie_NextEvent);
  583.     }
  584.     theEvent = theEvent->ie_NextEvent;
  585.     }
  586.  
  587.     *ThisEventPointer = NULL;
  588.  
  589.     Permit();
  590.  
  591.     return (EventList);
  592. }
  593.  
  594.         /* For testing purposes */
  595.  
  596. struct    NewWindow   nw =
  597. {
  598.     100,10, 120,200,  -1,-1, NULL, WINDOWDEPTH | WINDOWDRAG,
  599.     NULL, NULL, (UBYTE *)"test",
  600.     NULL, NULL, 50,15, -1,-1,
  601.     WBENCHSCREEN
  602. };
  603.  
  604. /*************************************************************************
  605.  * Test - is just a test routine, called when Arg_Testing is set, the
  606.  *      TESTING=TRUE (from WB) or -t options (from CLI)
  607.  */
  608. Test()
  609. {
  610.     CloseWindow (OpenWindow( &nw ));  /* OpenWindow fail? come on! */
  611. }
  612.  
  613.  
  614. /*************************************************************************
  615.  * ExecuteWicon - looks at the command line arguments and makes a wild
  616.  *          hack to put them in back into a single string.
  617.  *          It will work Ok for Wicon, but maybe not for all
  618.  *   24-Apr-88      other cases (like imbedded `"''s).
  619.  */
  620. Static
  621. ExecuteWicon(argc, argv)
  622. int argc;            /* Number of arguments */
  623. char **argv;            /* Array of arguments */
  624. {
  625. #define ARGLIMIT   256
  626.  
  627.     char command[ARGLIMIT+1];       /* the command line we are making */
  628.     struct FileHandle *FileH;
  629.     short   limit;            /* Counter/Waiting for port */
  630.  
  631.     char *p;
  632.  
  633.     p = command;
  634.     *p = '\0';
  635.  
  636.     strcat(p, "run <NIL: >NIL: \"");  /* cross our fingers */
  637.  
  638.     strncat(command, *argv++    ,          &command[ARGLIMIT] - p);
  639.     argc--;
  640.     strncat(command, "\" <NIL: >NIL: -!&", &command[ARGLIMIT] - p);
  641.  
  642.     while (*(++p))
  643.     ;
  644.  
  645.     if (argc!=0)
  646.     while (argc--)
  647.     {
  648.         if ((*argv)[1] != '&')    /* We don't want the -& argument */
  649.         {
  650.         *(p++) = ' ';
  651.         *(p++) = '\"';
  652.         *p     = '\0';
  653.  
  654.         strncat(command, *argv, &command[ARGLIMIT] - p);
  655.  
  656.         while (*(++p))
  657.             ;
  658.  
  659.         *(p++) = '\"';
  660.         *p     = '\0';
  661.         }
  662.         argv++;
  663.     }
  664.  
  665.     FileH = Open( "NIL:", MODE_NEWFILE );   /* From Rob Peck's Runback */
  666.  
  667. #ifdef DEBUG
  668.     printf("Execute(\"%s\", NIL, NIL)\n", command);
  669. #endif DEBUG
  670.  
  671.     Execute(command, FileH, FileH);         /* Fred Fish 74? */
  672.  
  673.     if (DeathPort)
  674.     DeletePort( DeathPort );
  675.      DeathPort = NULL;
  676.  
  677.     limit = 100;    /* Wait 5L * 100 / 50 seconds for child process */
  678.     while (limit-- > 0)
  679.     if (FindPort( "wicon.Death" ))
  680.         /* Other process has started */
  681.         break;
  682.     else
  683.         Delay(5L);      /* 1/10 of a second */
  684.  
  685.     return;
  686. }
  687.  
  688. #ifndef SMALLWICON
  689.  
  690. /*********************************************************************
  691.  *
  692.  * SetDefaults - they are done here so that no mucking around is
  693.  *         done in the .h files, and Priority must be done
  694.  *         at run-time
  695.  *
  696.  */
  697. SetDefaults()
  698. {
  699.     struct Task *Task = FindTask(0L);  /* Info about this task */
  700.  
  701.     /* See wicon.doc for documentation */
  702.  
  703.     Arg_AllScreens    = TRUE;
  704.     Arg_Boxes          = 15;
  705.     Arg_Chars          = 12;
  706.     Arg_Depth          = TRUE;
  707.     Arg_Execute       = TRUE;
  708.     Arg_FirstScreen   = FALSE;
  709.     Arg_Iconify       = TRUE;
  710.     Arg_Lines          = 1;
  711.     Arg_Priority      = Task->tc_Node.ln_Pri;
  712.     Arg_Quiet          = FALSE;
  713.     Arg_RMBTRAP       = FALSE;
  714.     Arg_Sticky          = FALSE;
  715.     Arg_Testing       = FALSE;
  716.     Arg_WBWs          = FALSE;
  717.     Arg_Window          = "CON:0/0/640/150/Wicon error messages";
  718.  
  719. }
  720.  
  721. #endif SMALLWICON
  722.  
  723.