home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Cruncher / ulib4271.lha / UnpackLib / For_Programmers_Only / Programmers_Tools / Examples / unpLibInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-15  |  3.5 KB  |  127 lines

  1. /*************************************************************************
  2. *                              unpLibInfo                                *
  3. *                                                                        *
  4. * This program will show which crunchers the library installed supports. *
  5. *                                                                        *
  6. *************************************************************************/
  7.  
  8. // First we include a lot of things
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #include <exec/types.h>
  15. #include <dos/rdargs.h>
  16. #include <libraries/unpack.h>
  17.  
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <proto/unpack.h>
  21.  
  22. // Global Variables
  23. struct Library *UnpackBase;
  24. struct UnpackInfo *cinfo=NULL;
  25. struct RDArgs *rda=NULL;
  26.  
  27.  
  28. #ifdef LATTICE
  29. void __regargs _CXBRK(void)               // Catch CTRL-C Handling
  30. {
  31.   fprintf(stderr,"*** User breaked\n");   // Print out break message
  32.   upFreeCInfo(cinfo);                     // and clean up after us
  33.   CloseLibrary(UnpackBase);
  34.   FreeArgs(rda);
  35.   exit(0);                                // then we exit our program.
  36. }
  37. #endif
  38.  
  39.  
  40. // Main program
  41. void main (void)
  42. {
  43. extern struct ExecBase *SysBase;
  44.  
  45. LONG   arguments[1] = {0};
  46. struct NumberStruct *unpnumber;
  47. struct UnpListStruct *unplist;
  48. char *name;
  49. int j,k;
  50. int i=0;
  51.  
  52.  
  53.   if( ((struct Library*) DOSBase)->lib_Version < 37 )
  54.   {
  55.       fprintf(stderr,"unpLibInfo requires at least Kickstart 2.04!\n");
  56.       exit(0);
  57.   }
  58.  
  59.   if (rda = ReadArgs("MORE/S",arguments,NULL))
  60.   {
  61.     if (UnpackBase = OpenLibrary("unpack.library",42L))
  62.     {
  63.       if (cinfo = upAllocCInfo())
  64.       {
  65.         printf("unpLibInfo 1.0 (2/10-1995) by Thomas Neumann\n\n");
  66.  
  67.         unpnumber = upNewUnpackNum();
  68.         printf("Contents of unpack.library %d.%d (types: %d, total: %d)\n\n",
  69.                 unpnumber->ns_Version, unpnumber->ns_Revision,
  70.                 unpnumber->ns_Types, unpnumber->ns_Unpackers);
  71.  
  72.         if (arguments[0] == 0)
  73.         {
  74.         // This method is the old one. This will only print out the
  75.         // names of the decrunchers.
  76.  
  77.           printf("%s\n",upUnpackList(cinfo));
  78.           while (name = upUnpackListNext(cinfo))
  79.             printf("%s\n",name);
  80.         }
  81.         else
  82.         {
  83.         // Well, here we have a new function from version 42. This
  84.         // function will return some more informations about the
  85.         // decrunchers.
  86.  
  87.         printf("Name                                                 |Number|TypeNum|Type\n");
  88.         printf("-----------------------------------------------------+------+-------+----\n");
  89.  
  90.         while (unplist = upGetUnpacker(cinfo, i++))
  91.         {
  92.           printf("%s",unplist->ul_Name);
  93.           if ((k = 53-strlen(unplist->ul_Name)) < 0)
  94.             k=1;
  95.  
  96.           for (j=0;j<k;j++)
  97.             printf(" ");
  98.  
  99.           printf("| %4d | %5d |",unplist->ul_CrunchNum, unplist->ul_TypeNum);
  100.  
  101.           switch (unplist->ul_Type)
  102.           {
  103.             case 1: printf("Archive");break;
  104.             case 2: printf("Data");break;
  105.             case 3: printf("Object");break;
  106.             case 5: printf("Track");break;
  107.             case 6: printf("Address");break;
  108.           }
  109.  
  110.           if (unplist->ul_Flags && (1<<ULFB_Encrypted))
  111.             printf("!Encrypted");
  112.           printf("\n");
  113.         }
  114.         }
  115.         upFreeCInfo(cinfo);
  116.       }
  117.       CloseLibrary(UnpackBase);
  118.     }
  119.     else
  120.       fprintf(stderr,"You need unpack.library version 42 or higher\n");
  121.  
  122.   FreeArgs(rda);
  123.   }
  124.   else
  125.     PrintFault(IoErr(),NULL);
  126. }
  127.