home *** CD-ROM | disk | FTP | other *** search
- //
- // ResGrep -- Programm zum nutzen von Mac-Resourcen auf dem Amiga
- //
- // 22.03.1992 Andre geschrieben
- //
-
- #include "resources.h"
- #include "utils.h"
- #include "export.h"
-
- struct IntuitionBase *IntuitionBase = NULL;
- struct GadToolsBase *GadToolsBase = NULL;
- struct AslBase *AslBase = NULL;
- struct IFFParseBase *IFFParseBase = NULL;
-
- struct Screen *theScreen = NULL;
- struct Window *theWindow = NULL;
- APTR VisualInfo = NULL;
- struct Menu *Menus = NULL;
- struct FileRequester *fr = NULL;
- struct MsgPort *up = NULL; // My very own UserPort
-
- list FileList;
- FILE *globalFile;
- bool AutoSave = true;
-
- extern list *conversions;
-
- void freeFileList(void)
- {
- node *n;
-
- while( (n=FileList.remhead())!=NULL )
- delete ((ResFile *)n);
- FileList.closedis();
- }
-
- void CleanUp(void)
- {
- struct Library *ml;
-
- // Es mⁿssen Expliziet die Fenster geschlossen werden
- // da der Destruktor sonst die Libraries ben÷tigt!
- freeFileList();
- if(fr) FreeFileRequest(fr);
- if(Menus) FreeMenus( Menus );
- if(up) DeleteMsgPort(up);
- if(VisualInfo) FreeVisualInfo( VisualInfo );
- if(theScreen) UnlockPubScreen( 0l, theScreen );
-
- if(IntuitionBase) {ml=(struct Library *)IntuitionBase; CloseLibrary(ml); }
- if(GadToolsBase) { ml=(struct Library *)GadToolsBase; CloseLibrary(ml); }
- if(AslBase) { ml=(struct Library *)AslBase; CloseLibrary(ml); }
- if(IFFParseBase) { ml=(struct Library *)IFFParseBase; CloseLibrary(ml); }
- return;
- }
-
-
-
- int main(void)
- {
- node *theNode, *n;
- struct IntuiMessage theIMsg, *imsg;
- int ret;
-
- struct TextAttr topaz8 =
- {
- ( STRPTR )"topaz.font", 8, 0x00, 0x01
- };
-
- struct NewMenu NewMenu[] =
- {
- NM_TITLE, (UBYTE *)"Project", 0l, 0, 0, 0l,
- NM_ITEM, (UBYTE *)"Open...", "O", 0, 0, 0l,
- NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
- NM_ITEM, (UBYTE *)"Print", "P", NM_ITEMDISABLED, 0, 0l,
- NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
- NM_ITEM, (UBYTE *)"Hide", 0l, 0, 0, 0l,
- NM_SUB, (UBYTE *)"Window", 0l, 0, 0, 0l,
- NM_SUB, (UBYTE *)"Child Windows", 0l, 0, 0, 0l,
- NM_SUB, (UBYTE *)"All Windows", 0l, 0, 0, 0l,
- NM_ITEM, (UBYTE *)"Reveal", 0l, 0, 0, 0l,
- NM_SUB, (UBYTE *)"Child Windows", 0l, 0, 0, 0l,
- NM_SUB, (UBYTE *)"All Windows", 0l, 0, 0, 0l,
- NM_ITEM, (UBYTE *)"Close", "K", 0, 0, 0l,
- NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
- NM_ITEM, (UBYTE *)"About...", 0l, 0, 0, 0l,
- NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
- NM_ITEM, (UBYTE *)"Quit ResGrep...", "Q", 0, 0, 0l,
- NM_TITLE, (UBYTE *)"Settings", 0l, 0, 0, 0l,
- NM_ITEM, (UBYTE *)"Autosave Settings?", 0l, CHECKIT|CHECKED, 0, 0l,
- NM_ITEM, (UBYTE *)"Create Icons?", 0l,
- NM_ITEMDISABLED|CHECKIT|CHECKED, 0, 0l,
- NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
- NM_ITEM, (UBYTE *)"Edit Conversions...", "E", 0, 0, 0l,
- NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l,
- NM_ITEM, (UBYTE *)"Load Settings...", 0l, 0, 0, 0l,
- NM_ITEM, (UBYTE *)"Save Settings", 0l, 0, 0, 0l,
- NM_ITEM, (UBYTE *)"Save Settings As...", 0l, 0, 0, 0l,
- NM_END, 0l, 0l, 0, 0l, 0l
- };
-
- // ╓ffne die Intuition-library als erste, damit ich dann wenigstens
- // bei den anderen Libraries Fehler anzeigen kann.
- if( (IntuitionBase=(struct IntuitionBase *)
- OpenLibrary((UBYTE *)"intuition.library",37))==NULL )
- {
- // Was soll ich tun?!?
- // printf("Kann IntuitionLibrary nicht ÷ffnen.\n");
- CleanUp();
- return 2;
- }
- if( (GadToolsBase=(struct GadToolsBase *)
- OpenLibrary((UBYTE *)"gadtools.library",37))==NULL )
- {
- ResError("Can't open 'gadtools.library'.");
- CleanUp();
- return 1;
- }
- if( (AslBase=(struct AslBase *)
- OpenLibrary((UBYTE *)"asl.library",37))==NULL )
- {
- ResError("Can't open 'asl.library'.");
- CleanUp();
- return 3;
- }
- if( (IFFParseBase=(struct IFFParseBase *)
- OpenLibrary((UBYTE *)"iffparse.library",37))==NULL )
- {
- ResError("Can't open 'iffparse.library'.");
- CleanUp();
- return 3;
- }
- if( (fr=(struct FileRequester *)AllocFileRequest())== NULL )
- {
- ResError("Can't alloc file requester.");
- CleanUp();
- return 4;
- }
-
- if ( NOT( theScreen = LockPubScreen( (UBYTE *)"Workbench" )))
- {
- ResError("Can't lock the Workbench Screen.");
- CleanUp();
- return 5;
- }
- if ( NOT( VisualInfo = GetVisualInfo( theScreen, TAG_DONE )))
- {
- ResError("Can't get Visualinfo.");
- CleanUp();
- return 6;
- }
- if ( NOT( Menus = CreateMenus( NewMenu, GTMN_FrontPen, 0l, TAG_DONE )))
- {
- CleanUp();
- return 7;
- }
-
- LayoutMenus( Menus, VisualInfo, GTMN_TextAttr, &topaz8, TAG_DONE );
-
- // Da ich jetzt kein 'echtes' MainWindow mehr habe, mu▀ ich mich
- // selbst um solche Dinge wie MessagePorts kⁿmmern.
- if( (up=CreateMsgPort("RESGREP",0))==NULL )
- {
- ResError("Can't create message port.");
- CleanUp();
- return 8;
- }
-
- initexport();
- loadsettings();
-
- // Das HauptWindow (jetzt das FileWindow) ÷ffnen
- FileList.display(up,Menus,readwrite,"pn",35,7, NewXPos(),NewYPos(),
- "ResGrep - FileList", "ResGrep");
- CoordsUsed();
- theWindow=FileList.getwin();
-
-
- // Open first File.
- {
- ResFile *rf=new ResFile();
-
- if( rf->open()==0 )
- {
- // Das Element einketten (safely!)
- FileList.start_change();
- FileList.addtail(rf);
- FileList.end_change();
- }
- else
- delete rf;
- }
-
- for(;;) { // MainEventLoop
-
- Wait( 1UL<<(unsigned long)(up->mp_SigBit) );
- while( (imsg=GT_GetIMsg(up)) != NULL )
- {
- // Message kopieren und sofort orginale sofort zurⁿckschicken.
- theIMsg=*imsg;
- GT_ReplyIMsg(imsg);
- // Zuerst einmal alle Messages abfangen, die nicht an ein
- // Fenster weitergegeben werden sollen. Dazu zΣhlen z.B. alle
- // Menuauswahlen.
- switch( theIMsg.Class )
- {
- case IDCMP_INTUITICKS:
- break;
- case IDCMP_MENUPICK:
- {
- int MenuNumber=theIMsg.Code;
- struct MenuItem *Item;
-
- while( MenuNumber!=MENUNULL )
- {
- Item=ItemAddress(Menus,MenuNumber);
- switch( MENUNUM(MenuNumber) )
- {
- case 0:
- switch( ITEMNUM(MenuNumber) )
- {
- case 0: // Open...
- {
- ResFile *rf=new ResFile();
-
- if( rf->open()==0 )
- {
- // Das Element einketten (safely!)
- FileList.start_change();
- FileList.addtail(rf);
- FileList.end_change();
- break;
- }
- else
- delete rf;
- }
- break;
- // 1 - BarLab
- case 2: // Print
- ResWarning("Print\nNot implemented yet.");
- break;
- // 3 - BarLab
- case 4: // Hide
- switch( SUBNUM(MenuNumber) )
- {
- case 0: // Hide >> Window
- for(n=FileList.getfirst();
- n->getsucc();n=n->getsucc())
- ((ResFile *)n)->hidewin(&theIMsg);
- break;
- case 1: // Hide >> Child Windows
- {
- struct IntuiMessage *im=&theIMsg;
-
- if( theIMsg.IDCMPWindow==FileList.getwin() )
- im=NULL;
-
- for(n=FileList.getfirst();
- n->getsucc();n=n->getsucc())
- ((ResFile *)n)->hidechild(im);
- }
- break;
- case 2: // Hide >> All Windows
- for(n=FileList.getfirst();n->getsucc();n=n->getsucc())
- ((ResFile *)n)->hidechild(NULL);
- break;
- }
- break;
- case 5: // Reveal
- switch( SUBNUM(MenuNumber) )
- {
- case 0: // Reveal >> Child Windows
- for(n=FileList.getfirst();
- n->getsucc();n=n->getsucc())
- ((ResFile *)n)->revealchild(&theIMsg);
- break;
- case 1: // Reveal >> All Windows
- for(n=FileList.getfirst();
- n->getsucc();n=n->getsucc())
- ((ResFile *)n)->revealchild(NULL);
- break;
- }
- break;
- case 6: // Close
- for(n=FileList.getfirst(); n->getsucc(); n=n->getsucc())
- ((ResFile *)n)->closewin(&theIMsg);
- break;
- // 7 - BarLab
- case 8: // About...
- ResMessage("ResGrep\n"
- "Version 0.2 beta\n"
- "copyright 1992 by Andreas Florath");
- break;
- // 9 - BarLab
- case 10: // Quit...
- CleanUp();
- return 0;
- break;
- default:
- ResError("Fatal:\nUnknown menu item.");
- break;
- }
- break;
- case 1:
- switch( ITEMNUM(MenuNumber) )
- {
- case 0:
- AutoSave = AutoSave ? false : true;
- break;
- case 3:
- editconv();
- if( AutoSave )
- savesettings();
- break;
- case 5:
- loadsettings();
- break;
- case 6:
- savesettings();
- break;
- case 7:
- savesettingsas();
- break;
- default:
- ResError("Fatal:\nUnknown menu item");
- break;
- }
- break;
- default:
- ResError("Fatal:\nUnknown menu");
- break;
- }
- MenuNumber=Item->NextSelect;
- } // End: while( MenuNumber!=MENUNULL ) ...
- } // End: case IDCMP_MENUPICK
- break;
- default:
- {
- node *theNode;
-
- /* printf("Meldung: Class: %08lx Code: %04x\n",
- theIMsg.Class, theIMsg.Code);
- */
-
- // Ist es fⁿr das MainWindow?
- if( theIMsg.IDCMPWindow==FileList.getwin() )
- {
- switch(theIMsg.Class)
- {
- case IDCMP_CLOSEWINDOW:
- theIMsg.IDCMPWindow=NULL;
- CleanUp();
- return 0;
- }
- }
- theNode=FileList.checkdis(&theIMsg);
- if( theIMsg.IDCMPWindow==NULL )
- {
- if( theNode==NULL )
- break;
- ((ResFile *)theNode)->displaywin(up,Menus);
- break;
- }
-
- for(node *n=FileList.getfirst(); n->getsucc(); n=n->getsucc())
- {
- globalFile= ((ResFile *)n)->getfp();
- theNode = ((ResFile *)n)->check(&theIMsg);
- /*
- if( theIMsg.IDCMPWindow==NULL )
- {
- if( theNode==NULL )
- printf("Aber keine Node zurⁿckbekommen\n");
- else
- theNode->print();
- }
- */
- }
- /*
- if( theIMsg.IDCMPWindow!=NULL )
- printf("Keiner konnte damit etwas anfangen.\n");
- */
- }
- break;
- }
- } // End: while( GetIMsg()!=NULL ) ...
-
- } // ForEver - Never
- return 0;
- }
-
-