home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1710 / vi.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  14.7 KB  |  426 lines

  1. /* vi.h */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    16820 SW Tallac Way
  6.  *    Beaverton, OR 97006
  7.  *    kirkenda@jove.cs.pdx.edu, or ...uunet!tektronix!psueea!jove!kirkenda
  8.  */
  9.  
  10.  
  11. /* This is the header file for my version of vi. */
  12.  
  13. #define VERSION "ELVIS 1.3, by Steve Kirkendall"
  14. #define COPYING    "This version of ELVIS is freely redistributable."
  15.  
  16. #include <errno.h>
  17. extern int errno;
  18. #if TOS
  19. #define ENOENT (-AEFILNF)
  20. #endif
  21.  
  22. #if TOS
  23. # include <types.h>
  24. # define O_RDONLY    0
  25. # define O_WRONLY    1
  26. # define O_RDWR        2
  27. #else
  28. # include <sys/types.h>
  29. # include <fcntl.h>
  30. #endif
  31.  
  32. #ifndef O_BINARY
  33. # define O_BINARY    0
  34. #endif
  35.  
  36. #include "curses.h"
  37.  
  38. /*------------------------------------------------------------------------*/
  39. /* Miscellaneous constants.                          */
  40.  
  41. #define INFINITY    2000000001L    /* a very large integer */
  42. #if MSDOS
  43. # define MAXMAPS    50        /* then we have lots of specials */
  44. #else
  45. # define MAXMAPS    20        /* number of :map keys */
  46. #endif
  47. #define LONGKEY        10        /* longest possible raw :map key */
  48. #define MAXDIGS        30        /* number of :digraph combos */
  49. #define MAXRCLEN    1000        /* longest possible .exrc file */
  50.  
  51. /*------------------------------------------------------------------------*/
  52. /* These describe how temporary files are divided into blocks             */
  53.  
  54. #define BLKSIZE    1024        /* size of blocks */
  55. #define MAXBLKS    (BLKSIZE / sizeof(unsigned short))
  56. typedef union
  57. {
  58.     char        c[BLKSIZE];    /* for text blocks */
  59.     unsigned short    n[MAXBLKS];    /* for the header block */
  60. }
  61.     BLK;
  62.  
  63. /*------------------------------------------------------------------------*/
  64. /* These are used manipulate BLK buffers.                                 */
  65.  
  66. extern BLK    hdr;        /* buffer for the header block */
  67. extern BLK    blkbuf[2];    /* buffers for text blocks */
  68. extern BLK    *blkget();    /* given index into hdr.c[], reads block */
  69. extern BLK    *blkadd();    /* inserts a new block into hdr.c[] */
  70.  
  71. /*------------------------------------------------------------------------*/
  72. /* These are used to keep track of various flags                          */
  73. extern struct _viflags
  74. {
  75.     short    file;        /* file flags */
  76. }
  77.     viflags;
  78.  
  79. /* file flags */
  80. #define NEWFILE        0x0001    /* the file was just created */
  81. #define READONLY    0x0002    /* the file is read-only */
  82. #define HADNUL        0x0004    /* the file contained NUL characters */
  83. #define MODIFIED    0x0008    /* the file has been modified */
  84. #define NOFILE        0x0010    /* no name is known for the current text */
  85. #define ADDEDNL        0x0020    /* newlines were added to the file */
  86.  
  87. /* macros used to set/clear/test flags */
  88. #define setflag(x,y)    viflags.x |= y
  89. #define clrflag(x,y)    viflags.x &= ~y
  90. #define tstflag(x,y)    (viflags.x & y)
  91. #define initflags()    viflags.file = 0;
  92.  
  93. /* The options */
  94. extern char    o_autoindent[1];
  95. extern char    o_autowrite[1];
  96. #ifndef NO_CHARATTR
  97. extern char    o_charattr[1];
  98. #endif
  99. extern char    o_columns[3];
  100. extern char    o_directory[30];
  101. extern char    o_errorbells[1];
  102. extern char    o_exrefresh[1];
  103. #ifndef NO_SENTENCE
  104. extern char    o_hideformat[1];
  105. #endif
  106. extern char    o_ignorecase[1];
  107. #ifndef NO_EXTENSIONS
  108. extern char    o_inputmode[1];
  109. #endif
  110. extern char    o_keytime[3];
  111. extern char    o_keywordprg[80];
  112. extern char    o_lines[3];
  113. extern char    o_list[1];
  114. #ifndef NO_MAGIC
  115. extern char    o_magic[1];
  116. #endif
  117. #ifndef NO_SENTENCE
  118. extern char    o_paragraphs[30];
  119. #endif
  120. #if MSDOS
  121. extern char    o_pcbios[1];
  122. #endif
  123. extern char    o_readonly[1];
  124. extern char    o_report[3];
  125. extern char    o_scroll[3];
  126. #ifndef NO_SENTENCE
  127. extern char    o_sections[30];
  128. #endif
  129. extern char    o_shell[60];
  130. extern char    o_showmode[1];
  131. extern char    o_shiftwidth[3];
  132. extern char    o_sidescroll[3];
  133. extern char    o_sync[1];
  134. extern char    o_tabstop[3];
  135. extern char    o_term[30];
  136. extern char    o_vbell[1];
  137. extern char    o_warn[1];
  138. extern char    o_wrapmargin[3];
  139. extern char    o_wrapscan[1];
  140.  
  141. /*------------------------------------------------------------------------*/
  142. /* These help support the single-line multi-change "undo" -- shift-U      */
  143.  
  144. extern char    U_text[BLKSIZE];
  145. extern long    U_line;
  146.  
  147. /*------------------------------------------------------------------------*/
  148. /* These are used to refer to places in the text               */
  149.  
  150. typedef long    MARK;
  151. #define markline(x)    (long)((x) / BLKSIZE)
  152. #define markidx(x)    (int)((x) & (BLKSIZE - 1))
  153. #define MARK_UNSET    ((MARK)0)
  154. #define MARK_FIRST    ((MARK)BLKSIZE)
  155. #define MARK_LAST    ((MARK)(nlines * BLKSIZE))
  156. #define MARK_AT_LINE(x)    ((MARK)((x) * BLKSIZE))
  157.  
  158. #define NMARKS    28
  159. extern MARK    mark[NMARKS];    /* marks 'a through 'z, plus mark '' */
  160. extern MARK    cursor;        /* mark where line is */
  161.  
  162. /*------------------------------------------------------------------------*/
  163. /* These are used to keep track of the current & previous files.      */
  164.  
  165. extern long    origtime;    /* modification date&time of the current file */
  166. extern char    origname[256];    /* name of the current file */
  167. extern char    prevorig[256];    /* name of the preceding file */
  168. extern long    prevline;    /* line number from preceding file */
  169.  
  170. /*------------------------------------------------------------------------*/
  171. /* misc housekeeping variables & functions                  */
  172.  
  173. extern int    tmpfd;        /* fd used to access the tmp file */
  174. extern long    lnum[MAXBLKS];    /* last line# of each block */
  175. extern long    nlines;        /* number of lines in the file */
  176. extern char    args[BLKSIZE];    /* file names given on the command line */
  177. extern int    argno;        /* the current element of args[] */
  178. extern int    nargs;        /* number of filenames in args */
  179. extern long    changes;    /* counts changes, to prohibit short-cuts */
  180. extern int    mustredraw;    /* boolean: force total redraw of screen? */
  181. extern long    redrawafter;    /* line# of first line to redraw */
  182. extern long    preredraw;    /* line# of last line changed, before change */
  183. extern long    postredraw;    /* line# of last line changed, after change */
  184. extern BLK    tmpblk;        /* a block used to accumulate changes */
  185. extern long    topline;    /* file line number of top line */
  186. extern int    leftcol;    /* column number of left col */
  187. #define        botline     (topline + LINES - 2)
  188. #define        rightcol (leftcol + COLS - 1)
  189. extern int    physcol;    /* physical column number that cursor is on */
  190. extern int    physrow;    /* physical row number that cursor is on */
  191. extern int    exwrote;    /* used to detect verbose ex commands */
  192. extern int    doingdot;    /* boolean: are we doing the "." command? */
  193. extern long    rptlines;    /* number of lines affected by a command */
  194. extern char    *rptlabel;    /* description of how lines were affected */
  195. extern char    *fetchline();    /* read a given line from tmp file */
  196. extern char    *parseptrn();    /* isolate a regexp in a line */
  197. extern MARK    paste();    /* paste from cut buffer to a given point */
  198. extern char    *wildcard();    /* expand wildcards in filenames */
  199. extern MARK    input();    /* inserts characters from keyboard */
  200. extern char    *linespec();    /* finds the end of a /regexp/ string */
  201. #define        ctrl(ch) ((ch)&037)
  202. #ifndef NO_RECYCLE
  203. extern long    allocate();    /* allocate a free block of the tmp file */
  204. #endif
  205. extern int    trapint();    /* trap handler for SIGINT */
  206.  
  207. /*------------------------------------------------------------------------*/
  208. /* macros that are used as control structures                             */
  209.  
  210. #define BeforeAfter(before, after) for((before),bavar=1;bavar;(after),bavar=0)
  211. #define ChangeText    BeforeAfter(beforedo(FALSE),afterdo())
  212.  
  213. extern int    bavar;        /* used only in BeforeAfter macros */
  214.  
  215. /*------------------------------------------------------------------------*/
  216. /* These are the movement commands.  Each accepts a mark for the starting */
  217. /* location & number and returns a mark for the destination.          */
  218.  
  219. extern MARK    m_up();            /* k */
  220. extern MARK    m_down();        /* j */
  221. extern MARK    m_right();        /* h */
  222. extern MARK    m_left();        /* l */
  223. extern MARK    m_toline();        /* G */
  224. extern MARK    m_tocol();        /* | */
  225. extern MARK    m_front();        /* ^ */
  226. extern MARK    m_rear();        /* $ */
  227. extern MARK    m_fword();        /* w */
  228. extern MARK    m_bword();        /* b */
  229. extern MARK    m_eword();        /* e */
  230. extern MARK    m_fWord();        /* W */
  231. extern MARK    m_bWord();        /* B */
  232. extern MARK    m_eWord();        /* E */
  233. extern MARK    m_fparagraph();    /* } */
  234. extern MARK    m_bparagraph();    /* { */
  235. extern MARK    m_fsection();        /* ]] */
  236. extern MARK    m_bsection();        /* [[ */
  237. extern MARK    m_match();        /* % */
  238. #ifndef NO_SENTENCE
  239. extern MARK    m_fsentence();    /* ) */
  240. extern MARK    m_bsentence();    /* ( */
  241. #endif
  242. extern MARK    m_tomark();        /* 'm */
  243. extern MARK    m_nsrch();        /* n */
  244. extern MARK    m_Nsrch();        /* N */
  245. extern MARK    m_fsrch();        /* /regexp */
  246. extern MARK    m_bsrch();        /* ?regexp */
  247. extern MARK    m__ch();        /* ; , */
  248. extern MARK    m_fch();        /* f */
  249. extern MARK    m_tch();        /* t */
  250. extern MARK    m_Fch();        /* F */
  251. extern MARK    m_Tch();        /* T */
  252. extern MARK    m_row();        /* H L M */
  253. extern MARK    m_z();        /* z */
  254. extern MARK    m_scroll();        /* ^B ^F ^E ^Y ^U ^D */
  255.  
  256. /* Some stuff that is used by movement functions... */
  257.  
  258. extern MARK    adjmove();        /* a helper fn, used by move fns */
  259.  
  260. /* This macro is used to set the default value of cnt */
  261. #define DEFAULT(val)    if (cnt < 1) cnt = (val)
  262.  
  263. /* These are used to minimize calls to fetchline() */
  264. extern int    plen;    /* length of the line */
  265. extern long    pline;    /* line number that len refers to */
  266. extern long    pchgs;    /* "changes" level that len refers to */
  267. extern char    *ptext;    /* text of previous line, if valid */
  268. extern void    pfetch();
  269.  
  270. /* This is used to build a MARK that corresponds to a specific point in the
  271.  * line that was most recently pfetch'ed.
  272.  */
  273. #define buildmark(text)    (MARK)(BLKSIZE * pline + (int)((text) - ptext))
  274.  
  275.  
  276. /*------------------------------------------------------------------------*/
  277. /* These are used to handle EX commands.                  */
  278.  
  279. #define  CMD_NULL    0    /* NOT A VALID COMMAND */
  280. #define  CMD_ABBR    1    /* "define an abbreviation" */
  281. #define  CMD_ARGS    2    /* "show me the args" */
  282. #define  CMD_APPEND    3    /* "insert lines after this line" */
  283. #define  CMD_BANG    4    /* "run a single shell command" */
  284. #define  CMD_COPY    5    /* "copy the selected text to a given place" */
  285. #define  CMD_CD        6    /* "change directories" */
  286. #define  CMD_CHANGE    7    /* "change some lines" */
  287. #define  CMD_DELETE    8    /* "delete the selected text" */
  288. #define  CMD_DIGRAPH    9    /* "add a digraph, or display them all" */
  289. #define  CMD_EDIT    10    /* "switch to a different file" */
  290. #define  CMD_FILE    11    /* "show the file's status" */
  291. #define  CMD_GLOBAL    12    /* "globally search & do a command" */
  292. #define  CMD_INSERT    13    /* "insert lines before the current line" */
  293. #define  CMD_JOIN    14    /* "join the selected line & the one after" */
  294. #define  CMD_LIST    15    /* "print lines, making control chars visible" */
  295. #define  CMD_MAP    16    /* "adjust the keyboard map" */
  296. #define  CMD_MARK    17    /* "mark this line" */
  297. #define  CMD_MKEXRC    18    /* "make a .exrc file" */
  298. #define  CMD_MOVE    19    /* "move the selected text to a given place" */
  299. #define  CMD_NEXT    20    /* "switch to next file in args" */
  300. #define  CMD_PRESERVE    21    /* "act as though vi crashed" */
  301. #define  CMD_PREVIOUS    22    /* "switch to the previous file in args" */
  302. #define  CMD_PRINT    23    /* "print the selected text" */
  303. #define  CMD_PUT    24    /* "insert any cut lines before this line" */
  304. #define  CMD_QUIT    25    /* "quit without writing the file" */
  305. #define  CMD_READ    26    /* "append the given file after this line */
  306. #define  CMD_RECOVER    27    /* "recover file after vi crashes" - USE -r FLAG */
  307. #define  CMD_REWIND    28    /* "rewind to first file" */
  308. #define  CMD_SET    29    /* "set a variable's value" */
  309. #define  CMD_SHELL    30    /* "run some lines through a command" */
  310. #define  CMD_SHIFTL    31    /* "shift lines left" */
  311. #define  CMD_SHIFTR    32    /* "shift lines right" */
  312. #define  CMD_SOURCE    33    /* "interpret a file's contents as ex commands" */
  313. #define  CMD_STOP    34    /* same as CMD_SUSPEND */
  314. #define  CMD_SUSPEND    35    /* "suspend the vi session" */
  315. #define  CMD_SUBSTITUTE    36    /* "substitute text in this line" */
  316. #define  CMD_TR        37    /* "transliterate chars in the selected lines" */
  317. #define  CMD_TAG    38    /* "go to a particular tag" */
  318. #define  CMD_UNABBR    39    /* "remove an abbreviation definition" */
  319. #define  CMD_UNDO    40    /* "undo the previous command" */
  320. #define  CMD_UNMAP    41    /* "remove a key sequence map */
  321. #define  CMD_VERSION    42    /* "describe which version this is" */
  322. #define  CMD_VGLOBAL    43    /* "apply a cmd to lines NOT containing an RE" */
  323. #define  CMD_VISUAL    44    /* "go into visual mode" */
  324. #define  CMD_WQUIT    45    /* "write this file out (any case) & quit" */
  325. #define  CMD_WRITE    46    /* "write the selected(?) text to a given file" */
  326. #define  CMD_XIT    47    /* "write this file out (if modified) & quit" */
  327. #define  CMD_YANK    48    /* "copy the selected text into the cut buffer" */
  328. #ifdef DEBUG
  329. # define CMD_DEBUG    49    /* access to internal data structures */
  330. # define CMD_VALIDATE    50    /* check for internal consistency */
  331. #endif
  332. typedef int CMD;
  333.  
  334. extern        ex();
  335. extern        vi();
  336. extern        doexcmd();
  337.  
  338. extern void    cmd_append();
  339. extern void    cmd_args();
  340. extern void    cmd_cd();
  341. extern void    cmd_delete();
  342. #ifndef NO_DIGRAPH
  343. extern void    cmd_digraph();
  344. #endif
  345. extern void    cmd_edit();
  346. extern void    cmd_file();
  347. extern void    cmd_global();
  348. extern void    cmd_join();
  349. extern void    cmd_mark();
  350. extern void    cmd_list();
  351. extern void    cmd_map();
  352. #ifndef NO_EXTENSIONS
  353. extern void    cmd_mkexrc();
  354. #endif
  355. extern void    cmd_next();
  356. extern void    cmd_print();
  357. extern void    cmd_put();
  358. extern void    cmd_quit();
  359. extern void    cmd_read();
  360. extern void    cmd_rewind();
  361. extern void    cmd_set();
  362. extern void    cmd_shell();
  363. extern void    cmd_shift();
  364. extern void    cmd_source();
  365. extern void    cmd_substitute();
  366. extern void    cmd_tag();
  367. extern void    cmd_undo();
  368. extern void    cmd_version();
  369. extern void    cmd_visual();
  370. extern void    cmd_write();
  371. extern void    cmd_xit();
  372. extern void    cmd_move();
  373. #ifdef DEBUG
  374. extern void    cmd_debug();
  375. extern void    cmd_validate();
  376. #endif
  377.  
  378. /*----------------------------------------------------------------------*/
  379. /* These are used to handle VI commands                 */
  380.  
  381. extern MARK    v_1ex();    /* : */
  382. extern MARK    v_mark();    /* m */
  383. extern MARK    v_quit();    /* Q */
  384. extern MARK    v_redraw();    /* ^L ^R */
  385. extern MARK    v_ulcase();    /* ~ */
  386. extern MARK    v_undo();    /* u */
  387. extern MARK    v_xchar();    /* x */
  388. extern MARK    v_Xchar();    /* X */
  389. extern MARK    v_replace();    /* r */
  390. extern MARK    v_overtype();    /* R */
  391. extern MARK    v_selcut();    /* " */
  392. extern MARK    v_paste();    /* p P */
  393. extern MARK    v_yank();    /* y Y */
  394. extern MARK    v_delete();    /* d D */
  395. extern MARK    v_join();    /* J */
  396. extern MARK    v_insert();    /* a A i I o O */
  397. extern MARK    v_change();    /* c C */
  398. extern MARK    v_subst();    /* s */
  399. extern MARK    v_lshift();    /* < */
  400. extern MARK    v_rshift();    /* > */
  401. extern MARK    v_filter();    /* ! */
  402. extern MARK    v_status();    /* ^G */
  403. extern MARK    v_switch();    /* ^^ */
  404. extern MARK    v_tag();    /* ^] */
  405. #ifndef NO_EXTENSIONS
  406. extern MARK    v_keyword();    /* ^K */
  407. extern MARK    v_increment();    /* * */
  408. #endif
  409. extern MARK    v_xit();    /* ZZ */
  410. extern MARK    v_undoline();    /* U */
  411.  
  412. /*----------------------------------------------------------------------*/
  413. /* These describe what mode we're in */
  414.  
  415. #define MODE_EX        1    /* executing ex commands */
  416. #define    MODE_VI        2    /* executing vi commands */
  417. #define    MODE_COLON    3    /* executing an ex command from vi mode */
  418. #define    MODE_QUIT    4
  419. extern int    mode;
  420.  
  421. #define WHEN_VICMD    1    /* getkey: we're reading a VI command */
  422. #define WHEN_VIINP    2    /* getkey: we're in VI's INPUT mode */
  423. #define WHEN_VIREP    4    /* getkey: we're in VI's REPLACE mode */
  424. #define WHEN_EX        8    /* getkey: we're in EX mode */
  425. #define WHEN_INMV    256    /* in input mode, interpret the key in VICMD mode */
  426.