home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
r
/
raylat10.zip
/
LAT2RAYL.C
< prev
next >
Wrap
Text File
|
1993-03-26
|
3KB
|
104 lines
#include <stdio.h>
#define VERSION 1.00
FILE *lathefile1, *lathefile2;
void main(argc,argv)
int argc;
char *argv[];
{
char filename1[30], filename2[30];
unsigned char byte;
int word, x, y;
int count;
int io_count = 0;
fprintf(stderr,"Lat2RayL v%2.2f (c) 1993 Koehler\n\n",VERSION);
if(argc < 2) /* Missing the input file name argument - bitch and die */
{
puts(" Usage: lat2rayl <infile>\n");
exit(1);
}
strcpy(filename1, argv[1]);
if (strchr(filename1, '.') != NULL)
{
printf("File cannot have an extension\n");
exit(2);
}
strcpy(filename2, filename1);
strcat(filename1, ".lat");
strcat(filename2, ".dat");
lathefile1=fopen(filename1,"rb");
if (lathefile1 == NULL)
{
printf("Error opening '%s'\n", filename1);
exit(3);
}
lathefile2=fopen(filename2,"w");
if (lathefile2 == NULL)
{
printf("Error opening '%s'\n", filename2);
fclose(lathefile1);
exit(3);
}
if (fseek(lathefile1, 48, SEEK_SET))
{
printf("Error seeking '%s'\n", filename1);
fclose(lathefile1);
fclose(lathefile2);
exit(4);
}
io_count = fread(&byte, 1, 1, lathefile1);
count = byte;
io_count += fread(&byte, 1, 1, lathefile1);
if (io_count != 2)
{
printf("Error reading '%s'\n", filename1);
fclose(lathefile1);
fclose(lathefile2);
exit(5);
}
count += byte * 256;
printf("%s contains %d points\n", filename1, count);
io_count += fread(&byte, 1, 1, lathefile1);
x = byte;
io_count += fread(&byte, 1, 1, lathefile1);
x += byte * 256;
io_count += fread(&byte, 1, 1, lathefile1);
y = byte;
io_count += fread(&byte, 1, 1, lathefile1);
y += byte * 256;
if (io_count != 6)
{
printf("Error reading '%s'\n", filename1);
fclose(lathefile1);
fclose(lathefile2);
exit(5);
}
fprintf(lathefile2, "%d %d %d\n", x, y, 0);
for (word=1; word < count; word++)
{
io_count = 0;
io_count += fread(&byte, 1, 1, lathefile1);
x = byte;
io_count += fread(&byte, 1, 1, lathefile1);
x += byte * 256;
io_count += fread(&byte, 1, 1, lathefile1);
y = byte;
io_count += fread(&byte, 1, 1, lathefile1);
y += byte * 256;
if (io_count != 4)
{
printf("Error reading '%s'\n", filename1);
fclose(lathefile1);
fclose(lathefile2);
exit(5);
}
fprintf(lathefile2, "%d %d %d\n", x, y, -1);
}
fprintf(lathefile2, "%d %d %d\n", -1, -1, -1);
fclose(lathefile2);
fclose(lathefile1);
}