From: Chris Allegretta Date: Sat, 11 May 2002 03:04:44 +0000 (+0000) Subject: DLR's latest patch X-Git-Tag: v1.1.9~7 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=4dc03d5733a9437477c76be37ca6dfe858725371;p=nano.git DLR's latest patch git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1204 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 9c85d466..b237ed23 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,11 @@ CVS code - syntaxfile_regexp and synfilematches. Global flag -Y ,--syntax to specify the type on the command line, if there's no good filename regex to use. Global variable syntaxstr. + - Changed many strcmp()s and strcpy()s to their equivalent + '\0' conterparts (David Lawrence Ramsey). + - Many chanes to allow marked cutting to work with multiple + file buffers: changes to openfilestruct type in nano.h and + files.c (David Lawrence Ramsey). - configure.ac: - Define NDEBUG to silence asserts (David Benbennick). - files.c: @@ -47,10 +52,15 @@ CVS code - - nano.spec.in: - Don't put Chris' name as the Packager in the distribution by default (Im an idiot). + - Fixed Source line (David Lawrence Ramsey). - nano.1: - Changed references to Debian GNU/Linux to Debian GNU (Jordi). +- nano.1.html: + - Updated for -Y option (David Lawrence Ramsey). - rcfile.c - Made some rc file errors less fatal. + - Added in my patch for getpwent instead of relying on $HOME + (David Lawrence Ramsey). - winio.c: edit_add() - Changed some syntax hilight computations for the sake of COLS. diff --git a/files.c b/files.c index 9e52548c..341c4c41 100644 --- a/files.c +++ b/files.c @@ -50,15 +50,15 @@ static int fileformat = 0; /* 0 = *nix, 1 = DOS, 2 = Mac */ #endif /* Load file into edit buffer - takes data from file struct */ -void load_file(int quiet) +void load_file(int update) { current = fileage; #ifdef ENABLE_MULTIBUFFER - /* if quiet is zero, add a new entry to the open_files structure; + /* if update is zero, add a new entry to the open_files structure; otherwise, update the current entry (the latter is needed in the case of the alternate spell checker) */ - add_open_file(quiet); + add_open_file(update); #endif #ifdef ENABLE_COLOR @@ -73,7 +73,7 @@ void new_file(void) { fileage = nmalloc(sizeof(filestruct)); fileage->data = charalloc(1); - strcpy(fileage->data, ""); + fileage->data[0] = '\0'; fileage->prev = NULL; fileage->next = NULL; fileage->lineno = 1; @@ -88,7 +88,7 @@ void new_file(void) /* if there aren't any entries in open_files, create the entry for this new file; without this, if nano is started without a filename on the command line, a new file will be created, but it will be - given no open_files entry, leading to problems later on */ + given no open_files entry */ if (!open_files) { add_open_file(0); /* turn off view mode in this case; this is for consistency @@ -108,7 +108,7 @@ void new_file(void) } -filestruct *read_line(char *buf, filestruct * prev, int *line1ins) +filestruct *read_line(char *buf, filestruct *prev, int *line1ins) { filestruct *fileptr; @@ -156,10 +156,10 @@ filestruct *read_line(char *buf, filestruct * prev, int *line1ins) return fileptr; } -int read_file(FILE *f, char *filename, int quiet) +int read_file(FILE *f, const char *filename, int quiet) { int num_lines = 0; - char input; /* current input character */ + signed char input; /* current input character */ char *buf; long i = 0, bufx = 128; filestruct *fileptr = current, *tmp = NULL; @@ -260,7 +260,9 @@ int read_file(FILE *f, char *filename, int quiet) new_magicline(); totsize--; - /* Update the edit buffer */ + /* Update the edit buffer; note that if using multibuffers, a + quiet load will update the current open_files entry, while a + noisy load will add a new open_files entry */ load_file(quiet); } @@ -281,15 +283,14 @@ int read_file(FILE *f, char *filename, int quiet) return 1; } - /* Open the file (and decide if it exists) */ -int open_file(char *filename, int insert, int quiet) +int open_file(const char *filename, int insert, int quiet) { int fd; FILE *f; struct stat fileinfo; - if (!strcmp(filename, "") || stat(filename, &fileinfo) == -1) { + if (filename[0] == '\0' || stat(filename, &fileinfo) == -1) { if (insert && !quiet) { statusbar(_("\"%s\" not found"), filename); return -1; @@ -313,7 +314,6 @@ int open_file(char *filename, int insert, int quiet) /* Don't open character or block files. Sorry, /dev/sndstat! */ statusbar(_("File \"%s\" is a device file"), filename); - if (!insert) new_file(); return -1; @@ -331,7 +331,6 @@ int open_file(char *filename, int insert, int quiet) return 1; } - /* This function will return the name of the first available extension of a filename (starting with the filename, then filename.1, etc). Memory is allocated for the return value. If no writable extension @@ -365,7 +364,7 @@ char *get_next_filename(const char *name) int do_insertfile(int loading_file) { - int i; + int i, old_current_x = current_x; char *realname = NULL; wrap_reset(); @@ -428,7 +427,7 @@ int do_insertfile(int loading_file) if (i == NANO_EXTCMD_KEY) { int ts; ts = statusq(1, extcmd_list, "", _("Command to execute ")); - if (ts == -1 || answer == NULL || !strcmp(answer,"")) { + if (ts == -1 || answer == NULL || answer[0] == '\0') { statusbar(_("Cancelled")); UNSET(KEEP_CUTBUFFER); display_main_list(); @@ -445,6 +444,9 @@ int do_insertfile(int loading_file) new_file(); UNSET(MODIFIED); +#ifndef NANO_SMALL + UNSET(MARK_ISSET); +#endif } #endif @@ -489,6 +491,17 @@ int do_insertfile(int loading_file) } #endif +#ifdef ENABLE_MULTIBUFFER + if (!loading_file) { +#endif + + /* Restore the old x-coordinate position */ + current_x = old_current_x; + +#ifdef ENABLE_MULTIBUFFER + } +#endif + /* If we've gone off the bottom, recenter; otherwise, just redraw */ if (current->lineno > editbot->lineno) edit_update(current, CENTER); @@ -582,19 +595,29 @@ int add_open_file(int update) /* save current line number */ open_files->file_lineno = current->lineno; + /* if we're updating, save current modification status (and marking + status, if available) */ + if (update) { +#ifndef NANO_SMALL + open_files->file_flags = (MODIFIED & ISSET(MODIFIED)) | (MARK_ISSET & ISSET(MARK_ISSET)); + if (ISSET(MARK_ISSET)) { + open_files->file_mark_beginbuf = mark_beginbuf; + open_files->file_mark_beginx = mark_beginx; + } +#else + open_files->file_flags = (MODIFIED & ISSET(MODIFIED)); +#endif + } + /* if we're in view mode and updating, the file contents won't have changed, so we won't bother resaving the filestruct then; otherwise, we will */ if (!(ISSET(VIEW_MODE) && !update)) { - /* save current filestruct and restore full file position - afterward */ - open_files->fileage = fileage; - do_gotopos(open_files->file_lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant); + /* save current file buffer */ + open_files->fileage = fileage; + open_files->filebot = filebot; } - /* save current modification status */ - open_files->file_modified = ISSET(MODIFIED); - #ifdef DEBUG fprintf(stderr, _("filename is %s"), open_files->filename); #endif @@ -602,21 +625,6 @@ int add_open_file(int update) return 0; } -/* - * Update only the filename stored in the current entry. Return 0 on - * success or 1 on error. - */ -int open_file_change_name(void) -{ - if (!open_files || !filename) - return 1; - - /* save current filename */ - open_files->filename = mallocstrcpy(open_files->filename, filename); - - return 0; -} - /* * Read the current entry in the open_files structure and set up the * currently open file using that entry's information. Return 0 on @@ -624,7 +632,6 @@ int open_file_change_name(void) */ int load_open_file(void) { - if (!open_files) return 1; @@ -633,27 +640,31 @@ int load_open_file(void) filename = mallocstrcpy(filename, open_files->filename); fileage = open_files->fileage; current = fileage; + filebot = open_files->filebot; totlines = open_files->file_totlines; totsize = open_files->file_totsize; - /* Unset the marker because nano can't (yet) handle marked text - flipping between open files */ - UNSET(MARK_ISSET); + /* restore modification status */ + if (open_files->file_flags & MODIFIED) + SET(MODIFIED); + else + UNSET(MODIFIED); + +#ifndef NANO_SMALL + /* restore marking status */ + if (open_files->file_flags & MARK_ISSET) { + mark_beginbuf = open_files->file_mark_beginbuf; + mark_beginx = open_files->file_mark_beginx; + SET(MARK_ISSET); + } else + UNSET(MARK_ISSET); +#endif /* restore full file position: line number, x-coordinate, y- coordinate, place we want */ do_gotopos(open_files->file_lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant); - /* restore the bottom of the file */ - filebot = current; - while (filebot->next) - filebot = filebot->next; - - /* set up modification status and update the titlebar */ - if (open_files->file_modified) - SET(MODIFIED); - else - UNSET(MODIFIED); + /* update the titlebar */ clearok(topwin, FALSE); titlebar(NULL); @@ -811,7 +822,11 @@ int close_open_file(void) if (!open_files) return 1; + /* make sure open_files->fileage and fileage, and open_files->filebot + and filebot, are in sync; they might not be if lines have been cut + from the top or bottom of the file */ open_files->fileage = fileage; + open_files->filebot = filebot; tmp = open_files; if (open_nextfile(1)) { @@ -1203,7 +1218,7 @@ int write_file(char *name, int tmp, int append, int nonamechange) struct stat st, lst; char *realname = NULL; - if (!strcmp(name, "")) { + if (name[0] == '\0') { statusbar(_("Cancelled")); return -1; } @@ -1224,8 +1239,9 @@ int write_file(char *name, int tmp, int append, int nonamechange) #ifndef DISABLE_OPERATINGDIR if (!tmp && operating_dir) { - /* if we're writing a temporary file, we're going outside the - operating directory, so skip the operating directory test */ + /* if we're writing a temporary file, we're probably going + outside the operating directory, so skip the operating + directory test */ if (check_operating_dir(realname, 0)) { statusbar(_("Can't write outside of %s"), operating_dir); @@ -1634,21 +1650,8 @@ int do_writeout(char *path, int exiting, int append) #ifdef ENABLE_MULTIBUFFER /* if we're not about to exit, update the current entry in the open_files structure */ - if (!exiting) { - - /* first, if the filename was changed during the save, - update the filename stored in the current entry, and - then update the current entry */ - if (strcmp(open_files->filename, filename)) { - open_file_change_name(); - add_open_file(1); - } - else { - - /* otherwise, just update the current entry */ - add_open_file(1); - } - } + if (!exiting) + add_open_file(1); #endif display_main_list(); @@ -1825,7 +1828,7 @@ char **cwd_tab_completion(char *buf, int *num_matches) strcat(buf, "*"); /* Okie, if there's a / in the buffer, strip out the directory part */ - if (strcmp(buf, "") && strstr(buf, "/")) { + if (buf[0] != '\0' && strstr(buf, "/")) { dirName = charalloc(strlen(buf) + 1); tmp = buf + strlen(buf); while (*tmp != '/' && tmp != buf) @@ -1988,7 +1991,7 @@ char *input_tab(char *buf, int place, int *lastWasTab, int *newplace, int *list) buf = nrealloc(buf, strlen(buf) + strlen(matches[0]) + 1); - if (strcmp(buf, "") && strstr(buf, "/")) { + if (buf[0] != '\0' && strstr(buf, "/")) { for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; tmp--); tmp++; @@ -2025,7 +2028,7 @@ char *input_tab(char *buf, int place, int *lastWasTab, int *newplace, int *list) /* Check to see if all matches share a beginning, and, if so, tack it onto buf and then beep */ - if (strcmp(buf, "") && strstr(buf, "/")) { + if (buf[0] != '\0' && strstr(buf, "/")) { for (tmp = buf + strlen(buf); *tmp != '/' && tmp != buf; tmp--); tmp++; @@ -2624,7 +2627,7 @@ char *do_browser(char *inpath) } while ((kbinput = wgetch(edit)) != NANO_EXIT_KEY); curs_set(1); blank_edit(); - titlebar(NULL); + titlebar(NULL); edit_refresh(); kb = keypad_on(edit, kb); diff --git a/move.c b/move.c index b16f3421..ba100ba6 100644 --- a/move.c +++ b/move.c @@ -113,12 +113,8 @@ int do_down(void) wrap_reset(); if (current->next != NULL) { update_line(current->prev, 0); - if (placewewant > 0) current_x = actual_x(current->next, placewewant); - - if (current_x > strlen(current->next->data)) - current_x = strlen(current->next->data); } else { UNSET(KEEP_CUTBUFFER); check_statblank(); @@ -193,9 +189,6 @@ int do_up(void) if (current->prev != NULL) { if (placewewant > 0) current_x = actual_x(current->prev, placewewant); - - if (current_x > strlen(current->prev->data)) - current_x = strlen(current->prev->data); } if (current_y > 0) current_y--; diff --git a/nano.1 b/nano.1 index b9f361d9..618fc38a 100644 --- a/nano.1 +++ b/nano.1 @@ -130,9 +130,11 @@ Nano will try to dump the buffer into an emergency file in some cases. Mainly, this will happen if Nano receives a SIGHUP or runs out of memory, when it will write the buffer into a file named "nano.save" if the buffer didn't have a name already, or will add a ".save" suffix to the -current filename. In multibuffer mode, nano will write all the open buffers to -the respective emergency files. Nano will \fBnot\fP write this file if a -previous one exists in the current directory. +current filename. If an emergency file with that name already exists in +the current directory, ".save" and a number (e.g. ".save.1") will be +suffixed to the current filename in order to make it unique. In +multibuffer mode, nano will write all the open buffers to the respective +emergency files. .SH BUGS Please send any comments or bug reports to .br diff --git a/nano.1.html b/nano.1.html index 654654fe..0cf2be41 100644 --- a/nano.1.html +++ b/nano.1.html @@ -88,6 +88,10 @@ Set the size (width) of a tab.
Show the current version number and author. +
-Y (--syntax=[str]) + +
+Specify a specific syntax hilighting from the .nanorc to use (if available).
-c (--const)
@@ -171,9 +175,11 @@ Nano will try to dump the buffer into an emergency file in some cases. Mainly, this will happen if Nano receives a SIGHUP or runs out of memory, when it will write the buffer into a file named "nano.save" if the buffer didn't have a name already, or will add a ".save" suffix to the -current filename. In multibuffer mode, nano will write all the open buffers to -the respective emergency files. Nano will not write this file if a -previous one exists in the current directory. +current filename. If an emergency file with that name already exists in +the current directory, ".save" and a number (e.g. ".save.1") will be +suffixed to the current filename in order to make it unique. In +multibuffer mode, nano will write all the open buffers to the respective +emergency files.  

BUGS

@@ -201,7 +207,7 @@ subject of "subscribe". Chris Allegretta <chrisa@asty.org>, et al (see AUTHORS and THANKS for details). This manual page was originally written by Jordi Mallach -<jordi@sindominio.net>, for the Debian GNU/Linux system (but may be +<jordi@sindominio.net>, for the Debian GNU system (but may be used by others).

@@ -221,6 +227,6 @@ used by others). This document was created by man2html, using the manual pages.
-Time: 12:14:20 GMT, March 04, 2002 +Time: 19:17:30 GMT, May 08, 2002 diff --git a/nano.c b/nano.c index 73bf5f60..1dc3639b 100644 --- a/nano.c +++ b/nano.c @@ -143,9 +143,14 @@ void die(char *msg, ...) /* if we already saved the file above (i. e. if it was the currently loaded file), don't save it again */ if (tmp != open_files) { + /* make sure open_files->fileage and fileage, and + open_files->filebot and filebot, are in sync; they + might not be if lines have been cut from the top or + bottom of the file */ fileage = open_files->fileage; + filebot = open_files->filebot; /* save the file if it's been modified */ - if (open_files->file_modified) + if (open_files->file_flags & MODIFIED) die_save_file(open_files->filename); } @@ -168,7 +173,7 @@ void die_save_file(char *die_filename) if (die_filename[0] == '\0') { name = "nano.save"; ret = get_next_filename(name); - if (strcmp(ret, "")) + if (ret[0] != '\0') i = write_file(ret, 1, 0, 0); name = ret; } @@ -177,7 +182,7 @@ void die_save_file(char *die_filename) strcpy(buf, die_filename); strcat(buf, ".save"); ret = get_next_filename(buf); - if (strcmp(ret, "")) + if (ret[0] != '\0') i = write_file(ret, 1, 0, 0); name = ret; free(buf); @@ -637,6 +642,7 @@ openfilestruct *make_new_opennode(openfilestruct * prevnode) newnode = nmalloc(sizeof(openfilestruct)); newnode->filename = NULL; newnode->fileage = NULL; + newnode->filebot = NULL; newnode->prev = prevnode; newnode->next = NULL; @@ -1267,7 +1273,7 @@ int do_backspace(void) line we're on now is NOT blank. if it is blank we can just use IT for the magic line. This is how Pico appears to do it, in any case */ - if (strcmp(current->data, "")) { + if (current->data[0] != '\0') { new_magicline(); fix_editbot(); } @@ -1297,7 +1303,7 @@ int do_delete(void) /* blbf -> blank line before filebot (see below) */ int blbf = 0; - if (current->next == filebot && !strcmp(current->data, "")) + if (current->next == filebot && current->data[0] == '\0') blbf = 1; if (current_x != strlen(current->data)) { @@ -1329,7 +1335,7 @@ int do_delete(void) /* Please see the comment in do_backspace if you don't understand this test */ - if (current == filebot && strcmp(current->data, "")) { + if (current == filebot && current->data[0] != '\0') { new_magicline(); fix_editbot(); totsize++; @@ -1407,7 +1413,7 @@ int do_int_spell_fix(char *word) search_last_line = FALSE; - if (strcmp(prevanswer,answer) != 0) { + if (strcmp(prevanswer, answer)) { j = i; do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j); } @@ -1475,7 +1481,6 @@ int do_int_speller(char *tempfile_name) } close(tempfile_fd); - /* send spell's standard out to the pipe */ if (dup2(in_fd[1], STDOUT_FILENO) != STDOUT_FILENO) { @@ -1662,8 +1667,7 @@ int do_spell(void) #ifdef ENABLE_MULTIBUFFER /* update the current open_files entry before spell-checking, in case - any problems occur; the case of there being no open_files entries - is handled elsewhere (before we reach this point) */ + any problems occur */ add_open_file(1); #endif @@ -3098,8 +3102,6 @@ int main(int argc, char *argv[]) fprintf(stderr, _("Main: open file\n")); #endif - titlebar(NULL); - /* Now we check to see if argv[optind] is non-null to determine if we're dealing with a new file or not, not argc == 1... */ if (argv[optind] == NULL) @@ -3107,6 +3109,8 @@ int main(int argc, char *argv[]) else open_file(filename, 0, 0); + titlebar(NULL); + if (startline > 0) do_gotoline(startline, 0); else diff --git a/nano.h b/nano.h index 799729c9..98513312 100644 --- a/nano.h +++ b/nano.h @@ -82,9 +82,18 @@ typedef struct openfilestruct { struct openfilestruct *next; /* Next node */ struct openfilestruct *prev; /* Previous node */ struct filestruct *fileage; /* Current file */ + struct filestruct *filebot; /* Current file's last line */ +#ifndef NANO_SMALL + struct filestruct *file_mark_beginbuf; + /* Current file's beginning marked line */ + int file_mark_beginx; /* Current file's beginning marked line's + x-coordinate position */ +#endif int file_current_x; /* Current file's x-coordinate position */ int file_current_y; /* Current file's y-coordinate position */ - int file_modified; /* Current file's modification status */ + int file_flags; /* Current file's flags: modification + status (and marking status, if + available) */ int file_placewewant; /* Current file's place we want */ int file_totlines; /* Current file's total number of lines */ long file_totsize; /* Current file's total size */ diff --git a/nano.spec.in b/nano.spec.in index e2cea61c..b9d04316 100644 --- a/nano.spec.in +++ b/nano.spec.in @@ -9,7 +9,7 @@ Release : %{rel} Copyright : GPL Group : Console/Editors URL : http://www.nano-editor.org -Source : http://www.nano-editor.org/dist/v1.1/%{name}/%{name}-%{ver}.tar.gz +Source : http://www.nano-editor.org/dist/v1.1/%{name}-%{ver}.tar.gz BuildRoot : /var/tmp/%{name}-buildroot Requires : ncurses diff --git a/proto.h b/proto.h index 56a8f342..9b81de6a 100644 --- a/proto.h +++ b/proto.h @@ -132,11 +132,11 @@ int do_cut_text(void); int do_uncut_text(void); int no_help(void); int renumber_all(void); -int open_file(char *filename, int insert, int quiet); +int open_file(const char *filename, int insert, int quiet); int do_insertfile(int loading_file); int num_of_digits(int n); int open_pipe(char *command); -int read_file(FILE *f, char *filename, int quiet); +int read_file(FILE *f, const char *filename, int quiet); #ifdef ENABLE_MULTIBUFFER int add_open_file(int update); diff --git a/rcfile.c b/rcfile.c index 243cad2b..765e5d16 100644 --- a/rcfile.c +++ b/rcfile.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -546,9 +548,7 @@ void do_rcfile(void) char *unable = _("Unable to open ~/.nanorc file, %s"); struct stat fileinfo; FILE *rcstream; - - if (getenv("HOME") == NULL) - return; + struct passwd *userage; nanorc = charalloc(strlen(SYSCONFDIR) + 10); sprintf(nanorc, "%s/nanorc", SYSCONFDIR); @@ -562,10 +562,21 @@ void do_rcfile(void) fclose(rcstream); } - nanorc = charalloc(strlen(getenv("HOME")) + 10); - sprintf(nanorc, "%s/.nanorc", getenv("HOME")); - lineno = 0; + + /* Determine home directory using getpwent(), don't rely on $HOME */ + for (userage = getpwent(); userage != NULL + && userage->pw_uid != geteuid(); userage = getpwent()) + ; + + if (userage == NULL) { + rcfile_error(_("I can't find my home directory! Wah!")); + return; + } + + nanorc = charalloc(strlen(userage->pw_dir) + 10); + sprintf(nanorc, "%s/.nanorc", userage->pw_dir); + if (stat(nanorc, &fileinfo) == -1) { /* Abort if the file doesn't exist and there's some other kind diff --git a/search.c b/search.c index fdb025d4..851fd244 100644 --- a/search.c +++ b/search.c @@ -56,11 +56,11 @@ void search_init_globals(void) { if (last_search == NULL) { last_search = charalloc(1); - last_search[0] = 0; + last_search[0] = '\0'; } if (last_replace == NULL) { last_replace = charalloc(1); - last_replace[0] = 0; + last_replace[0] = '\0'; } } @@ -82,7 +82,7 @@ int search_init(int replacing) search_init_globals(); buf = charalloc(strlen(last_search) + 5); - buf[0] = 0; + buf[0] = '\0'; /* Clear the backupstring if we've changed from Pico mode to regular @@ -123,7 +123,7 @@ int search_init(int replacing) } } else - strcpy(buf, ""); + buf[0] = '\0'; /* This is now one simple call. It just does a lot */ i = statusq(0, replacing ? replace_list : whereis_list, backupstring, @@ -247,10 +247,9 @@ int past_editbuff; /* findnextstr() is now searching lines not displayed */ filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beginx, char *needle) { - filestruct *fileptr; + filestruct *fileptr = current; char *searchstr, *rev_start = NULL, *found = NULL; int current_x_find = 0; - fileptr = current; past_editbuff = 0; @@ -278,6 +277,7 @@ filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beg return NULL; } + update_line(fileptr, 0); fileptr = fileptr->next; if (fileptr == editbot) @@ -286,12 +286,12 @@ filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beg /* EOF reached ?, wrap around once */ if (fileptr == NULL) { if (bracket_mode) /* don't wrap if looking for bracket match */ - return NULL; + return NULL; fileptr = fileage; past_editbuff = 1; if (!quiet) { - statusbar(_("Search Wrapped")); - SET(DISABLE_CURPOS); + statusbar(_("Search Wrapped")); + SET(DISABLE_CURPOS); } } @@ -340,6 +340,7 @@ filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beg return NULL; } + update_line(fileptr, 0); fileptr = fileptr->prev; if (fileptr == edittop->prev) @@ -436,7 +437,7 @@ int do_search(void) } /* The sneaky user deleted the previous search string */ - if (!ISSET(PICO_MODE) && !strcmp(answer, "")) { + if (!ISSET(PICO_MODE) && answer[0] == '\0') { statusbar(_("Search Cancelled")); search_abort(); return 0; @@ -445,7 +446,7 @@ int do_search(void) /* If answer is now == "", then PICO_MODE is set. So, copy last_search into answer... */ - if (!strcmp(answer, "")) + if (answer[0] == '\0') answer = mallocstrcpy(answer, last_search); else last_search = mallocstrcpy(last_search, answer); @@ -604,7 +605,7 @@ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx, switch (*i) { case -1: /* Aborted enter */ - if (strcmp(last_replace, "")) + if (last_replace[0] != '\0') answer = mallocstrcpy(answer, last_replace); statusbar(_("Replace Cancelled")); replace_abort(); @@ -620,7 +621,7 @@ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx, } } - if (ISSET(PICO_MODE) && !strcmp(answer, "")) + if (ISSET(PICO_MODE) && answer[0] == '\0') answer = mallocstrcpy(answer, last_replace); last_replace = mallocstrcpy(last_replace, answer); @@ -739,7 +740,7 @@ int do_replace(void) } /* Again, there was a previous string, but they deleted it and hit enter */ - if (!ISSET(PICO_MODE) && !strcmp(answer, "")) { + if (!ISSET(PICO_MODE) && answer[0] == '\0') { statusbar(_("Replace Cancelled")); replace_abort(); return 0; @@ -747,7 +748,7 @@ int do_replace(void) /* If answer is now == "", then PICO_MODE is set. So, copy last_search into answer (and prevanswer)... */ - if (!strcmp(answer, "")) { + if (answer[0] == '\0') { answer = mallocstrcpy(answer, last_search); prevanswer = mallocstrcpy(prevanswer, last_search); } else { @@ -757,7 +758,7 @@ int do_replace(void) if (ISSET(PICO_MODE)) { buf = charalloc(strlen(last_replace) + 5); - if (strcmp(last_replace, "")) { + if (last_replace[0] != '\0') { if (strlen(last_replace) > (COLS / 3)) { strncpy(buf, last_replace, COLS / 3); sprintf(&buf[COLS / 3 - 1], "..."); @@ -857,7 +858,6 @@ int do_gotoline_void(void) #if (defined ENABLE_MULTIBUFFER || !defined DISABLE_SPELLER) void do_gotopos(int line, int pos_x, int pos_y, int pos_placewewant) { - /* since do_gotoline() resets the x-coordinate but not the y-coordinate, set the coordinates up this way */ current_y = pos_y; @@ -877,7 +877,6 @@ void do_gotopos(int line, int pos_x, int pos_y, int pos_placewewant) #endif #if !defined(NANO_SMALL) && defined(HAVE_REGEX_H) - int do_find_bracket(void) { char ch_under_cursor, wanted_ch; diff --git a/winio.c b/winio.c index 6883d23c..9a9fe83d 100644 --- a/winio.c +++ b/winio.c @@ -91,7 +91,6 @@ int xpt(filestruct * fileptr, int index) return tabs; } - /* Return the actual place on the screen of current->data[current_x], which should always be > current_x */ int xplustabs(void) @@ -99,7 +98,6 @@ int xplustabs(void) return xpt(current, current_x); } - /* Return what current_x should be, given xplustabs() for the line, * given a start position in the filestruct's data */ int actual_x_from_start(filestruct * fileptr, int xplus, int start) @@ -111,19 +109,20 @@ int actual_x_from_start(filestruct * fileptr, int xplus, int start) for (i = start; tot <= xplus && fileptr->data[i] != 0; i++, tot++) if (fileptr->data[i] == NANO_CONTROL_I) { - if (tot % tabsize == 0) - tot++; - else + if (tot % tabsize != 0) tot += tabsize - (tot % tabsize); } else if (fileptr->data[i] & 0x80) tot++; /* Make 8 bit chars only 1 column (again) */ - else if (fileptr->data[i] < 32) + else if (fileptr->data[i] < 32 || fileptr->data[i] == 127) { + i++; tot += 2; + } #ifdef DEBUG fprintf(stderr, _("actual_x_from_start for xplus=%d returned %d\n"), xplus, i); #endif + return i - start; } @@ -151,7 +150,7 @@ int strnlenpt(char *buf, int size) } else if (buf[i] & 0x80) /* Make 8 bit chars only 1 column! */ ; - else if (buf[i] < 32) + else if (buf[i] < 32 || buf[i] == 127) tabs++; } @@ -163,7 +162,6 @@ int strlenpt(char *buf) return strnlenpt(buf, strlen(buf)); } - /* resets current_y, based on the position of current, and puts the cursor at (current_y, current_x) */ void reset_cursor(void) @@ -510,7 +508,7 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut *s, free(inputbuf); /* In pico mode, just check for a blank answer here */ - if (((ISSET(PICO_MODE)) && !strcmp(answer, ""))) + if (ISSET(PICO_MODE) && answer[0] == '\0') return -2; else return 0; @@ -546,7 +544,7 @@ void titlebar(char *path) namelen = strlen(what); - if (!strcmp(what, "")) + if (what[0] == '\0') mvwaddstr(topwin, 0, COLS / 2 - 6, _("New Buffer")); else { if (namelen > space) { @@ -567,7 +565,8 @@ void titlebar(char *path) } if (ISSET(MODIFIED)) mvwaddstr(topwin, 0, COLS - 10, _("Modified")); - + else if (ISSET(VIEW_MODE)) + mvwaddstr(topwin, 0, COLS - 10, _("View")); #ifdef ENABLE_COLOR color_off(topwin, COLOR_TITLEBAR); @@ -1170,7 +1169,7 @@ void update_line(filestruct * fileptr, int index) fileptr->data[pos] = '\0'; - /* Now, Paint the line */ + /* Now, paint the line */ if (current == fileptr && index > COLS - 2) { /* This handles when the current line is beyond COLS */ /* It requires figuring out what page we're on */