winio.c 41.6 KB
Newer Older
Chris Allegretta's avatar
Chris Allegretta committed
1
/* $Id$ */
Chris Allegretta's avatar
Chris Allegretta committed
2
3
4
5
6
7
/**************************************************************************
 *   winio.c                                                              *
 *                                                                        *
 *   Copyright (C) 1999 Chris Allegretta                                  *
 *   This program is free software; you can redistribute it and/or modify *
 *   it under the terms of the GNU General Public License as published by *
8
 *   the Free Software Foundation; either version 2, or (at your option)  *
Chris Allegretta's avatar
Chris Allegretta committed
9
10
11
12
13
14
15
16
17
18
19
20
21
 *   any later version.                                                   *
 *                                                                        *
 *   This program is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
 *   GNU General Public License for more details.                         *
 *                                                                        *
 *   You should have received a copy of the GNU General Public License    *
 *   along with this program; if not, write to the Free Software          *
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
 *                                                                        *
 **************************************************************************/

22
23
#include "config.h"

Chris Allegretta's avatar
Chris Allegretta committed
24
25
#include <stdarg.h>
#include <string.h>
26
#include <stdlib.h>
27
#include <unistd.h>
Chris Allegretta's avatar
Chris Allegretta committed
28
29
30
31
32
33
34
35
36
37
#include "proto.h"
#include "nano.h"

#ifndef NANO_SMALL
#include <libintl.h>
#define _(string) gettext(string)
#else
#define _(string) (string)
#endif

38
39

/* winio.c statics */
Chris Allegretta's avatar
Chris Allegretta committed
40
static int statblank = 0;	/* Number of keystrokes left after
41
				   we call statusbar(), before we
Chris Allegretta's avatar
Chris Allegretta committed
42
				   actually blank the statusbar */
43
44
45
46
47
48

/* Local Function Prototypes for only winio.c */
inline int get_page_from_virtual(int virtual);
inline int get_page_start_virtual(int page);
inline int get_page_end_virtual(int page);

Chris Allegretta's avatar
Chris Allegretta committed
49
50
51
52
53
54
55
/* Window I/O */

int do_first_line(void)
{
    current = fileage;
    placewewant = 0;
    current_x = 0;
56
    edit_update(current, CENTER);
Chris Allegretta's avatar
Chris Allegretta committed
57
58
59
60
61
62
63
64
    return 1;
}

int do_last_line(void)
{
    current = filebot;
    placewewant = 0;
    current_x = 0;
65
    edit_update(current, CENTER);
Chris Allegretta's avatar
Chris Allegretta committed
66
67
68
    return 1;
}

69
/* Like xplustabs, but for a specific index of a specific filestruct */
Chris Allegretta's avatar
Chris Allegretta committed
70
71
72
73
74
75
76
77
78
79
80
int xpt(filestruct * fileptr, int index)
{
    int i, tabs = 0;

    if (fileptr == NULL || fileptr->data == NULL)
	return 0;

    for (i = 0; i < index && fileptr->data[i] != 0; i++) {
	tabs++;

	if (fileptr->data[i] == NANO_CONTROL_I) {
81
	    if (tabs % tabsize == 0);
Chris Allegretta's avatar
Chris Allegretta committed
82
	    else
83
		tabs += tabsize - (tabs % tabsize);
Chris Allegretta's avatar
Chris Allegretta committed
84
	} else if (fileptr->data[i] & 0x80)
85
	    /* Make 8 bit chars only 1 column! */
Chris Allegretta's avatar
Chris Allegretta committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	    ;
	else if (fileptr->data[i] < 32)
	    tabs++;
    }

    return tabs;
}


/* Return the actual place on the screen of current->data[current_x], which 
   should always be > current_x */
int xplustabs(void)
{
    return xpt(current, current_x);
}


103
104
105
/* Return what current_x should be, given xplustabs() for the line, 
 * given a start position in the filestruct's data */
int actual_x_from_start(filestruct * fileptr, int xplus, int start)
Chris Allegretta's avatar
Chris Allegretta committed
106
{
107
    int i, tot = 1;
Chris Allegretta's avatar
Chris Allegretta committed
108
109
110
111

    if (fileptr == NULL || fileptr->data == NULL)
	return 0;

Chris Allegretta's avatar
Chris Allegretta committed
112
    for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++)
113
	if (fileptr->data[i] == NANO_CONTROL_I) {
114
	    if (tot % tabsize == 0)
Chris Allegretta's avatar
Chris Allegretta committed
115
116
		tot++;
	    else
117
		tot += tabsize - (tot % tabsize);
118
119
120
	} else if (fileptr->data[i] & 0x80)
	    tot++;		/* Make 8 bit chars only 1 column (again) */
	else if (fileptr->data[i] < 32)
Chris Allegretta's avatar
Chris Allegretta committed
121
122
123
	    tot += 2;

#ifdef DEBUG
Chris Allegretta's avatar
Chris Allegretta committed
124
125
    fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"),
	    xplus, i);
Chris Allegretta's avatar
Chris Allegretta committed
126
#endif
127
128
129
130
    return i - start;
}

/* Opposite of xplustabs */
131
int actual_x(filestruct * fileptr, int xplus)
132
133
{
    return actual_x_from_start(fileptr, xplus, 0);
Chris Allegretta's avatar
Chris Allegretta committed
134
135
136
137
138
139
140
141
142
143
144
145
146
147
}

/* a strlen with tabs factored in, similar to xplustabs() */
int strlenpt(char *buf)
{
    int i, tabs = 0;

    if (buf == NULL)
	return 0;

    for (i = 0; buf[i] != 0; i++) {
	tabs++;

	if (buf[i] == NANO_CONTROL_I) {
148
	    if (tabs % tabsize == 0);
Chris Allegretta's avatar
Chris Allegretta committed
149
	    else
150
		tabs += tabsize - (tabs % tabsize);
Chris Allegretta's avatar
Chris Allegretta committed
151
	} else if (buf[i] & 0x80)
152
	    /* Make 8 bit chars only 1 column! */
Chris Allegretta's avatar
Chris Allegretta committed
153
154
155
156
157
158
159
160
161
	    ;
	else if (buf[i] < 32)
	    tabs++;
    }

    return tabs;
}


162
/* resets current_y, based on the position of current, and puts the cursor at 
Chris Allegretta's avatar
Chris Allegretta committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
   (current_y, current_x) */
void reset_cursor(void)
{
    filestruct *ptr = edittop;
    int x;

    current_y = 0;

    while (ptr != current && ptr != editbot && ptr->next != NULL) {
	ptr = ptr->next;
	current_y++;
    }

    x = xplustabs();
    if (x <= COLS - 2)
178
	wmove(edit, current_y, x);
Chris Allegretta's avatar
Chris Allegretta committed
179
    else
180
	wmove(edit, current_y, x -
Chris Allegretta's avatar
Chris Allegretta committed
181
	      get_page_start_virtual(get_page_from_virtual(x)));
Chris Allegretta's avatar
Chris Allegretta committed
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

}

void blank_bottombars(void)
{
    int i = no_help()? 3 : 1;

    for (; i <= 2; i++)
	mvwaddstr(bottomwin, i, 0, hblank);

}

void blank_edit(void)
{
    int i;
    for (i = 0; i <= editwinrows - 1; i++)
	mvwaddstr(edit, i, 0, hblank);
}


void blank_statusbar(void)
{
    mvwaddstr(bottomwin, 0, 0, hblank);
}

void blank_statusbar_refresh(void)
{
    blank_statusbar();
    wrefresh(bottomwin);
}

void check_statblank(void)
{

    if (statblank > 1)
	statblank--;
    else if (statblank == 1 && !ISSET(CONSTUPDATE)) {
	statblank--;
	blank_statusbar_refresh();
    }
}

224
225
226
/* Repaint the statusbar when getting a character in nanogetstr */
void nanoget_repaint(char *buf, char *inputbuf, int x)
{
227
228
    int len = strlen(buf);
    int wid = COLS - len;
229

230
231
#ifdef ENABLE_COLOR
    color_on(bottomwin, COLOR_STATUSBAR);
232
233
#else
    wattron(bottomwin, A_REVERSE);
234
#endif
235
    blank_statusbar();
236

237
238
239
    if (x <= COLS - 1) {
	/* Black magic */
	buf[len - 1] = ' ';
240

241
242
243
244
245
246
247
	mvwaddstr(bottomwin, 0, 0, buf);
	waddnstr(bottomwin, inputbuf, wid);
	wmove(bottomwin, 0, (x % COLS));
    }
    else {
	/* Black magic */
	buf[len - 1] = '$';
248

249
250
251
252
	mvwaddstr(bottomwin, 0, 0, buf);
	waddnstr(bottomwin, &inputbuf[wid * ((x - len) / (wid))], wid);
	wmove(bottomwin, 0, ((x - len) % wid) + len);
    }
253
254
255

#ifdef ENABLE_COLOR
    color_off(bottomwin, COLOR_STATUSBAR);
256
257
#else
    wattroff(bottomwin, A_REVERSE);
258
#endif
259
260
}

