/*
**  Version 1.00 - by D. Clarke 22/07/94
**
**  Searches a file for the Amiga version string
**  and prints out the information found. This is
**  useful for checking the versions of programs
**  downloaded onto machines other than the Amiga.
**
**  The source has been compiled under both MS-DOS
**  and Unix (DEC3100). I can't see that there
**  should be any problems in compiling the code
**  under any other operating system as it is pure
**  ANSI C. If any problems are found I can be
**  contacted at the following E-Mail address until
**  the end of September 94 :
**
**  	p9365141@athmail1.causeway.qub.ac.uk
**
**  The code is Copyright (c) 1994 by D. Clarke.
**  However feel free to make any enhancements you
**  wish. I just don't want people changing the
**  code and leaving my name on it (so I get blamed
**  for their mistakes as well as my own!). If you
**  do make any improvements, I would appreciate a
**  copy.
**
**  This software is Freeware. This software is
**  supplied "AS IS" without warranty of any kind,
**  either expressed or implied. By using it, you
**  agree to accept the entire risk as to the
**  quality and performance of the program.
*/


#include <stdio.h>

main(int argc, char *argv[])
{
	FILE *fp;
	int  found = 0;
	int  c;
	char *version = "$VER: Version 1.00 (22.07.94)\0";

	/* Check if no arguments have been given */
	if (argc == 1)
	{
		fprintf(stderr, "Usage: version filename\n");
	}
	else
	{
		/* Attempt to open file */
		if ((fp = fopen(*++argv, "rb")) == NULL)
		{
			fprintf(stderr, "Can't open %s\n", *argv);
			exit(1);
		}
		else
		{
			/* Search file for version header */
			while (((c = getc(fp)) != EOF) && (found == 0))
			{
				if ((c=='$') &&
				    (getc(fp)=='V') &&
				    (getc(fp)=='E') &&
				    (getc(fp)=='R') &&
					(getc(fp)==':'))
				{
					/* Print out version information */
					while ((c = getc(fp)) != 0)
					{
						printf("%c", c);
					}

					printf("\n");
					found = 1;
				}
			}

			/* Check if version string was found */
			if (found == 0)
			{
				printf("No version string found\n");
			}

			fclose(fp);
		}
	}
	exit(0);
}

