home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / testzip.zip / testzip.c < prev    next >
C/C++ Source or Header  |  1997-07-23  |  25KB  |  720 lines

  1. /*****************************************************************
  2.  * Testzip version 1.13                                          *
  3.  * Test zip file integrity, Nuke Bad Zips                        *
  4.  * Also prints a list of what it deleted in optional logfile.    *
  5.  *                                                               *
  6.  * Programmer: Madman, with suggestions from Pantera             *
  7.  * Date: 12/6/96     Version 1.0                                 *
  8.  *                                                               *
  9.  * Modified by: Jeff Hamilton, hjeffrey@wam.umd.edu              *
  10.  * Date: 12/8/96     Version 1.01                                *
  11.  * Date: 12/12/96    Version 1.02                                *
  12.  * Date: 12/13/96    Version 1.03                                *
  13.  * Date: 12/15/96    Version 1.04                                *
  14.  * Date: 1/5/97      Version 1.1                                 *
  15.  *                                                               *
  16.  * Queue functions by John Dowdal (queue.c and queue.h)          *
  17.  *                                                               *
  18.  * See the readme.txt included with this source code for more    *
  19.  * information, and instructions for compiling and using this    *
  20.  * program.                                                      *
  21.  *                                                               *
  22.  * Disclaimer:   DISCLAIM THIS!!!!                               *
  23.  * This program and source code are distributed as is.  There is *
  24.  * NO guarantee that it will work on all systems.  Please test   *
  25.  * it out before using.  The programmers take no responsibilty   *
  26.  * for lost or damaged files, or any other problems that use of  *
  27.  * this software might cause.                                    *
  28.  *                                                               *
  29.  * Bug Reports:                                                  *
  30.  * If you find a bug, please e-mail a description of your        *
  31.  * operating system, what the bug does, and how to reproduce it  *
  32.  * to hjeffrey@wam.umd.edu  I will make every effort to find and *
  33.  * correct the bug.                                              *
  34.  *****************************************************************/
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <ctype.h>
  40. #include <unistd.h>
  41. #include <sys/types.h>
  42. #include <sys/stat.h>
  43. #include <dirent.h>
  44. #include "queue.h"
  45. #include "testzip.h"
  46.  
  47. #ifdef OS2
  48. #include <os2.h>
  49. #include "which2.h"
  50. #endif
  51.  
  52. FILE *outfile;
  53. config testzipcfg;
  54.  
  55. int main(int argc, char *argv[]) {
  56.    #ifdef OS2
  57.    if (_osmode != OS2_MODE) {
  58.       fprintf(stderr, "This program cannot be run in DOS mode.\n");
  59.       exit(1);
  60.    }
  61.    #endif
  62.  
  63.    load_config_defaults();
  64.    read_config();
  65.    read_options(&argc, argv);
  66.  
  67.    fprintf(stdout, "\nTestZip Version %s\n\n", TZ_VERSION);
  68.  
  69.    open_log();
  70.  
  71.    check_a_command();
  72.  
  73.    if (testzipcfg.recursive) {
  74.       recursive_check();
  75.    } else {
  76.       single_check();
  77.    }
  78.  
  79.    print_totals();
  80.  
  81.    if (testzipcfg.loglevel > 0)
  82.       fclose(outfile);
  83.  
  84.    return 0;
  85. }
  86.  
  87. void recursive_check() {
  88.    char tempdir[MAXPATHLEN];
  89.    short int i;
  90.    queue dirq;
  91.    qeltt *elt;
  92.    struct dirent *dp;
  93.    struct stat sb;
  94.    DIR *dirp;
  95.  
  96.    initq(&dirq);
  97.    addq(&dirq, testzipcfg.dir);
  98.  
  99.    while(!emptyq(&dirq)) {
  100.       elt = delq(&dirq);
  101.  
  102.       dirp = opendir(elt->data);
  103.       if (dirp == NULL) {
  104.          perror(elt->data);
  105.          exit(1);
  106.       }
  107.       #if defined(OS2)
  108.       _chdir2(elt->data);
  109.       #elif defined(UNIX)
  110.       chdir(elt->data);
  111.       #endif
  112.  
  113.       while ((dp = readdir(dirp)) != NULL) {
  114.          if (!memcmp(dp->d_name, "..", 2) || !memcmp(dp->d_name, ".", 1))
  115.             continue;
  116.  
  117.          if (stat(dp->d_name, &sb)) {
  118.             fprintf(stdout, "Error:  Can't get file info.  Skipping.\n");
  119.             if (testzipcfg.loglevel > 0)
  120.                fprintf(outfile, "Error:  Can't get file info.  Skipping.\n");
  121.             continue;
  122.          }
  123.  
  124.          if (sb.st_mode >= S_IFDIR && sb.st_mode < 0050000) {
  125.             #if defined(OS2)
  126.             _getcwd2(tempdir, MAXPATHLEN);
  127.             #elif defined(UNIX)
  128.             getcwd(tempdir, MAXPATHLEN);
  129.             #endif
  130.             check_dir(tempdir);
  131.             strcat(tempdir, dp->d_name);
  132.             addq(&dirq, tempdir);
  133.          } else {
  134.             if (testzipcfg.do_all == TRUE) {
  135.                for (i = 0; i < testzipcfg.num_archivers; i++) {
  136.                   testzipcfg.default_num = i;
  137.                   do_archive_test(dp->d_name);
  138.                }
  139.             } else {
  140.                do_archive_test(dp->d_name);
  141.             }
  142.          }
  143.       }
  144.       closedir(dirp);
  145.    }
  146. }
  147.  
  148. void single_check() {
  149.    short int i;
  150.    struct dirent *dp;
  151.    DIR *dirp;
  152.  
  153.    dirp = opendir(testzipcfg.dir);
  154.    if (dirp == NULL) {
  155.       perror(testzipcfg.dir);
  156.       exit(1);
  157.    }
  158.  
  159.    while ((dp = readdir(dirp)) != NULL) {
  160.       if (testzipcfg.do_all == TRUE) {
  161.          for (i = 0; i < testzipcfg.num_archivers; i++) {
  162.             testzipcfg.default_num = i;
  163.             do_archive_test(dp->d_name);
  164.          }
  165.       } else {
  166.          do_archive_test(dp->d_name);
  167.       }
  168.    }
  169.    closedir(dirp);
  170. }
  171.  
  172. void do_archive_test(char filename[]) {
  173.    char tmpfilename[255], tmpcommand[255], *tmpptr, tmpdir[MAXPATHLEN];
  174.    int status;
  175.    FILE *shit;
  176.  
  177.    strncpy(tmpfilename, filename, 254);
  178.    strtoupper(tmpfilename);
  179.    tmpptr = strrchr(tmpfilename, '.');
  180.    if (tmpptr && strstr(tmpptr, testzipcfg.archive[testzipcfg.default_num].extension) != NULL) {
  181.       testzipcfg.archive[testzipcfg.default_num].total_tested++;
  182.       #if defined(OS2)
  183.       _getcwd2(tmpdir, MAXPATHLEN);
  184.       #elif defined(UNIX)
  185.       getcwd(tmpdir, MAXPATHLEN);
  186.       #endif
  187.       check_dir(tmpdir);
  188.       if (testzipcfg.recursive) {
  189.          fprintf(stdout,"Testing '%s%s'", tmpdir, filename);
  190.          if (testzipcfg.loglevel > 0)
  191.             fprintf(outfile, "Testing '%s%s'", tmpdir, filename);
  192.       } else {
  193.          fprintf(stdout, "Testing '%s'", filename);
  194.          if (testzipcfg.loglevel > 0)
  195.             fprintf(outfile, "Testing '%s'", filename);
  196.       }
  197.       fflush(stdout);
  198.  
  199.       /*  Check for read/write permission for file to be tested */
  200.       shit = fopen(filename, "r");
  201.       if (shit == NULL) {
  202.          #if defined(OS2)
  203.          fprintf(stdout, "....File locked or in use. Skipping.\n");
  204.          if (testzipcfg.loglevel > 0)
  205.             fprintf(outfile, "....File locked or in use.  Skipping.\n");
  206.          #elif defined(UNIX)
  207.          fprintf(stdout, "....Permission Denied.  Skipping.\n");
  208.          if (testzipcfg.loglevel > 0)
  209.             fprintf(outfile, "....Permission Denied.  Skipping.\n");
  210.          #endif
  211.          fflush(stdout);
  212.          return;
  213.       }
  214.       fclose(shit);
  215.  
  216.       sprintf(tmpcommand, "%s \"%s%s\" >%s 2>%s",testzipcfg.archive[testzipcfg.default_num].command, tmpdir, filename, SYS_NULL, SYS_NULL);
  217.       if ((status = system(tmpcommand)) != 0) {
  218.          if (testzipcfg.loglevel > 0)
  219.             fprintf(outfile,"....Bad File.  Status: %d\n", status);
  220.          fprintf(stdout,"....Bad File.  Status: %d\n", status);
  221.          fflush(stdout);
  222.  
  223.          if (testzipcfg.do_delete == TRUE) {
  224.             fprintf(stdout,"*** Deleting Bad File: '%s' Status: %d\n", filename, status);
  225.             fflush(stdout);
  226.             testzipcfg.total_del++;
  227.             if (testzipcfg.loglevel > 0)
  228.                fprintf(outfile, "*** Deleting Bad File: '%s'  Status: %d\n", filename, status);
  229.             unlink(filename);
  230.          }
  231.          testzipcfg.total_bad++;
  232.       } else {
  233.          fprintf(stdout,"....Good File.\n");
  234.          fflush(stdout);
  235.          testzipcfg.total_good++;
  236.          if (testzipcfg.loglevel == 2)
  237.             fprintf(outfile, "....Good File.\n");
  238.       }
  239.       if (testzipcfg.loglevel > 0)
  240.          fflush(outfile);
  241.    }
  242. }
  243.  
  244. void open_log() {
  245.    if (testzipcfg.append == TRUE && testzipcfg.overwrite == TRUE) {
  246.       fprintf(stdout, "testzip:  Append (-a) and Overwrite (-o) are incompatible options. Exiting.\n");
  247.       exit(1);
  248.    }
  249.  
  250.    if (testzipcfg.overwrite == TRUE)
  251.       unlink(testzipcfg.logname);
  252.  
  253.    if (testzipcfg.loglevel > 0) {
  254.       if ((outfile = fopen(testzipcfg.logname,"a+")) == NULL ) {
  255.          #if READONLY_LOG
  256.          fprintf(stdout, "testzip:  Can not open logfile.  Disabling all logging.\n");
  257.          testzipcfg.loglevel = 0;
  258.          #else
  259.          fprintf(stdout, "testzip:  Can not open logfile.  Exiting.\n");
  260.          exit(1);
  261.          #endif
  262.       } else {
  263.          fprintf(outfile,"*** Begin Testing Run ***\n");
  264.          fflush(outfile);
  265.       }
  266.    }
  267. }
  268.  
  269. void print_totals() {
  270.    short int i;
  271.  
  272.    for (i = 0; i < testzipcfg.num_archivers; i++) {
  273.       if (testzipcfg.archive[i].total_tested > 0)
  274.          testzipcfg.total_tested += testzipcfg.archive[i].total_tested;
  275.    }
  276.  
  277.    if (testzipcfg.total_tested == 0)
  278.       return;
  279.  
  280.    fprintf(stdout, "\n");
  281.    for (i = 0; i < testzipcfg.num_archivers; i++) {
  282.       if (testzipcfg.archive[i].total_tested > 0)
  283.          fprintf(stdout, "%-4s Files: %-3d    ", testzipcfg.archive[i].name, testzipcfg.archive[i].total_tested);
  284.    }
  285.    fprintf(stdout, "\n");
  286.    fprintf(stdout, "Total Files: %-3d   Total Good: %-3d    Total Bad: %-3d", testzipcfg.total_tested, testzipcfg.total_good, testzipcfg.total_bad);
  287.    if (testzipcfg.do_delete == TRUE)
  288.       fprintf(stdout, "     Total Deleted: %-3d", testzipcfg.total_del);
  289.    fprintf(stdout, "\n");
  290.  
  291.    if (testzipcfg.loglevel > 0) {
  292.       fprintf(outfile, "\n");
  293.       for (i = 0; i < testzipcfg.num_archivers; i++) {
  294.          if (testzipcfg.archive[i].total_tested > 0)
  295.             fprintf(outfile, "%-4s Files: %-3d    ", testzipcfg.archive[i].name, testzipcfg.archive[i].total_tested);
  296.       }
  297.       fprintf(outfile, "\n");
  298.       fprintf(outfile, "Total Files: %-3d   Total Good: %-3d    Total Bad: %-3d",
  299.              testzipcfg.total_tested, testzipcfg.total_good, testzipcfg.total_bad);
  300.       if (testzipcfg.do_delete == TRUE)
  301.          fprintf(outfile, "     Total Deleted: %-3d", testzipcfg.total_del);
  302.  
  303.       fprintf(outfile,"\n*** End Testing Run ***\n\n");
  304.    }
  305. }
  306.  
  307. void check_a_command() {
  308.    short int i;
  309.    int status;
  310.    char command[MAX_TEST_COMMAND];
  311.    #ifdef UNIX
  312.    char t[MAX_TEST_COMMAND];
  313.    #endif
  314.  
  315.    for (i = 0; i < testzipcfg.num_archivers; i++) {
  316.       sscanf(testzipcfg.archive[i].command, "%s", command);
  317.       #if defined(OS2)
  318.       if ((status = which(command)) >= 1) {
  319.          fprintf(stdout, "Error: '%s' not recognized as an operable command.  Exiting.\n", command);
  320.          exit(1);
  321.       }
  322.       #elif defined(UNIX)
  323.       sprintf(t, "which %s >%s 2>%s", command, SYS_NULL, SYS_NULL);
  324.       if ((status = system(t)) >= 1) {
  325.          fprintf(stdout, "Error:  '%s' not recognized as on operable command.  Exiting.\n", command);
  326.          exit(1);
  327.       }
  328.       #endif
  329.    }
  330. }
  331.  
  332. void read_config() {
  333.    FILE *configfile;
  334.    char tmpstr[MAX_LINE_LEN+1], option[25], value[MAX_LINE_LEN], configpath[3][MAX_DIR_LEN + MAX_CONFIG_NAME + 2];
  335.    char *homepath, *tmp, *shit;
  336.    int i, count = 0;
  337.  
  338.    #if defined(OS2)
  339.       char *testzippath;
  340.  
  341.       testzippath = getenv("TESTZIP");
  342.       if (testzippath != NULL) {
  343.          strncpy(configpath[2], testzippath, MAX_DIR_LEN);
  344.          strncat(configpath[2], "/", 1);
  345.          strncat(configpath[2], CONFIG_NAME, MAX_CONFIG_NAME);
  346.       }
  347.    #elif defined(UNIX)
  348.       strncpy(configpath[2], CONFIG_PATH, MAX_DIR_LEN);
  349.       strncat(configpath[2], "/", 1);
  350.       strncat(configpath[2], CONFIG_NAME, MAX_CONFIG_NAME);
  351.    #endif
  352.    homepath = getenv("HOME");
  353.    if (homepath != NULL) {
  354.       strncpy(configpath[1], homepath, MAX_DIR_LEN);
  355.       strncat(configpath[1], "/", 1);
  356.       strncat(configpath[1], CONFIG_NAME, MAX_CONFIG_NAME);
  357.    }
  358.    strncpy(configpath[0], CONFIG_NAME, MAX_CONFIG_NAME);
  359.  
  360.    for (i = 0; i < 3; i++) {
  361.       configfile = fopen(configpath[i], "r");
  362.       if (configfile != NULL)
  363.          break;
  364.    }
  365.  
  366.    if (configfile == NULL) {
  367.       #if CONFIG_DEFAULTS
  368.          printf("testzip:  Config File not found.  Using default configuration.\n");
  369.          return;
  370.       #else
  371.          printf("testzip:  Config File not found. Exiting.\n");
  372.          exit(1);
  373.       #endif
  374.    }
  375.  
  376.    tmp = &tmpstr[12];
  377.  
  378.    while (fgets(tmpstr, MAX_LINE_LEN, configfile) != NULL) {
  379.       if (tmpstr[0] == '#' || tmpstr[0] == '\n' || tmpstr[0] == ' ')
  380.          continue;
  381.       shit = strstr(tmpstr, "#");
  382.       if (shit != NULL)
  383.          *shit = '\0';
  384.  
  385.       sscanf(tmpstr, "%24s %s", option, value);
  386.       strtoupper(option);
  387.  
  388.       if (strcmp(option, "DELETE") == 0) {
  389.          if (strlen(value) > 0) {
  390.             strtoupper(value);
  391.             if (strcmp(value, "YES") == 0) {
  392.                testzipcfg.do_delete = TRUE;
  393.             } else if (strcmp(value, "NO") == 0) {
  394.                testzipcfg.do_delete = FALSE;
  395.             } else {
  396.                printf("Config Error: %s is not a valid value for option %s.\n", value, option);
  397.                exit(1);
  398.             }
  399.          } else {
  400.             printf("Config Error: %s requires a value.\n", option);
  401.             exit(1);
  402.          }
  403.       } else if (strcmp(option, "DIR") == 0) {
  404.          if (strlen(value) > 0) {
  405.             check_dir(value);
  406.             strncpy(testzipcfg.dir, value, MAX_DIR_LEN);
  407.          } else {
  408.             printf("Config Error: %s requires a value.\n", option);
  409.             exit(1);
  410.          }
  411.       } else if (strcmp(option, "LOGNAME") == 0) {
  412.          if (strlen(value) > 0) {
  413.             strncpy(testzipcfg.logname, value, MAX_LOG_NAME);
  414.          } else {
  415.             printf("Config Error: %s requires a value.\n", option);
  416.             exit(1);
  417.          }
  418.       } else if (strcmp(option, "LOGLEVEL") == 0) {
  419.          if (strlen(value) > 0) {
  420.             if (strcmp(value, "0") == 0) {
  421.                testzipcfg.loglevel = 0;
  422.             } else if (strcmp(value, "1") == 0) {
  423.                testzipcfg.loglevel = 1;
  424.             } else if (strcmp(value, "2") == 0) {
  425.                testzipcfg.loglevel = 2;
  426.             } else {
  427.                printf("Config Error: %s is not a valid value for option %s.\n", value, option);
  428.                exit(1);
  429.             }
  430.          } else {
  431.             printf("Config Error: %s requires a value.\n", option);
  432.             exit(1);
  433.          }
  434.       } else if (strcmp(option, "OVERWRITE") ==0) {
  435.          if (strlen(value) > 0) {
  436.             strtoupper(value);
  437.             if (strcmp(value, "YES") == 0) {
  438.                testzipcfg.overwrite = TRUE;
  439.             } else if (strcmp(value, "NO") == 0) {
  440.                testzipcfg.overwrite = FALSE;
  441.             } else {
  442.                printf("Config Error: \'%s\' is not a valid value for option %s.\n", value, option);
  443.                exit(1);
  444.             }
  445.          } else {
  446.             printf("Config Error: %s requires a value.\n", option);
  447.             exit(1);
  448.          }
  449.       } else if (strcmp(option, "APPEND") == 0) {
  450.          strtoupper(value);
  451.          if (strcmp(value, "YES") == 0) {
  452.             testzipcfg.append = TRUE;
  453.          } else if (strcmp(value, "NO") == 0) {
  454.             testzipcfg.append = FALSE;
  455.          } else {
  456.             printf("Config Error: \'%s\' is not a valid value for option %s.\n", value, option);
  457.             exit(1);
  458.          }
  459.       } else if (strcmp(option, "ARCHIVER") == 0) {
  460.           count++;
  461.           if (count == MAX_ARCHIVERS) {
  462.              printf("Config Error:  Can not set more than %d archivers.\n", MAX_ARCHIVERS);
  463.              exit(1);
  464.           }
  465.           testzipcfg.num_archivers++;
  466.       } else if (strcmp(option, "DEFAULT") == 0) {
  467.          if (strlen(value) > 0) {
  468.             strtoupper(value);
  469.             if (strcmp(value, "YES") == 0) {
  470.                testzipcfg.default_num = count;
  471.             } else if (strcmp(value, "NO") == 0) {
  472.                ;
  473.             } else {
  474.                printf("Config Error:  %s is not a valid value for option %s.\n", value, option);
  475.                exit(1);
  476.             }
  477.          } else {
  478.             printf("Config Error: %s requires a value.\n", option);
  479.             exit(1);
  480.          }
  481.       } else if (strcmp(option, "NAME") == 0) {
  482.          if (strlen(value) > 0) {
  483.             strncpy(testzipcfg.archive[count].name, value, MAX_ARCHIVER_NAME);
  484.          } else {
  485.             printf("Config Error: %s requires a value.\n", option);
  486.             exit(1);
  487.          }
  488.       } else if (strcmp(option, "EXTENSION") == 0) {
  489.          strtoupper(value);
  490.          if (strlen(value) > 0) {
  491.             strncpy(testzipcfg.archive[count].extension, value, MAX_EXTENSION);
  492.          } else {
  493.             printf("Config Error: %s requires a value.\n", option);
  494.             exit(1);
  495.          }
  496.       } else if (strcmp(option, "TESTCOMMAND") == 0) {
  497.          if (strlen(value) > 0) {
  498.             strcpy(value, tmp);
  499.             value[strlen(value) - 1] = '\0';
  500.             strncpy(testzipcfg.archive[count].command, value, MAX_TEST_COMMAND);
  501.          } else {
  502.             printf("Config Error: %s requires a value.\n", option);
  503.             exit(1);
  504.          }
  505.       } else if (strcmp(option, "OPTION") == 0) {
  506.          if (value[0] != '\0') {
  507.             testzipcfg.archive[count].option = value[0];
  508.          } else {
  509.             printf("Config Error: %s requires a value.\n", option);
  510.             exit(1);
  511.          }
  512.       } else if (strcmp(option, "DOALL") == 0) {
  513.          if (strlen(value) > 0) {
  514.             strtoupper(value);
  515.             if (strcmp(value, "YES") == 0) {
  516.                testzipcfg.do_all = TRUE;
  517.             } else if (strcmp(value, "NO") == 0) {
  518.                testzipcfg.do_all = FALSE;
  519.             } else {
  520.                printf("Config Error: %s is not a valid value for option %s.\n", value, option);
  521.                exit(1);
  522.             }
  523.          }
  524.       } else if (strcmp(option, "RECURSIVE") == 0) {
  525.          if (strlen(value) > 0) {
  526.             strtoupper(value);
  527.             if (strcmp(value, "YES") == 0) {
  528.                testzipcfg.recursive = TRUE;
  529.             } else if (strcmp(value, "NO") == 0) {
  530.                testzipcfg.recursive = FALSE;
  531.             } else {
  532.                printf("Config Error: %s is not a valid value for option %s.\n", value, option);
  533.                exit(1);
  534.             }
  535.          }
  536.       } else {
  537.          printf("Config Error: Unrecognized option: %s", option);
  538.          exit(1);
  539.       }
  540.    }
  541.  
  542.    fclose(configfile);
  543. }
  544.  
  545. void load_config_defaults()
  546. {
  547.    testzipcfg.do_delete=FALSE;
  548.    testzipcfg.do_all=TRUE;
  549.    testzipcfg.recursive=FALSE;
  550.    testzipcfg.loglevel=1;
  551.    testzipcfg.overwrite=FALSE;
  552.    testzipcfg.append=TRUE;
  553.    testzipcfg.default_num=0;
  554.    testzipcfg.num_archivers=1;
  555.    strncpy(testzipcfg.dir, ".", MAX_DIR_LEN);
  556.    strncpy(testzipcfg.logname, "testzip.log", MAX_LOG_NAME);
  557.  
  558.    testzipcfg.archive[0].option='z';
  559.    strncpy(testzipcfg.archive[0].name, "Zip", MAX_ARCHIVER_NAME);
  560.    strncpy(testzipcfg.archive[0].extension, ".ZIP", MAX_EXTENSION);
  561.    strncpy(testzipcfg.archive[0].command, "unzip -t", MAX_TEST_COMMAND);
  562. }
  563.  
  564. void print_config()
  565. {
  566.    short int i;
  567.  
  568.    printf("Testzip %s Configuration\n\n(1 = True  0 = False)\n", TZ_VERSION);
  569.    printf("delete = %d\n", testzipcfg.do_delete);
  570.    printf("test all = %d\n", testzipcfg.do_all);
  571.    printf("recursive checking = %d\n", testzipcfg.recursive);
  572.    printf("overwrite = %d\n", testzipcfg.overwrite);
  573.    printf("append = %d\n\n", testzipcfg.append);
  574.    printf("loglevel = %d\n", testzipcfg.loglevel);
  575.    printf("default archiver = %s\n", testzipcfg.archive[testzipcfg.default_num].name);
  576.    printf("number of archivers = %d\n", testzipcfg.num_archivers);
  577.    printf("dir = %s\n", testzipcfg.dir);
  578.    printf("logname = %s\n", testzipcfg.logname);
  579.  
  580.    for (i = 0; i < testzipcfg.num_archivers; i++) {
  581.       if (i % 4 == 0) {
  582.          printf("\nPress Enter to continue...");
  583.          getchar();
  584.       }
  585.       printf("\nname = %s\n", testzipcfg.archive[i].name);
  586.       printf("extension = %s\n", testzipcfg.archive[i].extension);
  587.       printf("command = %s\n", testzipcfg.archive[i].command);
  588.       printf("option = %c\n", testzipcfg.archive[i].option);
  589.    }
  590. }
  591.  
  592. void strtoupper(char *string)
  593. {
  594.    int i;
  595.  
  596.    for (i = 0; i < strlen(string); i++)
  597.       string[i] = toupper(string[i]);
  598. }
  599.  
  600. void check_dir(char *string)
  601. {
  602.    int i;
  603.  
  604.    for (i = 0; i < strlen(string); i++) {
  605.       if (string[i] == '\\')
  606.          string[i] = '/';
  607.    }
  608.    if (string[strlen(string) - 1] != '/')
  609.       strcat(string, "/");
  610. }
  611.  
  612. void read_options(int *argc, char *argv[])
  613. {
  614.    short int i, options;
  615.    Bool done = FALSE;
  616.    extern char *optarg;
  617.  
  618.    while ((options = getopt(*argc, argv, "?hvDdEeRraol:f:c:t:p")) != EOF)
  619.    {
  620.       switch(options)
  621.       {
  622.       case 'D':
  623.          testzipcfg.do_delete = TRUE;
  624.          break;
  625.       case 'd':
  626.          testzipcfg.do_delete = FALSE;
  627.          break;
  628.       case 'E':
  629.          testzipcfg.do_all = TRUE;
  630.          break;
  631.       case 'e':
  632.          testzipcfg.do_all = FALSE;
  633.          break;
  634.       case 'R':
  635.          testzipcfg.recursive = TRUE;
  636.          break;
  637.       case 'r':
  638.          testzipcfg.recursive = FALSE;
  639.          break;
  640.       case 't':
  641.          strncpy(testzipcfg.dir, optarg, MAX_DIR_LEN);
  642.          check_dir(testzipcfg.dir);
  643.          break;
  644.       case 'l':
  645.          if (optarg[0] == '0') {
  646.             testzipcfg.loglevel = 0;
  647.             break;
  648.          } else if (optarg[0] == '1') {
  649.             testzipcfg.loglevel = 1;
  650.             break;
  651.          } else if (optarg[0] == '2') {
  652.             testzipcfg.loglevel = 2;
  653.             break;
  654.          } else {
  655.             fprintf(stderr, "testzip: Illegal argument for the '-l' option.\n\n");
  656.             exit(1);
  657.             break;
  658.          }
  659.          break;
  660.       case 'f':
  661.          strncpy(testzipcfg.logname, optarg, MAX_LOG_NAME);
  662.          break;
  663.       case 'a':
  664.          testzipcfg.append = TRUE;
  665.          testzipcfg.overwrite = FALSE;
  666.          break;
  667.       case 'o':
  668.          testzipcfg.append = FALSE;
  669.          testzipcfg.overwrite = TRUE;
  670.          break;
  671.       case 'c':
  672.          for (i = 0; i < testzipcfg.num_archivers; i++) {
  673.             if (optarg[0] == testzipcfg.archive[i].option) {
  674.                testzipcfg.default_num = i;
  675.                done = TRUE;
  676.             }
  677.          }
  678.          if (done == FALSE) {
  679.             fprintf(stderr, "testzip: Illegal argument for the '-c' option.\n\n");
  680.             exit(1);
  681.          }
  682.          break;
  683.       case 'p':
  684.          print_config();
  685.          exit(0);
  686.       case 'v':
  687.          printf("\nTestZip Version %s\n", TZ_VERSION);
  688.          printf("Compiled on %s at %s.\n\n", __DATE__, __TIME__);
  689.          printf("Programmed by MadMan with suggestions from Pantera: 12/6/96\n");
  690.          printf("Modified by [Gandolf]: 12/8/96 - 7/23/97\n\n");
  691.          
  692.          exit(0);
  693.          break;
  694.       case 'h':
  695.       case '?':
  696.          printf("\nTestZip Version %s Help:\n\n", TZ_VERSION);
  697.          printf("-? or -h  Display this help text.\n");
  698.          printf("-v\t  Display version information.\n");
  699.          printf("-p\t  Print testzip's configuration to screen.\n");
  700.          printf("-D\t  Delete any bad zip files.\n");
  701.          printf("-d\t  Do Not delete bad files.\n");
  702.          printf("-E\t  Test all defined archive types.\n");
  703.          printf("-e\t  Test only archive type specified by -c.\n");
  704.          printf("-R\t  Recursively check directories.\n");
  705.          printf("-r\t  Do not recursively check directories.\n");
  706.          printf("-t dir\t  Test all zip files in 'dir' (Default: %s)\n", testzipcfg.dir);
  707.          printf("-f name   Use 'name' as the log file. (Default: %s)\n", testzipcfg.logname);
  708.          printf("-o\t  Overwrite the log file if it already exists.\n");
  709.          printf("-a\t  Append to the log file if it already exists.\n");
  710.          printf("-l 0\t  Log Level 0:  No logging.\n");
  711.          printf("-l 1\t  Log Level 1:  Only bad files logged.\n");
  712.          printf("-l 2\t  Log Level 2:  All files logged.\n");
  713.          for (i = 0; i < testzipcfg.num_archivers; i++)
  714.             printf("-c %c\t  Test files compressed using %s.\n", testzipcfg.archive[i].option, testzipcfg.archive[i].name);
  715.          printf("\n");
  716.          exit(0);
  717.       }
  718.    }
  719. }
  720.