ubidiimp.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. *
  6. * Copyright (C) 1999-2016, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. * file name: ubidiimp.h
  11. * encoding: UTF-8
  12. * tab size: 8 (not used)
  13. * indentation:4
  14. *
  15. * created on: 1999aug06
  16. * created by: Markus W. Scherer, updated by Matitiahu Allouche
  17. */
  18. #ifndef UBIDIIMP_H
  19. #define UBIDIIMP_H
  20. #include "unicode/utypes.h"
  21. #include "unicode/ubidi.h"
  22. #include "unicode/uchar.h"
  23. #include "ubidi_props.h"
  24. /* miscellaneous definitions ---------------------------------------------- */
  25. typedef uint8_t DirProp;
  26. typedef uint32_t Flags;
  27. /* Comparing the description of the BiDi algorithm with this implementation
  28. is easier with the same names for the BiDi types in the code as there.
  29. See UCharDirection in uchar.h .
  30. */
  31. enum {
  32. L= U_LEFT_TO_RIGHT, /* 0 */
  33. R= U_RIGHT_TO_LEFT, /* 1 */
  34. EN= U_EUROPEAN_NUMBER, /* 2 */
  35. ES= U_EUROPEAN_NUMBER_SEPARATOR, /* 3 */
  36. ET= U_EUROPEAN_NUMBER_TERMINATOR, /* 4 */
  37. AN= U_ARABIC_NUMBER, /* 5 */
  38. CS= U_COMMON_NUMBER_SEPARATOR, /* 6 */
  39. B= U_BLOCK_SEPARATOR, /* 7 */
  40. S= U_SEGMENT_SEPARATOR, /* 8 */
  41. WS= U_WHITE_SPACE_NEUTRAL, /* 9 */
  42. ON= U_OTHER_NEUTRAL, /* 10 */
  43. LRE=U_LEFT_TO_RIGHT_EMBEDDING, /* 11 */
  44. LRO=U_LEFT_TO_RIGHT_OVERRIDE, /* 12 */
  45. AL= U_RIGHT_TO_LEFT_ARABIC, /* 13 */
  46. RLE=U_RIGHT_TO_LEFT_EMBEDDING, /* 14 */
  47. RLO=U_RIGHT_TO_LEFT_OVERRIDE, /* 15 */
  48. PDF=U_POP_DIRECTIONAL_FORMAT, /* 16 */
  49. NSM=U_DIR_NON_SPACING_MARK, /* 17 */
  50. BN= U_BOUNDARY_NEUTRAL, /* 18 */
  51. FSI=U_FIRST_STRONG_ISOLATE, /* 19 */
  52. LRI=U_LEFT_TO_RIGHT_ISOLATE, /* 20 */
  53. RLI=U_RIGHT_TO_LEFT_ISOLATE, /* 21 */
  54. PDI=U_POP_DIRECTIONAL_ISOLATE, /* 22 */
  55. ENL, /* EN after W7 */ /* 23 */
  56. ENR, /* EN not subject to W7 */ /* 24 */
  57. dirPropCount
  58. };
  59. /* Sometimes, bit values are more appropriate
  60. to deal with directionality properties.
  61. Abbreviations in these macro names refer to names
  62. used in the BiDi algorithm.
  63. */
  64. #define DIRPROP_FLAG(dir) (1UL<<(dir))
  65. #define PURE_DIRPROP(prop) ((prop)&~0xE0) ?????????????????????????
  66. /* special flag for multiple runs from explicit embedding codes */
  67. #define DIRPROP_FLAG_MULTI_RUNS (1UL<<31)
  68. /* are there any characters that are LTR or RTL? */
  69. #define MASK_LTR (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(ENL)|DIRPROP_FLAG(ENR)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)|DIRPROP_FLAG(LRI))
  70. #define MASK_RTL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)|DIRPROP_FLAG(RLI))
  71. #define MASK_R_AL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL))
  72. #define MASK_STRONG_EN_AN (DIRPROP_FLAG(L)|DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN))
  73. /* explicit embedding codes */
  74. #define MASK_EXPLICIT (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO)|DIRPROP_FLAG(PDF))
  75. /* explicit isolate codes */
  76. #define MASK_ISO (DIRPROP_FLAG(LRI)|DIRPROP_FLAG(RLI)|DIRPROP_FLAG(FSI)|DIRPROP_FLAG(PDI))
  77. #define MASK_BN_EXPLICIT (DIRPROP_FLAG(BN)|MASK_EXPLICIT)
  78. /* paragraph and segment separators */
  79. #define MASK_B_S (DIRPROP_FLAG(B)|DIRPROP_FLAG(S))
  80. /* all types that are counted as White Space or Neutral in some steps */
  81. #define MASK_WS (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT|MASK_ISO)
  82. /* types that are neutrals or could becomes neutrals in (Wn) */
  83. #define MASK_POSSIBLE_N (DIRPROP_FLAG(ON)|DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRPROP_FLAG(ET)|MASK_WS)
  84. /*
  85. * These types may be changed to "e",
  86. * the embedding type (L or R) of the run,
  87. * in the BiDi algorithm (N2)
  88. */
  89. #define MASK_EMBEDDING (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N)
  90. /* the dirProp's L and R are defined to 0 and 1 values in UCharDirection */
  91. #define GET_LR_FROM_LEVEL(level) ((DirProp)((level)&1))
  92. #define IS_DEFAULT_LEVEL(level) ((level)>=0xfe)
  93. /*
  94. * The following bit is used for the directional isolate status.
  95. * Stack entries corresponding to isolate sequences are greater than ISOLATE.
  96. */
  97. #define ISOLATE 0x0100
  98. U_CFUNC UBiDiLevel
  99. ubidi_getParaLevelAtIndex(const UBiDi *pBiDi, int32_t index);
  100. #define GET_PARALEVEL(ubidi, index) \
  101. ((UBiDiLevel)(!(ubidi)->defaultParaLevel || (index)<(ubidi)->paras[0].limit ? \
  102. (ubidi)->paraLevel : ubidi_getParaLevelAtIndex((ubidi), (index))))
  103. /* number of paras entries allocated initially without malloc */
  104. #define SIMPLE_PARAS_COUNT 10
  105. /* number of isolate entries allocated initially without malloc */
  106. #define SIMPLE_ISOLATES_COUNT 5
  107. /* number of isolate run entries for paired brackets allocated initially without malloc */
  108. #define SIMPLE_OPENINGS_COUNT 20
  109. #define CR 0x000D
  110. #define LF 0x000A
  111. /* Run structure for reordering --------------------------------------------- */
  112. enum {
  113. LRM_BEFORE=1,
  114. LRM_AFTER=2,
  115. RLM_BEFORE=4,
  116. RLM_AFTER=8
  117. };
  118. typedef struct Para {
  119. int32_t limit;
  120. int32_t level;
  121. } Para;
  122. enum { /* flags for Opening.flags */
  123. FOUND_L=DIRPROP_FLAG(L),
  124. FOUND_R=DIRPROP_FLAG(R)
  125. };
  126. typedef struct Opening {
  127. int32_t position; /* position of opening bracket */
  128. int32_t match; /* matching char or -position of closing bracket */
  129. int32_t contextPos; /* position of last strong char found before opening */
  130. uint16_t flags; /* bits for L or R/AL found within the pair */
  131. UBiDiDirection contextDir; /* L or R according to last strong char before opening */
  132. uint8_t filler; /* to complete a nice multiple of 4 chars */
  133. } Opening;
  134. typedef struct IsoRun {
  135. int32_t contextPos; /* position of char determining context */
  136. uint16_t start; /* index of first opening entry for this run */
  137. uint16_t limit; /* index after last opening entry for this run */
  138. UBiDiLevel level; /* level of this run */
  139. DirProp lastStrong; /* bidi class of last strong char found in this run */
  140. DirProp lastBase; /* bidi class of last base char found in this run */
  141. UBiDiDirection contextDir; /* L or R to use as context for following openings */
  142. } IsoRun;
  143. typedef struct BracketData {
  144. UBiDi *pBiDi;
  145. /* array of opening entries which should be enough in most cases; no malloc() */
  146. Opening simpleOpenings[SIMPLE_OPENINGS_COUNT];
  147. Opening *openings; /* pointer to current array of entries */
  148. int32_t openingsCount; /* number of allocated entries */
  149. int32_t isoRunLast; /* index of last used entry */
  150. /* array of nested isolated sequence entries; can never excess UBIDI_MAX_EXPLICIT_LEVEL
  151. + 1 for index 0, + 1 for before the first isolated sequence */
  152. IsoRun isoRuns[UBIDI_MAX_EXPLICIT_LEVEL+2];
  153. UBool isNumbersSpecial; /* reordering mode for NUMBERS_SPECIAL */
  154. } BracketData;
  155. typedef struct Isolate {
  156. int32_t startON;
  157. int32_t start1;
  158. int32_t state;
  159. int16_t stateImp;
  160. } Isolate;
  161. typedef struct Run {
  162. int32_t logicalStart, /* first character of the run; b31 indicates even/odd level */
  163. visualLimit, /* last visual position of the run +1 */
  164. insertRemove; /* if >0, flags for inserting LRM/RLM before/after run,
  165. if <0, count of bidi controls within run */
  166. } Run;
  167. /* in a Run, logicalStart will get this bit set if the run level is odd */
  168. #define INDEX_ODD_BIT (1UL<<31)
  169. #define MAKE_INDEX_ODD_PAIR(index, level) ((index)|((int32_t)((level)&1)<<31))
  170. #define ADD_ODD_BIT_FROM_LEVEL(x, level) ((x)|=((int32_t)((level)&1)<<31))
  171. #define REMOVE_ODD_BIT(x) ((x)&=~INDEX_ODD_BIT)
  172. #define GET_INDEX(x) ((x)&~INDEX_ODD_BIT)
  173. #define GET_ODD_BIT(x) ((uint32_t)(x)>>31)
  174. #define IS_ODD_RUN(x) ((UBool)(((x)&INDEX_ODD_BIT)!=0))
  175. #define IS_EVEN_RUN(x) ((UBool)(((x)&INDEX_ODD_BIT)==0))
  176. U_CFUNC UBool
  177. ubidi_getRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);
  178. /** BiDi control code points */
  179. enum {
  180. ZWNJ_CHAR=0x200c,
  181. ZWJ_CHAR,
  182. LRM_CHAR,
  183. RLM_CHAR,
  184. LRE_CHAR=0x202a,
  185. RLE_CHAR,
  186. PDF_CHAR,
  187. LRO_CHAR,
  188. RLO_CHAR,
  189. LRI_CHAR=0x2066,
  190. RLI_CHAR,
  191. FSI_CHAR,
  192. PDI_CHAR
  193. };
  194. #define IS_BIDI_CONTROL_CHAR(c) (((uint32_t)(c)&0xfffffffc)==ZWNJ_CHAR || (uint32_t)((c)-LRE_CHAR)<5 || (uint32_t)((c)-LRI_CHAR)<4)
  195. /* InsertPoints structure for noting where to put BiDi marks ---------------- */
  196. typedef struct Point {
  197. int32_t pos; /* position in text */
  198. int32_t flag; /* flag for LRM/RLM, before/after */
  199. } Point;
  200. typedef struct InsertPoints {
  201. int32_t capacity; /* number of points allocated */
  202. int32_t size; /* number of points used */
  203. int32_t confirmed; /* number of points confirmed */
  204. UErrorCode errorCode; /* for eventual memory shortage */
  205. Point *points; /* pointer to array of points */
  206. } InsertPoints;
  207. /* UBiDi structure ----------------------------------------------------------- */
  208. struct UBiDi {
  209. /* pointer to parent paragraph object (pointer to self if this object is
  210. * a paragraph object); set to NULL in a newly opened object; set to a
  211. * real value after a successful execution of ubidi_setPara or ubidi_setLine
  212. */
  213. const UBiDi * pParaBiDi;
  214. /* alias pointer to the current text */
  215. const UChar *text;
  216. /* length of the current text */
  217. int32_t originalLength;
  218. /* if the UBIDI_OPTION_STREAMING option is set, this is the length
  219. * of text actually processed by ubidi_setPara, which may be shorter than
  220. * the original length.
  221. * Otherwise, it is identical to the original length.
  222. */
  223. int32_t length;
  224. /* if the UBIDI_OPTION_REMOVE_CONTROLS option is set, and/or
  225. * marks are allowed to be inserted in one of the reordering mode, the
  226. * length of the result string may be different from the processed length.
  227. */
  228. int32_t resultLength;
  229. /* memory sizes in bytes */
  230. int32_t dirPropsSize, levelsSize, openingsSize, parasSize, runsSize, isolatesSize;
  231. /* allocated memory */
  232. DirProp *dirPropsMemory;
  233. UBiDiLevel *levelsMemory;
  234. Opening *openingsMemory;
  235. Para *parasMemory;
  236. Run *runsMemory;
  237. Isolate *isolatesMemory;
  238. /* indicators for whether memory may be allocated after ubidi_open() */
  239. UBool mayAllocateText, mayAllocateRuns;
  240. /* arrays with one value per text-character */
  241. DirProp *dirProps;
  242. UBiDiLevel *levels;
  243. /* are we performing an approximation of the "inverse BiDi" algorithm? */
  244. UBool isInverse;
  245. /* are we using the basic algorithm or its variation? */
  246. UBiDiReorderingMode reorderingMode;
  247. /* UBIDI_REORDER_xxx values must be ordered so that all the regular
  248. * logical to visual modes come first, and all inverse BiDi modes
  249. * come last.
  250. */
  251. #define UBIDI_REORDER_LAST_LOGICAL_TO_VISUAL UBIDI_REORDER_NUMBERS_SPECIAL
  252. /* bitmask for reordering options */
  253. uint32_t reorderingOptions;
  254. /* must block separators receive level 0? */
  255. UBool orderParagraphsLTR;
  256. /* the paragraph level */
  257. UBiDiLevel paraLevel;
  258. /* original paraLevel when contextual */
  259. /* must be one of UBIDI_DEFAULT_xxx or 0 if not contextual */
  260. UBiDiLevel defaultParaLevel;
  261. /* context data */
  262. const UChar *prologue;
  263. int32_t proLength;
  264. const UChar *epilogue;
  265. int32_t epiLength;
  266. /* the following is set in ubidi_setPara, used in processPropertySeq */
  267. const struct ImpTabPair * pImpTabPair; /* pointer to levels state table pair */
  268. /* the overall paragraph or line directionality - see UBiDiDirection */
  269. UBiDiDirection direction;
  270. /* flags is a bit set for which directional properties are in the text */
  271. Flags flags;
  272. /* lastArabicPos is index to the last AL in the text, -1 if none */
  273. int32_t lastArabicPos;
  274. /* characters after trailingWSStart are WS and are */
  275. /* implicitly at the paraLevel (rule (L1)) - levels may not reflect that */
  276. int32_t trailingWSStart;
  277. /* fields for paragraph handling */
  278. int32_t paraCount; /* set in getDirProps() */
  279. /* filled in getDirProps() */
  280. Para *paras;
  281. /* for relatively short text, we only need a tiny array of paras (no malloc()) */
  282. Para simpleParas[SIMPLE_PARAS_COUNT];
  283. /* fields for line reordering */
  284. int32_t runCount; /* ==-1: runs not set up yet */
  285. Run *runs;
  286. /* for non-mixed text, we only need a tiny array of runs (no malloc()) */
  287. Run simpleRuns[1];
  288. /* maximum or current nesting depth of isolate sequences */
  289. /* Within resolveExplicitLevels() and checkExplicitLevels(), this is the maximal
  290. nesting encountered.
  291. Within resolveImplicitLevels(), this is the index of the current isolates
  292. stack entry. */
  293. int32_t isolateCount;
  294. Isolate *isolates;
  295. /* for simple text, have a small stack (no malloc()) */
  296. Isolate simpleIsolates[SIMPLE_ISOLATES_COUNT];
  297. /* for inverse Bidi with insertion of directional marks */
  298. InsertPoints insertPoints;
  299. /* for option UBIDI_OPTION_REMOVE_CONTROLS */
  300. int32_t controlCount;
  301. /* for Bidi class callback */
  302. UBiDiClassCallback *fnClassCallback; /* action pointer */
  303. const void *coClassCallback; /* context pointer */
  304. };
  305. #define IS_VALID_PARA(x) ((x) && ((x)->pParaBiDi==(x)))
  306. #define IS_VALID_PARA_OR_LINE(x) ((x) && ((x)->pParaBiDi==(x) || (((x)->pParaBiDi) && (x)->pParaBiDi->pParaBiDi==(x)->pParaBiDi)))
  307. typedef union {
  308. DirProp *dirPropsMemory;
  309. UBiDiLevel *levelsMemory;
  310. Opening *openingsMemory;
  311. Para *parasMemory;
  312. Run *runsMemory;
  313. Isolate *isolatesMemory;
  314. } BidiMemoryForAllocation;
  315. /* Macros for initial checks at function entry */
  316. #define RETURN_IF_NULL_OR_FAILING_ERRCODE(pErrcode, retvalue) UPRV_BLOCK_MACRO_BEGIN { \
  317. if((pErrcode)==NULL || U_FAILURE(*pErrcode)) return retvalue; \
  318. } UPRV_BLOCK_MACRO_END
  319. #define RETURN_IF_NOT_VALID_PARA(bidi, errcode, retvalue) UPRV_BLOCK_MACRO_BEGIN { \
  320. if(!IS_VALID_PARA(bidi)) { \
  321. errcode=U_INVALID_STATE_ERROR; \
  322. return retvalue; \
  323. } \
  324. } UPRV_BLOCK_MACRO_END
  325. #define RETURN_IF_NOT_VALID_PARA_OR_LINE(bidi, errcode, retvalue) UPRV_BLOCK_MACRO_BEGIN { \
  326. if(!IS_VALID_PARA_OR_LINE(bidi)) { \
  327. errcode=U_INVALID_STATE_ERROR; \
  328. return retvalue; \
  329. } \
  330. } UPRV_BLOCK_MACRO_END
  331. #define RETURN_IF_BAD_RANGE(arg, start, limit, errcode, retvalue) UPRV_BLOCK_MACRO_BEGIN { \
  332. if((arg)<(start) || (arg)>=(limit)) { \
  333. (errcode)=U_ILLEGAL_ARGUMENT_ERROR; \
  334. return retvalue; \
  335. } \
  336. } UPRV_BLOCK_MACRO_END
  337. #define RETURN_VOID_IF_NULL_OR_FAILING_ERRCODE(pErrcode) UPRV_BLOCK_MACRO_BEGIN { \
  338. if((pErrcode)==NULL || U_FAILURE(*pErrcode)) return; \
  339. } UPRV_BLOCK_MACRO_END
  340. #define RETURN_VOID_IF_NOT_VALID_PARA(bidi, errcode) UPRV_BLOCK_MACRO_BEGIN { \
  341. if(!IS_VALID_PARA(bidi)) { \
  342. errcode=U_INVALID_STATE_ERROR; \
  343. return; \
  344. } \
  345. } UPRV_BLOCK_MACRO_END
  346. #define RETURN_VOID_IF_NOT_VALID_PARA_OR_LINE(bidi, errcode) UPRV_BLOCK_MACRO_BEGIN { \
  347. if(!IS_VALID_PARA_OR_LINE(bidi)) { \
  348. errcode=U_INVALID_STATE_ERROR; \
  349. return; \
  350. } \
  351. } UPRV_BLOCK_MACRO_END
  352. #define RETURN_VOID_IF_BAD_RANGE(arg, start, limit, errcode) UPRV_BLOCK_MACRO_BEGIN { \
  353. if((arg)<(start) || (arg)>=(limit)) { \
  354. (errcode)=U_ILLEGAL_ARGUMENT_ERROR; \
  355. return; \
  356. } \
  357. } UPRV_BLOCK_MACRO_END
  358. /* helper function to (re)allocate memory if allowed */
  359. U_CFUNC UBool
  360. ubidi_getMemory(BidiMemoryForAllocation *pMemory, int32_t *pSize, UBool mayAllocate, int32_t sizeNeeded);
  361. /* helper macros for each allocated array in UBiDi */
  362. #define getDirPropsMemory(pBiDi, length) \
  363. ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->dirPropsMemory, &(pBiDi)->dirPropsSize, \
  364. (pBiDi)->mayAllocateText, (length))
  365. #define getLevelsMemory(pBiDi, length) \
  366. ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->levelsMemory, &(pBiDi)->levelsSize, \
  367. (pBiDi)->mayAllocateText, (length))
  368. #define getRunsMemory(pBiDi, length) \
  369. ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->runsMemory, &(pBiDi)->runsSize, \
  370. (pBiDi)->mayAllocateRuns, (length)*sizeof(Run))
  371. /* additional macros used by ubidi_open() - always allow allocation */
  372. #define getInitialDirPropsMemory(pBiDi, length) \
  373. ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->dirPropsMemory, &(pBiDi)->dirPropsSize, \
  374. TRUE, (length))
  375. #define getInitialLevelsMemory(pBiDi, length) \
  376. ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->levelsMemory, &(pBiDi)->levelsSize, \
  377. TRUE, (length))
  378. #define getInitialOpeningsMemory(pBiDi, length) \
  379. ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->openingsMemory, &(pBiDi)->openingsSize, \
  380. TRUE, (length)*sizeof(Opening))
  381. #define getInitialParasMemory(pBiDi, length) \
  382. ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->parasMemory, &(pBiDi)->parasSize, \
  383. TRUE, (length)*sizeof(Para))
  384. #define getInitialRunsMemory(pBiDi, length) \
  385. ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->runsMemory, &(pBiDi)->runsSize, \
  386. TRUE, (length)*sizeof(Run))
  387. #define getInitialIsolatesMemory(pBiDi, length) \
  388. ubidi_getMemory((BidiMemoryForAllocation *)&(pBiDi)->isolatesMemory, &(pBiDi)->isolatesSize, \
  389. TRUE, (length)*sizeof(Isolate))
  390. #endif