261
/* Get the input from the kb; this should only be called from statusq */
262
int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen, 
263
	       int start_x, int list)
Chris Allegretta's avatar
Chris Allegretta committed
264
265
{
    int kbinput = 0, j = 0, x = 0, xend;
266
    int x_left = 0, inputlen, tabbed = 0;
267
    char *inputbuf;
268
#ifndef DISABLE_TABCOMP
269
270
    int shift = 0;
#endif
271
    
272
    inputbuf = charalloc(strlen(def) + 1);
273
    inputbuf[0] = 0;
Chris Allegretta's avatar
Chris Allegretta committed
274
275
276
277

    x_left = strlen(buf);
    x = strlen(def) + x_left;

278
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
279
280
    currshortcut = s;
    currslen = slen;
281
282
#endif

Chris Allegretta's avatar
Chris Allegretta committed
283
    /* Get the input! */
284
    if (strlen(def) > 0)
Chris Allegretta's avatar
Chris Allegretta committed
285
	strcpy(inputbuf, def);
286
287

    nanoget_repaint(buf, inputbuf, x);
Chris Allegretta's avatar
Chris Allegretta committed
288

289
290
291
    /* Make sure any editor screen updates are displayed before getting input */
    wrefresh(edit);

Chris Allegretta's avatar
Chris Allegretta committed
292
293
    while ((kbinput = wgetch(bottomwin)) != 13) {
	for (j = 0; j <= slen - 1; j++) {
294
295
296
297
#ifdef DEBUG
	    fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
#endif

298
	    if (kbinput == s[j].val && kbinput < 32) {
299

300
301
302
303
304
305
306
307
308
#ifndef DISABLE_HELP
		/* Have to do this here, it would be too late to do it in statusq */
		if (kbinput == NANO_HELP_KEY 
		    || kbinput == NANO_HELP_FKEY) {
		    do_help();
		    break;
		}
#endif

309
310
311
		/* We shouldn't discard the answer it gave, just because
		   we hit a keystroke, GEEZ! */
		answer = mallocstrcpy(answer, inputbuf);
312
		free(inputbuf);
Chris Allegretta's avatar
Chris Allegretta committed
313
314
315
316
317
		return s[j].val;
	    }
	}
	xend = strlen(buf) + strlen(inputbuf);

Chris Allegretta's avatar
Chris Allegretta committed
318
319
320
	if (kbinput != '\t')
	    tabbed = 0;

Chris Allegretta's avatar
Chris Allegretta committed
321
	switch (kbinput) {
322
323

	/* Stuff we want to equate with <enter>, ASCII 13 */
324
	case 343:
325
326
	    ungetch(13);	/* Enter on iris-ansi $TERM, sometimes */
	    break;
327
	/* Stuff we want to ignore */
328
329
330
#ifdef PDCURSES
	case 541:
	case 542:
331
	case 543:			/* Right ctrl again */
332
	case 544:
333
	case 545: 			/* Right alt again */
334
335
	    break;
#endif
336
#ifndef DISABLE_MOUSE
337
338
339
340
341
#ifdef NCURSES_MOUSE_VERSION
	case KEY_MOUSE:
	    do_mouse();
	    break;
#endif
342
#endif
343
	case NANO_HOME_KEY:
Chris Allegretta's avatar
Chris Allegretta committed
344
345
346
	case KEY_HOME:
	    x = x_left;
	    break;
347
	case NANO_END_KEY:
Chris Allegretta's avatar
Chris Allegretta committed
348
349
350
351
	case KEY_END:
	    x = x_left + strlen(inputbuf);
	    break;
	case KEY_RIGHT:
352
	case NANO_FORWARD_KEY:
Chris Allegretta's avatar
Chris Allegretta committed
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383

	    if (x < xend)
		x++;
	    wmove(bottomwin, 0, x);
	    break;
	case NANO_CONTROL_D:
	    if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
		memmove(inputbuf + (x - x_left),
			inputbuf + (x - x_left) + 1,
			strlen(inputbuf) - (x - x_left) - 1);
		inputbuf[strlen(inputbuf) - 1] = 0;
	    }
	    break;
	case NANO_CONTROL_K:
	case NANO_CONTROL_U:
	    *inputbuf = 0;
	    x = x_left;
	    break;
	case KEY_BACKSPACE:
	case 127:
	case NANO_CONTROL_H:
	    if (strlen(inputbuf) > 0) {
		if (x == (x_left + strlen(inputbuf)))
		    inputbuf[strlen(inputbuf) - 1] = 0;
		else if (x - x_left) {
		    memmove(inputbuf + (x - x_left) - 1,
			    inputbuf + (x - x_left),
			    strlen(inputbuf) - (x - x_left));
		    inputbuf[strlen(inputbuf) - 1] = 0;
		}
	    }
Chris Allegretta's avatar
Chris Allegretta committed
384
385
386
	    if (x > strlen(buf))
		x--;
	    break;
387
#ifndef DISABLE_TABCOMP
Chris Allegretta's avatar
Chris Allegretta committed
388
	case NANO_CONTROL_I:
389
	    if (allowtabs) {
390
391
		shift = 0;
		inputbuf = input_tab(inputbuf, (x - x_left), 
392
				&tabbed, &shift, &list);
393
		x += shift;
394
395
		if (x - x_left > strlen(inputbuf))
		    x = strlen(inputbuf) + x_left;
396
	    }
Chris Allegretta's avatar
Chris Allegretta committed
397
	    break;
398
#endif
Chris Allegretta's avatar
Chris Allegretta committed
399
	case KEY_LEFT:
400
	case NANO_BACK_KEY:
Chris Allegretta's avatar
Chris Allegretta committed
401
402
403
404
405
406
407
408
	    if (x > strlen(buf))
		x--;
	    wmove(bottomwin, 0, x);
	    break;
	case KEY_UP:
	case KEY_DOWN:
	    break;

409
410
411
	case KEY_DC:
	    goto do_deletekey;

Chris Allegretta's avatar
Chris Allegretta committed
412
413
	case 27:
	    switch (kbinput = wgetch(edit)) {
414
	    case 'O':
Chris Allegretta's avatar
Chris Allegretta committed
415
		switch (kbinput = wgetch(edit)) {
416
		case 'F':
Chris Allegretta's avatar
Chris Allegretta committed
417
418
		    x = x_left + strlen(inputbuf);
		    break;
419
		case 'H':
Chris Allegretta's avatar
Chris Allegretta committed
420
421
422
423
		    x = x_left;
		    break;
		}
		break;
424
	    case '[':
Chris Allegretta's avatar
Chris Allegretta committed
425
426
427
428
429
430
431
432
433
434
435
		switch (kbinput = wgetch(edit)) {
		case 'C':
		    if (x < xend)
			x++;
		    wmove(bottomwin, 0, x);
		    break;
		case 'D':
		    if (x > strlen(buf))
			x--;
		    wmove(bottomwin, 0, x);
		    break;
436
437
		case '1':
		case '7':
Chris Allegretta's avatar
Chris Allegretta committed
438
		    x = x_left;
439
440
441
		    goto skip_tilde;
		case '3':
		  do_deletekey:
Chris Allegretta's avatar
Chris Allegretta committed
442
443
444
445
446
447
448
		    if (strlen(inputbuf) > 0
			&& (x - x_left) != strlen(inputbuf)) {
			memmove(inputbuf + (x - x_left),
				inputbuf + (x - x_left) + 1,
				strlen(inputbuf) - (x - x_left) - 1);
			inputbuf[strlen(inputbuf) - 1] = 0;
		    }
449
450
451
		    goto skip_tilde;
		case '4':
		case '8':
Chris Allegretta's avatar
Chris Allegretta committed
452
		    x = x_left + strlen(inputbuf);
453
454
		    goto skip_tilde;
		  skip_tilde:
Chris Allegretta's avatar
Chris Allegretta committed
455
456
		    nodelay(edit, TRUE);
		    kbinput = wgetch(edit);
457
		    if (kbinput == '~' || kbinput == ERR)
Chris Allegretta's avatar
Chris Allegretta committed
458
459
460
461
			kbinput = -1;
		    nodelay(edit, FALSE);
		    break;
		}
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
	    default:

		for (j = 0; j <= slen - 1; j++) {
#ifdef DEBUG
	    fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
#endif
		    if (kbinput == s[j].val || kbinput == s[j].val - 32) {

			/* We hit an Alt key.   Do like above.  We don't
			   just ungetch the letter and let it get caught
			   above cause that screws the keypad... */
			answer = mallocstrcpy(answer, inputbuf);
			free(inputbuf);
			return s[j].val;
		    }
		}

Chris Allegretta's avatar
Chris Allegretta committed
479
480
481
482
	    }
	    break;

	default:
483

Chris Allegretta's avatar
Chris Allegretta committed
484
485
	    if (kbinput < 32)
		break;
486
487
488
489
490
491
492
493
494

	    inputlen = strlen(inputbuf);
	    inputbuf = nrealloc(inputbuf, inputlen + 2);

	    memmove(&inputbuf[x - x_left + 1], 
			&inputbuf[x - x_left],
                        inputlen - (x - x_left) + 1);
	    inputbuf[x - x_left] = kbinput;

Chris Allegretta's avatar
Chris Allegretta committed
495
496
497
498
499
500
	    x++;

#ifdef DEBUG
	    fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
#endif
	}
501
	nanoget_repaint(buf, inputbuf, x);
Chris Allegretta's avatar
Chris Allegretta committed
502
503
504
	wrefresh(bottomwin);
    }

