home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / libc / datetok.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-14  |  1.7 KB  |  62 lines

  1. #ifndef DATETOK_H__
  2. #define DATETOK_H__
  3.  
  4. #define AM 0
  5. #define PM 1
  6.  
  7. /* can't have more of these than there are bits in an unsigned long */
  8. #define MONTH    1
  9. #define YEAR    2
  10. #define DAY    3
  11. #define TIME    4
  12. #define TZ    5
  13. #define DTZ    6
  14. #define IGNORE    7
  15. #define AMPM    8
  16. /* below here are unused so far */
  17. #define SECONDS    9
  18. #define MONTHS    10
  19. #define YEARS    11
  20. #define NUMBER    12
  21. /* these are only for relative dates */
  22. #define BEFORE    13
  23. #define AFTER    14
  24. #define AGO    15
  25.  
  26.  
  27. #define SECS(n)        ((time_t)(n))
  28. #define MINS(n)        ((time_t)(n) * SECS(60))
  29. #define HOURS(n)    ((time_t)(n) * MINS(60))    /* 3600 secs */
  30. #define DAYS(n)        ((time_t)(n) * HOURS(24))    /* 86400 secs */
  31. /* months and years are not constant length, must be specially dealt with */
  32.  
  33. #define TOKMAXLEN 6    /* only this many chars are stored in datetktbl */
  34.  
  35. /*
  36.  * definitions for squeezing values into low 7 bits of "value" to avoid
  37.  * overflow on extremely picky machines with signed chars.
  38.  * all timezones we care about are divisible by 30, and the largest value
  39.  * (780) when divided is 26, which fits in 5 bits (037), so have a bit to
  40.  * spare(!).
  41.  */
  42. #define SIGNBIT 0100
  43. #define VALMASK  037
  44. #define DIVISOR 30
  45. #define NEG(n)        ((n)|SIGNBIT)
  46. #define PACK(v)        ((v) < 0? NEG((-(v))/DIVISOR): (v)/DIVISOR)
  47. #define TOVAL(tp, v)    ((tp)->value = PACK(v))
  48. #define SIGNEDCHAR(c)    ((c)&SIGNBIT? -((c)&VALMASK): (c))
  49. #define FROMVAL(tp)    (-SIGNEDCHAR((tp)->value) * DIVISOR)    /* uncompress */
  50.  
  51. /* keep this struct small; it gets used a lot */
  52. typedef struct {
  53.     char token[TOKMAXLEN];
  54.     char type;
  55.     char value;        /* this may be unsigned, alas */
  56. } datetkn;
  57.  
  58. extern datetkn *datetoktype(/* char *s */);
  59. extern datetkn *datebsearch(/* char *key, datetkn *base, unsigned int nel */);
  60.  
  61. #endif /* DATETOK_H__ */ /* Do not add anything after this line */
  62.