Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

testBdbTimeInput.cc

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: testBdbTimeInput.cc,v 1.2 2004/08/06 05:48:03 bartoldu Exp $
00004 //
00005 // Description:
00006 //      testBdbTimeInput program
00007 //
00008 // Environment:
00009 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00010 //
00011 // Author List:
00012 //      Gregory Dubois-Felsmann  (originator)
00013 //
00014 // Copyright Information:
00015 //      Copyright (C) 2003   California Institute of Technology
00016 //
00017 //------------------------------------------------------------------------
00018 #include "BaBar/BaBar.hh"
00019 
00020 //-----------------
00021 // C/C++ Headers --
00022 //-----------------
00023 #include <string.h>
00024 #include <unistd.h>
00025 #include <iostream>
00026 
00027 //-------------------------------
00028 // Collaborating Class Headers --
00029 //-------------------------------
00030 #include "BdbTime/BdbTimeInput.hh"
00031 using std::cerr;
00032 using std::cout;
00033 using std::endl;
00034 
00035 
00036 int
00037 main( int argc, char* argv[] )
00038 {
00039   char c;
00040   int parseErr = 0;
00041 
00042   bool odate = false;
00043   bool otime = false;
00044   bool quiet = false;
00045 
00046   while ( (c = getopt( argc, argv, "dtq")) != EOF ) {
00047     switch (c) {
00048     case 'd':  // date
00049       odate = true;
00050       break;
00051     case 't':  // time
00052       otime = true;
00053       break;
00054     case 'q':  // quiet: turn off debugging output
00055       quiet = true;
00056       break;
00057     case '?':
00058     default:
00059       parseErr++;
00060     }
00061   }
00062 
00063   // Get number of arguments to expect.
00064   // -d : one
00065   // -t : one
00066   // -dt : two
00067   // (neither) : two (date/time input & format)
00068   const unsigned nexpect = ( odate ^ otime ? 1 : 2 );
00069 
00070   if ( parseErr 
00071        || ( argc - optind ) != nexpect ) {
00072     cerr << "Usage: " << argv[0] << " [-q] { string fmt [ fmt ... ] | -d date | -t time | -dt date time }" << endl;
00073     return 1;
00074   }
00075 
00076   BdbTimeInput::setDebugging( !quiet );
00077   tzset();
00078 
00079   struct tm stm;
00080   memset( &stm, 0, sizeof(stm) );
00081 
00082   const unsigned which = ( odate ? 2 : 0 ) + ( otime ? 1 : 0 );
00083   
00084   BdbTimeInput::Status s;
00085   int retcode = 0;
00086 
00087   switch (which) {
00088   case 0:
00089     s = BdbTimeInput::parseString( argv[optind], argv+optind+1, stm, !quiet );
00090     break;
00091   case 1:
00092     s = BdbTimeInput::parseTime( argv[optind], stm );
00093     break;
00094   case 2:
00095     s = BdbTimeInput::parseDate( argv[optind], stm );
00096     break;
00097   case 3:
00098     s = BdbTimeInput::parseDate( argv[optind], stm );
00099     {
00100       if ( s != BdbTimeInput::Success ) {
00101         ++retcode;
00102         cout << "Date conversion status = " << int(s) << " (failed)" << endl;
00103       }
00104       else if ( !quiet ) {
00105         cout << "Date conversion status = Success" << endl;
00106       }
00107       if ( !quiet ) {
00108         char stime[1024];
00109         size_t l = strftime( stime, 1000, "%c -- zone %Z", &stm );
00110         cout << "strftime() returned " << l 
00111              << ", produced: \"" << stime << "\"" << endl;
00112       }
00113     }
00114     s = BdbTimeInput::parseTime( argv[optind+1], stm );
00115     break;
00116   }
00117 
00118   
00119   if ( s != BdbTimeInput::Success || !quiet ) {
00120     switch (which) {
00121     case 0:
00122       cout << "String";
00123       break;
00124     case 1:
00125     case 3:
00126       cout << "Time";
00127     break;
00128     case 2:
00129       cout << "Date";
00130     break;
00131     }
00132     cout << " conversion status = ";
00133     if ( s != BdbTimeInput::Success ) {
00134       ++retcode;
00135       cout << int(s) << " (failed)" << endl;
00136     }
00137     else {
00138       cout << " Success" << endl;
00139     }
00140   }
00141 
00142   if ( !quiet ) {
00143     char stime[1024];
00144     size_t l = strftime( stime, 1000, "%c -- zone %Z", &stm );
00145     cout << "strftime() returned " << l 
00146          << ", produced: \"" << stime << "\"" << endl;
00147   }
00148 
00149   time_t ttime = mktime( &stm );
00150   if ( ttime == (time_t) -1 ) {
00151     ++retcode;
00152     cout << "Normalization with mktime() failed!" << endl;
00153   }
00154 
00155   char stime[1024];
00156   size_t l = strftime( stime, 1000, "%c -- zone %Z", &stm );
00157   cout << "normalized strftime() produced: \"" << stime << "\"" << endl;
00158 
00159   return retcode;
00160 }

Generated on Mon Dec 5 18:22:13 2005 for CDB by doxygen1.3-rc3