home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / worldmap / demo / displayd.c < prev    next >
Text File  |  1986-01-18  |  1KB  |  50 lines

  1. /*  displayd  -    display the special demo file demo.mp2.
  2.  
  3.         Copyright 1986 John B. Allison                */
  4.  
  5. displayd(){
  6.  
  7. #define READMODE 0x8000        /*  open a file in read mode    */
  8.  
  9.     int fp, n;
  10.     float x, y;
  11.  
  12.     struct {                /*  input record structure  */
  13.     int    type;
  14.     float    xvalue,
  15.         yvalue;
  16.     } record;
  17.  
  18.  
  19.  
  20.     /*  Open the binary .mp2 file for read.  */
  21.  
  22.     if((fp=open("demo.mp2", READMODE)) == -1){
  23.         closegraphics();
  24.         printf("Error opening demo.mp2\n");
  25.         exit();
  26.     }
  27.  
  28.     /*  Read file until EOF  */
  29.  
  30.     while((n=read(fp, &record, sizeof(record))) != 0){
  31.  
  32.         if(n == -1){            /*  read error  */
  33.             closegraphics();
  34.             printf("Error reading demo.mp2\n");
  35.             exit();
  36.         }
  37.  
  38.         x = record.xvalue;    /*  successful read  */
  39.         y = record.yvalue;
  40.  
  41.         if(record.type == 0){    /*  start a new string  */
  42.             movabs(&x, &y);
  43.         } else {        /*  draw line segment  */
  44.             lnabs(&x, &y);    
  45.         }
  46.     }
  47.  
  48.     close(fp);
  49. }
  50.