home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / apps / text_ed / elv16b2 / st / vi.h < prev    next >
C/C++ Source or Header  |  1992-05-13  |  26KB  |  646 lines

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