MFC corrected printing of the slice number when adding a GPT partition.
[dragonfly.git] / contrib / nvi / tk / tk_funcs.c
blobbe2b0d96ea09fd174527be2b29792748b8a639b0
1 /*-
2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "@(#)tk_funcs.c 8.11 (Berkeley) 9/23/96";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
20 #include <bitstring.h>
21 #include <ctype.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <termios.h>
27 #include <unistd.h>
29 #include "../common/common.h"
30 #include "../vi/vi.h"
31 #include "tki.h"
34 * tk_addstr --
35 * Add len bytes from the string at the cursor, advancing the cursor.
37 * PUBLIC: int tk_addstr __P((SCR *, const char *, size_t));
39 int
40 tk_addstr(sp, str, len)
41 SCR *sp;
42 const char *str;
43 size_t len;
45 TK_PRIVATE *tkp;
46 int iv;
47 char buf[20];
49 iv = 0;
51 tkp = TKP(sp);
52 if (iv)
53 (void)Tcl_Eval(tkp->interp, "tk_standout");
55 (void)snprintf(buf, sizeof(buf), "%d ", (int)len);
56 if ((Tcl_VarEval(tkp->interp,
57 "tk_addstr ", buf, "{", str, "}", NULL) != TCL_OK))
58 return (1);
60 if (iv)
61 (void)Tcl_Eval(tkp->interp, "tk_standend");
62 return (0);
66 * tk_attr --
67 * Toggle a screen attribute on/off.
69 * PUBLIC: int tk_attr __P((SCR *, scr_attr_t, int));
71 int
72 tk_attr(sp, attribute, on)
73 SCR *sp;
74 scr_attr_t attribute;
75 int on;
77 TK_PRIVATE *tkp;
79 tkp = TKP(sp);
80 switch (attribute) {
81 case SA_ALTERNATE: /* No alternate screen. */
82 break;
83 case SA_INVERSE:
84 if (on)
85 (void)Tcl_Eval(tkp->interp, "tk_standout");
86 else
87 (void)Tcl_Eval(tkp->interp, "tk_standend");
88 break;
89 default:
90 abort();
92 return (0);
96 * tk_baud --
97 * Return the baud rate.
99 * PUBLIC: int tk_baud __P((SCR *, u_long *));
102 tk_baud(sp, ratep)
103 SCR *sp;
104 u_long *ratep;
106 *ratep = 9600;
107 return (0);
111 * tk_bell --
112 * Ring the bell/flash the screen.
114 * PUBLIC: int tk_bell __P((SCR *));
117 tk_bell(sp)
118 SCR *sp;
120 TK_PRIVATE *tkp;
122 tkp = TKP(sp);
123 return (Tcl_Eval(tkp->interp, "tk_flash") != TCL_OK);
127 * tk_clrtoeol --
128 * Clear from the current cursor to the end of the line.
130 * PUBLIC: int tk_clrtoeol __P((SCR *));
133 tk_clrtoeol(sp)
134 SCR *sp;
136 TK_PRIVATE *tkp;
138 tkp = TKP(sp);
139 return (Tcl_Eval(tkp->interp, "tk_clrtoeol") != TCL_OK);
143 * tk_cursor --
144 * Return the current cursor position.
146 * PUBLIC: int tk_cursor __P((SCR *, size_t *, size_t *));
149 tk_cursor(sp, yp, xp)
150 SCR *sp;
151 size_t *yp, *xp;
153 TK_PRIVATE *tkp;
155 tkp = TKP(sp);
156 *yp = (tkp->tk_cursor_row - 1) - sp->woff;
157 *xp = tkp->tk_cursor_col;
158 return (0);
162 * tk_deleteln --
163 * Delete the current line, scrolling all lines below it.
165 * PUBLIC: int tk_deleteln __P((SCR *));
168 tk_deleteln(sp)
169 SCR *sp;
171 TK_PRIVATE *tkp;
173 tkp = TKP(sp);
174 return (Tcl_Eval(tkp->interp, "tk_deleteln") != TCL_OK);
178 * tk_ex_adjust --
179 * Adjust the screen for ex.
181 * PUBLIC: int tk_ex_adjust __P((SCR *, exadj_t));
184 tk_ex_adjust(sp, action)
185 SCR *sp;
186 exadj_t action;
188 abort();
189 /* NOTREACHED */
193 * tk_insertln --
194 * Push down the current line, discarding the bottom line.
196 * PUBLIC: int tk_insertln __P((SCR *));
199 tk_insertln(sp)
200 SCR *sp;
202 TK_PRIVATE *tkp;
204 tkp = TKP(sp);
205 return (Tcl_Eval(tkp->interp, "tk_insertln") != TCL_OK);
209 * tk_keyval --
210 * Return the value for a special key.
212 * PUBLIC: int tk_keyval __P((SCR *, scr_keyval_t, CHAR_T *, int *));
215 tk_keyval(sp, val, chp, dnep)
216 SCR *sp;
217 scr_keyval_t val;
218 CHAR_T *chp;
219 int *dnep;
221 TK_PRIVATE *tkp;
224 * VEOF, VERASE and VKILL are required by POSIX 1003.1-1990,
225 * VWERASE is a 4BSD extension.
227 tkp = TKP(sp);
228 switch (val) {
229 case KEY_VEOF:
230 *dnep = (*chp = tkp->orig.c_cc[VEOF]) == _POSIX_VDISABLE;
231 break;
232 case KEY_VERASE:
233 *dnep = (*chp = tkp->orig.c_cc[VERASE]) == _POSIX_VDISABLE;
234 break;
235 case KEY_VKILL:
236 *dnep = (*chp = tkp->orig.c_cc[VKILL]) == _POSIX_VDISABLE;
237 break;
238 #ifdef VWERASE
239 case KEY_VWERASE:
240 *dnep = (*chp = tkp->orig.c_cc[VWERASE]) == _POSIX_VDISABLE;
241 break;
242 #endif
243 default:
244 *dnep = 1;
245 break;
247 return (0);
251 * tk_move --
252 * Move the cursor.
254 * PUBLIC: int tk_move __P((SCR *, size_t, size_t));
257 tk_move(sp, lno, cno)
258 SCR *sp;
259 size_t lno, cno;
261 TK_PRIVATE *tkp;
262 char buf[40];
264 (void)snprintf(buf, sizeof(buf), "%d %d", RLNO(sp, lno), cno);
266 tkp = TKP(sp);
267 return (Tcl_VarEval(tkp->interp, "tk_move ", buf, NULL) != TCL_OK);
271 * tk_refresh --
272 * Refresh the screen.
274 * PUBLIC: int tk_refresh __P((SCR *, int));
277 tk_refresh(sp, repaint)
278 SCR *sp;
279 int repaint;
281 TK_PRIVATE *tkp;
284 * If repaint is set, the editor is telling us that we don't know
285 * what's on the screen, so we have to repaint from scratch.
287 * XXX
288 * I have no idea how to do this in Tk. My guess is that we have
289 * to delete all of the text and call the editor with an E_REPAINT
290 * event.
292 if (repaint) {
295 tkp = TKP(sp);
296 return (Tcl_Eval(tkp->interp, "update idletasks") != TCL_OK);
300 * tk_rename --
301 * Rename the file.
303 * PUBLIC: int tk_rename __P((SCR *));
306 tk_rename(sp)
307 SCR *sp;
309 TK_PRIVATE *tkp;
311 tkp = TKP(sp);
312 return (Tcl_VarEval(tkp->interp,
313 "tk_rename ", sp->frp->name, NULL) != TCL_OK);
317 * tk_suspend --
318 * Suspend a screen.
320 * PUBLIC: int tk_suspend __P((SCR *, int *));
323 tk_suspend(sp, allowedp)
324 SCR *sp;
325 int *allowedp;
327 *allowedp = 0;
328 return (0);
332 * tk_usage --
333 * Print out the Tk/Tcl usage messages.
335 * PUBLIC: void tk_usage __P((void));
337 void
338 tk_usage()
340 #define USAGE "\
341 usage: tkvi [-eFlRrSv] [-c command] [-bg color] [-fg color]\n\
342 [-geometry widthxheight+x+y] [-i script] [-t tag] [-w size]\n\
343 [file ...]\n"
344 (void)fprintf(stderr, "%s", USAGE);
345 #undef USAGE