/* Check compliance and print attributes of EBS files Copyright (C) 1993/94 Markus Kuhn, Institut fuer Physiologie und Biokybernetik (IPB), Universitaet Erlangen, Deutschland Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and related publications and that both that copyright notice and this permission notice appear in supporting documentation. The authors make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. Send your comments, suggestions or bug reports to ftpebs@uni-erlangen.de Or mail to Institut fuer Physiologie und Biokybernetik Markus Prosch Universitaetsstrasse 17 D-91054 Erlangen Germany $Id: ebstype.c,v 1.16 1994/03/01 11:08:31 msprosch Exp $ */ #include #include #include #include #include #include "ebs.h" #ifndef SEEK_SET #define SEEK_SET 0 #endif #ifndef SEEK_END #define SEEK_END 2 #endif #ifdef MSDOS #include "setstack.c" #endif char copyright[]= "Check compliance and print attributes of EBS files\n" "Copyright (C) 1993/94 Markus Kuhn, Institut fuer Physiologie und\n" " Biokybernetik (IPB), Universitaet Erlangen, Deutschland\n\n" "Permission to use, copy, modify, distribute, and sell this software\n" "and its documentation for any purpose is hereby granted without fee,\n" "provided that the above copyright notice appear in all copies and\n" "related publications and that both that copyright notice and this\n" "permission notice appear in supporting documentation. The authors make\n" "no representations about the suitability of this software for any\n" "purpose. It is provided \"as is\" without express or implied warranty.\n\n" "Send your comments, suggestions or bug reports to\n" " ftpebs@uni-erlangen.de\n\n" "Or mail to\n" " Institut fuer Physiologie und Biokybernetik\n" " Markus Prosch\n" " Universitaetsstrasse 17\n" " D-91054 Erlangen\n" " Germany\n\n"; char usage[] = "Check compliance and print attributes of EBS files, V1.0\n" "(C) 1993/94, Markus Kuhn, IPB, Erlangen\n\n" "usage: %s [-l] [-s] {}\n\n" "options:\n" "\t-c print out copyright notice\n" "\t-h print out this message\n" "\t-l print also the contents of attributes with long lists\n" "\t of data (e.g. event lists, channel locations, ...)\n" "\t-s print only a short list with filenames and short\n" "\t description texts\n\n"; #define MAXSTRING 20000 /* maximum string length that will be printed */ #define PI 3.14159265358979323846 void analyse_ebs(FILE *fin, int long_mode, int summary) { unsigned long samples, samples_hi; unsigned long length, length_hi; unsigned long channels; unsigned long magic1, magic2, id; unsigned long tag; unsigned long attribute_length; long a = 0, b = 0, c, d, a_old = 0, b_old = 0; unsigned long ua, ub, ua_old, ub_old, uc, ud, ue; double f = 0, f_old = 0; long pos, data_start = 0, data_end = 0; float time; char string[MAXSTRING], string_old[MAXSTRING], *filter_text; int i, j, k, l = 0, m, n, nan, nan_old; int final_tag_counter; /* read fixed header */ magic1 = fgeti32(fin); magic2 = fgeti32(fin); id = fgeti32(fin); channels = fgeti32(fin); samples_hi = fgeti32(fin); samples = fgeti32(fin); length_hi = fgeti32(fin); length = fgeti32(fin); if (feof(fin)) { printf(" not an EBS file, too short.\n"); return; } if ((magic1 & 0xffffff00L) != (EBS_MAGIC1 & 0xffffff00L)) { printf(" not an EBS file.\n"); return; } if ((magic1 != EBS_MAGIC1) || (magic2 != EBS_MAGIC2)) { printf(" looks like an EBS file that has been corrupted during " "file transfer.\n"); return; } if (summary < 0) { /* print encoding ID */ printf(" EBS data format "); switch (id) { case EBS_CIB_16: printf("CIB_16 (channel order, 16-bit Bigendian integer)\n"); break; case EBS_TIB_16: printf("TIB_16 (time order, 16-bit Bigendian integer)\n"); break; case EBS_CIL_16: printf("CIL_16 (channel order, 16-bit Littleendian integer)\n"); break; case EBS_TIL_16: printf("TIL_16 (time order, 16-bit Littleendian integer)\n"); break; case EBS_CI_16D: printf("CI_16D (channel order, 16-bit integers as 8-bit differences)\n"); break; case EBS_TI_16D: printf("TI_16D (time order, 16-bit integers as 8-bit differences)\n"); break; default: printf("unknown (%s, encoding ID: 0x%08lx)\n", (id >= 0x80000000L) ? ((id == 0xffffffffL) ? "illegal" :"private") : "standard", id); } printf(" %lu channel%s, ", channels, (1 == channels) ? "" : "s"); if (samples_hi == 0xffffffffL && samples == 0xffffffffL) { printf("unspecified number of samples.\n"); if (id == EBS_CIB_16 || id == EBS_CIL_16 || id == EBS_CI_16D) printf(" Error: unspecified number of samples not allowed " "with channel order!\n"); } else if (samples_hi != 0) printf("more then 4294967295 samples per channel.\n"); else printf("%lu sample%s per channel.\n", samples, (1 == samples) ? "" : "s"); if (length_hi != 0 && !(length_hi == 0xffffffffL && length == 0xffffffffL)) { printf(" Unfortunately, the data part of this file is too long for " "this system.\n"); return; } } /* read variable header */ if (summary < 0) printf("\n information in the variable header:\n"); final_tag_counter = 0; do { while ((tag = fgeti32(fin)) != 0) { attribute_length = fgeti32(fin); if (feof(fin)) { printf(" Unexpected end of file!\n"); return; } pos = ftell(fin); if (summary >= 0) { if (tag == EBS_SHORT_DESCRIPTION) { if (attribute_length == 0) { printf("\n"); return; } else { i = fgets4(string, 65, fin); if (summary > 12) printf("\n "); else for (j = summary; j < 12; j++) putchar(' '); printf("%s%s\n", string, (i > 64) ? "..." : ""); return; } } else tag = EBS_IGNORE; /* don't do anything with the other attributes */ } switch (tag) { case EBS_PATIENT_NAME: case EBS_PATIENT_ID: case EBS_SHORT_DESCRIPTION: case EBS_INSTITUTION: if (attribute_length == 0) { printf(" Incorrect length (%lu words) in attribute " "(tag = 0x%08lx)!\n", attribute_length, tag); break; } i = fgets4(string, 65, fin); switch (tag) { case EBS_PATIENT_NAME: printf(" patient name: "); break; case EBS_PATIENT_ID: printf(" patient ID: "); break; case EBS_SHORT_DESCRIPTION: printf(" short description: "); break; case EBS_INSTITUTION: printf(" institution: "); break; } if (i > 50) printf("\n "); printf("%s", string); if (i > 64) printf("..."); printf("\n"); if (attribute_length != (ftell(fin) - pos) / 4) printf(" Attribute length is %lu, but should be better %ld words, " "because\n string length is %d!\n", attribute_length, (ftell(fin) - pos) / 4, i); break; case EBS_PATIENT_BIRTHDAY: if (attribute_length != 2) { printf(" Incorrect length (%lu words) in attribute " "PATIENT_BIRTHDAY!\n", attribute_length); break; } fread(string, 2, 4, fin); printf(" patient birthday: %.4s-%.2s-%.2s\n", string, string+4, string+6); break; case EBS_PATIENT_SEX: if (attribute_length != 1) { printf(" Incorrect length (%lu words) in attribute PATIENT_SEX!\n", attribute_length); break; } a = fgeti32(fin); printf(" patient sex: "); switch(a) { case 1: printf("male.\n"); break; case 2: printf("female.\n"); break; default: printf("unknown (code: 0x%08lx).\n", a); break; } break; case EBS_RECORDING_TIME: if (attribute_length < 100) fread(string, 4, attribute_length, fin); if (attribute_length == 4 && string[8] == 'T' && string[15] == 0 && isdigit(string[ 0]) && isdigit(string[ 1]) && isdigit(string[ 2]) && isdigit(string[ 3]) && isdigit(string[ 4]) && isdigit(string[ 5]) && isdigit(string[ 6]) && isdigit(string[ 7]) && isdigit(string[ 9]) && isdigit(string[10]) && isdigit(string[11]) && isdigit(string[12]) && isdigit(string[13]) && isdigit(string[14])) printf(" time of recording: %.4s-%.2s-%.2s %.2s:%.2s:%.2s\n", string, string+4, string+6, string+9, string+11, string+13); else if (attribute_length == 2 && isdigit(string[ 0]) && isdigit(string[ 1]) && isdigit(string[ 2]) && isdigit(string[ 3]) && isdigit(string[ 4]) && isdigit(string[ 5]) && isdigit(string[ 6]) && isdigit(string[ 7])) printf(" time of recording: %.4s-%.2s-%.2s\n", string, string+4, string+6); else printf(" Unknown time format (length %lu words) '%.*s'\n" " in attribute RECORDING_TIME!\n", attribute_length, (int) attribute_length * 4, string); break; case EBS_SAMPLE_RATE: if (attribute_length == 0) { printf(" Incorrect length (%lu words) in attribute SAMPLE_RATE!\n", attribute_length); break; } f = fgetf4(fin, &nan); if (nan == 1) { printf(" Value of SAMPLE_RATE is not-a-number!\n"); break; } else if (nan < 0) { printf(" Syntax error in value of SAMPLE_RATE!\n"); break; } printf(" sample rate is %g", f); printf(" samples per second (Hz).\n"); if (samples_hi == 0) { printf(" => recording time is "); time = samples / f; if ((int) (time / 3600.0) >= 1) { printf("%u hour%s, ", (int) (time / 3600.0), (1 == (int) (time / 3600.0)) ? "" : "s"); time -= 3600.0 * (int) (time / 3600.0); } if ((int) (time / 60.0) >= 1) { printf("%u minute%s, ", (int) (time / 60.0), (1 == (int) (time / 60.0)) ? "" : "s"); time -= 60.0 * (int) (time / 60.0); } printf("%g seconds.\n", time); } if (attribute_length != (ftell(fin) - pos) / 4) printf(" Attribute length is %lu, but should be better " "%ld words!\n", attribute_length, (ftell(fin) - pos) / 4); break; case EBS_CHANNEL_DESCRIPTION: if (attribute_length < channels*2) { printf(" Incorrect length (%lu words) in attribute " "CHANNEL_DESCRIPTION!\n", attribute_length); break; } printf(" channel descriptions:\n"); m = 0; /* column */ for (j = 0; j < channels; j++) { k = fgets4(string, 9, fin); l = fgets4(string + 100, 65, fin); if (m && l>0) { printf("\n"); m = 0; } if (k>0 || l>0) { if (!m) printf(" "); printf("%3d: ", j+1); if (k > 0) printf("%s%*s%s", string, 8-k, "", (k > 8) ? "... " : " "); if (l > 0) if (l > 42 || k == 0) { if (k > 0) printf("\n "); printf("%s%s", string + 100, (l > 64) ? "..." : ""); } else printf("%s", string + 100); if (m > 1 || l > 0) { printf("\n"); m = 0; }else { printf(" "); m++; } } } if (m) printf("\n"); if (attribute_length != (ftell(fin) - pos) / 4) printf(" Attribute length is %lu, but should be better " "%ld words!\n", attribute_length, (ftell(fin) - pos) / 4); break; case EBS_UNITS: if (attribute_length < 2*channels) { printf(" Incorrect length (%lu words) in attribute UNITS!\n", attribute_length); break; } printf(" physical units:\n"); if (channels > 0) { l = 0; f_old = fgetf4(fin, &nan_old); k = fgets4(string_old, 9, fin); } for (j = 1; j <= channels; j++) { if (j < channels) { f = fgetf4(fin, &nan); k = fgets4(string, 9, fin); } if (j == channels || (f != f_old || nan != nan_old || strcmp(string,string_old) != 0)) { if (!nan_old) { if (l == j-1) printf(" channel%3d: 1 bin represents %g %s\n", l+1, f_old, string_old); else printf(" channel%3d -%3d: 1 bin represents %g %s\n", l+1, j, f_old, string_old); } else if (nan_old < 0) if (l == j-1) printf(" channel%3d: syntax error in floatingpoint " "value!\n", l+1); else printf(" channel%3d -%3d: syntax error in floatingpoint " "value!\n", l+1, j); l = j; f_old = f; nan_old = nan; strcpy(string_old, string); } } if (attribute_length != (ftell(fin) - pos) / 4) printf(" Attribute length is %lu, but should be better " "%ld words!\n", attribute_length, (ftell(fin) - pos) / 4); break; case EBS_PREFERRED_INTEGER_RANGE: if (attribute_length != 2*channels) { printf(" Incorrect length (%lu words) in attribute " "PREFERRED_INTEGER_RANGE, should be %lu!\n", attribute_length, 2 * channels); break; } printf(" preferred bin range (e.g. for default display scaling " "factor):\n"); if (channels > 0) { l = 0; a_old = fgeti32(fin); b_old = fgeti32(fin); } for (j = 1; j < channels+1; j++) { if (j < channels) { a = fgeti32(fin); b = fgeti32(fin); } if (j == channels || (a != a_old || b != b_old)) { if (a_old != b_old) if (l == j-1) printf(" channel%3d: minimum = %ld, maximum = %ld\n", l+1, a_old, b_old); else printf(" channel%3d -%3d: minimum = %ld, maximum = %ld\n", l+1, j, a_old, b_old); l = j; a_old = a; b_old = b; } } break; case EBS_PROCESSING_HISTORY: if (attribute_length == 0) { printf(" Incorrect length (%lu words) in attribute " "PROCESSING_HISTORY!\n",attribute_length); break; } printf(" processing history:\n"); do { j = fgets4(string, MAXSTRING, fin); printf(" - "); for (k = 0; k < j && k < MAXSTRING - 1; k++) if (string[k] == '\n') printf("\n "); else putchar(string[k]); if (j >= MAXSTRING - 1) printf("..."); printf("\n"); } while (!feof(fin) && (ftell(fin) - pos) / 4 < attribute_length); if (attribute_length != (ftell(fin) - pos) / 4) printf(" Attribute length is %lu, but should be better " "%ld words!\n", attribute_length, (ftell(fin) - pos) / 4); break; case EBS_DESCRIPTION: if (attribute_length == 0) { printf(" Incorrect length (%lu words) in attribute " "DESCRIPTION!\n", attribute_length); break; } printf(" description:\n"); j = fgets4(string, MAXSTRING, fin); printf(" "); for (k = 0; k < j && k < MAXSTRING - 1; k++) if (string[k] == '\n') printf("\n "); else putchar(string[k]); if (j >= MAXSTRING - 1) printf("..."); printf("\n"); if (attribute_length != (ftell(fin) - pos) / 4) printf(" Attribute length is %lu, but should be better " "%ld words!\n", attribute_length, (ftell(fin) - pos) / 4); break; case EBS_EVENTS: printf(" event lists:\n"); k = 0; /* event count */ while (!feof(fin) && ftell(fin) < pos + 4*attribute_length) { k++; l = fgets4(string, 25, fin); m = fgets4(string + 25, 9970, fin); n = fgeti32(fin); printf(" list %d, %d event%s", k, n, (n == 1) ? "" : "s"); if (l > 0) printf(", label '%.8s%s'", string, (l > 8) ? "..." : ""); printf("\n"); if (m > 0) { printf(" "); for (i = 0; i < m; i++) if (string[i+25] == '\n') printf("\n "); else putchar(string[i+25]); if (m > 9999) printf("..."); printf("\n"); } ua_old = 0; /* last event */ ub_old = 0; for (i = 0; i < n; i++) { uc = fgeti32(fin); ua = fgeti32(fin); ub = fgeti32(fin); ud = fgeti32(fin); ue = fgeti32(fin); l = fgets4(string, 193, fin); if (long_mode) { if (ud == 0 && ue == 0) { printf(" Event %d at position ", i + 1); if (ua == 0) printf("%lu.\n", ub); else printf(">4294967295.\n"); } else { printf(" Region %d from position ", i + 1); if (ua == 0) printf("%lu", ub); else printf(">4294967295"); printf(" to position "); if (ua == 0 && ud == 0 && ub + ue > ub) printf("%lu.\n", ub + ue); else printf(">4294967295.\n"); } } if (l) printf(" %s%s\n", string, (l > 64) ? "..." : ""); if (uc >= channels && uc != 0xffffffffL) printf(" Warning at event %d: channel number (%lu) is " "too high (maximum: %lu)!\n", i + 1, uc + 1, channels); if ((samples != 0xffffffffL || samples_hi != 0xffffffffL) && (ua > samples_hi || (ua == samples_hi && ub > samples))) printf(" Warning at event %d: start position is " "beyond end of data!\n", i + 1); else if ((samples != 0xffffffffL || samples_hi != 0xffffffffL) && (ua+ud > samples_hi || (ua+ud == samples_hi && ub+ue > samples))) printf(" Warning at region %d: end position is " "beyond end of data!\n", i + 1); if (ua < ua_old || (ua == ua_old && ub < ub_old)) printf(" Warning at event %d: start position is " "before previous one!\n", i + 1); ua_old = ua; ub_old = ub; if (l > 64) printf(" Warning at event %d: description string " "is too long (%d characters)!\n", i + 1, l); if (ftell(fin) > pos + 4*attribute_length) { printf(" Incorrect length (%lu words) in attribute " "EVENTS!\n", attribute_length); break; } } } break; case EBS_LOCATION_DIAGRAM: printf(" location diagram, %lu words.\n", attribute_length); break; case EBS_CHANNEL_LOCATIONS: if (attribute_length % 6 != 0) { printf(" Incorrect length (%lu words) in attribute " "CHANNEL_LOCATIONS!\n",attribute_length); break; } printf(" channel locations:%s", long_mode ? "\n" : ""); k = 0; while (!feof(fin) && ftell(fin) < pos + 4*attribute_length) { k++; uc = fgeti32(fin); /* channel number */ ua = fgeti32(fin); /* picture number */ a = fgeti32(fin); /* x1 coordinate */ b = fgeti32(fin); /* y1 coordinate */ c = fgeti32(fin); /* x2 coordinate */ d = fgeti32(fin); /* y2 coordinate */ if (long_mode) { printf(" channel %lu in picture %lu ", uc + 1, ua + 1); if (0x80000000L == c && 0x80000000L == d) printf("at %ld,%ld\n", a, b); else printf("from %ld,%ld to %ld,%ld\n", a, b, c, d); } } if (!long_mode) printf(" %d positions.\n", k); break; case EBS_CHANNEL_GROUPS: printf(" channel groups:\n"); k = 0; /* group count */ while (!feof(fin) && ftell(fin) < pos + 4*attribute_length) { k++; l = fgets4(string, 25, fin); m = fgets4(string + 25, MAXSTRING - 30, fin); n = fgeti32(fin); printf(" group %d, %d channel%s", k, n, (n == 1) ? "" : "s"); if (l > 0) printf(", label '%.8s%s'", string, (l > 8) ? "..." : ""); printf("\n"); if (m > 0) { printf(" "); for (i = 0; i < m && i < 64; i++) if (string[i+25] == '\n') printf("\n "); else putchar(string[i+25]); if (m > 64) printf("..."); printf("\n"); } ua = 0xffffffffL; /* number of wrong channel will be stored here */ if (n > 0) { for (i = 0; i < n; i++) { uc = fgeti32(fin); if ((i % 14) == 0) printf(" "); printf(" %lu", uc + 1); if (i < n-1) printf(","); if ((i % 14) == 13 || i == n - 1) printf("\n"); if (uc >= channels && ua == 0xffffffffL) ua = uc; } if (ua != 0xffffffffL) printf(" Error: channel %lu may not appear here, because\n" " this file has only %lu channels!\n", ua + 1, channels); } if (ftell(fin) > pos + 4*attribute_length) { printf(" Incorrect length (%lu words) in attribute " "CHANNEL_GROUPS!\n", attribute_length); break; } } break; case EBS_FILTERS: if (attribute_length < channels) { printf(" Incorrect length (%lu words) in attribute " "FILTERS!\n", attribute_length); break; } printf(" filters:\n"); l = 0; for (j = 0; j <= channels; j++) { if (0 == j) filter_text = string_old; else filter_text = string; if (j < channels) { filter_text[0] = '\0'; while ((ua = fgeti32(fin)) != 0xffffffffL && strlen(filter_text) < MAXSTRING - 100) { strcat(filter_text, " "); if (1 == ua) strcat(filter_text, "lowpass"); else if (2 == ua) strcat(filter_text, "highpass"); else if (3 == ua) strcat(filter_text, "notch"); else strcat(filter_text, "unknown"); f = fgetf4(fin, &nan); if (!nan) { sprintf(filter_text + strlen(filter_text), " filter, %g Hz", f); if (2 == ua && f > 0.0) { if (1/(2*PI*f) < 1.0) sprintf(filter_text + strlen(filter_text), " (t=%g ms)", 1000/(2*PI*f)); else sprintf(filter_text + strlen(filter_text), " (t=%g sec)", 1/(2*PI*f)); } } else strcat(filter_text, " filter, ??? Hz"); f = fgetf4(fin, &nan); if (nan == 0) sprintf(filter_text + strlen(filter_text), ", %g dB/decade falloff", f); else if (nan != 1) strcat(filter_text, ", ??? dB/decade falloff"); strcat(filter_text, "\n"); } } if (j > 0 && (j == channels || strcmp(string,string_old) != 0)) { if (l == j-1) printf(" channel%3d:\n%s", l + 1, string_old); else printf(" channel%3d -%3d:\n%s", l + 1, j, string_old); l = j; strcpy(string_old, string); } } if (attribute_length != (ftell(fin) - pos) / 4) printf(" Attribute length, is %lu but should be better " "%ld words!\n", attribute_length, (ftell(fin) - pos) / 4); break; case EBS_IGNORE: break; case EBS_ILLEGAL_TAG: printf(" illegal tag (0x%08lx), length %lu words !!!\n", tag, attribute_length); break; default: printf(" unknown tag (0x%08lx), length %lu words", tag, attribute_length); if (tag >= EBS_BEGIN_STANDARD_AREA && tag <= EBS_END_STANDARD_AREA) printf(", STANDARD AREA"); else if (tag >= EBS_BEGIN_RESERVATION_AREA && tag <= EBS_END_RESERVATION_AREA) printf(", RESERVATION AREA"); else if (tag >= EBS_BEGIN_FREE_AREA && tag <= EBS_END_FREE_AREA) printf(", FREE AREA"); else if (tag >= EBS_BEGIN_FREE_STRING_AREA && tag <= EBS_END_FREE_STRING_AREA) { printf(", FREE STRING AREA:\n"); if (attribute_length == 0) { printf(" Incorrect length (%lu words, must be >0)!\n", attribute_length); break; } j = fgets4(string, MAXSTRING, fin); printf(" "); for (k = 0; k < j && k < MAXSTRING - 1; k++) if (string[k] == '\n') printf("\n "); else putchar(string[k]); if (j >= MAXSTRING - 1) printf("..."); printf("\n"); if (attribute_length != (ftell(fin) - pos) / 4) printf(" Attribute length is %lu, but should be better " "%ld words!\n", attribute_length, (ftell(fin) - pos) / 4); break; } printf("\n"); break; } fseek(fin, attribute_length * 4 + pos, SEEK_SET); } /* while ((tag = fgeti32(fin)) != 0) */ final_tag_counter++; if (final_tag_counter == 1) { data_start = ftell(fin); if (length_hi == 0xffffffffL && length == 0xffffffffL) { if (fseek(fin, 0, SEEK_END)) fprintf(stderr, " Problem: can't jump with fseek() to end of " "input file!\n"); } else if (fseek(fin, length * 4 + data_start, SEEK_SET)) fprintf(stderr, " Problem: can't jump with fseek() to start of " "second variable header part!\n"); data_end = ftell(fin); } } while (final_tag_counter < 2 && (length_hi != 0xffffffffL || length != 0xffffffffL)); if (summary >= 0) { /* there wasn't any short description available */ printf("\n"); return; } /* check length of data part */ if (samples_hi == 0 && ((double) samples * (double) channels * 3.0 <= (unsigned long) ULONG_MAX)) { a = data_end - data_start; switch (id) { case EBS_CIB_16: case EBS_CIL_16: case EBS_TIB_16: case EBS_TIL_16: if (a > ((samples * channels * 2) | 3) + 1) printf("\n Warning: data part is %ld bytes longer than expected!\n", a - ((samples * channels * 2) | 3) + 1); else if (a < samples * channels * 2) printf("\n Error: data part is %ld bytes too short!\n", samples * channels * 2 - a); break; case EBS_TI_16D: case EBS_CI_16D: if (a > ((samples * channels * 3) | 3) + 1) printf("\n Warning: data part is %ld bytes longer than possible!\n", a - ((samples * channels * 3) | 3) + 1); else if (a < samples * channels + 2) printf("\n Error: data part is at least %ld bytes too short!\n", samples * channels + 2 - a); break; default: break; } } } int main(argc, argv) int argc; char **argv; { FILE *fin = NULL; int i, j, first = 1; int long_mode = 0; int summary = 0; /* do all the command line and file open stuff */ if (argc < 2 || !strcmp(argv[1], "/?")) { fprintf(stderr, usage, argv[0]); exit(1); } for (i = 1; i < argc; i++) { if (argv[i][0] == '-') for (j = 1; j < 999 && argv[i][j] != 0; j++) switch (argv[i][j]) { case 'l': case 'L': long_mode = 1; break; case 's': case 'S': summary = 1; break; case 'c': case 'C': fprintf (stderr, copyright); exit (1); default: fprintf(stderr, usage, argv[0]); exit(1); } else { fin = fopen(argv[i], "rb"); if (fin == NULL) { fprintf(stderr, "Can't open input file '%s", argv[i]); perror("'"); } else { if (!first && !summary) printf("\n"); first = 0; if (fin != stdin) if (summary) printf("%s", argv[i]); else printf("%s:\n", argv[i]); analyse_ebs(fin, long_mode, summary ? strlen(argv[i]) : -1); fclose(fin); } } } return 0; }