home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / ARC_LBR / LSTARC.ARC / LSTARC.C next >
Encoding:
C/C++ Source or Header  |  1987-11-14  |  9.5 KB  |  216 lines

  1. /************************************************************************/
  2. /* LSTARC.C - This program gives you a quick and easy display of the    */
  3. /* contents of and .ARC file. It will show you the member name,        */
  4. /* extracted file size, and the creation date. Also displayed is the    */
  5. /* total disk space ALL of the members will take if extracted. And     */
  6. /* the program will tell you which program will be needed to extract    */
  7. /* the members ( ARC or PKXARC).                    */
  8. /*                                    */
  9. /*                        Richard Nichols        */
  10. /*                        CIS : [7134,3607]    */
  11. /* This was edited with TABS set to 8, Using Turbo C version 1.0    */
  12. /*                                    */
  13. /************************************************************************/
  14.  
  15. #include <stdio.h>
  16.  
  17. #define MARK    0x1A    /* This marks the beginning of a header.    */
  18.  
  19. /************************************************************************/
  20. /* We use this array to convert the month from its numeric value    */
  21. /* to one easier on the eye.                         */
  22. /************************************************************************/
  23. char *months[] = {
  24.         "Jan", "Feb", "Mar", "Apr",
  25.         "May", "Jun", "Jul", "Aug",
  26.         "Sep", "Oct", "Nov", "Dec"
  27.         };
  28.  
  29. /************************************************************************/
  30. /* This is the internal member header format used by ARC and PKARC.    */
  31. /************************************************************************/
  32. struct arc_ent {
  33.     char    comp;        /* Compression Type (see do_name)    */
  34.     char    name[13];    /* Filename                */
  35.     long    arc_size;    /* File size in .ARC            */
  36.     unsigned int date;    /* Creation Date for member file    */
  37.     unsigned int time;    /* Creation Time for member file    */
  38.     unsigned int crc;    /* CRC                    */
  39.     long    file_size;    /* Actual File Size when Extracted     */
  40.     }*entry;
  41.  
  42. char fname[64];            /* Full filename (with path)        */
  43. FILE *in_file;            /* File pointer to .ARC file        */
  44.  
  45. int ch;                /* Used when looking for header mark    */
  46. int count   = 0;        /* Number of members found in the .ARC    */
  47. int c_line  = 0;        /* Current line count for screen pause    */
  48. int de_arc  = 0;        /* 0 = ARC, 1 = PKXARC            */
  49. long t_size = 0L;        /* Size of ALL members when extracted    */
  50.  
  51. main(int argc, char *argv[])
  52. {
  53.  
  54.     if(argc < 1)
  55.     {
  56.         printf("Syntax:\n\t%s Filename\n",argv[0]);
  57.         exit(1);
  58.     }
  59.     strcpy(fname, argv[1]);
  60.  
  61. /************************************************************************/
  62. /* Now Check the Filename for an extension. All we care about is the    */
  63. /* '.' if we find one we assume a full filename and if not we add the    */
  64. /* ".ARC" extension. So if you have archives that do not end with the    */
  65. /* standard ".ARC" extension you must enter the entire filename. If it    */
  66. /* does not have an extension the be sure to put a '.' at the end of     */
  67. /* the filename. Also remember you can enter the entire path name if     */
  68. /* you wish (63 characters max).                    */
  69. /************************************************************************/
  70.     if(strchr(fname,'.') == NULL)
  71.         strcat(fname,".ARC");
  72.  
  73. /************************************************************************/
  74. /* Make the filename all Uppercase so the display looks nice.        */
  75. /************************************************************************/
  76.     strupr(fname);
  77.  
  78. /************************************************************************/
  79. /* Try to open the file. If we fail tell the operator and show the     */
  80. /* filename we used (incase the operator entered the wrong drive or    */
  81. /* name) the exit back to DOS.                        */
  82. /************************************************************************/
  83.     if((in_file = fopen(fname,"rb")) == NULL)
  84.     {
  85.         printf("Sorry, could not find %s\n", fname);
  86.         exit(2);
  87.     }
  88.  
  89. /************************************************************************/
  90. /* Now Display the header and get to work!                */
  91. /************************************************************************/
  92.     printf("\nARC Directory for : %-13s",fname);
  93.     printf("\nMember Name    Actual Size    Creation Date");
  94.     while(( ch = fgetc( in_file)) != EOF )
  95.     {
  96.         if(ch == MARK)
  97.             do_name();
  98.     }
  99.     printf("\n       ====    ========");
  100.     printf("\nTotal  %4d    %8ld\n",count, t_size);
  101.  
  102. /************************************************************************/
  103. /* Now tell the operator what program(s) can be used to extract the    */
  104. /* members.                                 */
  105. /************************************************************************/
  106.     if(de_arc)
  107.         printf("You MUST use PKXARC on this Archive.\n");
  108.     else
  109.         printf("You May use ARC or PKXARC on this Archive.\n");
  110.  
  111. /************************************************************************/
  112. /* Close the file and return to DOS.                    */
  113. /************************************************************************/
  114.     fclose(in_file);
  115. }
  116.  
  117. /************************************************************************/
  118. /* After we have found what we think is a valid header mark we come    */
  119. /* here to get the actual information about the file. If the header    */
  120. /* does not contain what ARC and PKARC considers a valid compression    */
  121. /* style flag we return. If we find a valid flag we get the information    */
  122. /* we are going to display and skip to the end of the member.        */
  123. /************************************************************************/
  124. do_name()
  125. {
  126. static int val;
  127. static int month;
  128. static int day;
  129. static int year;
  130. static char s_date[12];
  131.  
  132. /************************************************************************/
  133. /* Read in what we think is the member's header.            */
  134. /************************************************************************/
  135.     val = fread(entry, sizeof( struct arc_ent),1,in_file);    
  136.  
  137. /************************************************************************/
  138. /* Check the entry, if it is not between 1 to 9 then it isn't valid.    */
  139. /*                                    */
  140. /* These are the valid compression types and their meanings. I will not    */
  141. /* go it to a  detailed explaination of each type here.            */
  142. /*                                    */
  143. /*    1 = Old, no compression                                         */
  144. /*    2 = New, no compression                                         */
  145. /*    3 = DLE for repeat chars                                        */
  146. /*    4 = Huffman encoding                                            */
  147. /*    5 = LZ, no CRC                                                  */
  148. /*    6 = LZ with CRC                                                 */
  149. /*    7 = Internal SEA use                                            */
  150. /*    8 = New lz with crc                                             */
  151. /*    9 = PK squashing                                                */
  152. /*                                    */
  153. /************************************************************************/
  154.     if((entry->comp > 9) || (entry->comp < 1))
  155.         return;
  156.  
  157. /************************************************************************/
  158. /* Check to see if ARC or PKARC is needed to de-ARC the Archive.    */
  159. /************************************************************************/
  160.     if(entry->comp == 9)
  161.         de_arc = 1;    /* Signal PKXARC Only            */
  162.  
  163. /************************************************************************/
  164. /* Increment the member count.                        */
  165. /************************************************************************/
  166.     count++;
  167.  
  168. /************************************************************************/
  169. /* Now get the Creation Date. This information is stored in the DOS    */
  170. /* format. So we do Shifting and ANDing to get to the bit fileds we    */
  171. /* want. You could also extract the Time information from the Time    */
  172. /* entry in the structure if you wanted.                */
  173. /************************************************************************/
  174.     day   = entry->date & 0x1F;
  175.     month = (entry->date >>5) &0x0F;
  176.     year  = ((entry->date >> 9) &0x7F) +80;
  177.  
  178. /************************************************************************/
  179. /* Now put the date information into a string to be displayed. This     */
  180. /* information could be combined into the printf line below instead.    */
  181. /************************************************************************/
  182.     sprintf(s_date, "%2d %3s %2d",day, months[month-1], year);
  183.  
  184. /************************************************************************/
  185. /* Don't forget the file size! This is NOT the size of the member, it     */
  186. /* the size of the file AFTER it is extracted from the Archive.        */
  187. /************************************************************************/
  188.     t_size += entry->file_size;
  189.  
  190. /************************************************************************/
  191. /* Now Dispaly the Information using the same display format as ARC.    */
  192. /************************************************************************/
  193.     printf("\n%-13s %9ld\t\t%s", entry->name, entry->file_size, s_date);
  194.  
  195. /************************************************************************/
  196. /* ARC does not pause when displaying the members, but I like to pause    */
  197. /* after a screen full.                         */
  198. /************************************************************************/
  199.     c_line++;
  200.     if(c_line > 23)
  201.     {
  202.         c_line = 0;
  203.         printf("\nPress Any Key for More...");
  204.         getch();
  205.     }
  206.  
  207. /************************************************************************/
  208. /* Since we have displayed the information now we want to skip past the    */
  209. /* actual file. So we tell DOS to do a FAST seek from the current file    */
  210. /* location to the actual end of the file data. This will put us at the    */
  211. /* beginning of the next header (or the end of the file) so we can     */
  212. /* continue working.                            */
  213. /************************************************************************/
  214.     val = fseek(in_file, entry->arc_size, SEEK_CUR);
  215. }
  216.