home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / include / xp_mcom.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.6 KB  |  197 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20.  * This file should be the first Mcom file included
  21.  *
  22.  * All cross-platform definitions, regardless of project, should be
  23.  *  contained in this file or its includes
  24.  */
  25.  
  26. #ifndef _MCOM_H_
  27. #define _MCOM_H_
  28.  
  29. #include "xp_core.h"
  30. #include "xp_mem.h"
  31. #include "xp_debug.h"
  32. #include "xp_str.h"
  33. #include "xp_list.h"
  34.  
  35.  
  36. /* platform-specific types */
  37.  
  38. /* include header files needed for prototypes/etc */
  39.  
  40. #include "xp_file.h"
  41.  
  42. XP_BEGIN_PROTOS
  43.  
  44. /* XXX where should this kind of junk go? */
  45. unsigned char *XP_WordWrap(int charset, unsigned char *string, int maxColumn,
  46.                  int checkQuoting);
  47.  
  48. XP_END_PROTOS
  49.  
  50. /* --------------------------------------------------------------------- */
  51. /*
  52.     Define the hooks for cross-platform string + memory functions
  53.  
  54. */
  55.  
  56. #ifdef DEBUG
  57.     XP_BEGIN_PROTOS
  58.         extern char * NOT_NULL (const char *x);
  59.     XP_END_PROTOS
  60. #else
  61. #    define NOT_NULL(X)    X
  62. #endif
  63.  
  64. #include <string.h>
  65. #define XP_STRLEN(s)              strlen(NOT_NULL(s))
  66. #define XP_STRCMP(a, b)           strcmp(NOT_NULL(a), NOT_NULL(b))
  67. #define XP_STRNCMP(a, b, n)       strncmp(NOT_NULL(a), NOT_NULL(b), (n))
  68. #define XP_STRCPY(d, s)           strcpy(NOT_NULL(d), NOT_NULL(s))
  69. #define XP_STRCHR                 strchr
  70. #define XP_STRRCHR                strrchr
  71. #define XP_STRTOK                 strtok
  72. #define XP_STRCAT                 strcat
  73. #define XP_STRNCAT                strncat
  74. #define XP_STRSTR                 strstr
  75. #define XP_STRTOUL                strtoul
  76.  
  77.  
  78. /* XP_FILENAMECMP compares two filenames, treating case differences
  79.    appropriately for this OS. */
  80.  
  81. #if defined(XP_WIN) || defined(XP_OS2)
  82. #define XP_FILENAMECMP         stricmp    
  83. #else
  84. #define XP_FILENAMECMP        XP_STRCMP
  85. #endif
  86.  
  87.  
  88. #if !defined(XP_WIN) && !defined(XP_OS2)
  89. /* strdup is not an ANSI function */
  90. XP_BEGIN_PROTOS
  91. extern char * strdup (const char * s);
  92. XP_END_PROTOS
  93. #endif
  94.  
  95. #include <memory.h>
  96.  
  97. #define XP_STRDUP(s)              strdup((s))
  98. #define XP_MEMCPY(d, s, n)        memcpy((d), (s), (n))
  99.  
  100. /* NOTE: XP_MEMMOVE gurantees that overlaps will be properly handled */
  101. #if defined( __sun) && !defined(__svr4__)
  102. #define XP_MEMMOVE(Dest,Src,Len)  bcopy((Src),(Dest),(Len))
  103. #else
  104. #define XP_MEMMOVE(Dest,Src,Len)  memmove((Dest),(Src),(Len))
  105. #endif /* __sun */
  106.  
  107. #define XP_MEMSET                 memset
  108. #define XP_SPRINTF                sprintf
  109.  
  110. /* should I really include this here or what? */
  111. #ifdef XP_MAC
  112. #include "prprf.h"  
  113. #else
  114. #include "prprf.h"  
  115. #endif
  116. #define XP_SAFE_SPRINTF              PR_snprintf
  117. #define XP_MEMCMP                 memcmp
  118.  
  119. #define XP_VSPRINTF               vsprintf
  120.  
  121. #define XP_IS_SPACE(VAL)                \
  122.     (((((intn)(VAL)) & 0x7f) == ((intn)(VAL))) && isspace((intn)(VAL)) )
  123.  
  124. #define XP_IS_CNTRL(i)     ((((unsigned int) (i)) > 0x7f) ? (int) 0 : iscntrl(i))
  125. #define XP_IS_DIGIT(i) ((((unsigned int) (i)) > 0x7f) ? (int) 0 : isdigit(i))
  126.  
  127. #if defined(XP_WIN) || defined(XP_OS2)
  128. #define XP_IS_ALPHA(VAL)                (isascii((int)(VAL)) && isalpha((int)(VAL)))
  129. #else
  130. #define XP_IS_ALPHA(VAL) ((((unsigned int) (VAL)) > 0x7f) ? FALSE : isalpha((int)(VAL)))
  131. #endif
  132.  
  133. #define XP_ATOI(PTR)                    (atoi((PTR)))
  134.  
  135. /* NOTE: XP_BCOPY gurantees that overlaps will be properly handled */
  136. #ifdef XP_WIN16
  137.  
  138. XP_BEGIN_PROTOS
  139. extern void WIN16_bcopy(char *, char *, unsigned long);
  140. XP_END_PROTOS
  141.  
  142. #define XP_BCOPY(PTR_FROM, PTR_TO, LEN) \
  143.                 (WIN16_bcopy((char *) (PTR_FROM), (char *)(PTR_TO), (LEN)))
  144. #else
  145. #define XP_BCOPY(Src,Dest,Len)  XP_MEMMOVE((Dest),(Src),(Len))
  146. #endif
  147.  
  148. #define XP_BZERO(a,b)             memset(a,0,b)
  149.  
  150. #ifdef XP_WIN
  151. #define XP_RANDOM         rand
  152. #define XP_SRANDOM(seed)    srand((seed))
  153. #endif
  154. #ifdef XP_OS2
  155. #define XP_RANDOM        rand
  156. #define XP_SRANDOM(seed)    srand((seed))
  157. #endif
  158. #ifdef XP_MAC
  159. #define XP_RANDOM         rand
  160. #define XP_SRANDOM(seed)    srand((seed))
  161. #endif
  162. #ifdef XP_UNIX
  163. #if !defined(XP_RANDOM) || !defined(XP_SRANDOM)   /* defined in both xp_mcom.h and xp_str.h */
  164. #if defined(UNIXWARE) || defined(_INCLUDE_HPUX_SOURCE) || (defined(__sun) && defined(__svr4__)) || defined(SNI) || defined(NCR)
  165. #define XP_RANDOM        rand
  166. #define XP_SRANDOM(seed)    srand((seed))
  167. #else
  168. #define XP_RANDOM        random
  169. #define XP_SRANDOM(seed)    srandom((seed))
  170. #endif
  171. #endif
  172. #endif
  173.  
  174. #ifdef XP_MAC
  175. XP_BEGIN_PROTOS
  176.  
  177. extern time_t GetTimeMac();
  178. extern time_t Mactime(time_t *timer);
  179. extern struct tm *Macgmtime(const time_t *timer);
  180. extern time_t Macmktime (struct tm *timeptr);
  181. extern char * Macctime(const time_t *);
  182. extern struct tm *Maclocaltime(const time_t *);
  183.  
  184. XP_END_PROTOS
  185.  
  186. #define XP_TIME()    GetTimeMac()
  187. #define time(t)        Mactime(t)
  188. #define gmtime(t)    Macgmtime(t)
  189. #define mktime(t)    Macmktime(t)
  190. #define ctime(t)    Macctime(t)
  191. #define localtime(t)    Maclocaltime(t)
  192. #define UNIXMINUSMACTIME 2082844800UL
  193. #else
  194. #define XP_TIME()    time(0)
  195. #endif
  196. #endif /* _MCOM_H_ */
  197.