1 # @(#)interp 8.5 (Berkeley) 10/19/96
5 The intention is to provide a way to graft a fairly generic extension
6 language into nvi. I think that the obvious candidates are Tcl/Rush,
7 Scheme, Python and Perl. Since the interpretation language chosen
8 is often a religious issue, the method should be as flexible as
9 possible. I don't expect to rewrite the editor in the interpreted
10 language, so that isn't a consideration.
12 Q: Is there any reason for nvi to support multiple interpreters in
15 Interpreter functions in nvi:
17 1: Function to get the current screen pointer.
21 Return a pointer to the current screen.
23 2: Functions to execute both ex and vi commands. The return value of the
24 function will be success/failure. The editor itself will continue to
25 handle the display of all messages and text for the foreseeable future.
27 int inter_vicmd(SCR *, char *cmds, size_t len);
28 int inter_excmd(SCR *, char *cmds, size_t len);
30 The byte string cmds, of length len, is entered into the standard
31 vi or ex parser, as if typed by the user. The characters are not
32 mapped in any way, i.e. the user's vi mappings don't apply. If
33 any error occurs, an error value is returned, and the rest of the
34 characters are discarded.
36 3: Functions to handle lines of text in the file.
38 int inter_gline(SCR *, recno_t lno, char **lp, size_t *lenp);
40 Return a pointer to the text of the line lno, into the location
41 referenced by lp, and its length into the location referenced by
44 int inter_dline(SCR *, recno_t lno);
46 Delete the line lno from the file.
48 int inter_aline(SCR *, recno_t lno, char *lp, size_t len);
50 Append a line consisting of the len bytes of text referenced by
53 int inter_iline(SCR *, recno_t lno, char *lp, size_t len);
55 Insert a line consisting of the len bytes of text referenced by
56 lp before the line lno.
58 int inter_sline(SCR *, recno_t lno, char *lp, size_t len);
60 Replace line lno with the len bytes of text referenced by lp.
62 int inter_lline(SCR *, recno_t *lnop);
64 Return the number of the last line in the file in the location
67 4: Function to post an error message to the user.
69 int inter_msgq(SCR *, enum msgtype, char *fmt, ...);
71 Display the message for the user. Valid message types are:
73 M_BERR Error: M_ERR if verbose, else bell.
74 M_ERR Error: Display in inverse video.
75 M_INFO Info: Display in normal video.
76 M_SYSERR Error: M_ERR, using strerror(3) message.
77 M_VINFO Info: M_INFO if verbose, else ignore.
79 5: Function to manipulate cut buffers.
81 int inter_setbuf(SCR *, CHAR_T buffer);
83 Create the specified buffer if it does not exist (the
84 buffer will have no contents).
86 int inter_getbuf(SCR *, CHAR_T buffer, TEXT **textp);
88 Return a pointer to the specified buffer in the location
89 referenced by textp. (Since a pointer to the real item
90 is being returned, it can be manipulated in any way the
93 6: Functions to manipulate marks.
95 int inter_setmark(SCR *, CHAR_T name);
97 Create the specified mark if it does not exist (the
98 mark will have no contents).
100 int inter_getmark(SCR *, CHAR_T name, MARK **markp);
102 Return a pointer to the specified mark in the location
103 referenced by markp. (Since a pointer to the real item
104 is being returned, it can be manipulated in any way the
105 interpreter chooses.)
107 7: Function to manipulate screens.
109 SCR *inter_iscreen();
111 Create a new screen, and return a pointer to it.
113 int inter_escreen(SCR *);
117 8: Functions to get input from the user.
119 int inter_getchar(CHAR_T *chp,
120 enum maptype {NONE, INPUT, COMMAND} mapt);
122 Return a character from the keyboard into the location referenced
123 by chp. Mapt can be set to INPUT, COMMAND or NONE, depending on
124 what vi mappings should be applied to the character.
126 int inter_getline(SCR *, char *prompt, CHAR_T **linep,
127 size_t *lenp, enum maptype {NONE, INPUT, COMMAND} mapt);
129 Return a pointer to a line entered by the user, and its length,
130 into the locations linep and lenp. A prompt may be specified
131 by prompt, and mappings by mapt.
133 int inter_freeline(CHAR_T *linep);
135 Free the memory that was allocated by inter_getline();
137 9: Function to retrieve and set the cursor.
139 int inter_getcursor(SCR *, MARK *mark);
141 Store the current cursor position in mark.
143 int inter_setcursor(SCR *, MARK *mark);
145 Set the current cursor position to mark.
147 10: Function to return a motion command from the user.
149 int inter_getmotion(SCR *,
150 MARK *start, MARK *end, enum movetype {LINE, CHAR} *mt);
152 Nvi gets a motion command from the user and returns the starting
153 and stopping points of the movement, reordered from the beginning
154 to the end of the file. The standard rules for line/character
155 motions are applied, and returned to the interpreter through the
158 11: Functions to return pathnames.
160 12: Functions to return edit options.
162 13: Nvi commands which will send text to the interpreter.
164 Nvi will have a new ex command "inter", which will pipe the rest of
165 the line up to the first unescaped <newline> to the interpreter, of
168 :[address[,address]] inter [count] command
170 The interface from the ex command to the interpreter is a function:
173 SCR *, /* Current screen. */
174 char *cmd; /* The command. */
175 size_t len; /* The command length. */
176 MARK *start, /* Starting address for INTER_EX */
177 MARK *end, /* Ending address for INTER_EX */
178 int count); /* Count. */
180 Nvi will have a new vi command "*<buffer>" which will pipe the contents
181 of the named buffer to the interpreter, of the following form:
185 The interface from the vi command to the interpreter is a function:
188 SCR *, /* Current screen. */
189 CHAR_T buffer, /* Buffer. */
190 int count); /* Count. */