home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Intuition / boopsi / pubi.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  2.6 KB  |  114 lines

  1.  
  2. /* pubi.c -- :ts=8
  3.  * installation of public image class by
  4.  * program (probably run in background)
  5.  * you type control-C to get this one to
  6.  * try to free its class and exit.
  7.  */
  8.  
  9. /*
  10. Copyright (c) 1989, 1990 Commodore-Amiga, Inc.
  11.  
  12. Executables based on this information may be used in software
  13. for Commodore Amiga computers. All other rights reserved.
  14. This information is provided "as is"; no warranties are made.
  15. All use is at your own risk, and no liability or responsibility
  16. is assumed.
  17. */
  18.  
  19. #include "sysall.h"
  20. #include <dos/dos.h>
  21.  
  22. #define D(x)    x
  23.  
  24. struct  IntuitionBase   *IntuitionBase;
  25. struct  GfxBase         *GfxBase;
  26. struct  Library         *UtilityBase;
  27.  
  28. /* class pointer is an abstract handle, which
  29.  * one never uses for "public" access to a class,
  30.  * but we as class owner can use for private access,
  31.  * or to free the class.
  32.  */
  33. void    *initEmbBClass();
  34. void    *EmbBClass;
  35.  
  36. Object    *NewObject();
  37.  
  38. struct EasyStruct myez = { sizeof (struct EasyStruct), 0,
  39.     "Emboxclass Installer",
  40.     "Cannot remove 'emboxclass'.",
  41.     "Retry|Private|Public",
  42. };
  43.  
  44. main()
  45. {
  46.     openAll();    /* get libraries open    */
  47.  
  48.     /* init the public class    */
  49.     EmbBClass = initEmbBClass();
  50.  
  51.     D( kprintf("class is initialized\n") );
  52.  
  53.     printf("Class initialized, break ^C to terminate.\n");
  54.  
  55.     /* take a shot at removing it when we get a Break signal */
  56.     for( Wait( SIGBREAKF_CTRL_C );; )
  57.     {
  58.         D( kprintf("try to free class\n") );
  59.  
  60.     /* quit if class can be freed    */
  61.     if (  freeEmbBClass( EmbBClass ) )
  62.     {
  63.         D( kprintf("FreeClass succeeded\n") );
  64.         break;
  65.     }
  66.  
  67.     switch ( EasyRequest( NULL, &myez, 0 ) )
  68.     {
  69.     case 1:    /* retry without waiting    */
  70.         D( kprintf("retry free\n") );
  71.         continue;
  72.  
  73.     default:
  74.         D( kprintf("default request return\n") );
  75.     case 0:        /* public: add, and wait    */
  76.         D( kprintf("add class back in\n") );
  77.         AddClass( EmbBClass );
  78.     case 2:        /* private: just go wait some more    */
  79.         break;
  80.     }
  81.  
  82.     D( kprintf("wait for break again\n") );
  83.     Wait( SIGBREAKF_CTRL_C );
  84.    }
  85.  
  86.     cleanup( "all done" );
  87. }
  88.  
  89. cleanup( str )
  90. char    *str;
  91. {
  92.     if (str) printf("%s\n", str);
  93.  
  94.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  95.     if (GfxBase) CloseLibrary(GfxBase);
  96.     if (UtilityBase) CloseLibrary(UtilityBase);
  97.  
  98.     exit (0);
  99. }
  100.  
  101. /* exits via cleanup() if failure    */
  102. openAll()
  103. {
  104.     if (!(UtilityBase=(struct Library *)OpenLibrary("utility.library",36L)))
  105.     { cleanup("no V36 utility library\n"); }
  106.  
  107.     if (!(IntuitionBase = 
  108.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  109.     { cleanup("no V36 intuition library\n"); }
  110.  
  111.     if (!(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 36L)))
  112.     { cleanup("no V36 graphics library\n"); }
  113. }
  114.