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
/* update the current entry in the open_files structure */
add_open_file(1);
- free_filestruct(fileage);
new_file();
UNSET(MODIFIED);
}
/* 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) {
/* 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 */
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);
}
/* 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;
}
+/* 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
load_open_file();
+ statusbar(_("Switched to %s"),
+ ((open_files->data[0] == '\0') ? "New Buffer" : open_files->data ));
+
#ifdef DEBUG
dump_buffer(current);
#endif
*/
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;
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"));
{
int i;
- for (i = 0; i < len - 1; i++)
+ for (i = 0; i < len; i++)
free(array[i]);
free(array);
}
if (tmp != foo)
*tmp = 0;
else
+ { /* SPK may need to make a 'default' path here */
+ if (*tmp != '/') *(tmp) = '.';
*(tmp+1) = 0;
+ }
return;
}
}
#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) {
}
/* Start over again with the new path value */
+ free_charptrarray(filelist, numents);
+ free(foo);
return do_browser(path);
} else {
retval = path;
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);
}
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
#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);
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);
#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);
#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);
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);
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,
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);
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);
#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);
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);
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 */
+
+}