/* ckformat: Print the image format number on standard output */
/* for use in a shell script to test image format requirements. */
/* A non-zero return status code indicates failure. */

/* Usage: ckformat imageFileName */

/* --- DO NOT EDIT THIS FILE --- */
/* --- Automatically generated from class ImageFormat 2010-12-31T16:30:58.66-05:00--- */
/* --- Souce code is in package ImageFormat, archive www.squeaksource.com/VMMaker --- */
/* --- DO NOT EDIT THIS FILE --- */

#include <stdio.h>

#include <stdlib.h>

int main(int argc, char **argv) {
	FILE *f;
	unsigned char buf[8];
	int formatNumber;
	int match;
	if (argc != 2) {
		printf("usage: ckformat imageFileName\n");
		exit(1);
	}
	f = fopen(argv[1], "r");
	if (f == NULL) {
		perror(argv[1]);
		exit(2);
	}
	if (fread(buf, 1, 8, f) < 8) {
		fprintf(stderr, "cannot read %s\n", argv[1]);
		exit(3);
	}
	formatNumber= 6502;
	match = 1;
	if (buf[0] != 0) match= 0;
	if (buf[1] != 0) match= 0;
	if (buf[2] != 25) match= 0;
	if (buf[3] != 102) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 6502;
	match = 1;
	if (buf[0] != 102) match= 0;
	if (buf[1] != 25) match= 0;
	if (buf[2] != 0) match= 0;
	if (buf[3] != 0) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 6504;
	match = 1;
	if (buf[0] != 0) match= 0;
	if (buf[1] != 0) match= 0;
	if (buf[2] != 25) match= 0;
	if (buf[3] != 104) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 6504;
	match = 1;
	if (buf[0] != 104) match= 0;
	if (buf[1] != 25) match= 0;
	if (buf[2] != 0) match= 0;
	if (buf[3] != 0) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 6505;
	match = 1;
	if (buf[0] != 0) match= 0;
	if (buf[1] != 0) match= 0;
	if (buf[2] != 25) match= 0;
	if (buf[3] != 105) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 6505;
	match = 1;
	if (buf[0] != 105) match= 0;
	if (buf[1] != 25) match= 0;
	if (buf[2] != 0) match= 0;
	if (buf[3] != 0) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 68000;
	match = 1;
	if (buf[0] != 0) match= 0;
	if (buf[1] != 0) match= 0;
	if (buf[2] != 0) match= 0;
	if (buf[3] != 0) match= 0;
	if (buf[4] != 0) match= 0;
	if (buf[5] != 1) match= 0;
	if (buf[6] != 9) match= 0;
	if (buf[7] != 160) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 68000;
	match = 1;
	if (buf[0] != 160) match= 0;
	if (buf[1] != 9) match= 0;
	if (buf[2] != 1) match= 0;
	if (buf[3] != 0) match= 0;
	if (buf[4] != 0) match= 0;
	if (buf[5] != 0) match= 0;
	if (buf[6] != 0) match= 0;
	if (buf[7] != 0) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 68002;
	match = 1;
	if (buf[0] != 0) match= 0;
	if (buf[1] != 0) match= 0;
	if (buf[2] != 0) match= 0;
	if (buf[3] != 0) match= 0;
	if (buf[4] != 0) match= 0;
	if (buf[5] != 1) match= 0;
	if (buf[6] != 9) match= 0;
	if (buf[7] != 162) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 68002;
	match = 1;
	if (buf[0] != 162) match= 0;
	if (buf[1] != 9) match= 0;
	if (buf[2] != 1) match= 0;
	if (buf[3] != 0) match= 0;
	if (buf[4] != 0) match= 0;
	if (buf[5] != 0) match= 0;
	if (buf[6] != 0) match= 0;
	if (buf[7] != 0) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 68003;
	match = 1;
	if (buf[0] != 0) match= 0;
	if (buf[1] != 0) match= 0;
	if (buf[2] != 0) match= 0;
	if (buf[3] != 0) match= 0;
	if (buf[4] != 0) match= 0;
	if (buf[5] != 1) match= 0;
	if (buf[6] != 9) match= 0;
	if (buf[7] != 163) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	formatNumber= 68003;
	match = 1;
	if (buf[0] != 163) match= 0;
	if (buf[1] != 9) match= 0;
	if (buf[2] != 1) match= 0;
	if (buf[3] != 0) match= 0;
	if (buf[4] != 0) match= 0;
	if (buf[5] != 0) match= 0;
	if (buf[6] != 0) match= 0;
	if (buf[7] != 0) match= 0;
	if (match) {
		printf("%d\n", formatNumber);
		exit(0);
	}
	printf("0"); /* print an invalid format number */
	exit (-1); /* not found, exit with error code */
}
