Ident.C

Go to the documentation of this file.
00001 /*
00002  * See the dyninst/COPYRIGHT file for copyright information.
00003  * 
00004  * We provide the Paradyn Tools (below described as "Paradyn")
00005  * on an AS IS basis, and do not warrant its validity or performance.
00006  * We reserve the right to update, modify, or discontinue this
00007  * software at any time.  We shall have no obligation to supply such
00008  * updates or modifications or any other form of support to you.
00009  * 
00010  * By your use of Paradyn, you understand and agree that we (or any
00011  * other person or entity with proprietary rights in Paradyn) are
00012  * under no obligation to provide either maintenance services,
00013  * update services, notices of latent defects, or correction of
00014  * defects for Paradyn.
00015  * 
00016  * This library is free software; you can redistribute it and/or
00017  * modify it under the terms of the GNU Lesser General Public
00018  * License as published by the Free Software Foundation; either
00019  * version 2.1 of the License, or (at your option) any later version.
00020  * 
00021  * This library is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024  * Lesser General Public License for more details.
00025  * 
00026  * You should have received a copy of the GNU Lesser General Public
00027  * License along with this library; if not, write to the Free Software
00028  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00029  */
00030 
00031 /************************************************************************
00032  * Ident.C: build identification functions (for POSIX systems)
00033  * $Id: Ident.C,v 1.6 2008/06/11 22:48:17 legendre Exp $
00034 ************************************************************************/
00035 
00036 #include "common/h/Ident.h"
00037 #include <stdio.h>
00038 #include <string>
00039 #include <iostream>
00040 #include <ostream>
00041 
00042 using namespace std;
00043 
00044 Ident::Ident (const char *Vstr, const char *expected_suite)
00045 {
00046     const int es_len = strlen(expected_suite);  // expected suite name length
00047     char fullrelease[32];            // temporary holder for release_+buildnum_
00048 
00049 #ifdef BROKEN_SSCANF
00050     char *p=strchr(Vstr,' ');
00051     if (!p || ((p-Vstr) > 16)) return;
00052 #endif
00053     int n = sscanf (Vstr, IdentFormat, 
00054         suite_, fullrelease, component_, revision_, date_, time_, builder_);
00055 
00056     ok_ = (n==IdentFields);
00057 
00058     if (n <= 0) {
00059         // parsing failed completely!
00060         cerr << "Warning! Failed to parse identification string:\n<"
00061              << Vstr << ">" << endl;
00062     } else if (n < IdentFields) {
00063         // report how far parsing succeeded
00064         cerr << "Warning! Parsed only " << n << " of " << IdentFields
00065              << " fields from $" << suite_ << " identification string: <"
00066              << Vstr << ">:" << endl;
00067         cerr << "Release=("     << fullrelease << ") "
00068              << "Component=("   << component_ << ") "
00069              << "Revision=("    << revision_ << ") "  
00070              << "Date=("        << date_ << ") "
00071              << "Time=("        << time_ << ") "
00072              << "Builder=("     << builder_ << ") "
00073              << endl;
00074     } else { 
00075         // check Suite is that expected
00076         if (strncmp(expected_suite, suite_, es_len) == 0) {
00077             //cerr << "Successfully parsed $Suite identification string" << endl;
00078             suite_[es_len]='\0';         // remove unnecessary trailing ":"
00079         } else {
00080             if (char *p=strrchr(suite_, ':')) { *p='\0'; }
00081             cerr << "Warning! Identifier contained unexpected suite name: "
00082                  << suite_ << " <=> " << expected_suite << endl;
00083         }
00084         // separate buildnum from release identifier
00085         if (char *p=strrchr(fullrelease, '-')) {
00086             strncpy (buildnum_, p, sizeof(buildnum_));
00087             *p='\0';
00088             strncpy (release_, fullrelease, sizeof(release_));
00089         } else {
00090             //cerr << "No buildnum located in release id " << fullrelease << endl;
00091             strncpy (release_, fullrelease, sizeof(release_));
00092         }
00093     }
00094 }
00095 
00096 Ident::~Ident() { }
00097 
00098 ostream& operator<< (ostream &os, const Ident &Id)
00099 {
00100 #if defined(notdef)
00101     // verbose tagged version intended for debugging
00102     pdstring buf = "{"
00103        + " suite="     + Id.suite()
00104        + " release="   + Id.release()
00105        + " buildnum="  + Id.buildnum()
00106        + " component=" + Id.component()
00107        + " revision="  + Id.revision()
00108        + " date="      + Id.date()
00109        + " time="      + Id.time()
00110        + " builder="   + Id.builder()
00111        + " }";
00112 #else
00113     // concise inline version intended for normal use
00114     char buf[128];
00115     sprintf(buf, IdentOutFmt, Id.suite_,
00116         Id.release_, Id.buildnum_, Id.component_, Id.revision_,
00117         Id.date_, Id.time_, Id.builder_);
00118 #endif
00119 
00120     return os << buf;
00121 }
00122 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 12 Jul 2013 for SymtabAPI by  doxygen 1.6.1