home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / utility / resgrep0.lzh / ResGrep / src / resgrep.cc < prev    next >
C/C++ Source or Header  |  1992-04-13  |  10KB  |  393 lines

  1. //
  2. // ResGrep -- Programm zum nutzen von Mac-Resourcen auf dem Amiga
  3. //
  4. // 22.03.1992 Andre    geschrieben
  5. //
  6.  
  7. #include "resources.h"
  8. #include "utils.h"
  9. #include "export.h"
  10.  
  11. struct IntuitionBase *IntuitionBase = NULL;
  12. struct GadToolsBase  *GadToolsBase  = NULL;
  13. struct AslBase         *AslBase        = NULL;
  14. struct IFFParseBase  *IFFParseBase  = NULL;
  15.  
  16. struct Screen         *theScreen     = NULL;
  17. struct Window         *theWindow     = NULL;
  18. APTR              VisualInfo    = NULL;
  19. struct Menu         *Menus        = NULL;
  20. struct FileRequester *fr        = NULL;
  21. struct MsgPort         *up        = NULL;  // My very own UserPort
  22.  
  23. list              FileList;
  24. FILE             *globalFile;
  25. bool              AutoSave = true;
  26.  
  27. extern list *conversions;
  28.  
  29. void freeFileList(void)
  30. {
  31.    node *n;
  32.  
  33.    while( (n=FileList.remhead())!=NULL )
  34.       delete ((ResFile *)n);
  35.    FileList.closedis();
  36. }
  37.  
  38. void CleanUp(void)
  39. {
  40.    struct Library *ml;
  41.  
  42.    // Es mⁿssen Expliziet die Fenster geschlossen werden
  43.    // da der Destruktor sonst die Libraries ben÷tigt!
  44.    freeFileList();
  45.    if(fr)         FreeFileRequest(fr);
  46.    if(Menus)      FreeMenus( Menus );
  47.    if(up)         DeleteMsgPort(up);
  48.    if(VisualInfo) FreeVisualInfo( VisualInfo );
  49.    if(theScreen)  UnlockPubScreen( 0l, theScreen );
  50.  
  51.    if(IntuitionBase) {ml=(struct Library *)IntuitionBase; CloseLibrary(ml); }
  52.    if(GadToolsBase)  { ml=(struct Library *)GadToolsBase; CloseLibrary(ml); }
  53.    if(AslBase)  { ml=(struct Library *)AslBase; CloseLibrary(ml); }
  54.    if(IFFParseBase)  { ml=(struct Library *)IFFParseBase; CloseLibrary(ml); }
  55.    return;
  56. }
  57.  
  58.  
  59.  
  60. int main(void)
  61. {
  62.    node         *theNode, *n;
  63.    struct IntuiMessage     theIMsg, *imsg;
  64.    int             ret;
  65.  
  66.    struct TextAttr topaz8 =
  67.    {
  68.       ( STRPTR )"topaz.font", 8, 0x00, 0x01
  69.    };
  70.  
  71.    struct NewMenu NewMenu[] =
  72.    {
  73.       NM_TITLE, (UBYTE *)"Project", 0l, 0, 0, 0l,
  74.       NM_ITEM, (UBYTE *)"Open...", "O", 0, 0, 0l,
  75.       NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
  76.       NM_ITEM, (UBYTE *)"Print", "P", NM_ITEMDISABLED, 0, 0l,
  77.       NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
  78.       NM_ITEM, (UBYTE *)"Hide", 0l, 0, 0, 0l,
  79.       NM_SUB, (UBYTE *)"Window", 0l, 0, 0, 0l,
  80.       NM_SUB, (UBYTE *)"Child Windows", 0l, 0, 0, 0l,
  81.       NM_SUB, (UBYTE *)"All Windows", 0l, 0, 0, 0l,
  82.       NM_ITEM, (UBYTE *)"Reveal", 0l, 0, 0, 0l,
  83.       NM_SUB, (UBYTE *)"Child Windows", 0l, 0, 0, 0l,
  84.       NM_SUB, (UBYTE *)"All Windows", 0l, 0, 0, 0l,
  85.       NM_ITEM, (UBYTE *)"Close", "K", 0, 0, 0l,
  86.       NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
  87.       NM_ITEM, (UBYTE *)"About...", 0l, 0, 0, 0l,
  88.       NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
  89.       NM_ITEM, (UBYTE *)"Quit ResGrep...", "Q", 0, 0, 0l,
  90.       NM_TITLE, (UBYTE *)"Settings", 0l, 0, 0, 0l,
  91.       NM_ITEM, (UBYTE *)"Autosave Settings?", 0l, CHECKIT|CHECKED, 0, 0l,
  92.       NM_ITEM, (UBYTE *)"Create Icons?", 0l,
  93.        NM_ITEMDISABLED|CHECKIT|CHECKED, 0, 0l,
  94.       NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
  95.       NM_ITEM, (UBYTE *)"Edit Conversions...", "E", 0, 0, 0l,
  96.       NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
  97.       NM_ITEM, (UBYTE *)"Load Settings...", 0l, 0, 0, 0l,
  98.       NM_ITEM, (UBYTE *)"Save Settings", 0l, 0, 0, 0l,
  99.       NM_ITEM, (UBYTE *)"Save Settings As...", 0l, 0, 0, 0l,
  100.       NM_END, 0l, 0l, 0, 0l, 0l
  101.    };
  102.  
  103.    // ╓ffne die Intuition-library als erste, damit ich dann wenigstens
  104.    // bei den anderen Libraries Fehler anzeigen kann.
  105.    if( (IntuitionBase=(struct IntuitionBase *)
  106.     OpenLibrary((UBYTE *)"intuition.library",37))==NULL )
  107.    {
  108.       // Was soll ich tun?!?
  109.       // printf("Kann IntuitionLibrary nicht ÷ffnen.\n");
  110.       CleanUp();
  111.       return 2;
  112.    }
  113.    if( (GadToolsBase=(struct GadToolsBase *)
  114.     OpenLibrary((UBYTE *)"gadtools.library",37))==NULL )
  115.    {
  116.       ResError("Can't open 'gadtools.library'.");
  117.       CleanUp();
  118.       return 1;
  119.    }
  120.    if( (AslBase=(struct AslBase *)
  121.     OpenLibrary((UBYTE *)"asl.library",37))==NULL )
  122.    {
  123.       ResError("Can't open 'asl.library'.");
  124.       CleanUp();
  125.       return 3;
  126.    }
  127.    if( (IFFParseBase=(struct IFFParseBase *)
  128.     OpenLibrary((UBYTE *)"iffparse.library",37))==NULL )
  129.    {
  130.       ResError("Can't open 'iffparse.library'.");
  131.       CleanUp();
  132.       return 3;
  133.    }
  134.    if( (fr=(struct FileRequester *)AllocFileRequest())== NULL )
  135.    {
  136.       ResError("Can't alloc file requester.");
  137.       CleanUp();
  138.       return 4;
  139.    }
  140.  
  141.    if ( NOT( theScreen = LockPubScreen( (UBYTE *)"Workbench" )))
  142.    {
  143.       ResError("Can't lock the Workbench Screen.");
  144.       CleanUp();
  145.       return 5;
  146.    }
  147.    if ( NOT( VisualInfo = GetVisualInfo( theScreen, TAG_DONE )))
  148.    {
  149.       ResError("Can't get Visualinfo.");
  150.       CleanUp();
  151.       return 6;
  152.    }
  153.    if ( NOT( Menus = CreateMenus( NewMenu, GTMN_FrontPen, 0l, TAG_DONE )))
  154.    {
  155.       CleanUp();
  156.       return 7;
  157.    }
  158.  
  159.    LayoutMenus( Menus, VisualInfo, GTMN_TextAttr, &topaz8, TAG_DONE );
  160.  
  161.    // Da ich jetzt kein 'echtes' MainWindow mehr habe, mu▀ ich mich
  162.    // selbst um solche Dinge wie MessagePorts kⁿmmern.
  163.    if( (up=CreateMsgPort("RESGREP",0))==NULL )
  164.    {
  165.       ResError("Can't create message port.");
  166.       CleanUp();
  167.       return 8;
  168.    }
  169.  
  170.    initexport();
  171.    loadsettings();
  172.  
  173.    // Das HauptWindow (jetzt das FileWindow) ÷ffnen
  174.    FileList.display(up,Menus,readwrite,"pn",35,7, NewXPos(),NewYPos(),
  175.             "ResGrep - FileList", "ResGrep");
  176.    CoordsUsed();
  177.    theWindow=FileList.getwin();
  178.  
  179.  
  180.    // Open first File.
  181.    {
  182.       ResFile *rf=new ResFile();
  183.  
  184.       if( rf->open()==0 )
  185.       {
  186.      // Das Element einketten (safely!)
  187.      FileList.start_change();
  188.      FileList.addtail(rf);
  189.      FileList.end_change();
  190.       }
  191.       else
  192.      delete rf;
  193.    }
  194.  
  195.    for(;;) {      // MainEventLoop
  196.  
  197.    Wait( 1UL<<(unsigned long)(up->mp_SigBit) );
  198.    while( (imsg=GT_GetIMsg(up)) != NULL )
  199.    {
  200.       // Message kopieren und sofort orginale sofort zurⁿckschicken.
  201.       theIMsg=*imsg;
  202.       GT_ReplyIMsg(imsg);
  203.       // Zuerst einmal alle Messages abfangen, die nicht an ein
  204.       // Fenster weitergegeben werden sollen. Dazu zΣhlen z.B. alle
  205.       // Menuauswahlen.
  206.       switch( theIMsg.Class )
  207.       {
  208.        case IDCMP_INTUITICKS:
  209.      break;
  210.        case IDCMP_MENUPICK:
  211.      {
  212.         int MenuNumber=theIMsg.Code;
  213.         struct MenuItem *Item;
  214.  
  215.         while( MenuNumber!=MENUNULL )
  216.         {
  217.            Item=ItemAddress(Menus,MenuNumber);
  218.            switch( MENUNUM(MenuNumber) )
  219.            {
  220.         case 0:
  221.           switch( ITEMNUM(MenuNumber) )
  222.           {
  223.            case 0:        // Open...
  224.              {
  225.             ResFile *rf=new ResFile();
  226.  
  227.             if( rf->open()==0 )
  228.             {
  229.                // Das Element einketten (safely!)
  230.                FileList.start_change();
  231.                FileList.addtail(rf);
  232.                FileList.end_change();
  233.                break;
  234.             }
  235.             else
  236.                delete rf;
  237.              }
  238.              break;
  239.                     // 1 - BarLab
  240.            case 2:        // Print
  241.              ResWarning("Print\nNot implemented yet.");
  242.              break;
  243.                     // 3 - BarLab
  244.            case 4:        // Hide
  245.              switch( SUBNUM(MenuNumber) )
  246.              {
  247.               case 0:        // Hide >>    Window
  248.             for(n=FileList.getfirst();
  249.                 n->getsucc();n=n->getsucc())
  250.                ((ResFile *)n)->hidewin(&theIMsg);
  251.             break;
  252.               case 1:        // Hide >>    Child Windows
  253.             {
  254.                struct IntuiMessage *im=&theIMsg;
  255.  
  256.                if( theIMsg.IDCMPWindow==FileList.getwin() )
  257.                   im=NULL;
  258.  
  259.                for(n=FileList.getfirst();
  260.                    n->getsucc();n=n->getsucc())
  261.                   ((ResFile *)n)->hidechild(im);
  262.             }
  263.             break;
  264.               case 2:        // Hide >>    All Windows
  265.             for(n=FileList.getfirst();n->getsucc();n=n->getsucc())
  266.                ((ResFile *)n)->hidechild(NULL);
  267.             break;
  268.              }
  269.              break;
  270.            case 5:        // Reveal
  271.              switch( SUBNUM(MenuNumber) )
  272.              {
  273.               case 0:        // Reveal >>  Child Windows
  274.             for(n=FileList.getfirst();
  275.                 n->getsucc();n=n->getsucc())
  276.                ((ResFile *)n)->revealchild(&theIMsg);
  277.             break;
  278.               case 1:        // Reveal >>  All Windows
  279.             for(n=FileList.getfirst();
  280.                 n->getsucc();n=n->getsucc())
  281.                ((ResFile *)n)->revealchild(NULL);
  282.             break;
  283.              }
  284.              break;
  285.            case 6:        // Close
  286.              for(n=FileList.getfirst(); n->getsucc(); n=n->getsucc())
  287.             ((ResFile *)n)->closewin(&theIMsg);
  288.              break;
  289.                     // 7 - BarLab
  290.            case 8:        // About...
  291.              ResMessage("ResGrep\n"
  292.                 "Version 0.2 beta\n"
  293.                 "copyright 1992 by Andreas Florath");
  294.              break;
  295.                     // 9 - BarLab
  296.            case 10:        // Quit...
  297.              CleanUp();
  298.              return 0;
  299.              break;
  300.            default:
  301.              ResError("Fatal:\nUnknown menu item.");
  302.              break;
  303.           }
  304.           break;
  305.         case 1:
  306.           switch( ITEMNUM(MenuNumber) )
  307.           {
  308.            case 0:
  309.              AutoSave = AutoSave ? false : true;
  310.              break;
  311.            case 3:
  312.              editconv();
  313.              if( AutoSave )
  314.             savesettings();
  315.              break;
  316.            case 5:
  317.              loadsettings();
  318.              break;
  319.            case 6:
  320.              savesettings();
  321.              break;
  322.            case 7:
  323.              savesettingsas();
  324.              break;
  325.            default:
  326.              ResError("Fatal:\nUnknown menu item");
  327.              break;
  328.           }
  329.           break;
  330.         default:
  331.           ResError("Fatal:\nUnknown menu");
  332.           break;
  333.            }
  334.            MenuNumber=Item->NextSelect;
  335.         } // End: while( MenuNumber!=MENUNULL ) ...
  336.      } // End: case IDCMP_MENUPICK
  337.      break;
  338.        default:
  339.      {
  340.         node *theNode;
  341.  
  342. /*          printf("Meldung: Class: %08lx   Code: %04x\n",
  343.            theIMsg.Class, theIMsg.Code);
  344. */
  345.  
  346.         // Ist es fⁿr das MainWindow?
  347.         if( theIMsg.IDCMPWindow==FileList.getwin() )
  348.         {
  349.            switch(theIMsg.Class)
  350.            {
  351.         case IDCMP_CLOSEWINDOW:
  352.           theIMsg.IDCMPWindow=NULL;
  353.           CleanUp();
  354.           return 0;
  355.            }
  356.         }
  357.         theNode=FileList.checkdis(&theIMsg);
  358.         if( theIMsg.IDCMPWindow==NULL )
  359.         {
  360.            if( theNode==NULL )
  361.           break;
  362.            ((ResFile *)theNode)->displaywin(up,Menus);
  363.            break;
  364.         }
  365.  
  366.         for(node *n=FileList.getfirst(); n->getsucc(); n=n->getsucc())
  367.         {
  368.            globalFile= ((ResFile *)n)->getfp();
  369.            theNode = ((ResFile *)n)->check(&theIMsg);
  370. /*
  371.            if( theIMsg.IDCMPWindow==NULL )
  372.            {
  373.           if( theNode==NULL )
  374.              printf("Aber keine Node zurⁿckbekommen\n");
  375.           else
  376.              theNode->print();
  377.            }
  378. */
  379.         }
  380. /*
  381.         if( theIMsg.IDCMPWindow!=NULL )
  382.            printf("Keiner konnte damit etwas anfangen.\n");
  383. */
  384.      }
  385.        break;
  386.       }
  387.    } // End: while( GetIMsg()!=NULL ) ...
  388.  
  389.    } // ForEver - Never
  390.    return 0;
  391. }
  392.  
  393.