home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / devcon / sanfrancisco_1989 / sf-devcon89.1 / commodities / aztec / popup / demomain.c < prev    next >
C/C++ Source or Header  |  1992-08-27  |  2KB  |  112 lines

  1. /* demomain.c -- demonstration of Commodities popup application */
  2.  
  3.  
  4. /*
  5. Copyright (c) 1987, 1988, 1989 Jim Mackraz and I&I Computing.
  6.  
  7. Executables based on this information may be used in software
  8. for Commodore Amiga computers.  All other rights reserved.
  9. This information is provided "as is"; no warranties are made.
  10. All use is at your own risk, and no liability or responsibility
  11. is assumed.
  12. */
  13.  
  14. #include "sysall.h"
  15.  
  16. #include "cx/cxfunctions.h"
  17.  
  18. #define D(x)    ;
  19. /* #define printf    kprintf */
  20.  
  21. /* for development purposes    */
  22. #ifndef LIBNAME
  23. #define LIBNAME "commodities.library"
  24. #endif
  25.  
  26. #define CXLIBNAME LIBNAME
  27. #define CXLIBVERS (0)
  28.  
  29. struct Library    *IntuitionBase = NULL;
  30. struct Library    *CxBase = NULL;
  31.  
  32. /* these globals are the connection between the main program
  33.  * loop and the two message handling routines
  34.  */
  35.  
  36. struct MsgPort    *cxport = NULL;    /* commodities messages here        */
  37. ULONG            cxsigflag = 0;    /* signal for above                    */
  38.  
  39. struct MsgPort    *iport = NULL;    /* Intuition IDCMP messages here    */
  40. ULONG            isigflag = 0;    /* signal for above                    */
  41.  
  42. main( argc, argv )
  43. char    **argv;
  44. {
  45.     char    **ttypes;
  46.     ULONG    sigrcvd;
  47.     struct Message    *msg;
  48.     struct Library    *openLibrary();
  49.  
  50.     IntuitionBase = openLibrary( "intuition.library", 33 );
  51.     CxBase = openLibrary( CXLIBNAME, CXLIBVERS );
  52.  
  53.     D( printf(" opening cx: %s, %d\n", CXLIBNAME, CXLIBVERS ) );
  54.  
  55.     if ( ! ( IntuitionBase && CxBase ) ) terminate();
  56.  
  57.     /* commodities support library function to find argv or tooltypes    */
  58.     ttypes = ArgArrayInit( argc, argv );
  59.  
  60.     if ( ! setupCX( ttypes ) )
  61.     {
  62.         D( printf(" setupCX failed, terminating\n") );
  63.         terminate();
  64.     }
  65.  
  66.     setupWindow();            /* will try to setup iport        */
  67.  
  68.     for (;;)                /* exit by calling terminate    */
  69.     {
  70.         /* handling two ports:
  71.          * either will wake us up;
  72.          * simple approach often works.
  73.          */
  74.         sigrcvd = Wait ( SIGBREAKF_CTRL_E | isigflag | cxsigflag );
  75.  
  76.         /* commodities convention: easy to kill    */
  77.         if ( sigrcvd & SIGBREAKF_CTRL_E ) terminate();
  78.  
  79.         while ( cxport && (msg = GetMsg( cxport )) ) handleCxMsg( msg );
  80.         while ( iport && (msg = GetMsg( iport )) ) handleIMsg( msg );
  81.     }
  82.  
  83. }
  84.  
  85. terminate()
  86. {
  87.     shutdownCX();
  88.     shutdownWindow();
  89.  
  90.     ArgArrayDone();     /* cx_supp.lib function    */
  91.  
  92.     closeLibrary( CxBase );
  93.     closeLibrary( IntuitionBase );
  94.  
  95.     exit();
  96. }
  97.  
  98. /*
  99.  * might want to call an alert or something
  100.  */
  101. struct Library    *openLibrary( name, version )
  102. char    *name;
  103. {
  104.     return ( OpenLibrary( name, (LONG) version ) );
  105. }
  106.  
  107. closeLibrary( lib )
  108. struct Library    *lib;
  109. {
  110.     if ( lib ) CloseLibrary( lib );
  111. }
  112.