do_writeout() takes an arg now, and mallocstrcpy now gives up if src == dest

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@453 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2001-01-07 05:50:36 +00:00
parent c08f50d9de
commit e1ebaf3821
5 changed files with 21 additions and 9 deletions

View File

@ -20,6 +20,9 @@ General -
- removed skipping . and .. when tabulating matches. - removed skipping . and .. when tabulating matches.
- Added the (char *) sizeof when allocating memory for the filename - Added the (char *) sizeof when allocating memory for the filename
array (Rocco). array (Rocco).
do_writeout()
- Now takes an argument so the string typed in can be retained
when calling the browser.
do_browser() do_browser()
- Don't decrement longest by the length of path. Fixes crashes - Don't decrement longest by the length of path. Fixes crashes
on entering various dirs (Rocco). on entering various dirs (Rocco).
@ -40,6 +43,7 @@ General -
mallocstrcpy() mallocstrcpy()
- Takes char pointers now instead of void (makes debugging a - Takes char pointers now instead of void (makes debugging a
helluva lot easier) helluva lot easier)
- Duh, don't do anything if src == dest!
- es.po: - es.po:
- Updates for file browser (Jordi). - Updates for file browser (Jordi).

18
files.c
View File

@ -374,7 +374,7 @@ int write_file(char *name, int tmp)
if (fd == -1) { if (fd == -1) {
if (!tmp && ISSET(TEMP_OPT)) { if (!tmp && ISSET(TEMP_OPT)) {
UNSET(TEMP_OPT); UNSET(TEMP_OPT);
return do_writeout(1); return do_writeout(filename, 1);
} }
statusbar(_("Could not open file for writing: %s"), statusbar(_("Could not open file for writing: %s"),
strerror(errno)); strerror(errno));
@ -391,7 +391,7 @@ int write_file(char *name, int tmp)
if ((fd = mkstemp(buf)) == -1) { if ((fd = mkstemp(buf)) == -1) {
if (ISSET(TEMP_OPT)) { if (ISSET(TEMP_OPT)) {
UNSET(TEMP_OPT); UNSET(TEMP_OPT);
return do_writeout(1); return do_writeout(filename, 1);
} }
statusbar(_("Could not open file for writing: %s"), statusbar(_("Could not open file for writing: %s"),
strerror(errno)); strerror(errno));
@ -495,15 +495,16 @@ int write_file(char *name, int tmp)
return 1; return 1;
} }
int do_writeout(int exiting) int do_writeout(char *path, int exiting)
{ {
int i = 0; int i = 0;
#ifdef NANO_EXTRA #ifdef NANO_EXTRA
static int did_cred = 0; static int did_cred = 0;
#endif #endif
fprintf(stderr, "answer = %s, path = %s\n", answer, path);
answer = mallocstrcpy(answer, filename); answer = mallocstrcpy(answer, path);
if ((exiting) && (ISSET(TEMP_OPT))) { if ((exiting) && (ISSET(TEMP_OPT))) {
if (filename[0]) { if (filename[0]) {
@ -532,8 +533,11 @@ int do_writeout(int exiting)
if (tmp != NULL) if (tmp != NULL)
answer = mallocstrcpy(answer, tmp); answer = mallocstrcpy(answer, tmp);
else else {
return do_writeout(exiting); fprintf(stderr, "Answer = %s\n", answer);
return do_writeout(answer, exiting);
}
} }
#endif #endif
@ -572,7 +576,7 @@ int do_writeout(int exiting)
int do_writeout_void(void) int do_writeout_void(void)
{ {
return do_writeout(0); return do_writeout(filename, 0);
} }
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP

2
nano.c
View File

@ -1421,7 +1421,7 @@ int do_exit(void)
#endif #endif
if (i == 1) { if (i == 1) {
if (do_writeout(1) > 0) if (do_writeout(filename, 1) > 0)
finish(0); finish(0);
} else if (i == 0) } else if (i == 0)
finish(0); finish(0);

View File

@ -81,7 +81,7 @@ int do_uncut_text(void);
int no_help(void); int no_help(void);
int renumber_all(void); int renumber_all(void);
int open_file(char *filename, int insert, int quiet); int open_file(char *filename, int insert, int quiet);
int do_writeout(int exiting); int do_writeout(char *path, int exiting);
int do_gotoline(long defline); int do_gotoline(long defline);
int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx, int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
int wholewords, int *i); int wholewords, int *i);

View File

@ -126,6 +126,10 @@ void *nrealloc(void *ptr, size_t howmuch)
void *mallocstrcpy(char *dest, char *src) void *mallocstrcpy(char *dest, char *src)
{ {
if (src == dest)
return src;
if (dest != NULL) if (dest != NULL)
free(dest); free(dest);