mirror of
https://github.com/open-simh/simtools.git
synced 2026-04-16 00:21:38 +00:00
Add -rt11 option to dumpobj too.
This commit is contained in:
107
dumpobj.c
107
dumpobj.c
@@ -57,7 +57,8 @@ int xferad = 1;
|
|||||||
|
|
||||||
char *readrec(
|
char *readrec(
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
int *len)
|
int *len,
|
||||||
|
int rt11)
|
||||||
{
|
{
|
||||||
int c,
|
int c,
|
||||||
i;
|
i;
|
||||||
@@ -66,33 +67,33 @@ char *readrec(
|
|||||||
|
|
||||||
chksum = 0;
|
chksum = 0;
|
||||||
|
|
||||||
#if RT11
|
if (rt11) {
|
||||||
while (c = fgetc(fp), c != EOF && c == 0) ;
|
while (c = fgetc(fp), c != EOF && c == 0) ;
|
||||||
|
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (c != 1) {
|
if (c != 1) {
|
||||||
fprintf(stderr, "Improperly formatted OBJ file (1)\n");
|
fprintf(stderr, "Improperly formatted OBJ file (1)\n");
|
||||||
return NULL; /* Not a properly formatted file. */
|
return NULL; /* Not a properly formatted file. */
|
||||||
|
}
|
||||||
|
|
||||||
|
chksum -= c;
|
||||||
|
|
||||||
|
c = fgetc(fp);
|
||||||
|
if (c != 0) {
|
||||||
|
fprintf(stderr, "Improperly formatted OBJ file (2)\n");
|
||||||
|
return NULL; /* Not properly formatted */
|
||||||
|
}
|
||||||
|
|
||||||
|
chksum -= c; /* even though for 0 the checksum isn't changed... */
|
||||||
}
|
}
|
||||||
|
|
||||||
chksum -= c;
|
|
||||||
|
|
||||||
c = fgetc(fp);
|
|
||||||
if (c != 0) {
|
|
||||||
fprintf(stderr, "Improperly formatted OBJ file (2)\n");
|
|
||||||
return NULL; /* Not properly formatted */
|
|
||||||
}
|
|
||||||
|
|
||||||
chksum -= c; /* even though for 0 the checksum isn't changed... */
|
|
||||||
#endif /* RT11 */
|
|
||||||
|
|
||||||
c = fgetc(fp);
|
c = fgetc(fp);
|
||||||
if (c == EOF) {
|
if (c == EOF) {
|
||||||
#if RT11
|
if (rt11) {
|
||||||
fprintf(stderr, "Improperly formatted OBJ file (3)\n");
|
fprintf(stderr, "Improperly formatted OBJ file (3)\n");
|
||||||
#endif /* RT11 */
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*len = c;
|
*len = c;
|
||||||
@@ -109,9 +110,10 @@ char *readrec(
|
|||||||
|
|
||||||
chksum -= c;
|
chksum -= c;
|
||||||
|
|
||||||
#if RT11
|
if (rt11) {
|
||||||
*len -= 4; /* Subtract header and length bytes from length */
|
*len -= 4; /* Subtract header and length bytes from length */
|
||||||
#endif
|
}
|
||||||
|
|
||||||
if (*len < 0) {
|
if (*len < 0) {
|
||||||
fprintf(stderr, "Improperly formatted OBJ file (5)\n");
|
fprintf(stderr, "Improperly formatted OBJ file (5)\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -133,28 +135,28 @@ char *readrec(
|
|||||||
for (i = 0; i < *len; i++)
|
for (i = 0; i < *len; i++)
|
||||||
chksum -= (buf[i] & 0xff);
|
chksum -= (buf[i] & 0xff);
|
||||||
|
|
||||||
#if RT11
|
if (rt11) {
|
||||||
c = fgetc(fp);
|
|
||||||
c &= 0xff;
|
|
||||||
chksum &= 0xff;
|
|
||||||
|
|
||||||
if (c != chksum) {
|
|
||||||
free(buf);
|
|
||||||
fprintf(stderr, "Bad record checksum, " "calculated=$%04x, recorded=$%04x\n", chksum, c);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (*len & 1) {
|
|
||||||
/* skip 1 byte of padding */
|
|
||||||
c = fgetc(fp);
|
c = fgetc(fp);
|
||||||
if (c == EOF) {
|
c &= 0xff;
|
||||||
|
chksum &= 0xff;
|
||||||
|
|
||||||
|
if (c != chksum) {
|
||||||
free(buf);
|
free(buf);
|
||||||
fprintf(stderr, "EOF where padding byte should be\n");
|
fprintf(stderr, "Bad record checksum, " "calculated=$%04x, recorded=$%04x\n", chksum, c);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (*len & 1) {
|
||||||
|
/* skip 1 byte of padding */
|
||||||
|
c = fgetc(fp);
|
||||||
|
if (c == EOF) {
|
||||||
|
free(buf);
|
||||||
|
fprintf(stderr, "EOF where padding byte should be\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* RT11 */
|
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@@ -683,7 +685,24 @@ int main(
|
|||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *cp;
|
int arg;
|
||||||
|
int rt11 = 0;
|
||||||
|
|
||||||
|
for (arg = 1; arg < argc; arg++) {
|
||||||
|
if (*argv[arg] == '-') {
|
||||||
|
char *cp;
|
||||||
|
|
||||||
|
cp = argv[arg] + 1;
|
||||||
|
if (!strcasecmp(cp, "rt11")) {
|
||||||
|
rt11 = 1;
|
||||||
|
} else if (!strcasecmp(cp, "rsx")) {
|
||||||
|
rt11 = 0;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Unknown option %s\n", argv[arg]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
fprintf(stderr, "Usage: dumpobj input.obj [ output.obj ]\n");
|
fprintf(stderr, "Usage: dumpobj input.obj [ output.obj ]\n");
|
||||||
@@ -699,7 +718,9 @@ int main(
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((cp = readrec(fp, &len)) != NULL) {
|
char *cp;
|
||||||
|
|
||||||
|
while ((cp = readrec(fp, &len, rt11)) != NULL) {
|
||||||
switch (cp[0] & 0xff) {
|
switch (cp[0] & 0xff) {
|
||||||
case 1:
|
case 1:
|
||||||
got_gsd(cp, len);
|
got_gsd(cp, len);
|
||||||
|
|||||||
Reference in New Issue
Block a user