source: trunk/third/tiff/libtiff/mkversion.c @ 18174

Revision 18174, 5.1 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18173, which included commits to RCS files with non-trunk default branches.
Line 
1/* "$Header: /afs/dev.mit.edu/source/repository/third/tiff/libtiff/mkversion.c,v 1.1.1.1 2002-12-26 02:37:33 ghudson Exp $ */
2
3/*
4 * Copyright (c) 1995-1997 Sam Leffler
5 * Copyright (c) 1995-1997 Silicon Graphics, Inc.
6 *
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the names of
11 * Sam Leffler and Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler and Silicon Graphics.
14 *
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
18 *
19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 * OF THIS SOFTWARE.
25 */
26
27/*
28 * Generate a library version string for systems that
29 * do not have a shell (by default this is done with
30 * awk and echo from the Makefile).
31 *
32 * This was written by Peter Greenham for Acorn systems.
33 *
34 * Syntax: mkversion [-v version-file] [-a alpha-file] [<outfile>]
35 */
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39
40static void
41usage(void)
42{
43    fprintf(stderr,
44            "usage: mkversion [-v version-file] [-a alpha-file]\n"
45            "                 [-r releasedate-file] [outfile]\n");
46    exit(-1);
47}
48
49static FILE*
50openFile(char* filename)
51{
52    FILE* fd = fopen(filename, "r");
53    if (fd == NULL) {
54        fprintf(stderr, "mkversion: %s: Could not open for reading.\n",
55            filename);
56        exit(-1);
57    }
58    return (fd);
59}
60
61int
62main(int argc, char* argv[])
63{
64    char* versionFile = "../VERSION";
65    char* releaseDateFile = "../RELEASE-DATE";
66    char* alphaFile = "../dist/tiff.alpha";
67    char version[128];
68    char rawReleaseDate[128];
69    char tiffLibVersion[128];
70    char alpha[128];
71    FILE* fd;
72    char* cp;
73
74    argc--, argv++;
75    while (argc > 0 && argv[0][0] == '-') {
76        if (strcmp(argv[0], "-v") == 0) {
77            if (argc < 1)
78                usage();
79            argc--, argv++;
80            versionFile = argv[0];
81        } else if (strcmp(argv[0], "-a") == 0) {
82            if (argc < 1)
83                usage();
84            argc--, argv++;
85            alphaFile = argv[0];
86        } else if (strcmp(argv[0], "-r") == 0) {
87            if (argc < 1)
88                usage();
89            argc--, argv++;
90            releaseDateFile = argv[0];
91        } else
92            usage();
93        argc--, argv++;
94    }
95
96    /*
97     * Read the VERSION file.
98     */
99    fd = openFile(versionFile);
100    if (fgets(version, sizeof (version)-1, fd) == NULL) {
101        fprintf(stderr, "mkversion: No version information in %s.\n",
102            versionFile);
103        exit(-1);
104    }
105    cp = strchr(version, '\n');
106    if (cp)
107        *cp = '\0';
108    fclose(fd);
109    fd = openFile(alphaFile);
110    if (fgets(alpha, sizeof (alpha)-1, fd) == NULL) {
111        fprintf(stderr, "mkversion: No alpha information in %s.\n", alphaFile);
112        exit(-1);
113    }
114    fclose(fd);
115    cp = strchr(alpha, ' ');            /* skip to 3rd blank-separated field */
116    if (cp)
117        cp = strchr(cp+1, ' ');
118    if (cp) {                           /* append alpha to version */
119        char* tp;
120        for (tp = strchr(version, '\0'), cp++; (*tp = *cp) != 0; tp++, cp++)
121            ;
122        if (tp[-1] == '\n')
123            tp[-1] = '\0';
124    } else {
125        fprintf(stderr, "mkversion: Malformed alpha information in %s.\n",
126            alphaFile);
127        exit(-1);
128    }
129
130    /*
131     * Read the RELEASE-DATE, and translate format to emit TIFFLIB_VERSION.
132     */
133    fd = openFile(releaseDateFile);
134    if (fgets(rawReleaseDate, sizeof (version)-1, fd) == NULL) {
135        fprintf(stderr, "mkversion: No release date information in %s.\n",
136                releaseDateFile);
137        exit(-1);
138    }
139    fclose(fd);
140
141    sprintf( tiffLibVersion, "#define TIFFLIB_VERSION %4.4s%2.2s%2.2s",
142             rawReleaseDate+6,
143             rawReleaseDate+0,
144             rawReleaseDate+3 );
145   
146    /*
147     * Emit the version.h file.
148     */
149    if (argc > 0) {
150        fd = fopen(argv[0], "w");
151        if (fd == NULL) {
152            fprintf(stderr, "mkversion: %s: Could not open for writing.\n",
153                argv[0]);
154            exit(-1);
155        }
156    } else
157        fd = stdout;
158    fprintf(fd, "#define TIFFLIB_VERSION_STR \"LIBTIFF, Version %s\\n", version);
159    fprintf(fd, "Copyright (c) 1988-1996 Sam Leffler\\n");
160    fprintf(fd, "Copyright (c) 1991-1996 Silicon Graphics, Inc.\"\n");
161
162    fprintf( fd,
163             "/*\n"
164             " * This define can be used in code that requires\n"
165             " * compilation-related definitions specific to a\n"
166             " * version or versions of the library.  Runtime\n"
167             " * version checking should be done based on the\n"
168             " * string returned by TIFFGetVersion.\n"
169             " */\n" );
170    fprintf(fd, "%s\n", tiffLibVersion );
171
172    if (fd != stdout)
173        fclose(fd);
174    return (0);
175}
Note: See TracBrowser for help on using the repository browser.