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