blob: 71adf291867725f9136ef3032a9a5b1a9d63c163 [file] [log] [blame]
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001/**************************************************************************
2 * winio.c *
3 * *
4 * Copyright (C) 1999 Chris Allegretta *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 1, or (at your option) *
8 * any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
18 * *
19 **************************************************************************/
20
21#include <stdarg.h>
22#include <string.h>
Chris Allegrettadba37ae2000-07-07 05:13:09 +000023#include <stdlib.h>
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000024#include "config.h"
25#include "proto.h"
26#include "nano.h"
27
28#ifndef NANO_SMALL
29#include <libintl.h>
30#define _(string) gettext(string)
31#else
32#define _(string) (string)
33#endif
34
35static int statblank = 0; /* Number of keystrokes left after
36 we call statubar() before we
37 actually blank the statusbar */
Robert Siemborskid8510b22000-06-06 23:04:06 +000038
39/* Local Function Prototypes for only winio.c */
40inline int get_page_from_virtual(int virtual);
41inline int get_page_start_virtual(int page);
42inline int get_page_end_virtual(int page);
43
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000044/* Window I/O */
45
46int do_first_line(void)
47{
48 current = fileage;
49 placewewant = 0;
50 current_x = 0;
51 edit_update(current);
52 return 1;
53}
54
55int do_last_line(void)
56{
57 current = filebot;
58 placewewant = 0;
59 current_x = 0;
60 edit_update(current);
61 return 1;
62}
63
64/* Like xplustabs, but for a specifc index of a speficific filestruct */
65int xpt(filestruct * fileptr, int index)
66{
67 int i, tabs = 0;
68
69 if (fileptr == NULL || fileptr->data == NULL)
70 return 0;
71
72 for (i = 0; i < index && fileptr->data[i] != 0; i++) {
73 tabs++;
74
75 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta6724a7e2000-06-19 23:19:07 +000076 if (tabs % TABSIZE == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000077 else
Chris Allegretta6724a7e2000-06-19 23:19:07 +000078 tabs += TABSIZE - (tabs % TABSIZE);
Chris Allegretta4da1fc62000-06-21 03:00:43 +000079 } else if (fileptr->data[i] & 0x80)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000080 /* Make 8 bit chars only 1 collumn! */
81 ;
82 else if (fileptr->data[i] < 32)
83 tabs++;
84 }
85
86 return tabs;
87}
88
89
90/* Return the actual place on the screen of current->data[current_x], which
91 should always be > current_x */
92int xplustabs(void)
93{
94 return xpt(current, current_x);
95}
96
97
Robert Siemborskid8510b22000-06-06 23:04:06 +000098/* Return what current_x should be, given xplustabs() for the line,
99 * given a start position in the filestruct's data */
100int actual_x_from_start(filestruct * fileptr, int xplus, int start)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000101{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000102 int i, tot = 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000103
104 if (fileptr == NULL || fileptr->data == NULL)
105 return 0;
106
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000107 for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000108 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000109 if (tot % TABSIZE == 0)
110 tot++;
111 else
112 tot += TABSIZE - (tot % TABSIZE);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000113 } else if (fileptr->data[i] & 0x80)
114 tot++; /* Make 8 bit chars only 1 column (again) */
115 else if (fileptr->data[i] < 32)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000116 tot += 2;
117
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000118#ifdef DEBUG
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000119 fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"),
120 xplus, i);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000121#endif
Robert Siemborskid8510b22000-06-06 23:04:06 +0000122 return i - start;
123}
124
125/* Opposite of xplustabs */
126inline int actual_x(filestruct * fileptr, int xplus)
127{
128 return actual_x_from_start(fileptr, xplus, 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000129}
130
131/* a strlen with tabs factored in, similar to xplustabs() */
132int strlenpt(char *buf)
133{
134 int i, tabs = 0;
135
136 if (buf == NULL)
137 return 0;
138
139 for (i = 0; buf[i] != 0; i++) {
140 tabs++;
141
142 if (buf[i] == NANO_CONTROL_I) {
Chris Allegretta6724a7e2000-06-19 23:19:07 +0000143 if (tabs % TABSIZE == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000144 else
Chris Allegretta6724a7e2000-06-19 23:19:07 +0000145 tabs += TABSIZE - (tabs % TABSIZE);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000146 } else if (buf[i] & 0x80)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000147 /* Make 8 bit chars only 1 collumn! */
148 ;
149 else if (buf[i] < 32)
150 tabs++;
151 }
152
153 return tabs;
154}
155
156
157/* resets current_y based on the position of current and puts the cursor at
158 (current_y, current_x) */
159void reset_cursor(void)
160{
161 filestruct *ptr = edittop;
162 int x;
163
164 current_y = 0;
165
166 while (ptr != current && ptr != editbot && ptr->next != NULL) {
167 ptr = ptr->next;
168 current_y++;
169 }
170
171 x = xplustabs();
172 if (x <= COLS - 2)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000173 wmove(edit, current_y, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000174 else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000175 wmove(edit, current_y, x -
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000176 get_page_start_virtual(get_page_from_virtual(x)));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000177
178}
179
180void blank_bottombars(void)
181{
182 int i = no_help()? 3 : 1;
183
184 for (; i <= 2; i++)
185 mvwaddstr(bottomwin, i, 0, hblank);
186
187}
188
189void blank_edit(void)
190{
191 int i;
192 for (i = 0; i <= editwinrows - 1; i++)
193 mvwaddstr(edit, i, 0, hblank);
194 wrefresh(edit);
195}
196
197
198void blank_statusbar(void)
199{
200 mvwaddstr(bottomwin, 0, 0, hblank);
201}
202
203void blank_statusbar_refresh(void)
204{
205 blank_statusbar();
206 wrefresh(bottomwin);
207}
208
209void check_statblank(void)
210{
211
212 if (statblank > 1)
213 statblank--;
214 else if (statblank == 1 && !ISSET(CONSTUPDATE)) {
215 statblank--;
216 blank_statusbar_refresh();
217 }
218}
219
220/* Get the input from the kb, this should only be called from statusq */
221int nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x)
222{
223 int kbinput = 0, j = 0, x = 0, xend;
224 int x_left = 0;
225 char inputstr[132], inputbuf[132] = "";
226
227 blank_statusbar();
228 mvwaddstr(bottomwin, 0, 0, buf);
229 if (strlen(def) > 0)
230 waddstr(bottomwin, def);
231 wrefresh(bottomwin);
232
233 x_left = strlen(buf);
234 x = strlen(def) + x_left;
235
236 /* Get the input! */
237 if (strlen(def) > 0) {
238 strcpy(answer, def);
239 strcpy(inputbuf, def);
240 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000241
242 while ((kbinput = wgetch(bottomwin)) != 13) {
243 for (j = 0; j <= slen - 1; j++) {
244 if (kbinput == s[j].val) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000245 strcpy(answer, "");
246 return s[j].val;
247 }
248 }
249 xend = strlen(buf) + strlen(inputbuf);
250
251 switch (kbinput) {
252 case KEY_HOME:
253 x = x_left;
254 blank_statusbar();
255 mvwaddstr(bottomwin, 0, 0, buf);
256 waddstr(bottomwin, inputbuf);
257 wmove(bottomwin, 0, x);
258 break;
259 case KEY_END:
260 x = x_left + strlen(inputbuf);
261 blank_statusbar();
262 mvwaddstr(bottomwin, 0, 0, buf);
263 waddstr(bottomwin, inputbuf);
264 wmove(bottomwin, 0, x);
265 break;
266 case KEY_RIGHT:
267
268 if (x < xend)
269 x++;
270 wmove(bottomwin, 0, x);
271 break;
272 case NANO_CONTROL_D:
273 if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
274 memmove(inputbuf + (x - x_left),
275 inputbuf + (x - x_left) + 1,
276 strlen(inputbuf) - (x - x_left) - 1);
277 inputbuf[strlen(inputbuf) - 1] = 0;
278 }
279 blank_statusbar();
280 mvwaddstr(bottomwin, 0, 0, buf);
281 waddstr(bottomwin, inputbuf);
282 wmove(bottomwin, 0, x);
283 break;
284 case NANO_CONTROL_K:
285 case NANO_CONTROL_U:
286 *inputbuf = 0;
287 x = x_left;
288 blank_statusbar();
289 mvwaddstr(bottomwin, 0, 0, buf);
290 waddstr(bottomwin, inputbuf);
291 wmove(bottomwin, 0, x);
292 break;
293 case KEY_BACKSPACE:
294 case KEY_DC:
295 case 127:
296 case NANO_CONTROL_H:
297 if (strlen(inputbuf) > 0) {
298 if (x == (x_left + strlen(inputbuf)))
299 inputbuf[strlen(inputbuf) - 1] = 0;
300 else if (x - x_left) {
301 memmove(inputbuf + (x - x_left) - 1,
302 inputbuf + (x - x_left),
303 strlen(inputbuf) - (x - x_left));
304 inputbuf[strlen(inputbuf) - 1] = 0;
305 }
306 }
307 blank_statusbar();
308 mvwaddstr(bottomwin, 0, 0, buf);
309 waddstr(bottomwin, inputbuf);
310 case KEY_LEFT:
311 if (x > strlen(buf))
312 x--;
313 wmove(bottomwin, 0, x);
314 break;
315 case KEY_UP:
316 case KEY_DOWN:
317 break;
318
319 case 27:
320 switch (kbinput = wgetch(edit)) {
321 case 79:
322 switch (kbinput = wgetch(edit)) {
323 case 70:
324 x = x_left + strlen(inputbuf);
325 blank_statusbar();
326 mvwaddstr(bottomwin, 0, 0, buf);
327 waddstr(bottomwin, inputbuf);
328 wmove(bottomwin, 0, x);
329 break;
330 case 72:
331 x = x_left;
332 blank_statusbar();
333 mvwaddstr(bottomwin, 0, 0, buf);
334 waddstr(bottomwin, inputbuf);
335 wmove(bottomwin, 0, x);
336 break;
337 }
338 break;
339 case 91:
340 switch (kbinput = wgetch(edit)) {
341 case 'C':
342 if (x < xend)
343 x++;
344 wmove(bottomwin, 0, x);
345 break;
346 case 'D':
347 if (x > strlen(buf))
348 x--;
349 wmove(bottomwin, 0, x);
350 break;
351 case 49:
352 x = x_left;
353 blank_statusbar();
354 mvwaddstr(bottomwin, 0, 0, buf);
355 waddstr(bottomwin, inputbuf);
356 wmove(bottomwin, 0, x);
357 goto skip_126;
358 case 51:
359 if (strlen(inputbuf) > 0
360 && (x - x_left) != strlen(inputbuf)) {
361 memmove(inputbuf + (x - x_left),
362 inputbuf + (x - x_left) + 1,
363 strlen(inputbuf) - (x - x_left) - 1);
364 inputbuf[strlen(inputbuf) - 1] = 0;
365 }
366 blank_statusbar();
367 mvwaddstr(bottomwin, 0, 0, buf);
368 waddstr(bottomwin, inputbuf);
369 wmove(bottomwin, 0, x);
370 goto skip_126;
371 case 52:
372 x = x_left + strlen(inputbuf);
373 blank_statusbar();
374 mvwaddstr(bottomwin, 0, 0, buf);
375 waddstr(bottomwin, inputbuf);
376 wmove(bottomwin, 0, x);
377 goto skip_126;
378 skip_126:
379 nodelay(edit, TRUE);
380 kbinput = wgetch(edit);
381 if (kbinput == 126 || kbinput == ERR)
382 kbinput = -1;
383 nodelay(edit, FALSE);
384 break;
385 }
386 }
387 blank_statusbar();
388 mvwaddstr(bottomwin, 0, 0, buf);
389 waddstr(bottomwin, inputbuf);
390 wmove(bottomwin, 0, x);
391 break;
392
393
394 default:
395 if (kbinput < 32)
396 break;
397 strcpy(inputstr, inputbuf);
398 inputstr[x - strlen(buf)] = kbinput;
399 strcpy(&inputstr[x - strlen(buf) + 1],
400 &inputbuf[x - strlen(buf)]);
401 strcpy(inputbuf, inputstr);
402 x++;
403
404 mvwaddstr(bottomwin, 0, 0, buf);
405 waddstr(bottomwin, inputbuf);
406 wmove(bottomwin, 0, x);
407
408#ifdef DEBUG
409 fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
410#endif
411 }
412 wrefresh(bottomwin);
413 }
414
415 strncpy(answer, inputbuf, 132);
416
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000417 if (!strcmp(answer, ""))
418 return -2;
419 else
420 return 0;
421}
422
423void horizbar(WINDOW * win, int y)
424{
425 wattron(win, A_REVERSE);
426 mvwaddstr(win, 0, 0, hblank);
427 wattroff(win, A_REVERSE);
428}
429
430void titlebar(void)
431{
432 int namelen, space;
433
434 horizbar(topwin, 0);
435 wattron(topwin, A_REVERSE);
436 mvwaddstr(topwin, 0, 3, VERMSG);
437
438 space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
439
440 namelen = strlen(filename);
441
442 if (!strcmp(filename, ""))
443 mvwaddstr(topwin, 0, center_x - 6, _("New Buffer"));
444 else {
445 if (namelen > space) {
446 waddstr(topwin, _(" File: ..."));
447 waddstr(topwin, &filename[namelen - space]);
448 } else {
449 mvwaddstr(topwin, 0, center_x - (namelen / 2 + 1), "File: ");
450 waddstr(topwin, filename);
451 }
452 }
453 if (ISSET(MODIFIED))
454 mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
455 wattroff(topwin, A_REVERSE);
456 wrefresh(topwin);
457 reset_cursor();
458}
459
460void onekey(char *keystroke, char *desc)
461{
462 char description[80];
463
464 snprintf(description, 12, " %-11s", desc);
465 wattron(bottomwin, A_REVERSE);
466 waddstr(bottomwin, keystroke);
467 wattroff(bottomwin, A_REVERSE);
468 waddstr(bottomwin, description);
469}
470
471void clear_bottomwin(void)
472{
473 if (ISSET(NO_HELP))
474 return;
475
476 mvwaddstr(bottomwin, 1, 0, hblank);
477 mvwaddstr(bottomwin, 2, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000478}
479
480void bottombars(shortcut s[], int slen)
481{
482 int i, j, k;
483 char keystr[10];
484
485 if (ISSET(NO_HELP))
486 return;
487
488 /* Determine how many extra spaces are needed to fill the bottom of the screen */
489 k = COLS / 6 - 13;
490
491 clear_bottomwin();
492 wmove(bottomwin, 1, 0);
493 for (i = 0; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000494 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000495 onekey(keystr, s[i].desc);
496
497 for (j = 0; j < k; j++)
498 waddch(bottomwin, ' ');
499 }
500
501 wmove(bottomwin, 2, 0);
502 for (i = 1; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000503 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000504 onekey(keystr, s[i].desc);
505
506 for (j = 0; j < k; j++)
507 waddch(bottomwin, ' ');
508 }
509
510 wrefresh(bottomwin);
511
512}
513
514/* If modified is not already set, set it and update titlebar */
515void set_modified(void)
516{
517 if (!ISSET(MODIFIED)) {
518 SET(MODIFIED);
519 titlebar();
520 wrefresh(topwin);
521 }
522}
523
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000524inline int get_page_from_virtual(int virtual)
525{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000526 int page = 2;
527
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000528 if (virtual <= COLS - 2)
529 return 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000530 virtual -= (COLS - 2);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000531
532 while (virtual > COLS - 2 - 7) {
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000533 virtual -= (COLS - 2 - 7);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000534 page++;
535 }
536
537 return page;
538}
539
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000540inline int get_page_start_virtual(int page)
541{
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000542 int virtual;
543 virtual = --page * (COLS - 7);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000544 if (page)
545 virtual -= 2 * page - 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000546 return virtual;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000547}
548
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000549inline int get_page_end_virtual(int page)
550{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000551 return get_page_start_virtual(page) + COLS - 1;
552}
553
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000554#ifndef NANO_SMALL
Robert Siemborski53875912000-06-16 04:25:30 +0000555/* Called only from edit_add, and therefore expects a
556 * converted-to-only-spaces line */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000557void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
558 int virt_cur_x, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000559{
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000560 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborski53875912000-06-16 04:25:30 +0000561 this_page_end = get_page_end_virtual(this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000562
563 /* 3 start points: 0 -> begin, begin->end, end->strlen(data) */
564 /* in data : pre sel post */
Robert Siemborskid8510b22000-06-06 23:04:06 +0000565 /* likewise, 3 data lengths */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000566 int pre_data_len = begin, sel_data_len = end - begin, post_data_len = 0; /* Determined from the other two */
Robert Siemborskid8510b22000-06-06 23:04:06 +0000567
568 /* now fix the start locations & lengths according to the cursor's
569 * position (ie: our page) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000570 if (pre_data_len < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000571 pre_data_len = 0;
572 else
573 pre_data_len -= this_page_start;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000574
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000575 if (begin < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000576 begin = this_page_start;
577
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000578 if (end < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000579 end = this_page_start;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000580
Robert Siemborskid8510b22000-06-06 23:04:06 +0000581 /* we don't care about end, because it will just get cropped
582 * due to length */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000583 if (begin > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000584 begin = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000585
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000586 if (end > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000587 end = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000588
Robert Siemborskia9addc72000-06-17 06:06:35 +0000589 sel_data_len = end - begin;
590 post_data_len = this_page_end - end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000591
Robert Siemborski53875912000-06-16 04:25:30 +0000592 mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000593 wattron(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000594 mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000595 &fileptr->data[begin], sel_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000596 wattroff(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000597 mvwaddnstr(edit, y, end - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000598 &fileptr->data[end], post_data_len);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000599}
600#endif
601
Robert Siemborski53875912000-06-16 04:25:30 +0000602/* Called only from update_line. Expects a converted-to-not-have-tabs
603 * line */
604void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000605 int virt_mark_beginx, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000606{
607#ifndef NANO_SMALL
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000608 if (ISSET(MARK_ISSET)) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000609 if ((fileptr->lineno > mark_beginbuf->lineno
610 && fileptr->lineno > current->lineno)
611 || (fileptr->lineno < mark_beginbuf->lineno
612 && fileptr->lineno < current->lineno)) {
613
614 /* We're on a normal, unselected line */
Robert Siemborski53875912000-06-16 04:25:30 +0000615 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000616 } else {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000617 if (fileptr != mark_beginbuf && fileptr != current) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000618 /* We're on selected text */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000619 wattron(edit, A_REVERSE);
Robert Siemborski53875912000-06-16 04:25:30 +0000620 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000621 wattroff(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000622 } else if (fileptr == mark_beginbuf && fileptr == current) {
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000623 /* Special case, we're still on the same line we started
Robert Siemborskia9addc72000-06-17 06:06:35 +0000624 * marking */
Robert Siemborski53875912000-06-16 04:25:30 +0000625 if (virt_cur_x < virt_mark_beginx)
626 add_marked_sameline(virt_cur_x, virt_mark_beginx,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000627 fileptr, yval, virt_cur_x,
628 this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000629 else
Robert Siemborski53875912000-06-16 04:25:30 +0000630 add_marked_sameline(virt_mark_beginx, virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000631 fileptr, yval, virt_cur_x,
632 this_page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000633 } else if (fileptr == mark_beginbuf) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000634 /* we're updating the line that was first marked */
Robert Siemborskid8510b22000-06-06 23:04:06 +0000635 int target;
636
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000637 if (mark_beginbuf->lineno > current->lineno)
638 wattron(edit, A_REVERSE);
639
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000640 target =
641 (virt_mark_beginx <
642 COLS - 1) ? virt_mark_beginx : COLS - 1;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000643
Robert Siemborski53875912000-06-16 04:25:30 +0000644 mvwaddnstr(edit, yval, 0, fileptr->data, target);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000645
646 if (mark_beginbuf->lineno < current->lineno)
647 wattron(edit, A_REVERSE);
648 else
649 wattroff(edit, A_REVERSE);
650
Robert Siemborski53875912000-06-16 04:25:30 +0000651 target = (COLS - 1) - virt_mark_beginx;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000652 if (target < 0)
653 target = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000654
Robert Siemborski53875912000-06-16 04:25:30 +0000655 mvwaddnstr(edit, yval, virt_mark_beginx,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000656 &fileptr->data[virt_mark_beginx], target);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000657
658 if (mark_beginbuf->lineno < current->lineno)
659 wattroff(edit, A_REVERSE);
660
661 } else if (fileptr == current) {
Robert Siemborskid8510b22000-06-06 23:04:06 +0000662 /* we're on the cursors line, but it's not the first
663 * one we marked... */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000664 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborskid8510b22000-06-06 23:04:06 +0000665 this_page_end = get_page_end_virtual(this_page);
666
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000667 if (mark_beginbuf->lineno < current->lineno)
668 wattron(edit, A_REVERSE);
669
Robert Siemborski53875912000-06-16 04:25:30 +0000670 if (virt_cur_x > COLS - 2) {
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000671 mvwaddnstr(edit, yval, 0,
672 &fileptr->data[this_page_start],
673 virt_cur_x - this_page_start);
Robert Siemborski53875912000-06-16 04:25:30 +0000674 } else {
675 mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
676 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000677
678 if (mark_beginbuf->lineno > current->lineno)
679 wattron(edit, A_REVERSE);
680 else
681 wattroff(edit, A_REVERSE);
682
Robert Siemborskia9addc72000-06-17 06:06:35 +0000683 if (virt_cur_x > COLS - 2)
Robert Siemborski53875912000-06-16 04:25:30 +0000684 mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
685 &fileptr->data[virt_cur_x],
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000686 this_page_end - virt_cur_x);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000687 else
Robert Siemborski53875912000-06-16 04:25:30 +0000688 mvwaddnstr(edit, yval, virt_cur_x,
689 &fileptr->data[virt_cur_x],
690 COLS - virt_cur_x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000691
692 if (mark_beginbuf->lineno > current->lineno)
693 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000694 }
695 }
696
697 } else
698#endif
Robert Siemborskia9addc72000-06-17 06:06:35 +0000699 mvwaddnstr(edit, yval, 0, &fileptr->data[start],
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000700 get_page_end_virtual(this_page) - start);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000701}
702
703/*
704 * Just update one line in the edit buffer
705 *
706 * index gives is a place in the string to update starting from.
707 * Likely args are current_x or 0.
708 */
709void update_line(filestruct * fileptr, int index)
710{
711 filestruct *filetmp;
Robert Siemborski53875912000-06-16 04:25:30 +0000712 int line = 0, col = 0;
713 int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
714 char *realdata, *tmp;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000715 int i, pos, len, page;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000716
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000717 if (!fileptr)
718 return;
Robert Siemborski53154a72000-06-18 00:11:03 +0000719
Robert Siemborski53875912000-06-16 04:25:30 +0000720 /* First, blank out the line (at a minimum) */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000721 for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
722 filetmp = filetmp->next)
723 line++;
724
725 mvwaddstr(edit, line, 0, hblank);
726
Robert Siemborski53875912000-06-16 04:25:30 +0000727 /* Next, convert all the tabs to spaces so everything else is easy */
728 index = xpt(fileptr, index);
729
730 realdata = fileptr->data;
731 len = strlen(realdata);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000732 fileptr->data = nmalloc(xpt(fileptr, len) + 1);
Robert Siemborski53875912000-06-16 04:25:30 +0000733
734 pos = 0;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000735 for (i = 0; i < len; i++) {
736 if (realdata[i] == '\t') {
Robert Siemborski53875912000-06-16 04:25:30 +0000737 do {
738 fileptr->data[pos++] = ' ';
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000739 if (i < current_x)
740 virt_cur_x++;
741 if (i < mark_beginx)
742 virt_mark_beginx++;
743 } while (pos % TABSIZE);
Robert Siemborski53875912000-06-16 04:25:30 +0000744 /* must decrement once to account for tab-is-one-character */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000745 if (i < current_x)
746 virt_cur_x--;
747 if (i < mark_beginx)
748 virt_mark_beginx--;
Robert Siemborski53875912000-06-16 04:25:30 +0000749 } else {
750 fileptr->data[pos++] = realdata[i];
751 }
752 }
753
754 fileptr->data[pos] = '\0';
755
756 /* Now, Paint the line */
757 if (current == fileptr && index > COLS - 2) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000758 /* This handles when the current line is beyond COLS */
759 /* It requires figureing out what page we're at */
760 page = get_page_from_virtual(index);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000761 col = get_page_start_virtual(page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000762
Robert Siemborskia9addc72000-06-17 06:06:35 +0000763 edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000764 mvwaddch(edit, line, 0, '$');
765
Robert Siemborskid8510b22000-06-06 23:04:06 +0000766 if (strlenpt(fileptr->data) > get_page_end_virtual(page))
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000767 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000768 } else {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000769 /* It's not the current line means that it's at x=0 and page=1 */
770 /* If it is the current line, then we're in the same boat */
771 edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000772
Robert Siemborski53875912000-06-16 04:25:30 +0000773 if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000774 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000775 }
Robert Siemborski53875912000-06-16 04:25:30 +0000776
777 /* Clean up our mess */
778 tmp = fileptr->data;
779 fileptr->data = realdata;
780 free(tmp);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000781}
782
783void center_cursor(void)
784{
785 current_y = editwinrows / 2;
786 wmove(edit, current_y, current_x);
787}
788
789/* Refresh the screen without changing the position of lines */
790void edit_refresh(void)
791{
792 int lines = 0, i = 0;
793 filestruct *temp, *hold = current;
794
795 if (current == NULL)
796 return;
797
798 temp = edittop;
799
800 while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) {
801 hold = temp;
802 update_line(temp, current_x);
803 temp = temp->next;
804 lines++;
805 }
806
807 if (lines <= editwinrows - 1)
808 while (lines <= editwinrows - 1) {
809 mvwaddstr(edit, lines, i, hblank);
810 lines++;
811 }
812 if (temp == NULL)
813 editbot = hold;
814 else
815 editbot = temp;
816}
817
818/*
819 * Nice generic routine to update the edit buffer given a pointer to the
820 * file struct =)
821 */
822void edit_update(filestruct * fileptr)
823{
Robert Siemborski29e9a762000-07-05 03:16:04 +0000824 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000825 filestruct *temp;
826
827 if (fileptr == NULL)
828 return;
829
830 temp = fileptr;
831 while (i <= editwinrows / 2 && temp->prev != NULL) {
832 i++;
833 temp = temp->prev;
834 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000835
Robert Siemborski29e9a762000-07-05 03:16:04 +0000836 edittop = temp;
837 fix_editbot();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000838
839 edit_refresh();
840}
841
842/* Now we want to update the screen using this struct as the top of the edit buffer */
843void edit_update_top(filestruct * fileptr)
844{
845 int i;
846 filestruct *temp = fileptr;
847
Chris Allegretta1e57e682000-07-03 04:24:39 +0000848 if (fileptr == NULL)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000849 return;
850
851 i = 0;
852 while (i <= editwinrows / 2 && temp->next != NULL) {
853 i++;
854 temp = temp->next;
855 }
856 edit_update(temp);
857}
858
859/* And also for the bottom... */
860void edit_update_bot(filestruct * fileptr)
861{
862 int i;
863 filestruct *temp = fileptr;
864
865 i = 0;
866 while (i <= editwinrows / 2 - 1 && temp->prev != NULL) {
867 i++;
868 temp = temp->prev;
869 }
870 edit_update(temp);
871}
872
873/* This function updates current based on where current_y is, reset_cursor
874 does the opposite */
875void update_cursor(void)
876{
877 int i = 0;
878
879#ifdef DEBUG
880 fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
881 current_x);
882#endif
883
884 current = edittop;
885 while (i <= current_y - 1 && current->next != NULL) {
886 current = current->next;
887 i++;
888 }
889
890#ifdef DEBUG
891 fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
892#endif
893
894}
895
896/*
897 * Ask a question on the statusbar. Answer will be stored in answer
898 * global. Returns -1 on aborted enter, -2 on a blank string, and 0
899 * otherwise, the valid shortcut key caught, Def is any editable text we
900 * want to put up by default.
901 */
902int statusq(shortcut s[], int slen, char *def, char *msg, ...)
903{
904 va_list ap;
905 char foo[133];
906 int ret;
907
908 bottombars(s, slen);
909
910 va_start(ap, msg);
911 vsnprintf(foo, 132, msg, ap);
912 strncat(foo, ": ", 132);
913 va_end(ap);
914
915 wattron(bottomwin, A_REVERSE);
916 ret = nanogetstr(foo, def, s, slen, (strlen(foo) + 3));
917 wattroff(bottomwin, A_REVERSE);
918
919 switch (ret) {
920
921 case NANO_FIRSTLINE_KEY:
922 do_first_line();
923 break;
924 case NANO_LASTLINE_KEY:
925 do_last_line();
926 break;
927 case NANO_CANCEL_KEY:
928 return -1;
929 default:
930 blank_statusbar_refresh();
931 }
932
933#ifdef DEBUG
934 fprintf(stderr, _("I got \"%s\"\n"), answer);
935#endif
936
937 return ret;
938}
939
940/*
941 * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
942 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
943 */
944int do_yesno(int all, int leavecursor, char *msg, ...)
945{
946 va_list ap;
947 char foo[133];
948 int kbinput, ok = -1;
949
950 /* Write the bottom of the screen */
951 clear_bottomwin();
952 wattron(bottomwin, A_REVERSE);
953 blank_statusbar_refresh();
954 wattroff(bottomwin, A_REVERSE);
955
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000956 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000957 if (!ISSET(NO_HELP)) {
958 wmove(bottomwin, 1, 0);
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000959 onekey(" Y", _("Yes"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000960 if (all)
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000961 onekey(" A", _("All"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000962 wmove(bottomwin, 2, 0);
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000963 onekey(" N", _("No"));
964 onekey("^C", _("Cancel"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000965 }
966 va_start(ap, msg);
967 vsnprintf(foo, 132, msg, ap);
968 va_end(ap);
969 wattron(bottomwin, A_REVERSE);
970 mvwaddstr(bottomwin, 0, 0, foo);
971 wattroff(bottomwin, A_REVERSE);
972 wrefresh(bottomwin);
973
974 if (leavecursor == 1)
975 reset_cursor();
976
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000977 while (ok == -1) {
978 kbinput = wgetch(edit);
979
980 switch (kbinput) {
981 case 'Y':
982 case 'y':
983 ok = 1;
984 break;
985 case 'N':
986 case 'n':
987 ok = 0;
988 break;
989 case 'A':
990 case 'a':
991 if (all)
992 ok = 2;
993 break;
994 case NANO_CONTROL_C:
995 ok = -2;
996 break;
997 }
998 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000999
1000 /* Then blank the screen */
1001 blank_statusbar_refresh();
1002
1003 if (ok == -2)
1004 return -1;
1005 else
1006 return ok;
1007}
1008
1009void statusbar(char *msg, ...)
1010{
1011 va_list ap;
1012 char foo[133];
1013 int start_x = 0;
1014
1015 va_start(ap, msg);
1016 vsnprintf(foo, 132, msg, ap);
1017 va_end(ap);
1018
1019 start_x = center_x - strlen(foo) / 2 - 1;
1020
1021 /* Blank out line */
1022 blank_statusbar();
1023
1024 wmove(bottomwin, 0, start_x);
1025
1026 wattron(bottomwin, A_REVERSE);
1027
1028 waddstr(bottomwin, "[ ");
1029 waddstr(bottomwin, foo);
1030 waddstr(bottomwin, " ]");
1031 wattroff(bottomwin, A_REVERSE);
1032 wrefresh(bottomwin);
1033
1034 if (ISSET(CONSTUPDATE))
1035 statblank = 1;
1036 else
1037 statblank = 25;
1038}
1039
1040void display_main_list(void)
1041{
1042 bottombars(main_list, MAIN_VISIBLE);
1043}
1044
1045int total_refresh(void)
1046{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001047 clearok(edit, TRUE);
1048 clearok(topwin, TRUE);
1049 clearok(bottomwin, TRUE);
1050 wnoutrefresh(edit);
1051 wnoutrefresh(topwin);
1052 wnoutrefresh(bottomwin);
1053 doupdate();
1054 clearok(edit, FALSE);
1055 clearok(topwin, FALSE);
1056 clearok(bottomwin, FALSE);
1057
1058 return 1;
1059}
1060
1061void previous_line(void)
1062{
1063 if (current_y > 0)
1064 current_y--;
1065}
1066
1067int do_cursorpos(void)
1068{
1069 filestruct *fileptr;
1070 float linepct, bytepct;
1071 int i, tot = 0;
1072
1073 if (current == NULL || fileage == NULL)
1074 return 0;
1075
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001076 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1077 fileptr = fileptr->next)
1078 tot += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001079
1080 if (fileptr == NULL)
1081 return -1;
1082
1083 i = tot + current_x;;
1084
1085 for (fileptr = current->next; fileptr != NULL; fileptr = fileptr->next)
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001086 tot += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001087
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001088 if (totlines > 0)
1089 linepct = 100 * current->lineno / totlines;
1090 else
1091 linepct = 0;
1092
1093 if (totsize > 0)
1094 bytepct = 100 * i / totsize;
1095 else
1096 bytepct = 0;
1097
1098#ifdef DEBUG
1099 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1100 linepct, bytepct);
1101#endif
1102
1103 statusbar(_("line %d of %d (%.0f%%), character %d of %d (%.0f%%)"),
1104 current->lineno, totlines, linepct, i, totsize, bytepct);
1105 reset_cursor();
1106 return 1;
1107}
1108
1109/* Our broken, non-shortcut list compliant help function.
1110 But hey, it's better than nothing, and it's dynamic! */
1111int do_help(void)
1112{
1113#ifndef NANO_SMALL
1114 char *ptr = help_text, *end;
1115 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0;
1116 int no_help_flag = 0;
1117
1118 blank_edit();
1119 curs_set(0);
1120 blank_statusbar();
1121
1122 if (ISSET(NO_HELP)) {
1123
1124 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001125 delwin(bottomwin);
1126 bottomwin = newwin(3, COLS, LINES - 3, 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001127 keypad(bottomwin, TRUE);
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001128
1129 editwinrows -= no_help();
1130 UNSET(NO_HELP);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001131 bottombars(help_list, HELP_LIST_LEN);
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001132 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001133 bottombars(help_list, HELP_LIST_LEN);
1134
1135 do {
1136 ptr = help_text;
1137 switch (kbinput) {
1138 case NANO_NEXTPAGE_KEY:
1139 case NANO_NEXTPAGE_FKEY:
1140 case KEY_NPAGE:
1141 if (!no_more) {
1142 blank_edit();
1143 page++;
1144 }
1145 break;
1146 case NANO_PREVPAGE_KEY:
1147 case NANO_PREVPAGE_FKEY:
1148 case KEY_PPAGE:
1149 if (page > 1) {
1150 no_more = 0;
1151 blank_edit();
1152 page--;
1153 }
1154 break;
1155 }
1156
1157 /* Calculate where in the text we should be based on the page */
1158 for (i = 1; i < page; i++) {
1159 row = 0;
1160 j = 0;
1161 while (row < editwinrows && *ptr != '\0') {
1162 if (*ptr == '\n' || j == COLS - 5) {
1163 j = 0;
1164 row++;
1165 }
1166 ptr++;
1167 j++;
1168 }
1169 }
1170
1171 i = 0;
1172 j = 0;
1173 while (i < editwinrows && *ptr != '\0') {
1174 end = ptr;
1175 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1176 end++;
1177 j++;
1178 }
1179 if (j == COLS - 5) {
1180
1181 /* Don't print half a word if we've run of of space */
1182 while (*end != ' ' && *end != '\0') {
1183 end--;
1184 j--;
1185 }
1186 }
1187 mvwaddnstr(edit, i, 0, ptr, j);
1188 j = 0;
1189 i++;
1190 if (*end == '\n')
1191 end++;
1192 ptr = end;
1193 }
1194 if (*ptr == '\0') {
1195 no_more = 1;
1196 continue;
1197 }
1198 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY);
1199
1200 if (no_help_flag) {
1201 werase(bottomwin);
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001202 wrefresh(bottomwin);
1203 delwin(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001204 SET(NO_HELP);
1205 bottomwin = newwin(3 - no_help(), COLS, LINES - 3 + no_help(), 0);
1206 keypad(bottomwin, TRUE);
1207 editwinrows += no_help();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001208 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001209 display_main_list();
1210
1211 curs_set(1);
1212 edit_refresh();
1213#else
1214 nano_small_msg();
1215#endif
1216
1217 return 1;
1218}
1219
1220/* Dump the current file structure to stderr */
1221void dump_buffer(filestruct * inptr)
1222{
1223#ifdef DEBUG
1224 filestruct *fileptr;
1225
1226 if (inptr == fileage)
1227 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1228 else if (inptr == cutbuffer)
1229 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1230 else
1231 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1232
1233 fileptr = inptr;
1234 while (fileptr != NULL) {
1235 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1236 fflush(stderr);
1237 fileptr = fileptr->next;
1238 }
1239#endif /* DEBUG */
1240}
1241
1242void dump_buffer_reverse(filestruct * inptr)
1243{
1244#ifdef DEBUG
1245 filestruct *fileptr;
1246
1247 fileptr = filebot;
1248 while (fileptr != NULL) {
1249 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1250 fflush(stderr);
1251 fileptr = fileptr->prev;
1252 }
1253#endif /* DEBUG */
1254}
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001255
1256/* Fix editbot based on the assumption that edittop is correct */
1257void fix_editbot(void) {
1258 int i;
1259 editbot = edittop;
1260 for(i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
1261 && (editbot != filebot); i++, editbot = editbot->next);
1262}
1263