Advertisement
Guest User

Untitled

a guest
Jun 21st, 2011
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include "parse_args.hpp"
  5.  
  6.  
  7.  
  8. void usage() {
  9.    
  10.     cout << "\n   +-++-++-+ +-+ +-++-++-++-++-+"
  11.             "\n   |w||3||b| |-| |C||r||4||c||k|"
  12.             "\n   +-++-++-+ +-+ +-++-++-++-++-+\n\n"
  13.             "\n     -h                 this screen"
  14.             "\n     -v                 be verbose"
  15.             "\n     -s*                single hash"
  16.             "\n     -f*                file of hashes"
  17.             "\n     -t* [NUM(1-5)]     check NUM amount of sites for each hash"
  18.             "\n\n  * requires an argument\n\n";
  19.            
  20.     exit(-1);
  21.    
  22. }
  23.  
  24.  
  25.  
  26. int set_top(char *x) {
  27.    
  28.     string t = x;
  29.    
  30.     if((t.length() == 1) && (isdigit(x[0])) && ((atoi(x) <= 3) && (atoi(x) > 0))) {
  31.          return(atoi(x));
  32.     }
  33.     else {
  34.          cout << "\n\n~! -t value is invalid !~\n\n";
  35.          return(false);
  36.     }
  37.    
  38. }
  39.  
  40.  
  41.  
  42. options parse_args(int arg_count, char **arg_values) {
  43.    
  44.     if(arg_count > 5) usage();
  45.    
  46.     int o;
  47.     options ops = { 0, "", "" };
  48.    
  49.     while((o = getopt(arg_count, arg_values, "hvrt:s:f:")) != -1)
  50.     {
  51.          switch(o)
  52.          {
  53.               case 'h': usage();
  54.               case 'v': VERBOSE = true; break;
  55.               case 'r': RANDOMIZE = true; break;
  56.               case 't': if(!((ops.top = set_top(optarg)))) usage(); else break;
  57.               case 's': ops.single_hash = optarg; break;
  58.               case 'f': ops.file_loc = optarg; break;
  59.               case '?': usage();
  60.               default: usage();
  61.          }
  62.     }
  63.    
  64.     if(((ops.file_loc.empty()) && (ops.single_hash.empty())) || ((!ops.file_loc.empty()) && (!ops.single_hash.empty()))) usage();
  65.    
  66.     return(ops);
  67.        
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement