add comment and formatting fixes, and remove now-useless global-specific code
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2906 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
3a9a32996b
commit
7f343a6dc4
67
src/files.c
67
src/files.c
|
@ -138,10 +138,11 @@ void open_buffer(const char *filename)
|
||||||
|
|
||||||
/* If the filename isn't blank, open the file. Otherwise, treat it
|
/* If the filename isn't blank, open the file. Otherwise, treat it
|
||||||
* as a new file. */
|
* as a new file. */
|
||||||
rc = (filename[0] != '\0') ?
|
rc = (filename[0] != '\0') ? open_file(filename, new_buffer, &f) :
|
||||||
open_file(filename, new_buffer, &f) : -2;
|
-2;
|
||||||
|
|
||||||
/* If we're loading into a new buffer, add a new openfile entry. */
|
/* If we're loading into a new buffer, add a new entry to
|
||||||
|
* openfile. */
|
||||||
if (new_buffer)
|
if (new_buffer)
|
||||||
make_new_buffer();
|
make_new_buffer();
|
||||||
|
|
||||||
|
@ -206,8 +207,8 @@ void switch_to_prevnext_buffer(bool next_buf)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Switch to the next or previous file, depending on the value of
|
/* Switch to the next or previous file buffer, depending on the
|
||||||
* next_buf. */
|
* value of next_buf. */
|
||||||
openfile = next_buf ? openfile->next : openfile->prev;
|
openfile = next_buf ? openfile->next : openfile->prev;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -227,35 +228,33 @@ void switch_to_prevnext_buffer(bool next_buf)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Switch to the previous entry in the openfile structure. This
|
/* Switch to the previous entry in the openfile filebuffer. */
|
||||||
* function is used by the shortcut list. */
|
|
||||||
void switch_to_prev_buffer_void(void)
|
void switch_to_prev_buffer_void(void)
|
||||||
{
|
{
|
||||||
switch_to_prevnext_buffer(FALSE);
|
switch_to_prevnext_buffer(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Switch to the next entry in the openfile structure. This function
|
/* Switch to the next entry in the openfile filebuffer. */
|
||||||
* is used by the shortcut list. */
|
|
||||||
void switch_to_next_buffer_void(void)
|
void switch_to_next_buffer_void(void)
|
||||||
{
|
{
|
||||||
switch_to_prevnext_buffer(TRUE);
|
switch_to_prevnext_buffer(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete an entry from the openfile filestruct, and switch to the one
|
/* Delete an entry from the openfile filebuffer, and switch to the one
|
||||||
* after it. Return TRUE on success, or FALSE if there are no more open
|
* after it. Return TRUE on success, or FALSE if there are no more open
|
||||||
* file buffers. */
|
* file buffers. */
|
||||||
bool close_buffer(void)
|
bool close_buffer(void)
|
||||||
{
|
{
|
||||||
assert(openfile != NULL);
|
assert(openfile != NULL);
|
||||||
|
|
||||||
/* If only one file is open, get out. */
|
/* If only one file buffer is open, get out. */
|
||||||
if (openfile == openfile->next)
|
if (openfile == openfile->next)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Switch to the next file. */
|
/* Switch to the next file buffer. */
|
||||||
switch_to_next_buffer_void();
|
switch_to_next_buffer_void();
|
||||||
|
|
||||||
/* Close the file we had open before. */
|
/* Close the file buffer we had open before. */
|
||||||
unlink_opennode(openfile->prev);
|
unlink_opennode(openfile->prev);
|
||||||
|
|
||||||
display_main_list();
|
display_main_list();
|
||||||
|
@ -277,7 +276,7 @@ filestruct *read_line(char *buf, filestruct *prevnode, bool
|
||||||
* here. */
|
* here. */
|
||||||
unsunder(buf, buf_len);
|
unsunder(buf, buf_len);
|
||||||
|
|
||||||
assert(strlen(buf) == buf_len);
|
assert(openfile->fileage != NULL && strlen(buf) == buf_len);
|
||||||
|
|
||||||
fileptr->data = mallocstrcpy(NULL, buf);
|
fileptr->data = mallocstrcpy(NULL, buf);
|
||||||
|
|
||||||
|
@ -288,7 +287,7 @@ filestruct *read_line(char *buf, filestruct *prevnode, bool
|
||||||
fileptr->data[buf_len - 1] = '\0';
|
fileptr->data[buf_len - 1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (*first_line_ins == TRUE || openfile->fileage == NULL) {
|
if (*first_line_ins == TRUE) {
|
||||||
/* Special case: We're inserting with the cursor on the first
|
/* Special case: We're inserting with the cursor on the first
|
||||||
* line. */
|
* line. */
|
||||||
fileptr->prev = NULL;
|
fileptr->prev = NULL;
|
||||||
|
@ -341,27 +340,17 @@ void read_file(FILE *f, const char *filename)
|
||||||
/* 0 = *nix, 1 = DOS, 2 = Mac, 3 = both DOS and Mac. */
|
/* 0 = *nix, 1 = DOS, 2 = Mac, 3 = both DOS and Mac. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
assert(openfile->fileage != NULL && openfile->current != NULL);
|
||||||
|
|
||||||
buf = charalloc(bufx);
|
buf = charalloc(bufx);
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
if (openfile->current != NULL) {
|
if (openfile->current == openfile->fileage)
|
||||||
if (openfile->current == openfile->fileage)
|
first_line_ins = TRUE;
|
||||||
first_line_ins = TRUE;
|
else
|
||||||
else
|
fileptr = openfile->current->prev;
|
||||||
fileptr = openfile->current->prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* For the assertion in read_line(), it must be true that if current
|
/* Read the entire file into the filestruct. */
|
||||||
* is NULL, then so is fileage. */
|
|
||||||
assert(openfile->current != NULL || openfile->fileage == NULL);
|
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
|
||||||
/* We don't know which file format we have yet, so assume it's a
|
|
||||||
* *nix file for now. */
|
|
||||||
openfile->fmt = NIX_FILE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Read the entire file into the file struct. */
|
|
||||||
while ((input_int = getc(f)) != EOF) {
|
while ((input_int = getc(f)) != EOF) {
|
||||||
input = (char)input_int;
|
input = (char)input_int;
|
||||||
|
|
||||||
|
@ -391,7 +380,6 @@ void read_file(FILE *f, const char *filename)
|
||||||
/* If it's a Mac file ('\r' without '\n'), and file conversion
|
/* If it's a Mac file ('\r' without '\n'), and file conversion
|
||||||
* isn't disabled, handle it! */
|
* 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') {
|
||||||
|
|
||||||
/* If we currently think the file is a *nix file, set format
|
/* If we currently think the file is a *nix file, set format
|
||||||
* to Mac. If we currently think the file is a DOS file,
|
* to Mac. If we currently think the file is a DOS file,
|
||||||
* set format to both DOS and Mac. */
|
* set format to both DOS and Mac. */
|
||||||
|
@ -467,7 +455,7 @@ void read_file(FILE *f, const char *filename)
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
/* If we didn't get a file and we don't already have one, load a
|
/* If we didn't get a file and we don't already have one, open a
|
||||||
* blank buffer. */
|
* blank buffer. */
|
||||||
if (fileptr == NULL)
|
if (fileptr == NULL)
|
||||||
open_buffer("");
|
open_buffer("");
|
||||||
|
@ -734,7 +722,7 @@ void do_insertfile(
|
||||||
if (execute) {
|
if (execute) {
|
||||||
#ifdef ENABLE_MULTIBUFFER
|
#ifdef ENABLE_MULTIBUFFER
|
||||||
if (ISSET(MULTIBUFFER))
|
if (ISSET(MULTIBUFFER))
|
||||||
/* Open a new blank buffer. */
|
/* Open a blank buffer. */
|
||||||
open_buffer("");
|
open_buffer("");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1561,12 +1549,7 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
/* Write a marked selection from a file out. First, set fileage and
|
/* Write a marked selection from a file out. */
|
||||||
* filebot as the top and bottom of the mark, respectively. Then call
|
|
||||||
* write_file() with the values of name, f_open, temp, and append, and
|
|
||||||
* with nonamechange set to TRUE so that we don't change the current
|
|
||||||
* filename. Finally, set fileage and filebot back to their old values
|
|
||||||
* and return. */
|
|
||||||
int write_marked_file(const char *name, FILE *f_open, bool tmp, int
|
int write_marked_file(const char *name, FILE *f_open, bool tmp, int
|
||||||
append)
|
append)
|
||||||
{
|
{
|
||||||
|
@ -1578,6 +1561,8 @@ int write_marked_file(const char *name, FILE *f_open, bool tmp, int
|
||||||
filestruct *top, *bot;
|
filestruct *top, *bot;
|
||||||
size_t top_x, bot_x;
|
size_t top_x, bot_x;
|
||||||
|
|
||||||
|
assert(openfile->mark_set);
|
||||||
|
|
||||||
/* Partition the filestruct so that it contains only the marked
|
/* Partition the filestruct so that it contains only the marked
|
||||||
* text. */
|
* text. */
|
||||||
mark_order((const filestruct **)&top, &top_x,
|
mark_order((const filestruct **)&top, &top_x,
|
||||||
|
|
12
src/nano.c
12
src/nano.c
|
@ -242,8 +242,8 @@ partition *partition_filestruct(filestruct *top, size_t top_x,
|
||||||
null_at(&bot->data, bot_x);
|
null_at(&bot->data, bot_x);
|
||||||
|
|
||||||
/* Remove all text before top_x at the top of the partition. */
|
/* Remove all text before top_x at the top of the partition. */
|
||||||
charmove(top->data, top->data + top_x, strlen(top->data) -
|
charmove(top->data, top->data + top_x, strlen(top->data) - top_x +
|
||||||
top_x + 1);
|
1);
|
||||||
align(&top->data);
|
align(&top->data);
|
||||||
|
|
||||||
/* Return the partition. */
|
/* Return the partition. */
|
||||||
|
@ -684,8 +684,8 @@ void window_init(void)
|
||||||
/* Set up the windows. */
|
/* Set up the windows. */
|
||||||
topwin = newwin(2 - no_more_space(), COLS, 0, 0);
|
topwin = newwin(2 - no_more_space(), COLS, 0, 0);
|
||||||
edit = newwin(editwinrows, COLS, 2 - no_more_space(), 0);
|
edit = newwin(editwinrows, COLS, 2 - no_more_space(), 0);
|
||||||
bottomwin = newwin(3 - no_help(), COLS, editwinrows +
|
bottomwin = newwin(3 - no_help(), COLS, editwinrows + (2 -
|
||||||
(2 - no_more_space()), 0);
|
no_more_space()), 0);
|
||||||
|
|
||||||
/* Turn the keypad back on. */
|
/* Turn the keypad back on. */
|
||||||
keypad(edit, TRUE);
|
keypad(edit, TRUE);
|
||||||
|
@ -725,8 +725,8 @@ void help_init(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* First, set up the initial help text for the current function. */
|
/* First, set up the initial help text for the current function. */
|
||||||
if (currshortcut == whereis_list || currshortcut == replace_list
|
if (currshortcut == whereis_list || currshortcut == replace_list ||
|
||||||
|| currshortcut == replace_list_2) {
|
currshortcut == replace_list_2) {
|
||||||
htx[0] = N_("Search Command Help Text\n\n "
|
htx[0] = N_("Search Command Help Text\n\n "
|
||||||
"Enter the words or characters you would like to "
|
"Enter the words or characters you would like to "
|
||||||
"search for, and then press Enter. If there is a "
|
"search for, and then press Enter. If there is a "
|
||||||
|
|
Loading…
Reference in New Issue