Advertisement
RunAwayScientist

Standardized Equipment Program for Jagged Alliance 2

Sep 9th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 37.80 KB | None | 0 0
  1. // Program by RunAwayScientist on 9/8/2016
  2. // PERM: Free to re-distribute and edit.
  3.  
  4.  
  5. // NOTE:
  6.  
  7.  
  8.  
  9. // DESC:  Program will replace one-for-one the
  10. //        gearkits in /Inventroy/MercStartingGear.xml with a standard 5 kits defined
  11. //        in ReplaceWith.txt
  12.  
  13.  
  14. // REQUIREMENTS:
  15. // Input.txt
  16. // ReplaceWith.txt
  17.  
  18.  
  19. // CURRENT SETTINGS: Program set to read from input.txt and create a full MercStartingGear.xml
  20. //                   in the same folder as the program. Reads from Strings defined in this
  21. //                   .cpp to get its replacement information.
  22.  
  23. // EXEC:
  24. //       0. Simple loop that counts to 5, replacing and cutting between <GEARKIT>
  25. //          XML tags. Strings replace1, replace2, replace3, replace4, and replace5 correspond
  26. //          to the first, second, third, fourth, and fifth gearkits.
  27.  
  28. //       1. Track two cursors. Use this to find strings between <GEARKIT> delineators
  29. //          then write this info to output string. Then add the replacement string, jump to
  30. //          next <GEARKIT> and substring in the last and beginning cursor. (DONE USING REPLACETAG METHOD)
  31.  
  32.  
  33. // INSTRUCTIONS (FULL):
  34. //
  35. // 1. Place your CURRENT MercStartingGear.xml content into Input.txt as raw text.
  36. //
  37. // 2. Place your desired gearkit XML replacement into ReplaceWith.txt
  38. //
  39. // 3. Run the program. Wait until it finishes. If errors, check source code and recompile or post on
  40. //    Bear Pits forums.
  41. //
  42. // 4. Take finished MercStartingGear.xml and replace your old file with it.
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. #include <iostream>
  54. #include <algorithm>
  55. #include <ctime>
  56. #include <cctype>
  57. #include <ctype.h>
  58. #include <cstdlib>
  59. #include <fstream>
  60. #include <string>
  61. #include <strings.h>
  62. #include <vector>
  63. #include <dirent.h>
  64. #include <stdio.h>
  65. #include <locale>
  66. #include <sys/types.h>
  67. #include <stdlib.h>
  68.  
  69.  
  70.  
  71. using namespace std;
  72.  
  73.  
  74.  
  75.  
  76. string tempS1 = "";
  77. string tempS2 = "";
  78. string tempS3 = "";
  79. string tempS4 = "";
  80. string tempS5 = "";
  81.  
  82.  
  83.  
  84. string currentFile = "blarg";
  85.  
  86.  
  87.  
  88. char tempC1[700];   // Temp buffer before transfer to tempS1
  89. int tempI1 = 0;     // Iterator used in all loops
  90. int tempI2 = 0;   // Count replace char total
  91. int tempI3 = 0; //Left comma location
  92. int tempI4 = 0; //Rightmost comma location
  93. int tempI5 = 0; //Rightmost location of and
  94. int tempI6 = 0; //Current place in vector
  95. int tempI7 = 0; // Special line corrections made
  96.  
  97.  
  98. string ReadContent(const string& s1)
  99. {
  100.       fstream tempTunnel90;
  101.       string returnString;
  102.       string tempGetString90;
  103.       tempTunnel90.open(s1.c_str(), fstream::in);
  104.       long int currentFileLine60 = 0;
  105.      
  106.       char tChar90[700];
  107.      
  108.      
  109.      
  110.      
  111.       if(!(tempTunnel90.is_open()))
  112.       {
  113.                                     cout << "-----------********----------\n";
  114.                                     cout << "ERROR FUNCTION ReadContent: " << "\n";
  115.                                     cout << "TRIED TO OPEN " << s1 << " BUT FAILED\n";
  116.                                     cout << "-----------********----------\n\n";
  117.                                                                 system("PAUSE");
  118.                     return "blarg";
  119.       }
  120.      
  121.      
  122.        do
  123.        {
  124.                     currentFileLine60++;
  125.                     tempTunnel90.getline(tChar90, 700);
  126.                     tempGetString90 = tChar90;
  127.                     returnString = returnString + tempGetString90 + "\n";
  128.        }
  129.        while (tempTunnel90.eof() != true);
  130.        
  131.        tempTunnel90.close();
  132.      
  133.       return returnString;
  134. }
  135. //USAGE:
  136. //NOTE: CASE SENSITIVE
  137. //      CutOut(originString, leftmost string, rightmost string)
  138. //      CutOut("<uiIndex>5</uiIndex>", "<uiIndex>","</uiIndex>")
  139. //
  140. //EXCEPTIONS:
  141. //           IF CANNOT FIND SECOND TAG, WILL CUT ALL THE WAY TO END
  142. //           OF THE STRING
  143. //           IF CANNOT FIND FIRST TAG, WILL RETURN 'blarg'
  144. string CutOut(const string& s1, const string& s2, const string& s3)
  145. {
  146.        long long int place1 = -1;
  147.        long long int place2 = -1;
  148.        string returnString="blarg";
  149.        
  150.        place1 = s1.find(s2);
  151.        if(place1 <= -1)
  152.        {
  153.                  return returnString;
  154.        }
  155.        
  156.        place1 = place1 + s2.size();
  157.        place1--;
  158.        place2 = s1.find(s3, (place1 + 1));
  159.        if(place2 <= -1)
  160.        {
  161.                  place2 = s1.size() - 1;
  162.        }
  163.        
  164.        returnString = s1.substr((place1+1),((place2-place1)-1));
  165.        
  166.        
  167.        return returnString;
  168. }
  169. long long int CutOutInt(const string& s1, const string& s2, const string& s3)
  170. {
  171.        long long int place1 = -1;
  172.        long long int place2 = -1;
  173.        long long int returnInt=-1;
  174.        string returnString = "";
  175.        
  176.        place1 = s1.find(s2);
  177.        if(place1 <= -1)
  178.        {
  179.                  return returnInt;
  180.        }
  181.        
  182.        place1 = place1 + s2.size();
  183.        place1--;
  184.        place2 = s1.find(s3, (place1 + 1));
  185.        if(place2 <= -1)
  186.        {
  187.                  place2 = s1.size() - 1;
  188.        }
  189.        
  190.        returnString = s1.substr((place1+1),((place2-place1)-1));
  191.        returnInt = atoi( returnString.c_str() );
  192.        
  193.        return returnInt;
  194. }
  195. long long int CutOutInt(const string& s1, const string& s2, const string& s3, unsigned long long int placeStart)
  196. {
  197.        long long int place1 = -1;
  198.        long long int place2 = -1;
  199.        long long int returnInt=-1;
  200.        string returnString = "";
  201.        
  202.        place1 = s1.find(s2,placeStart);
  203.        if(place1 <= -1)
  204.        {
  205.                  return returnInt;
  206.        }
  207.        
  208.        place1 = place1 + s2.size();
  209.        place1--;
  210.        place2 = s1.find(s3, (place1 + 1));
  211.        if(place2 <= -1)
  212.        {
  213.                  place2 = s1.size() - 1;
  214.        }
  215.        
  216.        returnString = s1.substr((place1+1),((place2-place1)-1));
  217.        returnInt = atoi( returnString.c_str() );
  218.        
  219.        return returnInt;
  220. }
  221. string CutOut(const string& s1, const string& s2, const string& s3, unsigned long long int placeStart)
  222. {
  223.        long long int place1 = -1;
  224.        long long int place2 = -1;
  225.        string returnString="blarg";
  226.        
  227.        place1 = s1.find(s2,placeStart);
  228.        if(place1 <= -1)
  229.        {
  230.         // Special ERRORCHECK this function
  231.        if(returnString == "blarg")
  232.        {
  233.                                     cout << "-----------********----------\n";
  234.                                     cout << "ERROR FUNCTION CutOut: " << "\n";
  235.                                     cout << "BLARG returned to returnString: " << returnString  << "\n";
  236.                                     cout << "(MOST LIKELY RETURNED FROM CUTOUT\nBLARG MEANS FIRST TAG NOT FOUND)" << "\n";
  237.                                     cout << "THIS MOST LIKELY MEANS THAT LESS\n";
  238.                                     cout << "THAN FIVE <GEARKIT>s WERE FOUND\n";
  239.                                     cout << "FATAL ERROR: CLOSE THIS PROGRAM\n";
  240.                                     cout << "AND DO -not- CONTINUE\n";
  241.                                     cout << "PLACESTART: " << placeStart << "\n";
  242.                                     cout << "-----------********----------\n\n";
  243.                                                                 system("PAUSE");
  244.        }
  245.                  return returnString;
  246.        }
  247.        place1 = place1 + s2.size();
  248.        place1--;
  249.        place2 = s1.find(s3, (place1 + 1));
  250.        if(place2 <= -1)
  251.        {
  252.                  place2 = s1.size() - 1;
  253.        }
  254.        
  255.        returnString = s1.substr((place1+1),((place2-place1)-1));
  256.        
  257.        
  258.        return returnString;
  259. }
  260. string CutLeft(const string& s1, const string& s2)
  261. {
  262.        long long int place1 = 0;
  263.        long long int place2 = -1;
  264.        string returnString="blarg";
  265.        
  266.  
  267.        place2 = s1.find(s2, (place1 + 1));
  268.        if(place2 <= 0)
  269.        {
  270.                  return returnString;
  271.        }
  272.        
  273.        returnString = s1.substr(place1,place2);
  274.        
  275.        
  276.        return returnString;
  277. }
  278. string CutLeft(const string& s1, const string& s2, unsigned long long int placeStart)
  279. {
  280.        long long int place1 = 0;
  281.        long long int place2 = -1;
  282.        string returnString="blarg";
  283.        
  284.  
  285.        place2 = s1.find(s2, placeStart);
  286.        if(place2 <= 0)
  287.        {
  288.                  return returnString;
  289.        }
  290.        
  291.        returnString = s1.substr(place1,place2);
  292.        
  293.        
  294.        return returnString;
  295. }
  296. string CutRight(const string& s1, const string& s2)
  297. {
  298.        long long int place1 = -1;
  299.        long long int place2 = ((s1.size()));
  300.        string returnString="blarg";
  301.        
  302.        place1 = s1.find(s2);
  303.        if(place1 <= -1)
  304.        {
  305.                  return returnString;
  306.        }
  307.        place1 = place1 + s2.size();
  308.        if(place1 >= (s1.size()-1))
  309.        {
  310.                  return returnString;
  311.        }
  312.        place2 = place2 - place1;
  313.        
  314.        returnString = s1.substr(place1,place2);
  315.        
  316.        
  317.        return returnString;
  318. }
  319. string CutRight(const string& s1, const string& s2, unsigned long long int placeStart)
  320. {
  321.        long long int place1 = -1;
  322.        long long int place2 = ((s1.size()));
  323.        string returnString="blarg";
  324.        
  325.        place1 = s1.find(s2, placeStart);
  326.        if(place1 <= -1)
  327.        {
  328.                  return returnString;
  329.        }
  330.        place1 = place1 + s2.size();
  331.        if(place1 >= (s1.size()-1))
  332.        {
  333.                  return returnString;
  334.        }
  335.        place2 = place2 - place1;
  336.        
  337.        returnString = s1.substr(place1,place2);
  338.        
  339.        
  340.        return returnString;
  341. }
  342. // USAGE:
  343. // ReadTag( <open tag> , <close tag> , <string> )
  344. // ReadTag("<value>","</value>",string1)
  345. string ReadTag (const string& s1, const string& s2, const string& s3)
  346. {
  347.        string returnString = "blarg";
  348.        
  349.        long long unsigned int place1 = 0;
  350.        long long unsigned int place2 = 0;
  351.        long long unsigned int cutlength = 0;
  352.        
  353.        place1 = s3.find(s1, 0);
  354.        place1 = place1 + (s1.size());
  355.        place2 = s3.find(s2, place1);
  356.        cutlength = place2 - place1;
  357.        
  358.        returnString = s3.substr(place1,cutlength);
  359.        
  360.        
  361.        
  362.        return returnString;
  363. }
  364. // USAGE:
  365. // ReadTag( <open tag> , <string> )
  366. // ReadTag("<value>", string1)
  367. string ReadTag (const string& s1, const string& s3)
  368. {
  369.        string returnString = "blarg";
  370.        string s2 = "</";
  371.        
  372.        long long unsigned int place1 = 0;
  373.        long long unsigned int place2 = 0;
  374.        long long unsigned int cutlength = 0;
  375.        
  376.        place1 = s3.find(s1,0);
  377.        place1 = place1 + (s1.size());
  378.        place2 = s3.find(s2, place1);
  379.        cutlength = place2 - place1;
  380.        
  381.        returnString = s3.substr(place1,cutlength);
  382.        
  383.        
  384.        
  385.        return returnString;
  386. }
  387. string ReadTag (const string& s1, const string& s2, const string& s3, long long unsigned int placeStart)
  388. {
  389.        string returnString = "blarg";
  390.        
  391.        long long unsigned int place1 = 0;
  392.        long long unsigned int place2 = 0;
  393.        long long unsigned int cutlength = 0;
  394.        
  395.        place1 = s3.find(s1, placeStart);
  396.        place1 = place1 + (s1.size());
  397.        place2 = s3.find(s2, place1);
  398.        cutlength = place2 - place1;
  399.        
  400.        returnString = s3.substr(place1,cutlength);
  401.        
  402.        
  403.        
  404.        return returnString;
  405. }
  406. // USAGE:
  407. // ReadTag( <open tag> , <string> , <integer>)
  408. // ReadTag("<value>", string1, 829)
  409. string ReadTag (const string& s1, const string& s3, long long unsigned int placeStart)
  410. {
  411.        string returnString = "blarg";
  412.        string s2 = "</";
  413.        
  414.        long long unsigned int place1 = 0;
  415.        long long unsigned int place2 = 0;
  416.        long long unsigned int cutlength = 0;
  417.        
  418.        place1 = s3.find(s1, placeStart);
  419.        place1 = place1 + (s1.size());
  420.        place2 = s3.find(s2, place1);
  421.        cutlength = place2 - place1;
  422.        
  423.        returnString = s3.substr(place1,cutlength);
  424.        
  425.        
  426.        
  427.        return returnString;
  428. }
  429. // USAGE:
  430. // ReadTag( <open tag> , <string> , <integer>)
  431. // ReadTag("<value>", string1, 829)
  432. int FindTag (const string& s1,const string& s3)
  433. {
  434.        long long unsigned int place1 = 0;
  435.        
  436.        place1 = s3.find(s1, 0);
  437. //       place1 = place1 + (s1.size());
  438.        
  439.        
  440.        
  441.        return place1;
  442. }
  443. int FindTagValue (const string& s1,const string& s3)
  444. {
  445.        long long unsigned int place1 = 0;
  446.        
  447.        place1 = s3.find(s1, 0);
  448.        place1 = place1 + (s1.size());
  449.        
  450.        
  451.        
  452.        return place1;
  453. }
  454. // USAGE:
  455. // FindTag ( <open tag> , <string> , <integertostart> )
  456. // FindTag ("<value>", string1, 829)
  457. int FindTag (const string& s1, const string& s3,long long unsigned int placeStart)
  458. {
  459.        long long unsigned int place1 = 0;
  460.        
  461.        place1 = s3.find(s1, placeStart);
  462. //       place1 = place1 + (s1.size());
  463.        
  464.        
  465.        
  466.        return place1;
  467. }
  468. int FindTagValue (const string& s1, const string& s3,long long unsigned int placeStart)
  469. {
  470.        long long unsigned int place1 = 0;
  471.        
  472.        place1 = s3.find(s1, placeStart);
  473.        place1 = place1 + (s1.size());
  474.        
  475.        
  476.        
  477.        return place1;
  478. }
  479.  
  480.  
  481.  
  482. unsigned long long int ReturnFileNumber (const string& inputString)
  483. {
  484.      long long int returnedNumber = -1;
  485.      string parseStringT = "";
  486.      long long int indexPos = -1;
  487.       int throwAway2 = -1;
  488.       string throwAway3 = "blarg";
  489.      
  490.      
  491.      indexPos = inputString.find_last_of("1234567890");
  492.      
  493.      if(indexPos != -1)
  494.      {
  495.          do
  496.          {
  497.                   parseStringT = inputString[indexPos] + parseStringT;
  498.                   indexPos--;
  499.                   throwAway2 = -1;
  500.                   throwAway3 = "blarg";
  501.                   if((indexPos < inputString.size()) && (indexPos >= 0))
  502.                   {
  503.                       throwAway3 = inputString[indexPos];
  504.                       throwAway2 = throwAway3.find_first_of("1234567890");
  505.                   }
  506.                   else
  507.                   {
  508.                       returnedNumber = atoi( parseStringT.c_str() );
  509.                       if(returnedNumber == -1)
  510.                       {
  511.                                     cout << "-----------********----------\n";
  512.                                     cout << "ERROR FUNCTION ReturnFileNumber: " << inputString << "\n";
  513.                                     cout << "TRIED TO PARSE " << parseStringT << " BUT DID NOT RETURN INTEGER\n";
  514.                                     cout << "-----------********----------\n\n";
  515.                                                                 system("PAUSE");
  516.                       }
  517.                       break;
  518.                   }
  519.                   if(throwAway2 != -1)
  520.                   {
  521.                                 continue;
  522.                   }
  523.                   else
  524.                   {
  525.                       returnedNumber = atoi( parseStringT.c_str() );
  526.                       if(returnedNumber == -1)
  527.                       {
  528.                                     cout << "-----------********----------\n";
  529.                                     cout << "ERROR FUNCTION ReturnFileNumber: " << inputString << "\n";
  530.                                     cout << "TRIED TO PARSE " << parseStringT << " BUT DID NOT RETURN INTEGER\n";
  531.                                     cout << "-----------********----------\n\n";
  532.                                                                 system("PAUSE");
  533.                       }  
  534.                       break;
  535.                   }
  536.                  
  537.          }
  538.          while(indexPos !=-1);
  539.      }
  540.                        
  541.                        
  542.      
  543.      return returnedNumber;
  544. }
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557. bool compareNoCase( const string& s1, const string& s2 )
  558. {
  559.      bool returnValue = false;
  560.      if((s1.size()) == (s2.size()))
  561.      {
  562.          returnValue = strcasecmp( s1.c_str(), s2.c_str() ) <= 0;
  563.      }
  564.      else
  565.      {
  566.          returnValue = s1.size() < s2.size();
  567.      }        
  568.     return returnValue;
  569. }
  570.  
  571.  
  572. bool compareNoCaseSameSizeCustom( const string& s1, const string& s2 )
  573. {
  574.      bool returnValue = false;
  575.      if((s1.size()) == (s2.size()))
  576.      {
  577.          returnValue = strcasecmp( s1.c_str(), s2.c_str() ) <= 0;
  578.      }
  579.      else
  580.      {
  581.          return false;
  582.      }        
  583.     return returnValue;
  584. }
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592. void toUpper(string& str) {
  593.     for(int x=0; x<str.length(); x++)
  594.         str[x]=toupper(str[x]);
  595. }
  596.  
  597.  
  598. void toLower(basic_string<char>& s) {
  599.    for (basic_string<char>::iterator p = s.begin();
  600.         p != s.end(); ++p) {
  601.       *p = tolower(*p);
  602.    }
  603. }
  604.  
  605. void toLower(basic_string<wchar_t>& s) {
  606.    for (basic_string<wchar_t>::iterator p = s.begin();
  607.         p != s.end(); ++p) {
  608.       *p = towlower(*p);
  609.    }
  610. }
  611.  
  612.  
  613.  
  614. void listdir (const char *path)
  615. {
  616.     // first off, we need to create a pointer to a directory
  617.     DIR *pdir = NULL; // remember, it's good practice to initialise a pointer to NULL!
  618.     pdir = opendir (path); // "." will refer to the current directory
  619.     struct dirent *pent = NULL;
  620.     if (pdir == NULL) // if pdir wasn't initialised correctly
  621.     { // print an error message and exit the program
  622.         printf ("\nERROR! pdir could not be initialised correctly");
  623.         return; // exit the function
  624.     } // end if
  625.  
  626.     while (pent = readdir (pdir)) // while there is still something in the directory to list
  627.     {
  628.         if (pent == NULL) // if pent has not been initialised correctly
  629.         { // print an error message, and exit the program
  630.             printf ("\nERROR! pent could not be initialised correctly");
  631.             return; // exit the function
  632.         }
  633.         // otherwise, it was initialised correctly. let's print it on the console:
  634.         printf ("%s\n", pent->d_name);
  635.     }
  636.  
  637.     // finally, let's close the directory
  638.     closedir (pdir);
  639. }
  640.  
  641.  
  642.  
  643. // Probes directory path.
  644. // If no directory, creates it. All of it.
  645. // , ofstream& osInput
  646. bool forceDir(basic_string<char>& thePath)
  647. {
  648.      int cursor = 0;
  649.      string returnedString = "blarg";
  650.      bool returnBool = false;
  651.      vector<string> tryStrings;
  652.     DIR *pdir = NULL;
  653.    
  654. //Check if already exists
  655.     pdir = NULL;
  656.     pdir = opendir (thePath.c_str());
  657.          
  658.          if(pdir != NULL)
  659.           {
  660.                   cout << "DIRECTORY " << thePath << " ALREADY EXISTS.";              
  661.                   return true;
  662.           }
  663.           else
  664.           {
  665.               pdir = NULL;
  666.           }
  667.          
  668.          
  669.           if(thePath[0] == '\\')
  670.           {
  671.                         cursor++;
  672.           }
  673.    
  674.  
  675.      do
  676.      {
  677.          
  678.                                   returnedString = CutLeft(thePath,"\\",cursor);
  679.                                   if(returnedString != "blarg")
  680.                                   {
  681.                                                     tryStrings.push_back (returnedString);
  682.                                                     cursor = thePath.find("\\", cursor);
  683.                                                     cursor++;
  684.                                   }
  685.                                   else
  686.                                   {
  687.                                       tryStrings.push_back (thePath);
  688.                                       break;
  689.                                   }
  690.      }
  691.      while(cursor < thePath.size());
  692.      
  693.      if(tryStrings.size() == 0)
  694.      {
  695.                                     cout << "-----------********----------\n";
  696.                                     cout << "ERROR FUNCTION forceDir: " << "\n";
  697.                                     cout << "PARSED VECTOR OF FILE PATHS WAS 0\n";
  698.                                     cout << "-----------********----------\n\n";
  699.                                                                 system("PAUSE");
  700.                           return false;
  701.      }
  702.      
  703.      
  704.      
  705.      cursor = 0;
  706.      string path = "blarg";
  707.      
  708.      do
  709.      {
  710.           pdir = NULL;
  711.           path = tryStrings[cursor];
  712.           pdir = opendir (path.c_str());
  713.          
  714.           if(pdir != NULL)
  715.           {
  716.                             cout << "OPENED " << path << " SUCCESSFULLY\n";
  717. //                                                                system("PAUSE");
  718.                             cursor++;
  719.                             closedir (pdir);
  720.           }
  721.           else
  722.           {
  723.               int tempThrowaway3 = mkdir(path.c_str());
  724.              
  725.               if(tempThrowaway3 == -1)
  726.               {
  727.                                     returnBool = false;
  728.                                     cout << "-----------********----------\n";
  729.                                     cout << "ERROR FUNCTION forceDir: " << "\n";
  730.                                     cout << "COULD NOT FORCE-CREATE DIRECTORY " << path << "\n";
  731.                                     cout << "-----------********----------\n\n";
  732.                                                                 system("PAUSE");
  733.                           return false;
  734.               }
  735.               else
  736.               {
  737.                               cout << "CREATED " << path << " SUCCESSFULLY\n";
  738. //                                                                system("PAUSE");
  739.                               cursor++;
  740.               }
  741.           }
  742.          
  743.       }
  744.      while(cursor < (tryStrings.size()));
  745.      
  746.  
  747.      pdir = opendir (thePath.c_str());
  748.  
  749.      if(pdir != NULL)
  750.      {
  751.              returnBool = true;
  752.              closedir (pdir);
  753.      }
  754.      else
  755.      {
  756.                                     cout << "-----------********----------\n";
  757.                                     cout << "ERROR FUNCTION forceDir: " << "\n";
  758.                                     cout << "FINAL DIRECTORY OPEN CHECK FAILED " << thePath << "\n";
  759.                                     cout << "-----------********----------\n\n";
  760.                                                                 system("PAUSE");
  761.          returnBool = false;
  762.      }
  763.      
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773. /*
  774.     if (!mkdir (".\\dream.in.code"))
  775.     {
  776.         printf ("mkdir() unsuccessful. Terminating...");
  777.         exit (3); // exit after a 3 second pause
  778.     } // otherwise, it was created, so we can continue
  779.     std::cout << "dream.in.code folder created successfully!"
  780.               << "Currently viewing:\n%s\n" << getcwd(NULL,0);
  781.     listdir (".");
  782.     std::cout << "\nMoving into our newly created directory";
  783.     chdir (".\\dream.in.code");
  784.     std::cout << "\nCurrently viewing:\n%s\n" << getcwd(NULL,0);
  785.     listdir (".");
  786.     chdir ("..\\"); // move back one
  787.     rmdir (".\dream.in.code");
  788.     listdir (".");
  789.  
  790.     std::cin.get (); // pause for input
  791.     return EXIT_SUCCESS; // program was executed successfully
  792.  
  793. */
  794.  
  795.      return returnBool;
  796. }
  797. // USAGE:
  798. // ReplaceTag ( left tag, right tag, original value, new value , working string)
  799. // ReplaceTag ("<myTag>","</myTag>","10","15", s1)
  800. // EXCEPTIONS:
  801. // Use "*" for original value to denote that all values should be replaced between
  802. // these tags (you could just use RegX for that anyway)
  803. string ReplaceTag ( const string& s1,const string& s2,const string& s3,const string& s4,const string& s5 )
  804. {
  805.        string returnString = "blarg";
  806.        string currValue = "blarg";
  807.        string leftString = "blarg";
  808.        string rightString = "blarg";
  809.        long long unsigned int place1 = 0;
  810.        long long unsigned int place2 = 0;
  811.        long long unsigned int place3 = 0;
  812.        
  813.        
  814.        
  815.        place1 = FindTagValue(s1,s5);
  816.        if(place1==0)
  817.        {
  818.                                     cout << "-----------********----------\n";
  819.                                     cout << "ERROR FUNCTION replaceTag: " << "\n";
  820.                                     cout << "TAG FIND FAILURE " << s1 << " ; " << s2 << "\n";
  821.                                     cout << "-----------********----------\n\n";
  822.                                                                 system("PAUSE");
  823.        }
  824.        place2 = FindTag(s1,s5);
  825.        if(place2==0)
  826.        {
  827.                                     cout << "-----------********----------\n";
  828.                                     cout << "ERROR FUNCTION replaceTag: " << "\n";
  829.                                     cout << "TAG2 FIND FAILURE " << s1 << " ; " << s2 << " ; " << place1 << "\n";
  830.                                     cout << "-----------********----------\n\n";
  831.                                                                 system("PAUSE");
  832.        }
  833.        currValue = ReadTag( s1, s5);
  834.        
  835.  
  836.        if((compareNoCaseSameSizeCustom(currValue, s3)) || (s3 == "*"))
  837.        {
  838.                              leftString =  s5.substr(0 , place1);
  839.                              rightString =  s5.substr( ((place1+currValue.size())) ,(s5.size() - (place1 + (currValue.size()-1))));
  840.                              returnString = leftString + s4;
  841.                              returnString = returnString + rightString;
  842.        }
  843.        currValue = ReadTag( s1, returnString);
  844.        
  845.        
  846.                                     cout << "-----------********----------\n";
  847.                                     cout << "INFORMATION: " << "\n";
  848.                                     cout << "currValue: " << returnString.size() << " ; " << s5.size() << " ; " << s5 << "\n";
  849.                                     cout << "-----------********----------\n\n";
  850.                                                                 system("PAUSE");
  851.        
  852.        
  853.        if(currValue != s4)
  854.        {
  855.                                     cout << "-----------********----------\n";
  856.                                     cout << "ERROR FUNCTION replaceTag: " << "\n";
  857.                                     cout << "FINAL VALUE MISMATCH incorrect: " << currValue << " ; Correct: " << s4 << "\n";
  858.                                     cout << " (PROB DUE TO TAG READ ERROR)" << "\n";
  859.                                     cout << "-----------********----------\n\n";
  860.                                                                 system("PAUSE");
  861.        }
  862.        
  863.        
  864.        
  865.        
  866.        
  867.        return returnString;
  868. }
  869. string ReplaceTag ( const string& s1,const string& s2,const string& s3,const string& s4,const string& s5,unsigned long long int placeStart )
  870. {
  871.        string returnString = "blarg";
  872.        string currValue = "blarg";
  873.        string leftString = "blarg";
  874.        string rightString = "blarg";
  875.        long long unsigned int place1 = 0;
  876.        long long unsigned int place2 = 0;
  877.        long long unsigned int place3 = 0;
  878.        
  879.        
  880.        
  881.        place1 = FindTagValue(s1,s5,placeStart);
  882.        if(place1==0)
  883.        {
  884.                                     cout << "-----------********----------\n";
  885.                                     cout << "ERROR FUNCTION replaceTag: " << "\n";
  886.                                     cout << "TAG FIND FAILURE " << s1 << " ; " << s2 << "\n";
  887.                                     cout << "-----------********----------\n\n";
  888.                                                                 system("PAUSE");
  889.        }
  890.        place2 = FindTag(s1,s5,placeStart);
  891.        if(place2==0)
  892.        {
  893.                                     cout << "-----------********----------\n";
  894.                                     cout << "ERROR FUNCTION replaceTag: " << "\n";
  895.                                     cout << "TAG2 FIND FAILURE " << s1 << " ; " << s2 << " ; " << place1 << "\n";
  896.                                     cout << "-----------********----------\n\n";
  897.                                                                 system("PAUSE");
  898.        }
  899.        currValue = ReadTag( s1, s2, s5, placeStart);
  900.        
  901.  
  902.        if((compareNoCaseSameSizeCustom(currValue, s3)) || (s3 == "*"))
  903.        {
  904.                              leftString =  s5.substr(0 , place1);
  905.                              rightString =  s5.substr( ((place1+currValue.size())) ,(s5.size() - (place1 + (currValue.size()-1))));
  906.                              returnString = leftString + s4;
  907.                              returnString = returnString + rightString;
  908.        }
  909.        currValue = ReadTag( s1, s2, returnString, place2);
  910.        
  911.        
  912. //                                    cout << "-----------********----------\n";
  913. //                                    cout << "INFORMATION: " << "\n";
  914. //                                    cout << "returnString/InputString: " << returnString.size() << " ; " << s5.size() << " ; " << "\n";
  915. //                                    cout << "-----------********----------\n\n";
  916. //                                                                system("PAUSE");
  917.  
  918.        
  919.        
  920.        if(currValue != s4)
  921.        {
  922.                                     cout << "-----------********----------\n";
  923.                                     cout << "ERROR FUNCTION replaceTag: " << "\n";
  924.                                     cout << "FINAL VALUE MISMATCH incorrect: " << currValue << " ; Correct: " << s4 << "\n";
  925.                                     cout << " (PROB DUE TO READTAG ERROR)" << "\n";
  926.                                     cout << "-----------********----------\n\n";
  927.                                                                 system("PAUSE");
  928.        }
  929.        
  930.        
  931.        
  932.        
  933.        
  934.        return returnString;
  935. }
  936.  
  937. //USAGE:
  938. // CutWhole(<source string>, <open tag>, <close tag>, <integer to start>)
  939. // CutWhole(mySource1, "<hello>", "</hello>", 0)
  940. //
  941. //
  942. // RETURNS: This will add <open tag> and <close tag> to beginning and end of
  943. // whatever content are in the middle of them. Essentially returning a
  944. // Cutout but WITH the tags, too.
  945. string CutWhole(const string& s1, const string& s2, const string& s3, unsigned long long int placeStart)
  946. {
  947.        string tempHolding8080 = "blarg";
  948.        string returnString = "";
  949.        tempHolding8080 = CutOut(s1,s2,s3,placeStart);
  950.        
  951.        //ERRORCHECK
  952.        if(tempHolding8080 == "blarg")
  953.        {
  954.                                     cout << "-----------********----------\n";
  955.                                     cout << "ERROR FUNCTION CutWhole: " << "\n";
  956.                                     cout << "BLARG returned to tempHolding8080: " << tempHolding8080  << "\n";
  957.                                     cout << "(MOST LIKELY RETURNED FROM CUTOUT\nBLARG MEANS FIRST TAG NOT FOUND)" << "\n";
  958.                                     cout << "THIS MOST LIKELY MEANS THAT LESS\n";
  959.                                     cout << "THAN FIVE <GEARKIT>s WERE FOUND\n";
  960.                                     cout << "FATAL ERROR: CLOSE THIS PROGRAM\n";
  961.                                     cout << "AND DO -not- CONTINUE\n";
  962.                                     cout << "-----------********----------\n\n";
  963.                                                                 system("PAUSE");
  964.        }
  965.        
  966.        
  967.        returnString = returnString + s2;
  968.        returnString = returnString + tempHolding8080;
  969.        returnString = returnString + s3;
  970.        
  971.        
  972.        
  973.        
  974.        return returnString;
  975. }
  976.  
  977.  
  978.  
  979.   int main()
  980. {
  981.      
  982.     cout << "============***********************===========\n";
  983.     cout << "............STANDARD EQUIPMENT PROGRAM........\n";
  984.     cout << "============***********************===========\n\n";
  985.    
  986.     srand((unsigned)time(0));
  987.     int throwAway0 = rand() % 9 + 1;
  988.    
  989.     if(throwAway0 == 1)
  990.     {
  991.         cout << "\"THE ONLY GOOD GEARKIT IS A DEAD GEARKIT\"\n\n\n";
  992.     }
  993.     if(throwAway0 == 2)
  994.     {
  995.         cout << "\"WHY DIDNT BIFF GET AN UMBRELLA\"\n\n\n";
  996.     }
  997.     if(throwAway0 == 3)
  998.     {
  999.         cout << "\"FLUGENTE GAVE ME CODER'S RASH\"\n\n\n";
  1000.     }
  1001.     if(throwAway0 == 4)
  1002.     {
  1003.         cout << "\"THEY SAID DEPRI WAS A LADY\"\n\n\n";
  1004.     }
  1005.     if(throwAway0 == 5)
  1006.     {
  1007.         cout << "\"IT'S TOO MUCH WORK\" - JA2 Community\n\n\n";
  1008.     }
  1009.     if(throwAway0 == 6)
  1010.     {
  1011.         cout << "\"CANADIAN CODE IS BEST CODE\"\n\n\n";
  1012.     }
  1013.     if(throwAway0 == 7)
  1014.     {
  1015.         cout << "\"FLUGENTE STOLE ALL OUR BASE\"\n\n\n";
  1016.     }
  1017.     if(throwAway0 == 8)
  1018.     {
  1019.         cout << "\"CVB is on a killstreak of 0!\"\n\n\n";
  1020.     }
  1021.     if(throwAway0 == 9)
  1022.     {
  1023.         cout << "\"silversurfer HAS FIXED THE TRUNK. Again.\"\n\n\n";
  1024.     }
  1025.    
  1026.    
  1027. // ADD PRE-FLIGHT CHECKLIST FOR MORONS WHO DONT READ THE INSTRUCTIONS.txt
  1028.    
  1029.     cout << "-----------------------------------------------\n";
  1030.     cout << "BEGINNING ANALYSIS OF [\\ReplaceWith.txt]\n";
  1031.     cout << "-----------------------------------------------\n\n\n";
  1032.    
  1033.          // DEFINE GEARKIT REPLACEMENTS
  1034.          // READ FROM ReplaceWith.txt
  1035.         string replace1 = "blarg";
  1036.         string replace2 = "blarg";
  1037.         string replace3 = "blarg";
  1038.         string replace4 = "blarg";
  1039.         string replace5 = "blarg";
  1040.        
  1041.        
  1042.        
  1043.         tempS1 = ""; // Holding for ReplaceWith.txt
  1044.         tempS2 = ""; // Temp for CutOut splice
  1045.         tempS1 = ReadContent("ReplaceWith.txt");
  1046.         tempI1 = 0;
  1047.        
  1048.         tempI1 = FindTag("<GEARKIT>",tempS1,0);
  1049.         replace1 = CutOut(tempS1,"<GEARKIT>","</GEARKIT>",tempI1);
  1050.         tempI1++;
  1051.         tempI1 = FindTag("<GEARKIT>",tempS1,tempI1);
  1052.         replace2 = CutOut(tempS1,"<GEARKIT>","</GEARKIT>",tempI1);
  1053.         tempI1++;
  1054.         tempI1 = FindTag("<GEARKIT>",tempS1,tempI1);
  1055.         replace3 = CutOut(tempS1,"<GEARKIT>","</GEARKIT>",tempI1);
  1056.         tempI1++;
  1057.         tempI1 = FindTag("<GEARKIT>",tempS1,tempI1);
  1058.         replace4 = CutOut(tempS1,"<GEARKIT>","</GEARKIT>",tempI1);
  1059.         tempI1++;
  1060.         tempI1 = FindTag("<GEARKIT>",tempS1,tempI1);
  1061.         replace5 = CutOut(tempS1,"<GEARKIT>","</GEARKIT>",tempI1);
  1062.        
  1063.        
  1064.     cout << "-----------------------------------------------\n";
  1065.     cout << "READING OF [\\ReplaceWith.txt] COMPLETE\n";
  1066.     cout << "-----------------------------------------------\n\n\n";
  1067.    
  1068.    
  1069.     cout << "-----------------------------------------------\n";
  1070.     cout << "BEGINNING READ OF [\\Input.txt] \n";
  1071.     cout << "( No it's not frozen, please wait... )\n";
  1072.     cout << "-----------------------------------------------\n\n\n";
  1073.        
  1074.        
  1075.        
  1076.         string inputFileString = "";
  1077.         inputFileString = ReadContent("Input.txt");
  1078.         tempI1 = 0; //PRIMARY CURSOR
  1079.         tempI2 = inputFileString.size(); //End cursor
  1080.         tempI3 = 1; // Count to 5 interator
  1081.         tempS1 = "";
  1082.         tempS2 = "";
  1083.         tempS3 = ""; //DEBUG PURPOSES ONLY
  1084.        
  1085.     cout << "-----------------------------------------------\n";
  1086.     cout << "READING OF [\\Input.txt] COMPLETE\n";
  1087.     cout << "-----------------------------------------------\n\n\n";
  1088.        
  1089.     cout << "-----------------------------------------------\n";
  1090.     cout << "BEGIN PRIMARY REPLACE LOOP\n";
  1091.     cout << "-----------------------------------------------\n\n\n";
  1092.        
  1093.        
  1094.         do
  1095.         {
  1096.                tempI1 = inputFileString.find("<GEARKIT>", tempI1);
  1097.                
  1098.                if(tempI1 == -1)
  1099.                {
  1100.                          cout << "-----------********----------\n";
  1101.                          cout << "PRIMARY REPLACE LOOP COMPLETE\n";
  1102.                          cout << "-----------********----------\n\n\n";
  1103.                          break;
  1104.                }
  1105.                
  1106. //               tempS3 = CutOut(inputFileString, "<GEARKIT>", "</GEARKIT>",tempI1);
  1107. //               cout << "-----------********----------\n";
  1108. //               cout << "INFORMATION: " << "\n";
  1109. //               cout << "Current replace target: \n" << tempS3.size()  << "\n";
  1110. //               cout << "-----------********----------\n\n";
  1111. //               system("PAUSE");
  1112.                
  1113.                if(tempI3==1)
  1114.                {
  1115.                             inputFileString = ReplaceTag( "<GEARKIT>","</GEARKIT>","*",replace1,inputFileString,tempI1 );
  1116.                             tempI3++;
  1117.                             tempI1++;
  1118.                             continue;
  1119.                }
  1120.                if(tempI3==2)
  1121.                {
  1122.                             inputFileString = ReplaceTag( "<GEARKIT>","</GEARKIT>","*",replace2,inputFileString,tempI1 );
  1123.                             tempI3++;
  1124.                             tempI1++;
  1125.                             continue;
  1126.                }
  1127.                if(tempI3==3)
  1128.                {
  1129.                             inputFileString = ReplaceTag( "<GEARKIT>","</GEARKIT>","*",replace3,inputFileString,tempI1 );
  1130.                             tempI3++;
  1131.                             tempI1++;
  1132.                             continue;
  1133.                }
  1134.                if(tempI3==4)
  1135.                {
  1136.                             inputFileString = ReplaceTag( "<GEARKIT>","</GEARKIT>","*",replace4,inputFileString,tempI1 );
  1137.                             tempI3++;
  1138.                             tempI1++;
  1139.                             continue;
  1140.                }
  1141.                if(tempI3==5)
  1142.                {
  1143.                             inputFileString = ReplaceTag( "<GEARKIT>","</GEARKIT>","*",replace5,inputFileString,tempI1 );
  1144.                             tempI3 = 1;
  1145.                             tempI1++;
  1146.                             continue;
  1147.                }
  1148.         }
  1149.         while(true);
  1150.        
  1151.                          cout << "----------------********---------------\n";
  1152.                          cout << "WRITING TO OUTPUT FILE MercStartingGear.xml\n";
  1153.                          cout << "----------------********---------------\n\n";
  1154.        
  1155.        
  1156.    ofstream myfile2;
  1157.    myfile2.open ("MercStartingGear.xml", ios::out);
  1158.  
  1159.    myfile2 << inputFileString;
  1160.    myfile2.close();
  1161.        
  1162.         // TESTING //
  1163. //        cout << replace5 <<"\n\n";
  1164. //        system("PAUSE");
  1165. //        return 0;
  1166.         // TESTING //
  1167.  
  1168.        
  1169.  
  1170.    
  1171.    cout << "--------------\n";
  1172.    cout << "END OF PROGRAM\n";
  1173.    cout << "--------------\n\n";
  1174.  
  1175.     system("PAUSE");
  1176.    
  1177.     return 0;
  1178.    
  1179.  
  1180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement