Skip to content
Newer
Older
100644 145 lines (121 sloc) 4.36 KB
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
1 /* more.c */
2 /* Copyright 1995 by Steve Kirkendall */
3
4
5
6 /* This file contains code which implements the "Hit <Enter> to continue"
7 * message. For the sake of uniformity, this is implemented as a special
8 * key processing state, applied to a buffer which just happens to contain
9 * the "Hit.." message.
10 *
11 * Any single character causes this edit mode to exit, so that editing can
12 * resume on the real edit buffer.
13 *
14 * When this key state is pushed, one character can be designated for
15 * special treatment. If that character is pressed, it will be re-inserted
16 * into the type-ahead queue. This is intended to support the use of <:>
17 * to start one ex command after another.
18 */
19
20 #include "elvis.h"
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored Dec 10, 2011
21 #ifdef FEATURE_RCSID
22 char id_more[] = "$Id: more.c,v 2.19 2003/10/17 17:41:23 steve Exp $";
23 #endif
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
24
25 #if USE_PROTOTYPES
26 static RESULT perform(WINDOW win);
27 static RESULT enter(WINDOW win);
28 static RESULT parse(_CHAR_ key, void *info);
29 static ELVCURSOR shape(WINDOW win);
30 #endif
31
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored Dec 10, 2011
32 ELVBOOL morehit;
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
33
34 typedef struct
35 {
36 CHAR special; /* character to receive special processing */
37 } MOREINFO;
38
39 /* This function performs a "[More]" command. It doesn't really do much;
40 * we really only wanted to wait for the user to hit a key.
41 */
42 static RESULT perform(win)
43 WINDOW win; /* window where <Enter> was hit */
44 {
45 MARKBUF from;
46
47 /* Erase the "Hit..." message. Why is that so hard? */
48 bufreplace(marktmp(from, markbuffer(win->state->cursor), 0),
49 win->state->cursor, NULL, 0);
50 drawopenedit(win);
51 win->di->drawstate = DRAW_VISUAL;
52 msg(MSG_STATUS, "");
53 win->di->drawstate = DRAW_OPENEDIT;
54
3a9bb55 @mbert Import Elvis 2.1_3 (written by Steve Kirkendall)
authored Dec 10, 2011
55 /* reset the morehit flag */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored Dec 10, 2011
56 morehit = ElvTrue;
3a9bb55 @mbert Import Elvis 2.1_3 (written by Steve Kirkendall)
authored Dec 10, 2011
57
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
58 return RESULT_COMPLETE;
59 }
60
61 /* If the user really does hit <Enter> at the "Hit <Enter> to continue" prompt,
62 * then this function is called after perform(). This function is a stub,
63 * because perform() does everything that needs to be done. In fact, the only
64 * reason we even bother to have an enter() function is so that the state.c
65 * module will know that the "Hit <Enter>..." prompt is a separate stratum.
66 */
67 static RESULT enter(win)
68 WINDOW win; /* window where <Enter> was hit */
69 {
70 return RESULT_MORE;
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored Dec 10, 2011
71 /* Not RESULT_COMPLETE, because RESULT_COMPLETE interferes with the
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
72 * perform() function, some how. I may be working around a bug here.
73 */
74 }
75
76
77 /* This function parses a command. For "[More]", any single key completes the
78 * command, so this is trivial. If it is the special character, then the
79 * character is pushed back onto the typeahead queue.
80 */
81 static RESULT parse(key, info)
82 _CHAR_ key; /* the key that the user hit */
83 void *info; /* struct, contains the special character */
84 {
85 MOREINFO *mi = (MOREINFO *)info;
86 CHAR keyarray[1];
87
88 /* if this is the special key, push it back into the type-ahead queue */
89 if (mi->special != '\0' && key == mi->special)
90 {
91 keyarray[0] = key;
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored Dec 10, 2011
92 mapunget(keyarray, 1, ElvFalse);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
93 }
94
95 return RESULT_COMPLETE;
96 }
97
98 /* This function decides on a cursor shape */
99 static ELVCURSOR shape(win)
100 WINDOW win; /* window waiting for <Enter> to be hit */
101 {
102 return CURSOR_COMMAND;
103 }
104
105
106 /* This function causes elvis to display "Hit <Enter> to continue", and
107 * then wait for a keystroke. Any keystroke is acceptable. If the keystroke
108 * happens to match the "special" argument, then it will be placed back in
109 * the type-ahead queue for further processing.
110 */
111 void morepush(win, special)
112 WINDOW win; /* window that should wait for <Enter> */
113 _CHAR_ special;/* a special character, or '\0' if none */
114 {
115 BUFFER buf;
116 MARKBUF from, to;
117
8d1ac0c @mbert Import Elvis 2.1 (written by Steve Kirkendall)
authored Dec 10, 2011
118 /* if we're in the middle of a macro, never wait for <Enter> */
119 if (mapbusy())
120 return;
121
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
122 /* Create the "more" buffer, and put the prompt into it */
9f1c6f0 @mbert Import Elvis 2.2_0 (written by Steve Kirkendall)
authored Dec 10, 2011
123 buf = bufalloc(toCHAR(MORE_BUF), 0, ElvTrue);
cf92e3b @mbert Import Elvis 2.0 (written by Steve Kirkendall)
authored Dec 10, 2011
124 bufreplace(marktmp(from, buf, 0), marktmp(to, buf, o_bufchars(buf)),
125 toCHAR("Hit <Enter> to continue\n"), 24);
126
127 /* Push the state. Make sure this keystate will be popped after
128 * a single command (keystroke)
129 */
130 statepush(win, ELVIS_POP|ELVIS_BOTTOM);
131
132 /* initialize the state */
133 win->state->enter = enter;
134 win->state->perform = perform;
135 win->state->parse = parse;
136 win->state->shape = shape;
137 win->state->info = safealloc(1, sizeof (MOREINFO));
138 ((MOREINFO *)win->state->info)->special = special;
139 win->state->modename = "More";
140 win->state->top = markalloc(buf, 0);
141 win->state->bottom = markalloc(buf, o_bufchars(buf));
142 win->state->cursor = markalloc(buf, o_bufchars(buf) - 1);
143 win->state->acton = win->state->pop;
144 }
Something went wrong with that request. Please try again.