source: release-kits/shared/windows/wirk.cpp@ 19845

Last change on this file since 19845 was 19845, checked in by oranfry, 15 years ago

tee.exe now part of wirk release kits so we can put the output of wirk into release directory

File size: 3.4 KB
Line 
1#include <windows.h>
2
3#include <fstream>
4#include <iostream>
5#include <string>
6#include <sstream>
7
8#ifndef XXX
9#define XXX 2
10#endif
11
12using namespace std;
13
14void 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}
24
25void show_help() {
26
27 cout << "Wirk" << XXX << " - Windows Release Kit for Greenstone" << XXX << endl;
28 cout << "Helps you to create releases from the Repository" << endl << endl;
29
30 cout << "usage: wirk" << XXX << " [args]" << endl;
31 cout << " -sim" << endl;
32 cout << " simulation only, don't actually do anything" << endl << endl;
33
34 cout << " -help" << endl;
35 cout << " show this help screen" << endl << endl;
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
48
49int main(int argc, char** argv ) {
50
51 //some checks
52 bool ok = true;
53 if ( getenv( "JAVA_HOME" ) == NULL ) {
54 cerr << "Please set JAVA_HOME before running wirk" << XXX << endl;
55 ok = false;
56 }
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;
65 ok = false;
66 }
67 if ( !ok ) {
68 return -1;
69 }
70
71 //load environment variables
72 string JAVA_HOME = getenv( "JAVA_HOME" );
73 string WIRK_HOME = getenv( wirk_home_var.c_str() );
74 putenv( ("ANT_HOME=" + WIRK_HOME + "\\core\\ant").c_str() );
75
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" );
83
84 //create the command
85 stringstream command;
86 command << "cmd.exe /c " << WIRK_HOME << "\\core\\ant\\bin\\ant.bat -f \"" << WIRK_HOME << "\\ant-scripts\\build.xml\" -addressing \"-Dwirk" << XXX << ".home=" << WIRK_HOME << "\"";
87
88 //pass on the arguments
89 string a;
90 bool simMode = false;
91 for ( int i=1; i < argc; i++ ) {
92 a = argv[i];
93
94 if ( a.compare("-help") == 0 || a.compare("--help") == 0 ) {
95 show_help();
96 return 0;
97 } else if ( a.compare("-sim") == 0) {
98 command << " " << a;
99 simMode = true;
100 } else {
101 command << " " << a;
102 }
103
104 }
105
106 //set the basedir in the command
107 command << " \"-Dbasedir=" << pwd << "\"";
108
109 //pipe it all to tee
110 command << " | " << WIRK_HOME << "\\windows\\util\\tee.exe " << pwd << "\\wirk" << XXX << ".out";
111
112 cout
113 << "O-----------------------------------------O" << endl
114 << "| |" << endl
115 << "| WiRK" << XXX << " |" << endl
116 << "| Windows Release Kit for Greenstone" << XXX << " |" << endl
117 << "| |" << endl
118 << "O-----------------------------------------O" << endl
119 ;
120
121 string final_command = command.str();
122 cout << "pwd: " << pwd << endl;
123 cout << "command: " << final_command << endl;
124
125 system( final_command.c_str() );
126
127 return 0;
128
129}
Note: See TracBrowser for help on using the repository browser.