505
    answer = mallocstrcpy(answer, inputbuf);
506
    free(inputbuf);
Chris Allegretta's avatar
Chris Allegretta committed
507

Chris Allegretta's avatar
Chris Allegretta committed
508
509
    /* In pico mode, just check for a blank answer here */
    if  (((ISSET(PICO_MODE)) && !strcmp(answer, "")))
Chris Allegretta's avatar
Chris Allegretta committed
510
511
512
513
514
515
516
517
518
519
520
521
	return -2;
    else
	return 0;
}

void horizbar(WINDOW * win, int y)
{
    wattron(win, A_REVERSE);
    mvwaddstr(win, 0, 0, hblank);
    wattroff(win, A_REVERSE);
}

Chris Allegretta's avatar
Chris Allegretta committed
522
void titlebar(char *path)
Chris Allegretta's avatar
Chris Allegretta committed
523
524
{
    int namelen, space;
Chris Allegretta's avatar
Chris Allegretta committed
525
526
527
528
    char *what = path;

    if (path == NULL)
	what = filename;
Chris Allegretta's avatar
Chris Allegretta committed
529

530
531
532
533
#ifdef ENABLE_COLOR
    color_on(topwin, COLOR_TITLEBAR);
    mvwaddstr(topwin, 0, 0, hblank);
#else
Chris Allegretta's avatar
Chris Allegretta committed
534
535
    horizbar(topwin, 0);
    wattron(topwin, A_REVERSE);
536
537
538
#endif


Chris Allegretta's avatar
Chris Allegretta committed
539
540
541
542
    mvwaddstr(topwin, 0, 3, VERMSG);

    space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;

Chris Allegretta's avatar
Chris Allegretta committed
543
    namelen = strlen(what);
Chris Allegretta's avatar
Chris Allegretta committed
544

Chris Allegretta's avatar
Chris Allegretta committed
545
    if (!strcmp(what, ""))
546
	mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer"));
Chris Allegretta's avatar
Chris Allegretta committed
547
548
    else {
	if (namelen > space) {
Chris Allegretta's avatar
Chris Allegretta committed
549
550
551
552
553
	    if (path == NULL)
		waddstr(topwin, _("  File: ..."));
	    else
		waddstr(topwin, _("   DIR: ..."));
	    waddstr(topwin, &what[namelen - space]);
Chris Allegretta's avatar
Chris Allegretta committed
554
	} else {
Chris Allegretta's avatar
Chris Allegretta committed
555
	    if (path == NULL)
556
		mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), "File: ");
Chris Allegretta's avatar
Chris Allegretta committed
557
	    else
558
	 	mvwaddstr(topwin, 0, COLS / 2 - (namelen / 2 + 1), " DIR: ");
Chris Allegretta's avatar
Chris Allegretta committed
559
	    waddstr(topwin, what);
Chris Allegretta's avatar
Chris Allegretta committed
560
561
562
563
	}
    }
    if (ISSET(MODIFIED))
	mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
564
565
566
567
568


#ifdef ENABLE_COLOR
    color_off(topwin, COLOR_TITLEBAR);
#else
Chris Allegretta's avatar
Chris Allegretta committed
569
    wattroff(topwin, A_REVERSE);
570
571
#endif

Chris Allegretta's avatar
Chris Allegretta committed
572
573
574
575
576
577
578
579
    wrefresh(topwin);
    reset_cursor();
}

void onekey(char *keystroke, char *desc)
{
    char description[80];

580
    snprintf(description, 12 - (strlen(keystroke) - 2), " %-10s", desc);
Chris Allegretta's avatar
Chris Allegretta committed
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
    wattron(bottomwin, A_REVERSE);
    waddstr(bottomwin, keystroke);
    wattroff(bottomwin, A_REVERSE);
    waddstr(bottomwin, description);
}

void clear_bottomwin(void)
{
    if (ISSET(NO_HELP))
	return;

    mvwaddstr(bottomwin, 1, 0, hblank);
    mvwaddstr(bottomwin, 2, 0, hblank);
}

void bottombars(shortcut s[], int slen)
{
    int i, j, k;
    char keystr[10];

    if (ISSET(NO_HELP))
	return;

604
605
606
607
#ifdef ENABLE_COLOR    
    color_on(bottomwin, COLOR_BOTTOMBARS);
#endif

Chris Allegretta's avatar
Chris Allegretta committed
608
    /* Determine how many extra spaces are needed to fill the bottom of the screen */
609
610
611
    if (slen < 2)
	k = COLS / 6 - 13;
    else
612
	k = COLS / ((slen + (slen %2)) / 2) - 13;
613

Chris Allegretta's avatar
Chris Allegretta committed
614
615
616

    clear_bottomwin();
    wmove(bottomwin, 1, 0);
617

618
    for (i = 0; i <= slen - 1; i += 2) {
619
620
621
622
623
624

	if (s[i].val < 97)
	    snprintf(keystr, 10, "^%c", s[i].val + 64);
	else
	    snprintf(keystr, 10, "M-%c", s[i].val - 32);

Chris Allegretta's avatar
Chris Allegretta committed
625
626
627
628
629
630
631
632
	onekey(keystr, s[i].desc);

	for (j = 0; j < k; j++)
	    waddch(bottomwin, ' ');
    }

    wmove(bottomwin, 2, 0);
    for (i = 1; i <= slen - 1; i += 2) {
633
634
635
636
637
638

	if (s[i].val < 97)
	    snprintf(keystr, 10, "^%c", s[i].val + 64);
	else
	    snprintf(keystr, 10, "M-%c", s[i].val - 32);

Chris Allegretta's avatar
Chris Allegretta committed
639
640
641
642
643
644
	onekey(keystr, s[i].desc);

	for (j = 0; j < k; j++)
	    waddch(bottomwin, ' ');
    }

645
646
647
648
#ifdef ENABLE_COLOR    
    color_off(bottomwin, COLOR_BOTTOMBARS);
#endif

Chris Allegretta's avatar
Chris Allegretta committed
649
650
651
652
653
654
655
656
657
    wrefresh(bottomwin);

}

/* If modified is not already set, set it and update titlebar */
void set_modified(void)
{
    if (!ISSET(MODIFIED)) {
	SET(MODIFIED);
Chris Allegretta's avatar
Chris Allegretta committed
658
	titlebar(NULL);
Chris Allegretta's avatar
Chris Allegretta committed
659
660
661
662
	wrefresh(topwin);
    }
}

663
664
665
/* And so start the display update routines */
/* Given a column, this returns the "page" it is on  */
/* "page" in the case of the display columns, means which set of 80 */
666
/* characters is viewable (e.g.: page 1 shows from 1 to COLS) */
Chris Allegretta's avatar
Chris Allegretta committed
667
668
inline int get_page_from_virtual(int virtual)
{
669
    int page = 2;
Chris Allegretta's avatar
Chris Allegretta committed
670

Chris Allegretta's avatar
Chris Allegretta committed
671
672
    if (virtual <= COLS - 2)
	return 1;
673
    virtual -= (COLS - 2);
674
675

    while (virtual > COLS - 2 - 7) {
676
	virtual -= (COLS - 2 - 7);
677
	page++;
Chris Allegretta's avatar
Chris Allegretta committed
678
679
    }

680
681
682
    return page;
}

683
/* The inverse of the above function */
Chris Allegretta's avatar
Chris Allegretta committed
684
685
inline int get_page_start_virtual(int page)
{
686
687
    int virtual;
    virtual = --page * (COLS - 7);
Chris Allegretta's avatar
Chris Allegretta committed
688
689
    if (page)
	virtual -= 2 * page - 1;
690
    return virtual;
691
692
}

