home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / d / elvis / Source / h / vi < prev   
Encoding:
Text File  |  1990-03-26  |  14.4 KB  |  423 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. #define ARC    /* Archimedes Port */
  11.  
  12. /* This is the header file for my version of vi. */
  13.  
  14. #define VERSION "ELVIS version 1.0, by Steve Kirkendall"
  15. #define COPYING    "This version of ELVIS is freely redistributable."
  16.  
  17. #include <errno.h>
  18.  
  19. #ifndef ARC
  20. extern int errno
  21. #else
  22. #define bsd 0
  23. #define M_SYSV 0
  24. #define ENOENT 2
  25. #endif /* ARC */
  26.  
  27. #include "curses.h"
  28.  
  29. #if M_SYSV || bsd
  30. # include <fcntl.h>
  31. #else
  32. # define O_RDONLY    0
  33. # define O_WRONLY    1
  34. # define O_RDWR        2
  35. #endif
  36.  
  37. #ifndef O_BINARY
  38. # define O_BINARY    0
  39. #endif
  40.  
  41. /*------------------------------------------------------------------------*/
  42. /* File names                                                             */
  43.  
  44. #ifndef TMPNAME
  45. # define TMPNAME    "ET%04x%04x"    /* temp file */
  46. #endif
  47. #ifndef CUTNAME
  48. # define CUTNAME    "EC%04x%04x"    /* cut buffer's temp file */
  49. #endif
  50. #define SCRATCHFILE     "_scratch_"    /* name of a scratch file */
  51. #define    TAGS        "tags"        /* tags file */
  52. #ifdef ARC
  53. #define SLASH        '.'        /* used to separate parts of pathname */
  54. #define EXRC        "-exrc"        /* init file in current directory */
  55. #define KEYWORDPRG    "%ref"        /* keyword "help" program */
  56. extern void ARC_keyword();
  57. #else
  58. #define SLASH        '/'        /* used to separate parts of pathname */
  59. #define EXRC        ".exrc"        /* init file in current directory */
  60. #define KEYWORDPRG    "/usr/bin/ref"    /* keyword "help" program */
  61. #endif /* ARC */
  62. #define HMEXRC        EXRC        /* init file in home directory */
  63.  
  64. /*------------------------------------------------------------------------*/
  65. /* Miscellaneous constants.                          */
  66.  
  67. #define INFINITY    2000000001L    /* a very large integer */
  68. #define MAXMAPS        20        /* number of :map keys */
  69. #define LONGKEY        10        /* longest possible raw :map key */
  70. #define MAXRCLEN    1000        /* longest possible .exrc file */
  71.  
  72. /*------------------------------------------------------------------------*/
  73. /* These describe how temporary files are divided into blocks             */
  74.  
  75. #define BLKSIZE    1024        /* size of blocks */
  76. #define MAXBLKS    (BLKSIZE / sizeof(unsigned short))
  77. typedef union
  78. {
  79.     char        c[BLKSIZE];    /* for text blocks */
  80.     unsigned short    n[MAXBLKS];    /* for the header block */
  81. }
  82.     BLK;
  83.  
  84. /*------------------------------------------------------------------------*/
  85. /* These are used manipulate BLK buffers.                                 */
  86.  
  87. extern BLK    hdr;        /* buffer for the header block */
  88. extern BLK    blkbuf[2];    /* buffers for text blocks */
  89. extern BLK    *blkget();    /* given index into hdr.c[], reads block */
  90. extern BLK    *blkadd();    /* inserts a new block into hdr.c[] */
  91.  
  92. /*------------------------------------------------------------------------*/
  93. /* These are used to keep track of various flags                          */
  94. extern struct _viflags
  95. {
  96.     short    file;        /* file flags */
  97. }
  98.     viflags;
  99.  
  100. /* file flags */
  101. #define NEWFILE        0x0001    /* the file was just created */
  102. #define READONLY    0x0002    /* the file is read-only */
  103. #define HADNUL        0x0004    /* the file contained NUL characters */
  104. #define MODIFIED    0x0008    /* the file has been modified */
  105. #define NOFILE        0x0010    /* no name is known for the current text */
  106. #define ADDEDNL        0x0020    /* newlines were added to the file */
  107.  
  108. /* macros used to set/clear/test flags */
  109. #define setflag(x,y)    viflags.x |= y
  110. #define clrflag(x,y)    viflags.x &= ~y
  111. #define tstflag(x,y)    (viflags.x & y)
  112. #define initflags()    viflags.file = 0;
  113.  
  114. /* The options */
  115. extern char    o_autoindent[1];
  116. extern char    o_autowrite[1];
  117. #ifndef SET_NOCHARATTR
  118. extern char    o_charattr[1];
  119. #endif
  120. extern char    o_columns[3];
  121. extern char    o_exrefresh[1];
  122. extern char    o_ignorecase[1];
  123. extern char    o_keytime[3];
  124. extern char    o_keywordprg[80];
  125. extern char    o_lines[3];
  126. extern char    o_magic[1];
  127. extern char    o_paragraphs[30];
  128. extern char    o_readonly[1];
  129. extern char    o_report[3];
  130. extern char    o_scroll[3];
  131. extern char    o_sections[30];
  132. extern char    o_shell[60];
  133. extern char    o_shiftwidth[3];
  134. extern char    o_sidescroll[3];
  135. extern char    o_tabstop[3];
  136. extern char    o_term[30];
  137. extern char    o_vbell[1];
  138. extern char    o_wrapmargin[3];
  139. extern char    o_wrapscan[1];
  140. #ifdef ARC
  141. extern char    o_colourf[3];
  142. extern char    o_colourb[3];
  143. #endif
  144.  
  145. /*------------------------------------------------------------------------*/
  146. /* These are used to refer to places in the text               */
  147.  
  148. typedef long    MARK;
  149. #define markline(x)    ((x) / BLKSIZE)
  150. #define markidx(x)    (int)((x) & (BLKSIZE - 1))
  151. #define MARK_UNSET    ((MARK)0)
  152. #define MARK_FIRST    ((MARK)BLKSIZE)
  153. #define MARK_LAST    ((MARK)(nlines * BLKSIZE))
  154. #define MARK_AT_LINE(x)    ((MARK)((x) * BLKSIZE))
  155.  
  156. #define NMARKS    28
  157. extern MARK    mark[NMARKS];    /* marks 'a through 'z, plus mark '' */
  158. extern MARK    cursor;        /* mark where line is */
  159.  
  160. /*------------------------------------------------------------------------*/
  161. /* These are used to keep track of the current & previous files.      */
  162.  
  163. extern long    origtime;    /* modification date&time of the current file */
  164. extern char    origname[256];    /* name of the current file */
  165. extern char    prevorig[256];    /* name of the preceding file */
  166. extern long    prevline;    /* line number from preceding file */
  167.  
  168. /*------------------------------------------------------------------------*/
  169. /* misc housekeeping variables & functions                  */
  170.  
  171. extern int    tmpfd;        /* fd used to access the tmp file */
  172. extern long    lnum[MAXBLKS];    /* last line# of each block */
  173. extern long    nlines;        /* number of lines in the file */
  174. extern int    forceit;    /* force a command (e.g. ":q!") */
  175. extern char    args[BLKSIZE];    /* file names given on the command line */
  176. extern int    argno;        /* the current element of args[] */
  177. extern int    nargs;        /* number of filenames in args */
  178. extern long    changes;    /* counts changes, to prohibit short-cuts */
  179. extern int    mustredraw;    /* boolean: force total redraw of screen? */
  180. extern long    redrawafter;    /* line# of first line to redraw */
  181. extern long    redrawpre;    /* line# of last line changed, before change */
  182. extern long    redrawpost;    /* line# of last line changed, after change */
  183. extern BLK    tmpblk;        /* a block used to accumulate changes */
  184. extern long    topline;    /* file line number of top line */
  185. extern int    leftcol;    /* column number of left col */
  186. #define        botline     (topline + LINES - 2)
  187. #define        rightcol (leftcol + COLS - 1)
  188. extern int    physcol;    /* physical column number that cursor is on */
  189. extern int    physrow;    /* physical row number that cursor is on */
  190. extern int    exwrote;    /* used to detect verbose ex commands */
  191. extern int    doingdot;    /* boolean: are we doing the "." command? */
  192. extern long    rptlines;    /* number of lines affected by a command */
  193. extern char    *rptlabel;    /* description of how lines were affected */
  194. extern char    *fetchline();    /* read a given line from tmp file */
  195. extern char    *parseptrn();    /* isolate a regexp in a line */
  196. extern MARK    paste();    /* paste from cut buffer to a given point */
  197. extern char    *wildcard();    /* expand wildcards in filenames */
  198. extern MARK    input();    /* inserts characters from keyboard */
  199. extern char    *linespec();    /* finds the end of a /regexp/ string */
  200. #define        ctrl(ch) ((ch)&037)
  201. #ifndef NO_RECYCLE
  202. extern long    allocate();    /* allocate a free block of the tmp file */
  203. #endif
  204.  
  205. /*------------------------------------------------------------------------*/
  206. /* macros that are used as control structures                             */
  207.  
  208. #define BeforeAfter(before, after) for((before),bavar=1;bavar;(after),bavar=0)
  209. #define ChangeText    BeforeAfter(beforedo(FALSE),afterdo())
  210.  
  211. extern int    bavar;        /* used only in BeforeAfter macros */
  212.  
  213. /*------------------------------------------------------------------------*/
  214. /* These are the movement commands.  Each accepts a mark for the starting */
  215. /* location & number and returns a mark for the destination.          */
  216.  
  217. extern MARK    moveup();        /* k */
  218. extern MARK    movedown();        /* j */
  219. extern MARK    moveright();        /* h */
  220. extern MARK    moveleft();        /* l */
  221. extern MARK    movetoline();        /* G */
  222. extern MARK    movetocol();        /* | */
  223. extern MARK    movefront();        /* ^ */
  224. extern MARK    moverear();        /* $ */
  225. extern MARK    movefword();        /* w */
  226. extern MARK    movebword();        /* b */
  227. extern MARK    moveeword();        /* e */
  228. extern MARK    movefWord();        /* W */
  229. extern MARK    movebWord();        /* B */
  230. extern MARK    moveeWord();        /* E */
  231. extern MARK    movefparagraph();    /* } */
  232. extern MARK    movebparagraph();    /* { */
  233. extern MARK    movefsection();        /* ]] */
  234. extern MARK    movebsection();        /* [[ */
  235. extern MARK    movematch();        /* % */
  236. extern MARK    movefsentence();    /* ) */
  237. extern MARK    movebsentence();    /* ( */
  238. extern MARK    movetomark();        /* 'm */
  239. extern MARK    movensrch();        /* n */
  240. extern MARK    moveNsrch();        /* N */
  241. extern MARK    movefsrch();        /* /regexp */
  242. extern MARK    movebsrch();        /* ?regexp */
  243. extern MARK    move_ch();        /* ; , */
  244. extern MARK    movefch();        /* f */
  245. extern MARK    movetch();        /* t */
  246. extern MARK    moveFch();        /* F */
  247. extern MARK    moveTch();        /* T */
  248. extern MARK    moverow();        /* H L M */
  249. extern MARK    movez();        /* z */
  250. extern MARK    movescroll();        /* ^B ^F ^E ^Y ^U ^D */
  251.  
  252. /* Some stuff that is used by movement functions... */
  253.  
  254. extern MARK    adjmove();        /* a helper fn, used by move fns */
  255.  
  256. /* This macro is used to set the default value of cnt */
  257. #define DEFAULT(val)    if (cnt < 1) cnt = (val)
  258.  
  259. /* These are used to minimize calls to fetchline() */
  260. extern int    plen;    /* length of the line */
  261. extern long    pline;    /* line number that len refers to */
  262. extern long    pchgs;    /* "changes" level that len refers to */
  263. extern char    *ptext;    /* text of previous line, if valid */
  264. #ifdef CRUNCH
  265. extern void    pfetch();
  266. #else
  267. # define pfetch(l)    if((l) != pline || changes != pchgs){\
  268.                 pline = (l);\
  269.                 ptext=fetchline(pline);\
  270.                 plen=strlen(ptext);\
  271.                 pchgs = changes;}
  272. #endif
  273.  
  274. /* This is used to build a MARK that corresponds to a specific point in the
  275.  * line that was most recently pfetch'ed.
  276.  */
  277. #define buildmark(text)    (MARK)(BLKSIZE * pline + ((text) - ptext))
  278.  
  279.  
  280. /*------------------------------------------------------------------------*/
  281. /* These are used to handle EX commands.                  */
  282.  
  283. typedef enum
  284. {
  285.     CMD_NULL,    /* NOT A VALID COMMAND */
  286.      /*    CMD_ABBR,    /* "define an abbreviation" */
  287.     CMD_ARGS,    /* "show me the args" */
  288.     CMD_APPEND,    /* "insert lines after this line" */
  289.     CMD_BANG,    /* "run a single shell command" */
  290.     CMD_COPY,    /* "copy the selected text to a given place" */
  291.     CMD_CD,        /* "change directories" */
  292.     CMD_CHANGE,    /* "change some lines" */
  293.     CMD_DELETE,    /* "delete the selected text" */
  294.     CMD_EDIT,    /* "switch to a different file" */
  295.     CMD_FILE,    /* "show the file's status" */
  296.     CMD_GLOBAL,    /* "globally search & do a command" */
  297.     CMD_INSERT,    /* "insert lines before the current line" */
  298.     CMD_JOIN,    /* "join the selected line & the one after" */
  299.     CMD_LIST,    /* "print lines, making control chars visible" */
  300.     CMD_MAP,    /* "adjust the keyboard map" */
  301.     CMD_MARK,    /* "mark this line" */
  302.     CMD_MKEXRC,    /* "make a .exrc file" */
  303.     CMD_MOVE,    /* "move the selected text to a given place" */
  304.     CMD_NEXT,    /* "switch to next file in args" */
  305.      /*    CMD_PRESERVE,    /* "act as though vi crashed" */
  306.     CMD_PREVIOUS,    /* "switch to the previous file in args" */
  307.     CMD_PRINT,    /* "print the selected text" */
  308.     CMD_PUT,    /* "insert any cut lines before this line" */
  309.     CMD_QUIT,    /* "quit without writing the file" */
  310.     CMD_READ,    /* "append the given file after this line */
  311.      /* CMD_RECOVER,    /* "recover file after vi crashes" - USE -r FLAG */
  312.     CMD_REWIND,    /* "rewind to first file" */
  313.     CMD_SET,    /* "set a variable's value" */
  314.     CMD_SHELL,    /* "run some lines through a command" */
  315.     CMD_SHIFTL,    /* "shift lines left" */
  316.     CMD_SHIFTR,    /* "shift lines right" */
  317.     CMD_SOURCE,    /* "interpret a file's contents as ex commands" */
  318.      /* CMD_STOP,    /* same as CMD_SUSPEND */
  319.      /* CMD_SUSPEND,    /* "suspend the vi session" */
  320.     CMD_SUBSTITUTE,    /* "substitute text in this line" */
  321.      /* CMD_TR,        /* "transliterate chars in the selected lines" */
  322.     CMD_TAG,    /* "go to a particular tag" */
  323.      /*    CMD_UNABBR,    /* "remove an abbreviation definition" */
  324.     CMD_UNDO,    /* "undo the previous command" */
  325.     CMD_UNMAP,    /* "remove a key sequence map */
  326.     CMD_VERSION,    /* "describe which version this is" */
  327.     CMD_VGLOBAL,    /* "apply a cmd to lines NOT containing an RE" */
  328.     CMD_VISUAL,    /* "go into visual mode" */
  329.     CMD_WRITE,    /* "write the selected(?) text to a given file" */
  330.     CMD_XIT,    /* "write this file out (if modified) & quit" */
  331. #ifdef DEBUG
  332.     CMD_DEBUG,    /* access to internal data structures */
  333.     CMD_VALIDATE,    /* check for internal consistency */
  334. #endif
  335.     CMD_YANK    /* "copy the selected text into the cut buffer" */
  336. }
  337.     CMD;
  338.  
  339. extern        ex();
  340. extern        vi();
  341. extern        doexcmd();
  342.  
  343. extern void    cmd_append();
  344. extern void    cmd_args();
  345. extern void    cmd_cd();
  346. extern void    cmd_delete();
  347. extern void    cmd_edit();
  348. extern void    cmd_file();
  349. extern void    cmd_global();
  350. extern void    cmd_join();
  351. extern void    cmd_mark();
  352. extern void    cmd_list();
  353. extern void    cmd_map();
  354. extern void    cmd_mkexrc();
  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_shiftl();    /* < */
  400. extern MARK    v_shiftr();    /* > */
  401. extern MARK    v_filter();    /* ! */
  402. extern MARK    v_status();    /* ^G */
  403. extern MARK    v_keyword();    /* ^K */
  404. extern MARK    v_tag();    /* ^] */
  405. extern MARK    v_xit();    /* ZZ */
  406.  
  407. /*----------------------------------------------------------------------*
  408. /* These describe what mode we're in */
  409.  
  410. extern enum _mode
  411. {
  412.     MODE_EX,    /* executing ex commands */
  413.     MODE_VI,    /* executing vi commands */
  414.     MODE_COLON,    /* executing an ex command from vi mode */
  415.     MODE_QUIT
  416. }
  417.     mode;
  418.  
  419. #define WHEN_VICMD    1    /* getkey: we're reading a VI command */
  420. #define WHEN_VIINP    2    /* getkey: we're in VI's INPUT mode */
  421. #define WHEN_VIREP    4    /* getkey: we're in VI's REPLACE mode */
  422. #define WHEN_EX        8    /* getkey: we're in EX mode */
  423.