Back to index

lightning-sunbird  0.9+nobinonly
Functions
dirver.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

Go to the source code of this file.

Functions

unsigned _CalcVersion (unsigned nMajor, unsigned nMinor, unsigned nPatch)
static void _GetVersions (char *szVer, unsigned *nMajor, unsigned *nMinor, unsigned *nPatch)
unsigned _CalcBuildDate (unsigned nYear, unsigned nMonth, unsigned nDay)
unsigned _GenBuildDate (char *szBuildDate)
static void ShowHelp (char *szFilename)
 main (int nArgc, char **lpArgv)

Function Documentation

unsigned _CalcBuildDate ( unsigned  nYear,
unsigned  nMonth,
unsigned  nDay 
)

Definition at line 112 of file dirver.c.

{
    unsigned nBuildDate = 0;

    if(nYear < 1900) /* they really mean 1900 + nYear */
        nYear += 1900;

    nYear -= 1980;
    nBuildDate = nYear;
    /*
    nBuildDate <<= 5;
    */
    nBuildDate <<= 4;
    nBuildDate += nMonth;
    /* nBuildDate <<= 4; */
    nBuildDate <<= 5; 
    nBuildDate += nDay;
    nBuildDate &= 0xFFFF;
    return(nBuildDate);
}

Here is the caller graph for this function:

unsigned _CalcVersion ( unsigned  nMajor,
unsigned  nMinor,
unsigned  nPatch 
)

Definition at line 72 of file dirver.c.

{
    unsigned nVersion;
    nVersion = nMajor;
    nVersion <<= 5;
    nVersion += nMinor;
    nVersion <<= 7;
    nVersion += nPatch;
    nVersion &= 0xFFFF;
    return(nVersion);
}

Here is the caller graph for this function:

unsigned _GenBuildDate ( char *  szBuildDate)

Definition at line 135 of file dirver.c.

{
    unsigned nReturn = 0;
    char *szToken;
    unsigned nYear = 0;
    unsigned nMonth = 0;
    unsigned nDay = 0;

    if((szBuildDate) && (strchr(szBuildDate, '\\') || strchr(szBuildDate, '/')) && (szToken = strtok(szBuildDate, "\\/")))
    {
        nMonth = atoi(szToken);
       nMonth--;     /* use months in the range [0..11], as in struct tm */
        if(szToken = strtok(NULL, "\\/"))
        {
            nDay = atoi(szToken);
            if(szToken = strtok(NULL, "\\/"))
            {
                nYear = atoi(szToken);
              if(nYear < 70) { /* handle 2 digit years like (20)00 */ 
                  nYear += 100;
              }
              else if (nYear < 100) {
              }
              else if (nYear > 1900){
                  nYear -= 1900;
              }
            }
        }
    }
    else
    {
              struct tm *newtime;
              time_t ltime;

              time( &ltime );

        /* Obtain coordinated universal time: */
              newtime = gmtime( &ltime );
        nYear = newtime->tm_year;
        nMonth = newtime->tm_mon;
        nDay = newtime->tm_mday;
    }

    nReturn = _CalcBuildDate(nYear, nMonth, nDay);
    return(nReturn);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void _GetVersions ( char *  szVer,
unsigned *  nMajor,
unsigned *  nMinor,
unsigned *  nPatch 
) [static]

Definition at line 85 of file dirver.c.

{
    char szVersion[128];
    unsigned nReturn = 0;
    char *szToken;
    *nMajor = 0;
    *nMinor = 0;
    *nPatch = 0;

    strcpy(szVersion, szVer);
    if(szToken = strtok(szVersion, ".\n"))
    {
        *nMajor = atoi(szToken);
        if(szToken = strtok(NULL, ".\n"))
        {
            *nMinor = atoi(szToken);
            if(szToken = strtok(NULL, ".\n"))
            {
                *nPatch = atoi(szToken);
            }
        }
    }
}

Here is the caller graph for this function:

main ( int  nArgc,
char **  lpArgv 
)

Definition at line 199 of file dirver.c.

{
    int nReturn = 0;
    unsigned nVersion = 0;
    unsigned nBuildDate = 0;

#ifdef macintosh
       nArgc = ccommand( &lpArgv );
#endif

    if(nArgc < 2)
    {
        ShowHelp(lpArgv[0]);
        nReturn = 1;
    }
    else
    {
        char *szVersion = NULL;
        char *szDate = NULL;
        char *szOutput = NULL;
        FILE *f = stdout;
              unsigned nMajor = 0;
              unsigned nMinor = 0;
              unsigned nPatch = 0;

        szVersion = (char *)lpArgv[1];
        szDate = (char *)lpArgv[2];
        szOutput = (char *)lpArgv[3];
              _GetVersions( szVersion, &nMajor, &nMinor, &nPatch );
              nVersion = _CalcVersion(nMajor, nMinor, nPatch);
        nBuildDate = _GenBuildDate(szDate);

        if(nArgc >= 4) {
            if (( f = fopen(szOutput, "w")) == NULL ) {
              perror( szOutput );
              exit( 1 );
           }
       }

        fprintf(f, "#define VI_PRODUCTVERSION %u.%u\n", nMajor, nMinor);
        fprintf(f, "#define PRODUCTTEXT \"%s\"\n", szVersion );
        fprintf(f, "#define VI_FILEVERSION %u, 0, 0,%u\n",
                            nVersion, nBuildDate);
        fprintf(f, "#define VI_FileVersion \"%s Build %u\\0\"\n",
                            szVersion, nBuildDate);

        if(nArgc >= 4)
            fclose(f);
        nReturn = (nVersion && !nBuildDate);
    }
    return(nReturn);
}

Here is the call graph for this function:

static void ShowHelp ( char *  szFilename) [static]

Definition at line 184 of file dirver.c.

{
    fprintf(stdout, "%s: Generates ascii format #define for FILEVERSION\n", szFilename);
    fprintf(stdout, "   resource identifier used by Windows executable binaries.\n");
    fprintf(stdout, "\n");
    fprintf(stdout, "Usage: %s <major.minor.patch> [mm/dd/yy] [outfile]\n", szFilename);
    fprintf(stdout, "\n");
    fprintf(stdout, "Examples:\n");
    fprintf(stdout, "%s 3.0.0\n", szFilename);
    fprintf(stdout, "%s 6.5.2 1/30/2001\n", szFilename);
    fprintf(stdout, "%s 6.5.2 1/30/2001 fileversion.h\n", szFilename);
}

Here is the call graph for this function:

Here is the caller graph for this function: