home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0908.lha / MegaView / source / source.lha / MegaView.c < prev    next >
C/C++ Source or Header  |  1993-08-01  |  23KB  |  616 lines

  1. /**** REVISION HEADER **************************************************\
  2. *                                                                       *
  3. *       Filename            :   MegaView.c                              *
  4. *       Source Rev          :   $VER: MegaView.c 1.03                   *
  5. *       Copyright           :   See documentation                       *
  6. *                                                                       *
  7. *   Revision History:                                                   *
  8. *   Date        Revision    Comment                                     *
  9. *   ---------------------------------------------------------------     *
  10. *   12-Jul-93   1.0         First public release                        *
  11. *   22-Jul-93   1.01        Added REQ commandline switch to allow       *
  12. *                           File Requester from the Shell               *
  13. *   22-Jul-93   1.02        Added 'loop' mode for SELECT button in      *
  14. *                           Popup requester to select more than one     *
  15. *                           file for viewing until cancel is pressed    *
  16. *   30-Jul-93   1.03        File requester is now "multi-select", i.e.  *
  17. *                           you can select more than one file to view   *
  18. *                                                                       *
  19. \***********************************************************************/
  20.  
  21. #include "global.h"
  22.  
  23. struct Library *WhatIsBase;
  24. struct Library *IntuitionBase;
  25. struct Library *WorkbenchBase;
  26. struct Library *IconBase;
  27. struct Library *AslBase;
  28.  
  29. #define REVISION "1.03"
  30. static char *version = "$VER: MegaView " REVISION ;
  31.  
  32. #define CONFIG_TEMPLATE (APTR)"TYPE/K/A,ACTION/K/A"
  33. #define CT_TYPE         0
  34. #define CT_ACTION       1
  35. #define CT_LENGTH       2
  36. LONG ConfigLine[CT_LENGTH];
  37.  
  38. #define COMMAND_TEMPLATE (APTR)"FILE,ICON/S,MENU/S,ICONNAME/K,MENUNAME/K,REQUESTER=REQ/S"
  39. #define CO_FILE         0
  40. #define CO_ICON         1
  41. #define CO_MENU         2
  42. #define CO_ICONNAME     3
  43. #define CO_MENUNAME     4
  44. #define CO_REQ          5
  45. #define CO_LENGTH       6
  46. LONG CommandLine[CO_LENGTH];
  47.  
  48. #define BUFSIZE 512                                                                 
  49. #define ACTIONFILE "s:FileActions"
  50. #define PNAME "MegaView"
  51. #define ABOUT "MegaView V" REVISION "\n⌐ 1993 DIgital DImensions\nVersion " REVISION 
  52.  
  53. char win[256];
  54.  
  55. char pbuf[512];
  56. BOOL wbrun=FALSE;
  57. BOOL IconMode=FALSE, MenuMode=FALSE;
  58. char IconName[50];
  59. char MenuName[50];
  60.  
  61. LONG ix=0,iy=0;
  62.  
  63. #define ICONID 4711L
  64.  
  65. char FileName[256]="";
  66. int NumArgs=0;
  67. struct FileRequester *request=NULL;
  68.  
  69. struct TagItem witags[] = {
  70.     WI_Deep, DEEPTYPE,
  71.     WI_FIB, 0,
  72.     TAG_DONE, 0L
  73. };
  74.  
  75. struct TagItem atags[] = {
  76.     ASL_Hail,       0L,
  77.     ASL_Dir,        0L,
  78.     TAG_DONE,       0L
  79. };
  80.  
  81. struct TagItem atags2[] = {
  82.     ASL_FuncFlags,  FILF_MULTISELECT,
  83.     TAG_DONE,   0L
  84. };
  85.  
  86.  
  87. UWORD MegaViewI1Data[] =
  88. {
  89. /* Plane 0 */
  90.     0x0000,0x0000,0x0000,0x3F80,0x0000,0x0000,0x0000,0x60E0,
  91.     0x0000,0x0000,0x0001,0xF830,0x0000,0x0000,0x001F,0xFF98,
  92.     0x0000,0x0000,0x0020,0x0058,0x0000,0x0000,0x0027,0x9E58,
  93.     0x0AAA,0xAAFE,0xAAA7,0x9E58,0x2822,0xAAEE,0xAAA7,0x9E70,
  94.     0x22A8,0x0000,0x02A0,0x0060,0x2AA8,0x0000,0x03A0,0x0040,
  95.     0x2AA8,0x00E0,0x03A0,0x0040,0x2AA8,0x07F8,0x03A0,0x0040,
  96.     0x2AA8,0x3FF0,0x03A0,0x0040,0x2AA8,0x7FEF,0x03A0,0x0040,
  97.     0x2AA8,0xFFFF,0x03A2,0xAA40,0x2AA8,0x73FE,0x03AA,0xAAC0,
  98.     0x2AA8,0x01DF,0xC3AA,0xAAC0,0x2AA8,0x000F,0xE3AA,0xAC00,
  99.     0x2AA8,0x0000,0x63AA,0xAC00,0x2AA8,0x0000,0x03AA,0xAC00,
  100.     0x2AA8,0x0000,0x03AA,0xAC00,0x2AA7,0xFFFF,0xFFCA,0xAC00,
  101.     0x0AAA,0xBEAA,0xBEAA,0x8C00,0x0000,0x0000,0x0000,0x0C00,
  102.     0x0000,0x0000,0x0000,0x0C00,0x7FFF,0xFFFF,0xFFFF,0xFC00,
  103.     0x0000,0x0000,0x0000,0x0000,
  104. /* Plane 1 */
  105.     0x0000,0x0000,0x0000,0x4000,0x0000,0x0000,0x0000,0x8100,
  106.     0x0000,0x0000,0x0002,0x0040,0x0000,0x0000,0x0000,0x0020,
  107.     0xFFFF,0xFFFF,0xFFDF,0xFFA0,0xD555,0x5555,0x5558,0x61A0,
  108.     0xD000,0x0100,0x0018,0x61A0,0xC7D8,0x0110,0x0018,0x6180,
  109.     0xCC03,0xFFFF,0xFC1F,0xFF80,0xC003,0xFFFF,0xFC1F,0xFF80,
  110.     0xC003,0xFFDF,0xFC1F,0xFF80,0xC003,0xFFE7,0xFC1F,0xFF80,
  111.     0xC003,0xFCCF,0xFC1F,0xFF80,0xC003,0xF19E,0xFC1F,0xFF80,
  112.     0xC003,0xE76C,0xFC1D,0x5580,0xC003,0x8F99,0xFC15,0x5500,
  113.     0xC003,0xFE3F,0xBC15,0x5500,0xC003,0xFFF0,0xDC00,0x1000,
  114.     0xC003,0xFFFF,0x9C00,0x1000,0xC003,0xFFFF,0xFC00,0x1000,
  115.     0xC003,0xFFFF,0xFC00,0x1000,0xC008,0x0000,0x0000,0x1000,
  116.     0xD000,0x4000,0x4000,0x5000,0xD555,0x5555,0x5555,0x5000,
  117.     0xD555,0x5555,0x5555,0x5000,0x8000,0x0000,0x0000,0x0000,
  118.     0x0000,0x0000,0x0000,0x0000,
  119. };
  120.  
  121. struct Image MegaViewI1 =
  122. {
  123.     0, 0,                       /* Upper left corner */
  124.     61, 27, 2,                  /* Width, Height, Depth */
  125.     MegaViewI1Data,             /* Image data */
  126.     0x0003, 0x0000,             /* PlanePick, PlaneOnOff */
  127.     NULL                        /* Next image */
  128. };
  129.  
  130. struct DiskObject MegaView =
  131. {
  132.     WB_DISKMAGIC,               /* Magic Number */
  133.     WB_DISKVERSION,             /* Version */
  134.     {                           /* Embedded Gadget Structure */
  135.         NULL,                   /* Next Gadget Pointer */
  136.         0, 0, 61, 27,           /* Left,Top,Width,Height */
  137.         GADGIMAGE | GADGHCOMP,  /* Flags */
  138.         RELVERIFY,              /* Activation Flags */
  139.         BOOLGADGET,             /* Gadget Type */
  140.         (APTR)&MegaViewI1,      /* Render Image */
  141.         NULL,                   /* Select Image */
  142.         NULL,                   /* Gadget Text */
  143.         NULL,                   /* Mutual Exclude */
  144.         NULL,                   /* Special Info */
  145.         100,                    /* Gadget ID */
  146.         (APTR) 0x0001,          /* User Data (Revision) */
  147.     },
  148.     WBTOOL,                     /* Icon Type */
  149.     NULL,                       /* Default Tool */
  150.     NULL,                       /* Tool Type Array */
  151.     NO_ICON_POSITION,           /* Current X */
  152.     NO_ICON_POSITION,           /* Current Y */
  153.     NULL,                       /* Drawer Structure */
  154.     NULL,                       /* Tool Window */
  155.     4096                                /* Stack Size */
  156. };
  157.  
  158.  
  159. BOOL FileRequest(void) {
  160.  
  161.     static char dir[256] = "\0";
  162.     BOOL result;
  163.  
  164.     NumArgs = 0;
  165.  
  166.     atags[0].ti_Data=(ULONG)"Select file(s) to view...";
  167.     atags[1].ti_Data=(ULONG)dir;
  168.     if (!request) request=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,atags);
  169.  
  170.     if (request==NULL) return FALSE ;
  171.     result = AslRequest(request,atags2);
  172.     if (result==FALSE) return FALSE;
  173.     strcpy(dir,(char *)(request->rf_Dir));
  174.     NumArgs=request->rf_NumArgs;
  175.     if (NumArgs == 0) {
  176.         strncpy(FileName,(char *)(request->rf_Dir),256);
  177.         AddPart((STRPTR)FileName,(STRPTR)request->rf_File,256);
  178.     } else {
  179.         strncpy(FileName,(char *)(request->rf_Dir),256);
  180.     }
  181.     return TRUE;
  182. }
  183.  
  184. long ShowRequest(char *text, char *gads) {
  185.     struct EasyStruct es;
  186.     es.es_StructSize=sizeof(struct EasyStruct);
  187.     es.es_Flags=0;
  188.     es.es_Title=(UBYTE *)PNAME " Request";
  189.     es.es_TextFormat=(UBYTE *)text;
  190.     es.es_GadgetFormat=(UBYTE *)gads;
  191.     return EasyRequestArgs(NULL,&es,NULL,NULL);
  192. }
  193. /* *****************************************************************
  194. void print(char *s) {
  195.     if (wbrun==TRUE && IntuitionBase) ShowRequest(s,"OK");
  196.     else printf("%s\n",s);
  197. }
  198. I replaced this routine with the #define below. Although this looks
  199. _VERY_ similar, the above routine did not run - MegaView got blasted
  200. when this routine was used in workbench mode and produced a whole lot
  201. of ugly but recoverable alerts. If anyone out there examining the source
  202. code sees why this happened, please tell me. I chased this bug
  203. for three days, and finally found out that it had to do with this routine.
  204.  
  205. *** NOTE ***
  206. Now I know! The icon had a stack size of 4096 specified, and that was
  207. WAY TO LOW!!!! If I think that it took me three days to find this out,
  208. all I can do is BITE ME IN THE ASS!!!!!!!!
  209.  
  210.    ***************************************************************** */
  211.  
  212. #define print(s) do { \
  213.     if (wbrun==TRUE && IntuitionBase) ShowRequest(s,"Okay"); \
  214.     else printf("%s\n",s); \
  215.   } while(0)
  216.  
  217. void CloseAll(char *s) {
  218.     if (s) print(s);
  219.     if (request)        FreeAslRequest(request);
  220.     if (WhatIsBase)     CloseLibrary(WhatIsBase);
  221.     if (IntuitionBase)  CloseLibrary(IntuitionBase);
  222.     if (WorkbenchBase)  CloseLibrary(WorkbenchBase);
  223.     if (IconBase)       CloseLibrary(IconBase);
  224.     if (AslBase)        CloseLibrary(AslBase);
  225.     exit(0L);
  226. }
  227.  
  228. void OpenAll(void) {
  229.     strcpy(FileName,"\0");
  230.     WhatIsBase      =   OpenLibrary((APTR)"whatis.library",0L);
  231.     if (!WhatIsBase)    CloseAll("Need whatis.library");
  232.     IntuitionBase   =   OpenLibrary((APTR)"intuition.library",37L);
  233.     if (!IntuitionBase) CloseAll("need intuition library V37");
  234.     WorkbenchBase   =   OpenLibrary((APTR)"workbench.library",37L);
  235.     if (!WorkbenchBase) CloseAll("Need workbench library V37");
  236.     IconBase        =   OpenLibrary((APTR)"icon.library",37L);
  237.     if (!IconBase)      CloseAll("Need icon library V37");
  238.     AslBase         =   OpenLibrary((APTR)"asl.library",37L);
  239.     if (!AslBase)       CloseAll("Need asl library V37");
  240. }
  241.  
  242. BOOL Scan(char *type, APTR buf, ULONG bufsize) {
  243.     BPTR fh=NULL;
  244.     APTR cs;
  245.     int line=0;
  246.     int c=0;
  247.     UBYTE *cur;
  248.     BOOL res=TRUE;
  249.     struct RDArgs *myargs=NULL,*ap;
  250.     fh=Open((APTR) ACTIONFILE,MODE_OLDFILE);
  251.     if (!fh) CloseAll("Missing file " ACTIONFILE);
  252.     cs= AllocVec(BUFSIZE,MEMF_CLEAR|MEMF_PUBLIC);
  253.     if (!cs) {           
  254.         if (fh) Close(fh);
  255.         fh=NULL;
  256.         return FALSE;
  257.     }
  258.     myargs=(struct RDArgs *)AllocDosObject(DOS_RDARGS,TAG_DONE);
  259.     if (!myargs) {
  260.         if (fh) Close(fh);
  261.         fh = NULL;
  262.         FreeVec(cs);
  263.         return FALSE;
  264.     }
  265.     do {
  266.         line++;
  267.         cur=(UBYTE *)FGets(fh,(STRPTR)cs,BUFSIZE);
  268.         if (!cur) {
  269.             res=FALSE;
  270.             break;
  271.         }
  272.         c=0;
  273.         c=strlen(cur);
  274.         if (*cur==';') continue;
  275.         if (*cur=='\n') continue;
  276.         if (cur[c-1]!='\n') {
  277.             print("Missing NEWLINE at end of " ACTIONFILE );
  278.             res=FALSE;
  279.             break;
  280.         }
  281.         myargs->RDA_Flags |= RDAF_NOPROMPT;
  282.         myargs->RDA_Source.CS_Buffer = cs;
  283.         myargs->RDA_Source.CS_Length = c;
  284.         myargs->RDA_Source.CS_CurChr = 0L;
  285.         ap=ReadArgs(CONFIG_TEMPLATE,ConfigLine,myargs);
  286.         if (!ap) {
  287.             res=FALSE;
  288.             Fault(IoErr(),NULL, cs, BUFSIZE);
  289.             sprintf(pbuf,"Parse error in line %ld: %s", line, (char *)cs);
  290.             print(pbuf);
  291.             break;
  292.         }
  293.         if (stricmp(type,(char *)ConfigLine[CT_TYPE])==0) {
  294.             strncpy((char *)buf,(char *)ConfigLine[CT_ACTION],bufsize);
  295.             res=TRUE;
  296.             if (bufsize<strlen((char *)ConfigLine[CT_ACTION])) res=FALSE;
  297.             break;
  298.         }
  299.         FreeArgs(ap);
  300.     } while (1);
  301.     if (fh) Close(fh);
  302.     fh = NULL;
  303.     if (cs) FreeVec(cs);
  304.     if (myargs) FreeDosObject(DOS_RDARGS,myargs);
  305.     return res;
  306. }
  307.  
  308. void HandleFile(char *fname) {
  309.     BOOL bl;
  310.     char cln[512];
  311.     BPTR lock;
  312.     APTR Buffer;
  313.     BPTR window;
  314.     FileType ft;
  315.     struct FileInfoBlock *fib;
  316.     Buffer=AllocVec(BUFSIZE,MEMF_CLEAR);
  317.     if (Buffer) {
  318.         lock=Lock((APTR)fname, SHARED_LOCK);
  319.         if (lock) {
  320.             fib=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,NULL);
  321.             if (fib) {
  322.                 Examine(lock,fib);
  323.                 witags[1].ti_Data=(ULONG)fib;
  324.                 ft=WhatIs(fname,witags);
  325.                 if (CmpFileType(ft,TYPE_UNKNOWNFILETYPE)==0)
  326.                     print("Unknown filetype\0");
  327.                 else {
  328.                     bl=Scan(GetIDString(ft),Buffer,BUFSIZE);
  329.                     if (bl==FALSE) {
  330.                         sprintf(cln,"Error: No ACTION for %s filetype\0",GetIDString(ft));
  331.                         print(cln);
  332.                     } else {
  333.                         sprintf(cln,(char *)Buffer,fname);
  334.                         window=Open((STRPTR)win,MODE_READWRITE);
  335.                         Execute((STRPTR)cln,NULL,window);
  336.                         Close(window);
  337.                     }
  338.                 }
  339.                 FreeDosObject(DOS_FIB,fib);
  340.             } else print("Unable to create FileInfoBlock");
  341.             UnLock(lock);
  342.         } else print("Unable to lock file");
  343.         FreeVec(Buffer);
  344.     } else print("Cannot allocate buffer");
  345. }
  346.  
  347. void SetUpAndHandleIcon(char *IconName) {
  348.     struct DiskObject *dobj;
  349.     struct AppIcon *ai;
  350.     struct MsgPort *port;
  351.     struct AppMessage *msg;
  352.     char fname[512];
  353.     int i;
  354.     BOOL loaded=FALSE;
  355.     BPTR oldlock;
  356.     BOOL running=TRUE;
  357.     BOOL flg=FALSE;
  358.     dobj=GetDiskObject((STRPTR)IconName);
  359.     if (dobj==NULL) dobj=&MegaView;
  360.     else loaded=TRUE;
  361.     if (ix==0) dobj->do_CurrentX=NO_ICON_POSITION; else dobj->do_CurrentX=ix;
  362.     if (iy==0) dobj->do_CurrentY=NO_ICON_POSITION; else dobj->do_CurrentY=iy;
  363.     port=CreatePort(NULL,0L);
  364.     if (port) {
  365.         ai=AddAppIconA(ICONID,0L,(STRPTR)IconName,port,
  366.                 NULL,dobj,NULL);
  367.         if (ai) {
  368.             while (running) {
  369.                 Wait(1<<port->mp_SigBit);
  370.                 while (msg=(struct AppMessage *)GetMsg(port)) {
  371.                     if (msg->am_Type!=MTYPE_APPICON) {
  372.                         ReplyMsg((struct Message *)msg);
  373.                         continue;
  374.                     }
  375.                     if (msg->am_NumArgs==0) {
  376.                         i=ShowRequest(ABOUT,"Quit|Select|Continue");
  377.                         switch(i) {
  378.                         case 0:
  379.                             break;
  380.                         case 1:
  381.                             running=FALSE;
  382.                             break;
  383.                         case 2:
  384.                             flg=TRUE;
  385.                             while (flg==TRUE) {
  386.                                 flg=FileRequest();
  387.                                 if (flg==FALSE) break;
  388.                                 if (NumArgs==0) HandleFile(FileName);
  389.                                 else {
  390.                                     int i;
  391.                                     char buffer[256];                               
  392.                                     for (i=0; i<NumArgs; i++) {
  393.                                         strncpy(buffer,FileName,256);
  394.                                         AddPart((STRPTR)buffer,(STRPTR)(request->rf_ArgList[i].wa_Name),256);
  395.                                         HandleFile(buffer);
  396.                                     }
  397.                                 }
  398.                                 if (flg==TRUE) Delay(1L);
  399.                             }
  400.                             break;
  401.                         }
  402.                     } else {
  403.                         for (i=0; i<msg->am_NumArgs; i++) {
  404.                             strcpy(fname,(char *)(msg->am_ArgList[i].wa_Name));
  405.                             oldlock=CurrentDir(msg->am_ArgList[i].wa_Lock);
  406.                             HandleFile(fname);
  407.                             CurrentDir(oldlock);
  408.                         }
  409.                     }
  410.                     ReplyMsg((struct Message *)msg);
  411.                 }
  412.             }
  413.             while (msg=(struct AppMessage *)GetMsg(port)) {
  414.                 ReplyMsg((struct Message *)msg);
  415.             }
  416.             RemoveAppIcon(ai);
  417.         } else print("Cannot AddAppIcon()");
  418.         DeletePort(port);
  419.     } else print("Cannot CreatePort()");
  420.     if (loaded==TRUE) {
  421.         FreeDiskObject(dobj);
  422.     }
  423. }
  424.  
  425.  
  426. void SetUpAndHandleMenu(char *MenuName) {
  427.     struct AppMenuItem *ai;
  428.     struct MsgPort *port;
  429.     struct AppMessage *msg;
  430.     char fname[512];
  431.     int i;
  432.     BPTR oldlock;
  433.     BOOL running=TRUE;
  434.     BOOL flg=FALSE;
  435.     port=CreatePort(NULL,0L);
  436.     if (port) {
  437.         ai=AddAppMenuItemA(ICONID,0L,(STRPTR)MenuName,port,NULL);
  438.         if (ai) {
  439.             while (running) {
  440.                 Wait(1<<port->mp_SigBit);
  441.                 while (msg=(struct AppMessage *)GetMsg(port)) {
  442.                     if (msg->am_Type!=MTYPE_APPMENUITEM) {
  443.                         ReplyMsg((struct Message *)msg);
  444.                         continue;
  445.                     }
  446.                     if (msg->am_NumArgs==0) {
  447.                         i=ShowRequest(ABOUT,"Quit|Select|Continue");
  448.                         switch(i) {
  449.                         case 0:
  450.                             break;
  451.                         case 1:
  452.                             running=FALSE;
  453.                             break;
  454.                         case 2:
  455.                             flg=TRUE;
  456.                             while (flg==TRUE) {
  457.                                 flg=FileRequest();
  458.                                 if (flg==FALSE) break;
  459.                                 if (NumArgs==0) HandleFile(FileName);
  460.                                 else {
  461.                                     int i;
  462.                                     char buffer[256];                               
  463.                                     for (i=0; i<NumArgs; i++) {
  464.                                         strncpy(buffer,FileName,256);
  465.                                         AddPart((STRPTR)buffer,(STRPTR)(request->rf_ArgList[i].wa_Name),256);
  466.                                         HandleFile(buffer);
  467.                                     }
  468.                                 }
  469.                                 if (flg==TRUE) Delay(1L); /* this is here to fix an optimzer bug in Aztec 5.0 */
  470.                             }
  471.                             break;
  472.                         }
  473.                     } else {
  474.                         for (i=0; i<msg->am_NumArgs; i++) {
  475.                             strcpy(fname,(char *)(msg->am_ArgList[i].wa_Name));
  476.                             oldlock=CurrentDir(msg->am_ArgList[i].wa_Lock);
  477.                             HandleFile(fname);
  478.                             CurrentDir(oldlock);
  479.                         }
  480.                     }
  481.                     ReplyMsg((struct Message *)msg);
  482.                 }
  483.             }
  484.             while (msg=(struct AppMessage *)GetMsg(port)) {
  485.                 ReplyMsg((struct Message *)msg);
  486.             }
  487.             RemoveAppMenuItem(ai);
  488.         } else print("Cannot AddAppMenuItem()");
  489.         DeletePort(port);
  490.     } else print("Cannot CreatePort()");
  491. }
  492.  
  493. void HandleWBStartup(char **argv) {
  494.     int i;
  495.     BPTR oldlock;
  496.     struct WBStartup *wbs;
  497.     char fname[256];
  498.     UBYTE **ta, *s;
  499.     struct DiskObject *dob;
  500.     struct WBArg *wba;
  501.     wbs=(struct WBStartup *)argv;
  502.     wbrun=TRUE;
  503.     wba=wbs->sm_ArgList;
  504.     strcpy(IconName,PNAME);
  505.     strcpy(MenuName,PNAME);
  506.     if (wbs->sm_NumArgs>1) { /* Display Files */
  507.         for (i=1; i<wbs->sm_NumArgs; i++) {
  508.             strcpy(fname,(char *)(wbs->sm_ArgList[i].wa_Name));
  509.             oldlock=CurrentDir(wbs->sm_ArgList[i].wa_Lock);
  510.             HandleFile(fname);
  511.             CurrentDir(oldlock);
  512.         }
  513.     } else { /* Use ToolsTypes */
  514.         if (wba->wa_Name) {
  515.             dob=GetDiskObject((STRPTR)(wba->wa_Name));
  516.             if (dob) {
  517.                 ta = (UBYTE  **)dob->do_ToolTypes;
  518.                 if (s=FindToolType(ta,(UBYTE *)"WINDOW"))   strcpy(win,s);
  519.                 if (s=FindToolType(ta,(UBYTE *)"ICONNAME")) strcpy(IconName,s);
  520.                 if (s=FindToolType(ta,(UBYTE *)"MENUNAME")) strcpy(MenuName,s);
  521.                 if (s=FindToolType(ta,(UBYTE *)"MODE")) {
  522.                     if (MatchToolValue(s,(UBYTE *)"Icon")) IconMode=TRUE;
  523.                     if (MatchToolValue(s,(UBYTE *)"Menu")) MenuMode=TRUE;
  524.                 }
  525.                 if (s=FindToolType(ta,(UBYTE *)"ICON_X")) ix=atoi(s);
  526.                 if (s=FindToolType(ta,(UBYTE *)"ICON_Y")) iy=atoi(s);
  527.                 FreeDiskObject(dob);
  528.                 if (IconMode && MenuMode) {
  529.                     print("Error: Mutual Excluding ToolTypes MENU and ICON set");
  530.                 } else {
  531.                     if (IconMode==TRUE) SetUpAndHandleIcon(IconName);
  532.                     if (MenuMode==TRUE) SetUpAndHandleMenu(MenuName);
  533.                     if (MenuMode==FALSE && IconMode==FALSE) {
  534.                         print("MegaView V" REVISION "\n⌐ 1993 by DIgital DImensions\n"
  535.                               "Usage from Workbench:\nDouble Click icon together with\n"
  536.                               "shift-selected Icons to show them, or use as Default Tool\n"
  537.                               "in Project Icons.\nToolTypes:\n"
  538.                               "MODE=Icon|Menu              Display Icon or Menu (watch case!)\n"
  539.                               "ICONNAME=<string>           Name of icon to use\n"
  540.                               "MENUNAME=<string>           Text for MenuItem\n"
  541.                               "WINDOW=<window string>      stdout window description");
  542.                     }
  543.                 }
  544.             } else print("Error opening Icon");
  545.         } else print("What's that??");
  546.     }
  547. }
  548.  
  549. void main(int argc, char **argv) {
  550.     struct RDArgs *rda;
  551.     char fname[256];
  552.     int i;
  553.     OpenAll();
  554.     if (argc==0) {
  555.         HandleWBStartup(argv);
  556.         CloseAll(NULL);
  557.     }
  558.     rda=ReadArgs(COMMAND_TEMPLATE,CommandLine,NULL);
  559.     if (rda==NULL) {
  560.         PrintFault(IoErr(),NULL);
  561.         CloseAll(NULL);
  562.     }
  563.     FreeArgs(rda);
  564.     if (CommandLine[CO_FILE]) {
  565.         strcpy(fname,(char *)CommandLine[CO_FILE]);
  566.     } else {
  567.         strcpy(fname,"");
  568.     }
  569.     if (CommandLine[CO_REQ]) {
  570.         BOOL flg;
  571.         for (i=0; i<7; i++) {
  572.             Delay(1L);
  573.             if (!request) request=(struct FileRequester *)AllocAslRequest(ASL_FileRequest,atags);
  574.             if (request) break;
  575.         }
  576.         flg=TRUE;
  577.         while (flg==TRUE) {
  578.             flg=FileRequest();
  579.             if (flg==FALSE) break;
  580.             if (NumArgs==0) HandleFile(FileName);
  581.             else {
  582.                 int i;
  583.                 char buffer[256];                               
  584.                 for (i=0; i<NumArgs; i++) {
  585.                     strncpy(buffer,FileName,256);
  586.                     AddPart((STRPTR)buffer,(STRPTR)(request->rf_ArgList[i].wa_Name),256);
  587.                     HandleFile(buffer);
  588.                 }
  589.             }
  590.             if (flg==TRUE) Delay(1L); /* this is here to fix an optimzer bug in Aztec 5.0 */
  591.         }
  592.         CloseAll(NULL);
  593.     }
  594.     if (CommandLine[CO_ICON]) {
  595.         if (CommandLine[CO_ICONNAME]) strncpy(IconName,(char *)CommandLine[CO_ICONNAME],50);
  596.         else strcpy(IconName,"MegaView");
  597.         SetUpAndHandleIcon(IconName);
  598.         CloseAll(NULL);
  599.     }
  600.     if (CommandLine[CO_MENU]) {
  601.         if (CommandLine[CO_MENUNAME]) strncpy(MenuName,(char *)CommandLine[CO_MENUNAME],50);
  602.         else strcpy(MenuName,"MegaView");
  603.         SetUpAndHandleMenu(MenuName);
  604.         CloseAll(NULL);
  605.     }
  606.     if (fname[0]=='\0') {
  607.         if (CommandLine[CO_ICON]==0 || CommandLine[CO_MENU]==0) {
  608.             print("Need a filename");
  609.         }
  610.     } else HandleFile(fname);
  611.     CloseAll(NULL);      
  612. }
  613.  
  614.  
  615.  
  616.