Mandrew

ManRNG - main.cpp (broken for-loop)

Sep 9th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ManRNG - a cross-platform command-line RNG generator for Pokémon games
  2.  (c) M.andrew 2012
  3.  
  4.  This utility provides the user with access to the full range of RNG
  5.  operations available in the popular Pokémon series of games, allowing
  6.  him to find shiny and/or flawless Pokémon no matter what type of computer
  7.  he is using. By default, positive results are send to stdout in CSV format,
  8.  allowing them to be easily piped into bash text manipulation utilities
  9.  or simply saved directly into text files.
  10.  
  11.  The ultimate goal of this program is to match the seed-generation capabilities
  12.  of the widely-known RNG Reporter utility for Windows while supporting all
  13.  of its major file formats, including the XML profiles of the alpha-stage
  14.  RNGR 9.96. Once this goal is realized and a standarized format for args
  15.  is set in place, I foresee writing frontends for the program to improve
  16.  its ease of use for the public.
  17. */
  18. #include <cstdio>
  19. #include <cstdlib>
  20. #include <cstring>
  21.  
  22. #include "researcher.h"
  23. #include "thirdgen.h"
  24. #include "fourthgen.h"
  25. #include "fifthgen.h"
  26.  
  27. enum ERROR_CODES {
  28.     ERR_NOARGS   = 1,
  29.     ERR_NOMETHOD,
  30.     ERR_FALSEARGS,
  31.     ERR_3GNOSUPPORT,
  32.     ERR_4GNOSUPPORT,
  33.     ERR_5GNOSUPPORT,
  34.     ERR_UNKNOWN  = 255,
  35. };
  36.  
  37. char RNGMethodHandler(int Generation, char* Method)
  38. {
  39.     char MethodSwitch;
  40.     size_t ArgLen = strlen(Method);
  41.     if (ArgLen < 2)
  42.     {
  43.         fprintf(stderr,"Method string must be at least 2 chars!\n");
  44.         exit(ERR_NOMETHOD);
  45.     }
  46.     else if (ArgLen == 2)
  47.     {
  48.         MethodSwitch = Method[1];
  49.     }
  50.     else   
  51.     {
  52.         // we're using longops here. we're going to convert
  53.         // them into single-char options and let them
  54.         // gracefully descend through the control flow
  55.        
  56.         // options supported:  
  57.         // -t [--timefinder]
  58.         // -p [--pandora]
  59.         // -v [--pidfromivs]
  60.         // -c [--chainsidfinder]
  61.         // -m [--seed2time]
  62.         // -r [--parameters]
  63.         // -q [--noclue]
  64.         int LongArgLen = static_cast<int>(ArgLen-2); // -2 to account for the two hyphens
  65.         char* LongOpName = new char[LongArgLen];
  66.         for (int i = 0; i >= LongArgLen; ++i)
  67.         {
  68.             LongOpName[i] = Method[i+2];
  69.         }
  70.         if      (LongOpName == "timefinder")     { MethodSwitch = 't'; }
  71.         else if (LongOpName == "pandora")        { MethodSwitch = 'p'; }
  72.         else if (LongOpName == "pidfromivs")     { MethodSwitch = 'v'; }
  73.         else if (LongOpName == "chainsidfinder") { MethodSwitch = 'c'; }
  74.         else if (LongOpName == "seed2time")      { MethodSwitch = 'm'; }
  75.         else if (LongOpName == "parameters")     { MethodSwitch = 'r'; }
  76.         else if (LongOpName == "noclue")         { MethodSwitch = 'q'; }
  77.         else
  78.         {
  79.             fprintf(stderr,"Long method name unrecognized!\n");
  80.             delete[] LongOpName;
  81.             exit(ERR_NOMETHOD);
  82.         }
  83.         delete[] LongOpName;
  84.     }
  85.     // Now that we're here, we should
  86.     switch (Generation)
  87.     {
  88.         case '3':
  89.             // options supported:
  90.             // -t [--timefinder]
  91.             // -p [--pandora]
  92.             switch (MethodSwitch)
  93.             {
  94.                 case 't':
  95.                     TimeFinderThird();
  96.                     break;
  97.                 case 'p':
  98.                     PandoraThird();
  99.                     break;
  100.                 default:
  101.                     fprintf(stderr,"Unsupported method for third generation RNG.\n");
  102.                     exit(ERR_3GNOSUPPORT);
  103.             }
  104.         break;
  105.  
  106.         case '4':
  107.             // options supported:
  108.             // -t [--timefinder]
  109.             // -v [--pidfromivs]
  110.             // -c [--chainsidfinder]
  111.             // -m [--seed2time]
  112.             // -p [--pandora]
  113.             switch (MethodSwitch)
  114.             {
  115.                 case 't':
  116.                     TimeFinderFourth();
  117.                     break;
  118.                 case 'v':
  119.                     PidFromIVsFourth();
  120.                     break;
  121.                 case 'c':
  122.                     ChainSIDFinderFourth();
  123.                     break;
  124.                 case 'm':
  125.                     Seed2TimeFourth();
  126.                     break;
  127.                 case 'p':
  128.                     PandoraFourth();
  129.                     break;
  130.                 default:
  131.                     fprintf(stderr,"Unsupported method for fourth generation RNG.\n");
  132.                     exit(ERR_5GNOSUPPORT);
  133.                     break;
  134.             }
  135.         break;
  136.  
  137.         case '5':      
  138.             // options supported:
  139.             // -t [--timefinder]
  140.             // -r [--parameters]
  141.             // -m [--seed2time] (c-gear)
  142.             // -p [--pandora]
  143.             switch (MethodSwitch)
  144.             {
  145.                 case 't':
  146.                     TimeFinderFifth();
  147.                     break;
  148.                 case 'r':
  149.                     ParamSearchFifth();
  150.                     break;
  151.                 case 'm':
  152.                     Seed2TimeFifth();
  153.                     break;
  154.                 case 'p':
  155.                     PandoraFifth();
  156.                     break;
  157.                 default:
  158.                     fprintf(stderr,"Unsupported method for fifth generation RNG.\n");
  159.                     exit(ERR_5GNOSUPPORT);
  160.                     break;
  161.             }
  162.         break;
  163.  
  164.         case 'r':
  165.             // options supported:
  166.             // -q [--noclue]
  167.             switch (MethodSwitch)
  168.             {
  169.                 case 'q':
  170.                     Researcher();
  171.                     break;
  172.                 default:
  173.                     fprintf(stderr,"I have no idea what modes Researcher should support. But not that one!\n");
  174.                     exit(ERR_UNKNOWN);
  175.                     break;
  176.             }
  177.         break;
  178.        
  179.         default:
  180.             fprintf(stderr,"This error should never happen. Consult Mandrew for advice.\n");
  181.             exit(ERR_UNKNOWN);
  182.             break;
  183.     }
  184.     return 0;
  185. }
  186.  
  187. int main(int argc, char* argv[])
  188. {
  189.     if (argv[1] == NULL)
  190.     {
  191.         fprintf(stderr,"ManRNG cannot function without any arguments!\n");
  192.         exit(ERR_NOARGS);
  193.     }
  194.    
  195.     char GenFlag = argv[1][1]; //this should be a 3, 4, or 5
  196.     char* MethodSearch;
  197.     if (GenFlag == '3' || GenFlag == '4' || GenFlag == '5' || GenFlag == 'r')
  198.     {
  199.         MethodSearch = argv[2];
  200.         if (MethodSearch == NULL)
  201.         {
  202.             fprintf(stderr,"ManRNG requires a method as its second argument.\n");
  203.             exit(ERR_NOMETHOD);
  204.         }
  205.         RNGMethodHandler(static_cast<int>(GenFlag),MethodSearch);
  206.     }
  207.     else if (GenFlag == 'v')
  208.     {
  209.         printf("ManRNG version 0.01\n");
  210.     }
  211.     else
  212.     {
  213.         fprintf(stderr,"ManRNG requires -3, -4, -5, -r, or -v as its first argument.\n");
  214.         exit(ERR_FALSEARGS);
  215.     }
  216. }
Advertisement
Add Comment
Please, Sign In to add comment