1
1

- Many malloc() cleanups and files.c tweaks by Steven Kneizys, new functions utils.c:free_shortcutage() (got to love that name\!) & free_toggles(), and big cleanup program thanks_for_all_the_fish() (originally thanks_for_the_memories()). Mods to shortcut_init() by Chris

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1085 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
Chris Allegretta 2002-02-27 04:14:16 +00:00
родитель bbcac936a0
Коммит f5de33a6ef
5 изменённых файлов: 208 добавлений и 14 удалений

Просмотреть файл

@ -1,4 +1,4 @@
CVS code -
2CVS code -
- General
- malloc->calloc, etc cleanups (DLR).
- New option, noconvert (-N, --noconvert) to completely stop
@ -18,6 +18,11 @@ CVS code -
- New code to handle multiple .save files. Changes to
die_save_file(), new function files.c:get_next_filename()
and utils.c:num_of_digits(). (Dwayne Rightler, DLR & Chris)
- Many malloc() cleanups and files.c tweaks by Steven Kneizys,
new functions utils.c:free_shortcutage() (got to love that
name!) & free_toggles(), and big cleanup program
thanks_for_all_the_fish() (originally
thanks_for_the_memories()). Mods to shortcut_init() by Chris.
- Makefile.am:
- Add SYSCONFDIR to DEFS, so we can have an /etc/nanorc.
- Change localedir line to 1.0's version.
@ -30,6 +35,8 @@ CVS code -
read_byte()
- Added check for conrol characters (indicative of a binary
file), set NO_CONVERT if found (fixes by DLR).
do_insertfile()
- Added support for -o in prompt (Steven Kneizys).
- global.c:
- Move openprev and opennext functions to shortcuts, they really
aren't toggles (DLR).

55
files.c
Просмотреть файл

