Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
6.4 KiB

  1. /*
  2. ** translat.h - Translation macros for common DOS / Windows functions.
  3. **
  4. ** Author: DavidDi (stolen from ToddLa)
  5. */
  6. #ifndef WM_USER
  7. /********************************* DOS code ********************************/
  8. // Globals
  9. ///////////
  10. INT _ret;
  11. INT _error;
  12. // Types
  13. /////////
  14. typedef unsigned CHAR BYTE;
  15. typedef unsigned SHORT WORD;
  16. typedef unsigned LONG DWORD;
  17. typedef INT BOOL;
  18. typedef CHAR * PSTR;
  19. typedef CHAR NEAR * NPSTR;
  20. typedef CHAR FAR * LPSTR;
  21. typedef INT FAR * LPINT;
  22. // Constants
  23. /////////////
  24. // NULL
  25. #ifndef NULL
  26. #if (_MSC_VER >= 600)
  27. #define NULL ((void *)0)
  28. #elif (defined(M_I86SM) || defined(M_I86MM))
  29. #define NULL 0
  30. #else
  31. #define NULL 0L
  32. #endif
  33. #endif
  34. // modifiers
  35. #define FAR FAR
  36. #define NEAR near
  37. #define LONG long
  38. #define VOID void
  39. #define PASCAL PASCAL
  40. // Boolean values
  41. #define FALSE 0
  42. #define TRUE 1
  43. // Macros
  44. //////////
  45. // byte manipulation
  46. #define LOWORD(l) ((WORD)(l))
  47. #define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
  48. #define LOBYTE(w) ((BYTE)(w))
  49. #define HIBYTE(w) (((WORD)(w) >> 8) & 0xFF)
  50. #define MAKELONG(a, b) ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
  51. // file i/o
  52. //-protect-
  53. #define FOPEN(psz) ( \
  54. (_ret = -1), \
  55. (_error = _dos_open(psz, O_RDONLY, &_ret)), \
  56. _ret \
  57. )
  58. //-protect-
  59. #define FCREATE(psz) ( \
  60. (_ret = -1), \
  61. (_error = _dos_creat(psz, _A_NORMAL, &_ret)), \
  62. _ret \
  63. )
  64. #define FCLOSE(dosh) (_error = _dos_close(dosh))
  65. //-protect-
  66. #define FREAD(dosh, buf, len) ( \
  67. (_error = _dos_read(dosh, buf, len, &_ret)), \
  68. _ret \
  69. )
  70. //-protect-
  71. #define FWRITE(dosh, buf, len) ( \
  72. (_error = _dos_write(dosh, buf, len, &_ret)), \
  73. _ret \
  74. )
  75. #define FSEEK(dosh, off, i) lseek(dosh, (long)(off), i)
  76. #define FERROR() _error
  77. // near heap memory management
  78. #define ALLOC(n) malloc(n)
  79. #define FREE(p) free(p)
  80. #define SIZE(p) _msize(p)
  81. #define REALLOC(p, n) realloc(p,n)
  82. // FAR heap memory management
  83. #define FALLOC(n) _fmalloc(n)
  84. #define FFREE(n) _ffree(n)
  85. // string manipulation
  86. #define STRCAT(psz1, psz2) strcat(psz1, psz2)
  87. #define STRCMP(psz1, psz2) strcmp(psz1, psz2)
  88. #define STRCMPI(psz1, psz2) strcmpi(psz1, psz2)
  89. #define STRCPY(psz1, psz2) strcpy(psz1, psz2)
  90. #define STRLEN(psz) strlen(psz)
  91. #define STRLWR(psz) strlwr(psz)
  92. #define STRUPR(psz) strupr(psz)
  93. // character classification
  94. #define ISALPHA(c) isalpha(c)
  95. #define ISALPHANUMERIC(c) isalnum(c)
  96. #define ISLOWER(c) islower(c)
  97. #define ISUPPER(c) isupper(c)
  98. #else
  99. /******************************* Windows code ******************************/
  100. // file i/o
  101. #ifdef ORGCODE
  102. #define FOPEN(psz) _lopen(psz, READ)
  103. #else
  104. #define FOPEN(psz) _lopen(psz, OF_READ)
  105. #endif
  106. #define FCREATE(psz) _lcreat(psz, 0)
  107. #define FCLOSE(dosh) _lclose(dosh)
  108. #define FREAD(dosh, buf, len) _lread(dosh, buf, len)
  109. #define FWRITE(dosh, buf, len) _lwrite(dosh, buf, len)
  110. #define FSEEK(dosh, off, i) _llseek(dosh, (DWORD)off, i)
  111. #define FERROR() 0
  112. // near heap memory management
  113. #define ALLOC(n) (VOID *)LocalAlloc(LPTR, n)
  114. #define FREE(p) LocalFree(p)
  115. #define SIZE(p) LocalSize(p)
  116. #define REALLOC(p, n) LocalRealloc(p, n, LMEM_MOVEABLE)
  117. // FAR heap memory management
  118. #ifdef ORGCODE
  119. #define FALLOC(n) (VOID FAR *)MAKELONG(0, GlobalAlloc(GPTR, (DWORD)n))
  120. #define FFREE(n) GlobalFree((HANDLE)HIWORD((LONG)n))
  121. #else
  122. #define FALLOC(n) GlobalAlloc(GPTR, (DWORD)n)
  123. #define FFREE(n) GlobalFree((HANDLE)n)
  124. #endif
  125. // string manipulation
  126. #define STRCAT(psz1, psz2) lstrcat(psz1, psz2)
  127. #define STRCMP(psz1, psz2) lstrcmp(psz1, psz2)
  128. #define STRCMPI(psz1, psz2) lstrcmpi(psz1, psz2)
  129. #define STRCPY(psz1, psz2) lstrcpy(psz1, psz2)
  130. #define STRLEN(psz) lstrlen(psz)
  131. #define STRLWR(psz) AnsiLower(psz)
  132. #define STRUPR(psz) AnsiUpper(psz)
  133. // character classification
  134. #define ISALPHA(c) IsCharAlpha(c)
  135. #define ISALPHANUMERIC(c) IsCharAlphaNumeric(c)
  136. #define ISLOWER(c) IsCharLower(c)
  137. #define ISUPPER(c) IsCharUpper(c)
  138. #endif
  139. /******************************* common code *******************************/
  140. // Constants
  141. /////////////
  142. #define SEP_STR "\\"
  143. #define EQUAL '='
  144. #define SPACE ' '
  145. #define COLON ':'
  146. #define PERIOD '.'
  147. #define LF 0x0a
  148. #define CR 0x0d
  149. #define CTRL_Z 0x1a
  150. // flags for _lseek
  151. #define SEEK_SET 0
  152. #define SEEK_CUR 1
  153. #define SEEK_END 2
  154. // Macros
  155. //////////
  156. // character classification
  157. #define ISWHITE(c) ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r')
  158. #define ISFILL(c) ((c) == ' ' || (c) == '\t')
  159. #define ISEOL(c) ((c) == '\n' || (c) == '\r' || (c) == '\0' || (c) == CTRL_Z)
  160. #define ISCRLF(c) ((c) == '\n' || (c) == '\r')
  161. #define ISDIGIT(c) ((c) >= '0' && (c) <= '9')
  162. #define ISLETTER(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z'))
  163. #define ISSWITCH(c) ((c) == '/' || (c) == '-')
  164. #define ISSLASH(c) ((c) == '/' || (c) == '\\')
  165. // character manipulation
  166. #define TOUPPERCASE(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
  167. #define TOLOWERCASE(c) ((c) >= 'A' && (c) <= 'Z' ? (c) - 'A' + 'a' : (c))
  168. #define HEXVALUE(c) (ISDIGIT(c) ? (c) - '0' : TOUPPERCASE(c) - 'A' + 10)