home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Graphics / PPT / ModuleInfo / moduleinfo.c < prev    next >
C/C++ Source or Header  |  1999-11-28  |  11KB  |  438 lines

  1. /*
  2.    This extracts info out of a PPT module and prints it.
  3.  
  4.    BUG: Does not handle all tags.
  5.  
  6.    $Id: moduleinfo.c 1.11 1999/11/28 17:40:33 jj Exp jj $
  7.  */
  8.  
  9. /*--------------------------------------------------------------------------*/
  10.  
  11. /*
  12.  *  This tells which level of PPT calls we're emulating at some level
  13.  *  or another.
  14.  */
  15.  
  16. #define PPT_VERSION_SUPPORTED   6
  17.  
  18. /*
  19.  *  The number of library functions we recognise.
  20.  */
  21.  
  22. #define XLIB_FUNCS 44
  23.  
  24. /*--------------------------------------------------------------------------*/
  25.  
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <dos.h>
  29. #include <stdlib.h>
  30.  
  31. #include <exec/execbase.h>
  32.  
  33. #include <pragmas/pptsupp_pragmas.h>
  34. #include <pragmas/module_pragmas.h>
  35. #include <proto/utility.h>
  36. #include <proto/dos.h>
  37. #include <proto/intuition.h>
  38. #include <proto/graphics.h>
  39. #include <proto/gadtools.h>
  40. #define __USE_SYSBASE
  41. #include <proto/exec.h>
  42. #include <ppt_real.h>
  43.  
  44. /*--------------------------------------------------------------------------*/
  45. /* Compiler stuff and miscallaneous defines */
  46.  
  47. #ifdef _DCC
  48. #define SAVEDS  __geta4
  49. #define ASM
  50. #define REG(x)  __ ## x
  51. #define FAR     __far
  52. #define ALIGNED
  53. #define INLINE
  54. #else
  55. #ifdef __GNUC__
  56. #define SAVEDS  __saveds
  57. #define ASM
  58. #define REG(x)  register
  59. #define GREG(x) __asm( #x )
  60. #define ALIGNED __aligned
  61. #define INLINE  __inline
  62. #define __AMIGADATE__ __DATE__
  63. #else
  64. #define SAVEDS  __saveds
  65. #define ASM     __asm
  66. #define REG(x)  register __ ## x
  67. #define GREG(x)
  68. #define ALIGNED __aligned
  69. #define INLINE  __inline
  70. #endif
  71. #endif
  72.  
  73. #define REGPARAM( reg, type, name ) REG(reg) type name GREG(reg)
  74. #define REGDECL( reg, type ) REG(reg) type GREG(reg)
  75.  
  76. #define EXTSIZE (LIB_VECTSIZE * XLIB_FUNCS + sizeof(EXTBASE))
  77.  
  78. VOID RelExtBase(EXTBASE *);
  79.  
  80. /*--------------------------------------------------------------------------*/
  81.  
  82. typedef enum {
  83.     Effect,
  84.     IOModule
  85. } Type_T;
  86.  
  87. const char verstag[] = "$VER: moduleinfo 1.9 (04.02.97) (C) Janne Jalkanen 1996\0$";
  88.  
  89. EXTBASE *ExtBase = NULL;
  90. struct Library *ModuleBase = NULL;
  91.  
  92. SAVEDS ASM ULONG Dummy(VOID)
  93. {
  94.     printf("Unsupported function called.\n");
  95.     return 0;
  96. }
  97.  
  98. SAVEDS ASM ULONG X_TagData(REG(a0) struct TagItem * list, REG(d0) ULONG tag, REG(a6) EXTBASE * foo)
  99. {
  100.     return (GetTagData(tag, NULL, list));
  101. }
  102.  
  103. SAVEDS ASM ULONG X_SprintFA( REGPARAM(a0,STRPTR,buffer),
  104.                              REGPARAM(a1,STRPTR,format),
  105.                              REGPARAM(a2,APTR,args),
  106.                              REGPARAM(a6,EXTBASE *,PPTBase) )
  107. {
  108.     ULONG res;
  109.     res = vsprintf( buffer, format, args );
  110.     return res;
  111. }
  112.  
  113. APTR ExtLibData[] =
  114. {
  115.     Dummy,                      // NULL, /* LIB_OPEN */
  116.      Dummy,                     // NULL, /* LIB_CLOSE */
  117.      Dummy,                     // NULL, /* LIB_EXPUNGE */
  118.      Dummy,                     // NULL, /* LIB_RESERVED */
  119.      Dummy,                     // NewFrame,
  120.      Dummy,                     // MakeFrame,
  121.      Dummy,                     // InitFrame,
  122.      Dummy,                     // RemFrame,
  123.      Dummy,                     // DupFrame,
  124.  
  125.     Dummy,                      // FindFrame,
  126.  
  127.     Dummy,                      // GetPixel,
  128.      Dummy,                     // NULL, /* BUG: PutPixel */
  129.      Dummy,                     // GetPixelRow,
  130.      Dummy,                     // PutPixelRow,
  131.      Dummy,                     // GetNPixelRows,
  132.      Dummy,                     // PutNPixelRows,
  133.      Dummy,                     // GetBitMapRow,
  134.  
  135.     Dummy,                      // UpdateProgress,
  136.      Dummy,                     // InitProgress,
  137.      Dummy,                     // Progress,
  138.      Dummy,                     // FinishProgress,
  139.      Dummy,                     // ClearProgress,
  140.  
  141.     Dummy,                      // SetErrorCode,
  142.      Dummy,                     // SetErrorMsg,
  143.  
  144.     Dummy,                      // AskReqA,
  145.  
  146.     Dummy,                      // PlanarToChunky,
  147.      Dummy,                     // NULL, /* BUG: ChunkyToPlanar */
  148.  
  149.     Dummy,                      // GetStr_External,
  150.      X_TagData,                 // TagData,
  151.  
  152.     Dummy,                      // StartInput,
  153.      Dummy,                     // StopInput,
  154.  
  155.     Dummy,                      // GetBackgroundColor,
  156.  
  157.     Dummy,                      // GetOptions,
  158.     Dummy,                      // PutOptions,
  159.  
  160.     Dummy,                      // AddExtension,
  161.     Dummy,                      // FindExtension,
  162.     Dummy,                      // RemoveExtension,
  163.  
  164.     /* Start of V4 additions */
  165.  
  166.     Dummy,                      // ObtainPreviewFrameA,
  167.     Dummy,                      // ReleasePreviewFrame,
  168.     Dummy,                      // RenderFrame,       /* 40 */
  169.     Dummy,                      // CopyFrameData,
  170.  
  171.     /* Start of V5 additions */
  172.  
  173.     Dummy,                      // CloseProgress,
  174.     Dummy,                      // SetRexxVariable,
  175.  
  176.     /* Start of V6 additions */
  177.  
  178.     X_SprintFA,                 // SPrintFA,
  179.  
  180.     (APTR) ~ 0                  /* Marks the end of the table for MakeFunctions() */
  181. };
  182.  
  183. /*
  184.    Won't close libs, because uses the SAS/C auto-open feature.
  185.  */
  186. VOID CloseLibBases(EXTBASE * xd)
  187. {
  188.     if (xd->mport)
  189.         DeleteMsgPort(xd->mport);       /* Exec call. Safe to do. */
  190. }
  191.  
  192. /*
  193.    Opens up libraries:
  194.  
  195.    Fakes this by using the auto-open feature.
  196.  */
  197.  
  198. PERROR OpenLibBases(EXTBASE * xd)
  199. {
  200.     xd->lib.lib_Version = PPT_VERSION_SUPPORTED;
  201.     xd->lib.lib_Revision = 0L;
  202.     xd->g = NULL;
  203.     xd->mport = CreateMsgPort();        /* Exec call. Safe to do. */
  204.     xd->lb_Sys = SysBase;
  205.     xd->lb_DOS = DOSBase;
  206.     xd->lb_Utility = UtilityBase;
  207.     xd->lb_Intuition = IntuitionBase;
  208.     xd->lb_BGUI = NULL;
  209.     xd->lb_Gfx = GfxBase;
  210.     xd->lb_GadTools = GadToolsBase;
  211.     xd->lb_Locale = NULL;
  212.  
  213.     return PERR_OK;
  214. }
  215.  
  216. EXTBASE *NewExtBase(VOID)
  217. {
  218.     EXTBASE *ExtBase = NULL;
  219.     APTR realptr;
  220.  
  221.     realptr = malloc(EXTSIZE);
  222.  
  223.     if (realptr) {
  224.         ExtBase = (EXTBASE *) ((ULONG) realptr + (EXTSIZE - sizeof(EXTBASE)));
  225.         bzero(realptr, EXTSIZE);
  226.  
  227.         if (OpenLibBases(ExtBase) != PERR_OK) {
  228.             free(ExtBase);
  229.             return NULL;
  230.         }
  231.         MakeFunctions(ExtBase, ExtLibData, NULL);
  232.     }
  233.     return ExtBase;
  234. }
  235.  
  236. /*
  237.    Use to release ExtBase allocated in NewExtBase()
  238.  */
  239.  
  240. SAVEDS VOID RelExtBase(EXTBASE * xb)
  241. {
  242.     APTR realptr;
  243.  
  244.     CloseLibBases(xb);
  245.     realptr = (APTR) ((ULONG) xb - (EXTSIZE - sizeof(EXTBASE)));
  246.     free(realptr);
  247. }
  248.  
  249. char *DecodeCS(ULONG cs)
  250. {
  251.     static char buf[256];
  252.  
  253.     strcpy(buf, "");
  254.  
  255.     if (cs == ~0) {
  256.         strcpy(buf, "All");
  257.         return buf;
  258.     }
  259.     if (cs & CSF_RGB)
  260.         strcat(buf, "RGB,");
  261.     if (cs & CSF_GRAYLEVEL)
  262.         strcat(buf, "Graylevel,");
  263.     if (cs & CSF_LUT)
  264.         strcat(buf, "Colormapped,");
  265.     if (cs & CSF_ARGB)
  266.         strcat(buf, "ARGB,");
  267.  
  268.     if (cs)
  269.         buf[strlen(buf) - 1] = '\0';    // Remove last comma.
  270.  
  271.     return buf;
  272. }
  273.  
  274. char *DecodeSF(ULONG sf)
  275. {
  276.     char *s;
  277.  
  278.     s = DecodeCS(sf);
  279.  
  280.     if (s[0] == '\0')
  281.         strcpy(s, "<<Saving not supported>>");
  282.  
  283.     return s;
  284. }
  285.  
  286. char *DecodeCPU(ULONG flags)
  287. {
  288.     static char buf[256];
  289.  
  290.     strcpy(buf, "");
  291.  
  292.     if (!flags) {
  293.         strcpy(buf, "generic 68000");
  294.         return buf;
  295.     }
  296.     if (flags & AFF_68010)
  297.         strcat(buf, "68010,");
  298.  
  299.     if (flags & AFF_68020)
  300.         strcat(buf, "68020,");
  301.  
  302.     if (flags & AFF_68030)
  303.         strcat(buf, "68030,");
  304.  
  305.     if (flags & AFF_68040)
  306.         strcat(buf, "68040,");
  307.  
  308.     if (flags & AFF_68060)
  309.         strcat(buf, "68060,");
  310.  
  311.     if (flags & AFF_68881)
  312.         strcat(buf, "68881,");
  313.  
  314.     if (flags & AFF_68882)
  315.         strcat(buf, "68882,");
  316.  
  317.     if (flags & AFF_PPC)
  318.         strcat(buf, "PowerPC,");
  319.  
  320.     buf[strlen(buf) - 1] = '\0';        // Remove last comma.
  321.  
  322.     return buf;
  323. }
  324.  
  325. void ShowInfo(char *name)
  326. {
  327.     char buf[512], *s;
  328.     Type_T type;
  329.  
  330.     s = strrchr(name, '.');
  331.     if (s) {
  332.         if (strcmp(++s, "effect") == 0)
  333.             type = Effect;
  334.         else
  335.             type = IOModule;
  336.     } else {
  337.         printf("Wrong name?!?\n");
  338.         return;
  339.     }
  340.  
  341.     if (ModuleBase = OpenLibrary(name, 0L)) {
  342.         printf("MODULE: %s  (%s)\n", name, (type == Effect) ? "Effect" : "IO Module");
  343.         printf("  Name:                    %s\n", Inquire(PPTX_Name, ExtBase));
  344.         printf("  Version:                 %d.%d\n", ModuleBase->lib_Version, ModuleBase->lib_Revision);
  345.         printf("  CPU Level:               %s\n", DecodeCPU(Inquire(PPTX_CPU, ExtBase)));
  346.  
  347.         strncpy(buf, (STRPTR) Inquire(PPTX_InfoTxt, ExtBase), 511);
  348.         printf("  Infotext:                %s\n", strtok(buf, "\n"));
  349.         while (s = strtok(NULL, "\n"))
  350.             printf("                           %s\n", s);
  351.  
  352.         printf("  Author:                  %s\n", Inquire(PPTX_Author, ExtBase));
  353.         printf("  PPT Revision required:   %d\n", Inquire(PPTX_ReqPPTVersion, ExtBase));
  354.         printf("  OS Version required:     %d\n", Inquire(PPTX_ReqKickVersion, ExtBase));
  355.         s = (char *) Inquire(PPTX_RexxTemplate, ExtBase);
  356.         printf("  REXX arguments:          %s\n", s ? s : "<<REXX not supported>>");
  357.         printf("  Priority:                %d\n", Inquire(PPTX_Priority, ExtBase));
  358.         printf("  GetArgs:                 %s\n", Inquire(PPTX_SupportsGetArgs,ExtBase) ? "supported" : "not supported" );
  359.  
  360.         if (type == IOModule) {
  361.             printf("  Save formats supported:  %s\n",
  362.                    DecodeSF(Inquire(PPTX_ColorSpaces, ExtBase)));
  363.         } else {
  364.             printf("  Colorspaces handled:     %s\n",
  365.                    DecodeCS(Inquire(PPTX_ColorSpaces, ExtBase)));
  366.         }
  367.  
  368.         CloseLibrary(ModuleBase);
  369.     } else {
  370.         printf("%s is not a library!\n", name);
  371.     }
  372. }
  373.  
  374. int main(int argc, char **argv)
  375. {
  376.     int i;
  377.     struct AnchorPath *ap;
  378.     LONG err;
  379.     BOOL quit = FALSE;
  380.  
  381.     if (argc == 0) {
  382.         argc = _WBArgc;
  383.         argv = _WBArgv;
  384.     }
  385.     ap = malloc(sizeof(struct AnchorPath) + MAXPATHLEN);
  386.  
  387.     if (!ap)
  388.         return 20;
  389.  
  390.     if (argc > 1) {
  391.  
  392.         ExtBase = NewExtBase();
  393.  
  394.         for (i = 1; i < argc && !quit; i++) {
  395.  
  396.             bzero(ap, sizeof(struct AnchorPath) + MAXPATHLEN);
  397.  
  398.             ap->ap_Strlen = MAXPATHLEN - 1;
  399.  
  400.             if (0 == (err = MatchFirst(argv[i], ap))) {
  401.                 ap->ap_Flags &= ~(APF_DODIR);   /* No, we don't want dirs */
  402.                 do {
  403.                     /*
  404.                      *  Skip all directories!
  405.                      */
  406.  
  407.                     if (ap->ap_Info.fib_DirEntryType < 0) {
  408.                         ShowInfo(ap->ap_Buf);
  409.                     }
  410.                     /*
  411.                      *  Check for break
  412.                      */
  413.  
  414.                     if (CheckSignal(SIGBREAKF_CTRL_C)) {
  415.                         printf("***BREAK\n");
  416.                         quit = TRUE;
  417.                     }
  418.                 } while (!quit && 0 == (err = MatchNext(ap)));
  419.                 MatchEnd(ap);
  420.             }
  421.             if (err != 0 && err != ERROR_NO_MORE_ENTRIES) {
  422.                 char errbuf[81];
  423.  
  424.                 Fault(err, NULL, errbuf, 80);
  425.                 printf("%s: Error while reading '%s' : %s\n", argv[0], argv[i], errbuf);
  426.                 break;
  427.             }
  428.         }
  429.  
  430.         RelExtBase(ExtBase);
  431.  
  432.     } else {
  433.         printf("Usage: %s [module] [module] ...\n", argv[0]);
  434.     }
  435.  
  436.     free(ap);
  437. }
  438.