home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / grafic / cyberblanker / source-code / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-05  |  6.9 KB  |  259 lines

  1.  
  2.    /***********************************************************************
  3.    *                                                                      *
  4.    *                            COPYRIGHTS                                *
  5.    *                                                                      *
  6.    *   Copyright (c) 1990  Commodore-Amiga, Inc.  All Rights Reserved.    *
  7.    *   This file was modified by © Zinneberg-Soft.                        *
  8.    ***********************************************************************/
  9.  
  10. /*
  11.  * main.c -- Skeleton program for a typical Commodities application.
  12.  */
  13. #include "local.h"
  14.  
  15. struct IntuitionBase *IntuitionBase = NULL;
  16. struct Library       *CxBase        = NULL;
  17. struct GfxBase       *GfxBase       = NULL;
  18. struct Library       *GadToolsBase  = NULL;
  19. struct Library       *IconBase      = NULL;
  20. struct Library       *CyberGfxBase  = NULL;
  21.  
  22.   
  23. char     **ttypes;
  24.  
  25.  
  26. /* these globals are the connection between the main program
  27.  * loop and the two message handling routines
  28.  */
  29.  
  30. struct MsgPort *cxport   = NULL; /* commodities messages here      */
  31. ULONG          cxsigflag = 0;    /* signal for above               */
  32.  
  33.  
  34. struct MsgPort *iport    = NULL; /* Intuition IDCMP messages here   */
  35. ULONG          isigflag  = 0;    /* signal for above                */
  36.  
  37. #if CSIGNAL
  38. LONG           csignal   = -1L;
  39. struct Task    *maintask = NULL;
  40. #endif
  41. ULONG          csigflag  = 0L;
  42.  
  43. VOID main(int,char **);
  44. VOID main( argc, argv )
  45. int  argc;
  46. char **argv;
  47. {
  48.    ULONG    sigrcvd;
  49.    struct   Message    *msg;
  50.    W( char  *str; )
  51.  
  52.    CxBase       =                        OpenLibrary("commodities.library",40L);
  53.    DOSBase      =(struct DosLibrary *)   OpenLibrary("dos.library",40L);
  54.    IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",40L);
  55.    GfxBase      =(struct GfxBase *)      OpenLibrary("graphics.library",40L);
  56.    GadToolsBase =                        OpenLibrary("gadtools.library",40L);
  57.    IconBase     =                        OpenLibrary("icon.library",40L);
  58.    CyberGfxBase =               OpenLibrary("cybergraphics.library",40L);
  59.  
  60.  
  61. if ( ! ( IntuitionBase ) )
  62.    {
  63.  
  64.        ErrorF ("Can't open intuition.library 40L.");
  65.       terminate();
  66.    }
  67.  
  68. if ( ! ( CxBase ) )
  69.    {
  70.  
  71.        ErrorF ("Can't open commodities.library 40L.");
  72.       terminate();
  73.    }
  74.  
  75. if ( ! ( GfxBase ) )
  76.    {
  77.  
  78.        ErrorF ("Can't open graphics.library 40L.");
  79.       terminate();
  80.    }
  81.  
  82. if ( ! ( DOSBase  ) )
  83.    {
  84.  
  85.        ErrorF ("Can't open dos.library 40L.");
  86.       terminate();
  87.    }
  88.  
  89. if ( ! ( GadToolsBase ) )
  90.    {
  91.  
  92.        ErrorF ("Can't open gadtools.library 40L.");
  93.       terminate();
  94.    }
  95.  
  96. if ( ! ( IconBase ) )
  97.    {
  98.  
  99.        ErrorF ("Can't open icon.library 40L.");
  100.       terminate();
  101.    }
  102.  
  103. if ( ! ( CyberGfxBase ) )
  104.    {
  105.  
  106.        ErrorF ("Can't open cybergraphics.library 40L.");
  107.       terminate();
  108.    }
  109.  
  110. #if CSIGNAL
  111.    if((csignal = AllocSignal(-1L))==-1)
  112.    {
  113.       D1( kprintf("main.c: main() Failed to get custom signal\n") );
  114.       terminate();
  115.    }
  116.    csigflag = 1L <<csignal;
  117.    maintask=FindTask(0L);
  118. #endif
  119.  
  120.    /* commodities support library function to find argv or tooltypes   */
  121.    ttypes = ArgArrayInit( argc, argv );
  122.    D1(
  123.       {
  124.          int xx=0;
  125.  
  126.          while(ttypes[xx])
  127.          {
  128.             printf("ttypes[0x%lx]=%s\n",xx,ttypes[xx]);
  129.             xx++;
  130.          }
  131.       }
  132.    )
  133.  
  134.    if ( ! setupCX( ttypes ) )
  135.    {
  136.       D1( kprintf("main.c: main() setupCX failed\n") );
  137.       terminate();
  138.    }
  139.    W(
  140.       str = ArgString( ttypes, POP_ON_START_TOOL_TYPE,CX_DEFAULT_POP_ON_START);
  141.       if(strcmpi(str,"yes")==0)
  142.          setupWindow();         /* will try to setup iport      */
  143.       D1( kprintf("main.c: main() After setupWindow\n") );
  144.    )
  145.  
  146.    for (;;)            /* exit by calling terminate   */
  147.    {
  148.       /* handling two ports:
  149.        * either will wake us up;
  150.        * simple approach often works.
  151.        */
  152.       D1( kprintf("main.c: main() Waiting for a signal\n") );
  153.       sigrcvd = Wait ( SIGBREAKF_CTRL_C | isigflag | cxsigflag | csigflag );
  154.       D1( kprintf("main.c: main() Recieved a signal\n") );
  155.  
  156.       /* commodities convention: easy to kill   */
  157.       if ( sigrcvd & SIGBREAKF_CTRL_C )
  158.       {
  159.          D1( kprintf("main.c: main() Recieved a SIGBREAKF_CTRL_C\n") );
  160.          terminate();
  161.       }
  162.  
  163. #if CSIGNAL
  164.       if ( sigrcvd & csigflag )
  165.       {
  166.          D1( kprintf("main.c: main() Recieved a Custom Signal\n") );
  167.          handleCustomSignal();
  168.       }
  169. #endif
  170.  
  171.       while(cxport && (msg=GetMsg(cxport)))
  172.          handleCxMsg(msg);
  173.       W(
  174.          while(iport && (msg=(struct Message *)GT_GetIMsg(iport)))
  175.             handleIMsg((struct IntuiMessage *)msg);
  176.       )
  177.    }
  178.  
  179. }
  180. /****i* Blank.ld/terminate() ******************************************
  181. *
  182. *   NAME
  183. *        terminate -- Cleanup all resources and exit the program.
  184. *
  185. *   SYNOPSIS
  186. *        terminate()
  187. *
  188. *        VOID terminate(VOID);
  189. *
  190. *   FUNCTION
  191. *        This function performs all the necessary cleanup for the
  192. *        commodity and calls exit() to return control to the OS.
  193. *        No matter how the program exits this should be the last function
  194. *        called.
  195. *
  196. *   INPUTS
  197. *        None.
  198. *
  199. *   RESULT
  200. *        All resources are freed and the program exits.
  201. *
  202. *   EXAMPLE
  203. *        if(!AllocWindow())
  204. *           terminate();
  205. *
  206. *   NOTES
  207. *        This function must be set up so that it can be called at any
  208. *        time regardless of the current state of the program.
  209. *
  210. *   BUGS
  211. *
  212. *   SEE ALSO
  213. *        shutdownCX();
  214. *        shutdownWindow();
  215. *
  216. *****************************************************************************
  217. *
  218. */
  219. VOID terminate()
  220. {
  221.    D1( kprintf("main.c: terminate() enter\n") );
  222.  
  223.    shutdownCX();
  224.    D1( kprintf("main.c: terminate(), after shutdownCX()\n") );
  225.  
  226.    W(
  227.       shutdownWindow();
  228.       D1( kprintf("main.c: terminate(), after shutdownWindow()\n") );
  229.    )
  230.  
  231.    ArgArrayDone();    /* cx_supp.lib function   */
  232.    D1( kprintf("main.c: terminate(), after ArgArrayDone()\n") );
  233.  
  234. #if CSIGNAL
  235.    if(csignal != -1) FreeSignal(csignal);
  236.    D1( kprintf("main.c: terminate(), after FreeSignal()()\n") );
  237. #endif
  238.  
  239.    D1( kprintf("main.c: terminate() CxBase        = %lx\n",CxBase) );
  240.    D1( kprintf("main.c: terminate() IntuitionBase = %lx\n",IntuitionBase) );
  241.    D1( kprintf("main.c: terminate() GfxBase       = %lx\n",GfxBase) );
  242.    D1( kprintf("main.c: terminate() DOSBase       = %lx\n",DOSBase) );
  243.    D1( kprintf("main.c: terminate() GadToolsBase  = %lx\n",GadToolsBase) );
  244.    D1( kprintf("main.c: terminate() IconBase      = %lx\n",IconBase) );
  245.    D1( kprintf("main.c: terminate() CyberGfxBase  = %lx\n",CyberGfxBase) );
  246.  
  247.    if(CxBase)        CloseLibrary(CxBase);
  248.    if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  249.    if(GfxBase)       CloseLibrary((struct Library *)GfxBase);
  250.    if(DOSBase)       CloseLibrary((struct Library *)DOSBase);
  251.    if(GadToolsBase)  CloseLibrary(GadToolsBase);
  252.    if(IconBase)      CloseLibrary(IconBase);
  253.    if(CyberGfxBase)  CloseLibrary((struct Library *)CyberGfxBase);
  254.  
  255.    D1( kprintf("main.c: terminate(), after CloseLibrarys()\n") );
  256.   
  257.    exit(0);
  258. }
  259.