home *** CD-ROM | disk | FTP | other *** search
/ HomeWare 14 / HOMEWARE14.bin / archive / au116_4s.arj / TEST.CPP < prev    next >
C/C++ Source or Header  |  1994-04-03  |  5KB  |  221 lines

  1. // TEST.CPP                                  1          1    6666
  2. // Dave Harris                                11         11   6
  3. // Compiled using Borland C++ ver 3.1       1 1        1 1   6666
  4. // 03-03-94                                  1     ..   1   6   6
  5. //                                           11111 .. 11111  666
  6. ////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "au.hpp"
  9.  
  10. /*********************************************************************/
  11. /* Define Statements */
  12. /*********************/
  13.  
  14. #define PROGRAM "TEST"    // Name of module
  15.  
  16. /*********************************************************************/
  17.  
  18. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  19. static BYTE archive_has_password(AU *au, char *file_name)
  20. {
  21.     ARC_FILE arcFile;
  22.     BYTE ret_code = FALSE;
  23.     ARC_RECORD record;
  24.  
  25.     check_for_key();
  26.  
  27.     arc_file_init(au, &arcFile, file_name);
  28.     for (;;)
  29.     {
  30.         if (get_record(au, &arcFile, &record) != 0)
  31.             break;
  32.         if (record.encrypted)
  33.         {
  34.             ret_code = TRUE;
  35.             break;
  36.         }
  37.     }
  38.  
  39.     arc_file_deinit(au, &arcFile);
  40.     return ret_code;
  41. }
  42. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  43. static int test_one(AU *au, char *file_name, PACKAGE *package)
  44. {
  45.     char string[FLENGTH];     /* build the dos commands in the string */
  46.     int  did_rename;
  47.     int  ret_value;
  48.  
  49.     if (!au->no_extra)
  50.         au_printf(au, "@?6Testing @?1%s@?H\n", file_name);
  51.     act_log_printf(au, "   + TEST    : %s", file_name);
  52.  
  53.     if (package->test == NULL)
  54.     {
  55.         au_printf_error(au, "No testing method specified for %s\n", file_name);
  56.         press_any_key(au);
  57.         return 0;
  58.     }
  59.  
  60.     did_rename = rename_strict(au, package, au->source_directory, file_name);
  61.  
  62.     au->number_processed++;
  63.  
  64.     substitute_macros(string, package->test, NULL, NULL, file_name);
  65.  
  66.     if (!au->simulate)
  67.     {
  68.         ret_value = execute(au, string, au->output, NULL, package->memoryNeeded);
  69.  
  70.         if (did_rename)
  71.             rename_strict_back(au->source_directory, file_name);
  72.  
  73.         if (ret_value > 0)
  74.         {
  75.             if (archive_has_password(au, file_name))
  76.                 add_to_bad_list(au, au->source_directory, file_name, ret_value, 5);
  77.             else
  78.             {
  79.                 if (au->rename_to[0] != '\0')
  80.                 {
  81.                     rename(file_name, fit_mask(file_name, au->rename_to));
  82.                     fix_flist(au, file_name, fit_mask(file_name, au->rename_to));
  83.                 }
  84.  
  85.                 add_to_bad_list(au, au->source_directory, file_name, ret_value, 1);
  86.             }
  87.             return -1;
  88.         }
  89.     }
  90.     return 0;
  91. }
  92. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  93. static void quick_test_one(AU *au, char *file_name, ARC_FILE *arcFile)
  94. {
  95.     int ret_code;
  96.     ARC_RECORD record;
  97.  
  98.     if (!au->no_extra)
  99.         au_printf(au, "@?6Quick Testing @?1%s@?H\n", file_name);
  100.     act_log_printf(au, "   + TEST -Q : %s", file_name);
  101.     au->number_processed++;
  102.  
  103.     for (;;)
  104.     {
  105.         ret_code = get_record(au, arcFile, &record);
  106.         if (ret_code == EOF)
  107.             break;
  108.         else if (ret_code == -2)
  109.         {
  110.             add_to_bad_list(au, au->source_directory, file_name, 0);
  111.             return;
  112.         }
  113.     }
  114. }
  115. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  116. int test(AU *au, char *file_name)
  117. {
  118.     ARC_FILE arcFile;
  119.  
  120.     check_for_key();
  121.  
  122.     arc_file_init(au, &arcFile, file_name);
  123.     if (au->quick_test)
  124.     {
  125.         if (arcFile.type > 0)
  126.             quick_test_one(au, file_name, &arcFile);
  127.         arc_file_deinit(au, &arcFile);
  128.     }
  129.     else
  130.     {
  131.         arc_file_deinit(au, &arcFile);
  132.         if (arcFile.type > 0)
  133.             return test_one(au, file_name, &au->package[arcFile.type]);
  134.     }
  135.     return 0;
  136. }
  137. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  138. static void ReadCFGInfo(AU *au, HANDLE file, char *cfg_file, int *cfg_line)
  139. {
  140.     char string[200],
  141.          string2[200],
  142.          string3[200];
  143.  
  144.     for(EVER)
  145.     {
  146.         if (get_file_line(au, file, string)==EOF)
  147.             break;
  148.  
  149.         split_string(string, string2);
  150.         split_string(string, string3);
  151.  
  152.         if (string2[0] == '\0')
  153.             continue;
  154.  
  155.         strcpy(au->curOpt, string2);
  156.         au->curVal = string3;
  157.         switch (toupper(string2[1]) << 8 | toupper(string2[0]))
  158.         {
  159.             case 'BE':                                          // Begin
  160.                 return;
  161.             case 'PA':
  162.                 au->pause = get_value(au, OFF | ON);
  163.                 break;
  164.             case 'RE':
  165.                 strcpy(au->rename_to, string3);
  166.                 break;
  167.             default:
  168.                 au_invalid_cfg_option(au, string2, cfg_file, *cfg_line);
  169.         }
  170.     }
  171. }
  172. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  173. static BYTE parse_comm_line(AU *au, char option, char *cur_argv,
  174.                             PARSE_TYPE type)
  175. {
  176.     Unused(cur_argv);
  177.  
  178.     switch (type)
  179.     {
  180.     case PARSE_SINGLE_OPTION:
  181.         if (option == 'Q')
  182.         {
  183.             au->quick_test = TRUE;
  184.             return TRUE;
  185.         }
  186.         return FALSE;
  187.     case PARSE_PARAM_OPTION:
  188.         switch (option)
  189.         {
  190.             case 'P':
  191.                 au->pause = get_value(au, OFF | ON);
  192.                 break;
  193.             case '?':
  194.                 au_standard_opt_header(au, "Test",
  195.                     "@?3-Q@?H               Quick Test\n"
  196.                     "@?3-P@?Hon|off         Pause after bad archive found\n");
  197.                 exit (0);
  198.             default:
  199.                 au_invalid_option(au, PROGRAM, option);
  200.         }
  201.         return TRUE;
  202.     }
  203.     return FALSE;
  204. }
  205. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  206. int main_test(AU *au, int argc, char *argv[])
  207. {
  208.     ReadGlobalCFGInfo(au, au->cfg_file, PROGRAM, ReadCFGInfo);
  209.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  210.     process_files(au, test);
  211.  
  212.     if (!au->no_extra)
  213.         au_printf_c(au, 15, "\n\nFiles Tested = %d\n", au->number_processed);
  214.  
  215.     /* Prevent recursion when disp_bad_arcs is later called */
  216.     au->quick_test = FALSE;
  217.  
  218.     return 0;
  219. }
  220.  
  221.