processor.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #include <string>
  15. #include <vector>
  16. #include <iostream>
  17. #include <fstream>
  18. using namespace std;
  19. string getFileVector(const char* fileName){
  20. vector<string> text;
  21. string line;
  22. ifstream textstream(fileName);
  23. while ( getline(textstream, line) ){
  24. text.push_back(line + "\n");
  25. }
  26. textstream.close();
  27. string alltext;
  28. for (int i=0; i < text.size(); i++)
  29. alltext += text[i];
  30. return alltext;
  31. }
  32. int main(int argc, char* argv[])
  33. {
  34. if (argc != 4) {
  35. fprintf(stderr, "Usage: %s <bash-vars> <input> <output>\n", argv[0]);
  36. return 1;
  37. }
  38. string bashVars = getFileVector(argv[1]);
  39. string inFileContents = getFileVector(argv[2]);
  40. string searchString( "###<REPLACE>###" );
  41. string replaceString( bashVars );
  42. string::size_type pos = 0;
  43. while ( (pos = inFileContents.find(searchString, pos)) != string::npos )
  44. {
  45. inFileContents.replace( pos, searchString.size(), replaceString );
  46. pos++;
  47. }
  48. ofstream outstream(argv[3]);
  49. outstream<<inFileContents;
  50. outstream.close();
  51. return 0;
  52. }