diff -u nano/files.c nano-cursorpos/files.c --- nano/files.c Sun Jan 26 15:44:25 2003 +++ nano-cursorpos/files.c Sun Jan 26 15:44:08 2003 @@ -840,13 +840,6 @@ clearok(topwin, FALSE); titlebar(NULL); - /* if we're constantly displaying the cursor position and - DISABLE_CURPOS isn't set, update it (and do so unconditionally, - in the rare case that the character count is the same but the - line count isn't) */ - if (ISSET(CONSTUPDATE) && !ISSET(DISABLE_CURPOS)) - do_cursorpos(0); - /* now we're done */ return 0; } diff -u nano/nano.c nano-cursorpos/nano.c --- nano/nano.c Sun Jan 26 15:44:25 2003 +++ nano-cursorpos/nano.c Sun Jan 26 15:51:24 2003 @@ -3452,6 +3452,9 @@ int keyhandled = 0; /* Have we handled the keystroke yet? */ int kbinput; /* Input from keyboard */ + if (ISSET(CONSTUPDATE)) + do_cursorpos(1); + #if !defined(DISABLE_BROWSER) || !defined(DISABLE_HELP) || (!defined(DISABLE_MOUSE) && defined(NCURSES_MOUSE_VERSION)) currshortcut = main_list; #endif @@ -3752,11 +3755,6 @@ do_char(kbinput); } - if (ISSET(DISABLE_CURPOS)) - UNSET(DISABLE_CURPOS); - else if (ISSET(CONSTUPDATE)) - do_cursorpos(1); - reset_cursor(); wrefresh(edit); } diff -u nano/search.c nano-cursorpos/search.c --- nano/search.c Sun Jan 26 15:44:25 2003 +++ nano-cursorpos/search.c Sun Jan 26 15:44:10 2003 @@ -270,10 +270,8 @@ return NULL; fileptr = fileage; search_offscreen = 1; - if (!quiet) { + if (!quiet) statusbar(_("Search Wrapped")); - SET(DISABLE_CURPOS); - } } /* Original start line reached */ @@ -324,10 +322,8 @@ return NULL; fileptr = filebot; search_offscreen = 1; - if (!quiet) { + if (!quiet) statusbar(_("Search Wrapped")); - SET(DISABLE_CURPOS); - } } /* Original start line reached */ if (fileptr == begin) diff -u nano/winio.c nano-cursorpos/winio.c --- nano/winio.c Sun Jan 26 15:44:25 2003 +++ nano-cursorpos/winio.c Sun Jan 26 15:44:10 2003 @@ -1411,67 +1411,66 @@ wrefresh(bottomwin); - if (ISSET(CONSTUPDATE)) - statblank = 1; - else - statblank = 25; + SET(DISABLE_CURPOS); + statblank = 26; } +/* + * If constant is false, the user typed ^C so we unconditionally display + * the cursor position. Otherwise, we display it only if the character + * position changed, and DISABLE_CURPOS is not set. + * + * If constant and DISABLE_CURPOS is set, we unset it and update old_i and + * old_totsize. That way, we leave the current statusbar alone, but next + * time we will display. */ int do_cursorpos(int constant) { - filestruct *fileptr; - float linepct = 0.0, bytepct = 0.0, colpct = 0.0; - long i = 0, j = 0; - static long old_i = -1, old_totsize = -1; + const filestruct *fileptr; + unsigned long i = 0; + static unsigned long old_i = 0; + static long old_totsize = -1; - if (current == NULL || fileage == NULL) - return 0; - - if (old_i == -1) - old_i = i; + assert(current != NULL && fileage != NULL && totlines != 0); if (old_totsize == -1) old_totsize = totsize; - colpct = 100 * (xplustabs() + 1) / (strlenpt(current->data) + 1); - - for (fileptr = fileage; fileptr != current && fileptr != NULL; - fileptr = fileptr->next) + for (fileptr = fileage; fileptr != current; fileptr = fileptr->next) { + assert(fileptr != NULL); i += strlen(fileptr->data) + 1; - - if (fileptr == NULL) - return -1; - + } i += current_x; - j = totsize; - - if (totsize > 0) - bytepct = 100 * i / totsize; - - if (totlines > 0) - linepct = 100 * current->lineno / totlines; - -#ifdef DEBUG - fprintf(stderr, "%s: linepct = %f, bytepct = %f\n", - "do_cursorpos()", linepct, bytepct); -#endif + if (constant && ISSET(DISABLE_CURPOS)) { + UNSET(DISABLE_CURPOS); + old_i = i; + old_totsize = totsize; + return 0; + } - /* if constant is zero, display the position on the statusbar + /* if constant is false, display the position on the statusbar unconditionally; otherwise, only display the position when the character values have changed */ - if (!constant || (old_i != i || old_totsize != totsize)) { - statusbar(_ - ("line %d/%d (%.0f%%), col %ld/%ld (%.0f%%), char %ld/%ld (%.0f%%)"), - current->lineno, totlines, linepct, xplustabs() + 1, - strlenpt(current->data) + 1, colpct, i, j, bytepct); + if (!constant || old_i != i || old_totsize != totsize) { + unsigned long xpt = xplustabs() + 1; + unsigned long cur_len = strlenpt(current->data) + 1; + int linepct = 100 * current->lineno / totlines; + int colpct = 100 * xpt / cur_len; + int bytepct = totsize == 0 ? 0 : 100 * i / totsize; + + statusbar( + _("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%ld (%d%%)"), + current->lineno, totlines, linepct, + xpt, cur_len, colpct, + i, totsize, bytepct); + UNSET(DISABLE_CURPOS); } old_i = i; old_totsize = totsize; reset_cursor(); - return 1; + return 0; } int do_cursorpos_void(void)