home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / readmap / readmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-29  |  2.8 KB  |  102 lines

  1. /*-------------------------------------------------------------------------
  2. File    : readmap.c
  3. Author  : John Carmack (id Software) - the algorithms and original code.
  4.           Cameron Newham - conversion to C, load_file,
  5.                            and some commenting.
  6. Version : 1.0
  7. Date    : 96/08/29
  8.  
  9. Description
  10. -----------
  11. Reads the MAP file into a buffer and then parses the buffer, extracting
  12. tokens and creating brushes (faces) if necessary.
  13.  
  14. Comments
  15. --------
  16. Rather a hodgepodge at the moment.
  17. -------------------------------------------------------------------------*/
  18.  
  19. #include <stdio.h>
  20. #include "readmap.h"
  21. #include "io.h"
  22.  
  23. struct key_value_pair
  24. {
  25.   char key [MAXTOKEN];
  26.   char value [MAXTOKEN];
  27. };
  28.  
  29. struct     key_value_pair keys[MAXKEYS];  /* an array of key/value pairs */
  30.  
  31.  
  32. /*--------------------------------------
  33. ***MAIN***
  34. --------------------------------------*/
  35. void main ()
  36. {
  37.   char       *dat;            /* the text from the file in one lump */
  38.   char       *fname;     
  39.   int        location;        /* location in the char data */
  40.   int        scriptline;      /* which line from original file we are on */
  41.   char       token[MAXTOKEN]; /* somewhere to put each token */
  42.   int        key_number;      /* next storage for keys */
  43.  
  44. float *point;
  45.  
  46.  
  47.   /* load the data from the file into the dat structure */
  48.   dat = Load_File ("test.map", dat);
  49.  
  50.   /* initialise for reading tokens */
  51.   location = 0;
  52.   scriptline = 0;
  53.   key_number = 0;
  54.  
  55.  
  56.   /* Look for the first { token */
  57.   if (!GetToken(TRUE, token, &scriptline, dat, &location))
  58.   {
  59.     free(dat);  /* nothing to be done so free memory*/
  60.     exit (0);
  61.   }
  62.  
  63.  
  64.   if (strcmp(token, "{"))
  65.     Error(scriptline,"Error: { not found\n");
  66.  
  67.   while (TRUE) {
  68.     /* Start looking for other tokens */
  69.     if (!GetToken (TRUE, token, &scriptline, dat, &location))
  70.       break;
  71.     if (!strcmp (token, "}") )
  72.       break;
  73.     if (!strcmp (token, "{") )
  74.     {
  75.       /* Read a brush */
  76.       ReadBrush (token, &scriptline, dat, &location);
  77.  
  78. /* HOOK - the global "faces" is an array of faces for the current
  79.    brush.  "numfaces" is the number of faces there are. Copy these
  80.    because they'll be overwritten by the next call to ReadBrush. Also
  81.    be aware that freeWindings gets called but has been modified so
  82.    as not to destroy the structures containing the winding (vertex)
  83.    information */
  84.  
  85.     }
  86.     else
  87.     {
  88.       /* Read a key/value pair */
  89.       strcpy (keys[key_number].key, token);
  90.       GetToken (FALSE, token, &scriptline, dat, &location);
  91.       strcpy (keys[key_number++].value, token);
  92. printf (">>key/val pair = %s/%s\n", keys[key_number-1].key,keys[key_number-1].value);
  93.  
  94. /* HOOK - key/value pairs get stored in "keys". This only applies
  95.    to the initial info before the brush definitions. */
  96.  
  97.     }
  98.   }
  99. printf(">>Finished.  lastline = %d\n", scriptline);
  100. }
  101.  
  102.