Chris Allegretta's avatar
Chris Allegretta committed
693
694
inline int get_page_end_virtual(int page)
{
695
696
697
698
    return get_page_start_virtual(page) + COLS - 1;
}

#ifndef NANO_SMALL
699
700
701
/* This takes care of the case where there is a mark that covers only */
/* the current line. */

702
/* It expects a line with no tab characters (i.e.: the type that edit_add */
703
/* deals with */
Chris Allegretta's avatar
Chris Allegretta committed
704
705
void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
			 int virt_cur_x, int this_page)
706
{
707
708
709
    /*
     * The general idea is to break the line up into 3 sections: before
     * the mark, the mark, and after the mark.  We then paint each in
710
     * turn (for those that are currently visible, of course)
711
712
713
714
     *
     * 3 start points: 0 -> begin, begin->end, end->strlen(data)
     *    in data    :    pre          sel           post        
     */
Chris Allegretta's avatar
Chris Allegretta committed
715
    int this_page_start = get_page_start_virtual(this_page),
716
	this_page_end = get_page_end_virtual(this_page);
717
718

    /* likewise, 3 data lengths */
Chris Allegretta's avatar
Chris Allegretta committed
719
    int pre_data_len = begin, sel_data_len = end - begin, post_data_len = 0;	/* Determined from the other two */
720
721

    /* now fix the start locations & lengths according to the cursor's 
722
     * position (i.e.: our page) */
Chris Allegretta's avatar
Chris Allegretta committed
723
    if (pre_data_len < this_page_start)
724
725
726
	pre_data_len = 0;
    else
	pre_data_len -= this_page_start;
727

Chris Allegretta's avatar
Chris Allegretta committed
728
    if (begin < this_page_start)
729
730
	begin = this_page_start;

Chris Allegretta's avatar
Chris Allegretta committed
731
    if (end < this_page_start)
732
	end = this_page_start;
733

Chris Allegretta's avatar
Chris Allegretta committed
734
    if (begin > this_page_end)
735
	begin = this_page_end;
736

Chris Allegretta's avatar
Chris Allegretta committed
737
    if (end > this_page_end)
738
	end = this_page_end;
739

740
    /* Now calculate the lengths */
741
742
    sel_data_len = end - begin;
    post_data_len = this_page_end - end;
743

744
745
746
#ifdef ENABLE_COLOR
    color_on(edit, COLOR_MARKER);
#else
747
    wattron(edit, A_REVERSE);
748
749
#endif /* ENABLE_COLOR */

750
    mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta's avatar
Chris Allegretta committed
751
	       &fileptr->data[begin], sel_data_len);
752
753
754
755

#ifdef ENABLE_COLOR
    color_off(edit, COLOR_MARKER);
#else
756
    wattroff(edit, A_REVERSE);
757
758
#endif /* ENABLE_COLOR */

Chris Allegretta's avatar
Chris Allegretta committed
759
760
761
}
#endif

762
763
764
765
/* edit_add takes care of the job of actually painting a line into the
 * edit window.
 * 
 * Called only from update_line.  Expects a converted-to-not-have-tabs
766
767
 * line */
void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta's avatar
Chris Allegretta committed
768
	      int virt_mark_beginx, int this_page)
Chris Allegretta's avatar
Chris Allegretta committed
769
{
770

Chris Allegretta's avatar
Chris Allegretta committed
771
#ifndef NANO_SMALL
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
    colortype *tmpcolor = NULL;
    colorstr *tmpstr = NULL;
    int k, paintlen;
#endif



    /* Just paint the string in any case (we'll add color or reverse on
	just the text that needs it */
    mvwaddnstr(edit, yval, 0, &fileptr->data[start],
	    get_page_end_virtual(this_page) - start + 1);

#ifndef NANO_SMALL
    if (colorstrings != NULL)
	for (tmpcolor = colorstrings; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
	    for (tmpstr = tmpcolor->str; tmpstr != NULL; tmpstr = tmpstr->next) {

		k = start;
		regcomp(&search_regexp, tmpstr->val, 0);
		while (!regexec(&search_regexp, &fileptr->data[k], 1, 
		    regmatches, 0)) {

#ifdef DEBUG
		    fprintf(stderr, "Match! (%d chars) \"%s\"\n",
			regmatches[0].rm_eo - regmatches[0].rm_so,
			&fileptr->data[k + regmatches[0].rm_so]);
#endif
		    if (regmatches[0].rm_so < COLS - 1) {
			if (tmpcolor->bright)
			    wattron(edit, A_BOLD);
			wattron(edit, COLOR_PAIR(tmpcolor->pairnum));

			if (regmatches[0].rm_eo - regmatches[0].rm_so 
			    + k <= COLS)
			    paintlen = regmatches[0].rm_eo - regmatches[0].rm_so;
			else
			    paintlen = COLS - (regmatches[0].rm_eo 
					-  regmatches[0].rm_so);

			mvwaddnstr(edit, yval, regmatches[0].rm_so + k,
			    &fileptr->data[k + regmatches[0].rm_so], 
			    paintlen);


		    }

		    if (tmpcolor->bright)
			wattroff(edit, A_BOLD);
		    wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));

		    k += regmatches[0].rm_eo;
		}
	    }
	}

827
    /* There are quite a few cases that could take place; we'll deal
828
     * with them each in turn */
829
830
    if (ISSET(MARK_ISSET) &&  
	!((fileptr->lineno > mark_beginbuf->lineno
831
832
833
	      && fileptr->lineno > current->lineno)
	     || (fileptr->lineno < mark_beginbuf->lineno
		 && fileptr->lineno < current->lineno))) {
834
	/* If we get here we are on a line that is at least
835
836
837
838
839
	 * partially selected.  The lineno checks above determined
	 * that */
	if (fileptr != mark_beginbuf && fileptr != current) {
	    /* We are on a completely marked line, paint it all
	     * inverse */
840
841
842
#ifdef ENABLE_COLOR
	    color_on(edit, COLOR_MARKER);
#else
843
	    wattron(edit, A_REVERSE);
844
845
#endif /* ENABLE_COLOR */

846
	    mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
847
848
849
850

#ifdef ENABLE_COLOR
	    color_off(edit, COLOR_MARKER);
#else
851
	    wattroff(edit, A_REVERSE);
852
853
#endif /* ENABLE_COLOR */

854
855
856
857
858
859
860
861
862
863
864
865
866
867
	} else if (fileptr == mark_beginbuf && fileptr == current) {
	    /* Special case, we're still on the same line we started
	     * marking -- so we call our helper function */
	    if (virt_cur_x < virt_mark_beginx) {
		/* To the right of us is marked */
		add_marked_sameline(virt_cur_x, virt_mark_beginx,
				    fileptr, yval, virt_cur_x, this_page);
	    } else {
		/* To the left of us is marked */
		add_marked_sameline(virt_mark_beginx, virt_cur_x,
				    fileptr, yval, virt_cur_x, this_page);
	    }
	} else if (fileptr == mark_beginbuf) {
	    /*
868
	     * We're updating the line that was first marked,
869
	     * but we're not currently on it.  So we want to
870
	     * figure out which half to invert based on our
871
872
	     * relative line numbers.
	     *
873
874
875
	     * I.e. if we're above the "beginbuf" line, we want to
	     * mark the left side.  Otherwise, we're below, so we
	     * mark the right.
876
877
878
	     */
	    int target;

879
880
881
882
	    if (mark_beginbuf->lineno > current->lineno) {
#ifdef ENABLE_COLOR
		color_on(edit, COLOR_MARKER);
#else
Chris Allegretta's avatar
Chris Allegretta committed
883
		wattron(edit, A_REVERSE);
884
#endif /* ENABLE_COLOR */
885

886
887
		target =
		    (virt_mark_beginx < COLS - 1) ? virt_mark_beginx : COLS - 1;
888

889
		mvwaddnstr(edit, yval, 0, fileptr->data, target);
890
891

#ifdef ENABLE_COLOR
892
		color_off(edit, COLOR_MARKER);
893
#else
894
		wattroff(edit, A_REVERSE);
895
896
897
#endif /* ENABLE_COLOR */


898
899
900
	    }

	    if (mark_beginbuf->lineno < current->lineno) {
901
#ifdef ENABLE_COLOR
902
		color_on(edit, COLOR_MARKER);
903
#else
904
		wattron(edit, A_REVERSE);
905
906
#endif /* ENABLE_COLOR */

907
		target = (COLS - 1) - virt_mark_beginx;
908

909
910
		if (target < 0)
		    target = 0;
911

912
		mvwaddnstr(edit, yval, virt_mark_beginx,
913
914
		       &fileptr->data[virt_mark_beginx], target);

915
916
917
#ifdef ENABLE_COLOR
		color_off(edit, COLOR_MARKER);
#else
918
		wattroff(edit, A_REVERSE);
919
920
921
#endif /* ENABLE_COLOR */

	    }
922
923

	} else if (fileptr == current) {
924
	    /* We're on the cursor's line, but it's not the first
925
926
927
928
	     * one we marked.  Similar to the previous logic. */
	    int this_page_start = get_page_start_virtual(this_page),
		this_page_end = get_page_end_virtual(this_page);

929
930
931
932
933
	    if (mark_beginbuf->lineno < current->lineno) {

#ifdef ENABLE_COLOR
		color_on(edit, COLOR_MARKER);
#else
934
		wattron(edit, A_REVERSE);
935
936
#endif /* ENABLE_COLOR */

937
938
		if (virt_cur_x > COLS - 2) {
		    mvwaddnstr(edit, yval, 0,
939
940
			   &fileptr->data[this_page_start],
			   virt_cur_x - this_page_start);
941
942
		} else
		    mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
943
944

#ifdef ENABLE_COLOR
945
		color_off(edit, COLOR_MARKER);
946
#else
947
		wattroff(edit, A_REVERSE);
948
949
#endif /* ENABLE_COLOR */

950
951
952
	    }

	    if (mark_beginbuf->lineno > current->lineno) {
953
954

#ifdef ENABLE_COLOR
955
		color_on(edit, COLOR_MARKER);
956
#else
957
		wattron(edit, A_REVERSE);
958
959
#endif /* ENABLE_COLOR */

960
961
		if (virt_cur_x > COLS - 2)
		    mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
962
963
			   &fileptr->data[virt_cur_x],
			   this_page_end - virt_cur_x);
964
965
		else
		    mvwaddnstr(edit, yval, virt_cur_x,
966
967
			   &fileptr->data[virt_cur_x], COLS - virt_cur_x);

968
969
970
#ifdef ENABLE_COLOR
		color_off(edit, COLOR_MARKER);
#else
971
		wattroff(edit, A_REVERSE);
972
973
974
#endif /* ENABLE_COLOR */

	    }
Chris Allegretta's avatar
Chris Allegretta committed
975
	}
