reorder some functions for consistency
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2830 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
542
src/files.c
542
src/files.c
@@ -40,6 +40,277 @@
|
||||
static file_format fmt = NIX_FILE;
|
||||
/* The format of the current file. */
|
||||
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
/* Create a new openfilestruct node. */
|
||||
openfilestruct *make_new_opennode(void)
|
||||
{
|
||||
openfilestruct *newnode =
|
||||
(openfilestruct *)nmalloc(sizeof(openfilestruct));
|
||||
newnode->filename = NULL;
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* Splice a node into an existing openfilestruct. */
|
||||
void splice_opennode(openfilestruct *begin, openfilestruct *newnode,
|
||||
openfilestruct *end)
|
||||
{
|
||||
assert(newnode != NULL && begin != NULL);
|
||||
|
||||
newnode->next = end;
|
||||
newnode->prev = begin;
|
||||
begin->next = newnode;
|
||||
if (end != NULL)
|
||||
end->prev = newnode;
|
||||
}
|
||||
|
||||
/* Unlink a node from the rest of the openfilestruct, and delete it. */
|
||||
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);
|
||||
}
|
||||
|
||||
/* Delete a node from the openfilestruct. */
|
||||
void delete_opennode(openfilestruct *fileptr)
|
||||
{
|
||||
assert(fileptr != NULL && fileptr->filename != NULL && fileptr->fileage != NULL);
|
||||
|
||||
free(fileptr->filename);
|
||||
free_filestruct(fileptr->fileage);
|
||||
free(fileptr);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
/* Deallocate all memory associated with this and later files, including
|
||||
* the lines of text. */
|
||||
void free_openfilestruct(openfilestruct *src)
|
||||
{
|
||||
assert(src != NULL);
|
||||
|
||||
while (src != src->next) {
|
||||
src = src->next;
|
||||
delete_opennode(src->prev);
|
||||
}
|
||||
delete_opennode(src);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Add/update an entry to the open_files openfilestruct. If update is
|
||||
* FALSE, a new entry is created; otherwise, the current entry is
|
||||
* updated. */
|
||||
void add_open_file(bool update)
|
||||
{
|
||||
if (update && open_files == NULL)
|
||||
return;
|
||||
|
||||
/* If there are no entries in open_files, make the first one. */
|
||||
if (open_files == NULL) {
|
||||
open_files = make_new_opennode();
|
||||
splice_opennode(open_files, open_files, open_files);
|
||||
/* Otherwise, if we're not updating, make a new entry for
|
||||
* open_files and splice it in after the current entry. */
|
||||
} else if (!update) {
|
||||
splice_opennode(open_files, make_new_opennode(),
|
||||
open_files->next);
|
||||
open_files = open_files->next;
|
||||
}
|
||||
|
||||
/* Save the current filename. */
|
||||
open_files->filename = mallocstrcpy(open_files->filename, filename);
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Save the current file's stat. */
|
||||
open_files->originalfilestat = originalfilestat;
|
||||
#endif
|
||||
|
||||
/* Save the current file buffer. */
|
||||
open_files->fileage = fileage;
|
||||
open_files->filebot = filebot;
|
||||
|
||||
/* Save the current top of the edit window. */
|
||||
open_files->edittop = edittop;
|
||||
|
||||
/* Save the current line. */
|
||||
open_files->current = current;
|
||||
|
||||
/* Save the current cursor position. */
|
||||
open_files->current_x = current_x;
|
||||
|
||||
/* Save the current place we want. */
|
||||
open_files->placewewant = placewewant;
|
||||
|
||||
/* Save the current total number of lines. */
|
||||
open_files->totlines = totlines;
|
||||
|
||||
/* Save the current total size. */
|
||||
open_files->totsize = totsize;
|
||||
|
||||
/* Start with no flags saved. */
|
||||
open_files->flags = 0;
|
||||
|
||||
/* Save the current modification status. */
|
||||
if (ISSET(MODIFIED))
|
||||
open_files->flags |= MODIFIED;
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Save the current marking status and mark, if applicable. */
|
||||
if (ISSET(MARK_ISSET)) {
|
||||
open_files->flags |= MARK_ISSET;
|
||||
open_files->mark_beginbuf = mark_beginbuf;
|
||||
open_files->mark_beginx = mark_beginx;
|
||||
}
|
||||
|
||||
/* Save the current file format. */
|
||||
open_files->fmt = fmt;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "filename is %s\n", open_files->filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Read the current entry in the open_files structure and set up the
|
||||
* currently open file buffer using that entry's information. */
|
||||
void load_open_file(void)
|
||||
{
|
||||
assert(open_files != NULL);
|
||||
|
||||
/* Restore the current filename. */
|
||||
filename = mallocstrcpy(filename, open_files->filename);
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Restore the current file's stat. */
|
||||
originalfilestat = open_files->originalfilestat;
|
||||
#endif
|
||||
|
||||
/* Restore the current file buffer. */
|
||||
fileage = open_files->fileage;
|
||||
filebot = open_files->filebot;
|
||||
|
||||
/* Restore the current top of the edit window. */
|
||||
edittop = open_files->edittop;
|
||||
|
||||
/* Restore the current line. */
|
||||
current = open_files->current;
|
||||
|
||||
/* Restore the current cursor position. */
|
||||
current_x = open_files->current_x;
|
||||
|
||||
/* Restore the current place we want. */
|
||||
placewewant = open_files->placewewant;
|
||||
|
||||
/* Restore the current total number of lines. */
|
||||
totlines = open_files->totlines;
|
||||
|
||||
/* Restore the current total size. */
|
||||
totsize = open_files->totsize;
|
||||
|
||||
/* Restore the current modification status. */
|
||||
if (open_files->flags & MODIFIED)
|
||||
SET(MODIFIED);
|
||||
else
|
||||
UNSET(MODIFIED);
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Restore the current marking status and mark, if applicable. */
|
||||
if (open_files->flags & MARK_ISSET) {
|
||||
mark_beginbuf = open_files->mark_beginbuf;
|
||||
mark_beginx = open_files->mark_beginx;
|
||||
SET(MARK_ISSET);
|
||||
} else
|
||||
UNSET(MARK_ISSET);
|
||||
|
||||
/* Restore the current file format. */
|
||||
fmt = open_files->fmt;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
update_color();
|
||||
#endif
|
||||
edit_refresh();
|
||||
|
||||
/* Update the titlebar. */
|
||||
titlebar(NULL);
|
||||
}
|
||||
|
||||
/* Open either the next or previous file buffer. */
|
||||
void open_prevnext_file(bool next_file)
|
||||
{
|
||||
assert(open_files != NULL);
|
||||
|
||||
add_open_file(TRUE);
|
||||
|
||||
/* If only one file buffer is open, indicate it on the statusbar and
|
||||
* get out. */
|
||||
if (open_files == open_files->next) {
|
||||
statusbar(_("No more open file buffers"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Switch to the next or previous file, depending on the value of
|
||||
* next. */
|
||||
open_files = next_file ? open_files->next : open_files->prev;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "filename is %s\n", open_files->filename);
|
||||
#endif
|
||||
|
||||
/* Load the file we switched to. */
|
||||
load_open_file();
|
||||
|
||||
/* And indicate the switch on the statusbar. */
|
||||
statusbar(_("Switched to %s"),
|
||||
((open_files->filename[0] == '\0') ? _("New Buffer") :
|
||||
open_files->filename));
|
||||
|
||||
#ifdef DEBUG
|
||||
dump_buffer(current);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Open the previous entry in the open_files structure. This function
|
||||
* is used by the shortcut list. */
|
||||
void open_prevfile_void(void)
|
||||
{
|
||||
open_prevnext_file(FALSE);
|
||||
}
|
||||
|
||||
/* Open the next entry in the open_files structure. This function is
|
||||
* used by the shortcut list. */
|
||||
void open_nextfile_void(void)
|
||||
{
|
||||
open_prevnext_file(TRUE);
|
||||
}
|
||||
|
||||
/* Delete an entry from the open_files filestruct. After deletion of an
|
||||
* entry, the next entry is opened. Return TRUE on success or FALSE if
|
||||
* there are no more open file buffers. */
|
||||
bool close_open_file(void)
|
||||
{
|
||||
assert(open_files != NULL);
|
||||
|
||||
/* If only one file is open, get out. */
|
||||
if (open_files == open_files->next)
|
||||
return FALSE;
|
||||
|
||||
/* Open the next file. */
|
||||
open_nextfile_void();
|
||||
|
||||
/* Close the file we had open before. */
|
||||
unlink_opennode(open_files->prev);
|
||||
|
||||
/* Reinitialize the shortcut list. */
|
||||
shortcut_init(FALSE);
|
||||
display_main_list();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif /* ENABLE_MULTIBUFFER */
|
||||
|
||||
/* What happens when there is no file to open? aiee! */
|
||||
void new_file(void)
|
||||
{
|
||||
@@ -714,277 +985,6 @@ void do_insertfile_void(void)
|
||||
display_main_list();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
/* Create a new openfilestruct node. */
|
||||
openfilestruct *make_new_opennode(void)
|
||||
{
|
||||
openfilestruct *newnode =
|
||||
(openfilestruct *)nmalloc(sizeof(openfilestruct));
|
||||
newnode->filename = NULL;
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* Splice a node into an existing openfilestruct. */
|
||||
void splice_opennode(openfilestruct *begin, openfilestruct *newnode,
|
||||
openfilestruct *end)
|
||||
{
|
||||
assert(newnode != NULL && begin != NULL);
|
||||
|
||||
newnode->next = end;
|
||||
newnode->prev = begin;
|
||||
begin->next = newnode;
|
||||
if (end != NULL)
|
||||
end->prev = newnode;
|
||||
}
|
||||
|
||||
/* Unlink a node from the rest of the openfilestruct, and delete it. */
|
||||
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);
|
||||
}
|
||||
|
||||
/* Delete a node from the openfilestruct. */
|
||||
void delete_opennode(openfilestruct *fileptr)
|
||||
{
|
||||
assert(fileptr != NULL && fileptr->filename != NULL && fileptr->fileage != NULL);
|
||||
|
||||
free(fileptr->filename);
|
||||
free_filestruct(fileptr->fileage);
|
||||
free(fileptr);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
/* Deallocate all memory associated with this and later files, including
|
||||
* the lines of text. */
|
||||
void free_openfilestruct(openfilestruct *src)
|
||||
{
|
||||
assert(src != NULL);
|
||||
|
||||
while (src != src->next) {
|
||||
src = src->next;
|
||||
delete_opennode(src->prev);
|
||||
}
|
||||
delete_opennode(src);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Add/update an entry to the open_files openfilestruct. If update is
|
||||
* FALSE, a new entry is created; otherwise, the current entry is
|
||||
* updated. */
|
||||
void add_open_file(bool update)
|
||||
{
|
||||
if (update && open_files == NULL)
|
||||
return;
|
||||
|
||||
/* If there are no entries in open_files, make the first one. */
|
||||
if (open_files == NULL) {
|
||||
open_files = make_new_opennode();
|
||||
splice_opennode(open_files, open_files, open_files);
|
||||
/* Otherwise, if we're not updating, make a new entry for
|
||||
* open_files and splice it in after the current entry. */
|
||||
} else if (!update) {
|
||||
splice_opennode(open_files, make_new_opennode(),
|
||||
open_files->next);
|
||||
open_files = open_files->next;
|
||||
}
|
||||
|
||||
/* Save the current filename. */
|
||||
open_files->filename = mallocstrcpy(open_files->filename, filename);
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Save the current file's stat. */
|
||||
open_files->originalfilestat = originalfilestat;
|
||||
#endif
|
||||
|
||||
/* Save the current file buffer. */
|
||||
open_files->fileage = fileage;
|
||||
open_files->filebot = filebot;
|
||||
|
||||
/* Save the current top of the edit window. */
|
||||
open_files->edittop = edittop;
|
||||
|
||||
/* Save the current line. */
|
||||
open_files->current = current;
|
||||
|
||||
/* Save the current cursor position. */
|
||||
open_files->current_x = current_x;
|
||||
|
||||
/* Save the current place we want. */
|
||||
open_files->placewewant = placewewant;
|
||||
|
||||
/* Save the current total number of lines. */
|
||||
open_files->totlines = totlines;
|
||||
|
||||
/* Save the current total size. */
|
||||
open_files->totsize = totsize;
|
||||
|
||||
/* Start with no flags saved. */
|
||||
open_files->flags = 0;
|
||||
|
||||
/* Save the current modification status. */
|
||||
if (ISSET(MODIFIED))
|
||||
open_files->flags |= MODIFIED;
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Save the current marking status and mark, if applicable. */
|
||||
if (ISSET(MARK_ISSET)) {
|
||||
open_files->flags |= MARK_ISSET;
|
||||
open_files->mark_beginbuf = mark_beginbuf;
|
||||
open_files->mark_beginx = mark_beginx;
|
||||
}
|
||||
|
||||
/* Save the current file format. */
|
||||
open_files->fmt = fmt;
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "filename is %s\n", open_files->filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Read the current entry in the open_files structure and set up the
|
||||
* currently open file buffer using that entry's information. */
|
||||
void load_open_file(void)
|
||||
{
|
||||
assert(open_files != NULL);
|
||||
|
||||
/* Restore the current filename. */
|
||||
filename = mallocstrcpy(filename, open_files->filename);
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Restore the current file's stat. */
|
||||
originalfilestat = open_files->originalfilestat;
|
||||
#endif
|
||||
|
||||
/* Restore the current file buffer. */
|
||||
fileage = open_files->fileage;
|
||||
filebot = open_files->filebot;
|
||||
|
||||
/* Restore the current top of the edit window. */
|
||||
edittop = open_files->edittop;
|
||||
|
||||
/* Restore the current line. */
|
||||
current = open_files->current;
|
||||
|
||||
/* Restore the current cursor position. */
|
||||
current_x = open_files->current_x;
|
||||
|
||||
/* Restore the current place we want. */
|
||||
placewewant = open_files->placewewant;
|
||||
|
||||
/* Restore the current total number of lines. */
|
||||
totlines = open_files->totlines;
|
||||
|
||||
/* Restore the current total size. */
|
||||
totsize = open_files->totsize;
|
||||
|
||||
/* Restore the current modification status. */
|
||||
if (open_files->flags & MODIFIED)
|
||||
SET(MODIFIED);
|
||||
else
|
||||
UNSET(MODIFIED);
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Restore the current marking status and mark, if applicable. */
|
||||
if (open_files->flags & MARK_ISSET) {
|
||||
mark_beginbuf = open_files->mark_beginbuf;
|
||||
mark_beginx = open_files->mark_beginx;
|
||||
SET(MARK_ISSET);
|
||||
} else
|
||||
UNSET(MARK_ISSET);
|
||||
|
||||
/* Restore the current file format. */
|
||||
fmt = open_files->fmt;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COLOR
|
||||
update_color();
|
||||
#endif
|
||||
edit_refresh();
|
||||
|
||||
/* Update the titlebar. */
|
||||
titlebar(NULL);
|
||||
}
|
||||
|
||||
/* Open either the next or previous file buffer. */
|
||||
void open_prevnext_file(bool next_file)
|
||||
{
|
||||
assert(open_files != NULL);
|
||||
|
||||
add_open_file(TRUE);
|
||||
|
||||
/* If only one file buffer is open, indicate it on the statusbar and
|
||||
* get out. */
|
||||
if (open_files == open_files->next) {
|
||||
statusbar(_("No more open file buffers"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Switch to the next or previous file, depending on the value of
|
||||
* next. */
|
||||
open_files = next_file ? open_files->next : open_files->prev;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "filename is %s\n", open_files->filename);
|
||||
#endif
|
||||
|
||||
/* Load the file we switched to. */
|
||||
load_open_file();
|
||||
|
||||
/* And indicate the switch on the statusbar. */
|
||||
statusbar(_("Switched to %s"),
|
||||
((open_files->filename[0] == '\0') ? _("New Buffer") :
|
||||
open_files->filename));
|
||||
|
||||
#ifdef DEBUG
|
||||
dump_buffer(current);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Open the previous entry in the open_files structure. This function
|
||||
* is used by the shortcut list. */
|
||||
void open_prevfile_void(void)
|
||||
{
|
||||
open_prevnext_file(FALSE);
|
||||
}
|
||||
|
||||
/* Open the next entry in the open_files structure. This function is
|
||||
* used by the shortcut list. */
|
||||
void open_nextfile_void(void)
|
||||
{
|
||||
open_prevnext_file(TRUE);
|
||||
}
|
||||
|
||||
/* Delete an entry from the open_files filestruct. After deletion of an
|
||||
* entry, the next entry is opened. Return TRUE on success or FALSE if
|
||||
* there are no more open file buffers. */
|
||||
bool close_open_file(void)
|
||||
{
|
||||
assert(open_files != NULL);
|
||||
|
||||
/* If only one file is open, get out. */
|
||||
if (open_files == open_files->next)
|
||||
return FALSE;
|
||||
|
||||
/* Open the next file. */
|
||||
open_nextfile_void();
|
||||
|
||||
/* Close the file we had open before. */
|
||||
unlink_opennode(open_files->prev);
|
||||
|
||||
/* Reinitialize the shortcut list. */
|
||||
shortcut_init(FALSE);
|
||||
display_main_list();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif /* ENABLE_MULTIBUFFER */
|
||||
|
||||
/* When passed "[relative path]" or "[relative path][filename]" in
|
||||
* origpath, return "[full path]" or "[full path][filename]" on success,
|
||||
* or NULL on error. Do this if the file doesn't exist but the relative
|
||||
|
||||
Reference in New Issue
Block a user