VAX file format conversion
Richard Loken
rlloken at telus.net
Mon Aug 15 22:35:33 CDT 2016
On Mon, 15 Aug 2016, Peter Coghlan wrote:
> The most likely to work solutions are to use $ SET FILE /ATTRIBUTES or
> Joe Meadows' FILE utility to change the file attributes from fixed 512 to
> stream format. The CR-LF pairs in the file will then be treated as record
> delimiters and the file will then be usable. Alternatively, delete the
> file and transfer it again selecting a text transfer mode rather than
> a binary transfer mode.
Yes, you are right. I stopped making that particular mistake many years
ago and I had forgotten. So back in 1986 I wrote a bit of garbage code
to fix that problem in the crudest manner possible.
Namely this:
/* Name: clean_cp.c
* Purpose: copy an rms file and ignore record length
* Author: Richard Loken
* Date: 17-Dec-1986
* Modified: 30-Sep-1987 - RLL Throw out any \r's that may be in the file.
* 07-Oct-1987 - RLL and most other non printing characters.
* 07-Sep-1994 - RLL Hacked for OpenVMS AXP and DEC C
*/
#include stdio
#include file
#include stat
#include stdlib
#include "au_src:[lib]extern_lib.h"
#define ERROR (-1)
#define MAXSTR 256
#define TOTAL 2 /* number of arguments expected */
char prompt[TOTAL][7] = {"input", "output"}; /* error message array */
main(argc, argv)
int argc;
char *argv[];
{
char files[TOTAL][MAXSTR]; /* names of input and output files */
char program[MAXSTR]; /* name of the executable file */
FILE *fin, *fout; /* input rms file and converted out */
int c;
int count; /* character count for pars_arg() */
int i, j;
unsigned fsize; /* size of input file */
/* initialize the variables */
i = 0;
j = 0;
short_path(argv[0], program); /* get rid of device & directories */
ltou(program); /* lets capitalize it */
/* parse any arguments to learn the file names */
while(i < TOTAL)
{
files[i++][0] = '\0';
}
if((argc > 1) && (argc <= (TOTAL + 1)))
{
for(i = 1; i < argc; i++)
{
count = 0;
while(j < TOTAL)
{
if((count = pars_arg(argv[i], count, files[j++])) == 0)
{
break;
}
else if(count == EOF)
{
j--;
break;
}
}
}
}
/* if we don't have enough file names, prompt for the rest */
for(j = 0; j < TOTAL; j++)
{
while(files[j][0] == '\0')
{
fprintf(stderr, "%s file: ", prompt[j]);
gets(files[j]);
}
}
/* open input and output files */
if((fin = fopen(files[0], "r")) == NULL)
{
fprintf(stderr, "\n%s\nCANNOT OPEN %s\n", program, files[0]);
exit(4); /* a fatal error */
}
if((fout = fopen(files[1], "w")) == NULL)
{
fprintf(stderr, "\n%s\nCANNOT OPEN %s\n", program, files[1]);
exit(4); /* a fatal error */
}
/* crude, copy char by char until the end */
while((c = getc(fin)) != EOF)
{
putc(c, fout);
}
fclose(fin);
fclose(fout);
}
--
Richard Loken VE6BSV, Systems Programmer - VMS : "...underneath those
Athabasca University : tuques we wear, our
Athabasca, Alberta Canada : heads are naked!"
** rlloken at telus.net ** : - Arthur Black
More information about the cctalk
mailing list