David's fixes for read_file and the assert stuff for renumber
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1147 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
bb88ece93c
commit
f6cba64376
|
@ -13,6 +13,9 @@ CVS code -
|
||||||
- Stat full_path, not path (Steven Kneizys).
|
- Stat full_path, not path (Steven Kneizys).
|
||||||
read_file()
|
read_file()
|
||||||
- Abort if we read a file of 0 lines (num_lines == 0), fixes BUG #70.
|
- Abort if we read a file of 0 lines (num_lines == 0), fixes BUG #70.
|
||||||
|
- Reverse tests to stop segfault on editing a new file of 0
|
||||||
|
lines (David Benbennick)
|
||||||
|
- Change input var to one char instead of array (David Benbennick).
|
||||||
- nano.c:
|
- nano.c:
|
||||||
do_justify()
|
do_justify()
|
||||||
- More fixes for indented justify (David Benbennick).
|
- More fixes for indented justify (David Benbennick).
|
||||||
|
|
35
files.c
35
files.c
|
@ -115,6 +115,8 @@ int read_byte(int fd, char *filename, char *input)
|
||||||
resetty();
|
resetty();
|
||||||
endwin();
|
endwin();
|
||||||
perror(filename);
|
perror(filename);
|
||||||
|
total_refresh();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (!size)
|
if (!size)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -175,7 +177,7 @@ int read_file(int fd, char *filename, int quiet)
|
||||||
{
|
{
|
||||||
long size;
|
long size;
|
||||||
int num_lines = 0;
|
int num_lines = 0;
|
||||||
char input[2]; /* buffer */
|
char input; /* current input character */
|
||||||
char *buf;
|
char *buf;
|
||||||
long i = 0, bufx = 128;
|
long i = 0, bufx = 128;
|
||||||
filestruct *fileptr = current, *tmp = NULL;
|
filestruct *fileptr = current, *tmp = NULL;
|
||||||
|
@ -192,19 +194,18 @@ int read_file(int fd, char *filename, int quiet)
|
||||||
current = fileage;
|
current = fileage;
|
||||||
line1ins = 1;
|
line1ins = 1;
|
||||||
}
|
}
|
||||||
input[1] = 0;
|
|
||||||
/* Read the entire file into file struct */
|
/* Read the entire file into file struct */
|
||||||
while ((size = read_byte(fd, filename, input)) > 0) {
|
while ((size = read_byte(fd, filename, &input)) > 0) {
|
||||||
|
|
||||||
if (input[0] == '\n') {
|
if (input == '\n') {
|
||||||
fileptr = read_line(buf, fileptr, &line1ins);
|
fileptr = read_line(buf, fileptr, &line1ins);
|
||||||
num_lines++;
|
num_lines++;
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
} else if (!ISSET(NO_CONVERT) && input[0] >= 0 && input[0] <= 31
|
} else if (!ISSET(NO_CONVERT) && input >= 0 && input <= 31
|
||||||
&& input[0] != '\t' && input[0] != '\r'
|
&& input != '\t' && input != '\r'
|
||||||
&& input[0] != '\n')
|
&& input != '\n')
|
||||||
/* If the file has binary chars in it, don't stupidly
|
/* If the file has binary chars in it, don't stupidly
|
||||||
assume it's a DOS or Mac formatted file! */
|
assume it's a DOS or Mac formatted file! */
|
||||||
SET(NO_CONVERT);
|
SET(NO_CONVERT);
|
||||||
|
@ -215,7 +216,7 @@ int read_file(int fd, char *filename, int quiet)
|
||||||
fileformat = 2;
|
fileformat = 2;
|
||||||
fileptr = read_line(buf, fileptr, &line1ins);
|
fileptr = read_line(buf, fileptr, &line1ins);
|
||||||
num_lines++;
|
num_lines++;
|
||||||
buf[0] = input[0];
|
buf[0] = input;
|
||||||
buf[1] = 0;
|
buf[1] = 0;
|
||||||
i = 1;
|
i = 1;
|
||||||
#endif
|
#endif
|
||||||
|
@ -229,7 +230,7 @@ int read_file(int fd, char *filename, int quiet)
|
||||||
buf = nrealloc(buf, bufx + 128);
|
buf = nrealloc(buf, bufx + 128);
|
||||||
bufx += 128;
|
bufx += 128;
|
||||||
}
|
}
|
||||||
buf[i] = input[0];
|
buf[i] = input;
|
||||||
buf[i + 1] = 0;
|
buf[i + 1] = 0;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -243,13 +244,6 @@ int read_file(int fd, char *filename, int quiet)
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Did we try to insert a file of 0 bytes? */
|
|
||||||
if (num_lines == 0)
|
|
||||||
{
|
|
||||||
statusbar(_("Read %d lines"), 0);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Did we even GET a file if we don't already have one? */
|
/* Did we even GET a file if we don't already have one? */
|
||||||
if (totsize == 0 || fileptr == NULL) {
|
if (totsize == 0 || fileptr == NULL) {
|
||||||
new_file();
|
new_file();
|
||||||
|
@ -257,6 +251,13 @@ int read_file(int fd, char *filename, int quiet)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Did we try to insert a file of 0 bytes? */
|
||||||
|
if (num_lines == 0)
|
||||||
|
{
|
||||||
|
statusbar(_("Read %d lines"), 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (current != NULL) {
|
if (current != NULL) {
|
||||||
fileptr->next = current;
|
fileptr->next = current;
|
||||||
current->prev = fileptr;
|
current->prev = fileptr;
|
||||||
|
@ -310,7 +311,7 @@ int open_pipe(char *command)
|
||||||
dup2(fd[1], fileno(stderr));
|
dup2(fd[1], fileno(stderr));
|
||||||
/* If execl() returns at all, there was an error. */
|
/* If execl() returns at all, there was an error. */
|
||||||
|
|
||||||
execl("/bin/sh","/bin/sh","-c",command,0);
|
execl("/bin/sh","sh","-c",command,0);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
nano.c
2
nano.c
|
@ -369,6 +369,7 @@ int renumber_all(void)
|
||||||
filestruct *temp;
|
filestruct *temp;
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
|
assert(fileage==NULL || fileage!=fileage->next);
|
||||||
for (temp = fileage; temp != NULL; temp = temp->next) {
|
for (temp = fileage; temp != NULL; temp = temp->next) {
|
||||||
temp->lineno = i++;
|
temp->lineno = i++;
|
||||||
}
|
}
|
||||||
|
@ -384,6 +385,7 @@ int renumber(filestruct * fileptr)
|
||||||
renumber_all();
|
renumber_all();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
assert(fileptr==NULL || fileptr!=fileptr->next);
|
||||||
for (temp = fileptr; temp != NULL; temp = temp->next) {
|
for (temp = fileptr; temp != NULL; temp = temp->next) {
|
||||||
if (temp->prev != NULL)
|
if (temp->prev != NULL)
|
||||||
temp->lineno = temp->prev->lineno + 1;
|
temp->lineno = temp->prev->lineno + 1;
|
||||||
|
|
Loading…
Reference in New Issue