976
977
978
    }
#endif

Chris Allegretta's avatar
Chris Allegretta committed
979
980
981
}

/*
982
983
 * Just update one line in the edit buffer.  Basically a wrapper for
 * edit_add
Chris Allegretta's avatar
Chris Allegretta committed
984
 *
985
 * index gives us a place in the string to update starting from.
Chris Allegretta's avatar
Chris Allegretta committed
986
987
988
989
990
 * Likely args are current_x or 0.
 */
void update_line(filestruct * fileptr, int index)
{
    filestruct *filetmp;
991
992
993
    int line = 0, col = 0;
    int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
    char *realdata, *tmp;
Chris Allegretta's avatar
Chris Allegretta committed
994
    int i, pos, len, page;
Chris Allegretta's avatar
Chris Allegretta committed
995

Chris Allegretta's avatar
Chris Allegretta committed
996
997
    if (!fileptr)
	return;
998

999
    /* First, blank out the line (at a minimum) */
Chris Allegretta's avatar
Chris Allegretta committed
1000
1001
1002
1003
1004
    for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
	 filetmp = filetmp->next)
	line++;

    mvwaddstr(edit, line, 0, hblank);
1005

1006
    /* Next, convert all the tabs to spaces, so everything else is easy */
1007
1008
1009
1010
    index = xpt(fileptr, index);

    realdata = fileptr->data;
    len = strlen(realdata);
1011
    fileptr->data = charalloc(xpt(fileptr, len) + 1);
1012
1013

    pos = 0;
Chris Allegretta's avatar
Chris Allegretta committed
1014
1015
    for (i = 0; i < len; i++) {
	if (realdata[i] == '\t') {
1016
1017
	    do {
		fileptr->data[pos++] = ' ';
Chris Allegretta's avatar
Chris Allegretta committed
1018
1019
1020
1021
		if (i < current_x)
		    virt_cur_x++;
		if (i < mark_beginx)
		    virt_mark_beginx++;
1022
	    } while (pos % tabsize);
1023
	    /* must decrement once to account for tab-is-one-character */
Chris Allegretta's avatar
Chris Allegretta committed
1024
1025
1026
1027
	    if (i < current_x)
		virt_cur_x--;
	    if (i < mark_beginx)
		virt_mark_beginx--;
1028
	} else if (realdata[i] < 32) {
1029
	    /* Treat control characters as ^letter */
1030
1031
	    fileptr->data[pos++] = '^';
	    fileptr->data[pos++] = realdata[i] + 64;
1032
1033
1034
1035
1036
1037
	} else {
	    fileptr->data[pos++] = realdata[i];
	}
    }

    fileptr->data[pos] = '\0';
Chris Allegretta's avatar
Chris Allegretta committed
1038

1039
1040
    /* Now, Paint the line */
    if (current == fileptr && index > COLS - 2) {
1041
	/* This handles when the current line is beyond COLS */
1042
	/* It requires figuring out what page we're on      */
1043
	page = get_page_from_virtual(index);
1044
	col = get_page_start_virtual(page);
Chris Allegretta's avatar
Chris Allegretta committed
1045

1046
	edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegretta's avatar
Chris Allegretta committed
1047
1048
	mvwaddch(edit, line, 0, '$');

Chris Allegretta's avatar
Chris Allegretta committed
1049
	if (strlenpt(fileptr->data) > get_page_end_virtual(page) + 1)
Chris Allegretta's avatar
Chris Allegretta committed
1050
	    mvwaddch(edit, line, COLS - 1, '$');
1051
    } else {
1052
1053
1054
	/* It's not the current line means that it's at x=0 and page=1 */
	/* If it is the current line, then we're in the same boat      */
	edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegretta's avatar
Chris Allegretta committed
1055

1056
	if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta's avatar
Chris Allegretta committed
1057
	    mvwaddch(edit, line, COLS - 1, '$');
1058
    }
1059
1060
1061
1062
1063

    /* Clean up our mess */
    tmp = fileptr->data;
    fileptr->data = realdata;
    free(tmp);
Chris Allegretta's avatar
Chris Allegretta committed
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
}

void center_cursor(void)
{
    current_y = editwinrows / 2;
    wmove(edit, current_y, current_x);
}

/* Refresh the screen without changing the position of lines */
void edit_refresh(void)
{
Chris Allegretta's avatar
Chris Allegretta committed
1075
    static int noloop = 0;
1076
    int lines = 0, i = 0, currentcheck = 0;
Chris Allegretta's avatar
Chris Allegretta committed
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
    filestruct *temp, *hold = current;

    if (current == NULL)
	return;

    temp = edittop;

    while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) {
	hold = temp;
	update_line(temp, current_x);
1087
1088
1089
	if (temp == current)
	    currentcheck = 1;

Chris Allegretta's avatar
Chris Allegretta committed
1090
1091
1092
	temp = temp->next;
	lines++;
    }
Chris Allegretta's avatar
Chris Allegretta committed
1093
1094
    /* If noloop == 1, then we already did an edit_update without finishing
       this function.  So we don't run edit_update again */
1095
    if (!currentcheck && !noloop) {	/* Then current has run off the screen... */
1096
	edit_update(current, CENTER);
Chris Allegretta's avatar
Chris Allegretta committed
1097
	noloop = 1;
1098
    } else if (noloop)
Chris Allegretta's avatar
Chris Allegretta committed
1099
	noloop = 0;
Chris Allegretta's avatar
Chris Allegretta committed
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109

    if (lines <= editwinrows - 1)
	while (lines <= editwinrows - 1) {
	    mvwaddstr(edit, lines, i, hblank);
	    lines++;
	}
    if (temp == NULL)
	editbot = hold;
    else
	editbot = temp;
1110
1111
1112
1113

    /* What the hell are we expecting to update the screen if this isn't 
	here? luck?? */
    wrefresh(edit);
Chris Allegretta's avatar
Chris Allegretta committed
1114
1115
}

1116
/*
1117
 * Same as above, but touch the window first, so everything is redrawn.
1118
1119
1120
1121
1122
1123
1124
1125
 */
void edit_refresh_clearok(void)
{
    clearok(edit, TRUE);
    edit_refresh();
    clearok(edit, FALSE);
}

Chris Allegretta's avatar
Chris Allegretta committed
1126
/*
1127
 * Nice generic routine to update the edit buffer, given a pointer to the
Chris Allegretta's avatar
Chris Allegretta committed
1128
1129
 * file struct =) 
 */
