add miscellaneous color and openfilestruct cleanups, and move the

openfilestruct functions to nano.c, since they're no longer specific to
file operations


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2903 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-07-20 21:08:38 +00:00
parent ca62f9fa2b
commit e99494f21a
8 changed files with 116 additions and 103 deletions

View File

@ -13,17 +13,18 @@ CVS code -
openfilestruct, and so that the values in it are used directly openfilestruct, and so that the values in it are used directly
instead of being periodically synced up with the globals. instead of being periodically synced up with the globals.
Accordingly, remove the globals. Changes to pretty much Accordingly, remove the globals. Changes to pretty much
every function. Rename global_init() window_size_init(), every function. Rename add_open_file() make_new_buffer(),
rename add_open_file() make_new_buffer(), rename load_buffer() rename load_buffer() open_buffer(), rename load_open_file()
open_buffer(), rename load_open_file() display_buffer(), display_buffer(), rename open_prevnext_file()
rename open_prevnext_file() switch_to_prevnext_buffer(), switch_to_prevnext_buffer(), rename open_prevfile_void()
rename open_prevfile_void() switch_to_prev_buffer(), rename switch_to_prev_buffer(), rename open_nextfile_void()
open_nextfile_void() switch_to_next_buffer(), rename switch_to_next_buffer(), rename write_marked()
write_marked() write_marked_file(), remove load_file(), rename write_marked_file(), remove load_file(), rename cancel_fork()
cancel_fork() cancel_command(), rename open_pipe() cancel_command(), rename open_pipe() execute_command(), remove
execute_command(), remove execute_command(), remove execute_command(), rename resize_variables(), rename
resize_variables(), rename get_buffer() get_key_buffer(), and global_init() window_size_init(), rename get_buffer()
rename get_buffer_len() get_key_buffer_len(). (DLR) get_key_buffer(), and rename get_buffer_len()
get_key_buffer_len(). (DLR)
- Replace all mvwaddstr(hblank) calls with a new function that - Replace all mvwaddstr(hblank) calls with a new function that
does the same thing without the need for hblank. New function does the same thing without the need for hblank. New function
blank_line(); changes to do_browser(), blank_titlebar(), blank_line(); changes to do_browser(), blank_titlebar(),
@ -49,18 +50,20 @@ CVS code -
do_colorinit() (renamed color_init()), color_to_int() (renamed do_colorinit() (renamed color_init()), color_to_int() (renamed
color_to_short()), and parse_colors(). (DLR) color_to_short()), and parse_colors(). (DLR)
- Change color handling to save only the regex strings - Change color handling to save only the regex strings
constantly, and to actually compile them on an as-needed constantly, and to actually compile them on an as-needed
basis. Changes to update_color() and basis. Changes to update_color() and
thanks_for_all_the_fish(). (Brand Huntsman and DLR) thanks_for_all_the_fish(). (Brand Huntsman and DLR)
- Various other color fixes. Handle unspecified foreground - Various other color fixes. Handle unspecified foreground
colors properly, don't automatically reinitialize the colors properly, don't automatically reinitialize the
displayed colors every time we update the current buffer's displayed colors every time we update the current buffer's
colors (since the buffer may not be displayed immediately), colors (since the buffer may not be displayed immediately),
and don't bother doing complete refreshes of the screen when don't bother doing complete refreshes of the screen when
color support is enabled if there's no regex associated with color support is enabled if there's no regex associated with
the current file. Changes to do_colorinit() (renamed the current file, and rename variable exttype->val to
color_init()), update_color() (renamed color_update()), exttype->ext, for consistency. Changes to do_colorinit()
write_file(), do_input(), and do_output(). (DLR) (renamed color_init()), update_color() (renamed
color_update()), write_file(), do_input(), do_output(), and
parse_syntax(). (DLR)
- Simplify get_totals() to only get the total number of - Simplify get_totals() to only get the total number of
characters, and eliminate dependence on its old ability to get characters, and eliminate dependence on its old ability to get
the total number of lines by renumber()ing when necessary and the total number of lines by renumber()ing when necessary and

View File

@ -124,7 +124,7 @@ void color_update(void)
for (e = tmpsyntax->extensions; e != NULL; e = e->next) { for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
/* Set colorstrings if we matched the extension regex. */ /* Set colorstrings if we matched the extension regex. */
if (regexec(&e->val, openfile->filename, 0, NULL, 0) == 0) if (regexec(&e->ext, openfile->filename, 0, NULL, 0) == 0)
openfile->colorstrings = tmpsyntax->color; openfile->colorstrings = tmpsyntax->color;
if (openfile->colorstrings != NULL) if (openfile->colorstrings != NULL)

View File

@ -37,67 +37,6 @@
#include <assert.h> #include <assert.h>
#include "proto.h" #include "proto.h"
/* 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);
#ifndef NANO_SMALL
free(fileptr->current_stat);
#endif
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 an entry to the openfile openfilestruct. This should only be /* Add an entry to the openfile openfilestruct. This should only be
* called from open_buffer(). */ * called from open_buffer(). */
void make_new_buffer(void) void make_new_buffer(void)
@ -159,14 +98,13 @@ void initialize_buffer(void)
/* Reinitialize the current entry of the openfile openfilestruct. */ /* Reinitialize the current entry of the openfile openfilestruct. */
void reinitialize_buffer(void) void reinitialize_buffer(void)
{ {
assert(openfile != NULL); assert(openfile != NULL && openfile->filename != NULL && openfile->fileage != NULL);
free(openfile->filename); free(openfile->filename);
free_filestruct(openfile->fileage); free_filestruct(openfile->fileage);
#ifndef NANO_SMALL #ifndef NANO_SMALL
free(openfile->current_stat); if (openfile->current_stat != NULL)
free(openfile->current_stat);
#endif #endif
initialize_buffer(); initialize_buffer();
@ -619,6 +557,7 @@ int open_file(const char *filename, bool newfie, FILE **f)
} else } else
statusbar(_("Reading File")); statusbar(_("Reading File"));
} }
return 0; return 0;
} }

