blob: 50ae04d758082bfac6aab381b3cd224e23a2cdca [file] [log] [blame]
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001/*
2 * Line-editing routines
3 *
4 * Copyright 1992 Simmule Turner and Rich Salz. All rights reserved.
5 *
6 *
7 * This software is not subject to any license of the American Telephone
8 * and Telegraph Company or of the Regents of the University of California.
9 *
10 * Permission is granted to anyone to use this software for any purpose on
11 * any computer system, and to alter it and redistribute it freely, subject
12 * to the following restrictions:
13 * 1. The authors are not responsible for the consequences of use of this
14 * software, no matter how awful, even if they arise from flaws in it.
15 * 2. The origin of this software must not be misrepresented, either by
16 * explicit claim or by omission. Since few users ever read sources,
17 * credits must appear in the documentation.
18 * 3. Altered versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software. Since few users
20 * ever read sources, credits must appear in the documentation.
21 * 4. This notice may not be removed or altered.
22 *
23 * The code was heavily simplified for inclusion in Wine. -- AJ
24 */
25
26#include "config.h"
Alexandre Julliardf0b23541993-09-29 12:21:49 +000027#include <ctype.h>
Alexandre Julliard18f92e71996-07-17 20:02:21 +000028#include <stdio.h>
Alexandre Julliardecc37121994-11-22 16:31:29 +000029#include <stdlib.h>
Alexandre Julliard18f92e71996-07-17 20:02:21 +000030#include <string.h>
Alexandre Julliard18f92e71996-07-17 20:02:21 +000031
Jim Aston2e1cafa1999-03-14 16:35:05 +000032#include "windef.h"
Michael Stefaniuc85d30862001-04-12 21:07:25 +000033#include "winbase.h"
Alexandre Julliardf818d422000-05-03 17:48:21 +000034#include "wincon.h"
Ove Kaavendda17c61999-04-25 12:24:42 +000035#include "debugger.h"
Alexandre Julliardf0b23541993-09-29 12:21:49 +000036
37/*
38** Manifest constants.
39*/
40#define SCREEN_WIDTH 80
41#define SCREEN_ROWS 24
42#define NO_ARG (-1)
43#define DEL 127
44#define CTL(x) ((x) & 0x1F)
45#define ISCTL(x) ((x) && (x) < ' ')
46#define UNCTL(x) ((x) + 64)
47#define META(x) ((x) | 0x80)
48#define ISMETA(x) ((x) & 0x80)
49#define UNMETA(x) ((x) & 0x7F)
50#if !defined(HIST_SIZE)
51#define HIST_SIZE 20
52#endif /* !defined(HIST_SIZE) */
Alexandre Julliard18f92e71996-07-17 20:02:21 +000053#define CRLF "\r\n"
54#define MEM_INC 64
55#define SCREEN_INC 256
56
Ove Kaavendda17c61999-04-25 12:24:42 +000057#define DISPOSE(p) DBG_free((char *)(p))
Alexandre Julliard18f92e71996-07-17 20:02:21 +000058#define NEW(T, c) \
Ove Kaavendda17c61999-04-25 12:24:42 +000059 ((T *)DBG_alloc((unsigned int)(sizeof (T) * (c))))
Alexandre Julliard18f92e71996-07-17 20:02:21 +000060#define RENEW(p, T, c) \
Ove Kaavendda17c61999-04-25 12:24:42 +000061 (p = (T *)DBG_realloc((char *)(p), (unsigned int)(sizeof (T) * (c))))
Alexandre Julliard18f92e71996-07-17 20:02:21 +000062#define COPYFROMTO(new, p, len) \
63 (void)memcpy((char *)(new), (char *)(p), (int)(len))
Alexandre Julliardf0b23541993-09-29 12:21:49 +000064
65/*
66** Command status codes.
67*/
68typedef enum _STATUS {
69 CSdone, CSeof, CSmove, CSdispatch, CSstay
70} STATUS;
71
72/*
73** The type of case-changing to perform.
74*/
75typedef enum _CASE {
76 TOupper, TOlower
77} CASE;
78
79/*
80** Key to command mapping.
81*/
82typedef struct _KEYMAP {
83 CHAR Key;
84 STATUS (*Function)();
85} KEYMAP;
86
87/*
88** Command history structure.
89*/
90typedef struct _HISTORY {
91 int Size;
92 int Pos;
93 CHAR *Lines[HIST_SIZE];
94} HISTORY;
95
96/*
97** Globals.
98*/
Alexandre Julliard18f92e71996-07-17 20:02:21 +000099static int rl_eof;
100static int rl_erase;
101static int rl_intr;
102static int rl_kill;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000103
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000104static CHAR NIL[] = "";
105static const CHAR *Input = NIL;
106static CHAR *Line;
107static const char *Prompt;
108static CHAR *Yanked;
109static char *Screen;
110static char NEWLINE[]= CRLF;
111static HISTORY H;
112static int rl_quit;
113static int Repeat;
114static int End;
115static int Mark;
116static int OldPoint;
117static int Point;
118static int PushBack;
119static int Pushed;
120static KEYMAP Map[33];
121static KEYMAP MetaMap[16];
122static size_t Length;
123static size_t ScreenCount;
124static size_t ScreenSize;
125static char *backspace;
126static int TTYwidth;
127static int TTYrows;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000128
129/* Display print 8-bit chars as `M-x' or as the actual 8-bit char? */
130int rl_meta_chars = 1;
131
132/*
133** Declarations.
134*/
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000135static CHAR *editinput();
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000136
137/*
138** TTY input/output functions.
139*/
140
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000141static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000142rl_ttyset(int Reset)
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000143{
Eric Pouech04c16b82000-04-30 12:21:15 +0000144 static DWORD old_mode;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000145
Eric Pouech04c16b82000-04-30 12:21:15 +0000146 if (Reset == 0) {
147 GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &old_mode);
148 SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), 0 /*ENABLE_PROCESSED_INPUT|ENABLE_WINDOW_INPUT|ENABLE_MOUSE_INPUT*/);
149 } else {
150 SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), old_mode);
151 }
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000152}
153
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000154static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000155TTYflush(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000156{
157 if (ScreenCount) {
Eric Pouech04c16b82000-04-30 12:21:15 +0000158 DEBUG_Output(DBG_CHN_MESG, Screen, ScreenCount);
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000159 ScreenCount = 0;
160 }
161}
162
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000163static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000164TTYput(CHAR c)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000165{
166 Screen[ScreenCount] = c;
167 if (++ScreenCount >= ScreenSize - 1) {
168 ScreenSize += SCREEN_INC;
169 RENEW(Screen, char, ScreenSize);
170 }
171}
172
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000173static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000174TTYputs(CHAR *p)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000175{
176 while (*p)
177 TTYput(*p++);
178}
179
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000180static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000181TTYshow(CHAR c)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000182{
183 if (c == DEL) {
184 TTYput('^');
185 TTYput('?');
186 }
187 else if (ISCTL(c)) {
188 TTYput('^');
189 TTYput(UNCTL(c));
190 }
191 else if (rl_meta_chars && ISMETA(c)) {
192 TTYput('M');
193 TTYput('-');
194 TTYput(UNMETA(c));
195 }
196 else
197 TTYput(c);
198}
199
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000200static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000201TTYstring(CHAR *p)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000202{
203 while (*p)
204 TTYshow(*p++);
205}
206
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000207static unsigned int
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000208TTYget(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000209{
210 CHAR c;
Eric Pouech04c16b82000-04-30 12:21:15 +0000211 DWORD retv;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000212
213 TTYflush();
214 if (Pushed) {
215 Pushed = 0;
216 return PushBack;
217 }
218 if (*Input)
219 return *Input++;
Alexandre Julliard638f1691999-01-17 16:32:32 +0000220
Eric Pouech04c16b82000-04-30 12:21:15 +0000221 for (;;) {
222 /* data available ? */
223 if (ReadConsole(GetStdHandle(STD_INPUT_HANDLE), &c, 1, &retv, NULL) &&
224 retv == 1)
225 return c;
226 switch (WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), INFINITE)) {
227 case WAIT_OBJECT_0:
228 break;
229 default:
230 DEBUG_Printf(DBG_CHN_FIXME, "shouldn't happen\n");
Francois Gouget588ff372001-08-21 17:07:17 +0000231 /* fall through */
Eric Pouech04c16b82000-04-30 12:21:15 +0000232 case WAIT_ABANDONED:
233 case WAIT_TIMEOUT:
234 return EOF;
235 }
Alexandre Julliard638f1691999-01-17 16:32:32 +0000236 }
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000237}
238
239#define TTYback() (backspace ? TTYputs((CHAR *)backspace) : TTYput('\b'))
240
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000241static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000242TTYbackn(int n)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000243{
244 while (--n >= 0)
245 TTYback();
246}
247
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000248static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000249TTYinfo(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000250{
Eric Pouech04c16b82000-04-30 12:21:15 +0000251 COORD c = GetLargestConsoleWindowSize(GetStdHandle(STD_INPUT_HANDLE));
Alexandre Julliardf818d422000-05-03 17:48:21 +0000252 TTYwidth = c.X;
253 TTYrows = c.Y;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000254}
255
256
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000257
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000258static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000259reposition(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000260{
261 int i;
262 CHAR *p;
263
264 TTYput('\r');
265 TTYputs((CHAR *)Prompt);
266 for (i = Point, p = Line; --i >= 0; p++)
267 TTYshow(*p);
268}
269
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000270static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000271left(STATUS Change)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000272{
273 TTYback();
274 if (Point) {
275 if (ISCTL(Line[Point - 1]))
276 TTYback();
277 else if (rl_meta_chars && ISMETA(Line[Point - 1])) {
278 TTYback();
279 TTYback();
280 }
281 }
282 if (Change == CSmove)
283 Point--;
284}
285
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000286static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000287right(STATUS Change)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000288{
289 TTYshow(Line[Point]);
290 if (Change == CSmove)
291 Point++;
292}
293
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000294static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000295ring_bell(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000296{
297 TTYput('\07');
298 TTYflush();
299 return CSstay;
300}
301
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000302static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000303do_macro(unsigned int c)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000304{
305 CHAR name[4];
306
307 name[0] = '_';
308 name[1] = c;
309 name[2] = '_';
310 name[3] = '\0';
311
312 if ((Input = (CHAR *)getenv((char *)name)) == NULL) {
313 Input = NIL;
314 return ring_bell();
315 }
316 return CSstay;
317}
318
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000319static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000320do_forward(STATUS move)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000321{
322 int i;
323 CHAR *p;
324
325 i = 0;
326 do {
327 p = &Line[Point];
328 for ( ; Point < End && (*p == ' ' || !isalnum(*p)); Point++, p++)
329 if (move == CSmove)
330 right(CSstay);
331
332 for (; Point < End && isalnum(*p); Point++, p++)
333 if (move == CSmove)
334 right(CSstay);
335
336 if (Point == End)
337 break;
338 } while (++i < Repeat);
339
340 return CSstay;
341}
342
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000343static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000344do_case(CASE type)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000345{
346 int i;
347 int end;
348 int count;
349 CHAR *p;
350
351 (void)do_forward(CSstay);
352 if (OldPoint != Point) {
353 if ((count = Point - OldPoint) < 0)
354 count = -count;
355 Point = OldPoint;
356 if ((end = Point + count) > End)
357 end = End;
358 for (i = Point, p = &Line[i]; i < end; i++, p++) {
359 if (type == TOupper) {
360 if (islower(*p))
361 *p = toupper(*p);
362 }
363 else if (isupper(*p))
364 *p = tolower(*p);
365 right(CSmove);
366 }
367 }
368 return CSstay;
369}
370
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000371static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000372case_down_word(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000373{
374 return do_case(TOlower);
375}
376
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000377static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000378case_up_word(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000379{
380 return do_case(TOupper);
381}
382
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000383static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000384ceol(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000385{
386 int extras;
387 int i;
388 CHAR *p;
389
390 for (extras = 0, i = Point, p = &Line[i]; i <= End; i++, p++) {
391 TTYput(' ');
392 if (ISCTL(*p)) {
393 TTYput(' ');
394 extras++;
395 }
396 else if (rl_meta_chars && ISMETA(*p)) {
397 TTYput(' ');
398 TTYput(' ');
399 extras += 2;
400 }
401 }
402
403 for (i += extras; i > Point; i--)
404 TTYback();
405}
406
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000407static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000408clear_line(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000409{
410 Point = -strlen(Prompt);
411 TTYput('\r');
412 ceol();
413 Point = 0;
414 End = 0;
415 Line[0] = '\0';
416}
417
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000418static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000419insert_string(CHAR *p)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000420{
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000421 size_t len;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000422 int i;
423 CHAR *new;
424 CHAR *q;
425
426 len = strlen((char *)p);
427 if (End + len >= Length) {
428 if ((new = NEW(CHAR, Length + len + MEM_INC)) == NULL)
429 return CSstay;
430 if (Length) {
431 COPYFROMTO(new, Line, Length);
432 DISPOSE(Line);
433 }
434 Line = new;
435 Length += len + MEM_INC;
436 }
437
438 for (q = &Line[Point], i = End - Point; --i >= 0; )
439 q[len + i] = q[i];
440 COPYFROMTO(&Line[Point], p, len);
441 End += len;
442 Line[End] = '\0';
443 TTYstring(&Line[Point]);
444 Point += len;
445
446 return Point == End ? CSstay : CSmove;
447}
448
449
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000450static CHAR *
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000451next_hist(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000452{
453 return H.Pos >= H.Size - 1 ? NULL : H.Lines[++H.Pos];
454}
455
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000456static CHAR *
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000457prev_hist()
458{
459 return H.Pos == 0 ? NULL : H.Lines[--H.Pos];
460}
461
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000462static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000463do_insert_hist(CHAR *p)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000464{
465 if (p == NULL)
466 return ring_bell();
467 Point = 0;
468 reposition();
469 ceol();
470 End = 0;
471 return insert_string(p);
472}
473
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000474static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000475do_hist(CHAR *(*move)(void))
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000476{
477 CHAR *p;
478 int i;
479
480 i = 0;
481 do {
482 if ((p = (*move)()) == NULL)
483 return ring_bell();
484 } while (++i < Repeat);
485 return do_insert_hist(p);
486}
487
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000488static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000489h_next(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000490{
491 return do_hist(next_hist);
492}
493
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000494static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000495h_prev(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000496{
497 return do_hist(prev_hist);
498}
499
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000500static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000501h_first(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000502{
503 return do_insert_hist(H.Lines[H.Pos = 0]);
504}
505
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000506static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000507h_last(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000508{
509 return do_insert_hist(H.Lines[H.Pos = H.Size - 1]);
510}
511
512/*
513** Return zero if pat appears as a substring in text.
514*/
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000515static int
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000516substrcmp(char *text, char *pat, int len)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000517{
518 CHAR c;
519
520 if ((c = *pat) == '\0')
521 return *text == '\0';
522 for ( ; *text; text++)
Alexandre Julliard7cbe6571995-01-09 18:21:16 +0000523 if ((CHAR)*text == c && strncmp(text, pat, len) == 0)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000524 return 0;
525 return 1;
526}
527
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000528static CHAR *
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000529search_hist(CHAR *search, CHAR *(*move)(void))
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000530{
531 static CHAR *old_search;
532 int len;
533 int pos;
534 int (*match)();
535 char *pat;
536
537 /* Save or get remembered search pattern. */
538 if (search && *search) {
539 if (old_search)
540 DISPOSE(old_search);
Ove Kaavendda17c61999-04-25 12:24:42 +0000541 old_search = (CHAR *)DBG_strdup((char *)search);
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000542 }
543 else {
544 if (old_search == NULL || *old_search == '\0')
545 return NULL;
546 search = old_search;
547 }
548
549 /* Set up pattern-finder. */
550 if (*search == '^') {
551 match = strncmp;
552 pat = (char *)(search + 1);
553 }
554 else {
555 match = substrcmp;
556 pat = (char *)search;
557 }
558 len = strlen(pat);
559
560 for (pos = H.Pos; (*move)() != NULL; )
561 if ((*match)((char *)H.Lines[H.Pos], pat, len) == 0)
562 return H.Lines[H.Pos];
563 H.Pos = pos;
564 return NULL;
565}
566
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000567static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000568h_search(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000569{
570 static int Searching;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000571 const char *old_prompt;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000572 CHAR *(*move)();
573 CHAR *p;
574
575 if (Searching)
576 return ring_bell();
577 Searching = 1;
578
579 clear_line();
580 old_prompt = Prompt;
581 Prompt = "Search: ";
582 TTYputs((CHAR *)Prompt);
583 move = Repeat == NO_ARG ? prev_hist : next_hist;
584 p = search_hist(editinput(), move);
585 clear_line();
586 Prompt = old_prompt;
587 TTYputs((CHAR *)Prompt);
588
589 Searching = 0;
590 return do_insert_hist(p);
591}
592
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000593static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000594fd_char(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000595{
596 int i;
597
598 i = 0;
599 do {
600 if (Point >= End)
601 break;
602 right(CSmove);
603 } while (++i < Repeat);
604 return CSstay;
605}
606
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000607static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000608save_yank(int begin, int i)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000609{
610 if (Yanked) {
611 DISPOSE(Yanked);
612 Yanked = NULL;
613 }
614
615 if (i < 1)
616 return;
617
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000618 if ((Yanked = NEW(CHAR, (size_t)i + 1)) != NULL) {
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000619 COPYFROMTO(Yanked, &Line[begin], i);
620 Yanked[i] = '\0';
621 }
622}
623
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000624static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000625delete_string(int count)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000626{
627 int i;
628 CHAR *p;
629
630 if (count <= 0 || End == Point)
631 return ring_bell();
632
633 if (count == 1 && Point == End - 1) {
634 /* Optimize common case of delete at end of line. */
635 End--;
636 p = &Line[Point];
637 i = 1;
638 TTYput(' ');
639 if (ISCTL(*p)) {
640 i = 2;
641 TTYput(' ');
642 }
643 else if (rl_meta_chars && ISMETA(*p)) {
644 i = 3;
645 TTYput(' ');
646 TTYput(' ');
647 }
648 TTYbackn(i);
649 *p = '\0';
650 return CSmove;
651 }
652 if (Point + count > End && (count = End - Point) <= 0)
653 return CSstay;
654
655 if (count > 1)
656 save_yank(Point, count);
657
658 for (p = &Line[Point], i = End - (Point + count) + 1; --i >= 0; p++)
659 p[0] = p[count];
660 ceol();
661 End -= count;
662 TTYstring(&Line[Point]);
663 return CSmove;
664}
665
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000666static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000667bk_char(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000668{
669 int i;
670
671 i = 0;
672 do {
673 if (Point == 0)
674 break;
675 left(CSmove);
676 } while (++i < Repeat);
677
678 return CSstay;
679}
680
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000681static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000682bk_del_char(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000683{
684 int i;
685
686 i = 0;
687 do {
688 if (Point == 0)
689 break;
690 left(CSmove);
691 } while (++i < Repeat);
692
693 return delete_string(i);
694}
695
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000696static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000697redisplay(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000698{
699 TTYputs((CHAR *)NEWLINE);
700 TTYputs((CHAR *)Prompt);
701 TTYstring(Line);
702 return CSmove;
703}
704
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000705static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000706kill_line(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000707{
708 int i;
709
710 if (Repeat != NO_ARG) {
711 if (Repeat < Point) {
712 i = Point;
713 Point = Repeat;
714 reposition();
715 (void)delete_string(i - Point);
716 }
717 else if (Repeat > Point) {
718 right(CSmove);
719 (void)delete_string(Repeat - Point - 1);
720 }
721 return CSmove;
722 }
723
724 save_yank(Point, End - Point);
725 Line[Point] = '\0';
726 ceol();
727 End = Point;
728 return CSstay;
729}
730
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000731static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000732insert_char(int c)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000733{
734 STATUS s;
735 CHAR buff[2];
736 CHAR *p;
737 CHAR *q;
738 int i;
739
740 if (Repeat == NO_ARG || Repeat < 2) {
741 buff[0] = c;
742 buff[1] = '\0';
743 return insert_string(buff);
744 }
745
746 if ((p = NEW(CHAR, Repeat + 1)) == NULL)
747 return CSstay;
748 for (i = Repeat, q = p; --i >= 0; )
749 *q++ = c;
750 *q = '\0';
751 Repeat = 0;
752 s = insert_string(p);
753 DISPOSE(p);
754 return s;
755}
756
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000757static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000758meta(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000759{
760 unsigned int c;
761 KEYMAP *kp;
762
763 if ((c = TTYget()) == EOF)
764 return CSeof;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000765 /* Also include VT-100 arrows. */
766 if (c == '[' || c == 'O')
767 switch (c = TTYget()) {
768 default: return ring_bell();
769 case EOF: return CSeof;
770 case 'A': return h_prev();
771 case 'B': return h_next();
772 case 'C': return fd_char();
773 case 'D': return bk_char();
774 }
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000775
776 if (isdigit(c)) {
777 for (Repeat = c - '0'; (c = TTYget()) != EOF && isdigit(c); )
778 Repeat = Repeat * 10 + c - '0';
779 Pushed = 1;
780 PushBack = c;
781 return CSstay;
782 }
783
784 if (isupper(c))
785 return do_macro(c);
786 for (OldPoint = Point, kp = MetaMap; kp->Function; kp++)
787 if (kp->Key == c)
788 return (*kp->Function)();
789
790 return ring_bell();
791}
792
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000793static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000794emacs(unsigned int c)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000795{
796 STATUS s;
797 KEYMAP *kp;
798
799 if (ISMETA(c)) {
800 Pushed = 1;
801 PushBack = UNMETA(c);
802 return meta();
803 }
804 for (kp = Map; kp->Function; kp++)
805 if (kp->Key == c)
806 break;
807 s = kp->Function ? (*kp->Function)() : insert_char((int)c);
808 if (!Pushed)
809 /* No pushback means no repeat count; hacky, but true. */
810 Repeat = NO_ARG;
811 return s;
812}
813
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000814static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000815TTYspecial(unsigned int c)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000816{
817 if (ISMETA(c))
818 return CSdispatch;
819
820 if (c == rl_erase || c == DEL)
821 return bk_del_char();
822 if (c == rl_kill) {
823 if (Point != 0) {
824 Point = 0;
825 reposition();
826 }
827 Repeat = NO_ARG;
828 return kill_line();
829 }
830 if (c == rl_intr || c == rl_quit) {
831 Point = End = 0;
832 Line[0] = '\0';
833 return redisplay();
834 }
835 if (c == rl_eof && Point == 0 && End == 0)
836 return CSeof;
837
838 return CSdispatch;
839}
840
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000841static CHAR *
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000842editinput(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000843{
844 unsigned int c;
845
846 Repeat = NO_ARG;
847 OldPoint = Point = Mark = End = 0;
848 Line[0] = '\0';
849
850 while ((c = TTYget()) != EOF)
851 switch (TTYspecial(c)) {
852 case CSdone:
853 return Line;
854 case CSeof:
855 return NULL;
856 case CSmove:
857 reposition();
858 break;
859 case CSdispatch:
860 switch (emacs(c)) {
861 case CSdone:
862 return Line;
863 case CSeof:
864 return NULL;
865 case CSmove:
866 reposition();
867 break;
868 case CSdispatch:
869 case CSstay:
870 break;
871 }
872 break;
873 case CSstay:
874 break;
875 }
876 return NULL;
877}
878
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000879static void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000880hist_add(CHAR *p)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000881{
882 int i;
883
Ove Kaavendda17c61999-04-25 12:24:42 +0000884 if ((p = (CHAR *)DBG_strdup((char *)p)) == NULL)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000885 return;
886 if (H.Size < HIST_SIZE)
887 H.Lines[H.Size++] = p;
888 else {
889 DISPOSE(H.Lines[0]);
890 for (i = 0; i < HIST_SIZE - 1; i++)
891 H.Lines[i] = H.Lines[i + 1];
892 H.Lines[i] = p;
893 }
894 H.Pos = H.Size - 1;
895}
896
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000897char *
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000898readline(const char *prompt)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000899{
900 CHAR *line;
901
902 if (Line == NULL) {
903 Length = MEM_INC;
904 if ((Line = NEW(CHAR, Length)) == NULL)
905 return NULL;
906 }
907
908 TTYinfo();
909 rl_ttyset(0);
910 hist_add(NIL);
911 ScreenSize = SCREEN_INC;
912 Screen = NEW(char, ScreenSize);
913 Prompt = prompt ? prompt : (char *)NIL;
914 TTYputs((CHAR *)Prompt);
915 if ((line = editinput()) != NULL) {
Ove Kaavendda17c61999-04-25 12:24:42 +0000916 line = (CHAR *)DBG_strdup((char *)line);
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000917 TTYputs((CHAR *)NEWLINE);
918 TTYflush();
919 }
920 rl_ttyset(1);
921 DISPOSE(Screen);
922 DISPOSE(H.Lines[--H.Size]);
923 return (char *)line;
924}
925
926void
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000927add_history(char *p)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000928{
929 if (p == NULL || *p == '\0')
930 return;
931
932#if defined(UNIQUE_HISTORY)
933 if (H.Pos && strcmp(p, H.Lines[H.Pos - 1]) == 0)
934 return;
935#endif /* defined(UNIQUE_HISTORY) */
936 hist_add((CHAR *)p);
937}
938
939
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000940static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000941beg_line(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000942{
943 if (Point) {
944 Point = 0;
945 return CSmove;
946 }
947 return CSstay;
948}
949
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000950static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000951del_char(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000952{
953 return delete_string(Repeat == NO_ARG ? 1 : Repeat);
954}
955
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000956static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000957end_line(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000958{
959 if (Point != End) {
960 Point = End;
961 return CSmove;
962 }
963 return CSstay;
964}
965
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000966static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000967accept_line(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000968{
969 Line[End] = '\0';
970 return CSdone;
971}
972
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000973static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000974transpose(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000975{
976 CHAR c;
977
978 if (Point) {
979 if (Point == End)
980 left(CSmove);
981 c = Line[Point - 1];
982 left(CSstay);
983 Line[Point - 1] = Line[Point];
984 TTYshow(Line[Point - 1]);
985 Line[Point++] = c;
986 TTYshow(c);
987 }
988 return CSstay;
989}
990
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000991static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000992quote(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000993{
994 unsigned int c;
995
996 return (c = TTYget()) == EOF ? CSeof : insert_char((int)c);
997}
998
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000999static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001000wipe(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001001{
1002 int i;
1003
1004 if (Mark > End)
1005 return ring_bell();
1006
1007 if (Point > Mark) {
1008 i = Point;
1009 Point = Mark;
1010 Mark = i;
1011 reposition();
1012 }
1013
1014 return delete_string(Mark - Point);
1015}
1016
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001017static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001018mk_set(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001019{
1020 Mark = Point;
1021 return CSstay;
1022}
1023
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001024static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001025exchange(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001026{
1027 unsigned int c;
1028
1029 if ((c = TTYget()) != CTL('X'))
1030 return c == EOF ? CSeof : ring_bell();
1031
1032 if ((c = Mark) <= End) {
1033 Mark = Point;
1034 Point = c;
1035 return CSmove;
1036 }
1037 return CSstay;
1038}
1039
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001040static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001041yank(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001042{
1043 if (Yanked && *Yanked)
1044 return insert_string(Yanked);
1045 return CSstay;
1046}
1047
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001048static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001049copy_region(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001050{
1051 if (Mark > End)
1052 return ring_bell();
1053
1054 if (Point > Mark)
1055 save_yank(Mark, Point - Mark);
1056 else
1057 save_yank(Point, Mark - Point);
1058
1059 return CSstay;
1060}
1061
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001062static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001063move_to_char(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001064{
1065 unsigned int c;
1066 int i;
1067 CHAR *p;
1068
1069 if ((c = TTYget()) == EOF)
1070 return CSeof;
1071 for (i = Point + 1, p = &Line[i]; i < End; i++, p++)
1072 if (*p == c) {
1073 Point = i;
1074 return CSmove;
1075 }
1076 return CSstay;
1077}
1078
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001079static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001080fd_word(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001081{
1082 return do_forward(CSmove);
1083}
1084
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001085static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001086fd_kill_word(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001087{
1088 int i;
1089
1090 (void)do_forward(CSstay);
1091 if (OldPoint != Point) {
1092 i = Point - OldPoint;
1093 Point = OldPoint;
1094 return delete_string(i);
1095 }
1096 return CSstay;
1097}
1098
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001099static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001100bk_word(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001101{
1102 int i;
1103 CHAR *p;
1104
1105 i = 0;
1106 do {
1107 for (p = &Line[Point]; p > Line && !isalnum(p[-1]); p--)
1108 left(CSmove);
1109
1110 for (; p > Line && p[-1] != ' ' && isalnum(p[-1]); p--)
1111 left(CSmove);
1112
1113 if (Point == 0)
1114 break;
1115 } while (++i < Repeat);
1116
1117 return CSstay;
1118}
1119
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001120static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001121bk_kill_word(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001122{
1123 (void)bk_word();
1124 if (OldPoint != Point)
1125 return delete_string(OldPoint - Point);
1126 return CSstay;
1127}
1128
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001129static int
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001130argify(CHAR *line, CHAR ***avp)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001131{
1132 CHAR *c;
1133 CHAR **p;
1134 CHAR **new;
1135 int ac;
1136 int i;
1137
1138 i = MEM_INC;
1139 if ((*avp = p = NEW(CHAR*, i))== NULL)
1140 return 0;
1141
1142 for (c = line; isspace(*c); c++)
1143 continue;
1144 if (*c == '\n' || *c == '\0')
1145 return 0;
1146
1147 for (ac = 0, p[ac++] = c; *c && *c != '\n'; ) {
1148 if (isspace(*c)) {
1149 *c++ = '\0';
1150 if (*c && *c != '\n') {
1151 if (ac + 1 == i) {
1152 new = NEW(CHAR*, i + MEM_INC);
1153 if (new == NULL) {
1154 p[ac] = NULL;
1155 return ac;
1156 }
1157 COPYFROMTO(new, p, i * sizeof (char **));
1158 i += MEM_INC;
1159 DISPOSE(p);
1160 *avp = p = new;
1161 }
1162 p[ac++] = c;
1163 }
1164 }
1165 else
1166 c++;
1167 }
1168 *c = '\0';
1169 p[ac] = NULL;
1170 return ac;
1171}
1172
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001173static STATUS
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001174last_argument(void)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001175{
1176 CHAR **av;
1177 CHAR *p;
1178 STATUS s;
1179 int ac;
1180
1181 if (H.Size == 1 || (p = H.Lines[H.Size - 2]) == NULL)
1182 return ring_bell();
1183
Ove Kaavendda17c61999-04-25 12:24:42 +00001184 if ((p = (CHAR *)DBG_strdup((char *)p)) == NULL)
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001185 return CSstay;
1186 ac = argify(p, &av);
1187
1188 if (Repeat != NO_ARG)
1189 s = Repeat < ac ? insert_string(av[Repeat]) : ring_bell();
1190 else
1191 s = ac ? insert_string(av[ac - 1]) : CSstay;
1192
1193 if (ac)
1194 DISPOSE(av);
1195 DISPOSE(p);
1196 return s;
1197}
1198
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001199static KEYMAP Map[33] = {
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001200 { CTL('@'), ring_bell },
1201 { CTL('A'), beg_line },
1202 { CTL('B'), bk_char },
1203 { CTL('D'), del_char },
1204 { CTL('E'), end_line },
1205 { CTL('F'), fd_char },
1206 { CTL('G'), ring_bell },
1207 { CTL('H'), bk_del_char },
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00001208 { CTL('I'), ring_bell },
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001209 { CTL('J'), accept_line },
1210 { CTL('K'), kill_line },
1211 { CTL('L'), redisplay },
1212 { CTL('M'), accept_line },
1213 { CTL('N'), h_next },
1214 { CTL('O'), ring_bell },
1215 { CTL('P'), h_prev },
1216 { CTL('Q'), ring_bell },
1217 { CTL('R'), h_search },
1218 { CTL('S'), ring_bell },
1219 { CTL('T'), transpose },
1220 { CTL('U'), ring_bell },
1221 { CTL('V'), quote },
1222 { CTL('W'), wipe },
1223 { CTL('X'), exchange },
1224 { CTL('Y'), yank },
1225 { CTL('Z'), ring_bell },
1226 { CTL('['), meta },
1227 { CTL(']'), move_to_char },
1228 { CTL('^'), ring_bell },
1229 { CTL('_'), ring_bell },
1230 { 0, NULL }
1231};
1232
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001233static KEYMAP MetaMap[16]= {
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001234 { CTL('H'), bk_kill_word },
1235 { DEL, bk_kill_word },
1236 { ' ', mk_set },
1237 { '.', last_argument },
1238 { '<', h_first },
1239 { '>', h_last },
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00001240 { '?', ring_bell },
Alexandre Julliardf0b23541993-09-29 12:21:49 +00001241 { 'b', bk_word },
1242 { 'd', fd_kill_word },
1243 { 'f', fd_word },
1244 { 'l', case_down_word },
1245 { 'u', case_up_word },
1246 { 'y', yank },
1247 { 'w', copy_region },
1248 { 0, NULL }
1249};