/* * certVersion.c * * Created by Andrew Salamon on Wed Jun 7 2006. * * Copyright (c) 2006 Machine Perception Laboratory * University of California San Diego. * * Please read the disclaimer and notes about redistribution * at the end of this file. * */ #include #include #include /** \file * This file contains functions and static variables for getting the 'current' SVN revision number. * There are two methods used. The first uses Subversion's keyword substitution to put the revision * number and last changed date into string variables. Unfortunately, that method only reflects the * revision/date as of the last modification to this file itself. * The second method requires the build environment to set the value of a pre-processor define macro. * This can be done using the svnrevision tool. */ #ifdef WIN32 #define snprintf _snprintf #endif /** Static variables holding SVN keywords in strings. * These two static variables (lastChangedRevision and lastChangedDate) are probably not going to be accurate * because they only get updated when this file actually changes. * It's far better to use the SVN_REV define or it's revision variable. */ static const char *lastChangedRevision = "$LastChangedRevision$"; static const char *lastChangedDate = "$LastChangedDate$"; #ifndef SVN_REV /** SVN revision pre-processor define. * This needs to be set by the build environment, probably using the svnrevision tool. */ #define SVN_REV "139:173M" #endif static const char *revision = SVN_REV; /** Get a simple integer representation of the SVN Revision number. * This function may not be accurate because the SVN revision number can contain non-numeric info. * For example '128:205M' is a valid SVN revision number. * The string version should be used instead, whenever possible. * The revision number is pulled from the \#define variable first, since that's more likely to be accurate, * but if it doesn't exist the keyword based info will be used. */ int getCertRevision() { static int rev = 0; if( 0 == rev ) { if( strlen( revision ) > 0 ) { int cnt = sscanf( revision, "%d", &rev ); if( cnt != 1 ) rev = -1; } else { int cnt = sscanf( lastChangedRevision, "$LastChangedRevision: %d", &rev ); if( cnt != 1 ) rev = -1; } } return rev; } /** Get a string representation of the SVN Revision number. * This will return the full revision number, possibly a simple integer but possibly something like '128:205M'. * The revision number is pulled from the \#define variable first, since that's more likely to be accurate, * but if that doesn't exist the keyword based info will be used. */ const char *getCertRevisionString() { if( strlen( revision ) <= 0 ) { char revBuf[256]; int cnt = sscanf( lastChangedRevision, "$LastChangedRevision: %255s ", revBuf ); if( cnt != 1 ) revision = "NA"; else { revision = (char *)malloc( strlen(revBuf) + 1 ); strcpy( (char *)revision, revBuf ); } } return revision; } char *getCertRevisionDate() { static char *date = NULL; if( NULL == date ) { char dateBuf[21]; char timeBuf[21]; char tzBuf[21]; int cnt = sscanf( lastChangedDate, "$LastChangedDate: %20s %20s %20s", dateBuf, timeBuf, tzBuf ); if( cnt != 3 ) date = "Unknown build date"; else { unsigned int len = strlen(dateBuf); date = (char *)malloc( len + 3 ); snprintf( date, len-1, "%s", dateBuf ); } } return date; } /* * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */