home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / elvis184.zip / src / vi.h < prev    next >
C/C++ Source or Header  |  1995-05-26  |  27KB  |  684 lines

  1. /* vi.h */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    1500 SW Park $326
  6.  *    Portland, OR 97201
  7.  *    kirkenda@cs.pdx.edu
  8.  */
  9.  
  10. #define VERSION "ELVIS 1.8pl4, by Steve Kirkendall (27 June 1994)"
  11. #define COPYING    "This version of ELVIS is freely redistributable."
  12.  
  13. #include <errno.h>
  14. #if TOS
  15. # ifndef __GNUC__
  16. #  define ENOENT (-AEFILNF)
  17. # endif
  18. #endif
  19.  
  20. #if TOS || VMS
  21. # include <types.h>
  22. # define O_RDONLY    0
  23. # define O_WRONLY    1
  24. # define O_RDWR        2
  25. # ifdef __GNUC__
  26. #  define S_IJDIR    S_IFDIR
  27. # endif
  28. #else
  29. # if OSK
  30. #  include <modes.h>
  31. #  define O_RDONLY    S_IREAD
  32. #  define O_WRONLY    S_IWRITE
  33. #  define O_RDWR    (S_IREAD | S_IWRITE)
  34. #  define ENOENT    E_PNNF
  35. #  define sprintf    Sprintf
  36. # else
  37. #  if !AMIGA
  38. #   include <sys/types.h>
  39. #  endif
  40. #  if COH_286
  41. #   include <sys/fcntl.h>
  42. #  else
  43. #   include <fcntl.h>
  44. #  endif
  45. # endif
  46. #endif
  47.  
  48. #ifndef O_BINARY
  49. # define O_BINARY    0
  50. #endif
  51.  
  52. #include "curses.h"
  53.  
  54. #include <signal.h>
  55. #ifdef __STDC__
  56. # include <stdio.h>    /* for [v]sprintf prototype        */
  57. # include <string.h>    /* for str* prototypes            */
  58. # include <stdlib.h>    /* for atoi, system, malloc, free    */
  59. # include <stdarg.h>    /* for vararg definitions        */
  60. # ifdef NeXT
  61. #  include <libc.h>
  62. # else
  63. #  if ANY_UNIX
  64. #   include <unistd.h>    /* for read, write, ... prototypes      */
  65. #   include <sys/wait.h>/* for wait prototype                   */
  66. #  endif
  67. # endif
  68. #endif
  69.  
  70. #if TURBOC
  71. # include <string.h>
  72. # include <stdarg.h>    /* for vararg definitions        */
  73. #endif
  74.  
  75. /*------------------------------------------------------------------------*/
  76. /* Miscellaneous constants.                          */
  77.  
  78. #define INFINITY    2000000001L    /* a very large integer */
  79. #define LONGKEY        10        /* longest possible raw :map key */
  80. #ifndef MAXRCLEN
  81. # define MAXRCLEN    1000        /* longest possible :@ command */
  82. #endif
  83.  
  84. /*------------------------------------------------------------------------*/
  85. /* These describe how temporary files are divided into blocks             */
  86.  
  87. #define MAXBLKS    (BLKSIZE / sizeof(unsigned short))
  88. typedef union
  89. {
  90.     char        c[BLKSIZE];    /* for text blocks */
  91.     unsigned short    n[MAXBLKS];    /* for the header block */
  92. }
  93.     BLK;
  94.  
  95. /*------------------------------------------------------------------------*/
  96. /* These are used manipulate BLK buffers.                                 */
  97.  
  98. extern BLK    hdr;        /* buffer for the header block */
  99. extern BLK *blkget P_((int));    /* given index into hdr.c[], reads block */
  100. extern BLK *blkadd P_((int));    /* inserts a new block into hdr.c[] */
  101.  
  102. /*------------------------------------------------------------------------*/
  103. /* These are used to keep track of various flags                          */
  104. extern struct _viflags
  105. {
  106.     short    file;        /* file flags */
  107. }
  108.     viflags;
  109.  
  110. /* file flags */
  111. #define NEWFILE        0x0001    /* the file was just created */
  112. #define READONLY    0x0002    /* the file is read-only */
  113. #define HADNUL        0x0004    /* the file contained NUL characters */
  114. #define MODIFIED    0x0008    /* the file has been modified, but not saved */
  115. #define ADDEDNL        0x0010    /* newlines were added to the file */
  116. #define HADBS        0x0020    /* backspace chars were lost from the file */
  117. #define UNDOABLE    0x0040    /* file has been modified */
  118. #define NOTEDITED    0x0080    /* the :file command has been used */
  119.  
  120. /* macros used to set/clear/test flags */
  121. #define setflag(x,y)    viflags.x |= y
  122. #define clrflag(x,y)    viflags.x &= ~y
  123. #define tstflag(x,y)    (viflags.x & y)
  124. #define initflags()    viflags.file = 0;
  125.  
  126. /* The options */
  127. extern char    o_autoindent[1];
  128. extern char    o_autoprint[1];
  129. extern char    o_autotab[1];
  130. extern char    o_autowrite[1];
  131. extern char    o_columns[3];
  132. extern char    o_directory[30];
  133. extern char    o_edcompatible[1];
  134. extern char    o_equalprg[80];
  135. extern char    o_errorbells[1];
  136. extern char    o_exrefresh[1];
  137. extern char    o_ignorecase[1];
  138. extern char    o_keytime[3];
  139. extern char    o_keywordprg[80];
  140. extern char    o_lines[3];
  141. extern char    o_list[1];
  142. extern char    o_number[1];
  143. extern char    o_readonly[1];
  144. extern char    o_remap[1];
  145. extern char    o_report[3];
  146. extern char    o_scroll[3];
  147. extern char    o_shell[60];
  148. extern char    o_shiftwidth[3];
  149. extern char    o_sidescroll[3];
  150. extern char    o_sync[1];
  151. extern char    o_tabstop[3];
  152. extern char    o_term[30];
  153. extern char    o_flash[1];
  154. extern char    o_warn[1];
  155. extern char    o_wrapscan[1];
  156.  
  157. #ifndef CRUNCH
  158. extern char    o_beautify[1];
  159. extern char    o_exrc[1];
  160. extern char    o_mesg[1];
  161. extern char    o_more[1];
  162. extern char    o_nearscroll[3];
  163. extern char    o_newfile[1];
  164. extern char    o_novice[1];
  165. extern char    o_optimize[1];
  166. extern char    o_prompt[1];
  167. extern char    o_taglength[3];
  168. extern char    o_tags[256];
  169. extern char    o_terse[1];
  170. extern char    o_window[3];
  171. extern char    o_wrapmargin[3];
  172. extern char    o_writeany[1];
  173. #endif
  174.  
  175. #ifndef NO_ERRLIST
  176. extern char    o_cc[30];
  177. extern char    o_make[30];
  178. #endif
  179.  
  180. #ifndef NO_CHARATTR
  181. extern char    o_charattr[1];
  182. #endif
  183.  
  184. #ifndef NO_DIGRAPH
  185. extern char    o_digraph[1];
  186. extern char    o_flipcase[80];
  187. #endif
  188.  
  189. #ifndef NO_SENTENCE
  190. extern char    o_hideformat[1];
  191. #endif
  192.  
  193. #ifndef NO_EXTENSIONS
  194. extern char    o_inputmode[1];
  195. extern char    o_keepanon[1];
  196. extern char    o_ruler[1];
  197. #endif
  198.  
  199. #ifndef NO_MAGIC
  200. extern char    o_magic[1];
  201. #endif
  202.  
  203. #ifndef NO_MODELINES
  204. extern char    o_modelines[1];
  205. #endif
  206.  
  207. #ifndef NO_SENTENCE
  208. extern char    o_paragraphs[30];
  209. extern char    o_sections[30];
  210. #endif
  211.  
  212. #if MSDOS
  213. extern char    o_pcbios[1];
  214. extern char    o_controlz[1];
  215. #endif
  216.  
  217. #if OS2
  218. extern char    o_viomode[1];
  219. #endif
  220.  
  221. #ifndef NO_SHOWMATCH
  222. extern char    o_showmatch[1];
  223. #endif
  224.  
  225. #ifndef    NO_SHOWMODE
  226. extern char    o_smd[1];
  227. #endif
  228.  
  229. #ifndef NO_TAGSTACK
  230. extern char    o_tagstack[1];
  231. #endif
  232.  
  233. #ifndef NO_SAFER
  234. extern char    o_safer[1];
  235. #endif
  236.  
  237. #ifdef DEBUG
  238. extern char    o_slowmacro[1];
  239. #endif
  240.  
  241. /*------------------------------------------------------------------------*/
  242. /* These help support the single-line multi-change "undo" -- shift-U      */
  243.  
  244. extern char    U_text[BLKSIZE];
  245. extern long    U_line;
  246.  
  247. /*------------------------------------------------------------------------*/
  248. /* These are used to refer to places in the text               */
  249.  
  250. typedef long    MARK;
  251. #define markline(x)    (long)((x) / BLKSIZE)
  252. #define markidx(x)    (int)((x) & (BLKSIZE - 1))
  253. #define MARK_UNSET    ((MARK)0)
  254. #define MARK_FIRST    ((MARK)BLKSIZE)
  255. #define MARK_LAST    ((MARK)(nlines * BLKSIZE))
  256. #define MARK_EOF    ((MARK)((nlines + 1) * BLKSIZE - 1L))    /* -g.t. */
  257. #define MARK_AT_LINE(x)    ((MARK)(x) * BLKSIZE)
  258.  
  259. #define NMARKS    29
  260. extern MARK    mark[NMARKS];    /* marks a-z, plus mark ' and two temps */
  261. extern MARK    cursor;        /* mark where line is */
  262.  
  263. /*------------------------------------------------------------------------*/
  264. /* These are used to keep track of the current & previous files.      */
  265.  
  266. extern long    origtime;    /* modification date&time of the current file */
  267. extern char    origname[256];    /* name of the current file */
  268. extern char    prevorig[256];    /* name of the preceding file */
  269. extern long    prevline;    /* line number from preceding file */
  270.  
  271. /*------------------------------------------------------------------------*/
  272. /* misc housekeeping variables & functions                  */
  273.  
  274. extern int    tmpfd;                /* fd used to access the tmp file */
  275. extern int    tmpnum;                /* counter used to generate unique filenames */
  276. extern long    lnum[MAXBLKS];            /* last line# of each block */
  277. extern long    nlines;                /* number of lines in the file */
  278. extern char    args[BLKSIZE];            /* file names given on the command line */
  279. extern int    argno;                /* the current element of args[] */
  280. extern int    nargs;                /* number of filenames in args */
  281. extern long    changes;            /* counts changes, to prohibit short-cuts */
  282. extern int    significant;            /* boolean: was a *REAL* change made? */
  283. extern int    exitcode;            /* 0=not updated, 1=overwritten, else error */
  284. extern BLK    tmpblk;                /* a block used to accumulate changes */
  285. extern long    topline;            /* file line number of top line */
  286. extern int    leftcol;            /* column number of left col */
  287. #define        botline     (topline + LINES - 2)
  288. #define        rightcol (leftcol + COLS - (*o_number ? 9 : 1))
  289. extern int    physcol;            /* physical column number that cursor is on */
  290. extern int    physrow;            /* physical row number that cursor is on */
  291. extern int    exwrote;            /* used to detect verbose ex commands */
  292. extern int    doingdot;            /* boolean: are we doing the "." command? */
  293. extern int    doingglobal;            /* boolean: are doing a ":g" command? */
  294. extern long    rptlines;            /* number of lines affected by a command */
  295. extern char    *rptlabel;            /* description of how lines were affected */
  296. extern char    *fetchline P_((long));        /* read a given line from tmp file */
  297. extern char    *parseptrn P_((REG char *));    /* isolate a regexp in a line */
  298. extern MARK    paste P_((MARK, int, int));    /* paste from cut buffer to a given point */
  299. extern char    *wildcard P_((char *));        /* expand wildcards in filenames */
  300. extern MARK    input P_((MARK, MARK, int, int));    /* inserts characters from keyboard */
  301. extern char    *linespec P_((REG char *, MARK *));    /* finds the end of a /regexp/ string */
  302. #define        ctrl(ch) ((ch)&037)
  303. #ifndef NO_RECYCLE
  304. extern long    allocate P_((void));        /* allocate a free block of the tmp file */
  305. #endif
  306. extern SIGTYPE    trapint P_((int));        /* trap handler for SIGINT */
  307. extern SIGTYPE    deathtrap P_((int));        /* trap handler for deadly signals */
  308. extern void    blkdirty P_((BLK *));        /* marks a block as being "dirty" */
  309. extern void    blksync P_((void));        /* forces all "dirty" blocks to disk */
  310. extern void    blkinit P_((void));        /* resets the block cache to "empty" state */
  311. extern void    beep P_((void));        /* rings the terminal's bell */
  312. extern void    exrefresh P_((void));        /* writes text to the screen */
  313. extern void    msg P_((char *, ...));        /* writes a printf-style message to the screen */
  314. extern void    endmsgs P_((void));        /* if "manymsgs" is set, then scroll up 1 line */
  315. extern void    garbage P_((void));        /* reclaims any garbage blocks */
  316. extern void    redraw P_((MARK, int));        /* updates the screen after a change */
  317. extern void    resume_curses P_((int));    /* puts the terminal in "cbreak" mode */
  318. extern void    beforedo P_((int));        /* saves current revision before a new change */
  319. extern void    afterdo P_((void));        /* marks end of a beforedo() change */
  320. extern void    abortdo P_((void));        /* like "afterdo()" followed by "undo()" */
  321. extern int    undo P_((void));        /* restores file to previous undo() */
  322. extern void    dumpkey P_((int, int));        /* lists key mappings to the screen */
  323. extern void    mapkey P_((char *, char *, int, char *));    /* defines a new key mapping */
  324. extern void    redrawrange P_((long, long, long));    /* records clues from modify.c */
  325. #ifndef NO_LEARN
  326. extern void    learnkey P_((char));        /* adds keystroke to learn buffer */
  327. extern char    learn;                /* name of buffer being learned */
  328. #endif
  329. extern void    cut P_((MARK, MARK));        /* saves text in a cut buffer */
  330. extern void    delete P_((MARK, MARK));    /* deletes text */
  331. extern void    add P_((MARK, char *));        /* adds text */
  332. extern void    change P_((MARK, MARK, char *));/* deletes text, and then adds other text */
  333. extern void    cutswitch P_((void));        /* updates cut buffers when we switch files */
  334. extern void    do_digraph P_((int, char []));    /* defines or lists digraphs */
  335. extern void    exstring P_((char *, int, int));/* execute a string as EX commands */
  336. extern void    dumpopts P_((int));        /* display current option settings on the screen */
  337. extern void    setopts P_((char *));        /* assign new values to options */
  338. extern void    saveopts P_((int));        /* save current option values to a given fd */
  339. extern void    savedigs P_((int));        /* save current non-standard digraphs to fd */
  340. extern void    savecolor P_((int));        /* save current color settings (if any) to fd */
  341. extern void    cutname P_((int));        /* select cut buffer for next cut/paste */
  342. extern void    initopts P_((void));        /* initialize options */
  343. extern void    cutend P_((void));        /* free all cut buffers & delete temp files */
  344. extern int    storename P_((char *));        /* stamp temp file with pathname of text file */
  345. extern int    tmpstart P_((char *));        /* load a text file into edit buffer */
  346. extern int    tmpsave P_((char *, int));    /* write edit buffer out to text file */
  347. extern int    tmpend P_((int));        /* call tmpsave(), and then tmpabort */
  348. extern int    tmpabort P_((int));        /* abandon the current edit buffer */
  349. extern void    savemaps P_((int, int));    /* write current :map or :ab commands to fd */
  350. extern int    ansicolor P_((int, int));    /* emit ANSI color command to terminal */
  351. extern int    filter P_((MARK, MARK, char *, int)); /* I/O though another program */
  352. extern int    getkey P_((int));        /* return a keystroke, interpretting maps */
  353. extern int    vgets P_((int, char *, int));    /* read a single line from keyboard */
  354. extern int    doexrc P_((char *));        /* execute a string as a sequence of EX commands */
  355. extern int    cb2str P_((int, char *, unsigned));/* return a string containing cut buffer's contents */
  356. extern int    ansiquit P_((void));        /* neutralize previous ansicolor() call */
  357. extern int    ttyread P_((char *, int, int));    /* read from keyboard with optional timeout */
  358. extern int    tgetent P_((char *, char *));    /* start termcap */
  359. extern int    tgetnum P_((char *));        /* get a termcap number */
  360. extern int    tgetflag P_((char *));        /* get a termcap boolean */
  361. extern int    endcolor P_((void));        /* used during color output */
  362. extern int    getabkey P_((int, char *, int));/* like getkey(), but also does abbreviations */
  363. extern int    idx2col P_((MARK, REG char *, int)); /* returns column# of a given MARK */
  364. extern int    cutneeds P_((BLK *));        /* returns bitmap of blocks needed to hold cutbuffer text */
  365. extern void    execmap P_((int, char *, int));    /* replaces "raw" keys with "mapped" keys */
  366.  
  367. /*------------------------------------------------------------------------*/
  368. /* macros that are used as control structures                             */
  369.  
  370. #define BeforeAfter(before, after) for((before),bavar=1;bavar;(after),bavar=0)
  371. #define ChangeText    BeforeAfter(beforedo(FALSE),afterdo())
  372.  
  373. extern int    bavar;        /* used only in BeforeAfter macros */
  374.  
  375. /*------------------------------------------------------------------------*/
  376. /* These are the movement commands.  Each accepts a mark for the starting */
  377. /* location & number and returns a mark for the destination.          */
  378.  
  379. extern MARK    m_updnto P_((MARK, long, int));        /* k j G */
  380. extern MARK    m_right P_((MARK, long, int, int));    /* h */
  381. extern MARK    m_left P_((MARK, long));        /* l */
  382. extern MARK    m_tocol P_((MARK, long, int));        /* | */
  383. extern MARK    m_front P_((MARK, long));        /* ^ */
  384. extern MARK    m_rear P_((MARK, long));        /* $ */
  385. extern MARK    m_fword P_((MARK, long, int, int));    /* w */
  386. extern MARK    m_bword P_((MARK, long, int));        /* b */
  387. extern MARK    m_eword P_((MARK, long, int));        /* e */
  388. extern MARK    m_paragraph P_((MARK, long, int));    /* { } [[ ]] */
  389. extern MARK    m_match P_((MARK, long));        /* % */
  390. #ifndef NO_SENTENCE
  391. extern MARK    m_sentence P_((MARK, long, int));    /* ( ) */
  392. #endif
  393. extern MARK    m_tomark P_((MARK, long, int));        /* 'm */
  394. #ifndef NO_EXTENSIONS
  395. extern MARK    m_wsrch P_((char *, MARK, int));    /* ^A */
  396. #endif
  397. extern MARK    m_nsrch P_((MARK, long, int));        /* n */
  398. extern MARK    m_fsrch P_((MARK, char *));        /* /regexp */
  399. extern MARK    m_bsrch P_((MARK, char *));        /* ?regexp */
  400. #ifndef NO_CHARSEARCH
  401. extern MARK    m__ch P_((MARK, long, int));        /* ; , */
  402. extern MARK    m_fch P_((MARK, long, int));        /* f */
  403. extern MARK    m_tch P_((MARK, long, int));        /* t */
  404. extern MARK    m_Fch P_((MARK, long, int));        /* F */
  405. extern MARK    m_Tch P_((MARK, long, int));        /* T */
  406. #endif
  407. extern MARK    m_row P_((MARK, long, int));        /* H L M */
  408. extern MARK    m_z P_((MARK, long, int));        /* z */
  409. extern MARK    m_scroll P_((MARK, long, int));        /* ^B ^F ^E ^Y ^U ^D */
  410.  
  411. /* Some stuff that is used by movement functions... */
  412.  
  413. extern MARK    adjmove P_((MARK, REG MARK, int));    /* a helper fn, used by move fns */
  414. extern char    *get_cursor_word P_((MARK));        /* returns word at cursor */
  415.  
  416. /* This macro is used to set the default value of cnt */
  417. #define DEFAULT(val)    if (cnt < 1) cnt = (val)
  418.  
  419. /* These are used to minimize calls to fetchline() */
  420. extern int    plen;    /* length of the line */
  421. extern long    pline;    /* line number that len refers to */
  422. extern long    pchgs;    /* "changes" level that len refers to */
  423. extern char    *ptext;    /* text of previous line, if valid */
  424. extern void    pfetch P_((long));
  425. extern char    digraph P_((int, int));
  426.  
  427. /* This is used to build a MARK that corresponds to a specific point in the
  428.  * line that was most recently pfetch'ed.
  429.  */
  430. #define buildmark(text)    (MARK)(BLKSIZE * pline + (int)((text) - ptext))
  431.  
  432.  
  433. /*------------------------------------------------------------------------*/
  434. /* These are used to handle EX commands.                  */
  435.  
  436. #define CMD_NULL    0    /* NOT A VALID COMMAND */
  437. #define CMD_ABBR    1    /* "define an abbreviation" */
  438. #define CMD_AND        2    /* "logical-AND the test condition with this one" */
  439. #define CMD_APPEND    3    /* "insert lines after this line" */
  440. #define CMD_ARGS    4    /* "show me the args" */
  441. #define CMD_AT        5    /* "execute a cut buffer's contents via EX" */
  442. #define CMD_BANG    6    /* "run a single shell command" */
  443. #define CMD_CC        7    /* "run `cc` and then do CMD_ERRLIST" */
  444. #define CMD_CD        8    /* "change directories" */
  445. #define CMD_CHANGE    9    /* "change some lines" */
  446. #define CMD_COLOR    10    /* "change the default colors" */
  447. #define CMD_COMMENT    11    /* "ignore the rest of this command line" */
  448. #define CMD_COPY    12    /* "copy the selected text to a given place" */
  449. #define CMD_DEBUG    13    /* access to internal data structures */
  450. #define CMD_DELETE    14    /* "delete the selected text" */
  451. #define CMD_DIGRAPH    15    /* "add a digraph, or display them all" */
  452. #define CMD_EDIT    16    /* "switch to a different file" */
  453. #define CMD_ELSE    17    /* "execute these commands if test condition is false */
  454. #define CMD_EQUAL    18    /* "display a line number" */
  455. #define CMD_ERRLIST    19    /* "locate the next error in a list" */
  456. #define CMD_FILE    20    /* "show the file's status" */
  457. #define CMD_GLOBAL    21    /* "globally search & do a command" */
  458. #define CMD_IF        22    /* "set the test condition */
  459. #define CMD_INSERT    23    /* "insert lines before the current line" */
  460. #define CMD_JOIN    24    /* "join the selected line & the one after" */
  461. #define CMD_LIST    25    /* "print lines, making control chars visible" */
  462. #define CMD_MAKE    26    /* "run `make` and then do CMD_ERRLIST" */
  463. #define CMD_MAP        27    /* "adjust the keyboard map" */
  464. #define CMD_MARK    28    /* "mark this line" */
  465. #define CMD_MKEXRC    29    /* "make a .exrc file" */
  466. #define CMD_MOVE    30    /* "move the selected text to a given place" */
  467. #define CMD_NEXT    31    /* "switch to next file in args" */
  468. #define CMD_NUMBER    32    /* "print lines from the file w/ line numbers" */
  469. #define CMD_OR        33    /* "logical-OR the test condition with this one" */
  470. #define CMD_POP        34    /* "pop a position off the tagstack" */
  471. #define CMD_PRESERVE    35    /* "act as though vi crashed" */
  472. #define CMD_PREVIOUS    36    /* "switch to the previous file in args" */
  473. #define CMD_PRINT    37    /* "print the selected text" */
  474. #define CMD_PUT        38    /* "insert any cut lines before this line" */
  475. #define CMD_QUIT    39    /* "quit without writing the file" */
  476. #define CMD_READ    40    /* "append the given file after this line */
  477. #define CMD_RECOVER    41    /* "recover file after vi crashes" - USE -r FLAG */
  478. #define CMD_REWIND    42    /* "rewind to first file" */
  479. #define CMD_SET        43    /* "set a variable's value" */
  480. #define CMD_SHELL    44    /* "run some lines through a command" */
  481. #define CMD_SHIFTL    45    /* "shift lines left" */
  482. #define CMD_SHIFTR    46    /* "shift lines right" */
  483. #define CMD_SOURCE    47    /* "interpret a file's contents as ex commands" */
  484. #define CMD_STOP    48    /* same as CMD_SUSPEND */
  485. #define CMD_SUBAGAIN    49    /* "repeat the previous substitution" */
  486. #define CMD_SUBSTITUTE    50    /* "substitute text in this line" */
  487. #define CMD_SUSPEND    51    /* "suspend the vi session" */
  488. #define CMD_TAG        52    /* "go to a particular tag" */
  489. #define CMD_THEN    53    /* "execute commands if previous test was true" */
  490. #define CMD_TR        54    /* "transliterate chars in the selected lines" */
  491. #define CMD_UNABBR    55    /* "remove an abbreviation definition" */
  492. #define CMD_UNDO    56    /* "undo the previous command" */
  493. #define CMD_UNMAP    57    /* "remove a key sequence map */
  494. #define CMD_VALIDATE    58    /* check for internal consistency */
  495. #define CMD_VERSION    59    /* "describe which version this is" */
  496. #define CMD_VGLOBAL    60    /* "apply a cmd to lines NOT containing an RE" */
  497. #define CMD_VISUAL    61    /* "go into visual mode" */
  498. #define CMD_WQUIT    62    /* "write this file out (any case) & quit" */
  499. #define CMD_WRITE    63    /* "write the selected(?) text to a given file" */
  500. #define CMD_XIT        64    /* "write this file out (if modified) & quit" */
  501. #define CMD_YANK    65    /* "copy the selected text into the cut buffer" */
  502. typedef int CMD;
  503.  
  504. extern void    ex P_((void));
  505. extern void    vi P_((void));
  506. extern int    doexcmd P_((char *, int));
  507.  
  508. extern void    cmd_append P_((MARK, MARK, CMD, int, char *));
  509. extern void    cmd_args P_((MARK, MARK, CMD, int, char *));
  510. #ifndef NO_AT
  511.  extern void    cmd_at P_((MARK, MARK, CMD, int, char *));
  512. #endif
  513. extern void    cmd_cd P_((MARK, MARK, CMD, int, char *));
  514. #ifndef NO_COLOR
  515.  extern void    cmd_color P_((MARK, MARK, CMD, int, char *));
  516. #endif
  517. extern void    cmd_comment P_((MARK, MARK, CMD, int, char *));
  518. extern void    cmd_delete P_((MARK, MARK, CMD, int, char *));
  519. #ifndef NO_DIGRAPH
  520.  extern void    cmd_digraph P_((MARK, MARK, CMD, int, char *));
  521. #endif
  522. extern void    cmd_edit P_((MARK, MARK, CMD, int, char *));
  523. #ifndef NO_ERRLIST
  524.  extern void    cmd_errlist P_((MARK, MARK, CMD, int, char *));
  525. #endif
  526. extern void    cmd_file P_((MARK, MARK, CMD, int, char *));
  527. extern void    cmd_global P_((MARK, MARK, CMD, int, char *));
  528. #ifndef NO_IF
  529. extern void    cmd_if P_((MARK, MARK, CMD, int, char *));
  530. #endif
  531. extern void    cmd_join P_((MARK, MARK, CMD, int, char *));
  532. extern void    cmd_mark P_((MARK, MARK, CMD, int, char *));
  533. #ifndef NO_ERRLIST
  534.  extern void    cmd_make P_((MARK, MARK, CMD, int, char *));
  535. #endif
  536. extern void    cmd_map P_((MARK, MARK, CMD, int, char *));
  537. #ifndef NO_MKEXRC
  538.  extern void    cmd_mkexrc P_((MARK, MARK, CMD, int, char *));
  539. #endif
  540. extern void    cmd_next P_((MARK, MARK, CMD, int, char *));
  541. #ifndef NO_TAGSTACK
  542. extern void    cmd_pop P_((MARK, MARK, CMD, int, char *));
  543. #endif
  544. extern void    cmd_print P_((MARK, MARK, CMD, int, char *));
  545. extern void    cmd_put P_((MARK, MARK, CMD, int, char *));
  546. extern void    cmd_read P_((MARK, MARK, CMD, int, char *));
  547. extern void    cmd_set P_((MARK, MARK, CMD, int, char *));
  548. extern void    cmd_shell P_((MARK, MARK, CMD, int, char *));
  549. extern void    cmd_shift P_((MARK, MARK, CMD, int, char *));
  550. extern void    cmd_source P_((MARK, MARK, CMD, int, char *));
  551. extern void    cmd_substitute P_((MARK, MARK, CMD, int, char *));
  552. extern void    cmd_tag P_((MARK, MARK, CMD, int, char *));
  553. #ifndef NO_IF
  554. extern void    cmd_then P_((MARK, MARK, CMD, int, char *));
  555. #endif
  556. extern void    cmd_undo P_((MARK, MARK, CMD, int, char *));
  557. extern void    cmd_version P_((MARK, MARK, CMD, int, char *));
  558. extern void    cmd_write P_((MARK, MARK, CMD, int, char *));
  559. extern void    cmd_xit P_((MARK, MARK, CMD, int, char *));
  560. extern void    cmd_move P_((MARK, MARK, CMD, int, char *));
  561. #ifdef DEBUG
  562.  extern void    cmd_debug P_((MARK, MARK, CMD, int, char *));
  563.  extern void    cmd_validate P_((MARK, MARK, CMD, int, char *));
  564. #endif
  565. #ifdef SIGTSTP
  566.  extern void    cmd_suspend P_((MARK, MARK, CMD, int, char *));
  567. #endif
  568.  
  569. /*----------------------------------------------------------------------*/
  570. /* These are used to handle VI commands                 */
  571.  
  572. extern MARK    v_1ex P_((MARK, char *));    /* : */
  573. extern MARK    v_mark P_((MARK, long, int));    /* m */
  574. extern MARK    v_quit P_((void));        /* Q */
  575. extern MARK    v_redraw P_((void));        /* ^L ^R */
  576. extern MARK    v_ulcase P_((MARK, long));    /* ~ */
  577. extern MARK    v_undo P_((MARK));        /* u */
  578. extern MARK    v_xchar P_((MARK, long, int));    /* x X */
  579. extern MARK    v_replace P_((MARK, long, int));/* r */
  580. extern MARK    v_overtype P_((MARK));        /* R */
  581. extern MARK    v_selcut P_((MARK, long, int));    /* " */
  582. extern MARK    v_paste P_((MARK, long, int));    /* p P */
  583. extern MARK    v_yank P_((MARK, MARK));    /* y Y */
  584. extern MARK    v_delete P_((MARK, MARK));    /* d D */
  585. extern MARK    v_join P_((MARK, long));    /* J */
  586. extern MARK    v_insert P_((MARK, long, int));    /* a A i I o O */
  587. extern MARK    v_change P_((MARK, MARK));    /* c C */
  588. extern MARK    v_subst P_((MARK, long));    /* s */
  589. extern MARK    v_lshift P_((MARK, MARK));    /* < */
  590. extern MARK    v_rshift P_((MARK, MARK));    /* > */
  591. extern MARK    v_reformat P_((MARK, MARK));    /* = */
  592. extern MARK    v_filter P_((MARK, MARK));    /* ! */
  593. extern MARK    v_status P_((void));        /* ^G */
  594. extern MARK    v_switch P_((void));        /* ^^ */
  595. extern MARK    v_tag P_((char *, MARK, long));    /* ^] */
  596. extern MARK    v_xit P_((MARK, long, int));    /* ZZ */
  597. extern MARK    v_undoline P_((MARK));        /* U */
  598. extern MARK    v_again P_((MARK, MARK));    /* & */
  599. #ifndef NO_EXTENSIONS
  600. extern MARK    v_keyword P_((char *, MARK, long));    /* K */
  601. extern MARK    v_increment P_((char *, MARK, long));    /* # */
  602. #endif
  603. #ifndef NO_ERRLIST
  604. extern MARK    v_errlist P_((MARK));        /* * */
  605. #endif
  606. #ifndef NO_AT
  607. extern MARK    v_at P_((MARK, long, int));    /* @ */
  608. #endif
  609. #ifdef SIGTSTP
  610. extern MARK    v_suspend P_((void));        /* ^Z */
  611. #endif
  612. #ifndef NO_POPUP
  613. extern MARK    v_popup P_((MARK, MARK));    /* \ */
  614. #endif
  615. #ifndef NO_TAGSTACK
  616. extern MARK    v_pop P_((MARK, long, int));    /* ^T */
  617. #endif
  618.  
  619. /*----------------------------------------------------------------------*/
  620. /* These flags describe the quirks of the individual visual commands */
  621. #define NO_FLAGS    0x00
  622. #define    MVMT        0x01    /* this is a movement command */
  623. #define PTMV        0x02    /* this can be *part* of a movement command */
  624. #define FRNT        0x04    /* after move, go to front of line */
  625. #define INCL        0x08    /* include last char when used with c/d/y */
  626. #define LNMD        0x10    /* use line mode of c/d/y */
  627. #define NCOL        0x20    /* this command can't change the column# */
  628. #define NREL        0x40    /* this is "non-relative" -- set the '' mark */
  629. #define SDOT        0x80    /* set the "dot" variables, for the "." cmd */
  630. #define FINL        0x100    /* final testing, more strict! */
  631. #define NWRP        0x200    /* no line-wrap (used for 'w' and 'W') */
  632. #define INPM        0x400    /* input mode -- cursor can be after EOL */
  633. #ifndef NO_VISIBLE
  634. # define VIZ        0x800    /* commands which can be used with 'v' */
  635. #else
  636. # define VIZ        0
  637. #endif
  638.  
  639. /* This variable is zeroed before a command executes, and later ORed with the
  640.  * command's flags after the command has been executed.  It is used to force
  641.  * certain flags to be TRUE for *some* invocations of a particular command.
  642.  * For example, "/regexp/+offset" forces the LNMD flag, and sometimes a "p"
  643.  * or "P" command will force FRNT.
  644.  */
  645. extern int    force_flags;
  646.  
  647. /*----------------------------------------------------------------------*/
  648. /* These describe what mode we're in */
  649.  
  650. #define MODE_EX        1    /* executing ex commands */
  651. #define    MODE_VI        2    /* executing vi commands */
  652. #define    MODE_COLON    3    /* executing an ex command from vi mode */
  653. #define    MODE_QUIT    4
  654. extern int    mode;
  655.  
  656. #define WHEN_VICMD    1    /* getkey: we're reading a VI command */
  657. #define WHEN_VIINP    2    /* getkey: we're in VI's INPUT mode */
  658. #define WHEN_VIREP    4    /* getkey: we're in VI's REPLACE mode */
  659. #define WHEN_EX        8    /* getkey: we're in EX mode */
  660. #define WHEN_MSG    16    /* getkey: we're at a "more" prompt */
  661. #define WHEN_POPUP    32    /* getkey: we're in the pop-up menu */
  662. #define WHEN_REP1    64    /* getkey: we're getting a single char for 'r' */
  663. #define WHEN_CUT    128    /* getkey: we're getting a cut buffer name */
  664. #define WHEN_MARK    256    /* getkey: we're getting a mark name */
  665. #define WHEN_CHAR    512    /* getkey: we're getting a destination for f/F/t/T */
  666. #define WHEN_INMV    4096    /* in input mode, interpret the key in VICMD mode */
  667. #define WHEN_FREE    8192    /* free the keymap after doing it once */
  668. #define WHENMASK    (WHEN_VICMD|WHEN_VIINP|WHEN_VIREP|WHEN_REP1|WHEN_CUT|WHEN_MARK|WHEN_CHAR)
  669.  
  670. #ifndef NO_VISIBLE
  671. extern MARK    V_from;
  672. extern int    V_linemd;
  673. extern MARK v_start P_((MARK m, long cnt, int cmd));
  674. #endif
  675.  
  676. #ifdef DEBUG
  677. # define malloc(size)    dbmalloc(size, __FILE__, __LINE__)
  678. # define free(ptr)    dbfree(ptr, __FILE__, __LINE__)
  679. # define checkmem()    dbcheckmem(__FILE__, __LINE__)
  680. extern char    *dbmalloc P_((int, char *, int));
  681. #else
  682. # define checkmem()
  683. #endif
  684.