]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Merge remote-tracking branch 'origin/pp-unary-numbers'
authorWolfgang Bumiller <blub@speed.at>
Thu, 3 Jan 2013 13:58:02 +0000 (14:58 +0100)
committerWolfgang Bumiller <blub@speed.at>
Thu, 3 Jan 2013 13:58:02 +0000 (14:58 +0100)
1  2 
ftepp.c

diff --combined ftepp.c
index ea686612cfd08156d65fe7326a29a205516779e6,ecc36d8e1851f422aed1c31f0e2696ae71db548a..838d0de38d37f9198fbe3fa2e795340e83c09394
+++ b/ftepp.c
@@@ -21,7 -21,6 +21,7 @@@
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   * SOFTWARE.
   */
 +#include <time.h>
  #include "gmqcc.h"
  #include "lexer.h"
  
@@@ -70,6 -69,11 +70,6 @@@ typedef struct 
      char        *includename;
  } ftepp_t;
  
 -typedef struct {
 -    const char  *name;
 -    char      *(*func)(lex_file *);
 -} predef_t;
 -
  /*
   * Implement the predef subsystem now.  We can do this safely with the
   * help of lexer contexts.
  static uint32_t ftepp_predef_countval = 0;
  static uint32_t ftepp_predef_randval  = 0;
  
 +/* __DATE__ */
 +char *ftepp_predef_date(lex_file *context) {
 +    struct tm *itime;
 +    time_t     rtime;
 +    char      *value = mem_a(82);
 +    /* 82 is enough for strftime but we also have " " in our string */
 +
 +    (void)context;
 +
 +    /* get time */
 +    time (&rtime);
 +    itime = localtime(&rtime);
 +
 +    strftime(value, 82, "\"%b %d %Y\"", itime);
 +
 +    return value;
 +}
 +
 +/* __TIME__ */
 +char *ftepp_predef_time(lex_file *context) {
 +    struct tm *itime;
 +    time_t     rtime;
 +    char      *value = mem_a(82);
 +    /* 82 is enough for strftime but we also have " " in our string */
 +
 +    (void)context;
 +
 +    /* get time */
 +    time (&rtime);
 +    itime = localtime(&rtime);
 +
 +    strftime(value, 82, "\"%X\"", itime);
 +
 +    return value;
 +}
 +
  /* __LINE__ */
  char *ftepp_predef_line(lex_file *context) {
      char   *value;
@@@ -163,15 -131,13 +163,15 @@@ char *ftepp_predef_randomlast(lex_file 
      return value;
  }
  
 -static const predef_t ftepp_predefs[] = {
 +const ftepp_predef_t ftepp_predefs[FTEPP_PREDEF_COUNT] = {
      { "__LINE__",         &ftepp_predef_line        },
      { "__FILE__",         &ftepp_predef_file        },
      { "__COUNTER__",      &ftepp_predef_counter     },
      { "__COUNTER_LAST__", &ftepp_predef_counterlast },
      { "__RANDOM__",       &ftepp_predef_random      },
      { "__RANDOM_LAST__",  &ftepp_predef_randomlast  },
 +    { "__DATE__",         &ftepp_predef_date        },
 +    { "__TIME__",         &ftepp_predef_time        }
  };
  
  #define ftepp_tokval(f) ((f)->lex->tok.value)
@@@ -822,6 -788,7 +822,7 @@@ static bool ftepp_if_value(ftepp_t *fte
  {
      ppmacro *macro;
      bool     wasnot = false;
+     bool     wasneg = false;
  
      if (!ftepp_skipspace(ftepp))
          return false;
              return false;
      }
  
+     if (ftepp->token == TOKEN_OPERATOR && !strcmp(ftepp_tokval(ftepp), "-"))
+     {
+         wasneg = true;
+         ftepp_next(ftepp);
+         if (!ftepp_skipspace(ftepp))
+             return false;
+     }
      switch (ftepp->token) {
          case TOKEN_IDENT:
          case TOKEN_TYPENAME:
              }
              break;
          case TOKEN_STRINGCONST:
+             *value_out = 0;
              *out = false;
              break;
          case TOKEN_INTCONST:
  
          default:
              ftepp_error(ftepp, "junk in #if: `%s` ...", ftepp_tokval(ftepp));
+             if (opts.debug)
+                 ftepp_error(ftepp, "internal: token %i\n", ftepp->token);
              return false;
      }
+     if (wasneg)
+         *value_out = -*value_out;
      if (wasnot) {
          *out = !*out;
          *value_out = (*out ? 1 : 0);