/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2004-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* pax calib format
*
* test registry
*
* 0x00200 disable auto-sequence
* 0x00400 disable latest version selection
* 0x00800 trace directory type { 0 1 }
* 0x01000 disable ibm => standard cobol conversions
* 0x02000 trace all directory types
* 0x04000 trace partial output record buffers
* 0x08000 trace record headers in decimal
* 0x10000 trace record headers in base 4
* 0x20000 trace record headers in base 4 (alternate format)
*/
#include <paxlib.h>
#include <codex.h>
#include <ccode.h>
#include <ctype.h>
#include <tm.h>
#include "camap.c"
typedef struct Cadir_s
{
unsigned short offset;
unsigned short blocks;
} Cadir_t;
typedef struct Ar_s
{
char* format;
char* suffix;
unsigned char* map;
unsigned char* imap;
unsigned char* buffer;
unsigned char* next;
int camap;
int count;
int digits;
int flags;
int increment;
int linesize;
int position;
int sequence;
int version;
void* cam;
} Ar_t;
#define cabcd5(x) ((((unsigned char*)x)[0]>>4)*10000+(((unsigned char*)x)[0]&0xf)*1000+(((unsigned char*)x)[1]>>4)*100+(((unsigned char*)x)[1]&0xf)*10+(((unsigned char*)x)[2]>>4))
#define casize3(x) ((((unsigned char*)x)[0]<<16)|(((unsigned char*)x)[1]<<8)|(((unsigned char*)x)[2]))
#define casize4(x) ((((unsigned char*)x)[0]<<24)|(((unsigned char*)x)[1]<<16)|(((unsigned char*)x)[2]<<8)|(((unsigned char*)x)[3]))
/*
* cobol keyword map
*/
static const char* cakey[] =
{
"FILLER ",
"PICTURE ",
"USAGE ",
"VALUE ",
"PERFORM ",
"SUBTRACT ",
"COMPUTE ",
"COMPUTATIONAL",
"COMP",
"REDEFINES ",
"RENAMES ",
"JUSTIFIED ",
"GIVING ",
"USING ",
"CALL ",
"ALTER ",
"EQUAL ",
"GREATER ",
"POSITIVE ",
"NEGATIVE ",
"ELSE ",
"OTHERWISE ",
"{22}",
"VARYING ",
"FROM ",
"UNTIL ",
"THRU ",
"ROUNDED ",
"GO TO ",
"MOVE ",
"ZERO ",
"ZEROS ",
"DEPENDING ",
"PIC ",
"BLANK ",
"OCCURS ",
"{36}",
"{37}",
"{38}",
"{39}",
"{40}",
"{41}",
"{42}",
"{43}",
"{44}",
"{45}",
"{46}",
"{47}",
"{48}",
"{49}",
"{50}",
"{51}",
"{52}",
"{53}",
"{54}",
"{55}",
"{56}",
"{57}",
"{58}",
"{59}",
"{60}",
"{61}",
"{62}",
"{63}",
"{64}",
"{65}",
"{66}",
"{67}",
"{68}",
"{69}",
"{70}",
"{71}",
"{72}",
"{73}",
"{74}",
"{75}",
"{76}",
"{77}",
"{78}",
"{79}",
"{80}",
"{81}",
"{82}",
"{83}",
"{84}",
"{85}",
"{86}",
"{87}",
"{88}",
"{89}",
"{90}",
"{91}",
"{92}",
"{93}",
"{94}",
"{95}",
"{96}",
"{97}",
"{98}",
"{99}",
"{100}",
"{101}",
"{102}",
"{103}",
"{104}",
"{105}",
"{106}",
"{107}",
"{108}",
"{109}",
"{110}",
"{111}",
"{112}",
"{113}",
"{114}",
"{115}",
"{116}",
"{117}",
"{118}",
"{119}",
"{120}",
"{121}",
"{122}",
"{123}",
"{124}",
"{125}",
"{126}",
"{127}",
};
/*
* return next nbits nibble from the input line
*/
_cagetbits((ar), (n)))
static int
{
int c;
{
{
}
return 0;
else
break;
}
}
static int
{
{
}
return 0;
}
static int
calib_getprologue(Pax_t* pax, Paxformat_t* fp, register Paxarchive_t* ap, Paxfile_t* f, unsigned char* buf, size_t size)
{
off_t n;
size_t m;
int j;
int k;
return 0;
else
return 0;
{
return -1;
}
j = 3;
do
{
(*pax->errorf)(NiL, pax, 1, "blk %c%c%c%c%c%c%c%c %02x %02x %02x %02x %02x %02x %02x %02x", ccmapchr(ar->map, blk[0]), ccmapchr(ar->map, blk[1]), ccmapchr(ar->map, blk[2]), ccmapchr(ar->map, blk[3]), ccmapchr(ar->map, blk[4]), ccmapchr(ar->map, blk[5]), ccmapchr(ar->map, blk[6]), ccmapchr(ar->map, blk[7]), blk[8], blk[9], blk[10], blk[11], blk[12], blk[13], blk[14], blk[15]);
while (k-- > 0)
{
(*pax->errorf)(NiL, pax, 1, "dir %c%c%c%c%c%c%c%c %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", ccmapchr(ar->map, dir[0]), ccmapchr(ar->map, dir[1]), ccmapchr(ar->map, dir[2]), ccmapchr(ar->map, dir[3]), ccmapchr(ar->map, dir[4]), ccmapchr(ar->map, dir[5]), ccmapchr(ar->map, dir[6]), ccmapchr(ar->map, dir[7]), dir[8], dir[9], dir[10], dir[11], dir[12], dir[13], dir[14], dir[15], dir[16], dir[17], dir[18], dir[19], dir[20], dir[21]);
{
{
return -1;
}
}
dp++;
}
} while (j);
{
return -1;
}
return 1;
}
static int
{
const char* s;
unsigned char* out;
long sequence;
int c;
int bits;
int flags;
int generate;
int noted;
int oline;
int version;
unsigned char* hdr;
unsigned char* b;
unsigned char* m;
char* ofile;
char* suffix;
ssize_t z;
off_t n;
/* 10 20 30 40 50 60 */
/*01234567890123456789012345678901234567890123456789012345678901234*/
{
wfp = 0;
suffix = 0;
}
else if (wfd < 0)
return 1;
{
return -1;
}
sequence = ar->digits && ar->increment && (ar->position + ar->digits) <= ar->linesize ? ar->sequence : -1;
sequence = -1;
block = 0;
error_info.line = 0;
for (;;)
{
block++;
{
if (flags & 0x0c)
break;
if (flags & 0x80)
{
if (!(flags & 0x01))
}
continue;
error_info.line++;
(*pax->errorf)(NiL, pax, 0, "%03d %3u %3u %5u %3u %03o %4u %4u %4u %4u %4u %4o %4o %4o %4u %4u", error_info.line, ar->count, ar->next - hdr, ar->next - ar->buffer, hdr[0], hdr[1], hdr[2], hdr[3], hdr[4], hdr[5], hdr[6], hdr[7], hdr[8], hdr[9], hdr[10], hdr[11]);
(*pax->errorf)(NiL, pax, 0, "%03d %3u %3u %3u %03o %04..4u %04..4u %04..4u %04..4u %04..4u %04..4u %04..4u %04..4u %04..4u %04..4u", error_info.line, ar->count, ar->next - hdr, hdr[0], hdr[1], hdr[2], hdr[3], hdr[4], hdr[5], hdr[6], hdr[7], hdr[8], hdr[9], hdr[10], hdr[11]);
(*pax->errorf)(NiL, pax, 0, "%03d %3d %03d:%02x:%04..4u:%03u | %03d:%02x:%04..4u:%03u %03d:%02x:%04..4u:%03u %03d:%02x:%04..4u:%03u %03d:%02x:%04..4u:%03u %03d:%02x:%04..4u:%03u %03d:%02x:%04..4u:%03u",
if (flags & 0x40)
{
bits = 8;
}
else
{
bits = 6;
m = (unsigned char*)map;
}
noted = 0;
{
{
*out++ = m[c];
else if (!noted)
{
noted = 1;
(*pax->errorf)(NiL, pax, 2, "%s: overbyte (bits=%d offset=%I*u+%I*u block=%I*u)", ap->name, bits, sizeof(off_t), paxseek(pax, ap, (off_t)0, SEEK_CUR, 0) - ar->bufsize, sizeof(index), index, sizeof(block), block);
}
break;
c = 0;
else
}
{
(*pax->errorf)(NiL, pax, 1, "part c=%d n=%d k=%d \"%-.*s\"", c, out - outbuf, ar->count & 0x7f, out - outbuf, outbuf);
goto key;
}
c = (c + 64) & 0x7f;
(*pax->errorf)(NiL, pax, 1, "part c=%d:%d:%d r=%d:%d bits=%d n=%d x=%u \"%-.*s\"", c, &outbuf[ar->linesize] - out, c ^ 64, ar->next - ar->buffer, ar->line, bits, out - outbuf, *ar->next, out - outbuf, outbuf);
{
continue;
goto key;
}
else if (c > 0)
{
out += c;
}
{
key:
(*pax->errorf)(NiL, pax, 1, "%s: keyword %s (bits=%d offset=%I*u+%I*u block=%I*u)", ap->name, s, bits, sizeof(off_t), paxseek(pax, ap, (off_t)0, SEEK_CUR, 0) - ar->bufsize, sizeof(index), index, sizeof(block), block);
while (c = *s++)
*out++ = c;
else
{
if (!noted)
{
noted = 1;
(*pax->errorf)(NiL, pax, 2, "%s: key overbyte (bits=%d offset=%I*u+%I*u block=%I*u)", ap->name, bits, sizeof(off_t), paxseek(pax, ap, (off_t)0, SEEK_CUR, 0) - ar->bufsize, sizeof(index), index, sizeof(block), block);
}
break;
}
}
}
if (!wfp)
{
if (flags & 0x01)
{
for (; b < out && *b == ' '; b++);
for (m = b; b < out && *b != ' '; b++);
{
while ((out - ++b) > 4)
{
if (*b == 'R' && *(b + 1) == 'E' && *(b + 2) == 'X' && *(b + 3) == 'X')
{
suffix = ".REXX";
break;
}
}
if (suffix)
break;
continue;
}
if (m == outbuf)
{
{
suffix = ".EZT";
break;
}
{
suffix = ".F";
break;
}
}
else if ((b - m) == 7 && strneq((char*)m, "INCLUDE", 7) || (b - m) == 4 && strneq((char*)m, "NAME", 4))
{
suffix = ".LNK";
break;
}
{
suffix = ".ASM";
break;
}
{
suffix = ".PLI";
break;
}
else if ((b - m) == 10 && strneq((char*)m, "SUBROUTINE", 10) || (b - m) == 9 && strneq((char*)m, "DIMENSION", 9) || (b - m) == 6 && strneq((char*)m, "COMMON", 6) || b < out && (b - m) >= 6 && strneq((char*)m, "FORMAT", 6) && (m[6] == '(' || m[6] == ' '))
{
suffix = ".F";
break;
}
if (b < out && *m++ == '.' && ((b - m) == 7 && strneq((char*)m, "REPLACE", 7) || (b - m) == 5 && strneq((char*)m, "QUOTE", 5) || (b - m) > 4 && strneq((char*)m, "END-", 4)))
{
suffix = ".QBL";
break;
}
if ((b - outbuf) > 6)
{
{
for (m = b; b < out && *b != ' '; b++);
{
for (; b < out && *b != '.'; b++);
if (b < out && *b == '.')
{
suffix = ".CPY";
break;
}
}
else
{
for (; b < out && *b == ' '; b++);
for (m = b; b < out && *b != '.'; b++);
{
suffix = ".COB";
break;
}
}
}
suffix = ".CPY";
}
}
}
else if (flags & 0x01)
{
if (sequence >= 0)
{
if ((b = outbuf + ar->position) >= out || *b == ' ' || isdigit(*b) || (out - outbuf) == ar->linesize && (b = out - ar->digits))
{
{
out += c;
}
b += sfsprintf((char*)b, ar->digits+1, "%0.*lu", ar->digits, generate ? sequence : casize3(&hdr[2]));
if (out < b)
out = b;
}
}
*out++ = '\n';
{
if ((out - outbuf) == 11 && outbuf[8] == '/' && (outbuf[9] == '*' || outbuf[9] == ' ' || !outbuf[9]))
else
{
m = 0;
if (*b == '/')
{
if (!m)
m = b;
else
{
if (*++b == '*' || *b == ' ' || *b == '\n')
{
c = m - outbuf - 8;
from[c] = 0;
c = b - m - 2;
to[c] = 0;
}
break;
}
}
}
}
else if (!pax->strict && !(pax->test & 0x01000) && outbuf[0] == '-' && outbuf[1] == 'I' && outbuf[2] == 'N' && outbuf[3] == 'C' && outbuf[4] == ' ')
{
if (from[0])
c = sfsprintf((char*)outbuf, sizeof(outbuf), " COPY %-.*s REPLACING ==%s== BY ==%s==.\n", m - b, b, from, to);
else
}
{
goto bad;
}
}
else
{
error_info.line--;
{
*out = 0;
}
}
}
if (!wfp)
break;
break;
{
}
(*pax->errorf)(NiL, pax, 3, "%s: format member read error (offset=%I*u block=%I*u)", ap->name, sizeof(off_t), paxseek(pax, ap, (off_t)0, SEEK_CUR, 0), sizeof(block), block);
}
if (wfp)
{
{
goto bad;
}
}
else if (suffix)
return 1;
bad:
return -1;
}
static int
{
register unsigned char* h;
register off_t n;
char* s;
char* t;
char* v;
int i;
int j;
int k;
int x;
return 0;
s = 0;
k = 0;
{
if ((i = *h) == 78)
{
j = h[2];
if (j == 5 && !h[1] && !h[3])
x = 1;
i -= 6;
h += 6;
}
else
{
if (j == 5)
x = 1;
i -= 2;
h += 2;
}
if (!(k & (1<<j)))
{
k |= (1<<j);
{
int y;
for (y = 0; y < i; y++)
}
switch (j)
{
case 0:
{
case 0x40:
break;
case 0xf1:
break;
}
f->st->st_mtime = f->st->st_ctime = f->st->st_atime = tmscan(sfprints("%-.6s%02u%02u%02u", memcmp(h + 18, "000000", 6) ? (h + 18) : (h + 12), h[24], h[25], h[26]), NiL, "%y%m%d%H%M%S", NiL, NiL, 0);
(*pax->errorf)(NiL, pax, 0, "head %-8s %d %03o %03o %03o %03o %03o %03o %03o", f->name, j, h[32], h[33], h[34], h[35], h[36], h[37], h[38]);
break;
case 1:
{
case 0x40:
break;
}
if (h[31] == 0x48)
{
}
else
{
}
f->st->st_mtime = f->st->st_ctime = f->st->st_atime = tmscan(sfprints("%-.6s%-.4s00", memcmp(h + 18, "000000", 6) ? (h + 18) : (h + 12), h + 24), NiL, "%m%d%y%H%M%S", NiL, NiL, 0);
(*pax->errorf)(NiL, pax, 0, "head %-8s %d %03o %03o %03o %03o %03o %03o %03o", f->name, j, h[32], h[33], h[34], h[35], h[36], h[37], h[38]);
break;
case 5:
if (s)
{
switch (h[38])
{
case 0x31:
v = "PLI";
break;
case 0x32:
case 0x42:
case 0x4c:
v = "COB";
break;
case 0x43:
v = "EST";
break;
case 0x4d:
v = "ASM";
break;
default:
t = (char*)h + 34;
v = suf;
while (t < ((char*)h + 37) && *t != ' ')
*v++ = *t++;
*v = 0;
if (!*(v = suf))
{
{
v = "LST";
}
else
switch (h[38])
{
case 0x00:
case 0x02:
v = "COB";
break;
case 0x01:
case 0x0a:
v = 0;
break;
default:
v = 0;
break;
}
}
v = "COB";
else if (streq(v, "PL1"))
v = "PLI";
break;
}
if (v)
{
*s++ = '.';
strcpy(s, v);
}
}
break;
}
}
}
for (s = f->name; *s; s++)
if (!isalnum(*s) && *s != '.')
*s = '_';
{
}
for (i = 0, s = f->name; *s; s++)
if (*s == '.')
{
break;
}
else if (islower(*s))
i = 1;
if (i && *s)
while (*++s)
if (isupper(*s))
*s = tolower(*s);
f->linkpath = 0;
return 1;
}
{
"ca-librarian",
"calib|librarian",
"mvs CA-librarian file",
0,
0,
0,
};