Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

SctRodDaqVersion.cpp

00001 #include "Sct/Version.h"
00002 #include "Sct/SctNames.h"
00003 #include <iostream>
00004 #include <fstream>
00005 #include <cstring>
00006 #include <sstream>
00007 #include <stdlib.h>
00008 using namespace Sct;
00009 using namespace std;
00010 
00011 
00012 void longVersion() {
00013     cout << "VersionString:" << VersionString << endl;
00014     cout << "MajorVersion: " << MajorVersion << " Minor Version: " << MinorVersion << " Modifier: " << VersionModifier << endl;
00015     cout << "Version: " << Version << endl;
00016     cout << "BuildSystem: " << BuildSystem << endl;
00017     cout << "BuildHost: " << BuildHost << endl;
00018     cout << "BuildDate: " << BuildDate << endl;
00019     cout << "RodDaq Version: " << RodDaqVersion << endl;
00020     cout << "CmtConfig: " << CmtConfig << endl;
00021     cout << "Dataflow Version: " << DataFlowVersion << endl;
00022     cout << "OnlineVersion : " << OnlineVersion << endl;
00023     cout << "RootVersion: " << RootVersion << endl;
00024     cout << "GccVersion: " << GccVersion << endl;    
00025 }
00026 
00027 void shortVersion() {
00028     cout << Version << VersionModifier << endl;
00029 }
00030 
00031 void check_equal_command(string cmd, string check_output, string label){
00032   istringstream iss(check_output);
00033   iss>>check_output;
00034   ostringstream oss;  oss << SctNames::getTempDir() << "/SctRodDaqVersion.XXXXXX";
00035   char tempfile_template[oss.str().size()];
00036   char* tempfile = tempfile_template;
00037   strcpy(tempfile, oss.str().c_str());
00038   mkstemp(tempfile);
00039 
00040   string fullcmd=cmd;  
00041   fullcmd += " > "; fullcmd += tempfile;
00042   if (system (fullcmd.c_str() ) !=0 ) {
00043     cerr << "Error executing command :" << cmd << endl;
00044     exit(1);
00045   }
00046 
00047   string output; ifstream f(tempfile); f>>output;
00048   system( (string("rm -f ")+tempfile).c_str() );
00049 
00050   if (output != check_output) {
00051     cerr << "SctRodDaqVersion: output of command `" << cmd << "'" 
00052      << " was : `" << output << "'" << endl 
00053      << "... but I think I was built with " << label << " = `" << check_output<< "'" << endl;
00054     exit(1);
00055   }else{
00056     cout << "SctRodDaqVersion: Checked " << label << "\t=\t" << check_output << endl;
00057   }
00058 }
00059 
00060 void checkVersion(){
00061   check_equal_command ( string ("echo $CMTCONFIG"), CmtConfig, "CmtConfig   ");
00062   check_equal_command ( string ("echo $CMTRELEASE"), OnlineVersion, "OnlineVersion");
00063   check_equal_command ( string ("echo $DF_INST_PATH | sed -e \"s@.*/\\\(DF-[0-9]\\+-[0-9]\\+-[0-9]\\+\\).*@\\1@\""), DataFlowVersion, "DataFlow");
00064   check_equal_command ( string ("root-config --version"), RootVersion, "RootVersion");
00065   check_equal_command ( string ("gcc -dumpversion"), GccVersion, "GccVersion   ");
00066   exit(0);
00067 }
00068 
00069 void helpMessage() {
00070     cout << "Prints out version information about the SctRodDaq system." << endl << endl;
00071     cout << "Usage: SctRodDaqVersion <options>" << endl;
00072     cout << "Possible options are: " << endl;
00073     cout << "\t-h, --help\t\tPrint this help message" << endl;
00074     cout << "\t-l, --long\t\tPrint out all version information" << endl;
00075     cout << "\t-s, --short\t\tPrint out short version information" << endl;
00076     cout << "\t-c, --check\t\tCheck versions" << endl;
00077     cout << endl << "If no option is given, the default is -s" << endl;
00078 }
00079 
00080 void handleShortArg(char arg) {
00081     switch (arg) {
00082     case 'h':
00083     helpMessage();
00084     break;
00085     case 'l':
00086     longVersion();
00087     break;
00088     case 's':
00089     shortVersion();
00090     break;
00091     case 'c':
00092     checkVersion();
00093     default:
00094     cout << "Argument -" << arg << " not recognized" << endl;
00095     }
00096 }
00097 
00098 void handleLongArg(const char* arg) {
00099     if (strcmp(arg, "--help") == 0) return handleShortArg('h');
00100     if (strcmp(arg, "--long") == 0) return handleShortArg('l');
00101     if (strcmp(arg, "--short") == 0) return handleShortArg('s');
00102     if (strcmp(arg, "--check") == 0) return handleShortArg('c');
00103     cout << "Argument " << arg << " not recognized" << endl;
00104     helpMessage();
00105 }
00106 
00107 void handleArg(const char* arg) {
00108     if (arg[0] != '-') {
00109     cout << "Argument " << arg << " not recognized" << endl;
00110     helpMessage();
00111     return;
00112     }
00113     if (strlen(arg) == 2) handleShortArg(arg[1]);
00114     else handleLongArg(arg);
00115 }
00116 
00117 int main(int argc, char** argv) {
00118     //Handle args
00119     switch (argc) {
00120     case 1:
00121     shortVersion();
00122     break;
00123     case 2:
00124     handleArg(argv[1]);
00125     break;
00126     default:
00127     helpMessage();
00128     }
00129     return 0;
00130 }

Generated on Thu Jul 15 09:50:53 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5