@ -366,7 +366,17 @@ int do_insertfile(int loading_file)
currshortcut = insertfile_list;
#endif
#ifndef DISABLE_OPERATINGDIR
if ((operating_dir) && (strcmp(operating_dir,"."))){
i = statusq(1, insertfile_list, "", _("File to insert [from %s] "),
operating_dir);
} else {
#endif
i = statusq(1, insertfile_list, "", _("File to insert [from ./] "));
#ifndef DISABLE_OPERATINGDIR
}
#endif
if (i != -1) {
#ifdef DEBUG
@ -412,7 +422,6 @@ int do_insertfile(int loading_file)
/* update the current entry in the open_files structure */
add_open_file(1);
free_filestruct(fileage);
new_file();
UNSET(MODIFIED);
}
@ -508,6 +517,7 @@ int add_open_file(int update)
/* if open_files->file is NULL at the nrealloc() below, we get a
segfault
open_files->file = open_files; */
open_files->file = NULL;
}
else if (!update) {
@ -526,6 +536,7 @@ int add_open_file(int update)
/* if open_files->file is NULL at the nrealloc() below, we get a
segfault
open_files->file = open_files; */
open_files->file = NULL;
}
/* save current filename */
@ -555,8 +566,7 @@ int add_open_file(int update)
if (!(ISSET(VIEW_MODE) && !update)) {
/* save current filestruct and restore full file position
afterward */
open_files->file = nmalloc(sizeof(filestruct));
open_files->file = copy_filestruct(fileage);
open_files->file = fileage;
do_gotopos(open_files->lineno, open_files->file_current_x, open_files->file_current_y, open_files->file_placewewant);
}
@ -598,7 +608,7 @@ int load_open_file(void)
/* set up the filename, the file buffer, the total number of lines in
the file, and the total file size */
filename = mallocstrcpy(filename, open_files->data);
fileage = copy_filestruct(open_files->file);
fileage = open_files->file;
current = fileage;
totlines = open_files->file_totlines;
totsize = open_files->file_totsize;
@ -679,8 +689,12 @@ int open_prevfile(int closing_file)
}
/* free_filestruct(fileage); // delete this before reloading */
load_open_file();
statusbar(_("Switched to %s"),
((open_files->data[0] == '\0') ? "New Buffer" : open_files->data ));
#ifdef DEBUG
dump_buffer(current);
#endif
@ -742,6 +756,9 @@ int open_nextfile(int closing_file)
load_open_file();
statusbar(_("Switched to %s"),
((open_files->data[0] == '\0') ? "New Buffer" : open_files->data ));
#ifdef DEBUG
dump_buffer(current);
#endif
@ -1069,10 +1086,10 @@ char *safe_tempnam(const char *dirname, const char *filename_prefix) {
*/
int check_operating_dir(char *currpath, int allow_tabcomp)
{
/* this is static so that we only need to get it the first time this
function is called; also, a relative operating directory path will
/* The char *full_operating_dir is global for mem cleanup, and
therefore we only need to get it the first time this function
is called; also, a relative operating directory path will
only be handled properly if this is done */
static char *full_operating_dir = NULL;
char *fullpath, *whereami1, *whereami2 = NULL;
@ -1151,11 +1168,11 @@ int check_operating_dir(char *currpath, int allow_tabcomp)
int write_file(char *name, int tmp, int append, int nonamechange)
{
long size, lineswritten = 0;
static char *buf = NULL;
char *buf = NULL;
filestruct *fileptr;
int fd, mask = 0, realexists, anyexists;
struct stat st, lst;
static char *realname = NULL;
char *realname = NULL;
if (!strcmp(name, "")) {
statusbar(_("Cancelled"));
@ -2088,7 +2105,7 @@ void free_charptrarray(char **array, int len)
{
int i;
for (i = 0; i < len - 1; i++)
for (i = 0; i < len; i++)
free(array[i]);
free(array);
}
@ -2127,7 +2144,10 @@ void striponedir(char *foo)
if (tmp != foo)
*tmp = 0;
else
{ /* SPK may need to make a 'default' path here */
if (*tmp != '/') *(tmp) = '.';
*(tmp+1) = 0;
}
return;
}
@ -2321,6 +2341,17 @@ char *do_browser(char *inpath)
}
#endif
/* SPK for '.' path, get the current path via getcwd */
if (!strcmp(path, "./..")) {
free(path);
path = getcwd(NULL, 0);
striponedir(path);
align(&path);
free_charptrarray(filelist, numents);
free(foo);
return do_browser(path);
}
st = filestat(path);
if (S_ISDIR(st.st_mode)) {
if ((test_dir = opendir(path)) == NULL) {
@ -2341,6 +2372,8 @@ char *do_browser(char *inpath)
}
/* Start over again with the new path value */
free_charptrarray(filelist, numents);
free(foo);
return do_browser(path);
} else {
retval = path;
@ -2375,7 +2408,7 @@ char *do_browser(char *inpath)
char *saveanswer = NULL;
saveanswer = mallocstrcpy(saveanswer, answer);
answer = realloc(answer, strlen(path) + strlen(saveanswer) + 2);
answer = nrealloc(answer, strlen(path) + strlen(saveanswer) + 2);
sprintf(answer, "%s/%s", path, saveanswer);
free(saveanswer);
}

149
global.c
Просмотреть файл

@ -77,8 +77,8 @@ filestruct *mark_beginbuf; /* the begin marker buffer */
int mark_beginx; /* X value in the string to start */
#ifndef DISABLE_OPERATINGDIR
char *operating_dir = NULL; /* Operating directory, which we can't go
higher than */
char *operating_dir = NULL; /* Operating directory, which we can't */
char *full_operating_dir = NULL;/* go higher than */
#endif
#ifndef DISABLE_SPELLER
@ -327,6 +327,9 @@ void shortcut_init(int unjustify)
#endif
#endif /* !NANO_SMALL */
if (main_list != NULL)
free_shortcutage(&main_list);
sc_init_one(&main_list, NANO_HELP_KEY, _("Get Help"),
nano_help_msg, 0, NANO_HELP_FKEY, 0, VIEW, do_help);
@ -476,6 +479,9 @@ void shortcut_init(int unjustify)
NANO_OPENNEXT_KEY, 0, 0, VIEW, open_nextfile_void);
#endif
if (whereis_list != NULL)
free_shortcutage(&whereis_list);
sc_init_one(&whereis_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
@ -508,6 +514,8 @@ void shortcut_init(int unjustify)
#endif
#endif /* !NANO_SMALL */
if (replace_list != NULL)
free_shortcutage(&replace_list);
sc_init_one(&replace_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
@ -541,6 +549,8 @@ void shortcut_init(int unjustify)
#endif
#endif /* !NANO_SMALL */
if (replace_list_2 != NULL)
free_shortcutage(&replace_list_2);
sc_init_one(&replace_list_2, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
@ -554,6 +564,8 @@ void shortcut_init(int unjustify)
sc_init_one(&replace_list_2, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, do_last_line);
if (goto_list != NULL)
free_shortcutage(&goto_list);
sc_init_one(&goto_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
@ -567,6 +579,8 @@ void shortcut_init(int unjustify)
sc_init_one(&goto_list, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, &do_last_line);
if (help_list != NULL)
free_shortcutage(&help_list);
sc_init_one(&help_list, NANO_PREVPAGE_KEY, _("Prev Page"),
nano_prevpage_msg,
@ -579,6 +593,8 @@ void shortcut_init(int unjustify)
sc_init_one(&help_list, NANO_EXIT_KEY, _("Exit"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit);
if (writefile_list != NULL)
free_shortcutage(&writefile_list);
sc_init_one(&writefile_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
@ -603,6 +619,8 @@ void shortcut_init(int unjustify)
sc_init_one(&writefile_list, NANO_CANCEL_KEY,
_("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0);
if (insertfile_list != NULL)
free_shortcutage(&insertfile_list);
sc_init_one(&insertfile_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
@ -623,6 +641,10 @@ void shortcut_init(int unjustify)
#ifndef DISABLE_BROWSER
if (browser_list != NULL)
free_shortcutage(&browser_list);
sc_init_one(&browser_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
@ -641,6 +663,9 @@ void shortcut_init(int unjustify)
nano_gotodir_msg, NANO_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0,
VIEW, 0);
if (gotodir_list != NULL)
free_shortcutage(&gotodir_list);
sc_init_one(&gotodir_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
@ -656,3 +681,123 @@ void shortcut_init(int unjustify)
toggle_init();
}
/* delete the structure */
void free_shortcutage(shortcut **shortcutage)
{
shortcut *s,*ps;
s = *shortcutage;
if (s == NULL) {
return;
} else {
s = *shortcutage;
do {
ps = s;
s = s->next;
free(ps);
} while (s->next != NULL);
free(s);
*shortcutage = NULL;
}
}
#ifndef NANO_SMALL
/* clear the toggles */
void free_toggles(void)
{
toggle *u,*lu;
if (toggles == NULL) {
return;
} else {
lu = NULL;
for (u = toggles; u->next != NULL; u = u->next) {
if (lu != NULL) free(lu);
lu = u;
}
if (lu != NULL) free(lu);
if (u != NULL) free(u);
}
}
#endif
/* added by SPK for memory cleanup, gracefully return our malloc()s */
void thanks_for_all_the_fish(void)
{
#ifdef ENABLE_MULTIBUFFER
filestruct * current_open_file;
#endif
#ifdef ENABLE_MULTIBUFFER
if (operating_dir != NULL)
free(operating_dir);
if (full_operating_dir != NULL)
free(full_operating_dir);
#endif
if (last_search != NULL)
free(last_search);
if (last_replace != NULL)
free(last_replace);
if (hblank != NULL)
free(hblank);
#ifndef DISABLE_SPELLER
if (alt_speller != NULL)
free(alt_speller);
#endif
if (help_text != NULL)
free(help_text);
if (filename != NULL)
free(filename);
if (answer != NULL)
free(answer);
if (cutbuffer != NULL)
free_filestruct(cutbuffer);
free_shortcutage(&main_list);
free_shortcutage(&whereis_list);
free_shortcutage(&replace_list);
free_shortcutage(&replace_list_2);
free_shortcutage(&help_list);
free_shortcutage(&writefile_list);
free_shortcutage(&insertfile_list);
free_shortcutage(&spell_list);
#ifndef DISABLE_BROWSER
free_shortcutage(&browser_list);
#endif
free_shortcutage(&gotodir_list);
free_shortcutage(&goto_list);
#ifndef NANO_SMALL
free_toggles();
#endif
#ifdef ENABLE_MULTIBUFFER
/* Cleanup of Multibuffers . . .
Do not cleanup the current one, that is fileage . . . do the
rest of them though! (should be none if all went well) */
current_open_file = open_files;
if (open_files != NULL){
while (open_files->prev != NULL)
open_files = open_files->prev;
while (open_files->next != NULL) {
/* cleanup of a multi buf . . . */
if (open_files != current_open_file)
free_filestruct(open_files->file);
open_files = open_files->next;
free_filestruct(open_files->prev);
}
/* cleanup of last multi buf . . . */
if (open_files != current_open_file)
free_filestruct(open_files->file);
free_filestruct(open_files);
}
#endif
/* starting the cleanup of fileage now . . . */
if (fileage != NULL)
free_filestruct(fileage);
/* that is all for now */
}

6
nano.c
Просмотреть файл

@ -100,6 +100,8 @@ RETSIGTYPE finish(int sigage)
/* Restore the old term settings */
tcsetattr(0, TCSANOW, &oldterm);
thanks_for_all_the_fish();
exit(sigage);
}
@ -3262,7 +3264,11 @@ int main(int argc, char *argv[])
/* Look through the main shortcut list to see if we've hit a
shortcut key */
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
for (s = currshortcut; s != NULL && !keyhandled; s = s->next) {
#else
for (s = main_list; s != NULL && !keyhandled; s = s->next) {
#endif
if (kbinput == s->val ||
(s->misc1 && kbinput == s->misc1) ||
(s->misc2 && kbinput == s->misc2)) {

Просмотреть файл

@ -47,6 +47,7 @@ extern char *last_search;
extern char *last_replace;
#ifndef DISABLE_OPERATINGDIR
extern char *operating_dir;
extern char *full_operating_dir;
#endif
#ifndef DISABLE_SPELLER
extern char *alt_speller;
@ -187,6 +188,8 @@ void print_view_warning(void);
void unlink_node(filestruct * fileptr);
void cut_marked_segment(filestruct * top, int top_x, filestruct * bot,
int bot_x, int destructive);
void free_shortcutage(shortcut **src);
void thanks_for_all_the_fish(void);
#ifdef ENABLE_NANORC
void do_rcfile(void);