home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / libc / datetok.h < prev    next >
C/C++ Source or Header  |  1992-11-06  |  2KB  |  66 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 HOURS    10    /* */
  19. #define DAYS    11    /* */
  20. #define MONTHS    12
  21. #define YEARS    13
  22. #define NUMBER    14
  23. /* these are only for relative dates */
  24. #define BEFORE    15
  25. #define AFTER    16
  26. #define AGO    17
  27. #define ORDINAL 18
  28.  
  29. #ifdef notdef
  30. #define SECS(n)        ((time_t)(n))
  31. #define MINS(n)        ((time_t)(n) * SECS(60))
  32. #define HOURS(n)    ((time_t)(n) * MINS(60))    /* 3600 secs */
  33. #define DAYS(n)        ((time_t)(n) * HOURS(24))    /* 86400 secs */
  34. /* months and years are not constant length, must be specially dealt with */
  35. #endif
  36.  
  37. #define TOKMAXLEN 6    /* only this many chars are stored in datetktbl */
  38.  
  39. /*
  40.  * definitions for squeezing values into low 7 bits of "value" to avoid
  41.  * overflow on extremely picky machines with signed chars.
  42.  * all timezones we care about are divisible by 30, and the largest value
  43.  * (780) when divided is 26, which fits in 5 bits (037), so have a bit to
  44.  * spare(!).
  45.  */
  46. #define SIGNBIT 0100
  47. #define VALMASK  037
  48. #define DIVISOR 30
  49. #define NEG(n)        ((n)|SIGNBIT)
  50. #define PACK(v)        ((v) < 0? NEG((-(v))/DIVISOR): (v)/DIVISOR)
  51. #define TOVAL(tp, v)    ((tp)->value = PACK(v))
  52. #define SIGNEDCHAR(c)    ((c)&SIGNBIT? -((c)&VALMASK): (c))
  53. #define FROMVAL(tp)    (-SIGNEDCHAR((tp)->value) * DIVISOR)    /* uncompress */
  54.  
  55. /* keep this struct small; it gets used a lot */
  56. typedef struct {
  57.     char token[TOKMAXLEN];
  58.     char type;
  59.     char value;        /* this may be unsigned, alas */
  60. } datetkn;
  61.  
  62. extern datetkn *datetoktype(/* char *s */);
  63. extern datetkn *datebsearch(/* char *key, datetkn *base, unsigned int nel */);
  64.  
  65. #endif /* DATETOK_H__ */ /* Do not add anything after this line */
  66.