blob: 429bee9051c055f6f4812f9e6fb1b6003dc65459 [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>
23#include "config.h"
24#include "proto.h"
25#include "nano.h"
26
27#ifndef NANO_SMALL
28#include <libintl.h>
29#define _(string) gettext(string)
30#else
31#define _(string) (string)
32#endif
33
34static int statblank = 0; /* Number of keystrokes left after
35 we call statubar() before we
36 actually blank the statusbar */
Robert Siemborskid8510b22000-06-06 23:04:06 +000037
38/* Local Function Prototypes for only winio.c */
39inline int get_page_from_virtual(int virtual);
40inline int get_page_start_virtual(int page);
41inline int get_page_end_virtual(int page);
42
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000043/* Window I/O */
44
45int do_first_line(void)
46{
47 current = fileage;
48 placewewant = 0;
49 current_x = 0;
50 edit_update(current);
51 return 1;
52}
53
54int do_last_line(void)
55{
56 current = filebot;
57 placewewant = 0;
58 current_x = 0;
59 edit_update(current);
60 return 1;
61}
62
63/* Like xplustabs, but for a specifc index of a speficific filestruct */
64int xpt(filestruct * fileptr, int index)
65{
66 int i, tabs = 0;
67
68 if (fileptr == NULL || fileptr->data == NULL)
69 return 0;
70
71 for (i = 0; i < index && fileptr->data[i] != 0; i++) {
72 tabs++;
73
74 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta6724a7e2000-06-19 23:19:07 +000075 if (tabs % TABSIZE == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000076 else
Chris Allegretta6724a7e2000-06-19 23:19:07 +000077 tabs += TABSIZE - (tabs % TABSIZE);
Chris Allegretta4da1fc62000-06-21 03:00:43 +000078 } else if (fileptr->data[i] & 0x80)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +000079 /* Make 8 bit chars only 1 collumn! */
80 ;
81 else if (fileptr->data[i] < 32)
82 tabs++;
83 }
84
85 return tabs;
86}
87
88
89/* Return the actual place on the screen of current->data[current_x], which
90 should always be > current_x */
91int xplustabs(void)
92{
93 return xpt(current, current_x);
94}
95
96
Robert Siemborskid8510b22000-06-06 23:04:06 +000097/* Return what current_x should be, given xplustabs() for the line,
98 * given a start position in the filestruct's data */
99int actual_x_from_start(filestruct * fileptr, int xplus, int start)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000100{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000101 int i, tot = 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000102
103 if (fileptr == NULL || fileptr->data == NULL)
104 return 0;
105
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000106 for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000107 if (fileptr->data[i] == NANO_CONTROL_I) {
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000108 if (tot % TABSIZE == 0)
109 tot++;
110 else
111 tot += TABSIZE - (tot % TABSIZE);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000112 } else if (fileptr->data[i] & 0x80)
113 tot++; /* Make 8 bit chars only 1 column (again) */
114 else if (fileptr->data[i] < 32)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000115 tot += 2;
116
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000117#ifdef DEBUG
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000118 fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"),
119 xplus, i);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000120#endif
Robert Siemborskid8510b22000-06-06 23:04:06 +0000121 return i - start;
122}
123
124/* Opposite of xplustabs */
125inline int actual_x(filestruct * fileptr, int xplus)
126{
127 return actual_x_from_start(fileptr, xplus, 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000128}
129
130/* a strlen with tabs factored in, similar to xplustabs() */
131int strlenpt(char *buf)
132{
133 int i, tabs = 0;
134
135 if (buf == NULL)
136 return 0;
137
138 for (i = 0; buf[i] != 0; i++) {
139 tabs++;
140
141 if (buf[i] == NANO_CONTROL_I) {
Chris Allegretta6724a7e2000-06-19 23:19:07 +0000142 if (tabs % TABSIZE == 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000143 else
Chris Allegretta6724a7e2000-06-19 23:19:07 +0000144 tabs += TABSIZE - (tabs % TABSIZE);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000145 } else if (buf[i] & 0x80)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000146 /* Make 8 bit chars only 1 collumn! */
147 ;
148 else if (buf[i] < 32)
149 tabs++;
150 }
151
152 return tabs;
153}
154
155
156/* resets current_y based on the position of current and puts the cursor at
157 (current_y, current_x) */
158void reset_cursor(void)
159{
160 filestruct *ptr = edittop;
161 int x;
162
163 current_y = 0;
164
165 while (ptr != current && ptr != editbot && ptr->next != NULL) {
166 ptr = ptr->next;
167 current_y++;
168 }
169
170 x = xplustabs();
171 if (x <= COLS - 2)
Robert Siemborskid8510b22000-06-06 23:04:06 +0000172 wmove(edit, current_y, x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000173 else
Robert Siemborskid8510b22000-06-06 23:04:06 +0000174 wmove(edit, current_y, x -
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000175 get_page_start_virtual(get_page_from_virtual(x)));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000176
177}
178
179void blank_bottombars(void)
180{
181 int i = no_help()? 3 : 1;
182
183 for (; i <= 2; i++)
184 mvwaddstr(bottomwin, i, 0, hblank);
185
186}
187
188void blank_edit(void)
189{
190 int i;
191 for (i = 0; i <= editwinrows - 1; i++)
192 mvwaddstr(edit, i, 0, hblank);
193 wrefresh(edit);
194}
195
196
197void blank_statusbar(void)
198{
199 mvwaddstr(bottomwin, 0, 0, hblank);
200}
201
202void blank_statusbar_refresh(void)
203{
204 blank_statusbar();
205 wrefresh(bottomwin);
206}
207
208void check_statblank(void)
209{
210
211 if (statblank > 1)
212 statblank--;
213 else if (statblank == 1 && !ISSET(CONSTUPDATE)) {
214 statblank--;
215 blank_statusbar_refresh();
216 }
217}
218
219/* Get the input from the kb, this should only be called from statusq */
220int nanogetstr(char *buf, char *def, shortcut s[], int slen, int start_x)
221{
222 int kbinput = 0, j = 0, x = 0, xend;
223 int x_left = 0;
224 char inputstr[132], inputbuf[132] = "";
225
226 blank_statusbar();
227 mvwaddstr(bottomwin, 0, 0, buf);
228 if (strlen(def) > 0)
229 waddstr(bottomwin, def);
230 wrefresh(bottomwin);
231
232 x_left = strlen(buf);
233 x = strlen(def) + x_left;
234
235 /* Get the input! */
236 if (strlen(def) > 0) {
237 strcpy(answer, def);
238 strcpy(inputbuf, def);
239 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000240
241 while ((kbinput = wgetch(bottomwin)) != 13) {
242 for (j = 0; j <= slen - 1; j++) {
243 if (kbinput == s[j].val) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000244 strcpy(answer, "");
245 return s[j].val;
246 }
247 }
248 xend = strlen(buf) + strlen(inputbuf);
249
250 switch (kbinput) {
251 case KEY_HOME:
252 x = x_left;
253 blank_statusbar();
254 mvwaddstr(bottomwin, 0, 0, buf);
255 waddstr(bottomwin, inputbuf);
256 wmove(bottomwin, 0, x);
257 break;
258 case KEY_END:
259 x = x_left + strlen(inputbuf);
260 blank_statusbar();
261 mvwaddstr(bottomwin, 0, 0, buf);
262 waddstr(bottomwin, inputbuf);
263 wmove(bottomwin, 0, x);
264 break;
265 case KEY_RIGHT:
266
267 if (x < xend)
268 x++;
269 wmove(bottomwin, 0, x);
270 break;
271 case NANO_CONTROL_D:
272 if (strlen(inputbuf) > 0 && (x - x_left) != strlen(inputbuf)) {
273 memmove(inputbuf + (x - x_left),
274 inputbuf + (x - x_left) + 1,
275 strlen(inputbuf) - (x - x_left) - 1);
276 inputbuf[strlen(inputbuf) - 1] = 0;
277 }
278 blank_statusbar();
279 mvwaddstr(bottomwin, 0, 0, buf);
280 waddstr(bottomwin, inputbuf);
281 wmove(bottomwin, 0, x);
282 break;
283 case NANO_CONTROL_K:
284 case NANO_CONTROL_U:
285 *inputbuf = 0;
286 x = x_left;
287 blank_statusbar();
288 mvwaddstr(bottomwin, 0, 0, buf);
289 waddstr(bottomwin, inputbuf);
290 wmove(bottomwin, 0, x);
291 break;
292 case KEY_BACKSPACE:
293 case KEY_DC:
294 case 127:
295 case NANO_CONTROL_H:
296 if (strlen(inputbuf) > 0) {
297 if (x == (x_left + strlen(inputbuf)))
298 inputbuf[strlen(inputbuf) - 1] = 0;
299 else if (x - x_left) {
300 memmove(inputbuf + (x - x_left) - 1,
301 inputbuf + (x - x_left),
302 strlen(inputbuf) - (x - x_left));
303 inputbuf[strlen(inputbuf) - 1] = 0;
304 }
305 }
306 blank_statusbar();
307 mvwaddstr(bottomwin, 0, 0, buf);
308 waddstr(bottomwin, inputbuf);
309 case KEY_LEFT:
310 if (x > strlen(buf))
311 x--;
312 wmove(bottomwin, 0, x);
313 break;
314 case KEY_UP:
315 case KEY_DOWN:
316 break;
317
318 case 27:
319 switch (kbinput = wgetch(edit)) {
320 case 79:
321 switch (kbinput = wgetch(edit)) {
322 case 70:
323 x = x_left + strlen(inputbuf);
324 blank_statusbar();
325 mvwaddstr(bottomwin, 0, 0, buf);
326 waddstr(bottomwin, inputbuf);
327 wmove(bottomwin, 0, x);
328 break;
329 case 72:
330 x = x_left;
331 blank_statusbar();
332 mvwaddstr(bottomwin, 0, 0, buf);
333 waddstr(bottomwin, inputbuf);
334 wmove(bottomwin, 0, x);
335 break;
336 }
337 break;
338 case 91:
339 switch (kbinput = wgetch(edit)) {
340 case 'C':
341 if (x < xend)
342 x++;
343 wmove(bottomwin, 0, x);
344 break;
345 case 'D':
346 if (x > strlen(buf))
347 x--;
348 wmove(bottomwin, 0, x);
349 break;
350 case 49:
351 x = x_left;
352 blank_statusbar();
353 mvwaddstr(bottomwin, 0, 0, buf);
354 waddstr(bottomwin, inputbuf);
355 wmove(bottomwin, 0, x);
356 goto skip_126;
357 case 51:
358 if (strlen(inputbuf) > 0
359 && (x - x_left) != strlen(inputbuf)) {
360 memmove(inputbuf + (x - x_left),
361 inputbuf + (x - x_left) + 1,
362 strlen(inputbuf) - (x - x_left) - 1);
363 inputbuf[strlen(inputbuf) - 1] = 0;
364 }
365 blank_statusbar();
366 mvwaddstr(bottomwin, 0, 0, buf);
367 waddstr(bottomwin, inputbuf);
368 wmove(bottomwin, 0, x);
369 goto skip_126;
370 case 52:
371 x = x_left + strlen(inputbuf);
372 blank_statusbar();
373 mvwaddstr(bottomwin, 0, 0, buf);
374 waddstr(bottomwin, inputbuf);
375 wmove(bottomwin, 0, x);
376 goto skip_126;
377 skip_126:
378 nodelay(edit, TRUE);
379 kbinput = wgetch(edit);
380 if (kbinput == 126 || kbinput == ERR)
381 kbinput = -1;
382 nodelay(edit, FALSE);
383 break;
384 }
385 }
386 blank_statusbar();
387 mvwaddstr(bottomwin, 0, 0, buf);
388 waddstr(bottomwin, inputbuf);
389 wmove(bottomwin, 0, x);
390 break;
391
392
393 default:
394 if (kbinput < 32)
395 break;
396 strcpy(inputstr, inputbuf);
397 inputstr[x - strlen(buf)] = kbinput;
398 strcpy(&inputstr[x - strlen(buf) + 1],
399 &inputbuf[x - strlen(buf)]);
400 strcpy(inputbuf, inputstr);
401 x++;
402
403 mvwaddstr(bottomwin, 0, 0, buf);
404 waddstr(bottomwin, inputbuf);
405 wmove(bottomwin, 0, x);
406
407#ifdef DEBUG
408 fprintf(stderr, _("input \'%c\' (%d)\n"), kbinput, kbinput);
409#endif
410 }
411 wrefresh(bottomwin);
412 }
413
414 strncpy(answer, inputbuf, 132);
415
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000416 if (!strcmp(answer, ""))
417 return -2;
418 else
419 return 0;
420}
421
422void horizbar(WINDOW * win, int y)
423{
424 wattron(win, A_REVERSE);
425 mvwaddstr(win, 0, 0, hblank);
426 wattroff(win, A_REVERSE);
427}
428
429void titlebar(void)
430{
431 int namelen, space;
432
433 horizbar(topwin, 0);
434 wattron(topwin, A_REVERSE);
435 mvwaddstr(topwin, 0, 3, VERMSG);
436
437 space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
438
439 namelen = strlen(filename);
440
441 if (!strcmp(filename, ""))
442 mvwaddstr(topwin, 0, center_x - 6, _("New Buffer"));
443 else {
444 if (namelen > space) {
445 waddstr(topwin, _(" File: ..."));
446 waddstr(topwin, &filename[namelen - space]);
447 } else {
448 mvwaddstr(topwin, 0, center_x - (namelen / 2 + 1), "File: ");
449 waddstr(topwin, filename);
450 }
451 }
452 if (ISSET(MODIFIED))
453 mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
454 wattroff(topwin, A_REVERSE);
455 wrefresh(topwin);
456 reset_cursor();
457}
458
459void onekey(char *keystroke, char *desc)
460{
461 char description[80];
462
463 snprintf(description, 12, " %-11s", desc);
464 wattron(bottomwin, A_REVERSE);
465 waddstr(bottomwin, keystroke);
466 wattroff(bottomwin, A_REVERSE);
467 waddstr(bottomwin, description);
468}
469
470void clear_bottomwin(void)
471{
472 if (ISSET(NO_HELP))
473 return;
474
475 mvwaddstr(bottomwin, 1, 0, hblank);
476 mvwaddstr(bottomwin, 2, 0, hblank);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000477}
478
479void bottombars(shortcut s[], int slen)
480{
481 int i, j, k;
482 char keystr[10];
483
484 if (ISSET(NO_HELP))
485 return;
486
487 /* Determine how many extra spaces are needed to fill the bottom of the screen */
488 k = COLS / 6 - 13;
489
490 clear_bottomwin();
491 wmove(bottomwin, 1, 0);
492 for (i = 0; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000493 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000494 onekey(keystr, s[i].desc);
495
496 for (j = 0; j < k; j++)
497 waddch(bottomwin, ' ');
498 }
499
500 wmove(bottomwin, 2, 0);
501 for (i = 1; i <= slen - 1; i += 2) {
Robert Siemborski6af14312000-07-01 21:34:26 +0000502 snprintf(keystr, 10, "^%c", s[i].val + 64);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000503 onekey(keystr, s[i].desc);
504
505 for (j = 0; j < k; j++)
506 waddch(bottomwin, ' ');
507 }
508
509 wrefresh(bottomwin);
510
511}
512
513/* If modified is not already set, set it and update titlebar */
514void set_modified(void)
515{
516 if (!ISSET(MODIFIED)) {
517 SET(MODIFIED);
518 titlebar();
519 wrefresh(topwin);
520 }
521}
522
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000523inline int get_page_from_virtual(int virtual)
524{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000525 int page = 2;
526
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000527 if (virtual <= COLS - 2)
528 return 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000529 virtual -= (COLS - 2);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000530
531 while (virtual > COLS - 2 - 7) {
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000532 virtual -= (COLS - 2 - 7);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000533 page++;
534 }
535
536 return page;
537}
538
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000539inline int get_page_start_virtual(int page)
540{
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000541 int virtual;
542 virtual = --page * (COLS - 7);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000543 if (page)
544 virtual -= 2 * page - 1;
Robert Siemborskie8c6fd02000-06-07 04:40:09 +0000545 return virtual;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000546}
547
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000548inline int get_page_end_virtual(int page)
549{
Robert Siemborskid8510b22000-06-06 23:04:06 +0000550 return get_page_start_virtual(page) + COLS - 1;
551}
552
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000553#ifndef NANO_SMALL
Robert Siemborski53875912000-06-16 04:25:30 +0000554/* Called only from edit_add, and therefore expects a
555 * converted-to-only-spaces line */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000556void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
557 int virt_cur_x, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000558{
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000559 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborski53875912000-06-16 04:25:30 +0000560 this_page_end = get_page_end_virtual(this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000561
562 /* 3 start points: 0 -> begin, begin->end, end->strlen(data) */
563 /* in data : pre sel post */
Robert Siemborskid8510b22000-06-06 23:04:06 +0000564 /* likewise, 3 data lengths */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000565 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 +0000566
567 /* now fix the start locations & lengths according to the cursor's
568 * position (ie: our page) */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000569 if (pre_data_len < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000570 pre_data_len = 0;
571 else
572 pre_data_len -= this_page_start;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000573
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000574 if (begin < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000575 begin = this_page_start;
576
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000577 if (end < this_page_start)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000578 end = this_page_start;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000579
Robert Siemborskid8510b22000-06-06 23:04:06 +0000580 /* we don't care about end, because it will just get cropped
581 * due to length */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000582 if (begin > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000583 begin = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000584
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000585 if (end > this_page_end)
Robert Siemborskia9addc72000-06-17 06:06:35 +0000586 end = this_page_end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000587
Robert Siemborskia9addc72000-06-17 06:06:35 +0000588 sel_data_len = end - begin;
589 post_data_len = this_page_end - end;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000590
Robert Siemborski53875912000-06-16 04:25:30 +0000591 mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000592 wattron(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000593 mvwaddnstr(edit, y, begin - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000594 &fileptr->data[begin], sel_data_len);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000595 wattroff(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000596 mvwaddnstr(edit, y, end - this_page_start,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000597 &fileptr->data[end], post_data_len);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000598}
599#endif
600
Robert Siemborski53875912000-06-16 04:25:30 +0000601/* Called only from update_line. Expects a converted-to-not-have-tabs
602 * line */
603void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000604 int virt_mark_beginx, int this_page)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000605{
606#ifndef NANO_SMALL
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000607 if (ISSET(MARK_ISSET)) {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000608 if ((fileptr->lineno > mark_beginbuf->lineno
609 && fileptr->lineno > current->lineno)
610 || (fileptr->lineno < mark_beginbuf->lineno
611 && fileptr->lineno < current->lineno)) {
612
613 /* We're on a normal, unselected line */
Robert Siemborski53875912000-06-16 04:25:30 +0000614 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000615 } else {
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000616 if (fileptr != mark_beginbuf && fileptr != current) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000617 /* We're on selected text */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000618 wattron(edit, A_REVERSE);
Robert Siemborski53875912000-06-16 04:25:30 +0000619 mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000620 wattroff(edit, A_REVERSE);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000621 } else if (fileptr == mark_beginbuf && fileptr == current) {
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000622 /* Special case, we're still on the same line we started
Robert Siemborskia9addc72000-06-17 06:06:35 +0000623 * marking */
Robert Siemborski53875912000-06-16 04:25:30 +0000624 if (virt_cur_x < virt_mark_beginx)
625 add_marked_sameline(virt_cur_x, virt_mark_beginx,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000626 fileptr, yval, virt_cur_x,
627 this_page);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000628 else
Robert Siemborski53875912000-06-16 04:25:30 +0000629 add_marked_sameline(virt_mark_beginx, virt_cur_x,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000630 fileptr, yval, virt_cur_x,
631 this_page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000632 } else if (fileptr == mark_beginbuf) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000633 /* we're updating the line that was first marked */
Robert Siemborskid8510b22000-06-06 23:04:06 +0000634 int target;
635
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000636 if (mark_beginbuf->lineno > current->lineno)
637 wattron(edit, A_REVERSE);
638
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000639 target =
640 (virt_mark_beginx <
641 COLS - 1) ? virt_mark_beginx : COLS - 1;
Robert Siemborskid8510b22000-06-06 23:04:06 +0000642
Robert Siemborski53875912000-06-16 04:25:30 +0000643 mvwaddnstr(edit, yval, 0, fileptr->data, target);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000644
645 if (mark_beginbuf->lineno < current->lineno)
646 wattron(edit, A_REVERSE);
647 else
648 wattroff(edit, A_REVERSE);
649
Robert Siemborski53875912000-06-16 04:25:30 +0000650 target = (COLS - 1) - virt_mark_beginx;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000651 if (target < 0)
652 target = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000653
Robert Siemborski53875912000-06-16 04:25:30 +0000654 mvwaddnstr(edit, yval, virt_mark_beginx,
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000655 &fileptr->data[virt_mark_beginx], target);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000656
657 if (mark_beginbuf->lineno < current->lineno)
658 wattroff(edit, A_REVERSE);
659
660 } else if (fileptr == current) {
Robert Siemborskid8510b22000-06-06 23:04:06 +0000661 /* we're on the cursors line, but it's not the first
662 * one we marked... */
Robert Siemborskia9addc72000-06-17 06:06:35 +0000663 int this_page_start = get_page_start_virtual(this_page),
Robert Siemborskid8510b22000-06-06 23:04:06 +0000664 this_page_end = get_page_end_virtual(this_page);
665
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000666 if (mark_beginbuf->lineno < current->lineno)
667 wattron(edit, A_REVERSE);
668
Robert Siemborski53875912000-06-16 04:25:30 +0000669 if (virt_cur_x > COLS - 2) {
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000670 mvwaddnstr(edit, yval, 0,
671 &fileptr->data[this_page_start],
672 virt_cur_x - this_page_start);
Robert Siemborski53875912000-06-16 04:25:30 +0000673 } else {
674 mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
675 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000676
677 if (mark_beginbuf->lineno > current->lineno)
678 wattron(edit, A_REVERSE);
679 else
680 wattroff(edit, A_REVERSE);
681
Robert Siemborskia9addc72000-06-17 06:06:35 +0000682 if (virt_cur_x > COLS - 2)
Robert Siemborski53875912000-06-16 04:25:30 +0000683 mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
684 &fileptr->data[virt_cur_x],
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000685 this_page_end - virt_cur_x);
Robert Siemborskia9addc72000-06-17 06:06:35 +0000686 else
Robert Siemborski53875912000-06-16 04:25:30 +0000687 mvwaddnstr(edit, yval, virt_cur_x,
688 &fileptr->data[virt_cur_x],
689 COLS - virt_cur_x);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000690
691 if (mark_beginbuf->lineno > current->lineno)
692 wattroff(edit, A_REVERSE);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000693 }
694 }
695
696 } else
697#endif
Robert Siemborskia9addc72000-06-17 06:06:35 +0000698 mvwaddnstr(edit, yval, 0, &fileptr->data[start],
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000699 get_page_end_virtual(this_page) - start);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000700}
701
702/*
703 * Just update one line in the edit buffer
704 *
705 * index gives is a place in the string to update starting from.
706 * Likely args are current_x or 0.
707 */
708void update_line(filestruct * fileptr, int index)
709{
710 filestruct *filetmp;
Robert Siemborski53875912000-06-16 04:25:30 +0000711 int line = 0, col = 0;
712 int virt_cur_x = current_x, virt_mark_beginx = mark_beginx;
713 char *realdata, *tmp;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000714 int i, pos, len, page;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000715
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000716 if (!fileptr)
717 return;
Robert Siemborski53154a72000-06-18 00:11:03 +0000718
Robert Siemborski53875912000-06-16 04:25:30 +0000719 /* First, blank out the line (at a minimum) */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000720 for (filetmp = edittop; filetmp != fileptr && filetmp != editbot;
721 filetmp = filetmp->next)
722 line++;
723
724 mvwaddstr(edit, line, 0, hblank);
725
Robert Siemborski53875912000-06-16 04:25:30 +0000726 /* Next, convert all the tabs to spaces so everything else is easy */
727 index = xpt(fileptr, index);
728
729 realdata = fileptr->data;
730 len = strlen(realdata);
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000731 fileptr->data = nmalloc(xpt(fileptr, len) + 1);
Robert Siemborski53875912000-06-16 04:25:30 +0000732
733 pos = 0;
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000734 for (i = 0; i < len; i++) {
735 if (realdata[i] == '\t') {
Robert Siemborski53875912000-06-16 04:25:30 +0000736 do {
737 fileptr->data[pos++] = ' ';
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000738 if (i < current_x)
739 virt_cur_x++;
740 if (i < mark_beginx)
741 virt_mark_beginx++;
742 } while (pos % TABSIZE);
Robert Siemborski53875912000-06-16 04:25:30 +0000743 /* must decrement once to account for tab-is-one-character */
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000744 if (i < current_x)
745 virt_cur_x--;
746 if (i < mark_beginx)
747 virt_mark_beginx--;
Robert Siemborski53875912000-06-16 04:25:30 +0000748 } else {
749 fileptr->data[pos++] = realdata[i];
750 }
751 }
752
753 fileptr->data[pos] = '\0';
754
755 /* Now, Paint the line */
756 if (current == fileptr && index > COLS - 2) {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000757 /* This handles when the current line is beyond COLS */
758 /* It requires figureing out what page we're at */
759 page = get_page_from_virtual(index);
Robert Siemborskid8510b22000-06-06 23:04:06 +0000760 col = get_page_start_virtual(page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000761
Robert Siemborskia9addc72000-06-17 06:06:35 +0000762 edit_add(filetmp, line, col, virt_cur_x, virt_mark_beginx, page);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000763 mvwaddch(edit, line, 0, '$');
764
Robert Siemborskid8510b22000-06-06 23:04:06 +0000765 if (strlenpt(fileptr->data) > get_page_end_virtual(page))
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000766 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000767 } else {
Robert Siemborskia9addc72000-06-17 06:06:35 +0000768 /* It's not the current line means that it's at x=0 and page=1 */
769 /* If it is the current line, then we're in the same boat */
770 edit_add(filetmp, line, 0, virt_cur_x, virt_mark_beginx, 1);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000771
Robert Siemborski53875912000-06-16 04:25:30 +0000772 if (strlenpt(&filetmp->data[col]) > COLS)
Chris Allegretta4da1fc62000-06-21 03:00:43 +0000773 mvwaddch(edit, line, COLS - 1, '$');
Robert Siemborskid8510b22000-06-06 23:04:06 +0000774 }
Robert Siemborski53875912000-06-16 04:25:30 +0000775
776 /* Clean up our mess */
777 tmp = fileptr->data;
778 fileptr->data = realdata;
779 free(tmp);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000780}
781
782void center_cursor(void)
783{
784 current_y = editwinrows / 2;
785 wmove(edit, current_y, current_x);
786}
787
788/* Refresh the screen without changing the position of lines */
789void edit_refresh(void)
790{
791 int lines = 0, i = 0;
792 filestruct *temp, *hold = current;
793
794 if (current == NULL)
795 return;
796
797 temp = edittop;
798
799 while (lines <= editwinrows - 1 && lines <= totlines && temp != NULL) {
800 hold = temp;
801 update_line(temp, current_x);
802 temp = temp->next;
803 lines++;
804 }
805
806 if (lines <= editwinrows - 1)
807 while (lines <= editwinrows - 1) {
808 mvwaddstr(edit, lines, i, hblank);
809 lines++;
810 }
811 if (temp == NULL)
812 editbot = hold;
813 else
814 editbot = temp;
815}
816
817/*
818 * Nice generic routine to update the edit buffer given a pointer to the
819 * file struct =)
820 */
821void edit_update(filestruct * fileptr)
822{
Robert Siemborski29e9a762000-07-05 03:16:04 +0000823 int i = 0;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000824 filestruct *temp;
825
826 if (fileptr == NULL)
827 return;
828
829 temp = fileptr;
830 while (i <= editwinrows / 2 && temp->prev != NULL) {
831 i++;
832 temp = temp->prev;
833 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000834
Robert Siemborski29e9a762000-07-05 03:16:04 +0000835 edittop = temp;
836 fix_editbot();
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000837
838 edit_refresh();
839}
840
841/* Now we want to update the screen using this struct as the top of the edit buffer */
842void edit_update_top(filestruct * fileptr)
843{
844 int i;
845 filestruct *temp = fileptr;
846
Chris Allegretta1e57e682000-07-03 04:24:39 +0000847 if (fileptr == NULL)
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000848 return;
849
850 i = 0;
851 while (i <= editwinrows / 2 && temp->next != NULL) {
852 i++;
853 temp = temp->next;
854 }
855 edit_update(temp);
856}
857
858/* And also for the bottom... */
859void edit_update_bot(filestruct * fileptr)
860{
861 int i;
862 filestruct *temp = fileptr;
863
864 i = 0;
865 while (i <= editwinrows / 2 - 1 && temp->prev != NULL) {
866 i++;
867 temp = temp->prev;
868 }
869 edit_update(temp);
870}
871
872/* This function updates current based on where current_y is, reset_cursor
873 does the opposite */
874void update_cursor(void)
875{
876 int i = 0;
877
878#ifdef DEBUG
879 fprintf(stderr, _("Moved to (%d, %d) in edit buffer\n"), current_y,
880 current_x);
881#endif
882
883 current = edittop;
884 while (i <= current_y - 1 && current->next != NULL) {
885 current = current->next;
886 i++;
887 }
888
889#ifdef DEBUG
890 fprintf(stderr, _("current->data = \"%s\"\n"), current->data);
891#endif
892
893}
894
895/*
896 * Ask a question on the statusbar. Answer will be stored in answer
897 * global. Returns -1 on aborted enter, -2 on a blank string, and 0
898 * otherwise, the valid shortcut key caught, Def is any editable text we
899 * want to put up by default.
900 */
901int statusq(shortcut s[], int slen, char *def, char *msg, ...)
902{
903 va_list ap;
904 char foo[133];
905 int ret;
906
907 bottombars(s, slen);
908
909 va_start(ap, msg);
910 vsnprintf(foo, 132, msg, ap);
911 strncat(foo, ": ", 132);
912 va_end(ap);
913
914 wattron(bottomwin, A_REVERSE);
915 ret = nanogetstr(foo, def, s, slen, (strlen(foo) + 3));
916 wattroff(bottomwin, A_REVERSE);
917
918 switch (ret) {
919
920 case NANO_FIRSTLINE_KEY:
921 do_first_line();
922 break;
923 case NANO_LASTLINE_KEY:
924 do_last_line();
925 break;
926 case NANO_CANCEL_KEY:
927 return -1;
928 default:
929 blank_statusbar_refresh();
930 }
931
932#ifdef DEBUG
933 fprintf(stderr, _("I got \"%s\"\n"), answer);
934#endif
935
936 return ret;
937}
938
939/*
940 * Ask a simple yes/no question on the statusbar. Returns 1 for Y, 0 for
941 * N, 2 for All (if all is non-zero when passed in) and -1 for abort (^C)
942 */
943int do_yesno(int all, int leavecursor, char *msg, ...)
944{
945 va_list ap;
946 char foo[133];
947 int kbinput, ok = -1;
948
949 /* Write the bottom of the screen */
950 clear_bottomwin();
951 wattron(bottomwin, A_REVERSE);
952 blank_statusbar_refresh();
953 wattroff(bottomwin, A_REVERSE);
954
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000955 /* Remove gettext call for keybindings until we clear the thing up */
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000956 if (!ISSET(NO_HELP)) {
957 wmove(bottomwin, 1, 0);
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000958 onekey(" Y", _("Yes"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000959 if (all)
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000960 onekey(" A", _("All"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000961 wmove(bottomwin, 2, 0);
Jordi Mallach0b0fc492000-06-23 01:00:13 +0000962 onekey(" N", _("No"));
963 onekey("^C", _("Cancel"));
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000964 }
965 va_start(ap, msg);
966 vsnprintf(foo, 132, msg, ap);
967 va_end(ap);
968 wattron(bottomwin, A_REVERSE);
969 mvwaddstr(bottomwin, 0, 0, foo);
970 wattroff(bottomwin, A_REVERSE);
971 wrefresh(bottomwin);
972
973 if (leavecursor == 1)
974 reset_cursor();
975
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000976 while (ok == -1) {
977 kbinput = wgetch(edit);
978
979 switch (kbinput) {
980 case 'Y':
981 case 'y':
982 ok = 1;
983 break;
984 case 'N':
985 case 'n':
986 ok = 0;
987 break;
988 case 'A':
989 case 'a':
990 if (all)
991 ok = 2;
992 break;
993 case NANO_CONTROL_C:
994 ok = -2;
995 break;
996 }
997 }
Chris Allegrettaa2ea1932000-06-06 05:53:49 +0000998
999 /* Then blank the screen */
1000 blank_statusbar_refresh();
1001
1002 if (ok == -2)
1003 return -1;
1004 else
1005 return ok;
1006}
1007
1008void statusbar(char *msg, ...)
1009{
1010 va_list ap;
1011 char foo[133];
1012 int start_x = 0;
1013
1014 va_start(ap, msg);
1015 vsnprintf(foo, 132, msg, ap);
1016 va_end(ap);
1017
1018 start_x = center_x - strlen(foo) / 2 - 1;
1019
1020 /* Blank out line */
1021 blank_statusbar();
1022
1023 wmove(bottomwin, 0, start_x);
1024
1025 wattron(bottomwin, A_REVERSE);
1026
1027 waddstr(bottomwin, "[ ");
1028 waddstr(bottomwin, foo);
1029 waddstr(bottomwin, " ]");
1030 wattroff(bottomwin, A_REVERSE);
1031 wrefresh(bottomwin);
1032
1033 if (ISSET(CONSTUPDATE))
1034 statblank = 1;
1035 else
1036 statblank = 25;
1037}
1038
1039void display_main_list(void)
1040{
1041 bottombars(main_list, MAIN_VISIBLE);
1042}
1043
1044int total_refresh(void)
1045{
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001046 clearok(edit, TRUE);
1047 clearok(topwin, TRUE);
1048 clearok(bottomwin, TRUE);
1049 wnoutrefresh(edit);
1050 wnoutrefresh(topwin);
1051 wnoutrefresh(bottomwin);
1052 doupdate();
1053 clearok(edit, FALSE);
1054 clearok(topwin, FALSE);
1055 clearok(bottomwin, FALSE);
1056
1057 return 1;
1058}
1059
1060void previous_line(void)
1061{
1062 if (current_y > 0)
1063 current_y--;
1064}
1065
1066int do_cursorpos(void)
1067{
1068 filestruct *fileptr;
1069 float linepct, bytepct;
1070 int i, tot = 0;
1071
1072 if (current == NULL || fileage == NULL)
1073 return 0;
1074
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001075 for (fileptr = fileage; fileptr != current && fileptr != NULL;
1076 fileptr = fileptr->next)
1077 tot += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001078
1079 if (fileptr == NULL)
1080 return -1;
1081
1082 i = tot + current_x;;
1083
1084 for (fileptr = current->next; fileptr != NULL; fileptr = fileptr->next)
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001085 tot += strlen(fileptr->data) + 1;
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001086
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001087 if (totlines > 0)
1088 linepct = 100 * current->lineno / totlines;
1089 else
1090 linepct = 0;
1091
1092 if (totsize > 0)
1093 bytepct = 100 * i / totsize;
1094 else
1095 bytepct = 0;
1096
1097#ifdef DEBUG
1098 fprintf(stderr, _("do_cursorpos: linepct = %f, bytepct = %f\n"),
1099 linepct, bytepct);
1100#endif
1101
1102 statusbar(_("line %d of %d (%.0f%%), character %d of %d (%.0f%%)"),
1103 current->lineno, totlines, linepct, i, totsize, bytepct);
1104 reset_cursor();
1105 return 1;
1106}
1107
1108/* Our broken, non-shortcut list compliant help function.
1109 But hey, it's better than nothing, and it's dynamic! */
1110int do_help(void)
1111{
1112#ifndef NANO_SMALL
1113 char *ptr = help_text, *end;
1114 int i, j, row = 0, page = 1, kbinput = 0, no_more = 0;
1115 int no_help_flag = 0;
1116
1117 blank_edit();
1118 curs_set(0);
1119 blank_statusbar();
1120
1121 if (ISSET(NO_HELP)) {
1122
1123 no_help_flag = 1;
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001124 delwin(bottomwin);
1125 bottomwin = newwin(3, COLS, LINES - 3, 0);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001126 keypad(bottomwin, TRUE);
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001127
1128 editwinrows -= no_help();
1129 UNSET(NO_HELP);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001130 bottombars(help_list, HELP_LIST_LEN);
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001131 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001132 bottombars(help_list, HELP_LIST_LEN);
1133
1134 do {
1135 ptr = help_text;
1136 switch (kbinput) {
1137 case NANO_NEXTPAGE_KEY:
1138 case NANO_NEXTPAGE_FKEY:
1139 case KEY_NPAGE:
1140 if (!no_more) {
1141 blank_edit();
1142 page++;
1143 }
1144 break;
1145 case NANO_PREVPAGE_KEY:
1146 case NANO_PREVPAGE_FKEY:
1147 case KEY_PPAGE:
1148 if (page > 1) {
1149 no_more = 0;
1150 blank_edit();
1151 page--;
1152 }
1153 break;
1154 }
1155
1156 /* Calculate where in the text we should be based on the page */
1157 for (i = 1; i < page; i++) {
1158 row = 0;
1159 j = 0;
1160 while (row < editwinrows && *ptr != '\0') {
1161 if (*ptr == '\n' || j == COLS - 5) {
1162 j = 0;
1163 row++;
1164 }
1165 ptr++;
1166 j++;
1167 }
1168 }
1169
1170 i = 0;
1171 j = 0;
1172 while (i < editwinrows && *ptr != '\0') {
1173 end = ptr;
1174 while (*end != '\n' && *end != '\0' && j != COLS - 5) {
1175 end++;
1176 j++;
1177 }
1178 if (j == COLS - 5) {
1179
1180 /* Don't print half a word if we've run of of space */
1181 while (*end != ' ' && *end != '\0') {
1182 end--;
1183 j--;
1184 }
1185 }
1186 mvwaddnstr(edit, i, 0, ptr, j);
1187 j = 0;
1188 i++;
1189 if (*end == '\n')
1190 end++;
1191 ptr = end;
1192 }
1193 if (*ptr == '\0') {
1194 no_more = 1;
1195 continue;
1196 }
1197 } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY);
1198
1199 if (no_help_flag) {
1200 werase(bottomwin);
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001201 wrefresh(bottomwin);
1202 delwin(bottomwin);
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001203 SET(NO_HELP);
1204 bottomwin = newwin(3 - no_help(), COLS, LINES - 3 + no_help(), 0);
1205 keypad(bottomwin, TRUE);
1206 editwinrows += no_help();
Chris Allegretta4da1fc62000-06-21 03:00:43 +00001207 } else
Chris Allegrettaa2ea1932000-06-06 05:53:49 +00001208 display_main_list();
1209
1210 curs_set(1);
1211 edit_refresh();
1212#else
1213 nano_small_msg();
1214#endif
1215
1216 return 1;
1217}
1218
1219/* Dump the current file structure to stderr */
1220void dump_buffer(filestruct * inptr)
1221{
1222#ifdef DEBUG
1223 filestruct *fileptr;
1224
1225 if (inptr == fileage)
1226 fprintf(stderr, _("Dumping file buffer to stderr...\n"));
1227 else if (inptr == cutbuffer)
1228 fprintf(stderr, _("Dumping cutbuffer to stderr...\n"));
1229 else
1230 fprintf(stderr, _("Dumping a buffer to stderr...\n"));
1231
1232 fileptr = inptr;
1233 while (fileptr != NULL) {
1234 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1235 fflush(stderr);
1236 fileptr = fileptr->next;
1237 }
1238#endif /* DEBUG */
1239}
1240
1241void dump_buffer_reverse(filestruct * inptr)
1242{
1243#ifdef DEBUG
1244 filestruct *fileptr;
1245
1246 fileptr = filebot;
1247 while (fileptr != NULL) {
1248 fprintf(stderr, "(%ld) %s\n", fileptr->lineno, fileptr->data);
1249 fflush(stderr);
1250 fileptr = fileptr->prev;
1251 }
1252#endif /* DEBUG */
1253}
Robert Siemborskidd53ec22000-07-04 02:35:19 +00001254
1255/* Fix editbot based on the assumption that edittop is correct */
1256void fix_editbot(void) {
1257 int i;
1258 editbot = edittop;
1259 for(i = 0; (i <= editwinrows - 1) && (editbot->next != NULL)
1260 && (editbot != filebot); i++, editbot = editbot->next);
1261}
1262