1130
void edit_update(filestruct * fileptr, int topmidbotnone)
Chris Allegretta's avatar
Chris Allegretta committed
1131
{
1132
    int i = 0;
Chris Allegretta's avatar
Chris Allegretta committed
1133
1134
1135
1136
1137
1138
    filestruct *temp;

    if (fileptr == NULL)
	return;

    temp = fileptr;
1139
1140
1141
1142
1143
    if (topmidbotnone == TOP);
    else if (topmidbotnone == NONE)
	for (i = 0; i <= current_y - 1 && temp->prev != NULL; i++)
	    temp = temp->prev;
    else if (topmidbotnone == BOTTOM)
1144
1145
1146
1147
1148
	for (i = 0; i <= editwinrows - 1 && temp->prev != NULL; i++)
	    temp = temp->prev;
    else
	for (i = 0; i <= editwinrows / 2 && temp->prev != NULL; i++)
	    temp = temp->prev;
Chris Allegretta's avatar
Chris Allegretta committed
1149

1150
1151
    edittop = temp;
    fix_editbot();
Chris Allegretta's avatar
Chris Allegretta committed
1152
1153
1154
1155

    edit_refresh();
}

1156
/* This function updates current, based on where current_y is; reset_cursor 
Chris Allegretta's avatar
Chris Allegretta committed
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
   does the opposite */
void update_cursor(void)
{
    int i = 0;

#ifdef DEBUG
    fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
	    current_x);
#endif

    current = edittop;
    while (i <= current_y - 1 && current->next != NULL) {
	current = current->next;
	i++;
    }

#ifdef DEBUG
    fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
#endif

}

/*
 * Ask a question on the statusbar.  Answer will be stored in answer
 * global.  Returns -1 on aborted enter, -2 on a blank string, and 0
1182
 * otherwise, the valid shortcut key caught.  Def is any editable text we
Chris Allegretta's avatar
Chris Allegretta committed
1183
 * want to put up by default.
1184
1185
 *
 * New arg tabs tells whether or not to allow tab completion.
Chris Allegretta's avatar
Chris Allegretta committed
1186
 */
1187
int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
Chris Allegretta's avatar
Chris Allegretta committed
1188
1189
1190
1191
1192
{
    va_list ap;
    char foo[133];
    int ret;

1193
1194
1195
1196
#ifndef DISABLE_TABCOMP
    int list;
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1197
1198
1199
1200
1201
    bottombars(s, slen);

    va_start(ap, msg);
    vsnprintf(foo, 132, msg, ap);
    va_end(ap);
1202
    strncat(foo, ": ", 132);
Chris Allegretta's avatar
Chris Allegretta committed
1203

1204
1205
1206
#ifdef ENABLE_COLOR
    color_on(bottomwin, COLOR_STATUSBAR);
#else
Chris Allegretta's avatar
Chris Allegretta committed
1207
    wattron(bottomwin, A_REVERSE);
1208
1209
1210
#endif


1211
1212
1213
1214
1215
1216
1217
#ifndef DISABLE_TABCOMP
    ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), list);
#else
    /* if we've disabled tab completion, the value of list won't be
       used at all, so it's safe to use 0 (NULL) as a placeholder */
    ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), 0);
#endif
1218
1219
1220
1221

#ifdef ENABLE_COLOR
    color_off(bottomwin, COLOR_STATUSBAR);
#else
Chris Allegretta's avatar
Chris Allegretta committed
1222
    wattroff(bottomwin, A_REVERSE);
1223
1224
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234

    switch (ret) {

    case NANO_FIRSTLINE_KEY:
	do_first_line();
	break;
    case NANO_LASTLINE_KEY:
	do_last_line();
	break;
    case NANO_CANCEL_KEY:
1235
1236
1237
1238
1239
1240
1241
#ifndef DISABLE_TABCOMP
	/* if we've done tab completion, there might be a list of
	   filename matches on the edit window at this point; make sure
	   they're cleared off */
	if (list)
	    edit_refresh();
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1242
1243
	return -1;
    default:
1244
	blank_statusbar();
Chris Allegretta's avatar
Chris Allegretta committed
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
    }

#ifdef DEBUG
    fprintf(stderr, _("I got \"%s\"\n"), answer);
#endif

    return ret;
}

/*
 * Ask a simple yes/no question on the statusbar.  Returns 1 for Y, 0 for
 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
 */
int do_yesno(int all, int leavecursor, char *msg, ...)
{
    va_list ap;
    char foo[133];
1262
1263
1264
1265
1266
    int kbinput, ok = -1, i;
    char *yesstr;		/* String of yes characters accepted */
    char *nostr;		/* Same for no */
    char *allstr;		/* And all, surprise! */
    char shortstr[5];		/* Temp string for above */
1267
#ifndef DISABLE_MOUSE
Chris Allegretta's avatar
Chris Allegretta committed
1268
1269
1270
1271
1272
#ifdef NCURSES_MOUSE_VERSION
    MEVENT mevent;
#endif
#endif

1273
1274
1275
1276
1277
1278
1279

    /* Yes, no and all are strings of any length.  Each string consists of
	all characters accepted as a valid character for that value.
	The first value will be the one displayed in the shortcuts. */
    yesstr = _("Yy");
    nostr = _("Nn");
    allstr = _("Aa");
Chris Allegretta's avatar
Chris Allegretta committed
1280
1281
1282

    /* Write the bottom of the screen */
    clear_bottomwin();
1283
1284
1285
1286

#ifdef ENABLE_COLOR
    color_on(bottomwin, COLOR_BOTTOMBARS);
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1287

Jordi Mallach's avatar
   
Jordi Mallach committed
1288
    /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegretta's avatar
Chris Allegretta committed
1289
1290
    if (!ISSET(NO_HELP)) {
	wmove(bottomwin, 1, 0);
1291
1292
1293
1294
1295
1296
1297
1298

	snprintf(shortstr, 3, " %c", yesstr[0]);
	onekey(shortstr, _("Yes"));

	if (all) {
	    snprintf(shortstr, 3, " %c", allstr[0]);
	    onekey(shortstr, _("All"));
	}
Chris Allegretta's avatar
Chris Allegretta committed
1299
	wmove(bottomwin, 2, 0);
1300
1301
1302
1303

	snprintf(shortstr, 3, " %c", nostr[0]);
	onekey(shortstr, _("No"));

Jordi Mallach's avatar
   
Jordi Mallach committed
1304
	onekey("^C", _("Cancel"));
Chris Allegretta's avatar
Chris Allegretta committed
1305
1306
1307
1308
    }
    va_start(ap, msg);
    vsnprintf(foo, 132, msg, ap);
    va_end(ap);
1309
1310
1311
1312
1313

#ifdef ENABLE_COLOR
    color_off(bottomwin, COLOR_BOTTOMBARS);
    color_on(bottomwin, COLOR_STATUSBAR);
#else
Chris Allegretta's avatar
Chris Allegretta committed
1314
    wattron(bottomwin, A_REVERSE);
1315
1316
1317
#endif /* ENABLE_COLOR */

    blank_statusbar();
Chris Allegretta's avatar
Chris Allegretta committed
1318
    mvwaddstr(bottomwin, 0, 0, foo);
1319
1320
1321
1322

#ifdef ENABLE_COLOR
    color_off(bottomwin, COLOR_STATUSBAR);
#else
Chris Allegretta's avatar
Chris Allegretta committed
1323
    wattroff(bottomwin, A_REVERSE);
1324
1325
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1326
1327
1328
1329
1330
1331
1332
1333
1334
    wrefresh(bottomwin);

    if (leavecursor == 1)
	reset_cursor();

    while (ok == -1) {
	kbinput = wgetch(edit);

	switch (kbinput) {
1335
#ifndef DISABLE_MOUSE
Chris Allegretta's avatar
Chris Allegretta committed
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
#ifdef NCURSES_MOUSE_VERSION
	case KEY_MOUSE:

	    /* Look ma!  We get to duplicate lots of code from do_mouse!! */
	    if (getmouse(&mevent) == ERR)
		break;
	    if (!wenclose(bottomwin, mevent.y, mevent.x) || ISSET(NO_HELP))
		break;
	    mevent.y -= editwinrows + 3;
	    if (mevent.y < 0)
		break;
	    else {

		/* Rather than a bunch of if statements, set up a matrix
		   of possible return keystrokes based on the x and y values */
		if (all) {
		    char yesnosquare[2][2] = {
			{yesstr[0], allstr[0]}, 
			{nostr[0], NANO_CONTROL_C }};

		    ungetch(yesnosquare[mevent.y][mevent.x/(COLS/6)]);
		} else {
		    char yesnosquare[2][2] = {
			{yesstr[0], '\0'},
			{nostr[0], NANO_CONTROL_C }};

		    ungetch(yesnosquare[mevent.y][mevent.x/(COLS/6)]);
		}
	    }
	    break;
#endif
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1368
1369
1370
	case NANO_CONTROL_C:
	    ok = -2;
	    break;
1371
1372
	default:

1373
	    /* Look for the kbinput in the yes, no and (optimally) all str */
1374
1375
1376
	    for (i = 0; yesstr[i] != 0 && yesstr[i] != kbinput; i++)
		;
	    if (yesstr[i] != 0) {
1377
		ok = 1;
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
	 	break;
	    }

	    for (i = 0; nostr[i] != 0 && nostr[i] != kbinput; i++)
		;
	    if (nostr[i] != 0) {
		ok = 0;
	 	break;
	    }

	    if (all) {
	        for (i = 0; allstr[i] != 0 && allstr[i] != kbinput; i++)
		    ;
		if (allstr[i] != 0) {
		    ok = 2;
	 	    break;
		}
	    }
Chris Allegretta's avatar
Chris Allegretta committed
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
	}
    }

    /* Then blank the screen */
    blank_statusbar_refresh();

    if (ok == -2)
	return -1;
    else
	return ok;
}

