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

  1. // BBSWEEP.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. #define PROGRAM "BBSWEEP"   // Name of module
  11. /************************************************************************/
  12. /* need to malloc some of this */
  13.  
  14. typedef struct
  15. {
  16.     char command[127];
  17.     char greater_than;
  18.     char less_than;
  19.     char pipe;
  20.     BYTE into_command;
  21. } SWEEP_INFO;
  22.  
  23. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  24. static int sweep(AU *au, char *file_name)
  25. {
  26.     SWEEP_INFO *in = (SWEEP_INFO *)au->info;
  27.  
  28.     if (!au->simulate)
  29.         au_printf(au, "\n");
  30.  
  31. //      au_printf(au, "@?6Processing @?1%s@?H\n", au->source_directory);
  32.  
  33.     check_for_key();
  34.     press_any_key(au);
  35.     if (!au->simulate)
  36.         system(in->command);
  37.  
  38.     Unused(file_name);
  39.     return 0;
  40. }
  41. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  42. static BYTE parse_comm_line(AU *au, char option, char *cur_argv,
  43.                             PARSE_TYPE type)
  44. {
  45.     char hold_dir[FLENGTH];
  46.     SWEEP_INFO *in = (SWEEP_INFO *)au->info;
  47.     int i;
  48.  
  49.     switch (type)
  50.     {
  51.     case PARSE_PARAM_OPTION:
  52.         switch (option)
  53.         {
  54.         case 'B':
  55.             au->pause = get_value(au, OFF | ON);
  56.             break;
  57.         case 'G':
  58.             in->greater_than=cur_argv[0];
  59.             break;
  60.         case 'L':
  61.             in->less_than=cur_argv[0];
  62.             break;
  63.         case 'P':
  64.             in->pipe=cur_argv[0];
  65.             break;
  66.         case '?':
  67.             au_syntax_message(au, "SWeep");
  68.             au_printf(au,
  69.                "@?H[@?3options@?H] [@?1paths(s)@?H] command [command parameters]\n\n");
  70.             au_param_heading(au);
  71.             au_printf(au,
  72.                "@?3-B@?Hon|off  Break at each directory\n"
  73.                "@?3-G@?H<char>  Greater than character, default = }\n"
  74.                "@?3-L@?H<char>  Less than character, default = { \n"
  75.                "@?3-P@?H<char>  Pipe character, default = ~\n\n"
  76.                "Where <char> is a single character\n");
  77.             exit (0);
  78.         default:
  79.             au_invalid_option(au, PROGRAM, option);
  80.         }
  81.         return TRUE;
  82.     case PARSE_FILESPEC:
  83.         if (!in->into_command)
  84.         {
  85.             getcwd(hold_dir, FLENGTH);
  86.             if (chdir(cur_argv) == 0)
  87.             {
  88.                 add_to_list(au, &au->process_list, cur_argv);
  89.                 chdir(hold_dir);
  90.             }
  91.             else
  92.                 in->into_command = TRUE;
  93.         }
  94.         if (in->into_command)
  95.         {
  96.             strcat(in->command, " ");
  97.             strcat(in->command, cur_argv);
  98.         }
  99.         return TRUE;
  100.     case PARSE_POST_CHECK:
  101.         if (in->command[0] == '\0')
  102.         {
  103.             au_printf_error(au, "Execution command is missing");
  104.             exit (1);
  105.         }
  106.         /* get back the > < and | from the command to execute */
  107.         for (i = strlen(in->command)-1; i >= 0; i--)
  108.         {
  109.             if (in->command[i] == in->greater_than)
  110.                 in->command[i] = '>';
  111.             else if (in->command[i] == in->less_than)
  112.                 in->command[i] = '<';
  113.             else if (in->command[i] == in->pipe)
  114.                 in->command[i] = '|';
  115.         }
  116.         return TRUE;
  117.     }
  118.     return FALSE;
  119. }
  120. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  121. int main_sweep(AU *au, int argc, char *argv[])
  122. {
  123.     SWEEP_INFO *in;
  124.  
  125.     in = (SWEEP_INFO *)au_malloc(au, sizeof(SWEEP_INFO));
  126.     memset(in, '\0', sizeof(SWEEP_INFO));
  127.     au->info = in;
  128.     in->greater_than = '}';
  129.     in->less_than = '{';
  130.     in->pipe = '~';
  131.  
  132.     au->dirs_only = TRUE;
  133.  
  134.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  135.     process_files(au, sweep);
  136.     return 0;
  137. }
  138.  
  139.