home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / ja91 / ASCII / AppWorkbench / adc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-11  |  19.6 KB  |  593 lines

  1. /*(c)  Copyright 1991 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice,
  3. and is provided "as is" without warranty of any kind, either expressed
  4. or implied.  The entire risk as to the use of this information is
  5. assumed by the user.
  6. */
  7.  
  8.  
  9. /****** AppWorkbench.demo/ADC *************************************************
  10.  
  11.     NAME
  12.         ADC -- AppWorkbench - Complete and contained demo of how to use
  13.                the AppWorkbench Interface.
  14.  
  15.     AUTHOR
  16.         Fred Mitchell, Copyright © 1991 Commodore-Amiga, Inc.
  17.  
  18.     VERSION
  19.         3.00    08 Jul 1991 - All known problems are rectified.
  20.  
  21.     FUNCTION
  22.         Demonstrates use of AppIcons, AppMenu, and AppWindow.
  23.  
  24.     COMPILE
  25.         lc -L adc
  26.  
  27. ******************************************************************************/
  28.  
  29. /* Includes */
  30. #include <exec/types.h>
  31. #include <intuition/intuition.h>
  32. #include <workbench/icon.h>
  33. #include <workbench/workbench.h>
  34. #include <workbench/startup.h>
  35. #include <dos.h>
  36. #include <dos/dos.h>
  37. #include <dos/dosextens.h>
  38. #include <dos/dostags.h>
  39.  
  40. /* Defines  */
  41. #define ASIZE   500     /* size of the arrays */
  42.  
  43. /* Structs, externs, and prototypes */
  44.  
  45. struct AppWindow *awin = NULL;
  46. struct Window *win = NULL;
  47.  
  48. struct AppIcon *aicon = NULL;
  49.  
  50. struct AppMenuItem *amenu[ASIZE];
  51. char *appName[ASIZE];
  52. short  amicount = NULL;
  53.  
  54. struct Remember *key = NULL;
  55. struct MsgPort *aport = NULL;   /* message port to be used with appicon system */
  56.  
  57. struct Library  *GfxBase,
  58.                 *IntuitionBase,
  59.                 *IconBase,
  60.                 *WorkbenchBase,
  61.                 *GadToolsBase;
  62.  
  63. extern struct Library *DOSBase, *SysBase;
  64.  
  65. /* Prototypes   */
  66.  
  67. void _main(void);
  68. void ProcessIcon(struct Window *win,
  69.                  struct AppMessage *am);
  70. UBYTE *BSTRtoSTR(ULONG b);
  71. void ShutDown(void);
  72. void warning(char *s);
  73. void warning2(char *r, char *s);
  74. void fatal(char *s);
  75. void fatal2(char *r, char *s);
  76. struct Window *MakeWindow(struct Remember **key);
  77. void UpdateWindow(struct Window *win);
  78. void FreePid(struct ProcID *pid);
  79.  
  80. /* Icon data    */
  81. USHORT    chip    BlackHoleGadData1[] = {
  82. /* Plane 0 */
  83.     0x0000,0x01ff,0xf087,0xff00,0x0000,0x0000,0x01ff,0xb807,
  84.     0xfc00,0x0000,0x0000,0x007f,0xbc07,0x7c00,0x0000,0x0000,
  85.     0x000f,0xfc03,0xfc00,0x0000,0x0000,0x0007,0xfe23,0xfc00,
  86.     0x0000,0x0000,0x0001,0xfe03,0xfc00,0x0000,0x0000,0x0220,
  87.     0x7f07,0xfc00,0x0000,0x0000,0x0000,0x7f03,0xfc00,0x0000,
  88.     0x0000,0x0000,0x3f07,0x9800,0x0000,0x0000,0x0000,0x3f03,
  89.     0xf800,0x0000,0x0000,0x7ff0,0x0e07,0xf000,0x0000,0x0000,
  90.     0xfffc,0x0e87,0xf000,0x0000,0x0033,0xeffe,0x0e1f,0xf000,
  91.     0x0000,0x00ff,0xf7ff,0x7d0f,0xc200,0x3000,0x01ff,0xffff,
  92.     0x3c9f,0xc000,0x3000,0x03ff,0xffff,0xabff,0x8000,0x7000,
  93.     0x07ff,0x7e53,0xbeff,0x0000,0xf000,0x0f3e,0x7807,0xf7fe,
  94.     0x0871,0xf000,0x13ff,0xe007,0x5b00,0x00e2,0xe000,0x01f3,
  95.     0xc018,0xffd0,0x01e7,0xc000,0x03a3,0x800d,0x5b60,0x03ff,
  96.     0xe400,0x07c7,0x087f,0xf7c0,0x1f7e,0x7800,0x0780,0x00ff,
  97.     0xbee5,0x3ffc,0xf000,0x0700,0x01f9,0xca7f,0xffff,0xe000,
  98.     0x0600,0x03f8,0x9eff,0xffff,0xc000,0x0600,0x27f4,0x3f7f,
  99.     0xf7fe,0x8000,0x0000,0x0ff0,0xf83f,0xfbfc,0x0000,0x0000,
  100.     0x0ff0,0x781f,0xff80,0x0000,0x0000,0x0fe0,0x7a07,0xff00,
  101.     0x0000,0x0000,0x0fe0,0x7c00,0x0000,0x0000,0x0000,0x1ae0,
  102.     0x7f00,0x0000,0x0000,0x0000,0x3fe0,0x7f00,0x2000,0x0000,
  103.     0x0000,0x3fe0,0x3f84,0x0000,0x0000,0x0000,0x1fc0,0x3fc0,
  104.     0x0000,0x0000,0x0000,0x3fe4,0x3ff0,0x0000,0x0000,0x0000,
  105.     0x3fe0,0x3fff,0x0000,0x0000,0x0000,0x3ff0,0x3eff,0x8000,
  106.     0x0000,0x0000,0x7ff0,0x9dff,0xc000,0x0000,
  107. /* Plane 1 */
  108.     0x0000,0x003c,0xf027,0x9f00,0x0000,0x0000,0x007f,0xf807,
  109.     0xfc00,0x0000,0x0000,0x0057,0xcc43,0x7c00,0x0000,0x0000,
  110.     0x0003,0xcd01,0xfc00,0x0000,0x0000,0x0100,0x0e01,0xec00,
  111.     0x0000,0x0000,0x0000,0x0e01,0xfc00,0x0000,0x0000,0x0080,
  112.     0x0701,0xfc00,0x0000,0x0000,0x0000,0x4101,0xfc00,0x0000,
  113.     0x0000,0x0080,0x2103,0xf800,0x0000,0x0000,0x0002,0x1943,
  114.     0x3800,0x0000,0x0000,0x7ff0,0x2986,0x0000,0x0000,0x0040,
  115.     0xf88e,0x5984,0x1000,0x0000,0x0033,0xf801,0x090c,0xf000,
  116.     0x0000,0x00fe,0xf800,0xfa68,0xc000,0x3000,0x01ff,0xf000,
  117.     0xd3b8,0xd000,0x3000,0x03ff,0xf87e,0x54f0,0x8500,0x7000,
  118.     0x07ff,0x704f,0x41e3,0x0000,0xf000,0x0f3e,0x600f,0x0802,
  119.     0x0071,0xf000,0x03df,0xc000,0xa4fe,0x00f3,0xe000,0x01b3,
  120.     0x805f,0x0071,0x00e6,0xc000,0x03e7,0x8032,0xa4e0,0x01fd,
  121.     0xe000,0x07c7,0x0060,0x0848,0x037a,0x7800,0x0780,0x00cf,
  122.     0xc179,0x07fc,0xf000,0x0700,0x518b,0xb5bf,0x0fff,0xe000,
  123.     0x0600,0x071c,0xe500,0x07ff,0xc000,0x0600,0x0712,0x4f80,
  124.     0x0fbe,0x8000,0x0000,0x0f10,0x9c40,0x0ffc,0x0000,0x0000,
  125.     0x0c10,0x9e38,0x8f81,0x0000,0x0000,0x0902,0x8847,0xff00,
  126.     0x0000,0x0000,0x0f80,0x4c00,0x8000,0x0000,0x0000,0x1fa0,
  127.     0x4700,0x0000,0x0000,0x0000,0x3fc0,0x4100,0x8000,0x0000,
  128.     0x0000,0x3fc0,0x0000,0x0000,0x0000,0x0000,0x1fc0,0x3880,
  129.     0x4000,0x0000,0x0000,0x37c0,0x6180,0x0000,0x0000,0x0000,
  130.     0x3fc1,0x21e3,0x0000,0x0000,0x0000,0x3fd0,0x37ff,0x8000,
  131.     0x0000,0x0000,0x7f82,0x1ffc,0xc000,0x0000,
  132. };
  133.  
  134. USHORT    chip    BlackHoleGadData2[] = {
  135. /* Plane 0 */
  136.     0x000b,0xfc00,0x9ff0,0x7fc0,0x0000,0x0043,0xc090,0x0fe5,
  137.     0x1380,0x0000,0x000f,0x8003,0x0370,0x0300,0x0000,0x0027,
  138.     0x0080,0x0362,0x03c0,0x0000,0x0002,0x0fcc,0x5ee0,0x07c0,
  139.     0x0000,0x000c,0x1ffa,0x4ef0,0x07e0,0x2000,0x0008,0x3efe,
  140.     0x00fc,0x2365,0x0000,0x0018,0x7fff,0xc075,0xa020,0x0000,
  141.     0x403c,0x0f2b,0xc0bc,0x0034,0x0000,0x24de,0x098f,0x44f0,
  142.     0x0019,0x0000,0x817e,0x1387,0xc0e3,0x001c,0x4000,0x0064,
  143.     0x0380,0xc073,0x3a1f,0x0000,0x0000,0xc311,0x63c1,0x9e0e,
  144.     0x0000,0x8080,0x0501,0xe6c1,0xfe06,0x0200,0x0100,0x2a01,
  145.     0xff80,0xfe06,0x4400,0x0180,0x09c1,0xdf00,0x5405,0x0000,
  146.     0x2548,0x0db1,0xfd04,0x2801,0x0800,0x0384,0x97ff,0xd700,
  147.     0xf801,0x0000,0xa200,0x1fd6,0xffe3,0x7201,0x8800,0x2302,
  148.     0x3e8f,0xbbe6,0xf081,0x8800,0x2300,0xbd07,0xfedf,0xf000,
  149.     0x8a00,0x0100,0x7e0b,0xd7ff,0xd243,0x8000,0x2100,0xe843,
  150.     0x7f1b,0x7025,0x4800,0x0140,0xd403,0xf707,0x0003,0x0000,
  151.     0x44c0,0xfe0d,0xff00,0x8801,0x0000,0x80c1,0xfe3f,0x8b01,
  152.     0xc002,0x0200,0x00c1,0xf36c,0x0621,0xa600,0x0000,0x01f1,
  153.     0x9b7c,0x0e03,0x004c,0x0000,0x0471,0x81be,0x0fc3,0x00f9,
  154.     0x0200,0x0131,0x837a,0x8bb7,0x40f6,0x4800,0x0040,0x837e,
  155.     0x07dd,0xe1f8,0x0400,0x0009,0x8a5a,0x01fa,0xfef0,0x0000,
  156.     0x014f,0x907c,0x41ff,0xf860,0x0000,0x080f,0xc03f,0xc4bf,
  157.     0xf0c0,0x0000,0x0007,0xc09a,0xc447,0xe180,0x0000,0x0005,
  158.     0xa01d,0x9004,0x0110,0x0000,0x0007,0xf03f,0xf110,0x0348,
  159.     0x0000,0x0007,0xfebf,0xfa04,0x7f80,0x0000,
  160. /* Plane 1 */
  161.     0x0083,0x3c7f,0x9c70,0x7fc0,0x0000,0x0007,0xce7f,0x8c6a,
  162.     0xd380,0x0000,0x001f,0xbfed,0x003f,0xc200,0x0000,0x0007,
  163.     0x70fc,0x02ef,0xe3c0,0x0000,0x0002,0xcfcc,0x5d8b,0xe7c0,
  164.     0x0000,0x0005,0x9824,0x0a17,0xe7e0,0x6000,0x000b,0x3886,
  165.     0x5e0f,0xd360,0x0000,0x0018,0x7841,0xdf9d,0xf824,0x0000,
  166.     0x003c,0x0e91,0xd684,0x78b4,0x0000,0x23de,0x6889,0x7ab0,
  167.     0x18dc,0x0000,0x416e,0xf374,0x16a1,0x00dd,0x4000,0x0064,
  168.     0xe379,0x9eb7,0x3a5e,0x0000,0x8001,0x634d,0x7981,0x9e4e,
  169.     0x0000,0x8003,0xc574,0xa65f,0xf266,0x0000,0x0023,0xe93d,
  170.     0xbfbf,0x62f6,0x4400,0x09e7,0xe9c5,0x003b,0xf5f1,0x2000,
  171.     0x4767,0xc931,0x01eb,0x39e1,0x0000,0x07f3,0x9e4a,0x291c,
  172.     0x09c1,0x0000,0x8267,0xd430,0x00c3,0x9341,0x9800,0x836d,
  173.     0xa086,0x446e,0x176d,0x8200,0x3305,0xa366,0x009a,0x57cc,
  174.     0x8200,0x0107,0x41fa,0x2827,0xfb9f,0xc000,0x010f,0xbb9b,
  175.     0x0113,0x3fcd,0xc400,0x091e,0x8fb1,0x017f,0x0fcf,0x2000,
  176.     0x44d8,0x81f9,0xfb79,0x0f88,0x0000,0x00c1,0xfebb,0x224d,
  177.     0xcf80,0x0200,0x00c1,0xf36a,0x26dd,0xad00,0x0200,0x00f1,
  178.     0x9be1,0xf93f,0x0e4c,0x0000,0x0571,0x8133,0xba5f,0x1ee9,
  179.     0x0400,0x0071,0xb323,0x3027,0x5cf7,0x8800,0x0040,0xbb53,
  180.     0xf72e,0xe1f8,0x0000,0x0049,0xbe65,0xf144,0x3ef0,0x0000,
  181.     0x000f,0x8f40,0xac82,0x3860,0x0000,0x0c0c,0xdf23,0x40d8,
  182.     0x30c0,0x0000,0x0004,0xcfd5,0xc447,0xe180,0x0000,0x0004,
  183.     0xa7d4,0x905c,0x0120,0x0000,0x0007,0xf7f9,0xf1fd,0x83c0,
  184.     0x0000,0x0007,0xf930,0x9ff8,0x7c80,0x0000,
  185. };
  186.  
  187. struct    Image    BlackHoleGadI1 = {
  188.     0, 0,                /* Top Corner */
  189.     71, 38, 2,            /* Width, Height, Depth */
  190.     &BlackHoleGadData1[0],        /* Image Data */
  191.     0x0003, 0x0000,            /* PlanePick,PlaneOnOff */
  192.     NULL                /* Next Image */
  193. };
  194.  
  195. struct    Image    BlackHoleGadI2 = {
  196.     0, 0,                /* Top Corner */
  197.     71, 38, 2,            /* Width, Height, Depth */
  198.     &BlackHoleGadData2[0],        /* Image Data */
  199.     0x0003, 0x0000,            /* PlanePick,PlaneOnOff */
  200.     NULL                /* Next Image */
  201. };
  202.  
  203. struct Gadget gad =
  204.    {
  205.    NULL,            /* Next Gadget           */
  206.    NULL,NULL,        /* Left Edge, Top Edge       */
  207.    71,38,            /* Width, Height       */
  208.    GFLG_GADGHIMAGE, /* Flags           */
  209.    NULL,            /* Activation  */
  210.    NULL,            /* Gadget Type           */
  211.    (APTR)&BlackHoleGadI1,   /* Gadget Render       */
  212.    (APTR)&BlackHoleGadI2,   /* Select Render       */
  213.    NULL,                    /* Gadget Text           */
  214.    NULL,                    /* Mutual Exclude       */
  215.    NULL,                    /* Special Info           */
  216.    };
  217.  
  218. void _main()
  219. {
  220.     /* Automatic variables  */
  221.     ULONG sig;
  222.     struct DiskObject *dob = NULL;
  223.     struct AppMessage *am;
  224.     struct IntuiMessage *tim, im;
  225.     struct FileInfoBlock *fib = NULL;
  226.     BOOL alive = TRUE;
  227.  
  228.     if (!(IntuitionBase = (void *) OpenLibrary("intuition.library", 37)))
  229.         fatal("Can't open Intuition.library");
  230.  
  231.     if (!(GfxBase = (void *) OpenLibrary("graphics.library", 37)))
  232.         fatal("Can't open graphics.library");
  233.  
  234.     if (!(IconBase = (void *) OpenLibrary("icon.library", 37)))
  235.         fatal("Can't open icon.library");
  236.  
  237.     if (!(WorkbenchBase = (void *) OpenLibrary("workbench.library", 37)))
  238.         fatal("Can't open workbench.library");
  239.  
  240.     fib = (struct FileInfoBlock *) calloc(sizeof(*fib), 1);  /* allocate the FileInfoBlock */
  241.  
  242.     win = MakeWindow(&key);
  243.     aport = (void *) CreatePort(NULL, 0);
  244.     awin = (struct AppWindow *) AddAppWindow(0, win, win, aport, NULL);    /* setup appwindow */
  245.     if (!win || !aport || !awin)
  246.         fatal2("ADC: General Failure.", "Could be Low Memory condition.");
  247.  
  248.     /* setup disk object    */
  249.     dob = (struct DiskObject *) calloc(sizeof(*dob), 1);
  250.     dob->do_Magic = NULL;
  251.     dob->do_Version = NULL;
  252.     dob->do_Gadget = gad;
  253.     dob->do_Type = NULL;
  254.     dob->do_DefaultTool = NULL;
  255.     dob->do_ToolTypes = NULL;
  256.     dob->do_CurrentX = dob->do_CurrentY = NO_ICON_POSITION;
  257.     dob->do_DrawerData = NULL;
  258.     dob->do_ToolWindow = NULL;
  259.     dob->do_StackSize = 0;
  260.  
  261.     if (!(aicon = (struct AppIcon *) AddAppIcon(NULL, NULL, "Application", aport, NULL, dob, TAG_END)))
  262.         fatal("ADC: Could not create AppIcon");
  263.     amenu[amicount++] = (void *) AddAppMenuItem(NULL, "Quit", "Quit AppDemo", aport, NULL);
  264.  
  265.     while (alive)
  266.     {
  267.         sig = (1 << aport->mp_SigBit) |
  268.                 ((win) ? (1 << win->UserPort->mp_SigBit) : NULL);
  269.         sig = Wait(sig);
  270.  
  271.         /* App Messages   */
  272.         if (sig & (1 << aport->mp_SigBit)) /* an app signal */
  273.         {
  274.             while (am = (struct AppMessage *) GetMsg(aport))
  275.             {
  276.                 switch(am->am_Type)
  277.                 {
  278.                 case MTYPE_APPWINDOW:   /* something was dropped in the window  */
  279.                     ProcessIcon(win, am);
  280.                     break;
  281.  
  282.                 case MTYPE_APPICON:     /* icon was double-clicked */
  283.                     if (!am->am_NumArgs) /* Double-Clicked  */
  284.                     {
  285.                         if (!win) /* is our (app) window open? */
  286.                         {
  287.                             if (!(win = MakeWindow(&key)))
  288.                             {
  289.                                 warning("ADC: Cannot open window!");
  290.                                 break;
  291.                             }
  292.  
  293.                             if (!(awin = (struct AppWindow *) AddAppWindow(NULL, NULL, win, aport, NULL)))
  294.                             {
  295.                                 warning("ADC: Cannot make window an AppWindow!");
  296.                                 CloseWindow(win); win = NULL;
  297.                             }
  298.                         }
  299.                         WindowToFront(win);
  300.                         ActivateWindow(win);
  301.                         UpdateWindow(win);
  302.                     }
  303.                     else /* Icons dropped on AppIcon    */
  304.                         ProcessIcon(win, am);
  305.  
  306.                     break;
  307.  
  308.                 case MTYPE_APPMENUITEM: /* menu item was selected */
  309.                     if (!stricmp(am->am_UserData, "quit"))
  310.                         alive = FALSE;
  311.  
  312.                     else /* we have something real */
  313.                     {
  314.                         SystemTags(am->am_UserData, SYS_Input, Open("nil:", MODE_NEWFILE),
  315.                                                     SYS_Output, Open("CON:////Application_Output/CLOSE/AUTO/WAIT", MODE_NEWFILE),
  316.                                                     SYS_Asynch, TRUE,
  317.                                                     NP_StackSize, 30000,    /* Let's be generous    */
  318.                                                     NP_Priority, 0,
  319.                                                     NP_Cli, FALSE,
  320.                                                     TAG_END, NULL);
  321.                     }
  322.                     break;
  323.  
  324.                 default:
  325.                     break;
  326.                 }
  327.                 ReplyMsg(am);
  328.             }
  329.         }
  330.  
  331.         /* Window Messages    */
  332.         if (win && (sig & (1 << win->UserPort->mp_SigBit))) /* an IDCMP signal */
  333.         {
  334.             while (win && (tim = (struct IntuiMessage*) GetMsg(win->UserPort)))
  335.             {
  336.                 im = *tim;
  337.                 ReplyMsg(tim);
  338.                 switch (im.Class)
  339.                 {
  340.                 case CLOSEWINDOW:
  341.                     UpdateWindow(win);
  342.                     RemoveAppWindow(awin); awin = NULL;
  343.                     CloseWindow(win); win = NULL;
  344.                     break;
  345.  
  346.                 case NEWSIZE:
  347.                 case REFRESHWINDOW:
  348.                     UpdateWindow(win);
  349.                     break;
  350.  
  351.                 default:
  352.                     break;
  353.                 }
  354.             }
  355.         }
  356.     }
  357.  
  358.     ShutDown();
  359. }
  360.  
  361. void ProcessIcon(struct Window *win, struct AppMessage *am)
  362. {
  363.     UBYTE buf[256], *name;  /* general work buffer & pointer */
  364.     struct FileInfoBlock *fib = (struct FileInfoBlock *) calloc(1, sizeof(*fib));
  365.     int i;
  366.  
  367.     if (fib)
  368.     {
  369.         for (i = 0; i < am->am_NumArgs; ++i)    /* until list exhausted */
  370.         {
  371.             if (am->am_ArgList[i].wa_Lock)
  372.             {
  373.                 if (Examine(am->am_ArgList[i].wa_Lock, fib))
  374.                 {
  375.                     if (!NameFromLock(am->am_ArgList[i].wa_Lock, buf, sizeof(buf)))
  376.                         fatal("ADC: GetPath failed!!");
  377.  
  378.                     if (buf[strlen(buf)-1] != ':') /* do we need to add a slash?    */
  379.                     {
  380.                         buf[strlen(buf)+1] = NULL;
  381.                         buf[strlen(buf)] = '/';
  382.                     }
  383.  
  384.                     /* append name to path
  385.                     */
  386.                     if (amicount < ASIZE)
  387.                     {
  388.                         appName[amicount] = name = (char*) strdup(am->am_ArgList[i].wa_Name);
  389.                         strcat(buf, am->am_ArgList[i].wa_Name);
  390.                         amenu[amicount] = (struct AppMenu*) AddAppMenuItem(amicount, strdup(buf), name, aport, NULL);
  391.                         ++amicount;
  392.                     }
  393.                     else
  394.                         warning2("ADC: Array Overflow - Cannot add", am->am_ArgList[i].wa_Name);
  395.                 }
  396.                 else
  397.                     warning2("ADCCant find directory for", am->am_ArgList[i].wa_Name);
  398.             }
  399.             else
  400.                 warning2("ADC: Entry Without Lock!!", am->am_ArgList[i].wa_Name);
  401.         }
  402.         UpdateWindow(win);
  403.  
  404.         free(fib);
  405.     }
  406. }
  407.  
  408. UBYTE *BSTRtoSTR(b)
  409. ULONG b;
  410. {
  411.     UBYTE *bstr, *str, *s;
  412.     int c;
  413.  
  414.     bstr = BADDR(b);
  415.     str = s = (UBYTE*) calloc(1, (c = *bstr++) + 1);
  416.     while(c--)
  417.         *s++ = *bstr++;
  418.  
  419.     return str;
  420. }
  421.  
  422. void ShutDown()
  423. {
  424.     int i;
  425.  
  426.     for (i = 0; i < amicount; ++i)
  427.         if (!RemoveAppMenuItem(amenu[i]))
  428.             warning("ADC: RemoveAppMenuItem failed!");
  429.     amicount = 0;
  430.  
  431.     if (aicon)
  432.     {
  433.         if (!RemoveAppIcon(aicon))
  434.             warning("ADC: RemoveAppIcon failed!");
  435.         aicon = NULL;
  436.     }
  437.  
  438.     if (awin)
  439.     {
  440.         if (!RemoveAppWindow(awin))
  441.             warning("ADC: RemoveAppWindow Failed!");
  442.         awin = NULL;
  443.     }
  444.     if (win)
  445.         CloseWindow(win), win = NULL;
  446.  
  447.     if (aport)
  448.         DeletePort(aport), aport = NULL;
  449.  
  450.     FreeRemember(&key, TRUE);
  451.  
  452.     if (GfxBase)        CloseLibrary(GfxBase),       GfxBase = NULL;
  453.     if (IntuitionBase)  CloseLibrary(IntuitionBase), IntuitionBase = NULL;
  454.     if (IconBase)       CloseLibrary(IconBase),      IconBase = NULL;
  455.     if (WorkbenchBase)  CloseLibrary(WorkbenchBase), WorkbenchBase = NULL;
  456.  
  457.     exit(0);
  458. }
  459.  
  460. struct NewWindow newwin = {
  461.     100, 100,   /* LeftEdge, TopEdge */
  462.     300, 150,   /* Width, Height */
  463.     1, 2,       /* DetailPen, BlockPen */
  464.     CLOSEWINDOW | NEWSIZE | MOUSEBUTTONS | VANILLAKEY,  /* IDCMPFlags */
  465.     WINDOWSIZING | WINDOWDRAG | WINDOWCLOSE | WINDOWDEPTH | SMART_REFRESH | GIMMEZEROZERO, /* Flags */
  466.     NULL,       /* FirstGadget */
  467.     NULL,       /* CheckMark */
  468.     NULL,       /* Title */
  469.     NULL,       /* Screen */
  470.     NULL,       /* BitMap */
  471.     50, 50, -1, -1, /* MinWidth, MinHeight, MaxWidth, MaxHeight */
  472.     WBENCHSCREEN    /* Type */
  473.     };
  474.  
  475. struct Window *MakeWindow(key) /* standard window creation */
  476. struct Remember **key;
  477. {
  478.     struct Window *win;
  479.  
  480.     if (win = (struct Window*) OpenWindow(&newwin))
  481.         SetWindowTitles(win, "AppDemo", "Application Launcher by Fred Mitchell");
  482.  
  483.     return win;
  484. }
  485.  
  486. void UpdateWindow(win)  /* display list of programs in window */
  487. struct Window *win;
  488. {
  489.     short height, i;
  490.  
  491.     if (win)
  492.     {
  493.         SetRast(win->RPort, 0);
  494.         SetAPen(win->RPort, 1);
  495.         SetDrMd(win->RPort, JAM1);
  496.         height = win->RPort->Font->tf_YSize + 2;
  497.  
  498.         for (i = 1; i < amicount; ++i)
  499.         {
  500.             Move(win->RPort, 0, height * i);
  501.             Text(win->RPort, appName[i], strlen(appName[i]));
  502.         }
  503.  
  504.         /* update newwindow structure with new size/location    */
  505.         newwin.LeftEdge = win->LeftEdge;
  506.         newwin.TopEdge  = win->TopEdge;
  507.         newwin.Width    = win->Width;
  508.         newwin.Height   = win->Height;
  509.     }
  510. }
  511.  
  512. void FreePid(pid)   /* free the list of ProcessID's */
  513. struct ProcID *pid;
  514. {
  515.     if (pid->nextID)
  516.         FreePid(pid->nextID);
  517.  
  518.     /* free(pid); ...*/
  519. }
  520.  
  521. /* Warning and Fatal Routines   */
  522.  
  523. static int _GetResponse(struct Window *win)
  524. {
  525.     int ret = (int) win;
  526.  
  527.     if ((BOOL) win != 0 && (BOOL) win != 1)
  528.     {
  529.         while ((ret = SysReqHandler(win, NULL, TRUE)) == -2)
  530.             ;
  531.         FreeSysRequest(win);
  532.     }
  533.     return ret;
  534. }
  535.  
  536. void fatal(m)  /* Program bug detected - could be fatal! */
  537. char *m;    /* message */
  538. {
  539.     struct EasyStruct es;
  540.  
  541.     es.es_StructSize = sizeof(es);
  542.     es.es_Flags = NULL;
  543.     es.es_Title = "<FATAL ERROR>";
  544.     es.es_TextFormat = "Fatal Error: %s";
  545.     es.es_GadgetFormat = "OK";
  546.  
  547.     _GetResponse((struct Window*) BuildEasyRequest(NULL, &es, NULL, m));
  548.     ShutDown();
  549. }
  550.  
  551. void fatal2(m, n)  /* Program bug detected - could be fatal! */
  552. char *m, *n;    /* message */
  553. {
  554.     struct EasyStruct es;
  555.  
  556.     es.es_StructSize = sizeof(es);
  557.     es.es_Flags = NULL;
  558.     es.es_Title = "<FATAL ERROR>";
  559.     es.es_TextFormat = "Fatal Error: %s\n%s";
  560.     es.es_GadgetFormat = "OK";
  561.  
  562.     _GetResponse((struct Window*) BuildEasyRequest(NULL, &es, NULL, m, n));
  563.     ShutDown();
  564. }
  565.  
  566. void warning(m) /* Far less serious - non-fatal error */
  567. char *m;    /* message */
  568. {
  569.     struct EasyStruct es;
  570.  
  571.     es.es_StructSize = sizeof(es);
  572.     es.es_Flags = NULL;
  573.     es.es_Title = "Warning";
  574.     es.es_TextFormat = "Error: %s";
  575.     es.es_GadgetFormat = "Continue";
  576.  
  577.     _GetResponse((struct Window*) BuildEasyRequest(NULL, &es, NULL, m));
  578. }
  579.  
  580. void warning2(m, n) /* Far less serious - non-fatal error */
  581. char *m, *n;    /* messages */
  582. {
  583.     struct EasyStruct es;
  584.  
  585.     es.es_StructSize = sizeof(es);
  586.     es.es_Flags = NULL;
  587.     es.es_Title = "Warning";
  588.     es.es_TextFormat = "Error: %s\n%s";
  589.     es.es_GadgetFormat = "Continue";
  590.  
  591.     _GetResponse((struct Window*) BuildEasyRequest(NULL, &es, NULL, m, n));
  592. }
  593.