void statusbar(char *msg, ...)
{
    va_list ap;
    char foo[133];
    int start_x = 0;

    va_start(ap, msg);
    vsnprintf(foo, 132, msg, ap);
    va_end(ap);

1418
    start_x = COLS / 2 - strlen(foo) / 2 - 1;
Chris Allegretta's avatar
Chris Allegretta committed
1419
1420
1421
1422
1423
1424

    /* Blank out line */
    blank_statusbar();

    wmove(bottomwin, 0, start_x);

1425
1426
1427
#ifdef ENABLE_COLOR
    color_on(bottomwin, COLOR_STATUSBAR);
#else
Chris Allegretta's avatar
Chris Allegretta committed
1428
    wattron(bottomwin, A_REVERSE);
1429
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1430
1431
1432
1433

    waddstr(bottomwin, "[ ");
    waddstr(bottomwin, foo);
    waddstr(bottomwin, " ]");
1434
1435
1436
1437

#ifdef ENABLE_COLOR
    color_off(bottomwin, COLOR_STATUSBAR);
#else
Chris Allegretta's avatar
Chris Allegretta committed
1438
    wattroff(bottomwin, A_REVERSE);
1439
1440
#endif

Chris Allegretta's avatar
Chris Allegretta committed
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
    wrefresh(bottomwin);

    if (ISSET(CONSTUPDATE))
	statblank = 1;
    else
	statblank = 25;
}

void display_main_list(void)
{
    bottombars(main_list, MAIN_VISIBLE);
}

int total_refresh(void)
{
    clearok(edit, TRUE);
    clearok(topwin, TRUE);
    clearok(bottomwin, TRUE);
    wnoutrefresh(edit);
    wnoutrefresh(topwin);
    wnoutrefresh(bottomwin);
    doupdate();
    clearok(edit, FALSE);
    clearok(topwin, FALSE);
    clearok(bottomwin, FALSE);
1466
    edit_refresh();
Chris Allegretta's avatar
Chris Allegretta committed
1467
    titlebar(NULL);
Chris Allegretta's avatar
Chris Allegretta committed
1468
1469
1470
1471
1472
1473
1474
1475
1476
    return 1;
}

void previous_line(void)
{
    if (current_y > 0)
	current_y--;
}

1477
int do_cursorpos(int constant)
Chris Allegretta's avatar
Chris Allegretta committed
1478
1479
{
    filestruct *fileptr;
Chris Allegretta's avatar
Chris Allegretta committed
1480
    float linepct = 0.0, bytepct = 0.0;
1481
    long i = 0;
1482
    static long old_i = -1, old_totsize = -1;
Chris Allegretta's avatar
Chris Allegretta committed
1483
1484
1485
1486

    if (current == NULL || fileage == NULL)
	return 0;

Chris Allegretta's avatar
Chris Allegretta committed
1487
1488
    for (fileptr = fileage; fileptr != current && fileptr != NULL;
	 fileptr = fileptr->next)
Chris Allegretta's avatar
Chris Allegretta committed
1489
	i += strlen(fileptr->data) + 1;
Chris Allegretta's avatar
Chris Allegretta committed
1490
1491
1492
1493

    if (fileptr == NULL)
	return -1;

Chris Allegretta's avatar
Chris Allegretta committed
1494
    i += current_x;
Chris Allegretta's avatar
Chris Allegretta committed
1495

1496
1497
1498
1499
1500
1501
    if (old_i == -1)
	old_i = i;

    if (old_totsize == -1)
	old_totsize = totsize;

Chris Allegretta's avatar
Chris Allegretta committed
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
    if (totlines > 0)
	linepct = 100 * current->lineno / totlines;

    if (totsize > 0)
	bytepct = 100 * i / totsize;

#ifdef DEBUG
    fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
	    linepct, bytepct);
#endif

1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
    /* if constant is zero, display the position on the statusbar
       unconditionally; otherwise, only display the position when the
       character values have changed */
    if (!constant || (old_i != i || old_totsize != totsize)) {
	statusbar(_("line %d of %d (%.0f%%), character %ld of %ld (%.0f%%)"),
		current->lineno, totlines, linepct, i, totsize, bytepct);
    }

    old_i = i;
    old_totsize = totsize;

Chris Allegretta's avatar
Chris Allegretta committed
1524
1525
1526
1527
    reset_cursor();
    return 1;
}

1528
1529
1530
1531
1532
int do_cursorpos_void(void)
{
    return do_cursorpos(0);
}

Chris Allegretta's avatar
Chris Allegretta committed
1533
/* Our broken, non-shortcut list compliant help function.
1534
   But, hey, it's better than nothing, and it's dynamic! */
Chris Allegretta's avatar
Chris Allegretta committed
1535
1536
int do_help(void)
{
1537
#ifndef DISABLE_HELP
1538
    char *ptr, *end;
1539
    int i, j, row = 0, page = 1, kbinput = 0, no_more = 0, kp, kp2;
Chris Allegretta's avatar
Chris Allegretta committed
1540
    int no_help_flag = 0;
1541
1542
    shortcut *oldshortcut;
    int oldslen;
Chris Allegretta's avatar
Chris Allegretta committed
1543
1544
1545

    blank_edit();
    curs_set(0);
1546
    wattroff(bottomwin, A_REVERSE);
Chris Allegretta's avatar
Chris Allegretta committed
1547
1548
    blank_statusbar();

1549
1550
1551
1552
1553
1554
    help_init();
    ptr = help_text;

    oldshortcut = currshortcut;
    oldslen = currslen;

1555
1556
    currshortcut = help_list;
    currslen = HELP_LIST_LEN;
1557

1558
    kp = keypad_on(edit, 1);
1559
    kp2 = keypad_on(bottomwin, 1);
1560

Chris Allegretta's avatar
Chris Allegretta committed
1561
1562
    if (ISSET(NO_HELP)) {

1563
	/* Well, if we're going to do this, we should at least
1564
	   do it the right way */
Chris Allegretta's avatar
Chris Allegretta committed
1565
	no_help_flag = 1;
Chris Allegretta's avatar
Chris Allegretta committed
1566
	UNSET(NO_HELP);
1567
	window_init();
Chris Allegretta's avatar
Chris Allegretta committed
1568
	bottombars(help_list, HELP_LIST_LEN);
1569

Chris Allegretta's avatar
Chris Allegretta committed
1570
    } else
Chris Allegretta's avatar
Chris Allegretta committed
1571
1572
1573
1574
1575
	bottombars(help_list, HELP_LIST_LEN);

    do {
	ptr = help_text;
	switch (kbinput) {
1576
#ifndef DISABLE_MOUSE
1577
1578
1579
1580
1581
1582
#ifdef NCURSES_MOUSE_VERSION
        case KEY_MOUSE:
            do_mouse();
            break;
#endif
#endif
Chris Allegretta's avatar
Chris Allegretta committed
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
	case NANO_NEXTPAGE_KEY:
	case NANO_NEXTPAGE_FKEY:
	case KEY_NPAGE:
	    if (!no_more) {
		blank_edit();
		page++;
	    }
	    break;
	case NANO_PREVPAGE_KEY:
	case NANO_PREVPAGE_FKEY:
	case KEY_PPAGE:
	    if (page > 1) {
		no_more = 0;
		blank_edit();
		page--;
	    }
	    break;
	}

1602
	/* Calculate where in the text we should be, based on the page */
Chris Allegretta's avatar
Chris Allegretta committed
1603
1604
1605
	for (i = 1; i < page; i++) {
	    row = 0;
	    j = 0;
1606
1607

	    while (row < editwinrows - 2 && *ptr != '\0') {
Chris Allegretta's avatar
Chris Allegretta committed
1608
1609
1610
1611
1612
1613
1614
1615
1616
		if (*ptr == '\n' || j == COLS - 5) {
		    j = 0;
		    row++;
		}
		ptr++;
		j++;
	    }
	}

1617
	if (i > 1) {
1618

1619
1620
	}

Chris Allegretta's avatar
Chris Allegretta committed
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
	i = 0;
	j = 0;
	while (i < editwinrows && *ptr != '\0') {
	    end = ptr;
	    while (*end != '\n' && *end != '\0' && j != COLS - 5) {
		end++;
		j++;
	    }
	    if (j == COLS - 5) {

1631
		/* Don't print half a word if we've run out of space */
Chris Allegretta's avatar
Chris Allegretta committed
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
		while (*end != ' ' && *end != '\0') {
		    end--;
		    j--;
		}
	    }
	    mvwaddnstr(edit, i, 0, ptr, j);
	    j = 0;
	    i++;
	    if (*end == '\n')
		end++;
	    ptr = end;
	}
	if (*ptr == '\0') {
	    no_more = 1;
	    continue;
	}
Chris Allegretta's avatar
Chris Allegretta committed
1648
1649
1650
    } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY && 
      kbinput != NANO_EXIT_FKEY);

