home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vile-src.zip / vile-8.1 / estruct.h < prev    next >
C/C++ Source or Header  |  1998-09-29  |  76KB  |  2,458 lines

  1. /*    ESTRUCT:    Structure and preprocessor defines for
  2.             vile.  Reshaped from the original, which
  3.             was for MicroEMACS 3.9
  4.  
  5.             vile is by Paul Fox
  6.             MicroEmacs was written by Dave G. Conroy
  7.             modified by Steve Wilhite, George Jones
  8.             substantially modified by Daniel Lawrence
  9. */
  10.  
  11. /*
  12.  * $Header: /usr/build/vile/vile/RCS/estruct.h,v 1.362 1998/09/29 23:43:08 tom Exp $
  13.  */
  14.  
  15. #ifndef _estruct_h
  16. #define _estruct_h 1
  17.  
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21.  
  22. #ifndef CHECK_PROTOTYPES
  23. #define CHECK_PROTOTYPES 0
  24. #endif
  25.  
  26. #ifndef os_chosen
  27.  
  28. /* All variants of UNIX should now be handled by the configure script */
  29.  
  30. #ifdef VMS        /* predefined by VAX/VMS compiler */
  31. # define scrn_chosen
  32. # define DISP_VMSVT  1
  33. #endif
  34.  
  35. /* non-unix flavors */
  36. #undef SYS_MSDOS
  37. #undef SYS_WIN31
  38.  
  39. #define SYS_MSDOS    0            /* MS-DOS            */
  40. #define SYS_WIN31    0            /* Windows 3.1            */
  41. #define SYS_OS2        0            /* son of DOS            */
  42. #define SYS_OS2_EMX    0            /* Unix'ed OS2            */
  43. #define SYS_WINNT    0            /* Windows/NT            */
  44.  
  45. /*    Compiler definitions            */
  46. #define CC_MSC        0    /* Microsoft C compile version 3 & 4 & 5 & 6 */
  47. #define CC_TURBO    0    /* Turbo C/MSDOS or Borland C++ */
  48. #define CC_WATCOM    0    /* WATCOM C/386 version 9.0 or above */
  49. #define CC_DJGPP    0    /* DJ's GCC version 1.09 */
  50. #define CC_CSETPP    0    /* IBM C Set ++ 2.x */
  51. #define CC_MSVC        0    /* Microsoft Visual C++ 7 & 8 & 9 */
  52.  
  53. #ifdef __TURBOC__    /* predefined in Turbo C, both DOS and Windows */
  54. # ifdef __FLAT__    /* predefined in Borland C for WIN32 */
  55. #  undef SYS_WINNT
  56. #  define SYS_WINNT  1
  57. # else
  58. #  ifdef _Windows    /* predefined in TurboC for Windows */
  59. #   undef SYS_WIN31
  60. #   define SYS_WIN31  1
  61. #  else
  62. #   undef SYS_MSDOS
  63. #   define SYS_MSDOS  1
  64. #  endif
  65. # endif
  66. # undef CC_TURBO
  67. # define CC_TURBO  1
  68. #endif
  69.  
  70. #ifdef _WIN32        /* predefined in Visual C/C++ 4.0 */
  71. # undef SYS_WINNT
  72. # define SYS_WINNT 1
  73. #endif
  74.  
  75. #ifdef __WATCOMC__
  76. #undef SYS_MSDOS
  77. #define SYS_MSDOS  1
  78. #undef CC_WATCOM
  79. #define CC_WATCOM 1
  80. #endif
  81.  
  82. #ifdef __IBMC__
  83. # if __IBMC__ >= 200    /* IBM C Set ++ version 2.x */
  84. #  undef  CC_CSETPP
  85. #  define CC_CSETPP 1
  86. # endif
  87. #endif
  88.  
  89. #ifdef __OS2__
  90. /* assume compiler already chosen */
  91. #undef SYS_OS2
  92. #undef SYS_MSDOS
  93. #define SYS_OS2    1
  94. #define SYS_MSDOS  0
  95. #endif
  96.  
  97. #ifdef __GO32__      /* DJ's GCC version 1.09 */
  98. #undef SYS_MSDOS
  99. #define SYS_MSDOS  1
  100. #undef CC_DJGPP
  101. #define CC_DJGPP   1
  102. #endif
  103.  
  104. #ifdef _MSC_VER
  105. #undef SYS_WINNT
  106. #define SYS_WINNT    1
  107. #undef CC_MSVC
  108. #define CC_MSVC        1
  109. #endif
  110.  
  111. /* As of version 3.51 of vile, CC_NEWDOSCC should be correct for Turbo,
  112.  * Watcom, and the DJ gcc (GO32) compilers.  I'm betting that it's also
  113.  * probably correct for MSC (Microsoft C) and ZTC (Zortech), but I'm not
  114.  * sure of those.  (It implies a lot of ANSI and POSIX behavior.)
  115.  */
  116. #if CC_TURBO || CC_WATCOM || CC_MSC || CC_DJGPP || SYS_WINNT || CC_CSETPP || CC_MSVC
  117. # define CC_NEWDOSCC 1
  118. # define HAVE_GETCWD 1
  119. #else
  120. # define CC_NEWDOSCC 0
  121. #endif
  122.  
  123. #if CC_TURBO
  124. # if !SYS_WINNT
  125. #  define off_t long        /* missing in TurboC 3.1 */
  126. # endif
  127. #endif
  128.  
  129. #if CC_CSETPP
  130. # define HAVE_UTIME        1
  131. # define HAVE_STRERROR        1
  132. # define HAVE_SYS_UTIME_H    1
  133. # define CPP_SUBS_BEFORE_QUOTE    1
  134. # define CC_CANNOT_OFFSET_CASES    1
  135. #endif
  136.  
  137. #if CC_DJGPP
  138. # define HAVE_UNISTD_H        1
  139. #endif
  140.  
  141. #endif /* os_chosen */
  142.  
  143. /*
  144.  * This may apply to makefile.emx, or to builds with the configure-script
  145.  */
  146. #ifdef __EMX__
  147. #define SYS_OS2_EMX 1
  148. #endif
  149.  
  150. /*
  151.  * Porting constraints: supply the normally assumed values that we get from
  152.  * the "configure" script, for systems on which we cannot run "configure"
  153.  * (e.g., VMS, OS2, MSDOS).
  154.  */
  155. #ifndef HAVE_ACCESS
  156. # define HAVE_ACCESS    1    /* if your system has the access() system call */
  157. #endif
  158.  
  159. #ifndef HAVE_MKDIR
  160. # define HAVE_MKDIR    1    /* if your system has the mkdir() system call */
  161. #endif
  162.  
  163. #ifndef HAVE_QSORT
  164. # define HAVE_QSORT    1    /* if your system has the qsort() system call */
  165. #endif
  166.  
  167. #ifndef HAVE_UTIME
  168. # define HAVE_UTIME    0    /* if your system has the utime() system call */
  169. #endif
  170.  
  171. #ifndef HAVE_SETJMP_H
  172. # define HAVE_SETJMP_H  1    /* if your system has <setjmp.h> */
  173. #endif
  174.  
  175. #ifndef HAVE_SIGNAL_H
  176. # define HAVE_SIGNAL_H  1    /* if your system has <signal.h> */
  177. #endif
  178.  
  179. #if !(defined(HAVE_STRCHR) || defined(HAVE_STRRCHR))
  180. # define HAVE_STRCHR    1
  181. # define HAVE_STRRCHR   1
  182. #endif
  183.  
  184. #ifndef HAVE_STDLIB_H
  185. # define HAVE_STDLIB_H  1    /* if your system has <stdlib.h> */
  186. #endif
  187.  
  188. #ifndef HAVE_STRING_H
  189. # define HAVE_STRING_H  1    /* if your system has <string.h> */
  190. #endif
  191.  
  192. /* Some code uses these as values in expressions, so we always want them
  193.  * defined, just in case we run into a substandard preprocessor.
  194.  */
  195. #ifndef DISP_X11
  196. # define DISP_X11 0
  197. #endif
  198. #ifndef SYS_MSDOS
  199. # define SYS_MSDOS 0
  200. #endif
  201. #ifndef SYS_OS2
  202. # define SYS_OS2 0
  203. #endif
  204. #ifndef SYS_WIN31
  205. # define SYS_WIN31 0
  206. #endif
  207. #ifndef SYS_WINNT
  208. # define SYS_WINNT     0
  209. #endif
  210. #if defined(VMS) || defined(__VMS) /* predefined by DEC's VMS compilers */
  211. # define SYS_VMS    1
  212. # define HAVE_GETCWD 1
  213. # if defined(__DECC) && !defined(__alpha)
  214. #  undef HAVE_ACCESS
  215. #  define HAVE_ACCESS 0    /* 'access()' is reported to not work properly */
  216. # endif
  217. # if !defined(__DECC)
  218. #  undef  HAVE_QSORT
  219. #  define HAVE_QSORT 0    /* VAX-C's 'qsort()' is definitely broken */
  220. # endif
  221. # define SIGT void
  222. # define SIGRET
  223. # define CC_CANNOT_OFFSET_CASES 1
  224. #else
  225. # define SYS_VMS    0
  226. #endif
  227. #ifdef apollo
  228. # define SYS_APOLLO 1    /* FIXME: still more ifdefs to autoconf */
  229. #endif
  230. #ifdef sun
  231. # define SYS_SUNOS 1    /* FIXME: need to tweak lint ifdefs */
  232. #endif
  233.  
  234. #define IBM_KBD     (SYS_MSDOS || SYS_OS2 || SYS_WINNT)
  235. #define IBM_VIDEO     (SYS_MSDOS || SYS_OS2 || SYS_WINNT)
  236. #define CRLF_LINES     (SYS_MSDOS || SYS_OS2 || SYS_WINNT)
  237.  
  238. #include <stdio.h>
  239. #include <sys/types.h>
  240. #include <sys/stat.h>    /* defines off_t */
  241.  
  242. #if HAVE_LIBC_H
  243. #include <libc.h>
  244. #endif
  245. #if HAVE_FCNTL_H
  246. #ifndef O_RDONLY    /* prevent multiple inclusion on lame systems */
  247. #include <fcntl.h>    /* 'open()' */
  248. #endif
  249. #endif
  250.  
  251. #if HAVE_SYS_TIME_H && ! SYSTEM_LOOKS_LIKE_SCO
  252. /* on SCO, sys/time.h conflicts with select.h, and we don't need it */
  253. #include <sys/time.h>
  254. #ifdef TIME_WITH_SYS_TIME
  255. # include <time.h>
  256. #endif
  257. #else
  258. #include <time.h>
  259. #endif
  260.  
  261. #if HAVE_SYS_RESOURCE_H && ! SYSTEM_LOOKS_LIKE_SCO
  262. /* On SunOS, struct rusage is referred to in <sys/wait.h>.  struct rusage
  263.    is defined in <sys/resource.h>.   NeXT may be similar.  On SCO,
  264.    resource.h needs time.h, which we excluded above.  */
  265. #include <sys/resource.h>
  266. #endif
  267.  
  268. #if HAVE_SYS_WAIT_H
  269. #include <sys/wait.h>    /* 'wait()' */
  270. #endif
  271.  
  272. /* definitions for testing apollo version with gcc warnings */
  273. #if SYS_APOLLO
  274. # ifdef __GNUC__        /* only tested for SR10.3 with gcc 1.36 */
  275. #  ifndef _APOLLO_SOURCE    /* ...defined in gcc 2.4.5 */
  276. #  define _APOLLO_SOURCE    /* appease gcc by forcing extern-defs */
  277. #  endif
  278. #  define __attribute(s)
  279. #  define APOLLO_STDLIB 1
  280. # endif
  281. # if defined(L_tmpnam)        /* SR10.3, CC 6.8 defines in <stdio.h> */
  282. #  define APOLLO_STDLIB 1
  283. # endif
  284. #endif
  285.  
  286. #ifndef APOLLO_STDLIB
  287. # define APOLLO_STDLIB 0
  288. #endif
  289.  
  290. #ifndef SIGT
  291. /* choose between void and int signal handler return type.
  292.   "typedefs?  we don't need no steenking typedefs..." */
  293. # if CC_NEWDOSCC
  294. #  define SIGT void
  295. #  define SIGRET
  296. # else
  297. #  define SIGT int
  298. #  define SIGRET return 0
  299. # endif
  300. #endif /* SIGT */
  301.  
  302. #if HAVE_SIGNAL_H
  303. #include <signal.h>
  304. #endif
  305.  
  306. #ifndef ACTUAL_SIG_ARGS
  307. # define ACTUAL_SIG_ARGS signo    /* some systems have more arguments... */
  308. #endif
  309.  
  310. #if defined(__GNUC__)
  311. # undef  SIG_DFL
  312. # undef  SIG_IGN
  313. # define SIG_DFL    (SIGT (*)(int ACTUAL_SIG_ARGS))0
  314. # define SIG_IGN    (SIGT (*)(int ACTUAL_SIG_ARGS))1
  315. #endif
  316.  
  317. #if HAVE_SETJMP_H
  318. #include    <setjmp.h>
  319. #endif
  320.  
  321. /* argument for 'exit()' or '_exit()' */
  322. #if SYS_VMS
  323. #include    <stsdef.h>
  324. #define GOODEXIT    (STS$M_INHIB_MSG | STS$K_SUCCESS)
  325. #define BADEXIT        (STS$M_INHIB_MSG | STS$K_ERROR)
  326. #else
  327. #define GOODEXIT    0
  328. #define BADEXIT        1
  329. #endif
  330.  
  331. /* has the select() or poll() call, only used for short sleeps in fmatch() */
  332. #if HAVE_SELECT
  333. #undef HAVE_POLL
  334. #endif
  335.  
  336. #if SYS_UNIX || SYS_MSDOS || SYS_WIN31 || SYS_VMS || SYS_OS2 || SYS_WINNT
  337. #define    ENVFUNC    1
  338. #else
  339. #define    ENVFUNC    0
  340. #endif
  341.  
  342. /* ====================================================================== */
  343. #ifndef scrn_chosen
  344. /*    Terminal Output definitions        */
  345. /* choose ONLY one of the following */
  346. #define DISP_TERMCAP    SYS_UNIX    /* Use TERMCAP            */
  347. #define DISP_ANSI    0        /* ANSI escape sequences    */
  348. #define DISP_AT386    0        /* AT style 386 unix console    */
  349. #define    DISP_VMSVT    SYS_VMS        /* various VMS terminal entries    */
  350. #define    DISP_BORLAND    0        /* Borland console I/O routines */
  351. #define    DISP_IBMPC    (SYS_MSDOS && !DISP_BORLAND && !DISP_ANSI) /* IBM-PC CGA/MONO/EGA driver */
  352. #define    DISP_X11    0        /* X Window System */
  353. #define DISP_NTCONS    0        /* Windows/NT console        */
  354. #define DISP_NTWIN    0        /* Windows/NT screen/windows    */
  355. #define DISP_VIO    SYS_OS2        /* OS/2 VIO (text mode)        */
  356. #define    DISP_HP150    0        /* (not supported)        */
  357. #endif
  358.  
  359. /* ====================================================================== */
  360. /*    Configuration options... pick and choose as you wish */
  361.  
  362. /*    Code size options    */
  363. #ifndef FEWNAMES
  364. #define    FEWNAMES 0    /* strip some names - will no longer be bindable */
  365. #endif
  366.  
  367. #ifndef SMALLER
  368. #define    SMALLER    0    /* strip some fluff -- not a lot smaller, but some */
  369. #endif
  370.  
  371. #ifndef OPT_SHELL
  372. #define OPT_SHELL 1    /* we'll disable this only as an exercise */
  373. #endif
  374.  
  375. #ifndef OPT_LOCALE
  376. #define OPT_LOCALE 0
  377. #endif
  378.  
  379. /* various color stuff */
  380. #define    OPT_COLOR (DISP_ANSI || IBM_VIDEO || DISP_TERMCAP)
  381. #define    OPT_16_COLOR (IBM_VIDEO || DISP_TERMCAP)
  382.  
  383. #define OPT_DUMBTERM (DISP_TERMCAP || DISP_VMSVT)
  384.  
  385. /* Feature turnon/turnoff */
  386. #define    OPT_DOSFILES    1    /* turn on code for DOS mode (lines that
  387.                    end in crlf).  use DOSFILES, for instance,
  388.                    if you edit DOS-created files under UNIX   */
  389. #define    OPT_REVSTA    1    /* Status line appears in reverse video       */
  390. #define    OPT_CFENCE    1    /* do fence matching in CMODE              */
  391. #define    OPT_LCKFILES    0    /* create lock files (file.lck style)           */
  392. #define    OPT_TAGS    1    /* tags support                    */
  393. #define    OPT_PROCEDURES    1    /* named procedures                  */
  394. #define    OPT_PATHLOOKUP    1    /* search $PATH for startup and help files    */
  395. #define    OPT_SCROLLCODE    1    /* code in display.c for scrolling the screen.
  396.                    Only useful if your display can scroll
  397.                    regions, or at least insert/delete lines.
  398.                    ANSI, TERMCAP, IBMPC, VMSVT and AT386 can
  399.                    do this */
  400. #define OPT_CVMVAS    1    /* arguments to forward/back page and half page
  401.                    are in pages    instead of rows (in vi,
  402.                    they're rows, and the argument is "sticky",
  403.                    i.e. it's remembered */
  404. #define OPT_PRETTIER_SCROLL 0    /* can improve the appearance of a scrolling
  405.                    screen, but it will in general be slower */
  406. #define OPT_STUTTER_SEC_CMD 0    /* must the next/prev section commands (i.e.
  407.                    ']]' and '[[' be stuttered?  they must be
  408.                    stuttered in real vi, I prefer them not
  409.                    to be */
  410. #define OPT_ICURSOR    0    /* use an insertion cursor if possible */
  411. #define OPT_W32PIPES    SYS_WINNT /* Win32 pipes */
  412.  
  413. #ifndef OPT_EXEC_MACROS        /* total numbered macros (see mktbls.c) */
  414. #if SMALLER
  415. #define OPT_EXEC_MACROS 10
  416. #else
  417. #define OPT_EXEC_MACROS 40
  418. #endif
  419. #endif
  420.  
  421.   /* NOTE:  OPT_ICURSOR is _only_ supported by borland.c for a PC build
  422.      and ntconio.c for a win32 build!! */
  423. #define OPT_TITLE    (SYS_WINNT)        /* use a window title */
  424.  
  425. /* the "working..." message -- we must have the alarm() syscall, and
  426.    system calls must be restartable after an interrupt by default or be
  427.    made restartable with sigaction() */
  428. #define OPT_WORKING (!SMALLER && HAVE_ALARM && HAVE_RESTARTABLE_PIPEREAD)
  429.  
  430. #define OPT_SCROLLBARS (XTOOLKIT | DISP_NTWIN)    /* scrollbars */
  431. #define OPT_VMS_PATH    (SYS_VMS)  /* vax/vms path parsing (testing/porting)*/
  432.  
  433. /* systems with MSDOS-like filename syntax */
  434. #define OPT_MSDOS_PATH  (SYS_MSDOS || SYS_WIN31 || SYS_OS2 || SYS_WINNT || SYS_OS2_EMX)
  435. #define OPT_CASELESS    (SYS_WINNT || SYS_OS2 || SYS_OS2_EMX)
  436. #define OPT_UNC_PATH    (SYS_WINNT)
  437.  
  438. /* individual features that are (normally) controlled by SMALLER */
  439. #define OPT_AEDIT       !SMALLER        /* advanced editing options: e.g. en/detabbing    */
  440. #define OPT_B_LIMITS    !SMALLER        /* left-margin */
  441. #define OPT_ENCRYPT     !SMALLER /* file encryption (not crypt(1) compatible!) */
  442. #define OPT_ENUM_MODES  !SMALLER        /* fixed-string modes */
  443. #define OPT_EVAL        !SMALLER        /* expression-evaluation */
  444. #define OPT_FILEBACK    !SMALLER && !SYS_VMS    /* file backup style */
  445. #define OPT_FINDERR     !SMALLER        /* finderr support. */
  446. #define OPT_FLASH       !SMALLER || DISP_IBMPC    /* visible-bell */
  447. #define OPT_FORMAT      !SMALLER        /* region formatting support. */
  448. #define OPT_HILITEMATCH !SMALLER        /* highlight all matches of a search */
  449. #define OPT_HISTORY     !SMALLER        /* command-history */
  450. #define OPT_ISO_8859    !SMALLER        /* ISO 8859 characters */
  451. #define OPT_ISRCH       !SMALLER        /* Incremental searches */
  452. #define OPT_LINEWRAP    !SMALLER        /* line-wrap mode */
  453. #define OPT_MAJORMODE   !SMALLER        /* majormode support */
  454. #define OPT_MLFORMAT    !SMALLER        /* modeline-format */
  455. #define OPT_MS_MOUSE    !SMALLER && DISP_IBMPC  /* MsDos-mouse */
  456. #define OPT_NAMEBST     !SMALLER        /* name's stored in a bst */
  457. #define OPT_ONLINEHELP  !SMALLER        /* short per-command help */
  458. #define OPT_POPUPCHOICE !SMALLER        /* popup-choices mode */
  459. #define OPT_POPUP_MSGS  !SMALLER        /* popup-msgs mode */
  460. #define OPT_REBIND      !SMALLER        /* permit rebinding of keys at run-time    */
  461. #define OPT_TAGS_CMPL   !SMALLER && OPT_TAGS    /* name-completion for tags */
  462. #define OPT_TERMCHRS    !SMALLER        /* set/show-terminal */
  463. #define OPT_UPBUFF      !SMALLER        /* animated buffer-update */
  464. #define OPT_WIDE_CTYPES !SMALLER        /* extra char-types tests */
  465. #define OPT_WORDCOUNT   !SMALLER        /* "count-words" command" */
  466.  
  467. /* "show" commands for the optional features */
  468. #define OPT_SHOW_CTYPE    !SMALLER        /* "show-printable" */
  469. #define OPT_SHOW_EVAL   !SMALLER && OPT_EVAL    /* "show-variables" */
  470. #define OPT_SHOW_MAPS   !SMALLER         /* display mapping for ":map" */
  471. #define OPT_SHOW_REGS   !SMALLER        /* "show-registers" */
  472. #define OPT_SHOW_TAGS   !SMALLER && OPT_TAGS    /* ":tags" displays tag-stack */
  473.  
  474. /* selections and attributed regions */
  475. #define OPT_VIDEO_ATTRS !SMALLER
  476. #define OPT_SELECTIONS  OPT_VIDEO_ATTRS
  477. #define OPT_HYPERTEXT    OPT_VIDEO_ATTRS
  478.  
  479. /* OPT_PSCREEN permits a direct interface to the pscreen data structure
  480.  * in display.c. This allows us to avoid storing the screen data on the
  481.  * screen interface side.
  482.  */
  483. #define OPT_PSCREEN  (XTOOLKIT && OPT_VIDEO_ATTRS)
  484.  
  485. #if    DISP_TERMCAP && !SMALLER
  486. /* the setting "xterm-mouse" is always available, i.e.  the modetbl entry
  487.  * is not conditional.  but all of the code that supports xterm-mouse _is_
  488.  * ifdefed.  this makes it easier for users to be able to put "set
  489.  * xterm-mouse" in their .vilerc which is shared between vile and xvile.
  490.  */
  491. #define    OPT_XTERM    2    /* mouse-clicking support */
  492. #else
  493. #define    OPT_XTERM    0    /* vile doesn't recognize xterm mouse */
  494. #endif
  495.  
  496.      /* combine select/yank (for mouse support) */
  497. #define OPT_SEL_YANK    ((DISP_X11 && XTOOLKIT) || SYS_WINNT || SYS_OS2)
  498.  
  499.     /* any mouse capability */
  500. #define OPT_MOUSE       (OPT_SEL_YANK || OPT_XTERM || OPT_MS_MOUSE)
  501.  
  502.     /* menus */
  503. #define    OPT_MENUS    (DISP_X11 && (MOTIF_WIDGETS||ATHENA_WIDGETS))
  504. #define OPT_MENUS_COLORED 0    /* (MOTIF_WIDGETS && OPT_MENUS) */
  505.  
  506. /*
  507.  * If selections will be used to communicate between vile and other
  508.  * applications, OWN_SELECTION must be defined to call the procedure
  509.  * for establishing ownership of the selection.
  510.  */
  511. #if OPT_SELECTIONS && XTOOLKIT /* or others? */
  512. #define OWN_SELECTION() own_selection()
  513. #else
  514. #define OWN_SELECTION()    /*EMPTY*/
  515. #endif
  516.  
  517. /*
  518.  * Special characters used in globbing
  519.  */
  520. #define    GLOB_MULTI    '*'
  521. #define    GLOB_SINGLE    '?'
  522. #define    GLOB_ELLIPSIS    "..."
  523. #define    GLOB_RANGE    "[]"
  524. #define    GLOB_NEGATE    "^!"
  525.  
  526. /*
  527.  * Configuration options for globbing
  528.  */
  529. #define    OPT_GLOB_ENVIRON    ENVFUNC && !SMALLER
  530. #define    OPT_GLOB_ELLIPSIS    SYS_VMS || SYS_UNIX || SYS_OS2 || SYS_WINNT || (SYS_MSDOS && !SMALLER)
  531. #define    OPT_GLOB_PIPE        SYS_UNIX && OPT_SHELL
  532. #define    OPT_GLOB_RANGE        SYS_UNIX || SYS_OS2 || SYS_WINNT || (SYS_MSDOS && !SMALLER)
  533.  
  534. /*    Debugging options    */
  535. #define    OPT_RAMSIZE        0  /* dynamic RAM memory usage tracking */
  536. #define OPT_DEBUGMACROS        0  /* $debug triggers macro debugging    */
  537. #define    OPT_VISIBLE_MACROS    0  /* update display during keyboard macros*/
  538.  
  539. #ifndef OPT_TRACE
  540. #define OPT_TRACE        0  /* turn on debug/trace (link with trace.o) */
  541. #endif
  542.  
  543. /* That's the end of the user selections -- the rest is static definition */
  544. /* (i.e. you shouldn't need to touch anything below here */
  545. /* ====================================================================== */
  546.  
  547. #include <errno.h>
  548. #if SYS_VMS
  549. #include <perror.h>    /* defines 'sys_errlist[]' */
  550. #endif
  551. #if SYS_UNIX
  552. # ifdef DECL_ERRNO
  553. extern    int    errno;    /* some systems don't define this in <errno.h> */
  554. # endif
  555. # ifdef DECL_SYS_NERR
  556. extern    int    sys_nerr;
  557. # endif
  558. # ifdef DECL_SYS_ERRLIST
  559. extern    char *    sys_errlist[];
  560. # endif
  561. #endif
  562. #define    set_errno(code)    errno = code
  563.  
  564.     /* bit-mask definitions */
  565. #define    lBIT(n)    ((ULONG)(1L<<(n)))
  566. #define    iBIT(n) ((UINT)(1 <<(n)))
  567.  
  568. /* FIXME: leftover definitions from K&R version */
  569. #define SIZE_T  size_t
  570. #define ALLOC_T size_t
  571.  
  572. #ifndef HAVE_GETHOSTNAME
  573. #define HAVE_GETHOSTNAME 0
  574. #endif
  575.  
  576. #if !(HAVE_STRCHR && HAVE_STRRCHR)
  577. #define USE_INDEX 1
  578. #endif
  579.  
  580. #ifdef USE_INDEX
  581. #define strchr index
  582. #define strrchr rindex
  583. #if MISSING_EXTERN_RINDEX
  584. extern char *index (const char *s, int c);
  585. extern char *rindex (const char *s, int c);
  586. #endif
  587. #endif /* USE_INDEX */
  588.  
  589. #if STDC_HEADERS || HAVE_STRING_H
  590. # include <string.h>
  591.   /* An ANSI string.h and pre-ANSI memory.h might conflict.  */
  592. # if !STDC_HEADERS && HAVE_MEMORY_H
  593. #  include <memory.h>
  594. # endif /* not STDC_HEADERS and HAVE_MEMORY_H */
  595. #else /* not STDC_HEADERS and not HAVE_STRING_H */
  596. # if HAVE_STRINGS_H
  597. #  include <strings.h>
  598.   /* memory.h and strings.h conflict on some systems */
  599.   /* FIXME: should probably define memcpy and company in terms of bcopy,
  600.      et al here */
  601. # endif
  602. #endif /* not STDC_HEADERS and not HAVE_STRING_H */
  603.  
  604. #if HAVE_SYS_PARAM_H
  605. #include <sys/param.h>
  606. #endif
  607.  
  608. /*    System dependent library redefinitions, structures and includes    */
  609.  
  610. #if CC_NEWDOSCC && ! CC_CSETPP
  611. #include <dos.h>
  612. # define HAVE_STRERROR        1
  613. #endif
  614.  
  615. #if CC_NEWDOSCC && ! CC_DJGPP && ! CC_CSETPP
  616. #undef peek
  617. #undef poke
  618. #define    peek(a,b,c,d)    movedata(a,b,FP_SEG(c),FP_OFF(c),d)
  619. #define    poke(a,b,c,d)    movedata(FP_SEG(c),FP_OFF(c),a,b,d)
  620. #define    movmem(a, b, c)        memcpy(b, a, c)
  621. #endif
  622.  
  623. #if  CC_WATCOM
  624. #include      <string.h>
  625. #endif
  626.  
  627. #if  CC_WATCOM || CC_DJGPP
  628. #define    movmem(a, b, c)        memcpy(b, a, c)
  629. #endif
  630.  
  631. #if CC_MSC
  632. #include <memory.h>
  633. #endif
  634.  
  635.  
  636. /* on MS-DOS we have to open files in binary mode to see the ^Z characters. */
  637.  
  638. #if SYS_MSDOS || SYS_WIN31 || SYS_OS2 || SYS_WINNT
  639. #define FOPEN_READ    "rb"
  640. #define FOPEN_WRITE    "wb"
  641. #define FOPEN_APPEND    "ab"
  642. #define FOPEN_UPDATE    "w+b"
  643. #else
  644. #define FOPEN_READ    "r"
  645. #define FOPEN_WRITE    "w"
  646. #define FOPEN_APPEND    "a"
  647. #define FOPEN_UPDATE    "w+"
  648. #endif
  649.  
  650. #if OPT_MSDOS_PATH && !SYS_OS2_EMX    /* DOS path / to \ conversions */
  651. # define is_slashc(c) (c == '\\' || c == '/')
  652. # define SL_TO_BSL(s)    sl_to_bsl(s)
  653. #else
  654. # define SL_TO_BSL(s)    (s)
  655. # define bsl_to_sl_inplace(s)
  656. #endif
  657.  
  658.  
  659. #ifndef is_slashc
  660. # define is_slashc(c) (c == '/')
  661. #endif
  662.  
  663. #define SLASHC '/'    /* UNIX, MSDOS-compatibility, VMS-shell */
  664.  
  665.  
  666. #if SYS_VMS
  667. #define    unlink(a)    delete(a)
  668. #define tempnam        vile_tempnam
  669. #endif
  670.  
  671. #if SYS_OS2 && CC_WATCOM
  672. #define unlink(a)    remove(a)
  673. #endif
  674.  
  675. /*    define some ability flags */
  676.  
  677.     /* intermediate config-controls for filec.c (needed in nemode.h) */
  678. #if !SMALLER
  679. #define COMPLETE_FILES  (SYS_UNIX || SYS_MSDOS || SYS_VMS || SYS_OS2 || SYS_WINNT)
  680. #define    COMPLETE_DIRS   (SYS_UNIX || SYS_MSDOS || SYS_VMS || SYS_OS2 || SYS_WINNT)
  681. #else
  682. #define COMPLETE_FILES  0
  683. #define COMPLETE_DIRS   0
  684. #endif
  685.  
  686. #if DISP_NTWIN
  687. extern int MainProgram(int argc, char *argv[]);
  688. #else
  689. #define MainProgram main
  690. #endif
  691.  
  692.     /* semaphore may be needed to prevent interrupt of display-code */
  693. #if !defined(SIGWINCH) && ! OPT_WORKING
  694. # define beginDisplay() /* nothing */
  695. # define endofDisplay() /* nothing */
  696. #endif
  697.  
  698. #if OPT_WORKING
  699. #define ShowWorking() (!global_b_val(MDTERSE) && global_g_val(GMDWORKING))
  700. #else
  701. #define ShowWorking() (!global_b_val(MDTERSE))
  702. #endif
  703.  
  704. /* how to signal our process group: pass the 0 to 'getpgrp()' if we can,
  705.  * since it's safer --- the machines where we can't are probably POSIX
  706.  * machines with ANSI C.
  707.  */
  708. #if !GETPGRP_VOID || MISSING_EXTERN_GETPGRP
  709. # define GETPGRPCALL getpgrp(0)
  710. #else
  711. # define GETPGRPCALL getpgrp()
  712. #endif
  713.  
  714. #if HAVE_KILLPG
  715. # define signal_pg(sig) killpg( GETPGRPCALL, sig)
  716. #else
  717. # define signal_pg(sig)   kill(-GETPGRPCALL, sig)
  718. #endif
  719.  
  720. #if    DISP_IBMPC
  721. #define    MEMMAP    1
  722. #else
  723. #define    MEMMAP    0
  724. #endif
  725.  
  726. #if SYS_OS2
  727. /*
  728.  * The OS/2 toolkit defines identical typedefs for UCHAR, etc.;
  729.  * we use those definitions to avoid trouble when using OS/2 include
  730.  * files.
  731.  */
  732. # include <os2def.h>
  733. #else
  734. # define UCHAR    unsigned char
  735. # define UINT    unsigned int
  736. # define USHORT    unsigned short
  737. # define ULONG    unsigned long
  738. #endif
  739.  
  740. /*    internal constants    */
  741.  
  742. #if SYS_MSDOS || SYS_WIN31
  743. #define    BITS_PER_INT    16
  744. #endif
  745.  
  746. #ifndef    BITS_PER_INT
  747. #define    BITS_PER_INT    32
  748. #endif
  749.  
  750. #ifdef  MAXPATHLEN            /* usually in <sys/param.h>    */
  751. #define NFILEN    MAXPATHLEN        /* # of bytes, file name    */
  752. #else
  753. #define NFILEN    256            /* # of bytes, file name    */
  754. #endif
  755. #define NBUFN    21            /* # of bytes, buffername, incl. null*/
  756. #define NLINE    256            /* # of bytes, input line    */
  757. #define    NSTRING    128            /* # of bytes, string buffers    */
  758. #define NPAT    128            /* # of bytes, pattern        */
  759. #define HUGE    (1<<(BITS_PER_INT-2))    /* Huge number            */
  760. #define    NLOCKS    100            /* max # of file locks active    */
  761. #if DISP_X11 || DISP_TERMCAP || IBM_VIDEO
  762. #define    NCOLORS    16            /* number of supported colors    */
  763. #else
  764. #define    NCOLORS    8            /* number of supported colors    */
  765. #endif
  766. #define    KBLOCK    256            /* sizeof kill buffer chunks    */
  767. #if !OPT_SELECTIONS
  768. #define    NKREGS    37            /* number of kill buffers    */
  769. #define KEYST_KREG (NKREGS-1)
  770. #else
  771. #define NKREGS    39            /* When selections are enabled, we
  772.                      * allocate an extra kill buffer for
  773.                      * the current selection and another
  774.                      * for the clipboard.
  775.                      */
  776. #define CLIP_KREG (NKREGS-1)
  777. #define SEL_KREG (NKREGS-2)
  778. #define KEYST_KREG (NKREGS-3)
  779. #endif
  780. #define    NBLOCK    16            /* line block chunk size    */
  781. #define MINWLNS    3            /* min # lines, window/screen    */
  782. #define MAXROWS    200            /* max # lines per screen    */
  783. #define MAXCOLS    200            /* max # cols per screen    */
  784.  
  785. #define C_BLACK 0
  786. #define C_WHITE (ncolors-1)
  787.  
  788. #define N_chars    256            /* must be a power-of-2        */
  789. #define HIGHBIT    0x00080        /* the meta bit            */
  790. #define CTLA       0x00100        /* ^A flag, or'ed in        */
  791. #define CTLX       0x00200        /* ^X flag, or'ed in        */
  792. #define SPEC       0x00400        /* special key (function keys)    */
  793. #define NOREMAP    0x00800        /* unremappable */
  794. #define YESREMAP   0x01000        /* override noremap */
  795. #define REMAPFLAGS (NOREMAP|YESREMAP)
  796. #define W32_KEY    0x02000        /* special Win32 keys         */
  797. #define W32_SHIFT  0x04000        /* shift was held down        */
  798. #define W32_CTRL   0x08000        /* control was held down    */
  799. #define W32_ALT    0x10000        /* alt was held down          */
  800. #define W32_NOMOD  (~(W32_KEY|W32_SHIFT|W32_CTRL|W32_ALT))
  801.  
  802. #define kcod2key(c)    ((c) & (UINT)(N_chars-1)) /* strip off the above prefixes */
  803. #define    isspecial(c)    (((UINT)(c) & (UINT)~(N_chars-1)) != 0)
  804.  
  805. #define    char2int(c)    ((int)(c & 0xff)) /* mask off sign-extension, etc. */
  806.  
  807. #define    PLURAL(n)    ((n!=1)?"s":"")
  808.  
  809. #define    EOS     '\0'
  810.  
  811. /* protect against losing namespaces */
  812. #undef    FALSE
  813. #undef    TRUE
  814. #undef    ABORT
  815. #undef    FAILED
  816. #undef    SORTOFTRUE
  817.  
  818. #define FALSE    0            /* False, no, bad, etc.     */
  819. #define TRUE    1            /* True, yes, good, etc.    */
  820. #define ABORT    2            /* Death, ESC, abort, etc.    */
  821. #define    FAILED    3            /* not-quite fatal false return    */
  822. #define    SORTOFTRUE    4        /* really!    */
  823.  
  824. #define    STOP    0            /* keyboard macro not in use    */
  825. #define    PLAY    1            /*    "     "      playing    */
  826. #define    RECORD    2            /*    "     "   recording    */
  827.  
  828. #define QUOTED    TRUE
  829. #define NOQUOTED    FALSE
  830.  
  831. #define DOMAP    TRUE
  832. #define NODOMAP    FALSE
  833.  
  834. /* values for regionshape */
  835. typedef enum {
  836.     EXACT,
  837.     FULLLINE,
  838.     RECTANGLE
  839. } REGIONSHAPE;
  840.  
  841. /* flook options */
  842. #define FL_EXECABLE  iBIT(0)    /* same as X_OK */
  843. #define FL_WRITEABLE iBIT(1)    /* same as W_OK */
  844. #define FL_READABLE  iBIT(2)    /* same as R_OK */
  845. #define FL_HERE      iBIT(3)    /* look in current directory */
  846. #define FL_HOME      iBIT(4)    /* look in home directory */
  847. #define FL_EXECDIR   iBIT(5)    /* look in execution directory */
  848. #define FL_TABLE     iBIT(6)    /* look in table */
  849. #define FL_PATH      iBIT(7)    /* look along execution-path */
  850.  
  851. #define FL_ANYWHERE  (FL_HERE|FL_HOME|FL_EXECDIR|FL_TABLE|FL_PATH)
  852.  
  853. /* definitions for name-completion */
  854. #define    NAMEC        name_cmpl /* char for forcing name-completion */
  855. #define    TESTC        test_cmpl /* char for testing name-completion */
  856.  
  857. /* kbd_string options */
  858. #define KBD_EXPAND    iBIT(0)    /* do we want to expand %, #, : */
  859. #define KBD_QUOTES    iBIT(1)    /* do we add and delete '\' chars for the caller */
  860. #define KBD_LOWERC    iBIT(2)    /* do we force input to lowercase */
  861. #define KBD_UPPERC    iBIT(3)    /* do we force input to uppercase */
  862. #define KBD_NOEVAL    iBIT(4)    /* disable 'tokval()' (e.g., from buffer) */
  863. #define KBD_MAYBEC    iBIT(5)    /* may be completed -- or not */
  864. #define KBD_NULLOK    iBIT(6)    /* may be empty -- or not */
  865. #define KBD_EXPCMD    iBIT(7)    /* expand %, #, : only in shell-command */
  866. #define KBD_SHPIPE    iBIT(8)    /* expand, assuming shell-command */
  867. #define KBD_NOMAP    iBIT(9) /* don't permit mapping via kbd_key() */
  868. #define KBD_EXPPAT    iBIT(10) /* expand ~ to last replacement */
  869. #define KBD_0CHAR    iBIT(11) /* string can have embedded nulls */
  870. #define KBD_STATED    iBIT(12) /* erasing buffer returns for prev-state */
  871.  
  872. /* default option for 'mlreply' (used in modes.c also) */
  873. #if !(SYS_MSDOS || SYS_WIN31 || SYS_OS2 || SYS_WINNT)
  874. #define    KBD_NORMAL    KBD_EXPAND|KBD_QUOTES
  875. #else
  876. #define    KBD_NORMAL    KBD_EXPAND
  877. #endif
  878.  
  879. /* This was an enum, but did not compile with TurboC */
  880. #define WATCHREAD   iBIT(0)
  881. #define WATCHWRITE  iBIT(1)
  882. #define WATCHEXCEPT iBIT(2)
  883. typedef UINT WATCHTYPE;
  884.  
  885. /* reserve space for ram-usage option */
  886. #if OPT_RAMSIZE
  887. #define    LastMsgCol    (term.t_ncol - 10)
  888. #else
  889. #define    LastMsgCol    (term.t_ncol - 1)
  890. #endif
  891.  
  892. /*
  893.  * directions for the scan routines.
  894.  */
  895. #define    FORWARD    0            /* forward direction        */
  896. #define REVERSE    1            /* backwards direction        */
  897.  
  898.     /* nonfatal codes */
  899. #define FIOFUN  -1            /* File I/O, eod of file/bad line*/
  900. #define FIOSUC  0            /* File I/O, success.        */
  901. #define FIOEOF  1            /* File I/O, end of file.    */
  902.     /* error codes */
  903. #define FIOFNF  2            /* File I/O, file not found.    */
  904. #define FIOERR  3            /* File I/O, error.        */
  905. #define FIOMEM  4            /* File I/O, out of memory    */
  906. #define FIOABRT 5            /* File I/O, aborted        */
  907.  
  908. /* three flavors of insert mode    */
  909. /* it's FALSE, or one of:    */
  910. #define INSERT 1
  911. #define OVERWRITE 2
  912. #define REPLACECHAR 3
  913.  
  914. /* kill register control -- values for kbflag */
  915. #define KNEEDCLEAN   iBIT(0)        /* Kill register needs cleaning */
  916. #define KYANK        iBIT(1)        /* Kill register resulted from yank */
  917. #define KLINES       iBIT(2)        /* Kill register contains full lines */
  918. #define KRECT        iBIT(3)        /* Kill register contains rectangle */
  919. #define KAPPEND      iBIT(4)        /* Kill register should be appended */
  920.  
  921. /* operator types.  Needed mainly because word movement changes depending on
  922.     whether operator is "delete" or not.  Aargh.  */
  923. #define OPDEL 1
  924. #define OPOTHER 2
  925.  
  926. /* popup-choices values */
  927. #define POPUP_CHOICES_OFF      0
  928. #define POPUP_CHOICES_IMMED    1
  929. #define POPUP_CHOICES_DELAYED  2
  930.  
  931. /* define these so C-fence matching doesn't get confused when we're editing
  932.     the cfence code itself */
  933. #define LBRACE '{'
  934. #define RBRACE '}'
  935. #define LPAREN '('
  936. #define RPAREN ')'
  937. #define LBRACK '['
  938. #define RBRACK ']'
  939.  
  940. /* these are the characters that are used in the expand-chars mode */
  941. #define EXPC_THIS  '%'
  942. #define EXPC_THAT  '#'
  943. #define EXPC_SHELL '!'
  944. #define EXPC_RPAT  '~'
  945. #if OPT_VMS_PATH || OPT_MSDOS_PATH    /* ':' gets in the way of drives */
  946. #define EXPC_TOKEN '&'
  947. #else
  948. #define EXPC_TOKEN ':'
  949. #endif
  950.  
  951. /* separator used when scanning PATH environment variable */
  952. #if SYS_VMS
  953. #define    PATHCHR    ','
  954. #endif
  955.  
  956. #if OPT_MSDOS_PATH
  957. #define    PATHCHR    ';'
  958. #endif
  959.  
  960. #ifndef PATHCHR                /* e.g., UNIX */
  961. #define    PATHCHR    ':'
  962. #endif
  963.  
  964. /* how big is the ascii rep. of an int? */
  965. #define    INTWIDTH    sizeof(int) * 3
  966.  
  967. /*    Macro argument token types                    */
  968.  
  969. #define    TKNUL    0            /* end-of-string        */
  970. #define    TKARG    1            /* interactive argument        */
  971. #define    TKBUF    2            /* buffer argument        */
  972. #define    TKVAR    3            /* user variables        */
  973. #define    TKENV    4            /* environment variables    */
  974. #define    TKFUN    5            /* function....            */
  975. #define    TKDIR    6            /* directive            */
  976. #define    TKLBL    7            /* line label            */
  977. #define    TKLIT    8            /* numeric literal        */
  978. #define    TKSTR    9            /* quoted string literal    */
  979. #define    TKCMD    10            /* command name            */
  980.  
  981. /*    Internal defined functions                    */
  982.  
  983. #define    nextab(a)    (((a / curtabval) + 1) * curtabval)
  984.  
  985. #define NEXT_COLUMN(col, c, list, tabs) \
  986.         ((c == '\t' && !list) \
  987.          ? (col + tabs - (col % tabs)) \
  988.          : (    (isPrint(c)) \
  989.             ? (col + 1) \
  990.             : (col + ((c & HIGHBIT) ? 4 : 2))))
  991.  
  992. /* these are the bits that go into the vl_chartypes_ array */
  993. /* the macros below test for them */
  994. #if OPT_WIDE_CTYPES
  995. #define chrBIT(n) lBIT(n)
  996. #else
  997. #define chrBIT(n) iBIT(n)
  998. #endif
  999.  
  1000. #define vl_upper    chrBIT(0)        /* upper case */
  1001. #define vl_lower    chrBIT(1)        /* lower case */
  1002. #define vl_digit    chrBIT(2)        /* digits */
  1003. #define vl_space    chrBIT(3)        /* whitespace */
  1004. #define vl_bspace   chrBIT(4)        /* backspace character (^H, DEL, and user's) */
  1005. #define vl_cntrl    chrBIT(5)        /* control characters, including DEL */
  1006. #define vl_print    chrBIT(6)        /* printable */
  1007. #define vl_punct    chrBIT(7)        /* punctuation */
  1008. #define vl_ident    chrBIT(8)        /* is typically legal in "normal" identifier */
  1009. #define vl_pathn    chrBIT(9)        /* is typically legal in a file's pathname */
  1010. #define vl_wild     chrBIT(10)        /* is typically a shell wildcard char */
  1011. #define vl_linespec chrBIT(11)        /* ex-style line range: 1,$ or 13,15 or % etc.*/
  1012. #define vl_fence    chrBIT(12)        /* a fence, i.e. (, ), [, ], {, } */
  1013. #define vl_nonspace chrBIT(13)        /* non-whitespace */
  1014. #define vl_qident   chrBIT(14)        /* is typically legal in "qualified" identifier */
  1015.  
  1016. #if OPT_WIDE_CTYPES
  1017. #define vl_scrtch   chrBIT(15)        /* legal in scratch-buffer names */
  1018. #define vl_shpipe   chrBIT(16)        /* legal in shell/pipe-buffer names */
  1019.  
  1020. #define    screen_to_bname(buf)\
  1021.     screen_string(buf,sizeof(buf),(CHARTYPE)(vl_pathn|vl_scrtch|vl_shpipe))
  1022. typedef    ULONG CHARTYPE;
  1023. #else
  1024. #define    screen_to_bname(buf)\
  1025.     screen_string(buf,sizeof(buf),(CHARTYPE)(vl_pathn))
  1026. typedef USHORT CHARTYPE;
  1027. #endif
  1028.  
  1029. /* these parallel the ctypes.h definitions, except that
  1030.     they force the char to valid range first */
  1031. #define istype(m,c) ((vl_chartypes_[((UINT)(c))&((UINT)(N_chars-1))] & (m)) != 0)
  1032.  
  1033. #define isAlnum(c)    istype(vl_lower|vl_upper|vl_digit, c)
  1034. #define isAlpha(c)    istype(vl_lower|vl_upper, c)
  1035. #define isCntrl(c)    istype(vl_cntrl, c)
  1036. #define isDigit(c)    istype(vl_digit, c)
  1037. #define isLower(c)    istype(vl_lower, c)
  1038. #define isPrint(c)    istype(vl_print, c)
  1039. #define isPunct(c)    istype(vl_punct, c)
  1040. #define isSpace(c)    istype(vl_space, c)
  1041. #define isUpper(c)    istype(vl_upper, c)
  1042.  
  1043. #define isbackspace(c)    (istype(vl_bspace, c) || (c) == backspc)
  1044. #define isfence(c)    istype(vl_fence, c)
  1045. #define isident(c)    istype(vl_ident, c)
  1046. #define islinespecchar(c)    istype(vl_linespec, c)
  1047. #define ispath(c)    istype(vl_pathn, c)
  1048. #define iswild(c)    istype(vl_wild, c)
  1049.  
  1050. /* macro for cases where return & newline are equivalent */
  1051. #define    isreturn(c)    ((c == '\r') || (c == '\n'))
  1052.  
  1053. /* macro for whitespace (non-return) */
  1054. #define    isBlank(c)      ((c == '\t') || (c == ' '))
  1055.  
  1056. /* DIFCASE represents the difference between upper
  1057.    and lower case letters, DIFCNTRL the difference between upper case and
  1058.    control characters.    They are xor-able values.  */
  1059. #define    DIFCASE        0x20
  1060. #define    DIFCNTRL    0x40
  1061. #define toUpper(c)    ((c)^DIFCASE)
  1062. #define toLower(c)    ((c)^DIFCASE)
  1063. #define tocntrl(c)    ((c)^DIFCNTRL)
  1064. #define toalpha(c)    ((c)^DIFCNTRL)
  1065.  
  1066. #define nocase_eq(bc,pc)    ((bc) == (pc) || \
  1067.             (isAlpha(bc) && (((bc) ^ DIFCASE) == (pc))))
  1068.  
  1069. #define ESC        tocntrl('[')
  1070. #define BEL        tocntrl('G')    /* ascii bell character        */
  1071. #define CONTROL_A    tocntrl('A')    /* for cntl_a attribute sequences */
  1072.  
  1073. #if !(SYS_MSDOS && CC_DJGPP)
  1074. /* some systems need a routine to check for interrupts.  most don't, and
  1075.  * the routine overhead can be expensive in some places
  1076.  */
  1077. # define interrupted() (am_interrupted != 0)
  1078. #endif
  1079.  
  1080. #define ABORTED(c) ((c) == abortc || (c) == intrc || interrupted())
  1081.  
  1082. /*
  1083.  * Definitions etc. for regexp(3) routines.
  1084.  *
  1085.  *    the regexp code is:
  1086.  *    Copyright (c) 1986 by University of Toronto.
  1087.  *    Written by Henry Spencer.  Not derived from licensed software.
  1088.  *
  1089.  */
  1090. #define NSUBEXP  10
  1091. typedef struct regexp {
  1092.     char *startp[NSUBEXP];
  1093.     char *endp[NSUBEXP];
  1094.     SIZE_T mlen;        /* convenience:  endp[0] - startp[0] */
  1095.     char regstart;        /* Internal use only. */
  1096.     char reganch;        /* Internal use only. */
  1097.     int regmust;        /* Internal use only. */
  1098.     int regmlen;        /* Internal use only. */
  1099.     SIZE_T size;        /* vile addition -- how big is this */
  1100.     char program[1];    /* Unwarranted chumminess with compiler. */
  1101. } regexp;
  1102.  
  1103. /*
  1104.  * The first byte of the regexp internal "program" is actually this magic
  1105.  * number; the start node begins in the second byte.
  1106.  */
  1107. #define    REGEXP_MAGIC    0234
  1108.  
  1109. #ifndef CHARBITS
  1110. #define    UCHAR_AT(p)    ((int)*(UCHAR *)(p))
  1111. #else
  1112. #define    UCHAR_AT(p)    ((int)*(p)&CHARBITS)
  1113. #endif
  1114.  
  1115. /* end of regexp stuff */
  1116.  
  1117. /*
  1118.  * Definitions for 'tbuff.c' (temporary/dynamic char-buffers)
  1119.  */
  1120. typedef    struct    vl_tbuff    {
  1121.     char *    tb_data;    /* the buffer-data */
  1122.     ALLOC_T    tb_size;    /* allocated size */
  1123.     ALLOC_T    tb_used;    /* total used in */
  1124.     ALLOC_T    tb_last;    /* last put/get index */
  1125.     int    tb_endc;
  1126.     } TBUFF;
  1127.  
  1128. /*
  1129.  * Definitions for 'itbuff.c' (temporary/dynamic int-buffers)
  1130.  */
  1131. typedef    struct    vl_itbuff    {
  1132.     int *    itb_data;    /* the buffer-data */
  1133.     ALLOC_T    itb_size;    /* allocated size */
  1134.     ALLOC_T    itb_used;    /* total used in */
  1135.     ALLOC_T    itb_last;    /* last put/get index */
  1136.     int    itb_endc;
  1137.     } ITBUFF;
  1138.  
  1139. /*
  1140.  * Primitive types
  1141.  */
  1142. typedef    int        L_NUM;        /* line-number */
  1143. typedef    int        C_NUM;        /* column-number */
  1144. typedef    struct {
  1145.     unsigned short flgs;
  1146.     unsigned short cook;
  1147. } L_FLAG;        /* LINE-flags */
  1148.  
  1149. typedef    ULONG        CMDFLAGS;    /* CMDFUNC flags */
  1150. typedef    long        B_COUNT;    /* byte-count */
  1151.  
  1152. #ifdef __cplusplus
  1153. #define EXTERN_CONST extern const
  1154. #else
  1155. #define EXTERN_CONST const
  1156. #endif
  1157.  
  1158. /*
  1159.  * Control structures
  1160.  */
  1161. #define    for_ever for(;;)
  1162.  
  1163.     /* avoid "constant-in-conditional-context */
  1164. #ifdef lint
  1165. #define one_time while(malloc(1)==0)
  1166. #else
  1167. #define one_time while(0)
  1168. #endif
  1169.  
  1170.     /* Some lint's do, many don't like this */
  1171. #ifdef lint
  1172. #undef  CC_CANNOT_OFFSET_CASES
  1173. #define CC_CANNOT_OFFSET_CASES 1
  1174. #endif
  1175.  
  1176. /*
  1177.  * All text is kept in circularly linked lists of "LINE" structures. These
  1178.  * begin at the header line. This line is pointed to by the "BUFFER".
  1179.  * Each line contains:
  1180.  *  number of bytes in the line (the "used" size),
  1181.  *  the size of the text array,
  1182.  *  the text.
  1183.  * The end of line is not stored as a byte; it's implied. Future
  1184.  * additions may include update hints, and a list of marks into the line.
  1185.  *
  1186.  * Lines are additionally sometimes stacked in undo lists.
  1187.  */
  1188. typedef    struct    LINE*    LINEPTR;
  1189.  
  1190. typedef struct    LINE {
  1191.     LINEPTR l_fp;            /* Link to the next line    */
  1192.     LINEPTR l_bp;            /* Link to the previous line    */
  1193.     union {
  1194.         SIZE_T    l_sze;        /* Allocated size         */
  1195.         C_NUM    l_fo;        /* forward undo dot offs (undo only) */
  1196.     } l_s_fo;
  1197.     union {
  1198.         L_NUM    l_nmbr;        /* line-# iff b_numlines > 0    */
  1199.         C_NUM    l_bo;        /* backward undo dot offs (undo only) */
  1200.     } l_n_bo;
  1201.     int    l_used;            /* Used size (may be negative)    */
  1202.     union {
  1203.         char *l_txt;        /* The data for this line    */
  1204.         LINEPTR l_nxt;        /* if an undo stack separator,    */
  1205.     } lt;                /*  a pointer to the next one    */
  1206.     union
  1207.     {
  1208.         LINEPTR    l_stklnk;    /* Link for undo stack        */
  1209.         L_FLAG    l_flg;        /* flags for undo ops        */
  1210.     } l;
  1211. }    LINE;
  1212.  
  1213. #define l_size        l_s_fo.l_sze
  1214. #define l_forw_offs    l_s_fo.l_fo
  1215. #define l_number    l_n_bo.l_nmbr
  1216. #define l_back_offs    l_n_bo.l_bo
  1217. #define l_text        lt.l_txt
  1218. #define l_nextsep    lt.l_nxt
  1219.  
  1220. #define l_undo_cookie    l_flg.cook
  1221. #define l_flag        l_flg.flgs
  1222.  
  1223. /* LINE.l_flag values */
  1224. #define LCOPIED  lBIT(0)    /* original line is already on an undo stack */
  1225. #define LGMARK   lBIT(1)    /* line matched a global scan */
  1226. #define LTRIMMED lBIT(2)    /* line doesn't have newline to display */
  1227.  
  1228. /* macros to ease the use of lines */
  1229. #define    for_each_line(lp,bp) for (lp = lforw(buf_head(bp)); \
  1230.                     lp != buf_head(bp); \
  1231.                     lp = lforw(lp))
  1232.  
  1233. #define l_nxtundo        l.l_stklnk
  1234.  
  1235.     /*
  1236.      * Special values used in LINE.l_used
  1237.      */
  1238. #define LINENOTREAL    ((int)(-1)) /* for undo, marks an inserted line */
  1239. #define LINEUNDOPATCH    ((int)(-2)) /* provides stack patching value for undo */
  1240. /* #define MARKPATCH    ((int)(-3)) *//*    unused */
  1241. #define STACKSEP    ((int)(-4)) /* delimit set of changes on undo stack */
  1242. #define PURESTACKSEP    ((int)(-5)) /* as above, but buffer unmodified before */
  1243.                     /* this change */
  1244.  
  1245. #define    null_ptr    (LINE *)0
  1246. #define set_lforw(a,b)    lforw(a) = (b)
  1247. #define set_lback(a,b)    lback(a) = (b)
  1248. #define lforw(lp)    (lp)->l_fp
  1249. #define lback(lp)    (lp)->l_bp
  1250.  
  1251.     /*
  1252.      * Macros for referencing fields in the LINE struct.
  1253.      */
  1254. #define lgetc(lp, n)        char2int((lp)->l_text[(n)])
  1255. #define lputc(lp, n, c)     ((lp)->l_text[(n)]=(c))
  1256. #define llength(lp)        ((lp)->l_used)
  1257.  
  1258. #define liscopied(lp)        ((lp)->l.l_undo_cookie == current_undo_cookie)
  1259. #define lsetcopied(lp)        ((lp)->l.l_undo_cookie = current_undo_cookie)
  1260. #define lsetnotcopied(lp)    ((lp)->l.l_undo_cookie = 0)
  1261.  
  1262. #define lismarked(lp)        ((lp)->l.l_flag & LGMARK)
  1263. #define lsetmarked(lp)        ((lp)->l.l_flag |= LGMARK)
  1264. #define lsetnotmarked(lp)    ((lp)->l.l_flag &= ~LGMARK)
  1265. #define lflipmark(lp)        ((lp)->l.l_flag ^= LGMARK)
  1266.  
  1267. #define listrimmed(lp)        ((lp)->l.l_flag & LTRIMMED)
  1268. #define lsettrimmed(lp)        ((lp)->l.l_flag |= LTRIMMED)
  1269. #define lsetnottrimmed(lp)    ((lp)->l.l_flag &= ~LTRIMMED)
  1270. #define lsetclear(lp)        ((lp)->l.l_flag = (lp)->l.l_undo_cookie = 0)
  1271.  
  1272. #define lisreal(lp)        ((lp)->l_used >= 0)
  1273. #define lisnotreal(lp)        ((lp)->l_used == LINENOTREAL)
  1274. #define lislinepatch(lp)    ((lp)->l_used == LINEUNDOPATCH)
  1275. /* #define lismarkpatch(lp)    ((lp)->l_used == MARKPATCH) */
  1276. #define lispatch(lp)        (lislinepatch(lp) /* || lismarkpatch(lp) */ )
  1277. #define lisstacksep(lp)        ((lp)->l_used == STACKSEP || \
  1278.                     (lp)->l_used == PURESTACKSEP)
  1279. #define lispurestacksep(lp)    ((lp)->l_used == PURESTACKSEP)
  1280.  
  1281. /* marks are a line and an offset into that line */
  1282. typedef struct MARK {
  1283.     LINEPTR l;
  1284.     C_NUM o;
  1285. } MARK;
  1286.  
  1287. /* some macros that take marks as arguments */
  1288. #define is_at_end_of_line(m)    (m.o == llength(m.l))
  1289. #define is_empty_line(m)    (llength(m.l) == 0)
  1290. #define sameline(m1,m2)        (m1.l == m2.l)
  1291. #define samepoint(m1,m2)    (sameline(m1,m2) && (m1.o == m2.o))
  1292. #define char_at(m)        (lgetc(m.l,m.o))
  1293. #define put_char_at(m,c)    (lputc(m.l,m.o,c))
  1294. #define is_header_line(m,bp)    (m.l == buf_head(bp))
  1295. #define is_last_line(m,bp)    (lforw(m.l) == buf_head(bp))
  1296. #define is_first_line(m,bp)    (lback(m.l) == buf_head(bp))
  1297.  
  1298. /*
  1299.  * The starting position of a region, and the size of the region in
  1300.  * characters, is kept in a region structure.  Used by the region commands.
  1301.  */
  1302. typedef struct    {
  1303.     MARK     r_orig;            /* Origin LINE address.     */
  1304.     MARK    r_end;            /* Ending LINE address.     */
  1305.     C_NUM    r_leftcol;        /* Leftmost column.         */
  1306.     C_NUM    r_rightcol;        /* Rightmost column.         */
  1307.     B_COUNT    r_size;         /* Length in characters.    */
  1308. #if OPT_SELECTIONS
  1309.     USHORT    r_attr_id;        /* id of corresponding display  */
  1310. #endif
  1311. }    REGION;
  1312.  
  1313. #if OPT_COLOR || DISP_X11 || OPT_HILITEMATCH
  1314. typedef USHORT VIDEO_ATTR;        /* assume short is at least 16 bits */
  1315. #else
  1316. typedef UCHAR VIDEO_ATTR;
  1317. #endif
  1318.  
  1319. #define VACURS    iBIT(0)            /* cursor -- this is intentionally
  1320.                      * the same as VADIRTY. It should
  1321.                      * not be used anywhere other than
  1322.                      * in specific places in the low
  1323.                      * level drivers (e.g, x11.c).
  1324.                      */
  1325. #define VAMLFOC    iBIT(1)            /* modeline w/ focus        */
  1326. #define VAML    iBIT(2)            /* standard mode line (no focus)*/
  1327. #define VASEL    iBIT(3)            /* selection            */
  1328. #define    VAREV    iBIT(4)            /* reverse video        */
  1329. #define    VAUL    iBIT(5)            /* underline            */
  1330. #define    VAITAL    iBIT(6)            /* italics            */
  1331. #define    VABOLD    iBIT(7)            /* bold                */
  1332. #define VAOWNER ((VIDEO_ATTR)0x0700)    /* owner mask            */
  1333. #define VASPCOL ((VIDEO_ATTR)0x0800)    /* specific color           */
  1334. #define VACOLOR ((VIDEO_ATTR)0xf000)    /* color mask            */
  1335. #define VACOL_0 (VASPCOL)        /* color palette index 0     */
  1336. #define VACOL_1 (VASPCOL+1)        /* etc.                */
  1337. #define VACOL_2 (VASPCOL+2)
  1338. #define VACOL_3 (VASPCOL+3)
  1339. #define VACOL_4 (VASPCOL+4)
  1340. #define VACOL_5 (VASPCOL+5)
  1341. #define VACOL_6 (VASPCOL+6)
  1342. #define VACOL_7 (VASPCOL+7)
  1343. #define VACOL_8 (VASPCOL+8)
  1344. #define VACOL_9 (VASPCOL+9)
  1345. #define VACOL_A (VASPCOL+0xA)
  1346. #define VACOL_B (VASPCOL+0xB)
  1347. #define VACOL_C (VASPCOL+0xC)
  1348. #define VACOL_D (VASPCOL+0xD)
  1349. #define VACOL_E (VASPCOL+0xE)
  1350. #define VACOL_F (VASPCOL+0xF)
  1351.  
  1352. #define VCOLORNUM(attr) (((attr) & VACOLOR) >> 12)
  1353. #define VCOLORATTR(num) ((UINT)(num) << 12)
  1354.  
  1355. /* who owns an attributed region -- so we can delete them independently */
  1356. #define VOWNER(attr)    ((attr) & VAOWNER)
  1357. #define VOWN_MATCHES    0x0100
  1358. #define VOWN_OPERS    0x0200
  1359. #define VOWN_SELECT    0x0300
  1360. #define VOWN_CTLA    0x0400
  1361.  
  1362. /* The VATTRIB macro masks out those bits which should not be considered
  1363.  * for comparison purposes
  1364.  */
  1365.  
  1366. #if OPT_PSCREEN
  1367. #define VADIRTY    iBIT(0)            /* cell needs to be written out */
  1368. #define VATTRIB(attr) ((attr) & (VIDEO_ATTR) ~(VAOWNER|VADIRTY))
  1369. #else
  1370. #define VADIRTY ((VIDEO_ATTR)0)        /* nop for all others */
  1371. #define VATTRIB(attr) ((attr) & (VIDEO_ATTR) ~(VAOWNER))
  1372. #endif
  1373.  
  1374. /* grow (or initially allocate) a vector of newsize types, pointed to by
  1375.  * ptr.  this is used primarily for resizing the screen
  1376.  * the studious will note this is a lot like realloc.   but realloc
  1377.  * doesn't guarantee to preserve contents if it fails, and this also
  1378.  * zeroes the new space.
  1379.  */
  1380. #define GROW(ptr, type, oldsize, newsize) \
  1381. { \
  1382.     int tmpold = oldsize; \
  1383.     type *tmpp; \
  1384.     tmpp = typeallocn(type, newsize); \
  1385.     if (tmpp == NULL) \
  1386.         return FALSE; \
  1387.  \
  1388.     if (ptr) { \
  1389.         (void) memcpy((char *)tmpp, (char *)ptr, tmpold * sizeof(type)); \
  1390.         free((char *)ptr); \
  1391.     } else { \
  1392.         tmpold = 0; \
  1393.     } \
  1394.     ptr = tmpp; \
  1395.     (void) memset ((char *)(ptr+tmpold), 0, (newsize - tmpold) * sizeof(type)); \
  1396. }
  1397.  
  1398. /*
  1399.  * An attributed region is attached to a buffer and indicates how the
  1400.  * region should be displayed; eg. inverse video, underlined, etc.
  1401.  */
  1402.  
  1403. typedef struct vl_aregion {
  1404.     struct vl_aregion    *ar_next;
  1405.     REGION        ar_region;
  1406.     VIDEO_ATTR    ar_vattr;
  1407.     REGIONSHAPE    ar_shape;
  1408. #if OPT_HYPERTEXT
  1409.     char *        ar_hypercmd;
  1410. #endif
  1411. }    AREGION;
  1412.  
  1413. typedef    struct {
  1414.     char *pat;
  1415.     regexp *reg;
  1416. } REGEXVAL;
  1417.  
  1418. /* this is to ensure values can be of any type we wish.
  1419.    more can be added if needed.  */
  1420. union V {
  1421.     int i;
  1422.     char *p;
  1423.     REGEXVAL *r;
  1424. };
  1425.  
  1426. struct VAL {
  1427.     union V v;
  1428.     union V *vp;
  1429. };
  1430.  
  1431. typedef    struct    {
  1432.     const struct VALNAMES *names;
  1433.     struct VAL      *local;
  1434.     struct VAL      *global;
  1435. } VALARGS;
  1436.  
  1437. #define CHGD_ARGS VALARGS *args, int glob_vals, int testing
  1438.  
  1439. typedef    int    (*ChgdFunc) ( CHGD_ARGS );
  1440.  
  1441. /* settable values have their names stored here, along with a synonym, and
  1442.     what type they are */
  1443. struct VALNAMES {
  1444.         const char *name;
  1445.         const char *shortname;
  1446.         char  type;
  1447.         ChgdFunc side_effect;
  1448. };
  1449. /* the values of VALNAMES->type */
  1450. #define VALTYPE_INT    0
  1451. #define VALTYPE_STRING 1
  1452. #define VALTYPE_BOOL   2
  1453. #define VALTYPE_REGEX  3
  1454. #define VALTYPE_ENUM   4
  1455. #define VALTYPE_MAJOR  5
  1456.  
  1457.     /*
  1458.      * Values are either local or global. We distinguish the two cases
  1459.      * by whether the value-pointer points into the VAL-struct or not.
  1460.      */
  1461. #define is_local_val(lv,which)          (lv[which].vp == &(lv[which].v))
  1462. #define make_local_val(lv,which)        (lv[which].vp = &(lv[which].v))
  1463. #define make_global_val(lv,gv,which)    (lv[which].vp = &(gv[which].v))
  1464.  
  1465. /* these are masks for the WINDOW.w_flag hint */
  1466. #define WFFORCE iBIT(0)            /* Window needs forced reframe    */
  1467. #define WFMOVE    iBIT(1)            /* Movement from line to line    */
  1468. #define WFEDIT    iBIT(2)            /* Editing within a line    */
  1469. #define WFHARD    iBIT(3)            /* Better do a full display    */
  1470. #define WFMODE    iBIT(4)            /* Update mode line.        */
  1471. #define WFCOLR    iBIT(5)            /* Needs a color change        */
  1472. #define WFKILLS    iBIT(6)            /* something was deleted    */
  1473. #define WFINS    iBIT(7)            /* something was inserted    */
  1474. #define WFSTAT    iBIT(8)            /* Update mode line (info only).*/
  1475. #define WFSBAR    iBIT(9)            /* Update scroll bar(s)        */
  1476.  
  1477. /* define indices for GLOBAL, BUFFER, WINDOW modes */
  1478. #ifdef realdef
  1479. #include "chgdfunc.h"
  1480. #endif
  1481.  
  1482. #if    CHECK_PROTOTYPES
  1483.     typedef long W_VALUES;
  1484.     typedef long M_VALUES;
  1485.     typedef long B_VALUES;
  1486. #else
  1487. #    include "nemode.h"
  1488. #endif
  1489.  
  1490. /* macros for setting GLOBAL modes */
  1491.  
  1492. #define global_g_val(which) global_g_values.gv[which].v.i
  1493. #define set_global_g_val(which,val) global_g_val(which) = val
  1494. #define global_g_val_ptr(which) global_g_values.gv[which].v.p
  1495. #define set_global_g_val_ptr(which,val) global_g_val_ptr(which) = val
  1496. #define global_g_val_rexp(which) global_g_values.gv[which].v.r
  1497. #define set_global_g_val_rexp(which,val) global_g_val_rexp(which) = val
  1498.  
  1499. /* these are window properties affecting window appearance _only_ */
  1500. typedef struct    {
  1501.     MARK     w_dt;        /* Line containing "."           */
  1502.         /* i don't think "mark" needs to be here -- I think it
  1503.             could safely live only in the buffer -pgf */
  1504. #if WINMARK
  1505.     MARK     w_mk;            /* Line containing "mark"      */
  1506. #endif
  1507.     MARK     w_ld;            /* Line containing "lastdotmark"*/
  1508.     MARK     w_tld;            /* Line which may become "lastdotmark"*/
  1509.     MARK     w_ln;        /* Top line in the window (offset used in linewrap) */
  1510. #if OPT_MOUSE
  1511.     int    insmode;
  1512. #endif
  1513.     W_VALUES w_vals;
  1514. } W_TRAITS;
  1515.  
  1516. #define global_w_val(which) global_w_values.wv[which].v.i
  1517. #define set_global_w_val(which,val) global_w_val(which) = val
  1518. #define global_w_val_ptr(which) global_w_values.wv[which].v.p
  1519. #define set_global_w_val_ptr(which,val) global_w_val_ptr(which) = val
  1520.  
  1521. #define w_val(wp,val) (wp->w_values.wv[val].vp->i)
  1522. #define set_w_val(wp,which,val) w_val(wp,which) = val
  1523. #define w_val_ptr(wp,val) (wp->w_values.wv[val].vp->p)
  1524. #define set_w_val_ptr(wp,which,val) w_val_ptr(wp,which) = val
  1525.  
  1526. #define make_local_w_val(wp,which)  \
  1527.     make_local_val(wp->w_values.wv, which)
  1528. #define make_global_w_val(wp,which)  \
  1529.     make_global_val(wp->w_values.wv, global_wvalues.wv, which)
  1530.  
  1531. #define is_local_w_val(wp,which)  \
  1532.     is_local_val(wp->w_values.wv,which)
  1533.  
  1534. #if OPT_COLOR
  1535. #define gfcolor global_g_val(GVAL_FCOLOR)
  1536. #define gbcolor global_g_val(GVAL_BCOLOR)
  1537. #else
  1538. #define gfcolor C_WHITE
  1539. #define gbcolor C_BLACK
  1540. #endif
  1541.  
  1542. #if OPT_MAJORMODE
  1543. /*
  1544.  * A majormode is a special set of buffer mode values, together with other
  1545.  * values (such as filename suffixes) which are used to determine when a
  1546.  * majormode should be attached to a buffer.  We allocate the structure in two
  1547.  * levels (MAJORMODE vs MAJORMODE_LIST) to avoid having to adjust pointers
  1548.  * within the VAL arrays (M_VALUES and B_VALUES) when we add or remove new
  1549.  * majormodes.
  1550.  */
  1551. typedef struct {
  1552.     char *name;
  1553.     M_VALUES mm;
  1554.     B_VALUES mb;
  1555. } MAJORMODE;
  1556.  
  1557. #define is_c_mode(bp) (bp->majr != 0 && !strcmp(bp->majr->name, "c"))
  1558. #define fix_cmode(bp,value)    /* nothing */
  1559. #else
  1560. #define is_c_mode(bp) (b_val(bp,MDCMOD))
  1561. #define fix_cmode(bp,value)    make_local_b_val(bp, MDCMOD), \
  1562.                 set_b_val(bp, MDCMOD, value)
  1563. #endif
  1564.  
  1565. /*
  1566.  * Text is kept in buffers. A buffer header, described below, exists for every
  1567.  * buffer in the system. The buffers are kept in a big list, so that commands
  1568.  * that search for a buffer by name can find the buffer header. There is a
  1569.  * safe store for the dot and mark in the header, but this is only valid if
  1570.  * the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
  1571.  * the buffer is kept in a circularly linked list of lines, with a pointer to
  1572.  * the header line in "b_line"    Buffers may be "Inactive" which means the files associated with them
  1573.  * have not been read in yet. These get read in at "use buffer" time.
  1574.  */
  1575.  
  1576. typedef struct    BUFFER {
  1577.     MARK     b_line;        /* Link to the header LINE (offset unused) */
  1578.     struct    BUFFER *b_bufp;     /* Link to next BUFFER        */
  1579.     MARK     *b_nmmarks;        /* named marks a-z        */
  1580. #if OPT_SELECTIONS
  1581.     AREGION    *b_attribs;        /* attributed regions        */
  1582. #endif
  1583. #if OPT_MAJORMODE
  1584.     MAJORMODE *majr;        /* majormode, if any */
  1585. #endif
  1586.     B_VALUES b_values;        /* buffer traits we inherit from */
  1587.                     /*  global values        */
  1588.     W_TRAITS b_wtraits;        /* saved window traits, while we're */
  1589.                     /*  not displayed        */
  1590.     B_COUNT    b_bytecount;        /* # of chars            */
  1591.     L_NUM    b_linecount;        /* no. lines in buffer        */
  1592.     L_NUM    b_lines_on_disk;    /* no. lines as of last read/write */
  1593.     LINEPTR b_udstks[2];        /* undo stack pointers        */
  1594.     MARK     b_uddot[2];        /* Link to "." before undoable op*/
  1595.     short    b_udstkindx;        /* which of above to use    */
  1596.     LINEPTR b_udtail;        /* tail of undo backstack    */
  1597.     LINEPTR b_udlastsep;        /* last stack separator pushed    */
  1598.     int    b_udcount;        /* how many undo's we can do    */
  1599.     LINEPTR    b_LINEs;        /* block-malloced LINE structs */
  1600.     LINEPTR    b_LINEs_end;        /* end of     "    "    " */
  1601.     LINEPTR    b_freeLINEs;        /* list of free "     "    " */
  1602.     UCHAR    *b_ltext;        /* block-malloced text */
  1603.     UCHAR    *b_ltext_end;        /* end of block-malloced text */
  1604.     LINEPTR    b_ulinep;        /* pointer at 'Undo' line    */
  1605.     int    b_active;        /* window activated flag    */
  1606.     UINT    b_nwnd;                /* Count of windows on buffer   */
  1607.     UINT    b_flag;                /* Flags                 */
  1608.     short    b_acount;        /* auto-save count            */
  1609.     char    *b_fname;        /* File name            */
  1610.     int    b_fnlen;        /* length of filename        */
  1611.     char    b_bname[NBUFN];     /* Buffer name            */
  1612. #if    OPT_ENCRYPT
  1613.     char    b_key[NPAT];        /* current encrypted key    */
  1614. #endif
  1615. #ifdef    MDCHK_MODTIME
  1616.     time_t    b_modtime;        /* file's last-modification time */
  1617.     time_t    b_modtime_at_warn;    /* file's modtime when user warned */
  1618. #endif
  1619. #if    OPT_UPBUFF
  1620.     int    (*b_upbuff) (struct BUFFER *bp); /* call to recompute  */
  1621.     int    (*b_rmbuff) (struct BUFFER *bp); /* call on removal    */
  1622. #endif
  1623. #if    OPT_B_LIMITS
  1624.     int    b_lim_left;        /* extra left-margin (cf:show-reg) */
  1625. #endif
  1626.     struct    BUFFER *b_relink;     /* Link to next BUFFER (sorting) */
  1627.     int    b_created;
  1628.     int    b_last_used;
  1629. #if OPT_HILITEMATCH
  1630.     USHORT    b_highlight;
  1631. #endif
  1632. #if OPT_PERL || OPT_TCL
  1633.     void *    b_api_private;        /* pointer to private perl, tcl, etc.
  1634.                                        data */
  1635. #endif
  1636. }    BUFFER;
  1637.  
  1638. /*
  1639.  * Special symbols for scratch-buffer names.
  1640.  */
  1641. #define    SCRTCH_LEFT  "["
  1642. #define    SCRTCH_RIGHT "]"
  1643. #define    SHPIPE_LEFT  "!"
  1644.  
  1645. /* warning:  code in file.c and fileio.c knows how long the shell, pipe, and
  1646.     append prefixes are (e.g. fn += 2 when appending) */
  1647. #define    isShellOrPipe(s)  ((s)[0] == SHPIPE_LEFT[0])
  1648. #define    isInternalName(s) (isShellOrPipe(s) || is_internalname(s))
  1649. #define    isAppendToName(s) ((s)[0] == '>' && (s)[1] == '>')
  1650.  
  1651. /* shift-commands can be repeated when typed on :-command */
  1652. #define isRepeatable(c)   ((c) == '<' || (c) == '>')
  1653.  
  1654. /*
  1655.  * Macros for manipulating buffer-struct members.
  1656.  */
  1657. #define    for_each_buffer(bp) for (bp = bheadp; bp; bp = bp->b_bufp)
  1658.  
  1659. #define global_b_val(which) global_b_values.bv[which].v.i
  1660. #define set_global_b_val(which,val) global_b_val(which) = val
  1661. #define global_b_val_ptr(which) global_b_values.bv[which].v.p
  1662. #define set_global_b_val_ptr(which,val) global_b_val_ptr(which) = val
  1663. #define global_b_val_rexp(which) global_b_values.bv[which].v.r
  1664. #define set_global_b_val_rexp(which,val) global_b_val_rexp(which) = val
  1665.  
  1666. #define b_val(bp,val) (bp->b_values.bv[val].vp->i)
  1667. #define set_b_val(bp,which,val) b_val(bp,which) = val
  1668. #define b_val_ptr(bp,val) (bp->b_values.bv[val].vp->p)
  1669. #define set_b_val_ptr(bp,which,val) b_val_ptr(bp,which) = val
  1670. #define b_val_rexp(bp,val) (bp->b_values.bv[val].vp->r)
  1671. #define set_b_val_rexp(bp,which,val) b_val_rexp(bp,which) = val
  1672.  
  1673. #define window_b_val(wp,val) \
  1674.      ((wp != 0 && wp->w_bufp != 0) \
  1675.          ? b_val(wp->w_bufp,val) \
  1676.         : global_b_val(val))
  1677.  
  1678. #define make_local_b_val(bp,which)  \
  1679.         make_local_val(bp->b_values.bv, which)
  1680. #define make_global_b_val(bp,which)  \
  1681.         make_global_val(bp->b_values.bv, global_b_values.bv, which)
  1682.  
  1683. #define is_local_b_val(bp,which)  \
  1684.     is_local_val(bp->b_values.bv,which)
  1685.  
  1686. #define is_empty_buf(bp) (lforw(buf_head(bp)) == buf_head(bp))
  1687.  
  1688. #define b_dot     b_wtraits.w_dt
  1689. #if WINMARK
  1690. #define b_mark    b_wtraits.w_mk
  1691. #endif
  1692. #define b_lastdot b_wtraits.w_ld
  1693. #define b_tentative_lastdot b_wtraits.w_tld
  1694. #define b_wline   b_wtraits.w_ln
  1695.  
  1696. #if OPT_CASELESS
  1697. #define eql_bname(bp,name) !stricmp(bp->b_bname, name)
  1698. #else
  1699. #define eql_bname(bp,name) !strcmp(bp->b_bname, name)
  1700. #endif
  1701.  
  1702. /* values for b_flag */
  1703. #define BFINVS     iBIT(0)    /* Internal invisible buffer    */
  1704. #define BFCHG      iBIT(1)    /* Changed since last write    */
  1705. #define BFSCRTCH   iBIT(2)    /* scratch -- gone on last close */
  1706. #define BFARGS     iBIT(3)    /* set for ":args" buffers */
  1707. #define BFEXEC     iBIT(4)    /* set for ":source" buffers */
  1708. #define BFIMPLY    iBIT(5)    /* set for implied-# buffers */
  1709. #define BFSIZES    iBIT(6)    /* set if byte/line counts current */
  1710. #define BFUPBUFF   iBIT(7)    /* set if buffer should be updated */
  1711. #define BFRCHG     iBIT(8)    /* Changed since last reset of this flag*/
  1712.  
  1713. /* macros for manipulating b_flag */
  1714. #define b_is_implied(bp)        ((bp)->b_flag & (BFIMPLY))
  1715. #define b_is_argument(bp)       ((bp)->b_flag & (BFARGS))
  1716. #define b_is_changed(bp)        ((bp)->b_flag & (BFCHG))
  1717. #define b_is_recentlychanged(bp) ((bp)->b_flag & (BFRCHG))
  1718. #define b_is_invisible(bp)      ((bp)->b_flag & (BFINVS))
  1719. #define b_is_scratch(bp)        ((bp)->b_flag & (BFSCRTCH))
  1720. #define b_is_temporary(bp)      ((bp)->b_flag & (BFINVS|BFSCRTCH))
  1721. #define b_is_counted(bp)        ((bp)->b_flag & (BFSIZES))
  1722. #define b_is_obsolete(bp)       ((bp)->b_flag & (BFUPBUFF))
  1723.  
  1724. #define b_set_flags(bp,flags)   (bp)->b_flag |= (flags)
  1725. #define b_set_changed(bp)       b_set_flags(bp, BFCHG)
  1726. #define b_set_recentlychanged(bp) b_set_flags(bp, BFRCHG)
  1727. #define b_set_counted(bp)       b_set_flags(bp, BFSIZES)
  1728. #define b_set_invisible(bp)     b_set_flags(bp, BFINVS)
  1729. #define b_set_obsolete(bp)      b_set_flags(bp, BFUPBUFF)
  1730. #define b_set_scratch(bp)       b_set_flags(bp, BFSCRTCH)
  1731.  
  1732. #define b_clr_flags(bp,flags)   (bp)->b_flag &= ~(flags)
  1733. #define b_clr_changed(bp)       b_clr_flags(bp, BFCHG)
  1734. #define b_clr_recentlychanged(bp) b_clr_flags(bp, BFRCHG)
  1735. #define b_clr_counted(bp)       b_clr_flags(bp, BFSIZES)
  1736. #define b_clr_obsolete(bp)      b_clr_flags(bp, BFUPBUFF)
  1737. #define b_clr_scratch(bp)       b_clr_flags(bp, BFSCRTCH)
  1738.  
  1739. #if OPT_HILITEMATCH
  1740. #define b_match_attrs_dirty(bp)    (bp)->b_highlight |= HILITE_DIRTY
  1741. #else
  1742. #define b_match_attrs_dirty(bp)
  1743. #endif
  1744.  
  1745. #if OPT_B_LIMITS
  1746. #define b_left_margin(bp)       bp->b_lim_left
  1747. #define b_set_left_margin(bp,n) b_left_margin(bp) = n
  1748. #else
  1749. #define b_left_margin(bp)       0
  1750. #define b_set_left_margin(bp,n)
  1751. #endif
  1752.  
  1753. #if OPT_HILITEMATCH
  1754. #define HILITE_ON    1
  1755. #define HILITE_DIRTY    2
  1756. #endif
  1757.  
  1758. /* macro for iterating over the marks associated with the current buffer */
  1759.  
  1760. #if OPT_PERL || OPT_TCL
  1761. extern MARK *api_mark_iterator(BUFFER *bp, int *iter);
  1762. #define api_do_mark_iterate_helper(mp, statement)    \
  1763.         {                        \
  1764.         int dmi_iter = 0;                \
  1765.         while ((mp = api_mark_iterator(curbp, &dmi_iter)) != NULL) { \
  1766.         statement                \
  1767.         }                        \
  1768.     }
  1769. #else
  1770. #define api_do_mark_iterate_helper(mp, statement)
  1771. #endif
  1772.  
  1773. #if OPT_VIDEO_ATTRS
  1774. #define do_mark_iterate(mp, statement)            \
  1775.     do {                        \
  1776.     struct MARK *mp;                \
  1777.     int         dmi_idx;                \
  1778.     AREGION     *dmi_ap = curbp->b_attribs;        \
  1779.     if (curbp->b_nmmarks != NULL)            \
  1780.         for (dmi_idx=0; dmi_idx < 26; dmi_idx++) {    \
  1781.         mp = &(curbp->b_nmmarks[dmi_idx]);    \
  1782.         statement                \
  1783.         }                        \
  1784.     if (dmi_ap != NULL) {                \
  1785.         while (dmi_ap != NULL) {            \
  1786.         mp = &dmi_ap->ar_region.r_orig;        \
  1787.         statement                \
  1788.         mp = &dmi_ap->ar_region.r_end;        \
  1789.         statement                \
  1790.         dmi_ap = dmi_ap->ar_next;        \
  1791.         }                        \
  1792.         sel_reassert_ownership(curbp);        \
  1793.     }                        \
  1794.     api_do_mark_iterate_helper(mp, statement)    \
  1795.     } one_time
  1796. #else /* OPT_VIDEO_ATTRS */
  1797. #define do_mark_iterate(mp, statement)            \
  1798.     do {                        \
  1799.     struct MARK *mp;                \
  1800.     if (curbp->b_nmmarks != NULL) {            \
  1801.         int dmi_idx;                \
  1802.         for (dmi_idx=0; dmi_idx < 26; dmi_idx++) {    \
  1803.         mp = &(curbp->b_nmmarks[dmi_idx]);    \
  1804.         statement                \
  1805.         }                        \
  1806.     }                        \
  1807.     api_do_mark_iterate_helper(mp, statement)    \
  1808.     } one_time
  1809. #endif /* OPT_VIDEO_ATTRS */
  1810.  
  1811. /*
  1812.  * There is a window structure allocated for every active display window. The
  1813.  * windows are kept in a big list, in top to bottom screen order, with the
  1814.  * listhead at "wheadp". Each window contains its own values of dot and mark.
  1815.  * The flag field contains some bits that are set by commands to guide
  1816.  * redisplay. Although this is a bit of a compromise in terms of decoupling,
  1817.  * the full blown redisplay is just too expensive to run for every input
  1818.  * character.
  1819.  */
  1820.  
  1821. #define WINDOW    vile_WINDOW        /* avoid conflict with curses.h */
  1822.  
  1823. typedef struct    WINDOW {
  1824.     W_TRAITS w_traits;        /* features of the window we should */
  1825.                     /*  remember between displays */
  1826.     struct    WINDOW *w_wndp;     /* Next window            */
  1827.     BUFFER  *w_bufp;         /* Buffer displayed in window    */
  1828.     int    w_toprow;            /* Origin 0 top row of window   */
  1829.     int    w_ntrows;            /* # of rows of text in window  */
  1830.     int    w_force;             /* If non-zero, forcing row.    */
  1831.     USHORT    w_flag;                /* Flags.                */
  1832.     ULONG    w_split_hist;        /* how to recombine deleted windows */
  1833. #ifdef WMDRULER
  1834.     int    w_ruler_line;
  1835.     int    w_ruler_col;
  1836. #endif
  1837. }    WINDOW;
  1838.  
  1839. #define is_visible_window(wp) ((wp)->w_toprow >= 0)
  1840. #define is_fake_window(wp) (!(is_visible_window(wp)))
  1841.  
  1842. #define    for_each_window(wp) for (wp = wheadp; wp; wp = wp->w_wndp)
  1843. #define for_each_visible_window(wp) \
  1844.         for_each_window(wp) if (is_visible_window(wp))
  1845.  
  1846. #define w_dot     w_traits.w_dt
  1847. #if WINMARK
  1848. #define w_mark    w_traits.w_mk
  1849. #endif
  1850. #define w_lastdot w_traits.w_ld
  1851. #define w_tentative_lastdot w_traits.w_tld
  1852. #define w_line    w_traits.w_ln
  1853. #define w_values  w_traits.w_vals
  1854.  
  1855. #define mode_row(wp)    ((wp)->w_toprow + (wp)->w_ntrows)
  1856. #define    buf_head(bp)    ((bp)->b_line.l)
  1857. #define    win_head(wp)    buf_head((wp)->w_bufp)
  1858.  
  1859. #define DOT curwp->w_dot
  1860. #if OPT_MOUSE
  1861. #define insertmode (curwp->w_traits.insmode)
  1862. #endif /* OPT_MOUSE */
  1863. #if WINMARK
  1864. #define MK curwp->w_mark
  1865. #else
  1866. #define MK Mark
  1867. #endif
  1868.  
  1869.     /* we use left-margin for protecting the prefix-area of [Registers]
  1870.      * from cut/paste selection.
  1871.      */
  1872. #define w_left_margin(wp) b_left_margin(wp->w_bufp)
  1873.  
  1874.     /* tputs uses a 3rd parameter (a function pointer).  We're stuck with
  1875.      * making ttputc and TTputc the same type.
  1876.      */
  1877. #ifdef OUTC_RETURN
  1878. #define OUTC_DCL int
  1879. #define OUTC_RET return
  1880. #else
  1881. #define OUTC_DCL void
  1882. #define OUTC_RET (void)
  1883. #endif
  1884.  
  1885. #ifndef OUTC_ARGS
  1886. #define OUTC_ARGS int c
  1887. #endif
  1888.  
  1889. /*
  1890.  * The editor communicates with the display using a high level interface. A
  1891.  * "TERM" structure holds useful variables, and indirect pointers to routines
  1892.  * that do useful operations. The low level get and put routines are here too.
  1893.  * This lets a terminal, in addition to having non standard commands, have
  1894.  * funny get and put character code too. The calls might get changed to
  1895.  * "termp->t_field" style in the future, to make it possible to run more than
  1896.  * one terminal type.
  1897.  */
  1898. typedef struct    {
  1899.     int    t_mrow;            /* max number of rows allowable */
  1900.     int    t_nrow;         /* current number of rows used    */
  1901.     int    t_mcol;         /* max Number of columns.    */
  1902.     int    t_ncol;         /* current Number of columns.    */
  1903.     int    t_margin;        /* min margin for extended lines*/
  1904.     int    t_scrsiz;        /* size of scroll region "    */
  1905.     int    t_pause;        /* # times thru update to pause */
  1906.     void    (*t_open) (void);    /* Open terminal at the start.    */
  1907.     void    (*t_close) (void);    /* Close terminal at end.    */
  1908.     void    (*t_kopen) (void);    /* Open keyboard        */
  1909.     void    (*t_kclose) (void);    /* close keyboard        */
  1910.     int    (*t_getchar) (void);    /* Get character from keyboard. */
  1911.     OUTC_DCL(*t_putchar) (OUTC_ARGS); /* Put character to display.    */
  1912.     int    (*t_typahead) (void);    /* character ready?        */
  1913.     void    (*t_flush) (void);    /* Flush output buffers.    */
  1914.     void    (*t_move) (int row, int col); /* Move the cursor, origin 0. */
  1915.     void    (*t_eeol) (void);    /* Erase to end of line.    */
  1916.     void    (*t_eeop) (void);    /* Erase to end of page.    */
  1917.     void    (*t_beep) (void);    /* Beep.            */
  1918.     void    (*t_rev) (UINT f);    /* set reverse video state    */
  1919.     int    (*t_rez) (const char *f); /* change screen resolution    */
  1920.     void    (*t_setfor) (int f);    /* set foreground color        */
  1921.     void    (*t_setback) (int b);    /* set background color        */
  1922.     void    (*t_setpal) (const char *p); /* set color palette    */
  1923.     void    (*t_scroll) (int from, int to, int n); /* scroll region    */
  1924.     void    (*t_pflush) (void);    /* really flush         */
  1925.     void    (*t_icursor) (int c);    /* set cursor shape for insertion */
  1926.     void    (*t_title) (char *t);    /* set window title        */
  1927.     int    (*t_watchfd)(int, WATCHTYPE, long *);
  1928.                     /* Watch a file descriptor for
  1929.                        input; execute associated
  1930.                        command when input is present*/
  1931.     void    (*t_unwatchfd)(int, long);
  1932.                     /* Don't watch file descriptor    */
  1933. }    TERM;
  1934.  
  1935. /*    TEMPORARY macros for terminal I/O  (to be placed in a machine
  1936.                         dependent place later)    */
  1937.  
  1938. #define    TTopen        (*term.t_open)
  1939. #define    TTclose        (*term.t_close)
  1940. #define    TTkopen        (*term.t_kopen)
  1941. #define    TTkclose    (*term.t_kclose)
  1942. #define    TTgetc        (*term.t_getchar)
  1943. #define    TTputc        (*term.t_putchar)
  1944. #define    TTtypahead    (*term.t_typahead)
  1945. #define    TTflush        (*term.t_flush)
  1946. #define    TTmove        (*term.t_move)
  1947. #define    TTeeol        (*term.t_eeol)
  1948. #define    TTeeop        (*term.t_eeop)
  1949. #define    TTbeep        (*term.t_beep)
  1950. #define    TTrev        (*term.t_rev)
  1951. #define    TTrez        (*term.t_rez)
  1952. #define    TTforg(f)    (*term.t_setfor)(f)
  1953. #define    TTbacg(b)    (*term.t_setback)(b)
  1954. #define    TTspal(p)    (*term.t_setpal)(p)
  1955. #define    TTscroll(f,t,n)    (*term.t_scroll)(f,t,n)
  1956. #define    TTpflush()    (*term.t_pflush)()
  1957. #define    TTicursor(c)    (*term.t_icursor)(c)
  1958. #define    TTtitle(t)    (*term.t_title)(t)
  1959. #define TTwatchfd(fd,tp,idp) (*term.t_watchfd)(fd,tp,idp)
  1960. #define TTunwatchfd(fd,id) (*term.t_unwatchfd)(fd,id)
  1961.  
  1962. typedef struct  VIDEO {
  1963.         UINT    v_flag;                 /* Flags */
  1964. #if    OPT_COLOR
  1965.     int    v_fcolor;        /* current forground color */
  1966.     int    v_bcolor;        /* current background color */
  1967.     int    v_rfcolor;        /* requested forground color */
  1968.     int    v_rbcolor;        /* requested background color */
  1969. #endif
  1970. #if    OPT_VIDEO_ATTRS
  1971.     VIDEO_ATTR *v_attrs;        /* screen data attributes */
  1972. #endif
  1973.     /* allocate 4 bytes here, and malloc 4 bytes less than we need,
  1974.         to keep malloc from rounding up. */
  1975.         char    v_text[4];              /* Screen data. */
  1976. }       VIDEO;
  1977.  
  1978. #define VideoText(vp) (vp)->v_text
  1979. #define VideoAttr(vp) (vp)->v_attrs
  1980.  
  1981. #if OPT_COLOR
  1982. #define CurFcolor(vp) (vp)->v_fcolor
  1983. #define CurBcolor(vp) (vp)->v_bcolor
  1984. #define ReqFcolor(vp) (vp)->v_rfcolor
  1985. #define ReqBcolor(vp) (vp)->v_rbcolor
  1986. #else
  1987. #define CurFcolor(vp) gfcolor
  1988. #define CurBcolor(vp) gbcolor
  1989. #define ReqFcolor(vp) gfcolor
  1990. #define ReqBcolor(vp) gbcolor
  1991. #endif
  1992.  
  1993. #define VFCHG    iBIT(0)         /* Changed flag            */
  1994. #define    VFEXT    iBIT(1)            /* extended (beyond column 80)    */
  1995. #define    VFREV    iBIT(2)            /* reverse video status        */
  1996. #define    VFREQ    iBIT(3)            /* reverse video request    */
  1997. #define    VFCOL    iBIT(4)            /* color change requested    */
  1998.  
  1999. #if DISP_IBMPC
  2000. /*
  2001.  * these need to go into edef.h eventually!
  2002.  */
  2003. #define    CDCGA    0            /* color graphics card        */
  2004. #define    CDMONO    1            /* monochrome text card        */
  2005. #define    CDEGA    2            /* EGA color adapter        */
  2006. #define    CDVGA    3            /* VGA color adapter        */
  2007. #define    CDSENSE    -1            /* detect the card type        */
  2008.  
  2009. #if OPT_COLOR
  2010. #define    CD_25LINE    CDCGA
  2011. #else
  2012. #define    CD_25LINE    CDMONO
  2013. #endif
  2014.  
  2015. #endif
  2016.  
  2017.  
  2018. /* Commands are represented as CMDFUNC structures, which contain a
  2019.  *    pointer to the actual function, and flags which help to classify it.
  2020.  *    (things like is it a MOTION, can it be UNDOne)
  2021.  *
  2022.  *    These structures are generated automatically from the cmdtbl file,
  2023.  *    and can be found in the file nefunc.h
  2024.  */
  2025. #define CMD_ARGS int f, int n
  2026.  
  2027. typedef    int    (*CmdFunc) (int f, int n);
  2028.  
  2029. typedef    struct {
  2030. #if CC_CANNOT_INIT_UNIONS
  2031.     void    *c_union;
  2032. #define CMD_U_FUNC(p) (CmdFunc)((p)->c_union)
  2033. #define CMD_U_BUFF(p) (BUFFER*)((p)->c_union)
  2034. #define CMD_U_PERL(p) (void  *)((p)->c_union)
  2035. #define INIT_UNION(n) n
  2036. #else    /* C can init unions */
  2037.     union {
  2038.         CmdFunc c_func;
  2039.         BUFFER *c_buff;
  2040. #if OPT_PERL
  2041.         void *c_perl;    /* Perl 5 'AV' type */
  2042. #endif
  2043.     } cu;
  2044.     /* using the union gives us some type-checking and eliminates casts */
  2045. #define CMD_U_FUNC(p) ((p)->cu.c_func)
  2046. #define CMD_U_BUFF(p) ((p)->cu.c_buff)
  2047. #define CMD_U_PERL(p) ((p)->cu.c_perl)
  2048. #define INIT_UNION(n) {n}
  2049. #endif /* CC_CANNOT_INIT_UNIONS */
  2050.     CMDFLAGS c_flags;    /* what sort of command is it? */
  2051. #if OPT_ONLINEHELP
  2052.     const char *c_help;    /* short help message for the command */
  2053. #endif
  2054. }    CMDFUNC;
  2055.  
  2056. /*
  2057.  * Other useful argument templates
  2058.  */
  2059. #define EOL_ARGS  const char * buffer, unsigned cpos, int c, int eolchar
  2060. #define DONE_ARGS int c, char *buf, unsigned *pos
  2061. #define LIST_ARGS int flag, void *ptr
  2062. #define REGN_ARGS void *flagp, int l, int r
  2063.  
  2064. typedef    int    (*OpsFunc) (void);
  2065.  
  2066. /* when referencing a command by name (e.g ":e file") it is looked up in
  2067.  *    the nametbl, which is an array of NTAB structures, containing the
  2068.  *    name, and a pointer to the CMDFUNC structure.  There can be several
  2069.  *    entries pointing at a single CMDFUNC, since a command might have
  2070.  *    several synonymous names.
  2071.  *
  2072.  *    The nametbl array is generated automatically from the cmdtbl file,
  2073.  *    and can be found in the file nename.h
  2074.  */
  2075. typedef struct {
  2076.     char *n_name;
  2077.     const CMDFUNC *n_cmd;
  2078. }    NTAB;
  2079.  
  2080. /*
  2081.  * a binary search tree of the above structure.  we use this so that we can
  2082.  * add in procedures as they are created.
  2083.  */
  2084. typedef struct {
  2085.     const char *bi_key;        /* the name of the command    */
  2086.     const CMDFUNC *n_cmd;        /* command details        */
  2087.     char n_flags;            /* flags (below)        */
  2088. #define    NBST_READONLY    1        /* for builtin functions    */
  2089. #define    NBST_DONE    2        /* temporary flag used by
  2090.                        bind.c:makebindlist()    */
  2091. }    NBST_DATA;
  2092.  
  2093.  
  2094. /* when a command is referenced by bound key (like h,j,k,l, or "dd"), it
  2095.  *    is looked up one of two ways: single character 7-bit ascii commands (by
  2096.  *    far the majority) are simply indexed into an array of CMDFUNC pointers.
  2097.  *    Other commands (those with ^A, ^X, or SPEC prefixes) are searched for
  2098.  *    in a binding table, made up of KBIND structures.  This structure
  2099.  *    contains the command code, and again, a pointer to the CMDFUNC
  2100.  *    structure for the command
  2101.  *
  2102.  *    The asciitbl array, and the kbindtbl array are generated automatically
  2103.  *    from the cmdtbl file, and can be found in the file nebind.h
  2104.  */
  2105. typedef struct  k_bind {
  2106. #if !SYS_WINNT
  2107.     short    k_code;         /* Key code            */
  2108. #else
  2109.     int      k_code;         /* Key code            */
  2110. #endif
  2111.     const CMDFUNC *k_cmd;
  2112. #if OPT_REBIND
  2113.     struct  k_bind *k_link;
  2114. #endif
  2115. }    KBIND;
  2116.  
  2117.  
  2118. /* These are the flags which can appear in the CMDFUNC structure, describing a
  2119.  * command.
  2120.  */
  2121. #define NONE    0L
  2122. #define cmdBIT(n) lBIT(n)    /* ...to simplify typing */
  2123. /* bits 0-11 */
  2124. #define UNDO    cmdBIT(0)    /* command is undo-able, so clean up undo lists */
  2125. #define REDO    cmdBIT(1)    /* command is redo-able, record it for dotcmd */
  2126. #define MOTION  cmdBIT(2)    /* command causes motion, okay after operator cmds */
  2127. #define FL      cmdBIT(3)    /* if command causes motion, opers act on full lines */
  2128. #define ABSM    cmdBIT(4)    /* command causes absolute (i.e. non-relative) motion */
  2129. #define GOAL    cmdBIT(5)    /* column goal should be retained */
  2130. #define GLOBOK  cmdBIT(6)    /* permitted after global command */
  2131. #define OPER    cmdBIT(7)    /* function is an operator, affects a region */
  2132. #define LISTED  cmdBIT(8)    /* internal use only -- used in describing
  2133.                  * bindings to only describe each once */
  2134. #define NOMOVE  cmdBIT(9)    /* dot doesn't move (although address may be used) */
  2135. #define VIEWOK  cmdBIT(10)    /* command is okay in view mode, even though it
  2136.                  * _may_ be undoable (macros and maps) */
  2137. #define RECT    cmdBIT(11)    /* motion causes rectangular operation */
  2138.  
  2139. /* These flags are 'ex' argument descriptors, adapted from elvis.  Not all are
  2140.  * used or honored or implemented.
  2141.  */
  2142. #define argBIT(n) cmdBIT(n+12)    /* ...to simplify adding bits */
  2143. /* bits 12-25 */
  2144. #define FROM    argBIT(0)    /* allow a linespec */
  2145. #define TO      argBIT(1)    /* allow a second linespec */
  2146. #define BANG    argBIT(2)    /* allow a ! after the command name */
  2147. #define EXTRA   argBIT(3)    /* allow extra args after command name */
  2148. #define XFILE   argBIT(4)    /* expand wildcards in extra part */
  2149. #define NOSPC   argBIT(5)    /* no spaces allowed in the extra part */
  2150. #define DFLALL  argBIT(6)    /* default file range is 1,$ */
  2151. #define DFLNONE argBIT(7)    /* no default file range */
  2152. #define NODFL   argBIT(8)    /* do not default to the current file name */
  2153. #define EXRCOK  argBIT(9)    /* can be in a .exrc file */
  2154. #define VI_NL   argBIT(10)    /* if !exmode, then write a newline first */
  2155. #define PLUS    argBIT(11)    /* allow a line number, as in ":e +32 foo" */
  2156. #define ZERO    argBIT(12)    /* allow 0 to be given as a line number */
  2157. #define OPTREG  argBIT(13)    /* allow optional register-name */
  2158. #define FILES   (XFILE | EXTRA)    /* multiple extra files allowed */
  2159. #define WORD1   (EXTRA | NOSPC)    /* one extra word allowed */
  2160. #define FILE1   (FILES | NOSPC)    /* 1 file allowed, defaults to current file */
  2161. #define NAMEDF  (FILE1 | NODFL)    /* 1 file allowed, defaults to "" */
  2162. #define NAMEDFS (FILES | NODFL)    /* multiple files allowed, default is "" */
  2163. #define RANGE   (FROM  | TO)    /* range of linespecs allowed */
  2164.  
  2165. /* these flags determine the type of cu.* */
  2166. #define typBIT(n) cmdBIT(n+26)    /* ...to simplify adding bits */
  2167. /* bits 26-27 */
  2168. #define CMD_FUNC 0L        /* this is the default (CmdFunc) */
  2169. #define CMD_PROC typBIT(0)    /* named procedure (BUFFER *) */
  2170. #define CMD_PERL typBIT(1)    /* perl subroutine (AV *) */
  2171. #define CMD_TYPE (CMD_PROC | CMD_PERL) /* type mask */
  2172.  
  2173. #define SPECIAL_BANG_ARG -42    /* arg passed as 'n' to functions which
  2174.                      were invoked by their "xxx!" name */
  2175.  
  2176. /* definitions for 'mlreply_file()' and other filename-completion */
  2177. #define    FILEC_REREAD   4
  2178. #define    FILEC_READ     3
  2179. #define    FILEC_UNKNOWN  2
  2180. #define    FILEC_WRITE    1
  2181.  
  2182. #define    FILEC_PROMPT   8    /* always prompt (never from screen) */
  2183. #define    FILEC_EXPAND   16    /* allow glob-expansion to multiple files */
  2184.  
  2185. #ifndef P_tmpdir        /* not all systems define this */
  2186. #if SYS_MSDOS || SYS_OS2 || SYS_WINNT
  2187. #define P_tmpdir ""
  2188. #endif
  2189. #if SYS_UNIX
  2190. #define P_tmpdir "/usr/tmp"
  2191. #endif
  2192. #if SYS_VMS
  2193. #define P_tmpdir "sys$scratch:"
  2194. #endif
  2195. #endif    /* P_tmpdir */
  2196.  
  2197. #undef TMPDIR
  2198.  
  2199. #if OPT_EVAL
  2200. #define TMPDIR gtenv("directory")
  2201. #else
  2202. #define TMPDIR P_tmpdir        /* defined in <stdio.h> */
  2203. #endif    /* OPT_EVAL */
  2204.  
  2205. /*    The editor holds deleted text chunks in the KILL registers. The
  2206.     kill registers are logically a stream of ascii characters, however
  2207.     due to unpredictable size, are implemented as a linked
  2208.     list of chunks. (The d_ prefix is for "deleted" text, as k_
  2209.     was taken up by the keycode structure)
  2210. */
  2211.  
  2212. typedef    struct KILL {
  2213.     struct KILL *d_next;    /* link to next chunk, NULL if last */
  2214.     UCHAR d_chunk[KBLOCK];    /* deleted text */
  2215. } KILL;
  2216.  
  2217. typedef struct KILLREG {
  2218.     struct KILL *kbufp;    /* current kill register chunk pointer */
  2219.     struct KILL *kbufh;    /* kill register header pointer    */
  2220.     unsigned kused;        /* # of bytes used in kill last chunk    */
  2221.     C_NUM kbwidth;        /* width of chunk, if rectangle */
  2222.     USHORT kbflag;        /* flags describing kill register    */
  2223. } KILLREG;
  2224.  
  2225. #define    KbSize(i,p)    ((p->d_next != 0) ? KBLOCK : kbs[i].kused)
  2226.  
  2227. /*
  2228.  * Incremental search defines.
  2229.  */
  2230. #if    OPT_ISRCH
  2231.  
  2232. #define    CMDBUFLEN    256    /* Length of our command buffer */
  2233.  
  2234. #define IS_REVERSE    tocntrl('R')    /* Search backward */
  2235. #define    IS_FORWARD    tocntrl('F')    /* Search forward */
  2236.  
  2237. #endif
  2238.  
  2239. #ifndef NULL
  2240. # define NULL 0
  2241. #endif
  2242.  
  2243. /*
  2244.  * General purpose includes
  2245.  */
  2246.  
  2247. #include <stdarg.h>
  2248.  
  2249. #if DISP_X11 && SYS_APOLLO
  2250. #define SYSV_STRINGS    /* <strings.h> conflicts with <string.h> */
  2251. #endif
  2252.  
  2253. #if HAVE_UNISTD_H
  2254. #include <unistd.h>
  2255. #endif
  2256.  
  2257. #if SYS_VMS
  2258. #include <unixio.h>
  2259. #include <unixlib.h>
  2260. #include <file.h>    /* aka <sys/file.h> */
  2261. #endif
  2262.  
  2263. #if HAVE_STDDEF_H
  2264. #include <stddef.h>
  2265. #endif
  2266.  
  2267. #if (HAVE_STDLIB_H || SYS_VMS || CC_NEWDOSCC)
  2268. #include <stdlib.h>
  2269. #else
  2270. extern void exit (int code);
  2271. extern void _exit (int code);
  2272. #endif    /* HAVE_STDLIB_H */
  2273.  
  2274. /* array/table size */
  2275. #define    TABLESIZE(v)    (sizeof(v)/sizeof(v[0]))
  2276.  
  2277. /* Quiet compiler warnings on places where we're being blamed incorrectly,
  2278.  * e.g., for casting away const, or for alignment problems.  It's always
  2279.  * legal to cast a pointer to long w/o loss of precision.
  2280.  */
  2281. #define TYPECAST(type,ptr) (type*)((long)(ptr))
  2282.  
  2283. /* structure-allocate, for linting */
  2284. #ifdef    lint
  2285. #define    castalloc(cast,nbytes)        ((cast *)0)
  2286. #define    castrealloc(cast,ptr,nbytes)    ((ptr)+(nbytes))
  2287. #define    typecalloc(cast)        ((cast *)0)
  2288. #define    typecallocn(cast,ntypes)    (((cast *)0)+(ntypes))
  2289. #define    typealloc(cast)            ((cast *)0)
  2290. #define    typeallocn(cast,ntypes)        (((cast *)0)+(ntypes))
  2291. #define    typereallocn(cast,ptr,ntypes)    ((ptr)+(ntypes))
  2292. #define    typeallocplus(cast,extra)    (((cast *)0)+(extra))
  2293. #else
  2294. #define    castalloc(cast,nbytes)        (cast *)malloc(nbytes)
  2295. #define    castrealloc(cast,ptr,nbytes)    (cast *)realloc((char *)(ptr),(nbytes))
  2296. #define    typecalloc(cast)        (cast *)calloc(sizeof(cast),1)
  2297. #define    typecallocn(cast,ntypes)    (cast *)calloc(sizeof(cast),ntypes)
  2298. #define    typealloc(cast)            (cast *)malloc(sizeof(cast))
  2299. #define    typeallocn(cast,ntypes)        (cast *)malloc((ntypes)*sizeof(cast))
  2300. #define    typereallocn(cast,ptr,ntypes)    (cast *)realloc((char *)(ptr),\
  2301.                             (ntypes)*sizeof(cast))
  2302. #define    typeallocplus(cast,extra)    (cast *)malloc((extra)+sizeof(cast))
  2303. #endif
  2304.  
  2305. #define    FreeAndNull(p)    if ((p) != 0) { free((char *)p); p = 0; }
  2306. #define    FreeIfNeeded(p)    if ((p) != 0) free((char *)(p))
  2307.  
  2308. #if SYS_WINNT && defined(VILE_OLE) && defined(DISP_NTWIN)
  2309. #define ExitProgram(code)   oleauto_exit(code)
  2310. #else
  2311. #define    ExitProgram(code)    exit(code)
  2312. #endif
  2313.  
  2314. /*
  2315.  * We cannot define these in config.h, since they require parameters to be
  2316.  * passed (that's non-portable).
  2317.  */
  2318. #ifdef __cplusplus
  2319. #undef GCC_PRINTF
  2320. #undef GCC_NORETURN
  2321. #undef GCC_UNUSED
  2322. #endif
  2323.  
  2324. #if GCC_PRINTF
  2325. #define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var)))
  2326. #else
  2327. #define GCC_PRINTFLIKE(fmt,var) /*nothing*/
  2328. #endif
  2329.  
  2330. #ifndef    GCC_NORETURN
  2331. #define    GCC_NORETURN /* nothing */
  2332. #endif
  2333.  
  2334. #ifndef    GCC_UNUSED
  2335. #define    GCC_UNUSED /* nothing */
  2336. #endif
  2337.  
  2338. #if HAVE_SELECT
  2339. # if HAVE_SELECT_H
  2340. # include <select.h>
  2341. # endif
  2342. # if HAVE_SYS_SELECT_H
  2343. # include <sys/select.h>
  2344. # endif
  2345. #endif
  2346.  
  2347. #if HAVE_UTIME_H
  2348. # include <utime.h>
  2349. #endif
  2350.  
  2351. #if HAVE_SYS_UTIME_H
  2352. # include <sys/utime.h>
  2353. #endif
  2354.  
  2355. /*
  2356.  * Comparison-function for 'qsort()'
  2357.  */
  2358. #ifndef ANSI_QSORT
  2359. #  if __STDC__ || defined(CC_TURBO) || CC_WATCOM
  2360. #    define    ANSI_QSORT 1
  2361. #  else
  2362. #    define    ANSI_QSORT 0
  2363. #  endif
  2364. #endif
  2365.  
  2366. /*
  2367.  * Debugging/memory-leak testing
  2368.  */
  2369.  
  2370. #ifndef    DOALLOC        /* record info for 'show_alloc()' */
  2371. #define    DOALLOC        0
  2372. #endif
  2373. #ifndef    USE_DBMALLOC    /* test malloc/free/strcpy/memcpy, etc. */
  2374. #define    USE_DBMALLOC    0
  2375. #endif
  2376. #ifndef    USE_DMALLOC    /* test malloc/free/strcpy/memcpy, etc. */
  2377. #define    USE_DMALLOC    0
  2378. #endif
  2379. #ifndef    NO_LEAKS    /* free permanent memory, analyze leaks */
  2380. #define    NO_LEAKS    0
  2381. #endif
  2382. #ifndef TEST_DOS_PIPES
  2383. #define TEST_DOS_PIPES    0
  2384. #endif
  2385.  
  2386. #undef TRACE
  2387.  
  2388. #if USE_DBMALLOC || USE_DMALLOC
  2389. #  undef strchr
  2390. #  undef strrchr
  2391. #  undef memcpy
  2392. #  undef memccpy
  2393. #  undef malloc
  2394. #  undef realloc
  2395. #  undef free
  2396. #  define strmalloc strdup
  2397. #  if USE_DBMALLOC
  2398. #    include <dbmalloc.h>        /* renamed from dbmalloc's convention */
  2399. #    define show_alloc() malloc_dump(fileno(stderr))
  2400. #  endif
  2401. #  if USE_DMALLOC
  2402. #    include <dmalloc.h>
  2403. #    define show_alloc() dmalloc_log_unfreed()
  2404. #  endif
  2405. #  if OPT_TRACE
  2406. #    include "trace.h"
  2407. #  endif
  2408. #else
  2409. #  if NO_LEAKS || DOALLOC || OPT_TRACE
  2410. #    include "trace.h"
  2411. #  endif
  2412. #endif    /* USE_DBMALLOC */
  2413.  
  2414. /* Normally defined in "trace.h" */
  2415. #ifndef TRACE
  2416. #define TRACE(p) /* nothing */
  2417. #endif
  2418.  
  2419. #if DISP_X11 && NEED_X_INCLUDES
  2420. #include    <X11/Intrinsic.h>
  2421. #include    <X11/StringDefs.h>
  2422. #endif
  2423.  
  2424. /*
  2425.  * Local prototypes (must follow NO_LEAKS definition)
  2426.  */
  2427.  
  2428. #if    !CHECK_PROTOTYPES
  2429. #include "neproto.h"
  2430. #include "proto.h"
  2431. #endif
  2432.  
  2433. /*
  2434.  * the list of generic function key bindings
  2435.  */
  2436. #if    !CHECK_PROTOTYPES
  2437. #include "nefkeys.h"
  2438. #endif
  2439.  
  2440. /*    Dynamic RAM tracking and reporting redefinitions    */
  2441. #if    OPT_RAMSIZE
  2442. #undef    realloc
  2443. #define    realloc    reallocate
  2444. #undef    calloc
  2445. #define    calloc(n,m)    allocate((n)*(m))
  2446. #undef    malloc
  2447. #define    malloc    allocate
  2448. #undef    free
  2449. #define    free    release
  2450. #endif
  2451.  
  2452. /* for debugging VMS pathnames on UNIX... */
  2453. #if SYS_UNIX && OPT_VMS_PATH
  2454. #include "fakevms.h"
  2455. #endif
  2456.  
  2457. #endif /* _estruct_h */
  2458.