[15023] | 1 | #include <windows.h>
|
---|
| 2 |
|
---|
| 3 | #include <fstream>
|
---|
| 4 | #include <iostream>
|
---|
| 5 | #include <string>
|
---|
[19467] | 6 | #include <sstream>
|
---|
[15023] | 7 |
|
---|
[19467] | 8 | #ifndef XXX
|
---|
| 9 | #define XXX 2
|
---|
| 10 | #endif
|
---|
| 11 |
|
---|
[15023] | 12 | using namespace std;
|
---|
| 13 |
|
---|
| 14 | void replace_all ( std::string & str, std::string const & pattern, std::string const & replacement ) {
|
---|
| 15 |
|
---|
| 16 | std::string::size_type start = str.find( pattern, 0 );
|
---|
| 17 |
|
---|
| 18 | while ( start != str.npos ) {
|
---|
| 19 | str.replace( start, pattern.size(), replacement );
|
---|
| 20 | start = str.find( pattern, start+replacement.size() );
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | }
|
---|
[16948] | 24 |
|
---|
| 25 | void show_help() {
|
---|
| 26 |
|
---|
[19467] | 27 | cout << "Wirk" << XXX << " - Windows Release Kit for Greenstone" << XXX << endl;
|
---|
[16948] | 28 | cout << "Helps you to create releases from the Repository" << endl << endl;
|
---|
| 29 |
|
---|
[19467] | 30 | cout << "usage: wirk" << XXX << " [args]" << endl;
|
---|
[16948] | 31 | cout << " -sim" << endl;
|
---|
[17043] | 32 | cout << " simulation only, don't actually do anything" << endl << endl;
|
---|
[16948] | 33 |
|
---|
| 34 | cout << " -help" << endl;
|
---|
[17043] | 35 | cout << " show this help screen" << endl << endl;
|
---|
[16948] | 36 |
|
---|
| 37 | cout << " -from <target>" << endl;
|
---|
| 38 | cout << " start execution from the target with the given target address" << endl << endl;
|
---|
| 39 |
|
---|
| 40 | cout << " -to <target>" << endl;
|
---|
| 41 | cout << " stop execution just before the target with the given target address" << endl << endl;
|
---|
| 42 |
|
---|
| 43 | cout << " -descend <target>" << endl;
|
---|
| 44 | cout << " execute only the target with the given address, including subtargets" << endl << endl;
|
---|
| 45 |
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[15023] | 48 |
|
---|
| 49 | int main(int argc, char** argv ) {
|
---|
| 50 |
|
---|
[17379] | 51 | //some checks
|
---|
| 52 | bool ok = true;
|
---|
| 53 | if ( getenv( "JAVA_HOME" ) == NULL ) {
|
---|
[19467] | 54 | cerr << "Please set JAVA_HOME before running wirk" << XXX << endl;
|
---|
[17379] | 55 | ok = false;
|
---|
| 56 | }
|
---|
[19467] | 57 |
|
---|
| 58 | stringstream out;
|
---|
| 59 | out << "WIRK" << XXX << "_HOME";
|
---|
| 60 | string wirk_home_var;
|
---|
| 61 | wirk_home_var = out.str();
|
---|
| 62 |
|
---|
| 63 | if ( getenv( wirk_home_var.c_str() ) == NULL ) {
|
---|
| 64 | cerr << "Please set " << wirk_home_var << " before running wirk" << XXX << endl;
|
---|
[17379] | 65 | ok = false;
|
---|
| 66 | }
|
---|
| 67 | if ( !ok ) {
|
---|
| 68 | return -1;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | //load environment variables
|
---|
[15023] | 72 | string JAVA_HOME = getenv( "JAVA_HOME" );
|
---|
[19467] | 73 | string WIRK_HOME = getenv( wirk_home_var.c_str() );
|
---|
| 74 | putenv( ("ANT_HOME=" + WIRK_HOME + "\\core\\ant").c_str() );
|
---|
[19324] | 75 |
|
---|
[15356] | 76 | //get the pwd
|
---|
| 77 | string pwd;
|
---|
| 78 | system( "CD > cd.dat" );
|
---|
| 79 | ifstream file( "cd.dat" ) ;
|
---|
| 80 | getline(file, pwd);
|
---|
| 81 | file.close();
|
---|
| 82 | system( "del cd.dat" );
|
---|
[17379] | 83 |
|
---|
[15023] | 84 | //create the command
|
---|
[19467] | 85 | stringstream command;
|
---|
[19848] | 86 | command << "c:\\windows\\cmd.exe /c " << WIRK_HOME << "\\core\\ant\\bin\\ant.bat -f \"" << WIRK_HOME << "\\ant-scripts\\build.xml\" -addressing \"-Dwirk" << XXX << ".home=" << WIRK_HOME << "\"";
|
---|
[19452] | 87 |
|
---|
[15023] | 88 | //pass on the arguments
|
---|
| 89 | string a;
|
---|
[16931] | 90 | bool simMode = false;
|
---|
[19467] | 91 | for ( int i=1; i < argc; i++ ) {
|
---|
[15023] | 92 | a = argv[i];
|
---|
[19452] | 93 |
|
---|
[16948] | 94 | if ( a.compare("-help") == 0 || a.compare("--help") == 0 ) {
|
---|
| 95 | show_help();
|
---|
[15023] | 96 | return 0;
|
---|
[16931] | 97 | } else if ( a.compare("-sim") == 0) {
|
---|
[19467] | 98 | command << " " << a;
|
---|
[16931] | 99 | simMode = true;
|
---|
[15023] | 100 | } else {
|
---|
[19467] | 101 | command << " " << a;
|
---|
[15023] | 102 | }
|
---|
| 103 |
|
---|
| 104 | }
|
---|
[15356] | 105 |
|
---|
[15023] | 106 | //set the basedir in the command
|
---|
[19467] | 107 | command << " \"-Dbasedir=" << pwd << "\"";
|
---|
[15356] | 108 |
|
---|
[19845] | 109 | //pipe it all to tee
|
---|
[19846] | 110 | command << " | " << WIRK_HOME << "\\windows\\utils\\tee.exe " << pwd << "\\wirk" << XXX << ".out";
|
---|
[19845] | 111 |
|
---|
[15095] | 112 | cout
|
---|
| 113 | << "O-----------------------------------------O" << endl
|
---|
| 114 | << "| |" << endl
|
---|
[19467] | 115 | << "| WiRK" << XXX << " |" << endl
|
---|
| 116 | << "| Windows Release Kit for Greenstone" << XXX << " |" << endl
|
---|
[15095] | 117 | << "| |" << endl
|
---|
| 118 | << "O-----------------------------------------O" << endl
|
---|
| 119 | ;
|
---|
[15023] | 120 |
|
---|
[19467] | 121 | string final_command = command.str();
|
---|
[15023] | 122 | cout << "pwd: " << pwd << endl;
|
---|
[19467] | 123 | cout << "command: " << final_command << endl;
|
---|
[15023] | 124 |
|
---|
[19467] | 125 | system( final_command.c_str() );
|
---|
[15023] | 126 |
|
---|
| 127 | return 0;
|
---|
| 128 |
|
---|
[16190] | 129 | }
|
---|