1651
1652
1653
    currshortcut = oldshortcut;
    currslen = oldslen;

Chris Allegretta's avatar
Chris Allegretta committed
1654
    if (no_help_flag) {
1655
	blank_bottombars();
Chris Allegretta's avatar
Chris Allegretta committed
1656
	wrefresh(bottomwin);
Chris Allegretta's avatar
Chris Allegretta committed
1657
	SET(NO_HELP);
1658
1659
	window_init();
    }
1660
1661
    else
	bottombars(currshortcut, currslen);
Chris Allegretta's avatar
Chris Allegretta committed
1662
1663
1664

    curs_set(1);
    edit_refresh();
1665
    kp = keypad_on(edit, kp);
1666
    kp2 = keypad_on(bottomwin, kp2);
1667

1668
1669
#elif defined(DISABLE_HELP)
    nano_disabled_msg();
Chris Allegretta's avatar
Chris Allegretta committed
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
#endif

    return 1;
}

/* Dump the current file structure to stderr */
void dump_buffer(filestruct * inptr)
{
#ifdef DEBUG
    filestruct *fileptr;

    if (inptr == fileage)
	fprintf(stderr, _("Dumping file buffer to stderr...\n"));
    else if (inptr == cutbuffer)
	fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
    else
	fprintf(stderr, _("Dumping a buffer to stderr...\n"));

    fileptr = inptr;
    while (fileptr != NULL) {
1690
	fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
Chris Allegretta's avatar
Chris Allegretta committed
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
	fflush(stderr);
	fileptr = fileptr->next;
    }
#endif				/* DEBUG */
}

void dump_buffer_reverse(filestruct * inptr)
{
#ifdef DEBUG
    filestruct *fileptr;

    fileptr = filebot;
    while (fileptr != NULL) {
1704
	fprintf(stderr, "(%d) %s\n", fileptr->lineno, fileptr->data);
Chris Allegretta's avatar
Chris Allegretta committed
1705
1706
1707
1708
1709
	fflush(stderr);
	fileptr = fileptr->prev;
    }
#endif				/* DEBUG */
}
Robert Siemborski's avatar
Robert Siemborski committed
1710

1711
/* Fix editbot, based on the assumption that edittop is correct */
1712
1713
void fix_editbot(void)
{
Robert Siemborski's avatar
Robert Siemborski committed
1714
1715
    int i;
    editbot = edittop;
1716
1717
    for (i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
	 && (editbot != filebot); i++, editbot = editbot->next);
Robert Siemborski's avatar
Robert Siemborski committed
1718
}
1719

Chris Allegretta's avatar
Chris Allegretta committed
1720
1721
1722
1723
1724
1725
1726
1727
1728
/* highlight the current word being replaced or spell checked */
void do_replace_highlight(int highlight_flag, char *word)
{
    char *highlight_word = NULL;
    int x, y;

    highlight_word = mallocstrcpy(highlight_word, &current->data[current_x]);
    highlight_word[strlen(word)] = '\0';

1729
    /* adjust output when word extends beyond screen */
Chris Allegretta's avatar
Chris Allegretta committed
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753

    x = xplustabs();
    y = get_page_end_virtual(get_page_from_virtual(x)) + 1;

    if ((COLS - (y - x) + strlen(word)) > COLS) {
	highlight_word[y - x - 1] = '$';
	highlight_word[y - x] = '\0';
    }

    /* OK display the output */

    reset_cursor();
    
    if (highlight_flag)
	wattron(edit, A_REVERSE);

    waddstr(edit, highlight_word);

    if (highlight_flag)
	wattroff(edit, A_REVERSE);

    free(highlight_word);
}

1754
#ifdef NANO_EXTRA
1755
#define CREDIT_LEN 48
1756
1757
void do_credits(void)
{
Chris Allegretta's avatar
Chris Allegretta committed
1758
    int i, j = 0, k, place = 0, start_x;
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
    char *what;

    char *nanotext = _("The nano text editor");
    char *version = _("version ");
    char *brought = _("Brought to you by:");
    char *specialthx = _("Special thanks to:");
    char *fsf = _("The Free Software Foundation");
    char *ncurses = _("Pavel Curtis, Zeyd Ben-Halim and Eric S. Raymond for ncurses");
    char *anyonelse = _("and anyone else we forgot...");
    char *thankyou = _("Thank you for using nano!\n");

    char *credits[CREDIT_LEN] = {nanotext, 
			version, 
			VERSION, 
			"",
			brought,
			"Chris Allegretta",
			"Jordi Mallach",
			"Adam Rogoyski",
			"Rob Siemborski",
			"Rocco Corsi",
			"Ken Tyler",
			"Sven Guckes",
			"Florian Knig",
			"Pauli Virtanen",
			"Daniele Medri",
			"Clement Laforet",
			"Tedi Heriyanto",
Chris Allegretta's avatar
Chris Allegretta committed
1787
			"Bill Soudan",
1788
			"Christian Weisgerber",
Chris Allegretta's avatar
Chris Allegretta committed
1789
			"Erik Andersen",
1790
1791
			"Big Gaute",
			"Joshua Jensen",
Chris Allegretta's avatar
Chris Allegretta committed
1792
			"Ryan Krebs",
1793
			"Albert Chin",
1794
			"David Lawrence Ramsey",
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
			"",
			specialthx,
			"Plattsburgh State University",
			"Benet Laboratories",
			"Amy Allegretta",
			"Linda Young",
			"Jeremy Robichaud",
			"Richard Kolb II",
			fsf,
			"Linus Torvalds",
			ncurses,
			anyonelse,
			thankyou,
			"", "", "", "",
			"(c) 2000 Chris Allegretta",
			"", "", "", "",
			"www.nano-editor.org"
    };

    curs_set(0);
    nodelay(edit, TRUE);
    blank_bottombars();
    mvwaddstr(topwin, 0, 0, hblank);
Chris Allegretta's avatar
Chris Allegretta committed
1818
1819
    blank_edit();
    wrefresh(edit);
1820
1821
1822
1823
    wrefresh(bottomwin);
    wrefresh(topwin);

    while (wgetch(edit) == ERR) {
Chris Allegretta's avatar
Chris Allegretta committed
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
	for (k = 0; k <= 1; k++) {
	    blank_edit();
	    for (i = editwinrows / 2 - 1; i >= (editwinrows / 2 - 1 - j); i--) {
		mvwaddstr(edit, i * 2 - k, 0, hblank);

		if (place - (editwinrows / 2 - 1 - i) < CREDIT_LEN)
		    what = credits[place - (editwinrows / 2 - 1 - i)];
		else
		    what = "";

1834
		start_x = COLS / 2 - strlen(what) / 2 - 1;
Chris Allegretta's avatar
Chris Allegretta committed
1835
1836
1837
1838
		mvwaddstr(edit, i * 2 - k, start_x, what);
	    }
	    usleep(700000);
	    wrefresh(edit);
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
	}
	if (j < editwinrows / 2 - 1)
	    j++;

	place++;

	if (place >= CREDIT_LEN + editwinrows / 2)
	    break;
    }

    nodelay(edit, FALSE);
    curs_set(1);
    display_main_list();
    total_refresh();
 }
#endif
1855

1856
int             keypad_on(WINDOW * win, int newval)
1857
1858
{

1859
/* This is taken right from aumix.  Don't sue me. */
1860
1861
1862
1863
#ifdef HAVE_USEKEYPAD
    int             old;

    old = win->_use_keypad;
1864
    keypad(win, newval);
1865
1866
    return old;
#else
1867
    keypad(win, newval);
1868
1869
1870
1871
1872
1873
1874
    return 1;
#endif                          /* HAVE_USEKEYPAD */

}