[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: script to put svn revision number in c source file

From: Jonathan Leffler <jleffler_at_us.ibm.com>
Date: 2004-03-29 21:29:27 CEST

I'm not exactly sure what you mean by 'script' - this C code probably
doesn't count,
though. However, FWIW (probably nothing) this is the code I use to deal
with this
problem.

const char *(err_rcs_string)(const char *s2, char *buffer, size_t buflen)
{
    const char *src = s2;
    char *dst = buffer;
    char *end = buffer + buflen - 1;

    /*
    ** Bother RCS! We've probably been given something like:
    ** "$Revision: 8.6 $ ($Date: 2003/08/05 22:19:58 $)"
    ** We only want to emit "7.5 (2001/08/11 06:25:48)".
    ** Skip the components between '$' and ': ', copy up to ' $',
    ** repeating as necessary. And we have to test for overflow!
    ** Also work with the unexpanded forms of keywords ($Keyword$).
    ** Never needed this with SCCS!
    */
    while (*src != '\0' && dst < end)
    {
        while (*src != '\0' && *src != '$')
        {
            *dst++ = *src++;
            if (dst >= end)
                break;
        }
        if (*src == '$')
            src++;
        while (*src != '\0' && *src != ':' && *src != '$')
            src++;
        if (*src == '\0')
            break;
        if (*src == '$')
        {
            /* Unexpanded keyword '$Keyword$' notation */
            src++;
            continue;
        }
        if (*src == ':')
            src++;
        if (*src == ' ')
            src++;
        while (*src != '\0' && *src != '$')
        {
            *dst++ = *src++;
            if (dst >= end)
                break;
        }
        if (*src == '$')
        {
            if (*(dst-1) == ' ')
                dst--;
            src++;
        }
    }
    *dst = '\0';
    return(buffer);
}

This is a verbatim extract from code in a file, stderr.c (header stderr.h)

that is available in a number of places, including the package SQLCMD
available from the Informix International Users Group software archive at
http://www.iiug.org/software (probably requires a free subscription;
contact
me directly if you want it separately). You'd also find it in practically
anything else I've written - but the majority of that is available mainly
on the IIUG web site too.

(And, if you're intested in arcana, you'll observe that RCS - it is the
VCS I still use for my own stuff still, pending migration to Subversion -
has updated the '$Revision: ... $ ($Date: ... $)' part of the comment
while being unable to alter the original contracted version - hence the
disagreement between the two lines.)

--
Jonathan Leffler (jleffler@us.ibm.com)
STSM, Informix Database Engineering, IBM Data Management
4100 Bohannon Drive, Menlo Park, CA 94025
Tel: +1 650-926-6921   Tie-Line: 630-6921
      "I don't suffer from insanity; I enjoy every minute of it!"
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Mon Mar 29 21:30:14 2004

This is an archived mail posted to the Subversion Users mailing list.