home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / PARSE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  2.3 KB  |  128 lines

  1. #include "stdafx.h"
  2. #include "qe3.h"
  3.  
  4. char    token[MAXTOKEN];
  5. qboolean    unget;
  6. char    *script_p;
  7. int        scriptline;
  8.  
  9. void    StartTokenParsing (char *data)
  10. {
  11.     scriptline = 1;
  12.     script_p = data;
  13.     unget = false;
  14. }
  15.  
  16. qboolean WINAPI GetToken (qboolean crossline)
  17. {
  18.     char    *token_p;
  19.  
  20.     if (unget)                         // is a token allready waiting?
  21.     {
  22.         unget = false;
  23.         return true;
  24.     }
  25.  
  26. //
  27. // skip space
  28. //
  29. skipspace:
  30.     while (*script_p <= 32)
  31.     {
  32.         if (!*script_p)
  33.         {
  34.             if (!crossline)
  35.                 Sys_Printf("Warning: Line %i is incomplete [01]\n",scriptline);
  36.             return false;
  37.         }
  38.         if (*script_p++ == '\n')
  39.         {
  40.             if (!crossline)
  41.                 Sys_Printf("Warning: Line %i is incomplete [02]\n",scriptline);
  42.             scriptline++;
  43.         }
  44.     }
  45.  
  46.     if (script_p[0] == '/' && script_p[1] == '/')    // comment field
  47.     {
  48.         if (!crossline)
  49.             Sys_Printf("Warning: Line %i is incomplete [03]\n",scriptline);
  50.         while (*script_p++ != '\n')
  51.             if (!*script_p)
  52.             {
  53.                 if (!crossline)
  54.                     Sys_Printf("Warning: Line %i is incomplete [04]\n",scriptline);
  55.                 return false;
  56.             }
  57.         goto skipspace;
  58.     }
  59.  
  60. //
  61. // copy token
  62. //
  63.     token_p = token;
  64.  
  65.     if (*script_p == '"')
  66.     {
  67.         script_p++;
  68.     //if (*script_p == '"')   // handle double quotes i suspect they are put in by other editors cccasionally
  69.     //  script_p++;
  70.         while ( *script_p != '"' )
  71.         {
  72.             if (!*script_p)
  73.                 Error ("EOF inside quoted token");
  74.             *token_p++ = *script_p++;
  75.             if (token_p == &token[MAXTOKEN])
  76.                 Error ("Token too large on line %i",scriptline);
  77.         }
  78.         script_p++;
  79.     //if (*script_p == '"')   // handle double quotes i suspect they are put in by other editors cccasionally
  80.     //  script_p++;
  81.     }
  82.     else while ( *script_p > 32 )
  83.     {
  84.         *token_p++ = *script_p++;
  85.         if (token_p == &token[MAXTOKEN])
  86.             Error ("Token too large on line %i",scriptline);
  87.     }
  88.  
  89.     *token_p = 0;
  90.     
  91.     return true;
  92. }
  93.  
  94. void WINAPI UngetToken (void)
  95. {
  96.     unget = true;
  97. }
  98.  
  99.  
  100. /*
  101. ==============
  102. TokenAvailable
  103.  
  104. Returns true if there is another token on the line
  105. ==============
  106. */
  107. qboolean TokenAvailable (void)
  108. {
  109.     char    *search_p;
  110.  
  111.     search_p = script_p;
  112.  
  113.     while ( *search_p <= 32)
  114.     {
  115.         if (*search_p == '\n')
  116.             return false;
  117.         if (*search_p == 0)
  118.             return false;
  119.         search_p++;
  120.     }
  121.  
  122.     if (*search_p == ';')
  123.         return false;
  124.  
  125.     return true;
  126. }
  127.  
  128.