Category : HD Utilities
Archive   : MAXTEST.ZIP
Filename : CONVERT.C
/* filename:convert.c */
/* programmer: Nancy Schulenburg */
/* date: August 27, 1990 */
/* purpose: convert Maxtest command files that show arrow on right to */
/* command files that show arrow on left */
/* do this conversion by inserting a space at the beginning of each of the */
/* 16 lines [column 0], and removing the character in column 79 */
/* user is prompted for filenames */
/* ************************************************************************* */
#include
#define blank 0x20
FILE *oldfile, *newfile;
char oldfilename[80], newfilename[80];
char buffer[1600];
char row = 0; /* which line of file [20 total] */
char col = 0; /* which column in file [80 per line] */
unsigned char inbyte;
int i;
main()
{
puts("File conversion for MAXTEST command files");
puts("Converts a command file that shows the execution arrow on the right");
puts(" to a file that shows the execution arrow on the left");
/* get oldfile name and open it */
get_oldfile:
printf("\n\nName of old file to convert? ");
gets(oldfilename);
oldfile = fopen(oldfilename, "r");
if (oldfile == 0)
{
puts("\n\aCan't open file %s: hit escape to exit, another key to try again");
inbyte = getch();
if (inbyte == 0x1B) /* escape */
exit(0);
goto get_oldfile;
}
/* read in oldfile as stream, converting while reading in */
i = 0; /* index into buffer array */
for (row = 0; row < 20; row++)
{
/* make first byte of row blank */
/* see if file already has blank in first byte; don't convert if so */
/* then read in 1 row, all but last byte, starting at column 1 */
/* read last byte of row, but ignore it */
buffer[i] = blank;
i++;
for (col = 1; col < 80; col++)
{
buffer[i] = fgetc(oldfile);
if (buffer[1] == blank) /* file already converted */
{
printf("\nFile already converted");
goto convert_another_file;
}
i++;
}
inbyte = fgetc(oldfile);
}
fclose(oldfile);
/* get newfile name and open it */
get_newfile:
printf("\n\nName of new file? ");
gets(newfilename);
newfile = fopen(newfilename, "w");
if (newfile == 0)
{
puts("\n\aCan't open file %s: hit escape to exit, another key to try again");
inbyte = getch();
if (inbyte == 0x1B) /* escape */
exit(0);
goto get_newfile;
}
/* write buffer to newfile as stream */
for (i = 0; i < 1600; i++)
fputc(buffer[i], newfile);
fclose(newfile);
/* see if user wants to convert another file */
convert_another_file:
printf("\n\nConvert another file? [Y/N] ");
inbyte = getche();
inbyte = toupper(inbyte);
if (inbyte == 'Y')
goto get_oldfile;
}