/*
 * mkversion.c
 *
 * Syntax: mkversion <infile> [<outfile>]
 */

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
	FILE* infile = NULL;
	FILE* outfile = NULL;
	char ch;

	switch (argc)
	{
		case 2:
		{
			infile = fopen(argv[1], "r");
			if (!infile)
			{
				printf("File %s would not open for input.\n", argv[1]);
				exit(EXIT_FAILURE);
			}
			outfile = stdout;
			break;
		}
		case 3:
		{
			infile = fopen(argv[1], "r");
			if (!infile)
			{
				printf("File %s would not open for input.\n", argv[1]);
				exit(EXIT_FAILURE);
			}
			outfile = fopen(argv[2], "w");
			if (!outfile)
			{
				printf("File %s would not open for output.\n", argv[2]);
				exit(EXIT_FAILURE);
			}
			break;
		}
		default:
		{
			printf("Syntax: mkversion <infile> [<outfile>]\n");
			exit(EXIT_FAILURE);
		}
	}

	fputs("#define VERSION \"LIBTIFF, Version ", outfile);
	ch = fgetc(infile);
	while (ch >= ' ')
	{
		fputc(ch, outfile);
		ch = fgetc(infile);
	}
	fputs("\\nCopyright (c) 1988-1995 Sam Leffler\\nCopyright (c) 1991-1995 Silicon Graphics, Inc.\"\n", outfile);

	fclose(infile);
	if (outfile != stdout) fclose(outfile);

	exit(EXIT_SUCCESS);
}
