warnings or errors. Changes to cancel_fork(),
handle_hipterm(), do_suspend(), and do_cont(). (David
Benbennick)
+ - Change flags to an unsigned long, and totsize to a size_t.
+ (DLR)
+ - Store the number of multibyte characters instead of the number
+ of single-byte characters in totsize, and use get_totals() to
+ get the value of totsize in a few more places. Changes to
+ read_line(), read_file(), do_delete(), do_input(),
+ get_totals(), and do_cursorpos(). (DLR)
- cut.c:
do_cut_text()
- If keep_cutbuffer is FALSE, only blow away the text in the
#ifndef NANO_SMALL
/* If it's a DOS file (CR LF), and file conversion isn't disabled,
* strip out the CR part. */
- if (!ISSET(NO_CONVERT) && len > 0 && buf[len - 1] == '\r') {
+ if (!ISSET(NO_CONVERT) && len > 0 && buf[len - 1] == '\r')
fileptr->data[len - 1] = '\0';
- totsize--;
- }
#endif
if (*first_line_ins || fileage == NULL) {
{
size_t num_lines = 0;
/* The number of lines in the file. */
+ size_t num_chars = 0;
+ /* The number of bytes in the file. */
size_t len = 0;
/* The length of the current line of the file. */
size_t i = 0;
len = 1;
num_lines++;
- totsize++;
buf[0] = input;
buf[1] = '\0';
i = 1;
bufx += 128;
buf = charealloc(buf, bufx);
}
+
buf[i] = input;
buf[i + 1] = '\0';
i++;
}
- totsize++;
}
/* This conditional duplicates previous read_byte() behavior.
/* If file conversion isn't disabled and the last character in this
* file is a CR, read it in properly as a Mac format line. */
if (len == 0 && !ISSET(NO_CONVERT) && input == '\r') {
+ len = 1;
+
buf[0] = input;
buf[1] = '\0';
- len = 1;
}
#endif
/* Read in the last line properly. */
fileptr = read_line(buf, fileptr, &first_line_ins, len);
num_lines++;
- totsize++;
}
+
free(buf);
/* If we didn't get a file and we don't already have one, make a new
* file. */
- if (totsize == 0 || fileptr == NULL)
+ if (fileptr == NULL)
new_file();
/* Did we try to insert a file of 0 bytes? */
} else if (fileptr->next == NULL) {
filebot = fileptr;
new_magicline();
- totsize--;
}
}
+ get_totals(fileage, filebot, NULL, &num_chars);
+ totsize += num_chars;
+
#ifndef NANO_SMALL
if (format == 3)
statusbar(
} else
#endif
statusbar(P_("Read %lu line", "Read %lu lines",
- (unsigned long)num_lines),(unsigned long)num_lines);
+ (unsigned long)num_lines), (unsigned long)num_lines);
totlines += num_lines;
}
struct stat fileinfo;
assert(f != NULL);
+
if (filename == NULL || filename[0] == '\0' ||
stat(filename, &fileinfo) == -1) {
if (newfie) {
openfilestruct *end)
{
assert(newnode != NULL && begin != NULL);
+
newnode->next = end;
newnode->prev = begin;
begin->next = newnode;
void unlink_opennode(openfilestruct *fileptr)
{
assert(fileptr != NULL && fileptr->prev != NULL && fileptr->next != NULL && fileptr != fileptr->prev && fileptr != fileptr->next);
+
fileptr->prev->next = fileptr->next;
fileptr->next->prev = fileptr->prev;
delete_opennode(fileptr);
void delete_opennode(openfilestruct *fileptr)
{
assert(fileptr != NULL && fileptr->filename != NULL && fileptr->fileage != NULL);
+
free(fileptr->filename);
free_filestruct(fileptr->fileage);
free(fileptr);
void free_openfilestruct(openfilestruct *src)
{
assert(src != NULL);
+
while (src != src->next) {
src = src->next;
delete_opennode(src->prev);
char *last_replace = NULL; /* Last replacement string */
int search_last_line; /* Is this the last search line? */
-long flags = 0; /* Our flag containing many options */
+unsigned long flags = 0; /* Our flag containing many options */
WINDOW *topwin; /* Top buffer */
WINDOW *edit; /* The file portion of the editor */
WINDOW *bottomwin; /* Bottom buffer */
char *answer = NULL; /* Answer str to many questions */
int totlines = 0; /* Total number of lines in the file */
-long totsize = 0; /* Total number of bytes in the file */
+size_t totsize = 0; /* Total number of characters in the
+ file */
size_t placewewant = 0; /* The column we'd like the cursor
to jump to when we go to the
next or previous line */
filestruct *top, size_t top_x, filestruct *bot, size_t bot_x)
{
filestruct *top_save;
- long part_totsize;
+ size_t part_totsize;
bool at_edittop;
#ifndef NANO_SMALL
bool mark_inside = FALSE;
{
filestruct *top_save;
int part_totlines;
- long part_totsize;
+ size_t part_totsize;
bool at_edittop;
assert(file_top != NULL && file_bot != NULL);
if (current_x < mark_beginx && mark_beginbuf == current)
mark_beginx -= char_buf_len;
#endif
- totsize -= char_buf_len;
+ totsize--;
} else if (current != filebot && (current->next != filebot ||
current->data[0] == '\0')) {
/* We can delete the line before filebot only if it is blank: it
* the alternate spell command. The line that mark_beginbuf
* points to will be freed, so we save the line number and
* restore afterwards. */
- long old_totsize = totsize;
+ size_t totsize_save = totsize;
/* Our saved value of totsize, used when we spell-check a marked
* selection. */
#ifndef NANO_SMALL
if (old_mark_set) {
- long part_totsize;
+ size_t part_totsize;
/* If the mark was on, partition the filestruct so that it
* contains only the marked text, and keep track of whether the
* it from the saved value of totsize. Note that we don't need
* to save totlines. */
get_totals(top, bot, NULL, &part_totsize);
- old_totsize -= part_totsize;
+ totsize_save -= part_totsize;
}
#endif
* saved value the actual value. */
renumber(top_save);
totlines = filebot->lineno;
- old_totsize += totsize;
- totsize = old_totsize;
+ totsize_save += totsize;
+ totsize = totsize_save;
/* Assign mark_beginbuf to the line where the mark began
* before. */
* unjustifies. Note that we don't need to save totlines. */
size_t current_x_save = current_x;
int current_y_save = current_y;
- long flags_save = flags, totsize_save = totsize;
+ unsigned long flags_save = flags;
+ size_t totsize_save = totsize;
filestruct *edittop_save = edittop, *current_save = current;
#ifndef NANO_SMALL
filestruct *mark_beginbuf_save = mark_beginbuf;
current_len - current_x + char_buf_len);
charcpy(¤t->data[current_x], char_buf, char_buf_len);
current_len += char_buf_len;
- totsize += char_buf_len;
+ totsize++;
set_modified();
#ifndef NANO_SMALL
char *alt_speller_cpy = alt_speller;
#endif
ssize_t tabsize_cpy = tabsize;
- long flags_cpy = flags;
+ unsigned long flags_cpy = flags;
#ifndef DISABLE_OPERATINGDIR
operating_dir = NULL;
size_t placewewant; /* Current file's place we want. */
int totlines; /* Current file's total number of
* lines. */
- long totsize; /* Current file's total size. */
- long flags; /* Current file's flags: modification
+ size_t totsize; /* Current file's total size. */
+ unsigned long flags; /* Current file's flags: modification
* status (and marking status, if
* available). */
file_format fmt; /* Current file's format. */
#ifndef NANO_SMALL
extern size_t mark_beginx;
#endif
-extern long totsize;
-extern long flags;
+extern size_t totsize;
+extern unsigned long flags;
extern ssize_t tabsize;
extern int currslen;
**bot, size_t *bot_x, bool *right_side_up);
#endif
void get_totals(const filestruct *begin, const filestruct *end, int
- *lines, long *size);
+ *lines, size_t *size);
#ifndef DISABLE_TABCOMP
int check_wildcard_match(const char *text, const char *pattern);
#endif
char regexp_pat[] = "[ ]";
size_t current_x_save, pww_save;
int count = 1;
- long flags_save;
+ unsigned long flags_save;
filestruct *current_save;
ch_under_cursor = current->data[current_x];
/* Calculate the number of lines and the number of characters between
* begin and end, and return them in lines and size, respectively. */
void get_totals(const filestruct *begin, const filestruct *end, int
- *lines, long *size)
+ *lines, size_t *size)
{
const filestruct *f;
/* Count the number of characters on this line. */
if (size != NULL) {
- *size += strlen(f->data);
+ *size += mbstrlen(f->data);
/* Count the newline if we have one. */
if (f->next != NULL)
/* Count the number of characters on this line. */
if (size != NULL) {
- *size += strlen(f->data);
+ *size += mbstrlen(f->data);
/* Count the newline if we have one. */
if (f->next != NULL)
* alone, but next time we will display. */
void do_cursorpos(bool constant)
{
- const filestruct *fileptr;
+ char c;
+ filestruct *f;
size_t i = 0;
- static size_t old_i = 0;
- static long old_totsize = -1;
+ static size_t old_i = 0, old_totsize = (size_t)-1;
assert(current != NULL && fileage != NULL && totlines != 0);
- if (old_totsize == -1)
+ if (old_totsize == (size_t)-1)
old_totsize = totsize;
- for (fileptr = fileage; fileptr != current; fileptr = fileptr->next) {
- assert(fileptr != NULL);
- i += strlen(fileptr->data) + 1;
- }
- i += current_x;
+ c = current->data[current_x];
+ f = current->next;
+ current->data[current_x] = '\0';
+ current->next = NULL;
+ get_totals(fileage, current, NULL, &i);
+ current->data[current_x] = c;
+ current->next = f;
/* Check whether totsize is correct. Else there is a bug
* somewhere. */
size_t 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;
+ 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,
(unsigned long)xpt, (unsigned long)cur_len, colpct,
- (unsigned long)i, totsize, bytepct);
+ (unsigned long)i, (unsigned long)totsize, bytepct);
UNSET(DISABLE_CURPOS);
}