[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] nanomisc2.patch: robustness (addendum)
From: |
David Lawrence Ramsey |
Subject: |
[Nano-devel] nanomisc2.patch: robustness (addendum) |
Date: |
Thu, 16 May 2002 13:48:25 -0700 (PDT) |
When I put the sanity checks back into move.c, I didn't put
them back in properly. Fixed now.
_____________________________________________________________
Sluggy.Net: The Sluggy Freelance Community!
_____________________________________________________________
Promote your group and strengthen ties to your members with address@hidden by
Everyone.net http://www.everyone.net/?btn=tag
diff -urN nano-1.1.9-cvs/faq.html nano-1.1.9-cvs-fixed/faq.html
--- nano-1.1.9-cvs/faq.html Sun May 12 20:09:30 2002
+++ nano-1.1.9-cvs-fixed/faq.html Thu May 16 16:48:30 2002
@@ -342,7 +342,7 @@
'gettext' and/or 'gettextdomain'. What can I do about it?</font></h2>
<blockquote><font color="#330000">Try doing a <b>./configure
--with-included-gettext</b>
-and see if that solves your problem. You make need to do a <b>make
+and see if that solves your problem. You may need to do a <b>make
clean ; make</b> to get it to work fully.</font></blockquote>
<h2>
diff -urN nano-1.1.9-cvs/files.c nano-1.1.9-cvs-fixed/files.c
--- nano-1.1.9-cvs/files.c Sun May 12 15:52:15 2002
+++ nano-1.1.9-cvs-fixed/files.c Thu May 16 16:48:30 2002
@@ -108,11 +108,15 @@
}
-filestruct *read_line(char *buf, filestruct *prev, int *line1ins)
+filestruct *read_line(char *buf, filestruct *prev, int *line1ins, int len)
{
filestruct *fileptr;
fileptr = nmalloc(sizeof(filestruct));
+
+ /* nulls to newlines; len is the string's real length here */
+ unsunder(buf, len);
+
fileptr->data = charalloc(strlen(buf) + 2);
strcpy(fileptr->data, buf);
@@ -158,7 +162,7 @@
int read_file(FILE *f, const char *filename, int quiet)
{
- int num_lines = 0;
+ int num_lines = 0, len = 0;
signed char input; /* current input character */
char *buf;
long i = 0, bufx = 128;
@@ -179,7 +183,7 @@
}
/* Read the entire file into file struct */
while ((input_int = getc(f)) != EOF) {
- input = (char) input_int;
+ input = (signed char) input_int;
#ifndef NANO_SMALL
if (!ISSET(NO_CONVERT) && input >= 0 && input <= 31
&& input != 127 && input != '\t' && input != '\r'
@@ -189,18 +193,41 @@
SET(NO_CONVERT);
#endif
+ /* calculate the total length of the line; it might have nulls in
+ it, so we can't just use strlen() */
+ len++;
+
if (input == '\n') {
- fileptr = read_line(buf, fileptr, &line1ins);
+
+ /* don't count the newline in the line length */
+ len--;
+
+ /* read in the line properly */
+ fileptr = read_line(buf, fileptr, &line1ins, len);
+
+ /* reset the line length, in preparation for the next line */
+ len = 0;
+
num_lines++;
buf[0] = 0;
i = 0;
#ifndef NANO_SMALL
/* If it's a Mac file (no LF just a CR), and file conversion
isn't disabled, handle it! */
- } else if (!ISSET(NO_CONVERT) && i > 0 && buf[i-1] == '\r') {
+ } else if (!ISSET(NO_CONVERT) && i > 0 && buf[i - 1] == '\r') {
fileformat = 2;
- fileptr = read_line(buf, fileptr, &line1ins);
+
+ /* don't count the newline in the line length */
+ len--;
+
+ /* read in the line properly */
+ fileptr = read_line(buf, fileptr, &line1ins, len);
+
+ /* reset the line length, in preparation for the next line */
+ len = 0;
+
num_lines++;
+ totsize++;
buf[0] = input;
buf[1] = 0;
i = 1;
@@ -230,8 +257,15 @@
/* Did we not get a newline but still have stuff to do? */
if (buf[0]) {
- fileptr = read_line(buf, fileptr, &line1ins);
+
+ /* read in the line properly */
+ fileptr = read_line(buf, fileptr, &line1ins, len);
+
+ /* reset the line length, in preparation for the next line */
+ len = 0;
+
num_lines++;
+ totsize++;
buf[0] = 0;
}
@@ -450,13 +484,6 @@
}
#endif
- /* Here is a kludge. If the current file is blank (including
- * after new_file()), then totlines==1 and totsize==0. Thus
- * after open_pipe() or open_file() below, the totsize is short
- * by one. */
- if (totlines==1 && totsize==0)
- totsize++;
-
#ifndef NANO_SMALL
if (i == NANO_EXTCMD_KEY) {
i = open_pipe(answer);
@@ -1326,7 +1353,15 @@
break;
data_len = strlen(fileptr->data);
+
+ /* newlines to nulls, just before we write to disk */
+ sunder(fileptr->data);
+
size = fwrite(fileptr->data, 1, data_len, f);
+
+ /* nulls to newlines; data_len is the string's real length here */
+ unsunder(fileptr->data, data_len);
+
if (size < data_len) {
statusbar(_("Could not open file for writing: %s"),
strerror(errno));
@@ -1354,7 +1389,15 @@
int data_len;
data_len = strlen(fileptr->data);
+
+ /* newlines to nulls, just before we write to disk */
+ sunder(fileptr->data);
+
size = fwrite(fileptr->data, 1, data_len, f);
+
+ /* nulls to newlines; data_len is the string's real length here */
+ unsunder(fileptr->data, data_len);
+
if (size < data_len) {
statusbar(_("Could not open file for writing: %s"),
strerror(errno));
diff -urN nano-1.1.9-cvs/global.c nano-1.1.9-cvs-fixed/global.c
--- nano-1.1.9-cvs/global.c Sun May 12 15:52:15 2002
+++ nano-1.1.9-cvs-fixed/global.c Thu May 16 16:48:30 2002
@@ -38,7 +38,7 @@
*/
int flags = 0; /* Our new flag containing many options */
-WINDOW *edit; /* The file portion of the editor */
+WINDOW *edit; /* The file portion of the editor */
WINDOW *topwin; /* Top line of screen */
WINDOW *bottomwin; /* Bottom buffer */
char *filename = NULL; /* Name of the file */
diff -urN nano-1.1.9-cvs/move.c nano-1.1.9-cvs-fixed/move.c
--- nano-1.1.9-cvs/move.c Sun May 12 15:52:15 2002
+++ nano-1.1.9-cvs-fixed/move.c Thu May 16 16:48:57 2002
@@ -112,9 +112,10 @@
{
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();
@@ -155,12 +156,11 @@
current_y = 0;
update_cursor();
-
}
int do_page_up(void)
{
- int i;
+ int i;
wrap_reset();
current_x = 0;
@@ -182,13 +182,14 @@
return 1;
}
-
int do_up(void)
{
wrap_reset();
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 -urN nano-1.1.9-cvs/nano.c nano-1.1.9-cvs-fixed/nano.c
--- nano-1.1.9-cvs/nano.c Sun May 12 15:52:15 2002
+++ nano-1.1.9-cvs-fixed/nano.c Thu May 16 16:48:30 2002
@@ -1239,6 +1239,9 @@
{
filestruct *previous, *tmp;
+ if (current_x > strlen(current->data))
+ current_x = strlen(current->data);
+
if (current_x != 0) {
/* Let's get dangerous */
memmove(¤t->data[current_x - 1], ¤t->data[current_x],
@@ -1316,6 +1319,9 @@
if (current->next == filebot && current->data[0] == '\0')
blbf = 1;
+ if (current_x > strlen(current->data))
+ current_x = strlen(current->data);
+
if (current_x != strlen(current->data)) {
/* Let's get dangerous */
memmove(¤t->data[current_x], ¤t->data[current_x + 1],
@@ -1367,6 +1373,9 @@
char *prevanswer = NULL, *save_search = NULL, *save_replace = NULL;
filestruct *begin;
int i = 0, j = 0, beginx, beginx_top, reverse_search_set;
+#ifndef NANO_SMALL
+ int mark_set;
+#endif
/* save where we are */
begin = current;
@@ -1376,6 +1385,12 @@
reverse_search_set = ISSET(REVERSE_SEARCH);
UNSET(REVERSE_SEARCH);
+#ifndef NANO_SMALL
+ /* Make sure the marking highlight is off during Spell Check */
+ mark_set = ISSET(MARK_ISSET);
+ UNSET(MARK_ISSET);
+#endif
+
/* save the current search/replace strings */
search_init_globals();
save_search = mallocstrcpy(save_search, last_search);
@@ -1438,6 +1453,12 @@
if (reverse_search_set)
SET(REVERSE_SEARCH);
+#ifndef NANO_SMALL
+ /* restore marking highlight */
+ if (mark_set)
+ SET(MARK_ISSET);
+#endif
+
edit_update(current, CENTER);
if (i == -1)
@@ -1451,8 +1472,7 @@
{
char *read_buff, *read_buff_ptr, *read_buff_word;
size_t pipe_buff_size, read_buff_size, read_buff_read, bytesread;
- int in_fd[2], tempfile_fd;
- int spell_status;
+ int in_fd[2], tempfile_fd, spell_status;
pid_t pid_spell;
/* Create a pipe to spell program */
@@ -1583,12 +1603,25 @@
{
int alt_spell_status, lineno_cur = current->lineno;
int x_cur = current_x, y_cur = current_y, pww_cur = placewewant;
+#ifndef NANO_SMALL
+ int mark_set = 0, mbb_lineno_cur, mbx_cur;
+#endif
pid_t pid_spell;
char *ptr;
static int arglen = 3;
static char **spellargs = (char **) NULL;
+#ifndef NANO_SMALL
+ mark_set = ISSET(MARK_ISSET);
+ if (mark_set) {
+ /* Save the marking position */
+ mbb_lineno_cur = mark_beginbuf->lineno;
+ mbx_cur = mark_beginx;
+ UNSET(MARK_ISSET);
+ }
+#endif
+
endwin();
/* Set up an argument list to pass the execvp function */
@@ -1634,6 +1667,15 @@
free_filestruct(fileage);
global_init(1);
open_file(file_name, 0, 1);
+
+#ifndef NANO_SMALL
+ if (mark_set) {
+ /* Restore the marking position */
+ do_gotopos(mbb_lineno_cur, mbx_cur, y_cur, 0);
+ mark_beginbuf = current;
+ SET(MARK_ISSET);
+ }
+#endif
/* go back to the old position, mark the file as modified, and make
sure that the titlebar is refreshed */
diff -urN nano-1.1.9-cvs/proto.h nano-1.1.9-cvs-fixed/proto.h
--- nano-1.1.9-cvs/proto.h Sun May 12 15:52:15 2002
+++ nano-1.1.9-cvs-fixed/proto.h Thu May 16 16:48:30 2002
@@ -175,6 +175,8 @@
char *real_dir_from_tilde(char *buf);
void signal_init(void);
+void unsunder(char *str, int true_len);
+void sunder(char *str);
void lowercase(char *src);
void blank_bottombars(void);
void check_wrap(filestruct * inptr);
diff -urN nano-1.1.9-cvs/search.c nano-1.1.9-cvs-fixed/search.c
--- nano-1.1.9-cvs/search.c Sun May 12 15:52:15 2002
+++ nano-1.1.9-cvs-fixed/search.c Thu May 16 16:48:30 2002
@@ -863,11 +863,9 @@
current_y = pos_y;
do_gotoline(line, 1);
- /* recalculate the x-coordinate and place we want, just in case their
- values are insane; if they aren't, they won't be changed by this */
- current_x = pos_x;
- pos_placewewant = xplustabs();
- pos_x = actual_x(current, pos_placewewant);
+ /* make sure that the x-coordinate is sane here */
+ if (pos_x > strlen(current->data))
+ pos_x = strlen(current->data);
/* set the rest of the coordinates up */
current_x = pos_x;
diff -urN nano-1.1.9-cvs/utils.c nano-1.1.9-cvs-fixed/utils.c
--- nano-1.1.9-cvs/utils.c Sun May 12 15:52:15 2002
+++ nano-1.1.9-cvs-fixed/utils.c Thu May 16 16:48:30 2002
@@ -52,6 +52,32 @@
return i;
}
+/* For non-null-terminated lines. A line, by definition, shouldn't
+ normally have newlines in it, so encode its nulls as newlines. */
+void unsunder(char *str, int true_len)
+{
+ int i;
+ if (strlen(str) < true_len) {
+ for (i = 0; i < true_len; i++) {
+ if (str[i] == '\0')
+ str[i] = '\n';
+ }
+ }
+}
+
+/* For non-null-terminated lines. A line, by definition, shouldn't
+ normally have newlines in it, so decode its newlines into nulls. */
+void sunder(char *str)
+{
+ int i, true_len = strlen(str);
+ if (strchr(str, '\n')) {
+ for (i = 0; i < true_len; i++) {
+ if (str[i] == '\n')
+ str[i] = '\0';
+ }
+ }
+}
+
/* Lower case a string - must be null terminated */
void lowercase(char *src)
{
diff -urN nano-1.1.9-cvs/winio.c nano-1.1.9-cvs-fixed/winio.c
--- nano-1.1.9-cvs/winio.c Sun May 12 16:43:49 2002
+++ nano-1.1.9-cvs-fixed/winio.c Thu May 16 16:48:30 2002
@@ -115,7 +115,6 @@
} else if (fileptr->data[i] & 0x80)
tot++; /* Make 8 bit chars only 1 column (again) */
else if (fileptr->data[i] < 32 || fileptr->data[i] == 127) {
- i++;
tot += 2;
}
@@ -504,6 +503,13 @@
nanoget_repaint(buf, inputbuf, x);
wrefresh(bottomwin);
}
+#ifndef DISABLE_TABCOMP
+ /* if we've done tab completion, there might be a list of filename
+ matches on the edit window at this point; make sure they're
+ cleared off */
+ if (list)
+ edit_refresh();
+#endif
answer = mallocstrcpy(answer, inputbuf);
free(inputbuf);
@@ -1181,12 +1187,19 @@
if (i < mark_beginx)
virt_mark_beginx--;
} else if (realdata[i] == 127) {
- /* Treat control characters as ^symbol (ASCII 1 - 31, 127) */
+ /* Treat control characters as ^symbol (ASCII 1 - 31 omitting
+ 10, 127) */
fileptr->data[pos++] = '^';
fileptr->data[pos++] = '?';
- } else if (realdata[i] >= 1 && realdata[i] <= 31) {
+ } else if (realdata[i] >= 1 && realdata[i] <= 31 && realdata[i] != 10) {
fileptr->data[pos++] = '^';
fileptr->data[pos++] = realdata[i] + 64;
+ } else if (realdata[i] == 10) {
+ /* Treat newlines (ASCII 10's) embedded in a line as encoded
+ nulls (ASCII 0's); the line in question should be run
+ through unsunder() before reaching here */
+ fileptr->data[pos++] = '^';
+ fileptr->data[pos++] = '@';
} else {
fileptr->data[pos++] = realdata[i];
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Nano-devel] nanomisc2.patch: robustness (addendum),
David Lawrence Ramsey <=