home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / src / macros.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-05-03  |  6.9 KB  |  225 lines

  1. /* vi:set ts=8 sts=4 sw=4:
  2.  *
  3.  * VIM - Vi IMproved    by Bram Moolenaar
  4.  *
  5.  * Do ":help uganda"  in Vim to read copying and usage conditions.
  6.  * Do ":help credits" in Vim to see a list of people who contributed.
  7.  */
  8.  
  9. /*
  10.  * macros.h: macro definitions for often used code
  11.  */
  12.  
  13. /*
  14.  * pchar(lp, c) - put character 'c' at position 'lp'
  15.  */
  16. #define pchar(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
  17.  
  18. /*
  19.  * Position comparisons
  20.  */
  21. #ifdef FEAT_VIRTUALEDIT
  22. # define lt(a, b) (((a).lnum != (b).lnum) \
  23.            ? (a).lnum < (b).lnum \
  24.            : (a).col != (b).col \
  25.                ? (a).col < (b).col \
  26.                : (a).coladd < (b).coladd)
  27. # define ltp(a, b) (((a)->lnum != (b)->lnum) \
  28.            ? (a)->lnum < (b)->lnum \
  29.            : (a)->col != (b)->col \
  30.                ? (a)->col < (b)->col \
  31.                : (a)->coladd < (b)->coladd)
  32. # define equal(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col) && ((a).coladd == (b).coladd))
  33. #else
  34. # define lt(a, b) (((a).lnum != (b).lnum) \
  35.            ? ((a).lnum < (b).lnum) : ((a).col < (b).col))
  36. # define ltp(a, b) (((a)->lnum != (b)->lnum) \
  37.            ? ((a)->lnum < (b)->lnum) : ((a)->col < (b)->col))
  38. # define equal(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col))
  39. #endif
  40.  
  41. #define ltoreq(a, b) (lt(a, b) || equal(a, b))
  42.  
  43. /*
  44.  * lineempty() - return TRUE if the line is empty
  45.  */
  46. #define lineempty(p) (*ml_get(p) == NUL)
  47.  
  48. /*
  49.  * bufempty() - return TRUE if the current buffer is empty
  50.  */
  51. #define bufempty() (curbuf->b_ml.ml_line_count == 1 && *ml_get((linenr_T)1) == NUL)
  52.  
  53. /*
  54.  * toupper() and tolower() that use the current locale.
  55.  * On some systems toupper()/tolower() only work on lower/uppercase characters
  56.  * Careful: Only call TOUPPER_LOC() and TOLOWER_LOC() with a character in the
  57.  * range 0 - 255.  toupper()/tolower() on some systems can't handle others.
  58.  * Note: for UTF-8 use utf_toupper() and utf_tolower().
  59.  */
  60. #ifdef MSWIN
  61. #  define TOUPPER_LOC(c)    toupper_tab[(c) & 255]
  62. #  define TOLOWER_LOC(c)    tolower_tab[(c) & 255]
  63. #else
  64. # ifdef BROKEN_TOUPPER
  65. #  define TOUPPER_LOC(c)    (islower(c) ? toupper(c) : (c))
  66. #  define TOLOWER_LOC(c)    (isupper(c) ? tolower(c) : (c))
  67. # else
  68. #  define TOUPPER_LOC        toupper
  69. #  define TOLOWER_LOC        tolower
  70. # endif
  71. #endif
  72.  
  73. /* toupper() and tolower() for ASCII only and ignore the current locale. */
  74. #ifdef EBCDIC
  75. # define TOUPPER_ASC(c)    (islower(c) ? toupper(c) : (c))
  76. # define TOLOWER_ASC(c)    (isupper(c) ? tolower(c) : (c))
  77. #else
  78. # define TOUPPER_ASC(c)    (((c) < 'a' || (c) > 'z') ? (c) : (c) - ('a' - 'A'))
  79. # define TOLOWER_ASC(c)    (((c) < 'A' || (c) > 'Z') ? (c) : (c) + ('a' - 'A'))
  80. #endif
  81.  
  82. /*
  83.  * MB_ISLOWER() and MB_ISUPPER() are to be used on multi-byte characters.  But
  84.  * don't use them for negative values or values above 0x100 for DBCS.
  85.  */
  86. #ifdef FEAT_MBYTE
  87. # define MB_ISLOWER(c)    (enc_utf8 && (c) > 0x80 ? utf_islower(c) : islower(c))
  88. # define MB_ISUPPER(c)    (enc_utf8 && (c) > 0x80 ? utf_isupper(c) : isupper(c))
  89. # define MB_TOLOWER(c)    (enc_utf8 && (c) > 0x80 ? utf_tolower(c) : TOLOWER_LOC(c))
  90. # define MB_TOUPPER(c)    (enc_utf8 && (c) > 0x80 ? utf_toupper(c) : TOUPPER_LOC(c))
  91. #else
  92. # define MB_ISLOWER(c)    islower(c)
  93. # define MB_ISUPPER(c)    isupper(c)
  94. # define MB_TOLOWER(c)    TOLOWER_LOC(c)
  95. # define MB_TOUPPER(c)    TOUPPER_LOC(c)
  96. #endif
  97.  
  98. /* Like isalpha() but reject non-ASCII characters.  Can't be used with a
  99.  * special key (negative value). */
  100. #ifdef EBCDIC
  101. # define ASCII_ISALPHA(c) isalpha(c)
  102. # define ASCII_ISALNUM(c) isalnum(c)
  103. # define ASCII_ISLOWER(c) islower(c)
  104. # define ASCII_ISUPPER(c) isupper(c)
  105. #else
  106. # define ASCII_ISALPHA(c) ((c) < 0x7f && isalpha(c))
  107. # define ASCII_ISALNUM(c) ((c) < 0x7f && isalnum(c))
  108. # define ASCII_ISLOWER(c) ((c) < 0x7f && islower(c))
  109. # define ASCII_ISUPPER(c) ((c) < 0x7f && isupper(c))
  110. #endif
  111.  
  112. /* macro version of chartab().
  113.  * Only works with values 0-255!
  114.  * Doesn't work for UTF-8 mode with chars >= 0x80. */
  115. #define CHARSIZE(c)    (chartab[c] & CT_CELL_MASK)
  116.  
  117. #ifdef FEAT_LANGMAP
  118. /*
  119.  * Adjust chars in a language according to 'langmap' option.
  120.  * NOTE that there is NO overhead if 'langmap' is not set; but even
  121.  * when set we only have to do 2 ifs and an array lookup.
  122.  * Don't apply 'langmap' if the character comes from the Stuff buffer.
  123.  * The do-while is just to ignore a ';' after the macro.
  124.  */
  125. # define LANGMAP_ADJUST(c, condition) do { \
  126.     if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \
  127.         c = langmap_mapchar[c]; \
  128.     } while (0)
  129. #endif
  130.  
  131. /*
  132.  * vim_isbreak() is used very often if 'linebreak' is set, use a macro to make
  133.  * it work fast.
  134.  */
  135. #define vim_isbreak(c) (breakat_flags[(char_u)(c)])
  136.  
  137. /*
  138.  * On VMS file names are different and require a translation.
  139.  * On the Mac open() has only two arguments.
  140.  */
  141. #ifdef VMS
  142. # define mch_access(n, p)    access(vms_fixfilename(n), (p))
  143.                 /* see mch_open() comment */
  144. # define mch_fopen(n, p)    fopen(vms_fixfilename(n), (p))
  145. # define mch_fstat(n, p)    fstat(vms_fixfilename(n), (p))
  146.     /* VMS does not have lstat() */
  147. # define mch_stat(n, p)        stat(vms_fixfilename(n), (p))
  148. #else
  149. # ifndef WIN32
  150. #   define mch_access(n, p)    access((n), (p))
  151. # endif
  152. # define mch_fopen(n, p)    fopen((n), (p))
  153. # define mch_fstat(n, p)    fstat((n), (p))
  154. # define mch_lstat(n, p)    lstat((n), (p))
  155. # ifdef MSWIN    /* has it's own mch_stat() function */
  156. #  define mch_stat(n, p)    vim_stat((n), (p))
  157. # else
  158. #  ifdef STAT_IGNORES_SLASH
  159.     /* On Solaris stat() accepts "file/" as if it was "file".  Return -1 if
  160.      * the name ends in "/" and it's not a directory. */
  161. #   define mch_stat(n, p)    (illegal_slash(n) ? -1 : stat((n), (p)))
  162. #  else
  163. #   define mch_stat(n, p)    stat((n), (p))
  164. #  endif
  165. # endif
  166. #endif
  167.  
  168. #ifdef MACOS_CLASSIC
  169. /* MacOS classic doesn't support perm but MacOS X does. */
  170. # define mch_open(n, m, p)    open((n), (m))
  171. #else
  172. # ifdef VMS
  173. /*
  174.  * It is possible to force some record format with:
  175.  * #  define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p)), "rat=cr", "rfm=stmlf", "mrs=0")
  176.  * but it is not recomended, because it can destroy indexes etc.
  177.  */
  178. #  define mch_open(n, m, p)    open(vms_fixfilename(n), (m), (p))
  179. # else
  180. #  define mch_open(n, m, p)    open((n), (m), (p))
  181. # endif
  182. #endif
  183.  
  184. /*
  185.  * Encryption macros.  Mohsin Ahmed, mosh@sasi.com 98-09-24
  186.  * Based on zip/crypt sources.
  187.  */
  188.  
  189. #ifdef FEAT_CRYPT
  190.  
  191. #ifndef __MINGW32__
  192. # define PWLEN 80
  193. #endif
  194.  
  195. /* encode byte c, using temp t.  Warning: c must not have side effects. */
  196. # define ZENCODE(c, t)  (t = decrypt_byte(), update_keys(c), t^(c))
  197.  
  198. /* decode byte c in place */
  199. # define ZDECODE(c)   update_keys(c ^= decrypt_byte())
  200.  
  201. #endif
  202.  
  203. #ifdef STARTUPTIME
  204. # define TIME_MSG(s) time_msg(s, NULL)
  205. #else
  206. # define TIME_MSG(s)
  207. #endif
  208.  
  209. #ifdef FEAT_VREPLACE
  210. # define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG))
  211. #else
  212. # define REPLACE_NORMAL(s) ((s) & REPLACE_FLAG)
  213. #endif
  214.  
  215. #ifdef FEAT_ARABIC
  216. # define UTF_COMPOSINGLIKE(p1, p2)  utf_composinglike((p1), (p2))
  217. #else
  218. # define UTF_COMPOSINGLIKE(p1, p2)  utf_iscomposing(utf_ptr2char(p2))
  219. #endif
  220.  
  221. #ifdef FEAT_RIGHTLEFT
  222.     /* Whether to draw the vertical bar on the right side of the cell. */
  223. # define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & CMDLINE) || cmdmsg_rl))
  224. #endif
  225.