home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the DOOM Gurus / TricksOfTheDoomGurus.iso / bonus / linux / waddir / waddir.c < prev    next >
C/C++ Source or Header  |  1994-07-12  |  2KB  |  57 lines

  1.  
  2. /* This module lists the directory of a wadfile to stdout. */
  3.  
  4. #include    <stdio.h>
  5. #include    <ctype.h>
  6. #include    "doomdefs.h"
  7. #include    "directory.h"
  8.  
  9. #define EM_END    "BLOCKMAP"    /* The last entry in a level resource list */
  10.  
  11. int waddir(int fd)
  12. {
  13.     dir_entry entry;
  14.     char dosdir[32]={'\0'};
  15.     char entryname[32];
  16.  
  17.     if ( set_directory(fd) < 0 ) {
  18.         fprintf(stderr, "Can't find the directory entries.\n");
  19.         return(-1);
  20.     }
  21.  
  22.     /* Print out the WADDIR.EXE header */
  23.     printf("# DOOM WAD FILE DIRECTORY LISTING\n");
  24.     printf("# LINES STARTING WITH # ARE IGNORED\n");
  25.     printf("# EACH LINE CONTAINS DOSFILE WADFILE SIZE\n");
  26.     printf("# THIS FILE CAN BE USED TO UNPACK/PACK WAD FILES\n");
  27.     printf("# DO NOT CHANGE THE ORDER OF THESE LINES!!!!\n");
  28.     printf("# HOWEVER, DELETION IS OKAY\n");
  29.  
  30.     /* Dump the directory listing */
  31.     while ( read(fd, (char *)&entry, ENTRY_SIZE) == ENTRY_SIZE ) {
  32.         /* Null terminate the name */
  33.         entry.name[8]='\0';
  34.         
  35.         sprintf(entryname, "%s%c", 
  36.             entry.name, ((entry.res_len == 0) ? '\\' : ' '));
  37.  
  38.         /* Print it out */
  39.         printf("%s%-20s %-20s %d\n", dosdir, entryname, entryname,
  40.                                 entry.res_len);
  41.  
  42.         /* See if we are at the start of an E?M? entry */
  43.         if ( entryname[0] == 'E' && isdigit(entryname[1]) &&
  44.              entryname[2] == 'M' && isdigit(entryname[1]) )
  45.             strcpy(dosdir, entryname);
  46.  
  47.         /* See if we are at the end of an E?M? entry */
  48.         if ( strcasecmp(EM_END, entry.name) == 0 )
  49.             dosdir[0]='\0';
  50.  
  51.         if ( strcasecmp(WADDIR_END, entry.name) == 0 )
  52.             break;
  53.     }
  54.     return(0);
  55. }
  56.  
  57.