/* * orict2b.c * AYM 2002-07-26 */ /* This file is copyright André Majorel 2002-2003. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include static int do_file (const char *pathname, FILE *fp); static void err (const char *fmt, ...); int main (int argc, char *argv[]) { int exit_status = 0; { int g; while ((g = getopt (argc, argv, "")) != EOF) { exit (1); } } { int n; for (n = optind; n < argc; n++) { FILE *fp = fopen (argv[n], "rb"); if (fp == NULL) { err ("%s: %s", argv[n], strerror (errno)); exit_status = 1; continue; } if (do_file (argv[n], fp) != 0) exit_status = 1; fclose (fp); } } return exit_status; } static int do_file (const char *pathname, FILE *fp) { int rc = 0; unsigned long offset; int c; unsigned char header[9]; unsigned char name[17]; unsigned char name2[42]; const char *type; offset = ftell (fp); c = getc (fp); if (c != 0x16) { err ("%s(%lu): expected 16h", pathname, offset); return 1; } while (c == 0x16) { offset = ftell (fp); c = getc (fp); } if (c != 0x24) { err ("%s(%lu): expected 24h", pathname, offset); return 1; } if (fread (header, 9, 1, fp) != 1) { err ("%s: read error in header", pathname); return 1; } if (header[2] == 0) type = "b"; else if (header[2] == 0x40) type = "a"; else if (header[2] == 0x80) type = "d"; else { static char buf[42]; sprintf (buf, "?", header[2]); rc = 1; type = buf; } { char *p = name; int printed = 0; do { c = getc (fp); if (p >= name + 16) { if (! printed) err ("%s: name longer than 16 characters", pathname); printed = 1; } else *p++ = c; } while (c != '\0'); } strcpy (name2, "\""); strcat (name2, name); strcat (name2, "\""); printf ("s=%04X e=%04X t=%-1s au=%s str=%s int=%s n=%-18.18s %s\n", header[7] + 0x100 * header[6], header[5] + 0x100 * header[4], type, header[3] == 0 ? "n" : "y", header[1] == 0 ? "n" : "y", header[0] == 0 ? "n" : "y", name2, pathname); return rc; } static void err (const char *fmt, ...) { va_list argp; fflush (stdout); fputs ("orict2b: ", stderr); va_start (argp, fmt); vfprintf (stderr, fmt, argp); va_end (argp); fputc ('\n', stderr); }