/* * extract_xmi_PS * * Compile: cc -o extract_xmi_PS extract_xmi_PS.c * Usage : ./extract_xmi_PS filename * * TSO XMIT files that contain a PS dataset instead of a PDS file * cannot be processed by DASDLOAD to get them onto a cckd disk. * As XmitManager doesn't run on 64bit Win7 systems (aarg) I needed * to knock up this quick and dirty utility to get the file out * of the XMI format file. * * This will extract the 'data' from the XMIT file if * the PS file contains normal text. * * IMPORTANT: we want an ASCII file, so use * dd conv=ascii if=xxx.XMI of=xxx.XMI.TXT * on the XMIT file and process the .TXT one, I don't * intend to upgrade this to process EBCDIC files. * (especially as if you have IND$FILE installed you * can send up the ascii file easily) * * Functionally... ASSUMES 170+123 character sequence is record break * - ignore all the xmit header info until we get a record break * - read/write all bytes, write newlines on record breaks * - on 151 suppress writes (151 seems to be trailer starting flag) * */ #include #include #include FILE *fHandle; /* input file handle to be used */ int cByte, cByte2; /* data byte, and check next data byte */ int iStart = 0; /* found start of text flag */ int main(int argc, char *argv[]) { if (argc < 2) { /* 1 is always program name, 1st arg is pos 2 */ fprintf( stderr, "Need an input file name as an argument \n" ); } else { if ( (fHandle = fopen( argv[1], "rb" )) == NULL ) { fprintf(stderr, "File Error %d: %s \n", errno, strerror(errno)); } else { while ( (cByte = fgetc( fHandle )) != EOF ) { /* DEBUGGING: uncomment if needed to find extra char codes */ /* printf("%c %d \n", (char)cByte, cByte); */ if (cByte == 170) { /* 170+123 seems to be record break */ cByte2 = fgetc( fHandle ); if (cByte2 == 123) { /* ok, data has started and line feed if we knew that */ if (iStart == 0) { iStart = 1; } else { printf( "\n" ); } } else { /* not a 170+123, write those two bytes out */ putc( cByte, stdout ); putc( cByte2, stdout ); } } else { if (iStart != 0) { if (cByte == 151) { /* preceeds trailer section */ iStart = 0; /* stop printing */ } else { putc( cByte, stdout ); /* else write data byte */ } } } } fclose(fHandle); /* EOF, close the file */ printf( "\n" ); /* And newline for last record */ } } }