Chris Allegretta | 11b0011 | 2000-08-06 21:13:45 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2 | /************************************************************************** |
| 3 | * nano.c * |
| 4 | * * |
| 5 | * Copyright (C) 1999 Chris Allegretta * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 1, or (at your option) * |
| 9 | * any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * |
| 19 | * * |
| 20 | **************************************************************************/ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <stdarg.h> |
| 25 | #include <signal.h> |
| 26 | #include <unistd.h> |
| 27 | #include <string.h> |
| 28 | #include <fcntl.h> |
| 29 | #include <sys/stat.h> |
| 30 | #include <sys/ioctl.h> |
| 31 | #include <sys/param.h> |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 32 | #include <sys/types.h> |
| 33 | #include <sys/wait.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 34 | #include <errno.h> |
| 35 | #include <ctype.h> |
| 36 | #include <locale.h> |
| 37 | #include <limits.h> |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 38 | #include <assert.h> |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 39 | |
| 40 | #include "config.h" |
| 41 | #include "proto.h" |
| 42 | #include "nano.h" |
| 43 | |
| 44 | #ifndef NANO_SMALL |
| 45 | #include <libintl.h> |
| 46 | #define _(string) gettext(string) |
| 47 | #else |
| 48 | #define _(string) (string) |
| 49 | #endif |
| 50 | |
| 51 | #ifdef HAVE_TERMIOS_H |
| 52 | #include <termios.h> |
| 53 | #endif |
| 54 | |
| 55 | #ifdef HAVE_TERMIO_H |
| 56 | #include <termio.h> |
| 57 | #endif |
| 58 | |
| 59 | #ifdef HAVE_GETOPT_H |
| 60 | #include <getopt.h> |
| 61 | #endif |
| 62 | |
| 63 | /* Former globals, now static */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 64 | int fill = 0; /* Fill - where to wrap lines, basically */ |
| 65 | static char *alt_speller; /* Alternative spell command */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 66 | struct termios oldterm; /* The user's original term settings */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 67 | static char *help_text_init = ""; |
| 68 | /* Initial message, not including shortcuts */ |
Chris Allegretta | 18f8be0 | 2000-09-04 03:20:38 +0000 | [diff] [blame] | 69 | static struct sigaction act; /* For all out fun signal handlers */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 70 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 71 | char *last_search = NULL; /* Last string we searched for */ |
| 72 | char *last_replace = NULL; /* Last replacement string */ |
| 73 | int search_last_line; /* Is this the last search line? */ |
| 74 | |
Chris Allegretta | 1cc0b7f | 2000-11-03 01:29:04 +0000 | [diff] [blame] | 75 | void keypad_on(int yesno) |
| 76 | { |
| 77 | keypad(edit, yesno); |
| 78 | keypad(bottomwin, yesno); |
| 79 | } |
| 80 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 81 | /* What we do when we're all set to exit */ |
| 82 | RETSIGTYPE finish(int sigage) |
| 83 | { |
| 84 | if (!ISSET(NO_HELP)) { |
| 85 | mvwaddstr(bottomwin, 1, 0, hblank); |
| 86 | mvwaddstr(bottomwin, 2, 0, hblank); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 87 | } else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 88 | mvwaddstr(bottomwin, 0, 0, hblank); |
Chris Allegretta | 1cc0b7f | 2000-11-03 01:29:04 +0000 | [diff] [blame] | 89 | |
| 90 | /* Apparently you REALLY can't get away with not calling keypad() |
| 91 | or your window looks awful when it exits. so we just call it right |
| 92 | before we exit, muhaha :-) */ |
| 93 | keypad_on(TRUE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 94 | wrefresh(bottomwin); |
| 95 | endwin(); |
| 96 | |
| 97 | /* Restore the old term settings */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 98 | tcsetattr(0, TCSANOW, &oldterm); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 99 | |
| 100 | exit(sigage); |
| 101 | } |
| 102 | |
| 103 | /* Die (gracefully?) */ |
| 104 | void die(char *msg, ...) |
| 105 | { |
| 106 | va_list ap; |
| 107 | |
| 108 | va_start(ap, msg); |
| 109 | vfprintf(stderr, msg, ap); |
| 110 | va_end(ap); |
| 111 | |
| 112 | /* if we can't save we have REAL bad problems, |
Robert Siemborski | fcf32bf | 2000-07-17 03:04:54 +0000 | [diff] [blame] | 113 | * but we might as well TRY. */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 114 | if (filename[0] == '\0') { |
Robert Siemborski | fcf32bf | 2000-07-17 03:04:54 +0000 | [diff] [blame] | 115 | write_file("nano.save", 0); |
| 116 | } else { |
| 117 | char buf[BUFSIZ]; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 118 | strncpy(buf, filename, BUFSIZ); |
| 119 | strncat(buf, ".save", BUFSIZ - strlen(buf)); |
Robert Siemborski | fcf32bf | 2000-07-17 03:04:54 +0000 | [diff] [blame] | 120 | write_file(buf, 0); |
| 121 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 122 | /* Restore the old term settings */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 123 | tcsetattr(0, TCSANOW, &oldterm); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 124 | |
| 125 | clear(); |
| 126 | refresh(); |
| 127 | resetty(); |
| 128 | endwin(); |
| 129 | |
| 130 | fprintf(stderr, msg); |
| 131 | fprintf(stderr, _("\nBuffer written to 'nano.save'\n")); |
| 132 | |
| 133 | exit(1); /* We have a problem: exit w/ errorlevel(1) */ |
| 134 | } |
| 135 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 136 | void print_view_warning(void) |
| 137 | { |
| 138 | statusbar(_("Key illegal in VIEW mode")); |
| 139 | } |
| 140 | |
Chris Allegretta | 1cc0b7f | 2000-11-03 01:29:04 +0000 | [diff] [blame] | 141 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 142 | /* Initialize global variables - no better way for now */ |
| 143 | void global_init(void) |
| 144 | { |
| 145 | int i; |
| 146 | |
| 147 | center_x = COLS / 2; |
| 148 | center_y = LINES / 2; |
| 149 | current_x = 0; |
| 150 | current_y = 0; |
| 151 | editwinrows = LINES - 5 + no_help(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 152 | fileage = NULL; |
| 153 | cutbuffer = NULL; |
| 154 | current = NULL; |
| 155 | edittop = NULL; |
| 156 | editbot = NULL; |
| 157 | totlines = 0; |
| 158 | placewewant = 0; |
| 159 | if (!fill) |
| 160 | fill = COLS - 8; |
| 161 | hblank = nmalloc(COLS + 1); |
| 162 | |
| 163 | /* Thanks BG for this bit... */ |
| 164 | for (i = 0; i <= COLS - 1; i++) |
| 165 | hblank[i] = ' '; |
| 166 | hblank[i] = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | void init_help_msg(void) |
| 170 | { |
| 171 | |
| 172 | #ifndef NANO_SMALL |
| 173 | |
| 174 | help_text_init = |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 175 | _(" nano help text\n\n " |
| 176 | "The nano editor is designed to emulate the functionality and " |
| 177 | "ease-of-use of the UW Pico text editor. There are four main " |
| 178 | "sections of the editor: The top line shows the program " |
| 179 | "version, the current filename being edited, and whether " |
| 180 | "or not the file has been modified. Next is the main editor " |
| 181 | "window showing the file being edited. The status line is " |
| 182 | "the third line from the bottom and shows important messages. " |
| 183 | "The bottom two lines show the most commonly used shortcuts " |
| 184 | "in the editor.\n\n " |
| 185 | "The notation for shortcuts is as follows: Control-key " |
Chris Allegretta | e49f123 | 2000-09-02 07:20:39 +0000 | [diff] [blame] | 186 | "sequences are notated with a caret (^) symbol and are entered " |
Chris Allegretta | d56bd79 | 2000-09-02 07:27:10 +0000 | [diff] [blame] | 187 | "with the Control (Ctrl) key. Escape-key sequences are notated " |
| 188 | "with the Meta (M) symbol and can be entered using either the " |
| 189 | "Esc, Alt or Meta key depending on your keyboard setup. The " |
| 190 | "following keystrokes are available in the main editor window. " |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 191 | "Optional keys are shown in parentheses:\n\n"); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 192 | #endif |
| 193 | |
| 194 | } |
| 195 | |
| 196 | /* Make a copy of a node to a pointer (space will be malloc()ed) */ |
| 197 | filestruct *copy_node(filestruct * src) |
| 198 | { |
| 199 | filestruct *dst; |
| 200 | |
| 201 | dst = nmalloc(sizeof(filestruct)); |
| 202 | dst->data = nmalloc(strlen(src->data) + 1); |
| 203 | |
| 204 | dst->next = src->next; |
| 205 | dst->prev = src->prev; |
| 206 | |
| 207 | strcpy(dst->data, src->data); |
| 208 | dst->lineno = src->lineno; |
| 209 | |
| 210 | return dst; |
| 211 | } |
| 212 | |
| 213 | /* Unlink a node from the rest of the struct */ |
| 214 | void unlink_node(filestruct * fileptr) |
| 215 | { |
| 216 | if (fileptr->prev != NULL) |
| 217 | fileptr->prev->next = fileptr->next; |
| 218 | |
| 219 | if (fileptr->next != NULL) |
| 220 | fileptr->next->prev = fileptr->prev; |
| 221 | } |
| 222 | |
| 223 | void delete_node(filestruct * fileptr) |
| 224 | { |
| 225 | if (fileptr->data != NULL) |
| 226 | free(fileptr->data); |
| 227 | free(fileptr); |
| 228 | } |
| 229 | |
| 230 | /* Okay, now let's duplicate a whole struct! */ |
| 231 | filestruct *copy_filestruct(filestruct * src) |
| 232 | { |
| 233 | filestruct *dst, *tmp, *head, *prev; |
| 234 | |
| 235 | head = copy_node(src); |
| 236 | dst = head; /* Else we barf on copying just one line */ |
| 237 | head->prev = NULL; |
| 238 | tmp = src->next; |
| 239 | prev = head; |
| 240 | |
| 241 | while (tmp != NULL) { |
| 242 | dst = copy_node(tmp); |
| 243 | dst->prev = prev; |
| 244 | prev->next = dst; |
| 245 | |
| 246 | prev = dst; |
| 247 | tmp = tmp->next; |
| 248 | } |
| 249 | |
| 250 | dst->next = NULL; |
| 251 | return head; |
| 252 | } |
| 253 | |
| 254 | /* Free() a single node */ |
| 255 | int free_node(filestruct * src) |
| 256 | { |
| 257 | if (src == NULL) |
| 258 | return 0; |
| 259 | |
| 260 | if (src->next != NULL) |
| 261 | free(src->data); |
| 262 | free(src); |
| 263 | return 1; |
| 264 | } |
| 265 | |
| 266 | int free_filestruct(filestruct * src) |
| 267 | { |
| 268 | filestruct *fileptr = src; |
| 269 | |
| 270 | if (src == NULL) |
| 271 | return 0; |
| 272 | |
| 273 | while (fileptr->next != NULL) { |
| 274 | fileptr = fileptr->next; |
| 275 | free_node(fileptr->prev); |
| 276 | |
| 277 | #ifdef DEBUG |
| 278 | fprintf(stderr, _("free_node(): free'd a node, YAY!\n")); |
| 279 | #endif |
| 280 | } |
| 281 | free_node(fileptr); |
| 282 | #ifdef DEBUG |
| 283 | fprintf(stderr, _("free_node(): free'd last node.\n")); |
| 284 | #endif |
| 285 | |
| 286 | return 1; |
| 287 | } |
| 288 | |
| 289 | int renumber_all(void) |
| 290 | { |
| 291 | filestruct *temp; |
| 292 | long i = 1; |
| 293 | |
| 294 | for (temp = fileage; temp != NULL; temp = temp->next) { |
| 295 | temp->lineno = i++; |
| 296 | } |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | int renumber(filestruct * fileptr) |
| 302 | { |
| 303 | filestruct *temp; |
| 304 | |
| 305 | if (fileptr == NULL || fileptr->prev == NULL || fileptr == fileage) { |
| 306 | renumber_all(); |
| 307 | return 0; |
| 308 | } |
| 309 | for (temp = fileptr; temp != NULL; temp = temp->next) { |
| 310 | temp->lineno = temp->prev->lineno + 1; |
| 311 | } |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | /* Fix the memory allocation for a string */ |
| 317 | void align(char **strp) |
| 318 | { |
| 319 | /* There was a serious bug here: the new address was never |
| 320 | stored anywhere... */ |
| 321 | |
| 322 | *strp = nrealloc(*strp, strlen(*strp) + 1); |
| 323 | } |
| 324 | |
Chris Allegretta | 6925bbd | 2000-07-28 01:41:29 +0000 | [diff] [blame] | 325 | /* Null a string at a certain index and align it */ |
| 326 | void null_at(char *data, int index) |
| 327 | { |
| 328 | data[index] = 0; |
| 329 | align(&data); |
| 330 | } |
| 331 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 332 | void usage(void) |
| 333 | { |
| 334 | #ifdef HAVE_GETOPT_LONG |
| 335 | printf(_("Usage: nano [GNU long option] [option] +LINE <file>\n\n")); |
| 336 | printf(_("Option Long option Meaning\n")); |
Chris Allegretta | 6724a7e | 2000-06-19 23:19:07 +0000 | [diff] [blame] | 337 | printf(_ |
| 338 | (" -T --tabsize=[num] Set width of a tab to num\n")); |
Chris Allegretta | 805c26d | 2000-09-06 13:39:17 +0000 | [diff] [blame] | 339 | #ifdef HAVE_REGEX_H |
Chris Allegretta | 9fc8d43 | 2000-07-07 01:49:52 +0000 | [diff] [blame] | 340 | printf(_ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 341 | (" -R --regexp Use regular expressions for search\n")); |
Chris Allegretta | 4780561 | 2000-07-07 02:35:34 +0000 | [diff] [blame] | 342 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 343 | printf |
| 344 | (_ |
| 345 | (" -V --version Print version information and exit\n")); |
| 346 | printf(_ |
| 347 | (" -c --const Constantly show cursor position\n")); |
| 348 | printf(_ |
| 349 | (" -h --help Show this message\n")); |
Chris Allegretta | d19e991 | 2000-07-12 18:14:51 +0000 | [diff] [blame] | 350 | #ifndef NANO_SMALL |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 351 | printf(_ |
Chris Allegretta | 627de19 | 2000-07-12 02:09:17 +0000 | [diff] [blame] | 352 | (" -k --cut Let ^K cut from cursor to end of line\n")); |
Chris Allegretta | d19e991 | 2000-07-12 18:14:51 +0000 | [diff] [blame] | 353 | #endif |
Chris Allegretta | 627de19 | 2000-07-12 02:09:17 +0000 | [diff] [blame] | 354 | printf(_ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 355 | (" -i --autoindent Automatically indent new lines\n")); |
| 356 | printf(_ |
Chris Allegretta | 71348ee | 2000-10-02 04:21:23 +0000 | [diff] [blame] | 357 | (" -l --nofollow Don't follow symbolic links, overwrite\n")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 358 | #ifndef NANO_SMALL |
| 359 | #ifdef NCURSES_MOUSE_VERSION |
| 360 | printf(_(" -m --mouse Enable mouse\n")); |
| 361 | #endif |
| 362 | #endif |
| 363 | printf |
| 364 | (_ |
| 365 | (" -r [#cols] --fill=[#cols] Set fill cols to (wrap lines at) #cols\n")); |
| 366 | printf(_ |
Chris Allegretta | bf9a8cc | 2000-11-17 01:37:39 +0000 | [diff] [blame] | 367 | (" -p --pico Emulate Pico as closely as possible\n")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 368 | printf(_ |
| 369 | (" -s [prog] --speller=[prog] Enable alternate speller\n")); |
| 370 | printf(_ |
| 371 | (" -t --tempfile Auto save on exit, don't prompt\n")); |
| 372 | printf(_ |
| 373 | (" -v --view View (read only) mode\n")); |
| 374 | printf(_ |
| 375 | (" -w --nowrap Don't wrap long lines\n")); |
| 376 | printf(_ |
| 377 | (" -x --nohelp Don't show help window\n")); |
| 378 | printf(_ |
| 379 | (" -z --suspend Enable suspend\n")); |
| 380 | printf(_ |
| 381 | (" +LINE Start at line number LINE\n")); |
| 382 | #else |
| 383 | printf(_("Usage: nano [option] +LINE <file>\n\n")); |
| 384 | printf(_("Option Meaning\n")); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 385 | printf(_(" -T [num] Set width of a tab to num\n")); |
Chris Allegretta | 9fc8d43 | 2000-07-07 01:49:52 +0000 | [diff] [blame] | 386 | printf(_(" -R Use regular expressions for search\n")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 387 | printf(_(" -V Print version information and exit\n")); |
| 388 | printf(_(" -c Constantly show cursor position\n")); |
| 389 | printf(_(" -h Show this message\n")); |
Chris Allegretta | d19e991 | 2000-07-12 18:14:51 +0000 | [diff] [blame] | 390 | #ifndef NANO_SMALL |
Chris Allegretta | 627de19 | 2000-07-12 02:09:17 +0000 | [diff] [blame] | 391 | printf(_(" -k Let ^K cut from cursor to end of line\n")); |
Chris Allegretta | d19e991 | 2000-07-12 18:14:51 +0000 | [diff] [blame] | 392 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 393 | printf(_(" -i Automatically indent new lines\n")); |
| 394 | printf(_ |
Chris Allegretta | 71348ee | 2000-10-02 04:21:23 +0000 | [diff] [blame] | 395 | (" -l Don't follow symbolic links, overwrite\n")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 396 | #ifndef NANO_SMALL |
| 397 | #ifdef NCURSES_MOUSE_VERSION |
| 398 | printf(_(" -m Enable mouse\n")); |
| 399 | #endif |
| 400 | #endif |
| 401 | printf(_ |
| 402 | (" -r [#cols] Set fill cols to (wrap lines at) #cols\n")); |
| 403 | printf(_(" -s [prog] Enable alternate speller\n")); |
Chris Allegretta | bf9a8cc | 2000-11-17 01:37:39 +0000 | [diff] [blame] | 404 | printf(_(" -p Emulate Pico as closely as possible\n")); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 405 | printf(_(" -t Auto save on exit, don't prompt\n")); |
| 406 | printf(_(" -v View (read only) mode\n")); |
| 407 | printf(_(" -w Don't wrap long lines\n")); |
| 408 | printf(_(" -x Don't show help window\n")); |
| 409 | printf(_(" -z Enable suspend\n")); |
| 410 | printf(_(" +LINE Start at line number LINE\n")); |
| 411 | #endif |
| 412 | exit(0); |
| 413 | } |
| 414 | |
| 415 | void version(void) |
| 416 | { |
| 417 | printf(_(" nano version %s by Chris Allegretta (compiled %s, %s)\n"), |
| 418 | VERSION, __TIME__, __DATE__); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 419 | printf(_ |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 420 | (" Email: nano@nano-editor.org Web: http://www.nano-editor.org")); |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 421 | printf(_("\n Compiled options:")); |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 422 | |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 423 | #ifdef NANO_SMALL |
| 424 | printf(" --enable-tiny"); |
| 425 | #endif |
| 426 | #ifdef NANO_EXTRA |
| 427 | printf(" --enable-extra"); |
| 428 | #endif |
| 429 | #ifdef DISABLE_TABCOMP |
| 430 | printf(" --disable-tabcomp"); |
| 431 | #endif |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 432 | #ifdef DISABLE_JUSTIFY |
| 433 | printf(" --disable-justify"); |
| 434 | #endif |
| 435 | #ifdef DISABLE_SPELL |
| 436 | printf(" --disable-spell"); |
| 437 | #endif |
Chris Allegretta | 8a0de3b | 2000-11-24 20:45:14 +0000 | [diff] [blame] | 438 | #ifdef USE_SLANG |
| 439 | printf(" --with-slang"); |
| 440 | #endif |
| 441 | printf("\n"); |
| 442 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 443 | } |
| 444 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 445 | filestruct *make_new_node(filestruct * prevnode) |
| 446 | { |
| 447 | filestruct *newnode; |
| 448 | |
| 449 | newnode = nmalloc(sizeof(filestruct)); |
| 450 | newnode->data = NULL; |
| 451 | |
| 452 | newnode->prev = prevnode; |
| 453 | newnode->next = NULL; |
| 454 | |
| 455 | if (prevnode != NULL) |
| 456 | newnode->lineno = prevnode->lineno + 1; |
| 457 | |
| 458 | return newnode; |
| 459 | } |
| 460 | |
Chris Allegretta | 7975ed8 | 2000-07-28 00:58:35 +0000 | [diff] [blame] | 461 | /* Splice a node into an existing filestruct */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 462 | void splice_node(filestruct * begin, filestruct * new, filestruct * end) |
Chris Allegretta | 7975ed8 | 2000-07-28 00:58:35 +0000 | [diff] [blame] | 463 | { |
| 464 | new->next = end; |
| 465 | new->prev = begin; |
| 466 | begin->next = new; |
| 467 | if (end != NULL) |
| 468 | end->prev = new; |
| 469 | } |
| 470 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 471 | int do_mark() |
| 472 | { |
| 473 | #ifdef NANO_SMALL |
| 474 | nano_small_msg(); |
| 475 | #else |
| 476 | if (!ISSET(MARK_ISSET)) { |
| 477 | statusbar(_("Mark Set")); |
| 478 | SET(MARK_ISSET); |
| 479 | mark_beginbuf = current; |
| 480 | mark_beginx = current_x; |
| 481 | } else { |
| 482 | statusbar(_("Mark UNset")); |
| 483 | UNSET(MARK_ISSET); |
| 484 | mark_beginbuf = NULL; |
| 485 | mark_beginx = 0; |
| 486 | |
| 487 | edit_refresh(); |
| 488 | } |
| 489 | #endif |
| 490 | return 1; |
| 491 | } |
| 492 | |
| 493 | int no_help(void) |
| 494 | { |
| 495 | if ISSET |
| 496 | (NO_HELP) |
| 497 | return 2; |
| 498 | else |
| 499 | return 0; |
| 500 | } |
| 501 | |
Chris Allegretta | 4eb7aa0 | 2000-12-01 18:57:11 +0000 | [diff] [blame] | 502 | #ifdef NANO_SMALL |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 503 | void nano_small_msg(void) |
| 504 | { |
| 505 | statusbar("Sorry, this function not available with nano-tiny option"); |
| 506 | } |
Chris Allegretta | 4eb7aa0 | 2000-12-01 18:57:11 +0000 | [diff] [blame] | 507 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 508 | |
Chris Allegretta | 4eb7aa0 | 2000-12-01 18:57:11 +0000 | [diff] [blame] | 509 | #if defined(DISABLE_JUSTIFY) || defined(DISABLE_SPELL) |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 510 | void nano_disabled_msg(void) |
| 511 | { |
| 512 | statusbar("Sorry, support for this function has been disabled"); |
| 513 | } |
Chris Allegretta | 4eb7aa0 | 2000-12-01 18:57:11 +0000 | [diff] [blame] | 514 | #endif |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 515 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 516 | /* The user typed a printable character; add it to the edit buffer */ |
| 517 | void do_char(char ch) |
| 518 | { |
Robert Siemborski | 63b3d7e | 2000-07-04 22:15:39 +0000 | [diff] [blame] | 519 | /* magic-line: when a character is inserted on the current magic line, |
| 520 | * it means we need a new one! */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 521 | if (filebot == current && current->data[0] == '\0') { |
Robert Siemborski | 63b3d7e | 2000-07-04 22:15:39 +0000 | [diff] [blame] | 522 | new_magicline(); |
Chris Allegretta | 28a0f89 | 2000-07-05 22:47:54 +0000 | [diff] [blame] | 523 | fix_editbot(); |
Robert Siemborski | 63b3d7e | 2000-07-04 22:15:39 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 526 | /* More dangerousness fun =) */ |
| 527 | current->data = nrealloc(current->data, strlen(current->data) + 2); |
| 528 | memmove(¤t->data[current_x + 1], |
| 529 | ¤t->data[current_x], |
| 530 | strlen(current->data) - current_x + 1); |
| 531 | current->data[current_x] = ch; |
| 532 | do_right(); |
| 533 | |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 534 | if (!ISSET(NO_WRAP) && (ch != '\t')) |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 535 | check_wrap(current, ch); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 536 | set_modified(); |
| 537 | check_statblank(); |
| 538 | UNSET(KEEP_CUTBUFFER); |
| 539 | totsize++; |
| 540 | |
| 541 | } |
| 542 | |
| 543 | /* Someone hits return *gasp!* */ |
| 544 | int do_enter(filestruct * inptr) |
| 545 | { |
| 546 | filestruct *new; |
| 547 | char *tmp, *spc; |
| 548 | int extra = 0; |
| 549 | |
| 550 | new = make_new_node(inptr); |
| 551 | tmp = ¤t->data[current_x]; |
| 552 | current_x = 0; |
| 553 | |
| 554 | /* Do auto-indenting, like the neolithic Turbo Pascal editor */ |
| 555 | if (ISSET(AUTOINDENT)) { |
| 556 | spc = current->data; |
| 557 | if (spc) { |
| 558 | while ((*spc == ' ') || (*spc == '\t')) { |
| 559 | extra++; |
| 560 | spc++; |
| 561 | current_x++; |
| 562 | } |
| 563 | new->data = nmalloc(strlen(tmp) + extra + 1); |
| 564 | strncpy(new->data, current->data, extra); |
| 565 | strcpy(&new->data[extra], tmp); |
| 566 | } |
| 567 | } else { |
| 568 | new->data = nmalloc(strlen(tmp) + 1); |
| 569 | strcpy(new->data, tmp); |
| 570 | } |
| 571 | *tmp = 0; |
| 572 | |
Chris Allegretta | da721be | 2000-07-31 01:26:42 +0000 | [diff] [blame] | 573 | if (inptr->next == NULL) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 574 | filebot = new; |
| 575 | editbot = new; |
| 576 | } |
Chris Allegretta | 7975ed8 | 2000-07-28 00:58:35 +0000 | [diff] [blame] | 577 | splice_node(inptr, new, inptr->next); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 578 | |
| 579 | totsize++; |
| 580 | renumber(current); |
| 581 | current = new; |
| 582 | align(¤t->data); |
| 583 | |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 584 | /* The logic here is as follows: |
| 585 | * -> If we are at the bottom of the buffer, we want to recenter |
| 586 | * (read: rebuild) the screen and forcably move the cursor. |
| 587 | * -> otherwise, we want simply to redraw the screen and update |
| 588 | * where we think the cursor is. |
| 589 | */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 590 | if (current_y == editwinrows - 1) { |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 591 | edit_update(current, CENTER); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 592 | reset_cursor(); |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 593 | } else { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 594 | current_y++; |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 595 | edit_refresh(); |
| 596 | update_cursor(); |
| 597 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 598 | |
| 599 | totlines++; |
| 600 | set_modified(); |
| 601 | |
Chris Allegretta | b0ae393 | 2000-06-15 23:39:14 +0000 | [diff] [blame] | 602 | placewewant = xplustabs(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 603 | return 1; |
| 604 | } |
| 605 | |
| 606 | int do_enter_void(void) |
| 607 | { |
| 608 | return do_enter(current); |
| 609 | } |
| 610 | |
| 611 | void do_next_word(void) |
| 612 | { |
Chris Allegretta | 9e2934f | 2000-12-01 23:49:48 +0000 | [diff] [blame^] | 613 | filestruct *fileptr, *old; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 614 | int i; |
| 615 | |
| 616 | if (current == NULL) |
| 617 | return; |
| 618 | |
Chris Allegretta | 9e2934f | 2000-12-01 23:49:48 +0000 | [diff] [blame^] | 619 | old = current; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 620 | i = current_x; |
| 621 | for (fileptr = current; fileptr != NULL; fileptr = fileptr->next) { |
| 622 | if (fileptr == current) { |
| 623 | while (isalnum((int) fileptr->data[i]) |
| 624 | && fileptr->data[i] != 0) |
| 625 | i++; |
| 626 | |
| 627 | if (fileptr->data[i] == 0) { |
| 628 | i = 0; |
| 629 | continue; |
| 630 | } |
| 631 | } |
| 632 | while (!isalnum((int) fileptr->data[i]) && fileptr->data[i] != 0) |
| 633 | i++; |
| 634 | |
| 635 | if (fileptr->data[i] != 0) |
| 636 | break; |
| 637 | |
| 638 | i = 0; |
| 639 | } |
| 640 | if (fileptr == NULL) |
| 641 | current = filebot; |
| 642 | else |
| 643 | current = fileptr; |
| 644 | |
| 645 | current_x = i; |
| 646 | placewewant = xplustabs(); |
Chris Allegretta | 9e2934f | 2000-12-01 23:49:48 +0000 | [diff] [blame^] | 647 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 648 | if (current->lineno >= editbot->lineno) |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 649 | edit_update(current, CENTER); |
Chris Allegretta | 9e2934f | 2000-12-01 23:49:48 +0000 | [diff] [blame^] | 650 | else { |
| 651 | /* If we've jumped lines, refresh the old line. We can't just use |
| 652 | * current->prev here, because we may have skipped over some blank |
| 653 | * lines, in which case the previous line is the wrong one. |
| 654 | */ |
| 655 | if (current != old) |
| 656 | update_line(old, 0); |
| 657 | |
| 658 | update_line(current, current_x); |
| 659 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 660 | |
| 661 | } |
| 662 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 663 | void do_wrap(filestruct * inptr, char input_char) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 664 | { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 665 | int i = 0; /* Index into ->data for line. */ |
| 666 | int i_tabs = 0; /* Screen position of ->data[i]. */ |
| 667 | int last_word_end = -1; /* Location of end of last word found. */ |
| 668 | int current_word_start = -1; /* Location of start of current word. */ |
| 669 | int current_word_start_t = -1; /* Location of start of current word screen position. */ |
| 670 | int current_word_end = -1; /* Location of end of current word */ |
| 671 | int current_word_end_t = -1; /* Location of end of current word screen position. */ |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 672 | int len = strlen(inptr->data); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 673 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 674 | int down = 0; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 675 | int right = 0; |
| 676 | struct filestruct *temp = NULL; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 677 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 678 | assert(strlenpt(inptr->data) > fill); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 679 | |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 680 | for (i = 0, i_tabs = 0; i < len; i++, i_tabs++) { |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 681 | if (!isspace((int) inptr->data[i])) { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 682 | last_word_end = current_word_end; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 683 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 684 | current_word_start = i; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 685 | current_word_start_t = i_tabs; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 686 | |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 687 | while (!isspace((int) inptr->data[i]) |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 688 | && inptr->data[i]) { |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 689 | i++; |
| 690 | i_tabs++; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 691 | if (inptr->data[i] < 32) |
| 692 | i_tabs++; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 693 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 694 | |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 695 | if (inptr->data[i]) { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 696 | current_word_end = i; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 697 | current_word_end_t = i_tabs; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 698 | } else { |
| 699 | current_word_end = i - 1; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 700 | current_word_end_t = i_tabs - 1; |
| 701 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 702 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 703 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 704 | if (inptr->data[i] == NANO_CONTROL_I) { |
Chris Allegretta | 6d690a3 | 2000-08-03 22:51:21 +0000 | [diff] [blame] | 705 | if (i_tabs % tabsize != 0); |
| 706 | i_tabs += tabsize - (i_tabs % tabsize); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 707 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 708 | |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 709 | if (current_word_end_t > fill) |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 710 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 711 | } |
| 712 | |
Adam Rogoyski | 3d449b4 | 2000-06-19 17:30:14 +0000 | [diff] [blame] | 713 | /* There are a few (ever changing) cases of what the line could look like. |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 714 | * 1) only one word on the line before wrap point. |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 715 | * a) one word takes up the whole line with no starting spaces. |
| 716 | * - do nothing and return. |
| 717 | * b) cursor is on word or before word at wrap point and there are spaces at beginning. |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 718 | * - word starts new line. |
| 719 | * - keep white space on original line up to the cursor. |
| 720 | * *) cursor is after word at wrap point |
| 721 | * - either it's all white space after word, and this routine isn't called. |
| 722 | * - or we are actually in case 2 (2 words). |
| 723 | * 2) Two or more words on the line before wrap point. |
Adam Rogoyski | 3d449b4 | 2000-06-19 17:30:14 +0000 | [diff] [blame] | 724 | * a) cursor is at a word or space before wrap point |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 725 | * - word at wrap point starts a new line. |
Adam Rogoyski | 3d449b4 | 2000-06-19 17:30:14 +0000 | [diff] [blame] | 726 | * - white space at end of original line is cleared, unless |
| 727 | * it is all spaces between previous word and next word which appears after fill. |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 728 | * b) cursor is at the word at the wrap point. |
| 729 | * - word at wrap point starts a new line. |
Adam Rogoyski | 3d449b4 | 2000-06-19 17:30:14 +0000 | [diff] [blame] | 730 | * 1. pressed a space and at first character of wrap point word. |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 731 | * - white space on original line is kept to where cursor was. |
Adam Rogoyski | 3d449b4 | 2000-06-19 17:30:14 +0000 | [diff] [blame] | 732 | * 2. pressed non space (or space elsewhere). |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 733 | * - white space at end of original line is cleared. |
| 734 | * c) cursor is past the word at the wrap point. |
| 735 | * - word at wrap point starts a new line. |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 736 | * - white space at end of original line is cleared |
| 737 | */ |
| 738 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 739 | temp = nmalloc(sizeof(filestruct)); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 740 | |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 741 | /* Category 1a: one word taking up the whole line with no beginning spaces. */ |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 742 | if ((last_word_end == -1) && (!isspace((int) inptr->data[0]))) { |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 743 | for (i = current_word_end; i < len; i++) { |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 744 | if (!isspace((int) inptr->data[i]) && i < len) { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 745 | current_word_start = i; |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 746 | while (!isspace((int) inptr->data[i]) && (i < len)) { |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 747 | i++; |
| 748 | } |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 749 | last_word_end = current_word_end; |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 750 | current_word_end = i; |
| 751 | break; |
| 752 | } |
| 753 | } |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 754 | |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 755 | if (last_word_end == -1) { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 756 | free(temp); |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 757 | return; |
| 758 | } |
| 759 | if (current_x >= last_word_end) { |
| 760 | right = (current_x - current_word_start) + 1; |
| 761 | current_x = last_word_end; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 762 | down = 1; |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | temp->data = nmalloc(strlen(&inptr->data[current_word_start]) + 1); |
| 766 | strcpy(temp->data, &inptr->data[current_word_start]); |
| 767 | inptr->data = nrealloc(inptr->data, last_word_end + 2); |
| 768 | inptr->data[last_word_end + 1] = 0; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 769 | } else |
| 770 | /* Category 1b: one word on the line and word not taking up whole line |
| 771 | (i.e. there are spaces at the beginning of the line) */ |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 772 | if (last_word_end == -1) { |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 773 | temp->data = nmalloc(strlen(&inptr->data[current_word_start]) + 1); |
| 774 | strcpy(temp->data, &inptr->data[current_word_start]); |
| 775 | |
| 776 | /* Inside word, remove it from original, and move cursor to right spot. */ |
| 777 | if (current_x >= current_word_start) { |
| 778 | right = current_x - current_word_start; |
| 779 | current_x = 0; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 780 | down = 1; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Chris Allegretta | 6925bbd | 2000-07-28 01:41:29 +0000 | [diff] [blame] | 783 | null_at(inptr->data, current_x); |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 784 | |
| 785 | if (ISSET(MARK_ISSET) && (mark_beginbuf == inptr)) { |
| 786 | mark_beginbuf = temp; |
| 787 | mark_beginx = 0; |
| 788 | } |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | /* Category 2: two or more words on the line. */ |
| 792 | else { |
| 793 | |
| 794 | /* Case 2a: cursor before word at wrap point. */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 795 | if (current_x < current_word_start) { |
| 796 | temp->data = |
| 797 | nmalloc(strlen(&inptr->data[current_word_start]) + 1); |
| 798 | strcpy(temp->data, &inptr->data[current_word_start]); |
| 799 | |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 800 | if (!isspace((int) input_char)) { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 801 | i = current_word_start - 1; |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 802 | while (isspace((int) inptr->data[i])) { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 803 | i--; |
| 804 | assert(i >= 0); |
| 805 | } |
| 806 | } else if (current_x <= last_word_end) |
| 807 | i = last_word_end - 1; |
| 808 | else |
| 809 | i = current_x; |
| 810 | |
| 811 | inptr->data = nrealloc(inptr->data, i + 2); |
| 812 | inptr->data[i + 1] = 0; |
| 813 | } |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 814 | |
| 815 | |
| 816 | /* Case 2b: cursor at word at wrap point. */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 817 | else if ((current_x >= current_word_start) |
| 818 | && (current_x <= (current_word_end + 1))) { |
| 819 | temp->data = |
| 820 | nmalloc(strlen(&inptr->data[current_word_start]) + 1); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 821 | strcpy(temp->data, &inptr->data[current_word_start]); |
| 822 | |
| 823 | down = 1; |
| 824 | |
| 825 | right = current_x - current_word_start; |
| 826 | i = current_word_start - 1; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 827 | if (isspace((int) input_char) |
| 828 | && (current_x == current_word_start)) { |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 829 | current_x = current_word_start; |
| 830 | |
Chris Allegretta | 6925bbd | 2000-07-28 01:41:29 +0000 | [diff] [blame] | 831 | null_at(inptr->data, current_word_start); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 832 | } else { |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 833 | |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 834 | while (isspace((int) inptr->data[i])) { |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 835 | i--; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 836 | assert(i >= 0); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 837 | } |
| 838 | inptr->data = nrealloc(inptr->data, i + 2); |
| 839 | inptr->data[i + 1] = 0; |
| 840 | } |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 841 | } |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 842 | |
| 843 | |
| 844 | /* Case 2c: cursor past word at wrap point. */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 845 | else { |
| 846 | temp->data = |
| 847 | nmalloc(strlen(&inptr->data[current_word_start]) + 1); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 848 | strcpy(temp->data, &inptr->data[current_word_start]); |
| 849 | |
| 850 | down = 1; |
| 851 | right = current_x - current_word_start; |
| 852 | |
| 853 | current_x = current_word_start; |
| 854 | i = current_word_start - 1; |
| 855 | |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 856 | while (isspace((int) inptr->data[i])) { |
Adam Rogoyski | 3d449b4 | 2000-06-19 17:30:14 +0000 | [diff] [blame] | 857 | i--; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 858 | assert(i >= 0); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 859 | inptr->data = nrealloc(inptr->data, i + 2); |
| 860 | inptr->data[i + 1] = 0; |
| 861 | } |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 862 | } |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 865 | /* We pre-pend wrapped part to next line. */ |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 866 | if (ISSET(SAMELINEWRAP) && inptr->next) { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 867 | /* Plus one for the space which concatenates the two lines together plus 1 for \0. */ |
| 868 | char *p = |
| 869 | nmalloc(strlen(temp->data) + strlen(inptr->next->data) + 2); |
Adam Rogoyski | 9aeb9da | 2000-06-16 01:19:31 +0000 | [diff] [blame] | 870 | int old_x = current_x, old_y = current_y; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 871 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 872 | strcpy(p, temp->data); |
| 873 | strcat(p, " "); |
| 874 | strcat(p, inptr->next->data); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 875 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 876 | free(inptr->next->data); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 877 | inptr->next->data = p; |
| 878 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 879 | free(temp->data); |
| 880 | free(temp); |
Adam Rogoyski | 9aeb9da | 2000-06-16 01:19:31 +0000 | [diff] [blame] | 881 | |
Adam Rogoyski | 9aeb9da | 2000-06-16 01:19:31 +0000 | [diff] [blame] | 882 | current_x = old_x; |
| 883 | current_y = old_y; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 884 | } |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 885 | /* Else we start a new line. */ |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 886 | else { |
| 887 | temp->prev = inptr; |
| 888 | temp->next = inptr->next; |
| 889 | |
| 890 | if (inptr->next) |
| 891 | inptr->next->prev = temp; |
| 892 | inptr->next = temp; |
| 893 | |
| 894 | if (!temp->next) |
| 895 | filebot = temp; |
| 896 | |
| 897 | SET(SAMELINEWRAP); |
| 898 | } |
| 899 | |
| 900 | |
| 901 | totlines++; |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 902 | /* Everything about it makes me want this line here but it causes |
| 903 | * totsize to be high by one for some reason. Sigh. (Rob) */ |
| 904 | /* totsize++; */ |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 905 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 906 | renumber(inptr); |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 907 | edit_update(edittop, TOP); |
Adam Rogoyski | 0223d6f | 2000-06-17 20:36:35 +0000 | [diff] [blame] | 908 | |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 909 | |
| 910 | /* Move the cursor to the new line if appropriate. */ |
| 911 | if (down) { |
| 912 | do_right(); |
| 913 | } |
| 914 | |
| 915 | /* Move the cursor to the correct spot in the line if appropriate. */ |
| 916 | while (right--) { |
| 917 | do_right(); |
| 918 | } |
| 919 | |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 920 | edit_update(edittop, TOP); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 921 | reset_cursor(); |
| 922 | edit_refresh(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | /* Check to see if we've just caused the line to wrap to a new line */ |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 926 | void check_wrap(filestruct * inptr, char ch) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 927 | { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 928 | int len = strlenpt(inptr->data); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 929 | #ifdef DEBUG |
| 930 | fprintf(stderr, _("check_wrap called with inptr->data=\"%s\"\n"), |
| 931 | inptr->data); |
| 932 | #endif |
| 933 | |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 934 | if (len <= fill) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 935 | return; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 936 | else { |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 937 | int i = actual_x(inptr, fill); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 938 | |
| 939 | /* Do not wrap if there are no words on or after wrap point. */ |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 940 | int char_found = 0; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 941 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 942 | while (isspace((int) inptr->data[i]) && inptr->data[i]) |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 943 | i++; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 944 | |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 945 | if (!inptr->data[i]) |
| 946 | return; |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 947 | |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 948 | /* String must be at least 1 character long. */ |
| 949 | for (i = strlen(inptr->data) - 1; i >= 0; i--) { |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 950 | if (isspace((int) inptr->data[i])) { |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 951 | if (!char_found) |
| 952 | continue; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 953 | char_found = 2; /* 2 for yes do wrap. */ |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 954 | break; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 955 | } else |
| 956 | char_found = 1; /* 1 for yes found a word, but must check further. */ |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 957 | } |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 958 | |
| 959 | if (char_found == 2) |
| 960 | do_wrap(inptr, ch); |
Adam Rogoyski | 77f36de | 2000-06-07 03:56:54 +0000 | [diff] [blame] | 961 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /* Stuff we do when we abort from programs and want to clean up the |
| 965 | * screen. This doesnt do much right now. |
| 966 | */ |
| 967 | void do_early_abort(void) |
| 968 | { |
| 969 | blank_statusbar_refresh(); |
| 970 | } |
| 971 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 972 | int do_backspace(void) |
| 973 | { |
| 974 | filestruct *previous, *tmp; |
| 975 | |
| 976 | if (current_x != 0) { |
| 977 | /* Let's get dangerous */ |
| 978 | memmove(¤t->data[current_x - 1], ¤t->data[current_x], |
| 979 | strlen(current->data) - current_x + 1); |
| 980 | #ifdef DEBUG |
| 981 | fprintf(stderr, _("current->data now = \"%s\"\n"), current->data); |
| 982 | #endif |
| 983 | align(¤t->data); |
| 984 | do_left(); |
| 985 | } else { |
| 986 | if (current == fileage) |
| 987 | return 0; /* Can't delete past top of file */ |
| 988 | |
| 989 | previous = current->prev; |
| 990 | current_x = strlen(previous->data); |
| 991 | previous->data = nrealloc(previous->data, |
| 992 | strlen(previous->data) + |
| 993 | strlen(current->data) + 1); |
| 994 | strcat(previous->data, current->data); |
| 995 | |
| 996 | tmp = current; |
| 997 | unlink_node(current); |
| 998 | delete_node(current); |
| 999 | if (current == edittop) { |
| 1000 | if (previous->next) |
| 1001 | current = previous->next; |
| 1002 | else |
| 1003 | current = previous; |
Chris Allegretta | da721be | 2000-07-31 01:26:42 +0000 | [diff] [blame] | 1004 | page_up_center(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1005 | } else { |
| 1006 | if (previous->next) |
| 1007 | current = previous->next; |
| 1008 | else |
| 1009 | current = previous; |
| 1010 | update_line(current, current_x); |
| 1011 | } |
| 1012 | |
| 1013 | /* Ooops, sanity check */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1014 | if (tmp == filebot) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1015 | filebot = current; |
| 1016 | editbot = current; |
Chris Allegretta | 28a0f89 | 2000-07-05 22:47:54 +0000 | [diff] [blame] | 1017 | |
| 1018 | /* Recreate the magic line if we're deleting it AND if the |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1019 | line we're on now is NOT blank. if it is blank we |
| 1020 | can just use IT for the magic line. This is how Pico |
| 1021 | appears to do it, in any case */ |
Chris Allegretta | 28a0f89 | 2000-07-05 22:47:54 +0000 | [diff] [blame] | 1022 | if (strcmp(current->data, "")) { |
| 1023 | new_magicline(); |
| 1024 | fix_editbot(); |
Chris Allegretta | 5537387 | 2000-07-06 22:38:37 +0000 | [diff] [blame] | 1025 | totsize++; |
Chris Allegretta | 28a0f89 | 2000-07-05 22:47:54 +0000 | [diff] [blame] | 1026 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | current = previous; |
| 1030 | renumber(current); |
| 1031 | previous_line(); |
| 1032 | totlines--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1033 | #ifdef DEBUG |
| 1034 | fprintf(stderr, _("After, data = \"%s\"\n"), current->data); |
| 1035 | #endif |
| 1036 | |
| 1037 | } |
| 1038 | |
| 1039 | totsize--; |
| 1040 | set_modified(); |
| 1041 | UNSET(KEEP_CUTBUFFER); |
| 1042 | edit_refresh(); |
| 1043 | return 1; |
| 1044 | } |
| 1045 | |
| 1046 | int do_delete(void) |
| 1047 | { |
| 1048 | filestruct *foo; |
| 1049 | |
| 1050 | if (current_x != strlen(current->data)) { |
| 1051 | /* Let's get dangerous */ |
| 1052 | memmove(¤t->data[current_x], ¤t->data[current_x + 1], |
| 1053 | strlen(current->data) - current_x); |
| 1054 | |
| 1055 | align(¤t->data); |
| 1056 | |
| 1057 | } else if (current->next != NULL) { |
| 1058 | current->data = nrealloc(current->data, |
| 1059 | strlen(current->data) + |
| 1060 | strlen(current->next->data) + 1); |
| 1061 | strcat(current->data, current->next->data); |
| 1062 | |
| 1063 | foo = current->next; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1064 | if (filebot == foo) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1065 | filebot = current; |
| 1066 | editbot = current; |
| 1067 | } |
| 1068 | |
| 1069 | unlink_node(foo); |
| 1070 | delete_node(foo); |
| 1071 | update_line(current, current_x); |
| 1072 | |
Chris Allegretta | 28a0f89 | 2000-07-05 22:47:54 +0000 | [diff] [blame] | 1073 | /* Please see the comment in do_basckspace if you don't understand |
| 1074 | this test */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1075 | if (current == filebot && strcmp(current->data, "")) { |
Chris Allegretta | 28a0f89 | 2000-07-05 22:47:54 +0000 | [diff] [blame] | 1076 | new_magicline(); |
| 1077 | fix_editbot(); |
Chris Allegretta | 5537387 | 2000-07-06 22:38:37 +0000 | [diff] [blame] | 1078 | totsize++; |
Chris Allegretta | 28a0f89 | 2000-07-05 22:47:54 +0000 | [diff] [blame] | 1079 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1080 | renumber(current); |
| 1081 | totlines--; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1082 | } else |
| 1083 | return 0; |
| 1084 | |
| 1085 | totsize--; |
| 1086 | set_modified(); |
| 1087 | UNSET(KEEP_CUTBUFFER); |
| 1088 | edit_refresh(); |
| 1089 | return 1; |
| 1090 | } |
| 1091 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1092 | void wrap_reset(void) |
| 1093 | { |
| 1094 | UNSET(SAMELINEWRAP); |
| 1095 | } |
| 1096 | |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 1097 | #if !defined(NANO_SMALL) && !defined(DISABLE_SPELL) |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1098 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1099 | int do_int_spell_fix(char *word) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1100 | { |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1101 | char *prevanswer = NULL, *save_search = NULL, *save_replace = NULL; |
Chris Allegretta | d00e6df | 2000-11-29 04:33:26 +0000 | [diff] [blame] | 1102 | filestruct *begin; |
| 1103 | int i = 0, j = 0, beginx, beginx_top; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1104 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1105 | /* save where we are */ |
| 1106 | begin = current; |
| 1107 | beginx = current_x + 1; |
| 1108 | |
| 1109 | /* save the current search/replace strings */ |
| 1110 | search_init_globals(); |
| 1111 | save_search = mallocstrcpy(save_search, last_search); |
| 1112 | save_replace = mallocstrcpy(save_replace, last_replace); |
| 1113 | |
| 1114 | /* set search/replace strings to mis-spelt word */ |
| 1115 | prevanswer = mallocstrcpy(prevanswer, word); |
| 1116 | last_search = mallocstrcpy(last_search, word); |
| 1117 | last_replace = mallocstrcpy(last_replace, word); |
| 1118 | |
| 1119 | /* start from the top of file */ |
Chris Allegretta | d00e6df | 2000-11-29 04:33:26 +0000 | [diff] [blame] | 1120 | current = fileage; |
| 1121 | current_x = beginx_top = -1; |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1122 | |
| 1123 | search_last_line = FALSE; |
| 1124 | |
Chris Allegretta | d00e6df | 2000-11-29 04:33:26 +0000 | [diff] [blame] | 1125 | edit_update(fileage, TOP); |
| 1126 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1127 | /* make sure word is still mis-spelt (i.e. when multi-errors) */ |
Chris Allegretta | d00e6df | 2000-11-29 04:33:26 +0000 | [diff] [blame] | 1128 | if (findnextstr(TRUE, fileage, beginx_top, prevanswer) != NULL) |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1129 | { |
Chris Allegretta | d00e6df | 2000-11-29 04:33:26 +0000 | [diff] [blame] | 1130 | do_replace_highlight(TRUE, prevanswer); |
| 1131 | |
| 1132 | /* allow replace word to be corrected */ |
| 1133 | i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace, |
| 1134 | _("Edit a replacement")); |
| 1135 | |
| 1136 | do_replace_highlight(FALSE, prevanswer); |
| 1137 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1138 | /* start from the start of this line again */ |
Chris Allegretta | d00e6df | 2000-11-29 04:33:26 +0000 | [diff] [blame] | 1139 | current = fileage; |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1140 | current_x = beginx_top; |
| 1141 | |
| 1142 | search_last_line = FALSE; |
| 1143 | |
Chris Allegretta | d00e6df | 2000-11-29 04:33:26 +0000 | [diff] [blame] | 1144 | j = i; |
| 1145 | do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1146 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1147 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1148 | /* restore the search/replace strings */ |
| 1149 | last_search = mallocstrcpy(last_search, save_search); |
| 1150 | last_replace = mallocstrcpy(last_replace, save_replace); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1151 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1152 | /* restore where we were */ |
| 1153 | current = begin; |
| 1154 | current_x = beginx - 1; |
| 1155 | |
| 1156 | edit_update(current, CENTER); |
| 1157 | |
| 1158 | if (i == -1) |
| 1159 | return FALSE; |
| 1160 | |
| 1161 | return TRUE; |
| 1162 | } |
| 1163 | #endif |
| 1164 | |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 1165 | #if !defined(NANO_SMALL) && !defined(DISABLE_SPELL) |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1166 | |
| 1167 | /* Integrated spell checking using 'spell' program */ |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1168 | int do_int_speller(char *tempfile_name) |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1169 | { |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1170 | char *read_buff, *read_buff_ptr, *read_buff_word; |
| 1171 | long pipe_buff_size; |
| 1172 | int in_fd[2], tempfile_fd; |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1173 | int spell_status; |
| 1174 | pid_t pid_spell; |
| 1175 | ssize_t bytesread; |
| 1176 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1177 | /* Create a pipe to spell program */ |
| 1178 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1179 | if (pipe(in_fd) == -1) |
| 1180 | return FALSE; |
| 1181 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1182 | /* A new process to run spell in */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1183 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1184 | if ( (pid_spell = fork()) == 0) { |
| 1185 | |
| 1186 | /* Child continues, (i.e. future spell process) */ |
| 1187 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1188 | close(in_fd[0]); |
| 1189 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1190 | /* replace the standard in with the tempfile */ |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1191 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1192 | if ( (tempfile_fd = open(tempfile_name, O_RDONLY)) == -1) { |
| 1193 | |
| 1194 | close(in_fd[1]); |
| 1195 | exit(1); |
| 1196 | } |
| 1197 | |
| 1198 | if (dup2(tempfile_fd, STDIN_FILENO) != STDIN_FILENO) { |
| 1199 | |
| 1200 | close(tempfile_fd); |
| 1201 | close(in_fd[1]); |
| 1202 | exit(1); |
| 1203 | } |
| 1204 | close(tempfile_fd); |
| 1205 | |
Chris Allegretta | d00e6df | 2000-11-29 04:33:26 +0000 | [diff] [blame] | 1206 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1207 | /* send spell's standard out to the pipe */ |
| 1208 | |
| 1209 | if (dup2(in_fd[1], STDOUT_FILENO) != STDOUT_FILENO) { |
| 1210 | |
| 1211 | close(in_fd[1]); |
| 1212 | exit(1); |
| 1213 | } |
| 1214 | close(in_fd[1]); |
| 1215 | |
| 1216 | /* Start spell program, we are using the PATH here!?!? */ |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1217 | execlp("spell", "spell", NULL); |
| 1218 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1219 | /* Should not be reached, if spell is found!!! */ |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1220 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1221 | exit(1); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | /* Parent continues here */ |
| 1225 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1226 | close(in_fd[1]); |
| 1227 | |
| 1228 | /* Child process was not forked successfully */ |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1229 | |
| 1230 | if (pid_spell < 0) { |
| 1231 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1232 | close(in_fd[0]); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1233 | return FALSE; |
| 1234 | } |
| 1235 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1236 | /* Get system pipe buffer size */ |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1237 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1238 | if ( (pipe_buff_size = fpathconf(in_fd[0], _PC_PIPE_BUF)) < 1) { |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1239 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1240 | close(in_fd[0]); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1241 | return FALSE; |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1242 | } |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1243 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1244 | read_buff = nmalloc( pipe_buff_size + 1 ); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1245 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1246 | /* Process the returned spelling errors */ |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1247 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1248 | while ( (bytesread = read(in_fd[0], read_buff, pipe_buff_size)) > 0) { |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1249 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1250 | read_buff[bytesread] = (char) NULL; |
| 1251 | read_buff_word = read_buff_ptr = read_buff; |
| 1252 | |
| 1253 | while (*read_buff_ptr != (char) NULL) { |
| 1254 | |
| 1255 | /* Windows version may need to process additional char '\r' */ |
| 1256 | |
| 1257 | /* Possible problem here if last word not followed by '\n' */ |
| 1258 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1259 | if (*read_buff_ptr == '\n') { |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1260 | *read_buff_ptr = (char) NULL; |
| 1261 | if (!do_int_spell_fix(read_buff_word)) { |
| 1262 | |
| 1263 | close(in_fd[0]); |
| 1264 | free(read_buff); |
| 1265 | replace_abort(); |
| 1266 | |
| 1267 | return TRUE; |
| 1268 | } |
| 1269 | read_buff_word = read_buff_ptr; |
| 1270 | read_buff_word++; |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | read_buff_ptr++; |
| 1274 | } |
| 1275 | } |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1276 | |
| 1277 | close(in_fd[0]); |
| 1278 | free(read_buff); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1279 | replace_abort(); |
| 1280 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1281 | /* Process end of spell process */ |
| 1282 | |
| 1283 | wait(&spell_status); |
| 1284 | if (WIFEXITED(spell_status)) { |
| 1285 | if (WEXITSTATUS(spell_status) != 0) |
| 1286 | return FALSE; |
| 1287 | } |
| 1288 | else |
| 1289 | return FALSE; |
| 1290 | |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1291 | return TRUE; |
| 1292 | } |
| 1293 | #endif |
| 1294 | |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 1295 | #if !defined(NANO_SMALL) && !defined(DISABLE_SPELL) |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1296 | |
| 1297 | /* External spell checking */ |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1298 | int do_alt_speller(char *file_name) |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1299 | { |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1300 | int alt_spell_status; |
| 1301 | pid_t pid_spell; |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1302 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1303 | endwin(); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1304 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1305 | /* Start a new process for the alternate speller */ |
| 1306 | |
| 1307 | if ( (pid_spell = fork()) == 0) { |
| 1308 | |
| 1309 | /* Start alternate spell program, we are using the PATH here!?!? */ |
| 1310 | execlp(alt_speller, alt_speller, file_name, NULL); |
| 1311 | |
| 1312 | /* Should not be reached, if alternate speller is found!!! */ |
| 1313 | |
| 1314 | exit(1); |
| 1315 | } |
| 1316 | |
| 1317 | /* Could not fork?? */ |
| 1318 | |
| 1319 | if (pid_spell < 0) |
| 1320 | return FALSE; |
| 1321 | |
| 1322 | /* Wait for alternate speller to complete */ |
| 1323 | |
| 1324 | wait(&alt_spell_status); |
| 1325 | if (WIFEXITED(alt_spell_status)) { |
| 1326 | if (WEXITSTATUS(alt_spell_status) != 0) |
| 1327 | return FALSE; |
| 1328 | } |
| 1329 | else |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1330 | return FALSE; |
| 1331 | |
Chris Allegretta | 8f6c069 | 2000-07-19 01:16:18 +0000 | [diff] [blame] | 1332 | refresh(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1333 | free_filestruct(fileage); |
| 1334 | global_init(); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1335 | open_file(file_name, 0, 1); |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 1336 | edit_update(fileage, CENTER); |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1337 | display_main_list(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1338 | set_modified(); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1339 | |
| 1340 | return TRUE; |
| 1341 | } |
| 1342 | #endif |
| 1343 | |
| 1344 | int do_spell(void) |
| 1345 | { |
| 1346 | |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 1347 | #if defined(NANO_SMALL) |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1348 | nano_small_msg(); |
| 1349 | return (TRUE); |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 1350 | #elif defined(DISABLE_SPELL) |
| 1351 | nano_disabled_msg(); |
| 1352 | return (TRUE); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1353 | #else |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1354 | char *temp; |
| 1355 | int spell_res; |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1356 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1357 | if ((temp = tempnam(0, "nano.")) == NULL) { |
| 1358 | statusbar(_("Could not create a temporary filename: %s"), |
| 1359 | strerror(errno)); |
| 1360 | return 0; |
| 1361 | } |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1362 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1363 | if (write_file(temp, 1) == -1) |
| 1364 | return 0; |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1365 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1366 | if (alt_speller) |
| 1367 | spell_res = do_alt_speller(temp); |
| 1368 | else |
| 1369 | spell_res = do_int_speller(temp); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1370 | |
Chris Allegretta | 271e972 | 2000-11-10 18:15:43 +0000 | [diff] [blame] | 1371 | remove(temp); |
Chris Allegretta | 27eb13f | 2000-11-05 16:52:21 +0000 | [diff] [blame] | 1372 | |
| 1373 | if (spell_res) |
| 1374 | statusbar(_("Finished checking spelling")); |
| 1375 | else |
| 1376 | statusbar(_("Spell checking failed")); |
| 1377 | |
| 1378 | return spell_res; |
| 1379 | |
Chris Allegretta | dbc12b2 | 2000-07-03 03:10:14 +0000 | [diff] [blame] | 1380 | #endif |
Chris Allegretta | 67105eb | 2000-07-03 03:18:32 +0000 | [diff] [blame] | 1381 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1382 | |
| 1383 | int do_exit(void) |
| 1384 | { |
| 1385 | int i; |
| 1386 | |
| 1387 | if (!ISSET(MODIFIED)) |
| 1388 | finish(0); |
| 1389 | |
Chris Allegretta | 3088555 | 2000-07-14 01:20:12 +0000 | [diff] [blame] | 1390 | if (ISSET(TEMP_OPT)) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1391 | i = 1; |
| 1392 | } else { |
| 1393 | i = |
| 1394 | do_yesno(0, 0, |
| 1395 | _ |
| 1396 | ("Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? ")); |
| 1397 | } |
| 1398 | |
| 1399 | #ifdef DEBUG |
| 1400 | dump_buffer(fileage); |
| 1401 | #endif |
| 1402 | |
| 1403 | if (i == 1) { |
| 1404 | if (do_writeout(1) > 0) |
| 1405 | finish(0); |
| 1406 | } else if (i == 0) |
| 1407 | finish(0); |
| 1408 | else |
| 1409 | statusbar(_("Cancelled")); |
| 1410 | |
| 1411 | display_main_list(); |
| 1412 | return 1; |
| 1413 | } |
| 1414 | |
| 1415 | #ifndef NANO_SMALL |
| 1416 | #ifdef NCURSES_MOUSE_VERSION |
| 1417 | void do_mouse(void) |
| 1418 | { |
| 1419 | MEVENT mevent; |
Chris Allegretta | e10debd | 2000-08-22 01:26:42 +0000 | [diff] [blame] | 1420 | int foo = 0, tab_found = 0; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1421 | |
| 1422 | if (getmouse(&mevent) == ERR) |
| 1423 | return; |
| 1424 | |
| 1425 | /* If mouse not in edit window, return (add help selection later). */ |
| 1426 | if (!wenclose(edit, mevent.y, mevent.x)) |
| 1427 | return; |
| 1428 | |
| 1429 | /* Subtract out size of topwin. Perhaps we need a constant somewhere? */ |
| 1430 | mevent.y -= 2; |
| 1431 | |
| 1432 | /* Selecting where the cursor is sets the mark. |
| 1433 | * Selecting beyond the line length with the cursor at the end of the |
| 1434 | * line sets the mark as well. |
| 1435 | */ |
| 1436 | if ((mevent.y == current_y) && |
| 1437 | ((mevent.x == current_x) || (current_x == strlen(current->data) |
| 1438 | && (mevent.x > |
| 1439 | strlen(current->data))))) { |
| 1440 | if (ISSET(VIEW_MODE)) { |
| 1441 | print_view_warning(); |
| 1442 | return; |
| 1443 | } |
| 1444 | do_mark(); |
| 1445 | } else if (mevent.y > current_y) { |
| 1446 | while (mevent.y > current_y) { |
| 1447 | if (current->next != NULL) |
| 1448 | current = current->next; |
| 1449 | else |
| 1450 | break; |
| 1451 | current_y++; |
| 1452 | } |
| 1453 | } else if (mevent.y < current_y) { |
| 1454 | while (mevent.y < current_y) { |
| 1455 | if (current->prev != NULL) |
| 1456 | current = current->prev; |
| 1457 | else |
| 1458 | break; |
| 1459 | current_y--; |
| 1460 | } |
| 1461 | } |
| 1462 | current_x = mevent.x; |
Chris Allegretta | e10debd | 2000-08-22 01:26:42 +0000 | [diff] [blame] | 1463 | placewewant = current_x; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1464 | while (foo < current_x) { |
| 1465 | if (current->data[foo] == NANO_CONTROL_I) { |
Chris Allegretta | e10debd | 2000-08-22 01:26:42 +0000 | [diff] [blame] | 1466 | current_x -= tabsize - (foo % tabsize); |
| 1467 | tab_found = 1; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1468 | } else if (current->data[foo] & 0x80); |
| 1469 | else if (current->data[foo] < 32) |
Chris Allegretta | e10debd | 2000-08-22 01:26:42 +0000 | [diff] [blame] | 1470 | current_x--; |
| 1471 | foo++; |
| 1472 | } |
| 1473 | /* This is where tab_found comes in. I can't figure out why, |
| 1474 | * but without it any line with a tab will place the cursor |
| 1475 | * one character behind. Whatever, this fixes it. */ |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1476 | if (tab_found == 1) |
Chris Allegretta | e10debd | 2000-08-22 01:26:42 +0000 | [diff] [blame] | 1477 | current_x++; |
| 1478 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1479 | if (current_x > strlen(current->data)) |
| 1480 | current_x = strlen(current->data); |
| 1481 | |
| 1482 | update_cursor(); |
| 1483 | edit_refresh(); |
| 1484 | |
| 1485 | } |
| 1486 | #endif |
| 1487 | #endif |
| 1488 | |
| 1489 | /* Handler for SIGHUP */ |
| 1490 | RETSIGTYPE handle_hup(int signal) |
| 1491 | { |
| 1492 | write_file("nano.save", 0); |
| 1493 | finish(1); |
| 1494 | } |
| 1495 | |
Chris Allegretta | 18f8be0 | 2000-09-04 03:20:38 +0000 | [diff] [blame] | 1496 | /* What do we do when we catch the suspend signal */ |
| 1497 | RETSIGTYPE do_suspend(int signal) |
| 1498 | { |
| 1499 | |
| 1500 | act.sa_handler = SIG_DFL; |
| 1501 | sigemptyset(&act.sa_mask); |
| 1502 | sigaction(SIGTSTP, &act, NULL); |
| 1503 | |
| 1504 | endwin(); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1505 | fprintf(stderr, "\n\n\n\n\nUse \"fg\" to return to nano\n"); |
Chris Allegretta | 18f8be0 | 2000-09-04 03:20:38 +0000 | [diff] [blame] | 1506 | raise(SIGTSTP); |
| 1507 | } |
| 1508 | |
| 1509 | /* Restore the suspend handler when we come back into the prog */ |
| 1510 | RETSIGTYPE do_cont(int signal) |
| 1511 | { |
| 1512 | |
| 1513 | act.sa_handler = do_suspend; |
| 1514 | sigemptyset(&act.sa_mask); |
| 1515 | sigaction(SIGTSTP, &act, NULL); |
| 1516 | initscr(); |
| 1517 | total_refresh(); |
| 1518 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1519 | |
| 1520 | void handle_sigwinch(int s) |
| 1521 | { |
| 1522 | #ifndef NANO_SMALL |
| 1523 | char *tty = NULL; |
| 1524 | int fd = 0; |
| 1525 | int result = 0; |
| 1526 | int i = 0; |
| 1527 | struct winsize win; |
| 1528 | |
| 1529 | tty = ttyname(0); |
| 1530 | if (!tty) |
| 1531 | return; |
| 1532 | fd = open(tty, O_RDWR); |
| 1533 | if (fd == -1) |
| 1534 | return; |
| 1535 | result = ioctl(fd, TIOCGWINSZ, &win); |
| 1536 | if (result == -1) |
| 1537 | return; |
| 1538 | |
| 1539 | |
| 1540 | COLS = win.ws_col; |
| 1541 | LINES = win.ws_row; |
| 1542 | |
| 1543 | center_x = COLS / 2; |
| 1544 | center_y = LINES / 2; |
| 1545 | editwinrows = LINES - 5 + no_help(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1546 | fill = COLS - 8; |
| 1547 | |
| 1548 | free(hblank); |
| 1549 | hblank = nmalloc(COLS + 1); |
| 1550 | |
| 1551 | for (i = 0; i <= COLS - 1; i++) |
| 1552 | hblank[i] = ' '; |
| 1553 | hblank[i] = 0; |
| 1554 | |
| 1555 | #ifdef HAVE_NCURSES_H |
| 1556 | resizeterm(LINES, COLS); |
| 1557 | #ifdef HAVE_WRESIZE |
| 1558 | if (wresize(topwin, 2, COLS) == ERR) |
| 1559 | die(_("Cannot resize top win")); |
| 1560 | if (mvwin(topwin, 0, 0) == ERR) |
| 1561 | die(_("Cannot move top win")); |
| 1562 | if (wresize(edit, editwinrows, COLS) == ERR) |
| 1563 | die(_("Cannot resize edit win")); |
| 1564 | if (mvwin(edit, 2, 0) == ERR) |
| 1565 | die(_("Cannot move edit win")); |
| 1566 | if (wresize(bottomwin, 3 - no_help(), COLS) == ERR) |
| 1567 | die(_("Cannot resize bottom win")); |
| 1568 | if (mvwin(bottomwin, LINES - 3 + no_help(), 0) == ERR) |
| 1569 | die(_("Cannot move bottom win")); |
| 1570 | #endif /* HAVE_WRESIZE */ |
| 1571 | #endif /* HAVE_NCURSES_H */ |
| 1572 | |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1573 | fix_editbot(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1574 | |
Chris Allegretta | bceb1b2 | 2000-06-19 04:22:15 +0000 | [diff] [blame] | 1575 | if (current_y > editwinrows - 1) { |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 1576 | edit_update(editbot, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1577 | } |
| 1578 | erase(); |
Chris Allegretta | 97accc6 | 2000-06-19 05:45:52 +0000 | [diff] [blame] | 1579 | |
| 1580 | /* Do these b/c width may have changed... */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1581 | refresh(); |
Chris Allegretta | 97accc6 | 2000-06-19 05:45:52 +0000 | [diff] [blame] | 1582 | titlebar(); |
| 1583 | edit_refresh(); |
| 1584 | display_main_list(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1585 | total_refresh(); |
| 1586 | #endif |
| 1587 | } |
| 1588 | |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1589 | void signal_init(void) |
| 1590 | { |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1591 | |
| 1592 | /* Trap SIGINT and SIGQUIT cuz we want them to do useful things. */ |
| 1593 | memset(&act, 0, sizeof(struct sigaction)); |
| 1594 | act.sa_handler = SIG_IGN; |
| 1595 | sigaction(SIGINT, &act, NULL); |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1596 | |
Chris Allegretta | 18f8be0 | 2000-09-04 03:20:38 +0000 | [diff] [blame] | 1597 | if (!ISSET(SUSPEND)) { |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1598 | sigaction(SIGTSTP, &act, NULL); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1599 | } else { |
Chris Allegretta | 18f8be0 | 2000-09-04 03:20:38 +0000 | [diff] [blame] | 1600 | act.sa_handler = do_suspend; |
| 1601 | sigaction(SIGTSTP, &act, NULL); |
| 1602 | |
| 1603 | act.sa_handler = do_cont; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1604 | sigaction(SIGCONT, &act, NULL); |
Chris Allegretta | 18f8be0 | 2000-09-04 03:20:38 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1607 | |
| 1608 | /* Trap SIGHUP cuz we want to write the file out. */ |
| 1609 | act.sa_handler = handle_hup; |
| 1610 | sigaction(SIGHUP, &act, NULL); |
| 1611 | |
| 1612 | act.sa_handler = handle_sigwinch; |
| 1613 | sigaction(SIGWINCH, &act, NULL); |
| 1614 | |
| 1615 | } |
| 1616 | |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1617 | void window_init(void) |
| 1618 | { |
Chris Allegretta | 92c9dd2 | 2000-09-13 14:03:27 +0000 | [diff] [blame] | 1619 | editwinrows = LINES - 5 + no_help(); |
| 1620 | |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1621 | /* Setup up the main text window */ |
| 1622 | edit = newwin(editwinrows, COLS, 2, 0); |
| 1623 | |
| 1624 | /* And the other windows */ |
| 1625 | topwin = newwin(2, COLS, 0, 0); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1626 | bottomwin = newwin(3 - no_help(), COLS, LINES - 3 + no_help(), 0); |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1629 | void mouse_init(void) |
| 1630 | { |
| 1631 | #ifndef NANO_SMALL |
| 1632 | #ifdef NCURSES_MOUSE_VERSION |
| 1633 | if (ISSET(USE_MOUSE)) { |
Chris Allegretta | 1cc0b7f | 2000-11-03 01:29:04 +0000 | [diff] [blame] | 1634 | keypad_on(TRUE); |
Chris Allegretta | 0b88ce0 | 2000-09-15 15:46:32 +0000 | [diff] [blame] | 1635 | |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1636 | mousemask(BUTTON1_RELEASED, NULL); |
| 1637 | mouseinterval(50); |
Chris Allegretta | 0b88ce0 | 2000-09-15 15:46:32 +0000 | [diff] [blame] | 1638 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1639 | } else { |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1640 | mousemask(0, NULL); |
Chris Allegretta | 1cc0b7f | 2000-11-03 01:29:04 +0000 | [diff] [blame] | 1641 | keypad_on(FALSE); |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1642 | } |
| 1643 | #endif |
| 1644 | #endif |
| 1645 | |
| 1646 | } |
| 1647 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1648 | int do_tab(void) |
| 1649 | { |
| 1650 | do_char('\t'); |
| 1651 | return 1; |
| 1652 | } |
| 1653 | |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 1654 | #if !defined(NANO_SMALL) && !defined(DISABLE_JUSTIFY) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1655 | int empty_line(const char *data) |
| 1656 | { |
| 1657 | while (*data) { |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 1658 | if (!isspace((int) *data)) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1659 | return 0; |
| 1660 | |
| 1661 | data++; |
| 1662 | } |
| 1663 | |
| 1664 | return 1; |
| 1665 | } |
| 1666 | |
| 1667 | int no_spaces(const char *data) |
| 1668 | { |
| 1669 | while (*data) { |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 1670 | if (isspace((int) *data)) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1671 | return 0; |
| 1672 | |
| 1673 | data++; |
| 1674 | } |
| 1675 | |
| 1676 | return 1; |
| 1677 | } |
| 1678 | |
| 1679 | void justify_format(char *data) |
| 1680 | { |
| 1681 | int i = 0; |
| 1682 | int len = strlen(data); |
| 1683 | |
| 1684 | /* Skip first character regardless and leading whitespace. */ |
| 1685 | for (i = 1; i < len; i++) { |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 1686 | if (!isspace((int) data[i])) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1687 | break; |
| 1688 | } |
| 1689 | |
| 1690 | i++; /* (i) is now at least 2. */ |
| 1691 | |
| 1692 | /* No double spaces allowed unless following a period. Tabs -> space. No double tabs. */ |
| 1693 | for (; i < len; i++) { |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 1694 | if (isspace((int) data[i]) && isspace((int) data[i - 1]) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1695 | && (data[i - 2] != '.')) { |
| 1696 | memmove(data + i, data + i + 1, len - i); |
| 1697 | len--; |
| 1698 | i--; |
| 1699 | } |
| 1700 | } |
| 1701 | } |
| 1702 | #endif |
| 1703 | |
| 1704 | int do_justify(void) |
| 1705 | { |
Chris Allegretta | ff269f8 | 2000-12-01 18:46:01 +0000 | [diff] [blame] | 1706 | #ifdef NANO_SMALL |
| 1707 | nano_small_msg(); |
| 1708 | return 1; |
| 1709 | #elif defined(DISABLE_JUSTIFY) |
| 1710 | nano_disabled_msg(); |
| 1711 | return 1; |
| 1712 | #else |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1713 | int slen = 0; /* length of combined lines on one line. */ |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1714 | int initial_y, kbinput; |
| 1715 | filestruct *initial = NULL, *tmpjust = NULL, *cutbak, *tmptop, *tmpbot; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1716 | |
| 1717 | if (empty_line(current->data)) { |
| 1718 | /* Justify starting at first non-empty line. */ |
| 1719 | do { |
| 1720 | if (!current->next) |
| 1721 | return 1; |
| 1722 | |
| 1723 | current = current->next; |
| 1724 | current_y++; |
| 1725 | } |
| 1726 | while (empty_line(current->data)); |
| 1727 | } else { |
| 1728 | /* Search back for the beginning of the paragraph, where |
| 1729 | * Paragraph is 1) A line with leading whitespace |
| 1730 | * or 2) A line following an empty line. |
| 1731 | */ |
| 1732 | while (current->prev != NULL) { |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 1733 | if (isspace((int) current->data[0]) || !current->data[0]) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1734 | break; |
| 1735 | |
| 1736 | current = current->prev; |
| 1737 | current_y--; |
| 1738 | } |
| 1739 | |
| 1740 | /* First line with leading whitespace may be empty. */ |
| 1741 | if (empty_line(current->data)) { |
| 1742 | if (current->next) { |
| 1743 | current = current->next; |
| 1744 | current_y++; |
| 1745 | } else |
| 1746 | return 1; |
| 1747 | } |
| 1748 | } |
| 1749 | initial = current; |
| 1750 | initial_y = current_y; |
| 1751 | |
| 1752 | set_modified(); |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1753 | cutbak = cutbuffer; /* Got to like cutbak ;) */ |
| 1754 | cutbuffer = NULL; |
| 1755 | |
| 1756 | tmptop = current; |
| 1757 | tmpjust = copy_node(current); |
| 1758 | add_to_cutbuffer(tmpjust); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1759 | /* Put the whole paragraph into one big line. */ |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 1760 | while (current->next && !isspace((int) current->next->data[0]) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1761 | && current->next->data[0]) { |
| 1762 | filestruct *tmpnode = current->next; |
| 1763 | int len = strlen(current->data); |
| 1764 | int len2 = strlen(current->next->data); |
| 1765 | |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1766 | tmpjust = NULL; |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1767 | tmpjust = copy_node(current->next); |
| 1768 | add_to_cutbuffer(tmpjust); |
| 1769 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1770 | /* length of both strings plus space between strings and ending \0. */ |
| 1771 | current->data = nrealloc(current->data, len + len2 + 2); |
| 1772 | current->data[len++] = ' '; |
| 1773 | current->data[len] = '\0'; |
| 1774 | |
| 1775 | strncat(current->data, current->next->data, len2); |
| 1776 | |
| 1777 | unlink_node(tmpnode); |
| 1778 | delete_node(tmpnode); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1781 | totsize -= strlen(current->data); |
| 1782 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1783 | justify_format(current->data); |
| 1784 | |
| 1785 | slen = strlen(current->data); |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1786 | totsize += slen; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1787 | |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1788 | if ((strlenpt(current->data) > (fill)) |
| 1789 | && !no_spaces(current->data)) { |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1790 | do { |
| 1791 | int i = 0; |
| 1792 | int len2 = 0; |
| 1793 | filestruct *tmpline = nmalloc(sizeof(filestruct)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1794 | |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1795 | /* Start at fill , unless line isn't that long (but it |
| 1796 | * appears at least fill long with tabs. |
| 1797 | */ |
| 1798 | if (slen > fill) |
| 1799 | i = fill; |
| 1800 | else |
| 1801 | i = slen; |
| 1802 | for (; i > 0; i--) { |
Chris Allegretta | 9e7efa3 | 2000-10-02 03:42:55 +0000 | [diff] [blame] | 1803 | if (isspace((int) current->data[i]) && |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1804 | ((strlenpt(current->data) - strlen(current->data + i)) |
| 1805 | <= fill)) |
| 1806 | break; |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1807 | } |
| 1808 | if (!i) |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1809 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1810 | |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1811 | current->data[i] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1812 | |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1813 | len2 = strlen(current->data + i + 1); |
| 1814 | tmpline->data = nmalloc(len2 + 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1815 | |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1816 | /* Skip the white space in current. */ |
| 1817 | memcpy(tmpline->data, current->data + i + 1, len2); |
| 1818 | tmpline->data[len2] = '\0'; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1819 | |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1820 | current->data = nrealloc(current->data, i + 1); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1821 | |
Robert Siemborski | a417ddc | 2000-07-24 23:18:48 +0000 | [diff] [blame] | 1822 | tmpline->prev = current; |
| 1823 | tmpline->next = current->next; |
| 1824 | if (current->next != NULL) |
| 1825 | current->next->prev = tmpline; |
| 1826 | |
| 1827 | current->next = tmpline; |
| 1828 | current = tmpline; |
| 1829 | slen -= i + 1; |
| 1830 | current_y++; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1831 | } while ((strlenpt(current->data) > (fill)) |
| 1832 | && !no_spaces(current->data)); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1833 | } |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1834 | tmpbot = current; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1835 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1836 | if (current->next) |
| 1837 | current = current->next; |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 1838 | else |
| 1839 | filebot = current; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1840 | current_x = 0; |
| 1841 | placewewant = 0; |
| 1842 | |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 1843 | renumber(initial); |
| 1844 | totlines = filebot->lineno; |
| 1845 | |
| 1846 | werase(edit); |
| 1847 | |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 1848 | if ((current_y < 0) || (current_y >= editwinrows - 1) |
| 1849 | || (initial_y <= 0)) { |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 1850 | edit_update(current, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1851 | center_cursor(); |
| 1852 | } else { |
Robert Siemborski | dd53ec2 | 2000-07-04 02:35:19 +0000 | [diff] [blame] | 1853 | fix_editbot(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
Adam Rogoyski | 09f9796 | 2000-06-20 02:50:33 +0000 | [diff] [blame] | 1856 | edit_refresh(); |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1857 | statusbar(_("Can now UnJustify!")); |
Chris Allegretta | 0779835 | 2000-11-27 22:58:23 +0000 | [diff] [blame] | 1858 | /* Change the shortcut list to display the unjustify code */ |
| 1859 | shortcut_init(1); |
| 1860 | display_main_list(); |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1861 | reset_cursor(); |
| 1862 | |
Chris Allegretta | 0779835 | 2000-11-27 22:58:23 +0000 | [diff] [blame] | 1863 | /* Now get a keystroke and see if it's unjustify, if not unget the keytroke |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1864 | and return */ |
Chris Allegretta | 4a9c858 | 2000-11-27 22:59:40 +0000 | [diff] [blame] | 1865 | if ((kbinput = wgetch(edit)) != NANO_UNJUSTIFY_KEY) |
Chris Allegretta | 0779835 | 2000-11-27 22:58:23 +0000 | [diff] [blame] | 1866 | ungetch(kbinput); |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1867 | else { |
| 1868 | /* Else restore the justify we just did (ungrateful user!) */ |
| 1869 | if (tmptop->prev != NULL) |
| 1870 | tmptop->prev->next = tmpbot->next; |
Chris Allegretta | d022eac | 2000-11-27 02:50:49 +0000 | [diff] [blame] | 1871 | else |
| 1872 | fileage = current; |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1873 | tmpbot->next->prev = tmptop->prev; |
| 1874 | current = tmpbot->next; |
| 1875 | tmpbot->next = NULL; |
| 1876 | do_uncut_text(); |
Chris Allegretta | d022eac | 2000-11-27 02:50:49 +0000 | [diff] [blame] | 1877 | if (tmptop->prev == NULL) |
| 1878 | edit_refresh(); |
| 1879 | |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1880 | free_filestruct(tmptop); |
| 1881 | blank_statusbar_refresh(); |
| 1882 | } |
Chris Allegretta | 4a9c858 | 2000-11-27 22:59:40 +0000 | [diff] [blame] | 1883 | shortcut_init(0); |
| 1884 | display_main_list(); |
Chris Allegretta | 9149e61 | 2000-11-27 00:23:41 +0000 | [diff] [blame] | 1885 | free_filestruct(cutbuffer); |
| 1886 | cutbuffer = cutbak; |
| 1887 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1888 | return 1; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1889 | #endif |
| 1890 | } |
| 1891 | |
| 1892 | |
| 1893 | void help_init(void) |
| 1894 | { |
| 1895 | int i, sofar = 0; |
| 1896 | long allocsize = 1; /* How much space we're gonna need for the help text */ |
| 1897 | char buf[BUFSIZ]; |
| 1898 | |
| 1899 | /* Compute the space needed for the shortcut lists - we add 15 to |
| 1900 | have room for the shortcut abbrev and its possible alternate keys */ |
| 1901 | for (i = 0; i < MAIN_LIST_LEN; i++) |
| 1902 | if (main_list[i].help != NULL) |
| 1903 | allocsize += strlen(main_list[i].help) + 15; |
| 1904 | |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1905 | /* And for the toggle list, we also allocate space for extra text. */ |
Chris Allegretta | 423cbfd | 2000-09-04 16:21:29 +0000 | [diff] [blame] | 1906 | for (i = 0; i <= TOGGLE_LEN - 1; i++) |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1907 | if (toggles[i].desc != NULL) |
| 1908 | allocsize += strlen(toggles[i].desc) + 30; |
| 1909 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1910 | allocsize += strlen(help_text_init); |
| 1911 | |
| 1912 | if (help_text != NULL) |
| 1913 | free(help_text); |
| 1914 | |
| 1915 | /* Allocate space for the help text */ |
| 1916 | help_text = nmalloc(allocsize); |
| 1917 | |
| 1918 | /* Now add the text we want */ |
| 1919 | strcpy(help_text, help_text_init); |
| 1920 | |
| 1921 | /* Now add our shortcut info */ |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1922 | for (i = 0; i < MAIN_LIST_LEN - 1; i++) { |
Robert Siemborski | 6af1431 | 2000-07-01 21:34:26 +0000 | [diff] [blame] | 1923 | sofar = snprintf(buf, BUFSIZ, "^%c ", main_list[i].val + 64); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1924 | |
| 1925 | if (main_list[i].misc1 > KEY_F0 && main_list[i].misc1 <= KEY_F(64)) |
Robert Siemborski | 6af1431 | 2000-07-01 21:34:26 +0000 | [diff] [blame] | 1926 | sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(F%d) ", |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1927 | main_list[i].misc1 - KEY_F0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1928 | else |
Robert Siemborski | 6af1431 | 2000-07-01 21:34:26 +0000 | [diff] [blame] | 1929 | sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " "); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1930 | |
| 1931 | if (main_list[i].altval > 0) |
Chris Allegretta | e49f123 | 2000-09-02 07:20:39 +0000 | [diff] [blame] | 1932 | sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ", |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1933 | main_list[i].altval - 32); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1934 | else |
Robert Siemborski | 6af1431 | 2000-07-01 21:34:26 +0000 | [diff] [blame] | 1935 | sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " "); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1936 | |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1937 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1938 | if (main_list[i].help != NULL) |
Robert Siemborski | 976847c | 2000-07-06 03:43:05 +0000 | [diff] [blame] | 1939 | snprintf(&buf[sofar], BUFSIZ - sofar, "%s", main_list[i].help); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1940 | |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1941 | |
| 1942 | strcat(help_text, buf); |
| 1943 | strcat(help_text, "\n"); |
| 1944 | } |
| 1945 | |
| 1946 | /* And the toggles... */ |
Chris Allegretta | 423cbfd | 2000-09-04 16:21:29 +0000 | [diff] [blame] | 1947 | for (i = 0; i <= TOGGLE_LEN - 1; i++) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1948 | sofar = snprintf(buf, BUFSIZ, |
| 1949 | "M-%c ", toggles[i].val - 32); |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1950 | |
| 1951 | if (toggles[i].desc != NULL) |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1952 | snprintf(&buf[sofar], BUFSIZ - sofar, _("%s enable/disable"), |
| 1953 | toggles[i].desc); |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1954 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1955 | strcat(help_text, buf); |
Robert Siemborski | 976847c | 2000-07-06 03:43:05 +0000 | [diff] [blame] | 1956 | strcat(help_text, "\n"); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | } |
| 1960 | |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1961 | void do_toggle(int which) |
| 1962 | { |
| 1963 | #ifndef NANO_SMALL |
Jordi Mallach | 2dc0f6b | 2000-09-07 10:48:00 +0000 | [diff] [blame] | 1964 | char *enabled = _("enabled"); |
| 1965 | char *disabled = _("disabled"); |
Chris Allegretta | f0f63a8 | 2000-09-02 18:44:21 +0000 | [diff] [blame] | 1966 | |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1967 | if (ISSET(toggles[which].flag)) |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1968 | UNSET(toggles[which].flag); |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1969 | else |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1970 | SET(toggles[which].flag); |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1971 | |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1972 | switch (toggles[which].val) { |
| 1973 | case TOGGLE_PICOMODE_KEY: |
Chris Allegretta | 0779835 | 2000-11-27 22:58:23 +0000 | [diff] [blame] | 1974 | shortcut_init(0); |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1975 | display_main_list(); |
| 1976 | break; |
| 1977 | case TOGGLE_SUSPEND_KEY: |
| 1978 | signal_init(); |
| 1979 | break; |
| 1980 | case TOGGLE_MOUSE_KEY: |
| 1981 | mouse_init(); |
| 1982 | break; |
| 1983 | case TOGGLE_NOHELP_KEY: |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1984 | wclear(bottomwin); |
| 1985 | wrefresh(bottomwin); |
| 1986 | window_init(); |
| 1987 | edit_refresh(); |
| 1988 | display_main_list(); |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 1989 | break; |
| 1990 | } |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1991 | |
| 1992 | if (!ISSET(toggles[which].flag)) { |
| 1993 | if (toggles[which].val == TOGGLE_NOHELP_KEY || |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 1994 | toggles[which].val == TOGGLE_WRAP_KEY) |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 1995 | statusbar("%s %s", toggles[which].desc, enabled); |
| 1996 | else |
| 1997 | statusbar("%s %s", toggles[which].desc, disabled); |
| 1998 | } else { |
| 1999 | if (toggles[which].val == TOGGLE_NOHELP_KEY || |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2000 | toggles[which].val == TOGGLE_WRAP_KEY) |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 2001 | statusbar("%s %s", toggles[which].desc, disabled); |
| 2002 | else |
| 2003 | statusbar("%s %s", toggles[which].desc, enabled); |
| 2004 | } |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 2005 | SET(DISABLE_CURPOS); |
| 2006 | |
Chris Allegretta | 4c780be | 2000-09-01 17:59:18 +0000 | [diff] [blame] | 2007 | #else |
| 2008 | nano_small_msg(); |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 2009 | #endif |
| 2010 | } |
| 2011 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2012 | int main(int argc, char *argv[]) |
| 2013 | { |
| 2014 | int optchr; |
| 2015 | int kbinput; /* Input from keyboard */ |
| 2016 | long startline = 0; /* Line to try and start at */ |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2017 | int keyhandled = 0; /* Have we handled the keystroke yet? */ |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2018 | int i; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2019 | char *argv0; |
Chris Allegretta | ad1dacc | 2000-09-21 04:25:45 +0000 | [diff] [blame] | 2020 | #ifdef _POSIX_VDISABLE |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2021 | struct termios term; |
Chris Allegretta | ad1dacc | 2000-09-21 04:25:45 +0000 | [diff] [blame] | 2022 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2023 | |
| 2024 | #ifdef HAVE_GETOPT_LONG |
| 2025 | int option_index = 0; |
| 2026 | struct option long_options[] = { |
Chris Allegretta | 805c26d | 2000-09-06 13:39:17 +0000 | [diff] [blame] | 2027 | #ifdef HAVE_REGEX_H |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2028 | {"regexp", 0, 0, 'R'}, |
Chris Allegretta | 4780561 | 2000-07-07 02:35:34 +0000 | [diff] [blame] | 2029 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2030 | {"version", 0, 0, 'V'}, |
| 2031 | {"const", 0, 0, 'c'}, |
| 2032 | {"suspend", 0, 0, 'z'}, |
| 2033 | {"nowrap", 0, 0, 'w'}, |
| 2034 | {"nohelp", 0, 0, 'x'}, |
| 2035 | {"help", 0, 0, 'h'}, |
Chris Allegretta | d19e991 | 2000-07-12 18:14:51 +0000 | [diff] [blame] | 2036 | #ifndef NANO_SMALL |
Chris Allegretta | 627de19 | 2000-07-12 02:09:17 +0000 | [diff] [blame] | 2037 | {"cut", 0, 0, 'k'}, |
Chris Allegretta | d19e991 | 2000-07-12 18:14:51 +0000 | [diff] [blame] | 2038 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2039 | {"autoindent", 0, 0, 'i'}, |
| 2040 | {"tempfile", 0, 0, 't'}, |
| 2041 | {"speller", 1, 0, 's'}, |
| 2042 | {"fill", 1, 0, 'r'}, |
| 2043 | {"mouse", 0, 0, 'm'}, |
| 2044 | {"pico", 0, 0, 'p'}, |
| 2045 | {"nofollow", 0, 0, 'l'}, |
Chris Allegretta | 4dbcc3c | 2000-08-04 15:44:29 +0000 | [diff] [blame] | 2046 | {"tabsize", 1, 0, 'T'}, |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2047 | {0, 0, 0, 0} |
| 2048 | }; |
| 2049 | #endif |
| 2050 | |
| 2051 | /* Flag inits... */ |
| 2052 | SET(FOLLOW_SYMLINKS); |
| 2053 | |
| 2054 | #ifndef NANO_SMALL |
| 2055 | setlocale(LC_ALL, ""); |
| 2056 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 2057 | textdomain(PACKAGE); |
| 2058 | #endif |
| 2059 | |
| 2060 | #ifdef HAVE_GETOPT_LONG |
Chris Allegretta | 627de19 | 2000-07-12 02:09:17 +0000 | [diff] [blame] | 2061 | while ((optchr = getopt_long(argc, argv, "?T:RVchiklmpr:s:tvwxz", |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2062 | long_options, &option_index)) != EOF) { |
| 2063 | #else |
Chris Allegretta | 627de19 | 2000-07-12 02:09:17 +0000 | [diff] [blame] | 2064 | while ((optchr = getopt(argc, argv, "h?T:RVciklmpr:s:tvwxz")) != EOF) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2065 | #endif |
| 2066 | |
| 2067 | switch (optchr) { |
Chris Allegretta | 6724a7e | 2000-06-19 23:19:07 +0000 | [diff] [blame] | 2068 | case 'T': |
Chris Allegretta | 99bf73f | 2000-08-04 00:22:08 +0000 | [diff] [blame] | 2069 | tabsize = atoi(optarg); |
| 2070 | if (tabsize <= 0) { |
Chris Allegretta | 6724a7e | 2000-06-19 23:19:07 +0000 | [diff] [blame] | 2071 | usage(); /* To stop bogus data for tab width */ |
| 2072 | finish(1); |
| 2073 | } |
| 2074 | break; |
Chris Allegretta | 805c26d | 2000-09-06 13:39:17 +0000 | [diff] [blame] | 2075 | #ifdef HAVE_REGEX_H |
Chris Allegretta | 9fc8d43 | 2000-07-07 01:49:52 +0000 | [diff] [blame] | 2076 | case 'R': |
| 2077 | SET(USE_REGEXP); |
| 2078 | break; |
Chris Allegretta | 4780561 | 2000-07-07 02:35:34 +0000 | [diff] [blame] | 2079 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2080 | case 'V': |
| 2081 | version(); |
| 2082 | exit(0); |
| 2083 | case 'c': |
| 2084 | SET(CONSTUPDATE); |
| 2085 | break; |
| 2086 | case 'h': |
| 2087 | case '?': |
| 2088 | usage(); |
| 2089 | exit(0); |
| 2090 | case 'i': |
| 2091 | SET(AUTOINDENT); |
| 2092 | break; |
Chris Allegretta | d19e991 | 2000-07-12 18:14:51 +0000 | [diff] [blame] | 2093 | #ifndef NANO_SMALL |
Chris Allegretta | 627de19 | 2000-07-12 02:09:17 +0000 | [diff] [blame] | 2094 | case 'k': |
| 2095 | SET(CUT_TO_END); |
| 2096 | break; |
Chris Allegretta | 18bd029 | 2000-07-28 01:18:10 +0000 | [diff] [blame] | 2097 | #else |
| 2098 | case 'k': |
| 2099 | usage(); /* Oops! You dont really have that option */ |
| 2100 | finish(1); |
Chris Allegretta | d19e991 | 2000-07-12 18:14:51 +0000 | [diff] [blame] | 2101 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2102 | case 'l': |
| 2103 | UNSET(FOLLOW_SYMLINKS); |
| 2104 | break; |
| 2105 | case 'm': |
| 2106 | SET(USE_MOUSE); |
| 2107 | break; |
| 2108 | case 'p': |
Chris Allegretta | bf9a8cc | 2000-11-17 01:37:39 +0000 | [diff] [blame] | 2109 | SET(PICO_MODE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2110 | break; |
| 2111 | case 'r': |
| 2112 | fill = atoi(optarg); |
| 2113 | if (fill <= 0) { |
| 2114 | usage(); /* To stop bogus data (like a string) */ |
| 2115 | finish(1); |
| 2116 | } |
| 2117 | break; |
| 2118 | case 's': |
| 2119 | alt_speller = nmalloc(strlen(optarg) + 1); |
| 2120 | strcpy(alt_speller, optarg); |
| 2121 | break; |
| 2122 | case 't': |
Chris Allegretta | 3088555 | 2000-07-14 01:20:12 +0000 | [diff] [blame] | 2123 | SET(TEMP_OPT); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2124 | break; |
| 2125 | case 'v': |
| 2126 | SET(VIEW_MODE); |
| 2127 | break; |
| 2128 | case 'w': |
| 2129 | SET(NO_WRAP); |
| 2130 | break; |
| 2131 | case 'x': |
| 2132 | SET(NO_HELP); |
| 2133 | break; |
| 2134 | case 'z': |
| 2135 | SET(SUSPEND); |
| 2136 | break; |
| 2137 | default: |
| 2138 | usage(); |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 2139 | exit(0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | } |
| 2143 | |
| 2144 | argv0 = strrchr(argv[0], '/'); |
| 2145 | if ((argv0 && strstr(argv0, "pico")) |
| 2146 | || (!argv0 && strstr(argv[0], "pico"))) |
Chris Allegretta | bf9a8cc | 2000-11-17 01:37:39 +0000 | [diff] [blame] | 2147 | SET(PICO_MODE); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2148 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2149 | /* See if there's a non-option in argv (first non-option is the |
| 2150 | filename, if +LINE is not given) */ |
| 2151 | if (argc == 1 || argc <= optind) |
| 2152 | strcpy(filename, ""); |
| 2153 | else { |
| 2154 | /* Look for the +line flag... */ |
| 2155 | if (argv[optind][0] == '+') { |
| 2156 | startline = atoi(&argv[optind][1]); |
| 2157 | optind++; |
| 2158 | if (argc == 1 || argc <= optind) |
| 2159 | strcpy(filename, ""); |
| 2160 | else |
| 2161 | strncpy(filename, argv[optind], 132); |
| 2162 | } else |
| 2163 | strncpy(filename, argv[optind], 132); |
| 2164 | |
| 2165 | } |
| 2166 | |
| 2167 | |
| 2168 | /* First back up the old settings so they can be restored, duh */ |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 2169 | tcgetattr(0, &oldterm); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2170 | |
Chris Allegretta | 9239d74 | 2000-09-06 15:19:18 +0000 | [diff] [blame] | 2171 | #ifdef _POSIX_VDISABLE |
Chris Allegretta | 8f6c069 | 2000-07-19 01:16:18 +0000 | [diff] [blame] | 2172 | term = oldterm; |
| 2173 | term.c_cc[VINTR] = _POSIX_VDISABLE; |
| 2174 | term.c_cc[VQUIT] = _POSIX_VDISABLE; |
| 2175 | term.c_lflag &= ~IEXTEN; |
Chris Allegretta | 4da1fc6 | 2000-06-21 03:00:43 +0000 | [diff] [blame] | 2176 | tcsetattr(0, TCSANOW, &term); |
Chris Allegretta | 9239d74 | 2000-09-06 15:19:18 +0000 | [diff] [blame] | 2177 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2178 | |
| 2179 | /* now ncurses init stuff... */ |
| 2180 | initscr(); |
| 2181 | savetty(); |
| 2182 | nonl(); |
| 2183 | cbreak(); |
| 2184 | noecho(); |
| 2185 | timeout(0); |
| 2186 | |
| 2187 | /* Set up some global variables */ |
| 2188 | global_init(); |
Chris Allegretta | 0779835 | 2000-11-27 22:58:23 +0000 | [diff] [blame] | 2189 | shortcut_init(0); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2190 | init_help_msg(); |
| 2191 | help_init(); |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 2192 | signal_init(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2193 | |
| 2194 | #ifdef DEBUG |
| 2195 | fprintf(stderr, _("Main: set up windows\n")); |
| 2196 | #endif |
| 2197 | |
Chris Allegretta | 2a42af1 | 2000-09-12 23:02:49 +0000 | [diff] [blame] | 2198 | window_init(); |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 2199 | mouse_init(); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2200 | |
Chris Allegretta | ad1dacc | 2000-09-21 04:25:45 +0000 | [diff] [blame] | 2201 | #ifdef PDCURSES |
| 2202 | /* Must have this for the arrow, et al, keys to even work in |
| 2203 | PDCurses+cygwin under Windows */ |
Chris Allegretta | 1cc0b7f | 2000-11-03 01:29:04 +0000 | [diff] [blame] | 2204 | keypad_on(TRUE); |
Chris Allegretta | ad1dacc | 2000-09-21 04:25:45 +0000 | [diff] [blame] | 2205 | #endif |
| 2206 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2207 | #ifdef DEBUG |
| 2208 | fprintf(stderr, _("Main: bottom win\n")); |
| 2209 | #endif |
| 2210 | /* Set up up bottom of window */ |
| 2211 | display_main_list(); |
| 2212 | |
| 2213 | #ifdef DEBUG |
| 2214 | fprintf(stderr, _("Main: open file\n")); |
| 2215 | #endif |
| 2216 | |
| 2217 | titlebar(); |
Chris Allegretta | 31c7666 | 2000-11-21 06:20:20 +0000 | [diff] [blame] | 2218 | |
| 2219 | /* Now we check to see if argv[optind] is non-null to determine if |
| 2220 | we're dealing with a new file or not, not argc == 1... */ |
| 2221 | if (argv[optind] == NULL) |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2222 | new_file(); |
| 2223 | else |
| 2224 | open_file(filename, 0, 0); |
| 2225 | |
| 2226 | if (startline > 0) |
| 2227 | do_gotoline(startline); |
| 2228 | else |
Chris Allegretta | 234a34d | 2000-07-29 04:33:38 +0000 | [diff] [blame] | 2229 | edit_update(fileage, CENTER); |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2230 | |
Robert Siemborski | 6967eec | 2000-07-08 14:23:32 +0000 | [diff] [blame] | 2231 | edit_refresh(); |
| 2232 | reset_cursor(); |
| 2233 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2234 | while (1) { |
Chris Allegretta | 9239d74 | 2000-09-06 15:19:18 +0000 | [diff] [blame] | 2235 | |
| 2236 | #ifndef _POSIX_VDISABLE |
| 2237 | /* We're going to have to do it the old way, i.e. on cygwin */ |
| 2238 | raw(); |
| 2239 | #endif |
| 2240 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2241 | kbinput = wgetch(edit); |
| 2242 | if (kbinput == 27) { /* Grab Alt-key stuff first */ |
| 2243 | switch (kbinput = wgetch(edit)) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2244 | /* Alt-O, suddenly very important ;) */ |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2245 | case 79: |
| 2246 | kbinput = wgetch(edit); |
| 2247 | if (kbinput <= 'S' && kbinput >= 'P') |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2248 | kbinput = KEY_F(kbinput - 79); |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2249 | #ifdef DEBUG |
| 2250 | else { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2251 | fprintf(stderr, _("I got Alt-O-%c! (%d)\n"), |
| 2252 | kbinput, kbinput); |
| 2253 | break; |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2254 | } |
| 2255 | #endif |
| 2256 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2257 | case 91: |
| 2258 | |
| 2259 | switch (kbinput = wgetch(edit)) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2260 | case '1': /* Alt-[-1-[0-5,7-9] = F1-F8 in X at least */ |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2261 | kbinput = wgetch(edit); |
| 2262 | if (kbinput >= '1' && kbinput <= '5') { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2263 | kbinput = KEY_F(kbinput - 48); |
| 2264 | wgetch(edit); |
| 2265 | } else if (kbinput >= '7' && kbinput <= '9') { |
| 2266 | kbinput = KEY_F(kbinput - 49); |
| 2267 | wgetch(edit); |
| 2268 | } else if (kbinput == 126) |
| 2269 | kbinput = KEY_HOME; |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2270 | |
| 2271 | #ifdef DEBUG |
| 2272 | else { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2273 | fprintf(stderr, _("I got Alt-[-1-%c! (%d)\n"), |
| 2274 | kbinput, kbinput); |
| 2275 | break; |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2276 | } |
| 2277 | #endif |
| 2278 | |
| 2279 | break; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2280 | case '2': /* Alt-[-2-[0,1,3,4] = F9-F12 in many terms */ |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2281 | kbinput = wgetch(edit); |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2282 | switch (kbinput) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2283 | case '0': |
| 2284 | kbinput = KEY_F(9); |
| 2285 | wgetch(edit); |
| 2286 | break; |
| 2287 | case '1': |
| 2288 | kbinput = KEY_F(10); |
| 2289 | wgetch(edit); |
| 2290 | break; |
| 2291 | case '3': |
| 2292 | kbinput = KEY_F(11); |
| 2293 | wgetch(edit); |
| 2294 | break; |
| 2295 | case '4': |
| 2296 | kbinput = KEY_F(12); |
| 2297 | wgetch(edit); |
| 2298 | break; |
| 2299 | case 126: /* Hack, make insert key do something |
| 2300 | usefile, like insert file */ |
| 2301 | do_insertfile(); |
| 2302 | keyhandled = 1; |
| 2303 | break; |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2304 | #ifdef DEBUG |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2305 | default: |
| 2306 | fprintf(stderr, _("I got Alt-[-2-%c! (%d)\n"), |
| 2307 | kbinput, kbinput); |
| 2308 | break; |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2309 | #endif |
| 2310 | |
| 2311 | } |
| 2312 | break; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2313 | case '3': /* Alt-[-3 = Delete? */ |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2314 | kbinput = NANO_DELETE_KEY; |
| 2315 | wgetch(edit); |
| 2316 | break; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2317 | case '4': /* Alt-[-4 = End? */ |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2318 | kbinput = NANO_END_KEY; |
| 2319 | wgetch(edit); |
| 2320 | break; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2321 | case '5': /* Alt-[-5 = Page Up */ |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2322 | kbinput = KEY_PPAGE; |
| 2323 | wgetch(edit); |
| 2324 | break; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2325 | case '6': /* Alt-[-6 = Page Down */ |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2326 | kbinput = KEY_NPAGE; |
| 2327 | wgetch(edit); |
| 2328 | break; |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2329 | case '[': /* Alt-[-[-[A-E], F1-F5 in linux console */ |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2330 | kbinput = wgetch(edit); |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2331 | if (kbinput >= 'A' && kbinput <= 'E') |
| 2332 | kbinput = KEY_F(kbinput - 64); |
Chris Allegretta | 16e4168 | 2000-09-11 22:33:54 +0000 | [diff] [blame] | 2333 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2334 | case 'A': |
| 2335 | kbinput = KEY_UP; |
| 2336 | break; |
| 2337 | case 'B': |
| 2338 | kbinput = KEY_DOWN; |
| 2339 | break; |
| 2340 | case 'C': |
| 2341 | kbinput = KEY_RIGHT; |
| 2342 | break; |
| 2343 | case 'D': |
| 2344 | kbinput = KEY_LEFT; |
| 2345 | break; |
| 2346 | case 'H': |
| 2347 | kbinput = KEY_HOME; |
| 2348 | break; |
| 2349 | case 'F': |
| 2350 | kbinput = KEY_END; |
| 2351 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2352 | default: |
| 2353 | #ifdef DEBUG |
| 2354 | fprintf(stderr, _("I got Alt-[-%c! (%d)\n"), |
| 2355 | kbinput, kbinput); |
| 2356 | #endif |
| 2357 | break; |
| 2358 | } |
| 2359 | break; |
| 2360 | default: |
| 2361 | |
| 2362 | /* Check for the altkey defs.... */ |
| 2363 | for (i = 0; i <= MAIN_LIST_LEN - 1; i++) |
| 2364 | if (kbinput == main_list[i].altval || |
| 2365 | kbinput == main_list[i].altval - 32) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2366 | kbinput = main_list[i].val; |
| 2367 | break; |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2368 | } |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 2369 | #ifndef NANO_SMALL |
| 2370 | /* And for toggle switches */ |
| 2371 | for (i = 0; i <= TOGGLE_LEN - 1 && !keyhandled; i++) |
| 2372 | if (kbinput == toggles[i].val || |
| 2373 | kbinput == toggles[i].val - 32) { |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2374 | do_toggle(i); |
| 2375 | keyhandled = 1; |
| 2376 | break; |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 2377 | } |
| 2378 | #endif |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2379 | #ifdef DEBUG |
| 2380 | fprintf(stderr, _("I got Alt-%c! (%d)\n"), kbinput, |
| 2381 | kbinput); |
| 2382 | #endif |
| 2383 | break; |
| 2384 | } |
| 2385 | } |
| 2386 | /* Look through the main shortcut list to see if we've hit a |
| 2387 | shortcut key */ |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 2388 | for (i = 0; i < MAIN_LIST_LEN && !keyhandled; i++) { |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2389 | if (kbinput == main_list[i].val || |
| 2390 | (main_list[i].misc1 && kbinput == main_list[i].misc1) || |
| 2391 | (main_list[i].misc2 && kbinput == main_list[i].misc2)) { |
| 2392 | if (ISSET(VIEW_MODE) && !main_list[i].viewok) |
| 2393 | print_view_warning(); |
| 2394 | else |
| 2395 | main_list[i].func(); |
| 2396 | keyhandled = 1; |
| 2397 | } |
| 2398 | } |
Chris Allegretta | 9239d74 | 2000-09-06 15:19:18 +0000 | [diff] [blame] | 2399 | #ifndef _POSIX_VDISABLE |
| 2400 | /* Since we're in raw mode, we have to catch ^Q and ^S */ |
| 2401 | if (kbinput == 17 || kbinput == 19) |
| 2402 | keyhandled = 1; |
| 2403 | |
| 2404 | /* And catch ^Z by hand when triggered */ |
| 2405 | if (kbinput == 26) { |
| 2406 | if (ISSET(SUSPEND)) |
| 2407 | do_suspend(0); |
| 2408 | keyhandled = 1; |
| 2409 | } |
| 2410 | #endif |
| 2411 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2412 | /* Last gasp, stuff that's not in the main lists */ |
| 2413 | if (!keyhandled) |
| 2414 | switch (kbinput) { |
| 2415 | #ifndef NANO_SMALL |
| 2416 | #ifdef NCURSES_MOUSE_VERSION |
| 2417 | case KEY_MOUSE: |
| 2418 | do_mouse(); |
| 2419 | break; |
| 2420 | #endif |
| 2421 | #endif |
| 2422 | case 0: /* Erg */ |
| 2423 | do_next_word(); |
| 2424 | break; |
| 2425 | case 331: /* Stuff that we don't want to do squat */ |
| 2426 | case -1: |
| 2427 | case 410: /* Must ignore this, it gets sent when we resize */ |
Chris Allegretta | ad1dacc | 2000-09-21 04:25:45 +0000 | [diff] [blame] | 2428 | #ifdef PDCURSES |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2429 | case 541: /* ???? */ |
| 2430 | case 542: /* Control and alt in Windows *shrug* */ |
Chris Allegretta | 7262358 | 2000-11-29 23:43:28 +0000 | [diff] [blame] | 2431 | case 543: /* Right ctrl key */ |
Chris Allegretta | ad1dacc | 2000-09-21 04:25:45 +0000 | [diff] [blame] | 2432 | case 544: |
Chris Allegretta | 7262358 | 2000-11-29 23:43:28 +0000 | [diff] [blame] | 2433 | case 545: /* Right alt key */ |
Chris Allegretta | ad1dacc | 2000-09-21 04:25:45 +0000 | [diff] [blame] | 2434 | #endif |
Chris Allegretta | bd9e7c3 | 2000-10-26 01:44:42 +0000 | [diff] [blame] | 2435 | |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2436 | break; |
| 2437 | default: |
| 2438 | #ifdef DEBUG |
| 2439 | fprintf(stderr, "I got %c (%d)!\n", kbinput, kbinput); |
| 2440 | #endif |
| 2441 | /* We no longer stop unhandled sequences so that people with |
| 2442 | odd character sets can type... */ |
| 2443 | |
| 2444 | if (ISSET(VIEW_MODE)) { |
| 2445 | print_view_warning(); |
| 2446 | break; |
| 2447 | } |
| 2448 | do_char(kbinput); |
| 2449 | } |
Chris Allegretta | 756f220 | 2000-09-01 13:32:47 +0000 | [diff] [blame] | 2450 | if (ISSET(CONSTUPDATE)) { |
| 2451 | if (ISSET(DISABLE_CURPOS)) |
| 2452 | UNSET(DISABLE_CURPOS); |
| 2453 | else |
| 2454 | do_cursorpos(); |
| 2455 | } |
Chris Allegretta | a2ea193 | 2000-06-06 05:53:49 +0000 | [diff] [blame] | 2456 | |
| 2457 | reset_cursor(); |
| 2458 | wrefresh(edit); |
| 2459 | keyhandled = 0; |
| 2460 | } |
| 2461 | |
| 2462 | getchar(); |
| 2463 | finish(0); |
| 2464 | |
| 2465 | } |