View File

@ -1218,7 +1218,7 @@ void thanks_for_all_the_fish(void)
exttype *bob = syntaxes->extensions; exttype *bob = syntaxes->extensions;
syntaxes->extensions = bob->next; syntaxes->extensions = bob->next;
regfree(&bob->val); regfree(&bob->ext);
free(bob); free(bob);
} }
while (syntaxes->color != NULL) { while (syntaxes->color != NULL) {

View File

@ -469,6 +469,77 @@ void copy_from_filestruct(filestruct *file_top, filestruct *file_bot)
openfile->totlines = openfile->filebot->lineno; openfile->totlines = openfile->filebot->lineno;
} }
/* Create a new openfilestruct node. */
openfilestruct *make_new_opennode(void)
{
openfilestruct *newnode =
(openfilestruct *)nmalloc(sizeof(openfilestruct));
newnode->filename = NULL;
newnode->fileage = NULL;
newnode->filebot = NULL;
newnode->edittop = NULL;
newnode->current = 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);
#ifndef NANO_SMALL
if (fileptr->current_stat != NULL)
free(fileptr->current_stat);
#endif
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
void print_view_warning(void) void print_view_warning(void)
{ {
statusbar(_("Key illegal in VIEW mode")); statusbar(_("Key illegal in VIEW mode"));

View File

@ -160,6 +160,15 @@ typedef struct filestruct {
ssize_t lineno; /* The line number. */ ssize_t lineno; /* The line number. */
} filestruct; } filestruct;
typedef struct partition {
filestruct *fileage;
filestruct *top_prev;
char *top_data;
filestruct *filebot;
filestruct *bot_next;
char *bot_data;
} partition;
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
typedef struct colortype { typedef struct colortype {
short fg; /* Foreground color. */ short fg; /* Foreground color. */
@ -180,7 +189,7 @@ typedef struct colortype {
} colortype; } colortype;
typedef struct exttype { typedef struct exttype {
regex_t val; /* The extensions that match this regex_t ext; /* The extensions that match this
* syntax. */ * syntax. */
struct exttype *next; struct exttype *next;
} exttype; } exttype;
@ -228,15 +237,6 @@ typedef struct openfilestruct {
/* Previous node. */ /* Previous node. */
} openfilestruct; } openfilestruct;
typedef struct partition {
filestruct *fileage;
filestruct *top_prev;
char *top_data;
filestruct *filebot;
filestruct *bot_next;
char *bot_data;
} partition;
typedef struct shortcut { typedef struct shortcut {
/* Key values that aren't used should be set to NANO_NO_KEY. */ /* Key values that aren't used should be set to NANO_NO_KEY. */
int ctrlval; /* Special sentinel key or control key we want int ctrlval; /* Special sentinel key or control key we want

View File

@ -228,14 +228,6 @@ void do_cut_till_end(void);
void do_uncut_text(void); void do_uncut_text(void);
/* Public functions in files.c. */ /* Public functions in files.c. */
openfilestruct *make_new_opennode(void);
void splice_opennode(openfilestruct *begin, openfilestruct *newnode,
openfilestruct *end);
void unlink_opennode(openfilestruct *fileptr);
void delete_opennode(openfilestruct *fileptr);
#ifdef DEBUG
void free_openfilestruct(openfilestruct *src);
#endif
void make_new_buffer(void); void make_new_buffer(void);
void initialize_buffer(void); void initialize_buffer(void);
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
@ -362,6 +354,14 @@ void unpartition_filestruct(partition **p);
void move_to_filestruct(filestruct **file_top, filestruct **file_bot, void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
filestruct *top, size_t top_x, filestruct *bot, size_t bot_x); filestruct *top, size_t top_x, filestruct *bot, size_t bot_x);
void copy_from_filestruct(filestruct *file_top, filestruct *file_bot); void copy_from_filestruct(filestruct *file_top, filestruct *file_bot);
openfilestruct *make_new_opennode(void);
void splice_opennode(openfilestruct *begin, openfilestruct *newnode,
openfilestruct *end);
void unlink_opennode(openfilestruct *fileptr);
void delete_opennode(openfilestruct *fileptr);
#ifdef DEBUG
void free_openfilestruct(openfilestruct *src);
#endif
void print_view_warning(void); void print_view_warning(void);
void finish(void); void finish(void);
void die(const char *msg, ...); void die(const char *msg, ...);

View File

@ -329,7 +329,7 @@ void parse_syntax(char *ptr)
break; break;
newext = (exttype *)nmalloc(sizeof(exttype)); newext = (exttype *)nmalloc(sizeof(exttype));
if (nregcomp(&newext->val, fileregptr, REG_NOSUB)) { if (nregcomp(&newext->ext, fileregptr, REG_NOSUB)) {
if (endext == NULL) if (endext == NULL)
endsyntax->extensions = newext; endsyntax->extensions = newext;
else else