home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / cad / rayl200.zip / LAT2RAYL.C < prev    next >
C/C++ Source or Header  |  1993-06-05  |  3KB  |  127 lines

  1. #include <stdio.h>
  2.  
  3. #define VERSION 1.10
  4.  
  5. FILE *lathefile1, *lathefile2;
  6.  
  7. void main(argc,argv)
  8.     int argc;
  9.     char *argv[];
  10.     {
  11.     char filename1[30], filename2[30];
  12.     unsigned char byte, slices;
  13.     int word, x, y;
  14.     int count;
  15.     int io_count = 0;
  16.     unsigned char slice_table[] = { 3,    4,  5,    6,  8,    9, 10, 12, 15, 18,
  17.                    20, 24, 30, 36, 40, 45, 60, 72, 90, 120};
  18.  
  19.     fprintf(stderr,"Lat2RayL v%2.2f (c) 1993 Koehler\n\n",VERSION);
  20.     if(argc < 2)   /* Missing the input file name argument - bitch and die */
  21.        {
  22.        puts("     Usage: lat2rayl <infile>\n");
  23.        exit(1);
  24.        }
  25.     strcpy(filename1, argv[1]);
  26.     if (strchr(filename1, '.') != NULL)
  27.     {
  28.     printf("File cannot have an extension\n");
  29.     exit(2);
  30.     }
  31.     strcpy(filename2, filename1);
  32.     strcat(filename1, ".lat");
  33.     strcat(filename2, ".dat");
  34.     lathefile1=fopen(filename1,"rb");
  35.     if (lathefile1 == NULL)
  36.     {
  37.     printf("Error opening '%s'\n", filename1);
  38.     exit(3);
  39.     }
  40.     lathefile2=fopen(filename2,"w");
  41.     if (lathefile2 == NULL)
  42.     {
  43.     printf("Error opening '%s'\n", filename2);
  44.     fclose(lathefile1);
  45.     exit(3);
  46.     }
  47.  
  48.     /*    -- Get Number of Slices -- */
  49.     if (fseek(lathefile1, 14, SEEK_SET))
  50.     {
  51.     printf("Error seeking '%s'\n", filename1);
  52.     fclose(lathefile1);
  53.     fclose(lathefile2);
  54.     exit(4);
  55.     }
  56.     if (fread(&byte, 1, 1, lathefile1) != 1)
  57.     {
  58.     printf("Error reading '%s'\n", filename1);
  59.     fclose(lathefile1);
  60.     fclose(lathefile2);
  61.     exit(5);
  62.     }
  63.     slices = slice_table [byte];
  64.     fprintf(lathefile2, "%d %d %d\n", -1, -1, slices);
  65.  
  66.     /*    -- Get Number of Points -- */
  67.     if (fseek(lathefile1, 48, SEEK_SET))
  68.     {
  69.     printf("Error seeking '%s'\n", filename1);
  70.     fclose(lathefile1);
  71.     fclose(lathefile2);
  72.     exit(4);
  73.     }
  74.     io_count = fread(&byte, 1, 1, lathefile1);
  75.     count = byte;
  76.     io_count += fread(&byte, 1, 1, lathefile1);
  77.     if (io_count != 2)
  78.     {
  79.     printf("Error reading '%s'\n", filename1);
  80.     fclose(lathefile1);
  81.     fclose(lathefile2);
  82.     exit(5);
  83.     }
  84.     count += byte * 256;
  85.  
  86.     printf("%s contains %d points\n", filename1, count);
  87.     io_count += fread(&byte, 1, 1, lathefile1);
  88.     x = byte;
  89.     io_count += fread(&byte, 1, 1, lathefile1);
  90.     x += byte * 256;
  91.     io_count += fread(&byte, 1, 1, lathefile1);
  92.     y = byte;
  93.     io_count += fread(&byte, 1, 1, lathefile1);
  94.     y += byte * 256;
  95.     if (io_count != 6)
  96.     {
  97.     printf("Error reading '%s'\n", filename1);
  98.     fclose(lathefile1);
  99.     fclose(lathefile2);
  100.     exit(5);
  101.     }
  102.     fprintf(lathefile2, "%d %d %d\n", x, y, 0);
  103.     for (word=1; word < count; word++)
  104.     {
  105.     io_count = 0;
  106.     io_count += fread(&byte, 1, 1, lathefile1);
  107.     x = byte;
  108.     io_count += fread(&byte, 1, 1, lathefile1);
  109.     x += byte * 256;
  110.     io_count += fread(&byte, 1, 1, lathefile1);
  111.     y = byte;
  112.     io_count += fread(&byte, 1, 1, lathefile1);
  113.     y += byte * 256;
  114.     if (io_count != 4)
  115.         {
  116.         printf("Error reading '%s'\n", filename1);
  117.         fclose(lathefile1);
  118.         fclose(lathefile2);
  119.         exit(5);
  120.         }
  121.     fprintf(lathefile2, "%d %d %d\n", x, y, -1);
  122.     }
  123.     fprintf(lathefile2, "%d %d %d\n", -1, -1, -1);
  124.     fclose(lathefile2);
  125.     fclose(lathefile1);
  126.     }
  127.