home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / plnk065.arj / PLNK065.ZIP / pilot-link.0.6.5 / include / pi-macros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-01  |  7.8 KB  |  281 lines

  1. #ifndef _PILOT_MACROS_H_
  2. #define _PILOT_MACROS_H_
  3.  
  4. #include "pi-args.h"
  5.  
  6. typedef unsigned long recordid_t;
  7.  
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11.  
  12. extern double get_float PI_ARGS((void *));
  13. extern void set_float PI_ARGS((void *, double));
  14.  
  15. #ifdef __cplusplus
  16. }
  17. #endif
  18.  
  19. #ifndef __cplusplus
  20.  
  21. #define get_long(ptr) ((unsigned long)\
  22.                        ((((unsigned char*)(ptr))[0] << 24) | \
  23.                        (((unsigned char*)(ptr))[1] << 16) | \
  24.                        (((unsigned char*)(ptr))[2] << 8)  | \
  25.                        (((unsigned char*)(ptr))[3])))
  26.  
  27. #define get_treble(ptr) ((unsigned long)\
  28.                         ((((unsigned char*)(ptr))[0] << 16) | \
  29.                          (((unsigned char*)(ptr))[1] << 8)  | \
  30.                          (((unsigned char*)(ptr))[2])))
  31.                        
  32. #define get_short(ptr) ((unsigned short)\
  33.                        ((((unsigned char*)(ptr))[0] << 8)  | \
  34.                         (((unsigned char*)(ptr))[1])))
  35.                         
  36. #define get_byte(ptr) (((unsigned char*)(ptr))[0])
  37.  
  38. #define get_slong(ptr) (signed long)(\
  39.                 (get_long((ptr)) > 0x7FFFFFFF) ?\
  40.                                 (((signed long)(get_long((ptr)) & 0x7FFFFFFF)) - 0x80000000):\
  41.                                 ((signed long)(get_long((ptr))))\
  42.                                 )
  43.  
  44. #define get_streble(ptr) (signed long)(\
  45.                 (get_treble((ptr)) > 0x7FFFFF) ?\
  46.                                 (((signed long)(get_treble((ptr)) & 0x7FFFFF)) - 0x800000):\
  47.                                 ((signed long)(get_treble((ptr))))\
  48.                                 )
  49.  
  50. #define get_sshort(ptr) (signed short)(\
  51.                 (get_short((ptr)) > 0x7FFF) ?\
  52.                                 (((signed short)(get_short((ptr)) & 0x7FFF)) - 0x8000):\
  53.                                 ((signed short)(get_short((ptr))))\
  54.                                 )
  55.  
  56. #define get_sbyte(ptr) (signed char)(\
  57.                 (get_byte((ptr)) > 0x7F) ?\
  58.                                 (((signed char)(get_byte((ptr)) & 0x7F)) - 0x80):\
  59.                                 ((signed char)(get_byte((ptr))))\
  60.                                 )
  61.  
  62. #define set_long(ptr,val) ((((unsigned char*)(ptr))[0] = (((unsigned long)(val)) >> 24) & 0xff), \
  63.                   (((unsigned char*)(ptr))[1] = (((unsigned long)(val)) >> 16) & 0xff), \
  64.                   (((unsigned char*)(ptr))[2] = (((unsigned long)(val)) >> 8) & 0xff), \
  65.                   (((unsigned char*)(ptr))[3] = (((unsigned long)(val)) >> 0) & 0xff))
  66.  
  67. #define set_slong(ptr,val) set_long((ptr),((unsigned long)(\
  68.                             (((signed long)(val)) < 0) ?\
  69.                             ((unsigned long)(((signed long)(val)) + 0x80000000) | 0x80000000) :\
  70.                             (val)\
  71.                            )))
  72.  
  73. #define set_treble(ptr,val) ((((unsigned char*)(ptr))[0] = (((unsigned long)(val)) >> 16) & 0xff), \
  74.                      (((unsigned char*)(ptr))[1] = (((unsigned long)(val)) >> 8) & 0xff), \
  75.                      (((unsigned char*)(ptr))[2] = (((unsigned long)(val)) >> 0) & 0xff))
  76.  
  77. #define set_streble(ptr,val) set_treble((ptr),((unsigned long)(\
  78.                             (((signed long)(val)) < 0) ?\
  79.                             ((unsigned long)(((signed long)(val)) + 0x800000) | 0x800000) :\
  80.                             (val)\
  81.                            )))
  82.                        
  83. #define set_short(ptr,val) ((((unsigned char*)(ptr))[0] = (((unsigned short)(val)) >> 8) & 0xff), \
  84.                     (((unsigned char*)(ptr))[1] = (((unsigned short)(val)) >> 0) & 0xff))
  85.  
  86. #define set_sshort(ptr,val) set_short((ptr),((unsigned short)(\
  87.                             (((signed short)(val)) < 0) ?\
  88.                             ((unsigned short)(((signed short)(val)) + 0x8000) | 0x8000) :\
  89.                             (val)\
  90.                            )))
  91.  
  92. #define set_byte(ptr,val) (((unsigned char*)(ptr))[0]=(val))
  93.  
  94. #define set_sbyte(ptr,val) set_byte((ptr),((unsigned char)(\
  95.                             (((signed char)(val)) < 0) ?\
  96.                             ((unsigned char)(((signed char)(val)) + 0x80) | 0x80) :\
  97.                             (val)\
  98.                            )))
  99.  
  100. #define char4(c1,c2,c3,c4) (((c1)<<24)|((c2)<<16)|((c3)<<8)|(c4))
  101.  
  102. #else /*ifdef __cplusplus*/
  103.  
  104. inline unsigned long get_long(const void *buf) 
  105. {
  106.      unsigned char *ptr = (unsigned char *) buf;
  107.  
  108.      return (*ptr << 24) | (*(++ptr) << 16) | (*(++ptr) << 8) | *(++ptr);
  109. }
  110.  
  111. inline signed long get_slong(const void *buf)
  112. {
  113.      unsigned long val = get_long(buf);
  114.      if (val > 0x7FFFFFFF)
  115.          return ((signed long)(val & 0x7FFFFFFF)) - 0x80000000;
  116.      else
  117.          return val;
  118. }
  119.  
  120. inline unsigned long get_treble(const void *buf) 
  121. {
  122.      unsigned char *ptr = (unsigned char *) buf;
  123.  
  124.      return (*ptr << 16) | (*(++ptr) << 8) | *(++ptr);
  125. }
  126.  
  127. inline signed long get_streble(const void *buf)
  128. {
  129.      unsigned long val = get_treble(buf);
  130.      if (val > 0x7FFFFF)
  131.          return ((signed long)(val & 0x7FFFFF)) - 0x800000;
  132.      else
  133.          return val;
  134. }
  135.  
  136. inline int get_short(const void *buf) 
  137. {
  138.      unsigned char *ptr = (unsigned char *) buf;
  139.  
  140.      return (*ptr << 8) | *(++ptr);
  141. }
  142.  
  143. inline signed short get_sshort(const void *buf)
  144. {
  145.      unsigned short val = get_short(buf);
  146.      if (val > 0x7FFF)
  147.          return ((signed short)(val & 0x7FFF)) - 0x8000;
  148.      else
  149.          return val;
  150. }
  151.  
  152. inline int get_byte(const void *buf) 
  153. {
  154.      return *((unsigned char *) buf);
  155. }
  156.  
  157. inline signed char get_sbyte(const void *buf)
  158. {
  159.      unsigned char val = get_byte(buf);
  160.      if (val > 0x7F)
  161.          return ((signed char)(val & 0x7F)) - 0x80;
  162.      else
  163.          return val;
  164. }
  165.  
  166. inline void set_long(void *buf, const unsigned long val) 
  167. {
  168.      unsigned char *ptr = (unsigned char *) buf;
  169.  
  170.      *ptr = (val >> 24) & 0xff;
  171.      *(++ptr) = (val >> 16) & 0xff;
  172.      *(++ptr) = (val >> 8) & 0xff;
  173.      *(++ptr) = val & 0xff;
  174. }
  175.  
  176. inline void set_slong(void *buf, const signed long val) 
  177. {
  178.      unsigned long uval;
  179.      
  180.      if (val < 0) {
  181.          uval = (val + 0x80000000);
  182.          uval |= 0x80000000;
  183.      } else
  184.          uval = val;
  185.      set_long(buf, uval);
  186. }
  187.  
  188. inline void set_treble(void *buf, const unsigned long val) 
  189. {
  190.      unsigned char *ptr = (unsigned char *) buf;
  191.      
  192.      *ptr = (val >> 16) & 0xff;
  193.      *(++ptr) = (val >> 8) & 0xff;
  194.      *(++ptr) = val & 0xff;
  195. }
  196.  
  197. inline void set_streble(void *buf, const signed long val) 
  198. {
  199.      unsigned long uval;
  200.      
  201.      if (val < 0) {
  202.          uval = (val + 0x800000);
  203.          uval |= 0x800000;
  204.      } else
  205.          uval = val;
  206.      set_treble(buf, uval);
  207. }
  208.  
  209. inline void set_short(void *buf, const int val) 
  210. {
  211.      unsigned char *ptr = (unsigned char *) buf;
  212.  
  213.      *ptr = (val >> 8) & 0xff;
  214.      *(++ptr) = val & 0xff;
  215. }
  216.  
  217. inline void set_sshort(void *buf, const signed short val) 
  218. {
  219.      unsigned short uval;
  220.      
  221.      if (val < 0) {
  222.          uval = (val + 0x8000);
  223.          uval |= 0x8000;
  224.      } else
  225.          uval = val;
  226.      set_treble(buf, uval);
  227. }
  228.  
  229. inline void set_byte(void *buf, const int val) 
  230. {
  231.      *((unsigned char *)buf) = val;
  232. }
  233.  
  234. inline void set_sbyte(void *buf, const signed char val) 
  235. {
  236.      unsigned char uval;
  237.      
  238.      if (val < 0) {
  239.          uval = (val + 0x80);
  240.          uval |= 0x80;
  241.      } else
  242.          uval = val;
  243.      set_byte(buf, uval);
  244. }
  245.  
  246. inline struct tm *getBufTm(struct tm *t, const void *buf, int setTime) 
  247. {
  248.      unsigned short int d = get_short(buf);
  249.      
  250.      t->tm_year = (d >> 9) + 4;
  251.      t->tm_mon = ((d >> 5) & 15) - 1;
  252.      t->tm_mday = d & 31;
  253.  
  254.      if (setTime) {
  255.       t->tm_hour = 0;
  256.       t->tm_min = 0;
  257.       t->tm_sec = 0;
  258.      }
  259.      
  260.      t->tm_isdst = -1;
  261.  
  262.      mktime(t);
  263.      
  264.      return t;
  265. }
  266.  
  267. inline void setBufTm(void *buf, const struct tm *t)
  268. {
  269.      set_short(buf,
  270.            ((t->tm_year - 4) << 9) | ((t->tm_mon + 1) << 5) | t->tm_mday);
  271. }
  272.  
  273. inline unsigned long char4(char c1, char c2, char c3, char c4)
  274. {
  275.      return (c1<<24)|(c2<<16)|(c3<<8)|c4;
  276. }
  277.  
  278. #endif /*__cplusplus*/
  279.  
  280. #endif /* _PILOT_MACROS_H_ */
  281.