home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 103.lha / Mach.c < prev    next >
C/C++ Source or Header  |  1980-07-10  |  37KB  |  1,171 lines

  1. /* Mach1.6 - Mouse Accelerator with Hotkey   **** 02-01-88 ****
  2.    MachClk1.2 - and clock with beeper and meter.
  3.  
  4.    Copyright 1988 by Brian Moats  @Polyglot Software.
  5.  
  6.    This program may be freely distributed providing that the copyright
  7.    notice and document file are included. It may not be used in any
  8.    commercial product without prior written permission.
  9.  
  10.    run mach [nambscqekp] hotkeystring hotkeystring...hotkeystring
  11.  
  12.    Arguments: All optional. Any order.
  13.  
  14.    -n     Accelerator factor where n >= 0 && n <=9.
  15.    -a     Switchs hotkey qualifier from Alternate to Amiga.
  16.    -m     Removes the trapping of left-amiga-m. (allows normal use)
  17.    -bnnn  Time delay before blanking screen. 0-999 minutes. 0 = no blank.
  18.    -s     Removes sunmouse.
  19.    -c     Removes click to front.
  20.    -q     Adds qualifier accumulating feature.
  21.    -estr  Use str as execute command string. Default = NewCLI.
  22.    -knnn  nnn > 0 put clock left edge at nnn. If nnn = 0, don't use clock.
  23.    -tnn   Set beep time interval to every nn minutes.
  24.    -pnnnn Set online rate. nnnn = pennies per hour. Default = 475.
  25.  
  26.    Usage eg. Run Mach -3 -m -a -b10 df0: df1: copy dir\n rename "blank space"
  27.  
  28.    Problem: The uninstall "Control-Qualifier-F1" and the Instant Screen
  29.             Blanker don't work right if defined in a hotkey. e.g. \c\A\2
  30.             doesn't blank the screen and \c\A\1 doesn't uninstall correctly.
  31.  
  32.   How to build this:
  33.   Simple (with Manx). I used version 3.4.
  34.  
  35.     cc machclk
  36.     ln machclk.o -lc
  37.  
  38.  
  39.   Changes from version 1.5:
  40.   1.  Uses UpfrontLayer() instead of WindowToFront() for the clock to prevent
  41.       lockups. Before, I was keeping track of the left mouse button and
  42.       not doing a WindowToFront() if the button was down because you may
  43.       be holding an icon. But...WindowToFront() doesn't actually happen
  44.       until the next event and if it happened that that event was a left
  45.       button down on an icon, bingo! it locks up. Sigh...live and learn.
  46.   2.  Allocate 1 byte for null in hotkey and execute definitions.
  47.   3.  Changed double control feature. Now you use -q. When you do, any
  48.       shift, alternate, amiga or control key is added to the next non-
  49.       qualifier key. This is intended primarily for disabled people who
  50.       find it difficult, if not impossible, to hold down two or more keys
  51.       at once. This accumulates qualifiers so you can hit for example,
  52.       control, shift, alternate and then F1. This is the same as typing
  53.       them at the same time. Hitting Caps Lock will reset the accumulator.
  54.   4.  Return value (rv) changed to long. If there is an error and if
  55.       short, it will crash when run from Runback but will set the returncode
  56.       when run from Run. If long, it won't crash but won't set the returncode
  57.       when run from Run. ??? Any ideas?
  58.  
  59.  
  60.  */
  61.  
  62. #define USINGCLOCK   /* take this out if you don't want the clock */
  63.  
  64. #include <devices/audio.h>
  65. #include <devices/input.h>
  66. #include <devices/inputevent.h>
  67. #include <devices/timer.h>
  68. #include <exec/types.h>
  69. #include <exec/interrupts.h>
  70. #include <exec/memory.h>
  71. #include <exec/ports.h>
  72. #include <graphics/gfxmacros.h>
  73. #include <intuition/intuitionbase.h>
  74. #include <libraries/dos.h>
  75. #include <functions.h>
  76.  
  77.  
  78.             /* key codes that we need */
  79. #define F1           0x50
  80. #define F2           0x51
  81. #define F3           0x52
  82. #define F4           0x53
  83. #define F5           0x54
  84. #define F6           0x55
  85. #define F7           0x56
  86. #define F8           0x57
  87. #define F9           0x58
  88. #define F10          0x59
  89. #define MCODE        0x37   /* "M" key code */
  90. #define ESC          0x45
  91. #define BACKSLASH    0x0d
  92. #define LSHIFT       0x60
  93. #define RSHIFT       0x61
  94. #define CTL          0x63
  95. #define LALT         0x64
  96. #define RALT         0x65
  97. #define LAMIGA       0x66
  98. #define RAMIGA       0x67
  99.  
  100.            /* event signals */
  101. #define QUIT         0x1
  102. #define HOTKEY       0x2
  103. #define ACCELERATE   0x4
  104. #define BACKSCREEN   0x8
  105. #define NEWCLI       0x10
  106. #define UNBLANK      0x20
  107. #define BLANK        0x40
  108. #define SUN          0x80
  109. #define CLICKTF      0x100
  110. #define CLOCK        0x200
  111.  
  112. #define FIVE_MINUTES 300         /* 300 seconds */
  113. #define WAIT_TIME    1000000L    /* 1 second (in micro seconds) */
  114.  
  115. #define CAPSRPTMASK     0x05fb  /* capslock & repeat masked */
  116. #define CTLCAPSRPTMASK  0x05f3  /* control, capslock and repeat masked */
  117.  
  118. #ifdef USINGCLOCK
  119. char info[] = "MachClk 1.2  \xa9 1988 by Brian Moats @Polyglot Software.\n";
  120.  
  121. char usage[] = "\n\
  122. Usage: Run MachClk [nscmqaebktp] hotkeystring hotkeystring...hotkeystring\n\
  123.    -n     Acceleration factor. n >= 0 && n <=9.\n\
  124.    -s     Removes sunmouse.\n\
  125.    -c     Removes click to front.\n\
  126.    -m     Allows normal use of Left-Amiga-M.\n\
  127.    -q     Adds qualifier accumulating feature.\n\
  128.    -a     Set qualifier from Alternate to Amiga.\n\
  129.    -estr  Use str as execute command string. Default = NewCLI.\n\
  130.    -bnnn  Time delay before blanking screen. 0 = no blank.\n\
  131.    -knnn  nnn > 0 put clock left edge at nnn. If nnn = 0, don't use clock.\n\
  132.    -tnn   Set beep time interval to every nn minutes.\n\
  133.    -pnnnn Set online rate. nnnn = pennies per hour. Default = 475.\n\n\
  134. Control-Qualify-Function Key Toggles:\n\
  135. F1 Remove, F2 Instant Blank, F3 Sun Mouse, F4 ClickToFront,\n\
  136. F5 Screen Shuffler, F6 Qualifier Accumulator, F7 Alternate/Amiga,\n\
  137. F8 Clock, F9 Meter, F10 Meter Reset.\n\n";
  138.  
  139. char reminfo[] = ">>> Use Control-Qualifier-F1 to remove MachClk. <<<\n";
  140. char die[] = "MachClk 1.2 removed.\n";
  141. char updated[] = "MachClk 1.2 updated.\n";
  142. char failed[] = "MachClk 1.2 failed.\n";
  143.  
  144. #else /* Otherwise use this stuff */
  145.  
  146. char info[] = "Mach 1.6  \xa9 1988 by Brian Moats @Polyglot Software.\n";
  147.  
  148. char usage[] = "\n\
  149. Usage: Run Mach [nscmqaeb] hotkeystring hotkeystring...hotkeystring\n\
  150.    -n    Acceleration factor. n >= 0 && n <=9.\n\
  151.    -s    Removes sunmouse.\n\
  152.    -c    Removes click to front.\n\
  153.    -m    Allows normal use of Left-Amiga-M.\n\
  154.    -q    Adds qualifier accumulating feature.\n\
  155.    -a    Set qualifier from Alternate to Amiga.\n\
  156.    -estr Use str as execute command string. Default = NewCLI.\n\
  157.    -bnnn Time delay before blanking screen. 0 = no blank.\n\n\
  158. Control-Qualify-Function Key Toggles:\n\
  159. F1 Remove, F2 Instant Blank, F3 Sun Mouse, F4 ClickToFront,\n\
  160. F5 Screen Shuffler, F6 Qualifier Accumulator, F7 Alternate/Amiga.\n\n";
  161.  
  162. char reminfo[] = ">>> Use Control-Qualifier-F1 to remove Mach. <<<\n";
  163. char die[] = "Mach 1.6 removed.\n";
  164. char updated[] = "Mach 1.6 updated.\n";
  165. char failed[] = "MachClk 1.6 failed.\n";
  166. #endif
  167.  
  168. char badarg[] = "\n>>> Bad arguments <<<\n";
  169.  
  170. char PortName[] = "Mach Port";
  171.  
  172. char DefECommand[] = "NewCLI >NIL: <NIL:";
  173.  
  174.  
  175.  
  176. short dx,dy;         /* mouse acceleration delta x y */
  177. short x,y;           /* sunmouse and clicktofront position */
  178.  
  179.              /* event info */
  180. short keyCount = 0;     /* # of function keys pressed in 1 event chain */
  181. short kt[10];           /* 10 function keys max */
  182. short event;            /* signal all of the above defined events */
  183. short lastcode = 0;     /* last keypressed code that was removed from event chain */
  184. long  sec,micro;        /* previous second and micro */
  185. short noevent;          /* # of seconds of no events */
  186. short buttonisdown = 0; /* maintain left button state */
  187.  
  188. short canClock = 1;     /* running the title bar clock */
  189. short canMeter = 0;     /* not showing online meter */
  190. short lastMin = 61;     /* init to impossible # of minutes */
  191.  
  192. short addQual = 0;      /* qualifier to add */
  193. short blanking = 0;     /* not blanking now */
  194.  
  195. struct MsgPort   *inputPort = NULL;
  196. struct IOStdReq  *inputReq = NULL;
  197. struct MsgPort   *TimerPort = NULL;
  198. struct Screen    *s,*blankS = NULL;
  199. struct Window    *mw = NULL;
  200. struct Layer     *ml;
  201. struct IntuitionBase *IntuitionBase = NULL;
  202. struct LayersBase    *LayersBase = NULL;
  203. struct GfxBase       *GfxBase = NULL;
  204. struct FileHandle    *msgfh, *nullfh = NULL;
  205.  
  206. struct NewScreen newScreen = {0,0,320,30,1,0,0,NULL,CUSTOMSCREEN,
  207.                               NULL,NULL,NULL,NULL};
  208.  
  209. struct timerequest Timer_Req;
  210. long   TimerSig,tdevice = 1;
  211.  
  212. struct InputEvent phoney;
  213.  
  214. struct HotInfo
  215.   {
  216.   struct Task *hotTask;
  217.   long  hotSig;
  218.   } hotStuff;
  219.  
  220. long signum = -1;
  221.  
  222. struct Interrupt handlerStuff;
  223.  
  224. /* This MsgPort holds all function key definitions and other variables that
  225.    can be changed by running the program again. */
  226.  
  227. struct defPort
  228.   {
  229.   struct MsgPort mp;
  230.   char * func[10];   /* pointers to 10 hotkey strings */
  231.   char * ECommand;   /* pointer to command to execute with qualifier esc */
  232.   short acc;         /* acceleration factor */
  233.   short ourLQual;    /* the qualifiers being used */
  234.   short ourRQual;
  235.   short canSun;      /* sunning toggle */
  236.   short canFront;    /* click to front toggle */
  237.   short canShuffle;  /* amiga-m toggle */
  238.   short canAddQuals; /* qualifier adding toggle */
  239.   short alternate;   /* alternate or amiga key toggle */
  240.   short blanktime;   /* how long to wait before blanking */
  241. #ifdef USINGCLOCK
  242.   short rate;        /* online rate */
  243.   short beepInterval; /* how long to wait between beeps */
  244. #endif
  245.   };
  246.  
  247. struct defPort *defPortPtr;
  248.  
  249. char defPortName[] = "Definition Port";
  250.  
  251. short updating = 0; /* set to 1 if we updated (actually just found) defPort. */
  252.  
  253. /* Clock stuff */
  254.  
  255. #ifdef USINGCLOCK
  256.  
  257. #define SCREENWIDTH    640
  258. #define WINDOWWIDTH    346
  259. #define LEFTEDGE       SCREENWIDTH-54-WINDOWWIDTH
  260.  
  261. struct NewWindow newWindow = {
  262.   LEFTEDGE, 0,
  263.   WINDOWWIDTH, 10,
  264.   -1, -1,
  265.   0,          /* No IDCMP messages */
  266.   WINDOWDRAG | SMART_REFRESH | NOCAREREFRESH,
  267.   NULL, NULL, NULL, NULL, NULL,
  268.   0, 0, 0, 0,
  269.   WBENCHSCREEN
  270.   };
  271.  
  272. char TimeBuffer[49];
  273.  
  274. struct IntuiText TimeText = {1,0,JAM2,0,0, NULL, (UBYTE *)TimeBuffer, NULL };
  275.  
  276. struct Window *ClockWindow = NULL;
  277. short clockEdge = LEFTEDGE;      /* default position */
  278.  
  279. short cost;   /* online costs */
  280.  
  281. #endif
  282.  
  283. /* end of clock stuff */
  284.  
  285.  
  286.  
  287.           /* character translation table. Key codes in ascii order with bit 8 */
  288.           /* set for upper case. e.g. Shift 1 is exclamation mark and is  */
  289.           /* key code 01, 2nd entry in table with bit 8 set. 0x101 */
  290. USHORT keytran[96] =
  291.  {0x140,0x101,0x12a,0x103,0x104,0x105,0x107,0x12a,0x109,0x10a,
  292.   0x108,0x10c,0x38,0x0b,0x39,0x3a,0x0a,0x01,0x02,0x03,
  293.   0x04,0x05,0x06,0x07,0x08,0x09,0x129,0x29,0x138,0x0c,
  294.   0x139,0x13a,0x102,0x120,0x135,0x133,0x122,
  295.   0x112,0x123,0x124,0x125,0x117,0x126,0x127,0x128,0x137,0x136,0x118,
  296.   0x119,0x110,0x113,0x121,0x114,0x116,0x134,0x111,0x132,0x115,0x131,0x1a,
  297.   0x0d,0x1c,0x106,0x10b,0x00,0x20,0x35,0x33,0x22,0x12,
  298.   0x23,0x24,0x25,0x17,0x26,0x27,0x28,0x37,0x36,0x18,
  299.   0x19,0x10,0x13,0x21,0x14,0x16,0x34,0x11,0x32,0x15,
  300.   0x31,0x11a,0x10d,0x11b,0x100};
  301.  
  302.  
  303.  
  304. void HandlerInterface()
  305.   {
  306. #asm
  307.  
  308.   movem.l a4,-(sp)        ;Manx small code/small data needs to
  309.   jsr _geta4#             ;set up a4 to get at global data.
  310.   movem.l   A0/A1,-(sp)
  311.   jsr       _myhandler
  312.   addq.l    #8,A7
  313.   movem.l (sp)+,a4        ;Manx needs this to.
  314.                           ;No rts. Manx adds it.
  315. #endasm
  316.   }
  317.  
  318. /* The C handler routine.
  319.    It's pretty long but each event is actually taken care of with just
  320.    a few decisions. */
  321.  
  322.  
  323. struct InputEvent *myhandler(ev1, hotStuff)
  324.   struct InputEvent *ev1;
  325.   struct HotInfo *hotStuff;
  326.   {
  327.   struct InputEvent *ev, *last;
  328.   short removeit;
  329.   short evcode,evqual;
  330.  
  331.   event = 0;
  332.   Forbid();
  333.   for (ev=ev1,last = NULL; ev; ev=ev->ie_NextEvent)
  334.     {
  335.     evcode = ev->ie_Code;        /* cause these are accessed so often... */
  336.     evqual = ev->ie_Qualifier;   /* ...it saves bytes to get'em once */
  337.     removeit = 0;
  338.  
  339.     if ((ev->ie_Class != IECLASS_TIMER))
  340.       {
  341.       noevent = 0;
  342.       if (blanking)
  343.         event |= UNBLANK; /* Not TIMER and screen is blank, need to un-blank */
  344.  
  345.       if (ev->ie_Class == IECLASS_RAWKEY)
  346.         if (evcode >= 0x80)
  347.           {
  348.           event &= !UNBLANK;    /* BUT don't unblank on upkey */
  349.           if (evcode == (lastcode | 0x80)) /* remove if keypressed was removed */
  350.             {
  351.             removeit = 1;
  352.             lastcode = 0;
  353.             }
  354.           }
  355.         else  /* This is where we collect qualifiers to add */
  356.           {
  357.           if (defPortPtr->canAddQuals)
  358.             if ((evcode >= LSHIFT) && (evcode <= RAMIGA))
  359.               {
  360.               lastcode = evcode;
  361.               removeit = 1;
  362.               switch (evcode)
  363.                 {
  364.                 case LSHIFT:
  365.                   addQual |= IEQUALIFIER_LSHIFT;
  366.                   break;
  367.                 case RSHIFT:
  368.                   addQual |= IEQUALIFIER_RSHIFT;
  369.                   break;
  370.                 case CTL:
  371.                   addQual |= IEQUALIFIER_CONTROL;
  372.                   break;
  373.                 case LALT:
  374.                   addQual |= IEQUALIFIER_LALT;
  375.                   break;
  376.                 case RALT:
  377.                   addQual |= IEQUALIFIER_RALT;
  378.                   break;
  379.                 case LAMIGA:
  380.                   addQual |= IEQUALIFIER_LCOMMAND;
  381.                   break;
  382.                 case RAMIGA:
  383.                   addQual |= IEQUALIFIER_RCOMMAND;
  384.                   break;
  385.                 default:
  386.                   lastcode = 0;
  387.                   removeit = 0;
  388.                   addQual = 0;   /* Caps Lock gets here so lets nullify all */
  389.                   break;         /* qualifiers. */
  390.                 }
  391.               }
  392.             else         /* if code is not alt, amiga or shift */
  393.               {          /* add any qualifiers that there may be. */
  394.               evqual |= addQual;
  395.               ev->ie_Qualifier |= addQual;
  396.               addQual = 0;
  397.               }
  398.  
  399.           if (((evcode >= F1) && (evcode <= F10)) || (evcode == ESC))
  400.             {
  401.             if (((evqual & CTLCAPSRPTMASK) == defPortPtr->ourLQual) ||
  402.                 ((evqual & CTLCAPSRPTMASK) == defPortPtr->ourRQual))
  403.               {
  404.               lastcode = evcode;
  405.               if (evqual & IEQUALIFIER_CONTROL)  /* qualifier+control+function */
  406.                 {
  407.                 switch (evcode)
  408.                   {
  409.                   case F1:
  410.                     removeit = 1;
  411.                     event |= QUIT;
  412.                     break;
  413.                   case F2:
  414.                     removeit = 1;
  415.                     event |= BLANK;
  416.                     break;
  417.                   case F3:
  418.                     removeit = 1;
  419.                     defPortPtr->canSun = !defPortPtr->canSun;
  420.                     break;
  421.                   case F4:
  422.                     removeit = 1;
  423.                     defPortPtr->canFront = !defPortPtr->canFront;
  424.                     break;
  425.                   case F5:
  426.                     removeit = 1;
  427.                     defPortPtr->canShuffle = !defPortPtr->canShuffle;
  428.                     break;
  429.                   case F6:
  430.                     removeit = 1;
  431.                     defPortPtr->canAddQuals = !defPortPtr->canAddQuals;
  432.                     break;
  433.                   case F7:
  434.                     removeit = 1;
  435.                     defPortPtr->alternate = !defPortPtr->alternate;
  436.                     if (defPortPtr->alternate)
  437.                       {
  438.                       defPortPtr->ourLQual = IEQUALIFIER_LALT;
  439.                       defPortPtr->ourRQual = IEQUALIFIER_RALT;
  440.                       }
  441.                     else
  442.                       {
  443.                       defPortPtr->ourLQual = IEQUALIFIER_LCOMMAND;
  444.                       defPortPtr->ourRQual = IEQUALIFIER_RCOMMAND;
  445.                       }
  446.                     break;
  447. #ifdef USINGCLOCK
  448.                   case F8:
  449.                     removeit = 1;
  450.                     canClock = !canClock;
  451.                     event |= CLOCK;
  452.                     break;
  453.                   case F9:
  454.                     removeit = 1;
  455.                     canMeter = !canMeter;
  456.                     break;
  457.                   case F10:
  458.                     removeit = 1;
  459.                     cost = 0;
  460.                     break;
  461. #endif
  462.                   default:
  463.                     lastcode = 0;   /* no down key we want to remove upkey of */
  464.                   }
  465.                 }
  466.               else                    /* qualifier + ESC or function */
  467.                 {
  468.                 if (evcode == ESC)
  469.                   {
  470.                   removeit = 1;
  471.                   event |= NEWCLI;
  472.                   }
  473.                 else
  474.                   {
  475.                   if (defPortPtr->func[evcode - F1])
  476.                     {
  477.                     removeit = 1;
  478.                     if (keyCount < 10)
  479.                       {
  480.                       kt[keyCount++] = evcode;  /* save f key */
  481.                       event |= HOTKEY;
  482.                       }
  483.                     }
  484.                   }
  485.                 }
  486.               }
  487.             }
  488.           else
  489.             if (defPortPtr->canShuffle && (evcode == MCODE)&&((evqual & IEQUALIFIER_LCOMMAND) == IEQUALIFIER_LCOMMAND))
  490.               {
  491.               lastcode = evcode;
  492.               removeit = 1;
  493.               event |= BACKSCREEN;
  494.               }
  495.           }
  496. /* end of RAWKEY stuff */
  497.  
  498.       if (ev->ie_Class == IECLASS_RAWMOUSE)
  499.         {
  500.         if (evcode == IECODE_LBUTTON)  /* keep track of left button. Up or */
  501.           buttonisdown = 1; /* down. Don't sun mouse or send clock to front */
  502.                              /* when down */
  503.         if (defPortPtr->canSun || defPortPtr->canFront)
  504.           {
  505.           s = IntuitionBase->FirstScreen;
  506.           while (s && (s->MouseY < 0)) s = s->NextScreen;
  507.           if (s == NULL) s = IntuitionBase->ActiveScreen;
  508.  
  509.           x = s->MouseX + ev->ie_X;
  510.           y = s->MouseY + ev->ie_Y;
  511.  
  512.           if ((defPortPtr->canSun) && !buttonisdown) /* don't sun while button is down */
  513.             event |= SUN;
  514.  
  515.           if ((defPortPtr->canFront) && (ev->ie_Code == IECODE_LBUTTON))
  516.             event |= CLICKTF;
  517.           }
  518.  
  519.         if (evcode == (IECODE_LBUTTON | 0x80))  /* Now set button up if it is */
  520.           buttonisdown = 0;
  521.  
  522.         if ((ev->ie_TimeStamp.tv_secs == sec) &&
  523.            ((ev->ie_TimeStamp.tv_micro / 50000) == micro))
  524.           {
  525.           dx = ev->ie_X;  /* only accel if 2 mouse moves in 1/20 second */
  526.           dy = ev->ie_Y;
  527.           event |= ACCELERATE;
  528.           }
  529.         if (ev->ie_TimeStamp.tv_secs) /* writeevent sets sec=0 */
  530.           {
  531.           micro = ev->ie_TimeStamp.tv_micro / 50000;
  532.           sec = ev->ie_TimeStamp.tv_secs;
  533.           }
  534.         }
  535.       }    /* if not timer event */
  536.            /* all events get here */
  537.       if (removeit)
  538.         if (last == NULL)       /* remove from event chain */
  539.           ev1 = ev->ie_NextEvent;
  540.         else
  541.           last->ie_NextEvent = ev->ie_NextEvent;
  542.       else
  543.         last = ev;
  544.     }    /* for */
  545.   if (event)
  546.     Signal(hotStuff->hotTask,hotStuff->hotSig);
  547.   Permit();
  548.   return(ev1);
  549.   }
  550.  
  551.  
  552. main(argc, argv)
  553.   short argc;
  554.   char *argv[];
  555.   {
  556.   struct IntuiMessage *Msg;
  557.   long                class;
  558.   long                len;
  559.   short               i,j,f,c;
  560.  
  561.  
  562.   msgfh = Output();
  563.   if (msgfh)
  564.     {
  565.     (void)Write(msgfh,info,(long)sizeof(info));
  566.     if ((argv[1][0] == '?') || (argc < 2))
  567.       {
  568.       (void)Write(msgfh,usage,(long)sizeof(usage));
  569.       if (argc < 2)
  570.         (void)Write(msgfh,reminfo,(long)sizeof(reminfo));
  571.       exit(0);
  572.       }
  573.     }
  574.  
  575.   IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0L);
  576.   GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0L);
  577.   LayersBase = (struct LayersBase *) OpenLibrary("layers.library",0L);
  578.  
  579.   defPortPtr = (struct defPort *) FindPort(defPortName);
  580.   if (defPortPtr == NULL)
  581.     {
  582.     if ((defPortPtr = (struct defPort *) AllocMem((long)sizeof(struct defPort),MEMF_PUBLIC | MEMF_CLEAR)) == NULL)
  583.       exit(10);
  584.     defPortPtr->acc = 1;       /* default acceleration rate */
  585.     defPortPtr->ourLQual = IEQUALIFIER_LALT;
  586.     defPortPtr->ourRQual = IEQUALIFIER_RALT; /* Defaults to Alternate qualifiers */
  587.     defPortPtr->canSun = 1;
  588.     defPortPtr->canFront = 1;
  589.     defPortPtr->canShuffle = 1;
  590.     defPortPtr->canAddQuals = 0;
  591.     defPortPtr->alternate = 1;
  592.     defPortPtr->blanktime = FIVE_MINUTES;
  593. #ifdef USINGCLOCK
  594.     defPortPtr->beepInterval = 15; /* minutes */
  595.     defPortPtr->rate = 475; /* default peoplelink rate */
  596. #endif
  597.     if ((defPortPtr->ECommand = AllocMem((long)sizeof(DefECommand),MEMF_PUBLIC)) != NULL)
  598.       strcpy(defPortPtr->ECommand,DefECommand);
  599.     }
  600.   else
  601.     updating = 1; /* Port found so we must be updating it */
  602.  
  603.   for (i = 1,f = 0; i < argc && f <= 9; i++)
  604.     if (argv[i][0] == '-')
  605.       {
  606.       j = 1;
  607.       while (argv[i][j])  /* parse multiple options with one leading "-" */
  608.         {
  609.         if ((argv[i][j] >= '0') && (argv[i][j] <= '9'))  /* Accelerating arg? */
  610.           defPortPtr->acc = (argv[i][j++] & 0x0f);
  611.         else
  612.           if ((argv[i][j] & 0x5f) == 'M')    /* Don't want screen shuffler? */
  613.             {
  614.             defPortPtr->canShuffle = 0;
  615.             j++;
  616.             }
  617.           else
  618.             if ((argv[i][j] & 0x5f) == 'A')   /* Want Amiga qualifier? */
  619.               {
  620.               defPortPtr->alternate = 0;
  621.               defPortPtr->ourLQual = IEQUALIFIER_LCOMMAND;
  622.               defPortPtr->ourRQual = IEQUALIFIER_RCOMMAND;
  623.               j++;
  624.               }
  625.             else
  626.               if ((argv[i][j] & 0x5f) == 'S')   /* Don't want sunmouse? */
  627.                 {
  628.                 defPortPtr->canSun = 0;
  629.                 j++;
  630.                 }
  631.               else
  632.                 if ((argv[i][j] & 0x5f) == 'C')   /* Don't want ClickToFront? */
  633.                   {
  634.                   defPortPtr->canFront = 0;
  635.                   j++;
  636.                   }
  637.                 else
  638.                   if ((argv[i][j] & 0x5f) == 'B')   /* Got blanking arg? */
  639.                     {
  640.                     defPortPtr->blanktime = atoi(&argv[i][j+1]) * 60;
  641.                     while (argv[i][++j]) ;
  642.                     }
  643.                   else
  644.                     if ((argv[i][j] & 0x5f) == 'Q') /* Want to add up qualifiers? */
  645.                       {
  646.                       defPortPtr->canAddQuals = 1;  /* this one defaults to off. */
  647.                       j++;
  648.                       }
  649.                     else
  650.                       if ((argv[i][j] & 0x5f) == 'E') /* Got execute command? */
  651.                         {
  652.                         if (defPortPtr->ECommand) /* free old command */
  653.                           FreeMem(defPortPtr->ECommand,(long)strlen(defPortPtr->ECommand)+1);
  654.                         if (defPortPtr->ECommand = AllocMem((long)strlen(&argv[i][j+1])+1,MEMF_PUBLIC))
  655.                           strcpy(defPortPtr->ECommand,&argv[i][j+1]);
  656.                         while (argv[i][++j]) ;
  657.                         }
  658. #ifdef USINGCLOCK
  659.                       else
  660.                         if ((argv[i][j] & 0x5f) == 'K') /* Clock stuff? */
  661.                           {
  662.                           clockEdge = atoi(&argv[i][j+1]);
  663.                           if (clockEdge == 0)   /* 0 or no number means no clock */
  664.                             canClock = 0;
  665.                           while (argv[i][++j]) ;
  666.                           }
  667.                         else
  668.                           if ((argv[i][j] & 0x5f) == 'T') /* Beep interval? */
  669.                             {
  670.                             defPortPtr->beepInterval = atoi(&argv[i][j+1]);
  671.                             while (argv[i][++j]) ;
  672.                             }
  673.                           else
  674.                             if ((argv[i][j] & 0x5f) == 'P') /* Penny watcher? */
  675.                               {
  676.                               defPortPtr->rate = atoi(&argv[i][j+1]);
  677.                               while (argv[i][++j]) ;
  678.                               }
  679. #endif
  680.                             else
  681.                               {
  682.                               if (msgfh)
  683.                                 {
  684.                                 Write(msgfh,badarg,(long)sizeof(badarg));
  685.                                 Write(msgfh,usage,(long)sizeof(usage));
  686.                                 }
  687.                               Uninstall(10L);
  688.                               }
  689.  
  690.         }
  691.       }
  692.     else  /* Not "-", must be hotkey definition. */
  693.           /* Set len equal to length of argv[i] + 1 for null if not a */
  694.           /* specific key given with +n. If +n, set len equal to length */
  695.           /* of argv[i] - 1. */
  696.       {
  697.       if (len = (long)strlen(argv[i]))
  698.         {
  699.         c = 0;
  700.         if (argv[i][0] == '+')  /* specific key? */
  701.           {
  702.           if (argv[i][1] >= '0' && argv[i][1] <= '9')
  703.             {
  704.             f = argv[i][1] - '0' - 1;
  705.             if (f < 0)
  706.               f = 9;
  707.             c = 2;   /* 1st char of definition */
  708.             len--;  /* less plus sign but keep 1 for null */
  709.             }
  710.           }
  711.         else
  712.           len++; /* add for null */
  713.  
  714.         if (defPortPtr->func[f]) /* free old definition */
  715.           FreeMem(defPortPtr->func[f],(long)strlen(defPortPtr->func[f])+1);
  716.         if (defPortPtr->func[f] = AllocMem(len,MEMF_PUBLIC))
  717.           strcpy(defPortPtr->func[f],&argv[i][c]);
  718.         }
  719.       f++;
  720.       }
  721.  
  722.   if (updating)    /* if we just updating, get out now */
  723.     Uninstall(0L);
  724.  
  725.   defPortPtr->mp.mp_Node.ln_Pri = 0;
  726.   defPortPtr->mp.mp_Node.ln_Type = NT_MSGPORT;
  727.   NewList(&(defPortPtr->mp.mp_MsgList));
  728.   defPortPtr->mp.mp_Node.ln_Name = (char *) &(defPortName);
  729.  
  730.   AddPort(defPortPtr); /* add our hotkey and definition port structure */
  731.  
  732.    /* Init HotStuff structure */
  733.   if((signum = AllocSignal((long)-1)) == -1)
  734.     Uninstall(11L);
  735.  
  736.   hotStuff.hotSig = 1 << signum;
  737.   hotStuff.hotTask = FindTask(NULL);
  738.  
  739.   /* and stuff to add the handler */
  740.   if(!(inputPort = CreatePort(PortName,0)))
  741.     Uninstall(12L);
  742.   if(!(inputReq = CreateStdIO(inputPort)))
  743.     Uninstall(13L);
  744.  
  745.   handlerStuff.is_Data = (APTR)&hotStuff;   /* shared data */
  746.   handlerStuff.is_Code = HandlerInterface;  /* assem entry */
  747.   handlerStuff.is_Node.ln_Pri = 55;         /* above Intuition */
  748.   handlerStuff.is_Node.ln_Name = "Mach Handler";
  749.  
  750.   if(OpenDevice("input.device",0L,inputReq,0L) != 0)
  751.     Uninstall(14L);
  752.  
  753.   inputReq->io_Command = IND_ADDHANDLER;
  754.   inputReq->io_Data = (APTR)&handlerStuff;
  755.  
  756.   DoIO(inputReq);
  757.  
  758.   nullfh = Open("NIL:",MODE_NEWFILE); /* used by Execute() */
  759.  
  760.   /* setup timer */
  761.  
  762.   if ((TimerPort = CreatePort("Timer Port", 0L)) == NULL)
  763.     Uninstall(15L);
  764.  
  765.   if ((tdevice = OpenDevice(TIMERNAME, UNIT_VBLANK, &Timer_Req, 0L)) != 0)
  766.     Uninstall(16L);
  767.   Timer_Req.tr_node.io_Message.mn_ReplyPort = TimerPort;
  768.   Timer_Req.tr_node.io_Command = TR_ADDREQUEST;
  769.   Timer_Req.tr_node.io_Flags = 0;
  770.   Timer_Req.tr_node.io_Error = 0;
  771.  
  772.   TimerSig = (1L << TimerPort->mp_SigBit);
  773.  
  774.   /* end of timer stuff */
  775.  
  776. #ifdef USINGCLOCK
  777.   if (canClock)
  778.     SetupClock();
  779.   DisplayTime();
  780. #endif
  781.  
  782.   (void)SetTaskPri(FindTask(NULL), 20L);
  783.  
  784.   QueTimer();
  785.  
  786.  /*************************************************************************
  787.                              MAIN EVENT LOOP
  788.  ***************************************************************************/
  789.  
  790.   for (;;)
  791.     {
  792.     Wait(hotStuff.hotSig | TimerSig);
  793.  
  794. #ifdef USINGCLOCK
  795.       if (event & CLOCK)
  796.         if (canClock)
  797.           SetupClock();
  798.         else
  799.           KillClock();
  800.  
  801. #endif
  802.       if ((Msg = (struct IntuiMessage *)GetMsg(TimerPort)) || (event & BLANK))
  803.         {
  804.         if (Msg)
  805.           {
  806.           QueTimer();
  807. #ifdef USINGCLOCK
  808.           DisplayTime();
  809. #endif
  810.           }
  811.         if ((((++noevent >= defPortPtr->blanktime) && defPortPtr->blanktime) ||
  812.            (event & BLANK)) && !blanking)
  813.           if ((blankS = OpenScreen(&newScreen)) != NULL)
  814.             {
  815.             SetRGB4(&(blankS->ViewPort),0L,0L,0L,0L);
  816.             OFF_DISPLAY;
  817.             blanking = 1;
  818.             }
  819.         }
  820.  
  821.     if (event & UNBLANK)
  822.       if ((blanking) && (blankS))
  823.         {
  824.         blanking = 0;
  825.         (void)CloseScreen(blankS);
  826.         ON_DISPLAY;
  827.         }
  828.  
  829.     i = 0;
  830.     if (event & HOTKEY)
  831.       {
  832.       while (i < keyCount)  /*may be more than 1 function key pressed */
  833.         WriteHotString(i++);
  834.       keyCount = 0;
  835.       }
  836.  
  837.     if (defPortPtr->acc && (event & ACCELERATE))
  838.       Accelerate();
  839.  
  840.     if (event & BACKSCREEN)
  841.       {
  842.       Forbid();
  843.       if (s = IntuitionBase->FirstScreen)
  844.         (void)ScreenToBack(s);
  845.       Permit();
  846.       }
  847.  
  848.     if (event & NEWCLI)
  849.       {
  850.       WBenchToFront();
  851.       Execute(defPortPtr->ECommand,nullfh,nullfh);
  852.       }
  853.  
  854.     if (event & (SUN | CLICKTF))
  855.       {
  856.       ml = WhichLayer(&(s->LayerInfo),(long)x,(long)y);
  857.       if (ml && (mw = (struct Window *)ml->Window))
  858.         {
  859.         if ( event & SUN)
  860.           if (mw != IntuitionBase->ActiveWindow)
  861.             (void)ActivateWindow(mw);
  862.  
  863.         if (event & CLICKTF)
  864.           {
  865.           if (!(mw->Flags & BACKDROP))
  866.             (void)WindowToFront(mw);
  867.           }
  868.         }
  869.       }
  870.  
  871.     if (event & QUIT)
  872.       Uninstall(0L);     /* all done...never to return */
  873.  
  874.     }  /* for(;;) */
  875.   }  /* main() */
  876.  
  877.  /************************************************************************/
  878.  
  879.  
  880. QueTimer()
  881.   {
  882.   Timer_Req.tr_time.tv_secs = 0;
  883.   Timer_Req.tr_time.tv_micro = WAIT_TIME;
  884.   SendIO(&Timer_Req.tr_node);
  885.   }
  886.  
  887.  
  888. #ifdef USINGCLOCK
  889.  
  890. SetupClock()
  891.   {
  892.   newWindow.LeftEdge = clockEdge;
  893.   if (!(ClockWindow = OpenWindow(&newWindow)))
  894.     canClock = 0;  /* if can't then just disable clock */
  895.   }
  896.  
  897. KillClock()
  898.   {
  899.   if (ClockWindow)
  900.     CloseWindow(ClockWindow);
  901.   ClockWindow = NULL;
  902.   canClock = 0;
  903.   }
  904.  
  905. DisplayTime()
  906.   {
  907.   long  hours, minutes, seconds;
  908.   long  chipfree, fastfree;
  909.   struct DateStamp time;
  910.  
  911.   if (canClock)
  912.     {
  913.     DateStamp(&time);
  914.     chipfree = AvailMem(MEMF_CHIP) >> 10;
  915.     fastfree = AvailMem(MEMF_FAST) >> 10;
  916.     hours = time.ds_Minute / 60 ;
  917.     if (hours >= 13) hours = (hours % 13)+1; /* don't want 24 hr. */
  918.     minutes = time.ds_Minute % 60 ;
  919.     seconds = time.ds_Tick / TICKS_PER_SECOND;
  920.     if (!(seconds % 4))          /* don't do to often. */
  921.       {
  922.       Forbid();
  923.       ml = WhichLayer(&(ClockWindow->WScreen->LayerInfo),(long)ClockWindow->LeftEdge,(long)ClockWindow->TopEdge+1);
  924.       if ((ml->Window != ClockWindow) && !buttonisdown)
  925.         UpfrontLayer(&(ClockWindow->WScreen->LayerInfo),ClockWindow->WLayer);
  926.       Permit();
  927.       }  /* Don't use windowtofront because it locks up if holding an icon */
  928.     if (canMeter)
  929.       sprintf(TimeBuffer, "[     ] Chip: %3ld  Fast:%4ld  Cost: $%2d.%02d ",
  930.                              chipfree,fastfree,cost/100,cost % 100);
  931.     else
  932.       sprintf(TimeBuffer, "[     ] Chip: %3ld  Fast:%4ld  Time:%2ld:%02ld:%02ld",
  933.                              chipfree,fastfree,hours,minutes,seconds);
  934.     if (lastMin != minutes)
  935.       {
  936.       lastMin = minutes;
  937.       cost = cost + (((defPortPtr->rate / 6) + (defPortPtr->rate % 6)) / 10);
  938.       }
  939.  
  940.     if (defPortPtr->canSun) TimeBuffer[1] = 's';    /* put in current toggles */
  941.     if (defPortPtr->canFront) TimeBuffer[2] = 'c';
  942.     if (defPortPtr->canShuffle) TimeBuffer[3] = 'm';
  943.     if (defPortPtr->canAddQuals) TimeBuffer[4] = 'q';
  944.     if (!(defPortPtr->alternate)) TimeBuffer[5] = 'a';
  945.  
  946.     PrintIText(ClockWindow->RPort, &TimeText, 1L, 1L);
  947.     if ((seconds == 0) && (defPortPtr->beepInterval) && ((minutes % defPortPtr->beepInterval)==0))
  948.       Beep();
  949.     }
  950.   }
  951.  
  952.  
  953. Beep()
  954.   {
  955.   struct IOAudio sound;
  956.   char * sData;
  957.   short i;
  958.   long soundUnit;
  959.  
  960.   if (sound.ioa_Request.io_Message.mn_ReplyPort = CreatePort("Beep Port",0L))
  961.     {
  962.     soundUnit = 0x01020408;
  963.     sound.ioa_Request.io_Message.mn_Node.ln_Pri = 10;
  964.     sound.ioa_Data = (UBYTE *) &soundUnit;
  965.     sound.ioa_Length = 4;
  966.  
  967.     if (OpenDevice(AUDIONAME,0L,&sound.ioa_Request,0L) == NULL)
  968.       {
  969.  
  970.       if ((sData = AllocMem(64L,MEMF_CHIP | MEMF_CLEAR)) != NULL)
  971.         {
  972.         for (i = 1;i < 64;i++)
  973.           sData[i] = i;
  974.  
  975.         sound.ioa_Request.io_Command = CMD_WRITE;
  976.         sound.ioa_Request.io_Flags = ADIOF_PERVOL;
  977.         sound.ioa_Data = (UBYTE *) sData;
  978.         sound.ioa_Cycles = 50;
  979.         sound.ioa_Length = 64;
  980.         sound.ioa_Period = 128; /* use a higher number for a lower tone */
  981.         sound.ioa_Volume = 64;
  982.  
  983.         BeginIO(&sound.ioa_Request);
  984.         WaitIO(&sound.ioa_Request);
  985.  
  986.         FreeMem(sData,64L);
  987.         }
  988.       CloseDevice(&sound.ioa_Request);
  989.       }
  990.     DeletePort(sound.ioa_Request.io_Message.mn_ReplyPort);
  991.     }
  992.   }
  993. #endif
  994.  
  995. #define ASCIIBIAS 0x20
  996. #define SHIFTBIT  0x100
  997. #define RETURN    0x44
  998.  
  999. WriteHotString(e)
  1000.   short e;         /* key table entry */
  1001.   {
  1002.   short k,j,outkey,outqual;
  1003.  
  1004.   k = 0;
  1005.   j = kt[e]-F1;        /* 1-10 from the function key code */
  1006.   if (!(defPortPtr->func[j])) return;
  1007.   while (defPortPtr->func[j][k])
  1008.     {
  1009.     outkey = 0;
  1010.     outqual = 0;
  1011.     while ((defPortPtr->func[j][k] == '\\') && (outkey == 0))
  1012.       {
  1013.       switch (defPortPtr->func[j][++k])
  1014.         {
  1015.         case 'N':
  1016.         case 'n':
  1017.           outkey = RETURN;
  1018.           ++k;
  1019.           break;
  1020.         case 'C':
  1021.         case 'c':
  1022.           outqual |= IEQUALIFIER_CONTROL;
  1023.           ++k;
  1024.           break;
  1025.         case 'a':
  1026.           outqual |= IEQUALIFIER_LALT;
  1027.           ++k;
  1028.           break;
  1029.         case 'A':
  1030.           outqual |= IEQUALIFIER_LCOMMAND;
  1031.           ++k;
  1032.           break;
  1033.         case 's':
  1034.         case 'S':
  1035.           outqual |= IEQUALIFIER_LSHIFT;
  1036.           ++k;
  1037.           break;
  1038.         case '\\':
  1039.           outkey = BACKSLASH;
  1040.           ++k;
  1041.           break;
  1042.         default:
  1043.           if ((defPortPtr->func[j][k] >= '0') && (defPortPtr->func[j][k] <= '9'))  /* Function key? */
  1044.             outkey = defPortPtr->func[j][k++] + 0x1f;  /* translate '1' - '9' to F1 - F9 */
  1045.           if (outkey == 0x4f)
  1046.             outkey = 0x59;     /* translate '0' to F10 */
  1047.           break;
  1048.         }
  1049.       }
  1050.     if (outkey == 0)  /* then didn't get return or function key or "\" */
  1051.       {               /* translate letter into keycode and qualifier */
  1052.       outkey = (keytran[(defPortPtr->func[j][k] - ASCIIBIAS)]);
  1053.       outqual |= (outkey & SHIFTBIT) >> 8; /* add shift qualifier if present */
  1054.       outkey &= 0x7f;                      /* then strip shiftbit */
  1055.       ++k;
  1056.       }
  1057.     WriteKey(outkey,outqual);               /* send it pressed down */
  1058.     WriteKey(outkey | 0x80,outqual);        /* and up */
  1059.     }
  1060.   }
  1061.  
  1062. WriteKey(c,q)
  1063.   short c,q;
  1064.   {
  1065.   inputReq->io_Command = IND_WRITEEVENT;
  1066.   inputReq->io_Flags = 0;
  1067.   inputReq->io_Length = sizeof(struct InputEvent);
  1068.   inputReq->io_Data = (APTR)&phoney;
  1069.  
  1070.   phoney.ie_NextEvent = NULL;
  1071.   phoney.ie_Class = IECLASS_RAWKEY;
  1072.   phoney.ie_TimeStamp.tv_secs = 0;
  1073.   phoney.ie_TimeStamp.tv_micro = 0;
  1074.   phoney.ie_Code = c;
  1075.   phoney.ie_Qualifier = q;
  1076.   phoney.ie_X = 0;
  1077.   phoney.ie_Y = 0;
  1078.   DoIO(inputReq);
  1079.   }
  1080.  
  1081. Accelerate()
  1082.   {
  1083.   inputReq->io_Command = IND_WRITEEVENT;
  1084.   inputReq->io_Flags = 0;
  1085.   inputReq->io_Length = sizeof(struct InputEvent);
  1086.   inputReq->io_Data = (APTR)&phoney;
  1087.  
  1088.   phoney.ie_NextEvent = NULL;
  1089.   phoney.ie_Class = IECLASS_RAWMOUSE;
  1090.   phoney.ie_TimeStamp.tv_secs = 0;
  1091.   phoney.ie_TimeStamp.tv_micro = 0;
  1092.   phoney.ie_Code = IECODE_NOBUTTON;
  1093.   phoney.ie_Qualifier = IEQUALIFIER_RELATIVEMOUSE;
  1094.   phoney.ie_X = (dx * defPortPtr->acc) / 2;
  1095.   phoney.ie_Y = (dy * defPortPtr->acc) / 3;
  1096.   DoIO(inputReq);
  1097.   }
  1098.  
  1099. Uninstall(rv)
  1100.   long rv;
  1101.   {
  1102.   short i;
  1103.  
  1104.   if (msgfh)
  1105.     if (event & QUIT)
  1106.       (void)Write(msgfh,die,(long)sizeof(die));
  1107.     else
  1108.       if (rv)
  1109.         (void)Write(msgfh,failed,(long)sizeof(failed));
  1110.       else
  1111.         if (updating)
  1112.           (void)Write(msgfh,updated,(long)sizeof(updated));
  1113.  
  1114.   if (!updating)
  1115.     {
  1116.     if (inputReq)      /* remove the handler */
  1117.       {
  1118.       inputReq->io_Command = IND_REMHANDLER;
  1119.       inputReq->io_Data = (APTR)&handlerStuff;
  1120.       DoIO(inputReq);
  1121.  
  1122.       CloseDevice(inputReq);
  1123.       DeleteStdIO(inputReq);
  1124.       }
  1125.  
  1126.    /* close, delete and free other stuff */
  1127.  
  1128.     if (nullfh)       Close(nullfh);
  1129.     if (inputPort)    DeletePort(inputPort);
  1130.     if (signum > -1)  FreeSignal(signum);
  1131.  
  1132.     if (tdevice == 0)
  1133.       {
  1134.       AbortIO(&Timer_Req.tr_node);
  1135.       CloseDevice(&Timer_Req);
  1136.       }
  1137.  
  1138.     if (TimerPort)
  1139.       DeletePort(TimerPort);
  1140.  
  1141. #ifdef USINGCLOCK
  1142.     if (canClock)
  1143.       KillClock();
  1144. #endif
  1145.  
  1146.     if (defPortPtr)
  1147.       {                       /* Free hotkey definitions */
  1148.       for (i=0;i<10;i++)
  1149.         if (defPortPtr->func[i])
  1150.           FreeMem(defPortPtr->func[i],(long)strlen(defPortPtr->func[i])+1);
  1151.  
  1152.                              /* Free Execute Command string */
  1153.       if (defPortPtr->ECommand)
  1154.         FreeMem(defPortPtr->ECommand,(long)strlen(defPortPtr->ECommand)+1);
  1155.  
  1156.       if (defPortPtr->mp.mp_Node.ln_Name)
  1157.         RemPort(defPortPtr);
  1158.       FreeMem(defPortPtr,(long)sizeof(struct defPort));
  1159.       }
  1160.     }
  1161.  
  1162.   if (IntuitionBase)
  1163.     CloseLibrary(IntuitionBase);
  1164.   if (GfxBase)
  1165.     CloseLibrary(GfxBase);
  1166.   if (LayersBase)
  1167.     CloseLibrary(LayersBase);
  1168.   exit(rv);
  1169.   }
  1170.  
  1171.