home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 634.lha / ppdata_v1.0 / src.LZH / src / ppdata.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-12  |  4.4 KB  |  191 lines

  1. /*
  2. *    ppdata.c
  3. *
  4. *    Initialisation and event-handler for PPData - an intuition front-end
  5. *    for crunch routines in powerpacker.library.
  6. *
  7. *    Martin W.Scott, 4/92.
  8. */
  9. #include <exec/types.h>
  10. #include <intuition/intuition.h>
  11. #include <libraries/asl.h>
  12. #include <libraries/ppbase.h>
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #include <proto/graphics.h>
  16. #include <proto/intuition.h>
  17.  
  18. #include "display.h"        /* menu numbers, wintexts */
  19. #include "prefs.h"        /* ppdata preferences definition */
  20. #include "messages.h"        /* prototypes for message routines */
  21. #include "crunch.h"        /* prototypes for file operations */
  22.  
  23. /* cback.o declarations */
  24. #ifndef DEBUG
  25. long _stack = 4000L;
  26. char *_procname = "PPData v1.0";
  27. long _priority = 0;
  28. long _BackGroundIO = 1;
  29. extern BPTR _Backstdout;
  30. #endif
  31.  
  32. /* function prototypes */
  33. static BOOL OpenLibs(void);
  34. static void CloseLibs(void), ProcessIDCMP(struct MsgPort *);
  35. static ULONG MenuPick(UWORD);
  36. void _main(char *);
  37.  
  38. /* global pointers */
  39. char version_str[] = "$VER: PPData v1.0\nby Martin W.Scott\n(Compiled : " __DATE__ ")";
  40. #define ABOUT_MESSAGE &version_str[6]
  41.  
  42. struct IntuitionBase *IntuitionBase;
  43. struct GfxBase *GfxBase;
  44. struct AslBase *AslBase;
  45. struct Library *GadToolsBase;
  46. struct PPBase *PPBase;
  47.  
  48.  
  49. static void CloseLibs()        /* close opened libraries */
  50. {
  51.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  52.     if (GfxBase) CloseLibrary(GfxBase);
  53.     if (AslBase) CloseLibrary(AslBase);
  54.     if (GadToolsBase) CloseLibrary(GadToolsBase);
  55.     if (PPBase) CloseLibrary(PPBase);
  56. }
  57.  
  58.  
  59. static BOOL OpenLibs()            /* open necessary libraries */
  60. {
  61.     if ((IntuitionBase = (void *)OpenLibrary("intuition.library", 37L)) &&
  62.         (GfxBase = (void *)OpenLibrary("graphics.library", 0L)) &&
  63.         (AslBase = (void *)OpenLibrary(AslName, 37L)) &&
  64.         (GadToolsBase = OpenLibrary("gadtools.library", 37L)) &&
  65.         (PPBase = (void *)OpenLibrary(PPNAME, PPVERSION)))
  66.         return TRUE;
  67.  
  68.     CloseLibs();
  69.     return FALSE;
  70. }
  71.  
  72.  
  73. static ULONG ProcessMenuPick(UWORD num)
  74. {
  75.     struct MenuItem *item;        /* next item from extended-select */
  76.     UWORD subnum;
  77.  
  78.     while (num != MENUNULL)
  79.     {
  80.         switch (MENUNUM(num))
  81.         {
  82.         case PROJECT:
  83.             switch (ITEMNUM(num))
  84.             {
  85.             case LOAD:    LoadRequest(); break;
  86.             case SAVE:    SaveRequest(); break;
  87.             case BATCH:    BatchRequest(); break;
  88.             case DELETE:    DeleteRequest(); break;
  89.             case ABOUT:    Message(ABOUT_MESSAGE); break;
  90.             case QUIT:    return CLOSEWINDOW;
  91.             }
  92.             break;
  93.         case PREFS:
  94.             subnum = SUBNUM(num);
  95.  
  96.             switch (ITEMNUM(num))
  97.             {
  98.             case COLOR:    prefs.color = subnum; break;
  99.             case EFFICIENCY:prefs.efficiency = subnum; break;
  100.             case SPEEDUP:    prefs.speedup = subnum; break;
  101.             case SUFFIX:    prefs.suffix ^= 1;
  102.                     break;
  103.             case OVERWRITE: prefs.overwrite ^= 1;
  104.                     break;
  105.             case SAVEPREFS:    SavePrefs(); break;
  106.             }
  107.             break;
  108.         case CONTROL:
  109.             prefs.control =  ITEMNUM(num);
  110.             break;
  111.  
  112.         } /* switch MENUNUM */
  113.  
  114.         item = ItemAddress(mainmenu, num);
  115.         num = item->NextSelect;
  116.  
  117.     } /* while */
  118.  
  119.     return MENUPICK;    /* normal menu choice (not quit) */
  120. }
  121.  
  122.  
  123. static void ProcessIDCMP(struct MsgPort *mp)    /* handle window input */
  124. {
  125.     struct IntuiMessage *msg;        /* our message */
  126.     ULONG class;                /* message class */
  127.     UWORD menunum;                /* menu-number */
  128.  
  129.     for (;;)    /* until closewindow */
  130.     {
  131.         Wait (1 << mp->mp_SigBit);    /* wait for next message */
  132.  
  133.         while (msg = (struct IntuiMessage *)GetMsg(mp))
  134.         {
  135.             class = msg->Class;
  136.             menunum = msg->Code;
  137.             ReplyMsg((struct Message *)msg);  /* reply asap */
  138.  
  139.             if (class == MENUPICK)
  140.                 class = ProcessMenuPick(menunum);
  141.  
  142.             if (class == CLOSEWINDOW)
  143.                 if (IsBufferSaved() ||
  144.                     Confirm("Work is unsaved.\nReally exit?"))
  145.                     return;
  146.         } /* while */
  147.  
  148.     } /* for */
  149. }
  150.  
  151.  
  152. void _main(char *args)    /* ppdata: intuition interface for (de)crunching files */
  153. {
  154.     if (OpenLibs())
  155.     {
  156.         InitMessages();        /* set up message routines */
  157.  
  158.         if (OpenDisplay())        /* open window etc. */
  159.         {
  160.             if (InitCrunch())    /* alloc asl requester etc. */
  161.             {
  162.                 if (AllocPPDataMenus())
  163.                 {
  164.                     LoadPrefs();
  165.                     SetPPDataMenu(MAINMENU);
  166. #ifndef DEBUG    /* cpr doesn't like cback.o */
  167.                     Close(_Backstdout);
  168.                     _Backstdout = NULL;
  169. #endif
  170.                     ProcessIDCMP(window->UserPort);
  171.                     SetMenuStrip(window, NULL);
  172.                     FreePPDataMenus();
  173.                 }
  174.                 else Message("Can't create menus");
  175.                     
  176.                 FinishCrunch();
  177.             }
  178.             else Message("Can't initialize data");
  179.  
  180.             CloseDisplay();
  181.         }
  182.         else Message("Can't open display");
  183.  
  184.         CloseLibs();
  185.     }
  186.     else PutStr("Can't open libraries\n");
  187. #ifndef DEBUG
  188.     if (_Backstdout) Close(_Backstdout);
  189. #endif
  190. } /* _main */
  191.