value. This allows the value to vary with the screen size yet
still be correct. New static value wrap_at to minimize code
inpact. Updated man page and info file.
+ - Allow file appending. New shortcut list nano_insertfile_list (since
+ insert and write routines can't share shortcut lists anymore),
+ new args to do_writeout and write_file called append, and of source
+ code changes to those functions.
- configure.in:
- New option, --enable-nanorc, which allows people to have a .nanorc
initialization file and set options normally used on the command
cut_marked_segment()
- Add bizarre copy of bot node, else *BSD goes ballistic (fixes
BUG #60).
+ - Added 'destructive' argument. Allows the selected text to be
+ added to the cutbuffer without changing the contents of the
+ file. This allows writing selection to separate files.
- faq.html:
- Brought the FAQ up to date, many little changes (Jordi).
- files.c:
- Added the "Goto Directory" code (Rocco)
- Don't shift the size of the file is it's less than 1K. Fixed
files less than 1K being displayed as 0B (Rocco).
+ do_writeout()
+ - New code to allow writing selected text to a separate file.
+ When this is done, the current filename is not changed, the
+ modification state is preserved, etc.
- global.c:
- Updated some of the lists for the "Goto Directory" code (Rocco)
- move.c:
int main() {
/* Ultrix mips cc rejects this. */
-typedef int charset[2]; const charset x;
+typedef int charset[2]; const charset x = {0,0};
/* SunOS 4.1.1 cc rejects this. */
char const *const *ccp;
char **p;
#include "confdefs.h"
int main() {
-} $ac_kw foo() {
+} int $ac_kw foo() {
; return 0; }
EOF
if { (eval echo configure:2758: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
#include "confdefs.h"
#include <alloca.h>
int main() {
-char *p = alloca(2 * sizeof(int));
+void *p = alloca(2 * sizeof(int));
; return 0; }
EOF
if { (eval echo configure:2864: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
#include <sys/types.h>
#include <fcntl.h>
#include <sys/mman.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
/* This mess was copied from the GNU getpagesize.h. */
#ifndef HAVE_GETPAGESIZE
-# ifdef HAVE_UNISTD_H
-# include <unistd.h>
-# endif
/* Assume that all systems that can run configure have sys/param.h. */
# ifndef HAVE_SYS_PARAM_H
/*
* First, make a file with some known garbage in it.
*/
- data = malloc(pagesize);
+ data = (char*)malloc(pagesize);
if (!data)
exit(1);
for (i = 0; i < pagesize; ++i)
fd = open("conftestmmap", O_RDWR);
if (fd < 0)
exit(1);
- data2 = malloc(2 * pagesize);
+ data2 = (char*)malloc(2 * pagesize);
if (!data2)
exit(1);
data2 += (pagesize - ((int) data2 & (pagesize - 1))) & (pagesize - 1);
*/
for (i = 0; i < pagesize; ++i)
*(data2 + i) = *(data2 + i) + 1;
- data3 = malloc(pagesize);
+ data3 = (char*)malloc(pagesize);
if (!data3)
exit(1);
if (read(fd, data3, pagesize) != pagesize)
}
EOF
-if { (eval echo configure:3327: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3330: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
ac_cv_func_mmap_fixed_mapped=yes
else
do
ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:3355: checking for $ac_hdr" >&5
+echo "configure:3358: checking for $ac_hdr" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3360 "configure"
+#line 3363 "configure"
#include "confdefs.h"
#include <$ac_hdr>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:3365: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:3368: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
strdup __argz_count __argz_stringify __argz_next
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:3395: checking for $ac_func" >&5
+echo "configure:3398: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3400 "configure"
+#line 3403 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:3423: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3426: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
for ac_func in stpcpy
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:3452: checking for $ac_func" >&5
+echo "configure:3455: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3457 "configure"
+#line 3460 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:3480: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3483: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
if test $ac_cv_header_locale_h = yes; then
echo $ac_n "checking for LC_MESSAGES""... $ac_c" 1>&6
-echo "configure:3514: checking for LC_MESSAGES" >&5
+echo "configure:3517: checking for LC_MESSAGES" >&5
if eval "test \"`echo '$''{'am_cv_val_LC_MESSAGES'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3519 "configure"
+#line 3522 "configure"
#include "confdefs.h"
#include <locale.h>
int main() {
return LC_MESSAGES
; return 0; }
EOF
-if { (eval echo configure:3526: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3529: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
am_cv_val_LC_MESSAGES=yes
else
fi
fi
echo $ac_n "checking whether NLS is requested""... $ac_c" 1>&6
-echo "configure:3547: checking whether NLS is requested" >&5
+echo "configure:3550: checking whether NLS is requested" >&5
# Check whether --enable-nls or --disable-nls was given.
if test "${enable_nls+set}" = set; then
enableval="$enable_nls"
EOF
echo $ac_n "checking whether included gettext is requested""... $ac_c" 1>&6
-echo "configure:3567: checking whether included gettext is requested" >&5
+echo "configure:3570: checking whether included gettext is requested" >&5
# Check whether --with-included-gettext or --without-included-gettext was given.
if test "${with_included_gettext+set}" = set; then
withval="$with_included_gettext"
ac_safe=`echo "libintl.h" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for libintl.h""... $ac_c" 1>&6
-echo "configure:3586: checking for libintl.h" >&5
+echo "configure:3589: checking for libintl.h" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3591 "configure"
+#line 3594 "configure"
#include "confdefs.h"
#include <libintl.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:3596: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:3599: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
echo "$ac_t""yes" 1>&6
echo $ac_n "checking for gettext in libc""... $ac_c" 1>&6
-echo "configure:3613: checking for gettext in libc" >&5
+echo "configure:3616: checking for gettext in libc" >&5
if eval "test \"`echo '$''{'gt_cv_func_gettext_libc'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3618 "configure"
+#line 3621 "configure"
#include "confdefs.h"
#include <libintl.h>
int main() {
return (int) gettext ("")
; return 0; }
EOF
-if { (eval echo configure:3625: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3628: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
gt_cv_func_gettext_libc=yes
else
if test "$gt_cv_func_gettext_libc" != "yes"; then
echo $ac_n "checking for bindtextdomain in -lintl""... $ac_c" 1>&6
-echo "configure:3641: checking for bindtextdomain in -lintl" >&5
+echo "configure:3644: checking for bindtextdomain in -lintl" >&5
ac_lib_var=`echo intl'_'bindtextdomain | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lintl $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3649 "configure"
+#line 3652 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
bindtextdomain()
; return 0; }
EOF
-if { (eval echo configure:3660: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3663: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
echo "$ac_t""yes" 1>&6
echo $ac_n "checking for gettext in libintl""... $ac_c" 1>&6
-echo "configure:3676: checking for gettext in libintl" >&5
+echo "configure:3679: checking for gettext in libintl" >&5
if eval "test \"`echo '$''{'gt_cv_func_gettext_libintl'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
echo $ac_n "checking for gettext in -lintl""... $ac_c" 1>&6
-echo "configure:3681: checking for gettext in -lintl" >&5
+echo "configure:3684: checking for gettext in -lintl" >&5
ac_lib_var=`echo intl'_'gettext | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-lintl $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3689 "configure"
+#line 3692 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
gettext()
; return 0; }
EOF
-if { (eval echo configure:3700: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3703: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
# Extract the first word of "msgfmt", so it can be a program name with args.
set dummy msgfmt; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:3739: checking for $ac_word" >&5
+echo "configure:3742: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_MSGFMT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
for ac_func in dcgettext
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:3773: checking for $ac_func" >&5
+echo "configure:3776: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3778 "configure"
+#line 3781 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
; return 0; }
EOF
-if { (eval echo configure:3801: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3804: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
# Extract the first word of "gmsgfmt", so it can be a program name with args.
set dummy gmsgfmt; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:3828: checking for $ac_word" >&5
+echo "configure:3831: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_GMSGFMT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "xgettext", so it can be a program name with args.
set dummy xgettext; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:3864: checking for $ac_word" >&5
+echo "configure:3867: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_XGETTEXT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
fi
cat > conftest.$ac_ext <<EOF
-#line 3896 "configure"
+#line 3899 "configure"
#include "confdefs.h"
int main() {
return _nl_msg_cat_cntr
; return 0; }
EOF
-if { (eval echo configure:3904: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3907: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
CATOBJEXT=.gmo
DATADIRNAME=share
if test "$CATOBJEXT" = "NONE"; then
echo $ac_n "checking whether catgets can be used""... $ac_c" 1>&6
-echo "configure:3927: checking whether catgets can be used" >&5
+echo "configure:3930: checking whether catgets can be used" >&5
# Check whether --with-catgets or --without-catgets was given.
if test "${with_catgets+set}" = set; then
withval="$with_catgets"
if test "$nls_cv_use_catgets" = "yes"; then
echo $ac_n "checking for main in -li""... $ac_c" 1>&6
-echo "configure:3940: checking for main in -li" >&5
+echo "configure:3943: checking for main in -li" >&5
ac_lib_var=`echo i'_'main | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
ac_save_LIBS="$LIBS"
LIBS="-li $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 3948 "configure"
+#line 3951 "configure"
#include "confdefs.h"
int main() {
main()
; return 0; }
EOF
-if { (eval echo configure:3955: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:3958: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
fi
echo $ac_n "checking for catgets""... $ac_c" 1>&6
-echo "configure:3983: checking for catgets" >&5
+echo "configure:3986: checking for catgets" >&5
if eval "test \"`echo '$''{'ac_cv_func_catgets'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 3988 "configure"
+#line 3991 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char catgets(); below. */
; return 0; }
EOF
-if { (eval echo configure:4011: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4014: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_catgets=yes"
else
# Extract the first word of "gencat", so it can be a program name with args.
set dummy gencat; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:4033: checking for $ac_word" >&5
+echo "configure:4036: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_GENCAT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "gmsgfmt", so it can be a program name with args.
set dummy gmsgfmt; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:4069: checking for $ac_word" >&5
+echo "configure:4072: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_GMSGFMT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "msgfmt", so it can be a program name with args.
set dummy msgfmt; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:4106: checking for $ac_word" >&5
+echo "configure:4109: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_GMSGFMT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "xgettext", so it can be a program name with args.
set dummy xgettext; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:4141: checking for $ac_word" >&5
+echo "configure:4144: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_XGETTEXT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "msgfmt", so it can be a program name with args.
set dummy msgfmt; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:4199: checking for $ac_word" >&5
+echo "configure:4202: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_MSGFMT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "gmsgfmt", so it can be a program name with args.
set dummy gmsgfmt; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:4233: checking for $ac_word" >&5
+echo "configure:4236: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_GMSGFMT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
# Extract the first word of "xgettext", so it can be a program name with args.
set dummy xgettext; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:4269: checking for $ac_word" >&5
+echo "configure:4272: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_path_XGETTEXT'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
LINGUAS=
else
echo $ac_n "checking for catalogs to be installed""... $ac_c" 1>&6
-echo "configure:4362: checking for catalogs to be installed" >&5
+echo "configure:4365: checking for catalogs to be installed" >&5
NEW_LINGUAS=
for lang in ${LINGUAS=$ALL_LINGUAS}; do
case "$ALL_LINGUAS" in
if test "$CATOBJEXT" = ".cat"; then
ac_safe=`echo "linux/version.h" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for linux/version.h""... $ac_c" 1>&6
-echo "configure:4390: checking for linux/version.h" >&5
+echo "configure:4393: checking for linux/version.h" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4395 "configure"
+#line 4398 "configure"
#include "confdefs.h"
#include <linux/version.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:4400: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:4403: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
}
#ifndef NANO_SMALL
+/* Cut a marked segment instead of a whole line. Only called from do_cut_text().
+ destructive is whether to actually modify the file structure, if not then
+ just copy the buffer into cutbuffer and don't pull it from the file */
+
void cut_marked_segment(filestruct * top, int top_x, filestruct * bot,
- int bot_x)
+ int bot_x, int destructive)
{
filestruct *tmp, *next, *botcopy;
char *tmpstr;
/* Chop off the end of the first line */
tmpstr = charalloc(top_x + 1);
strncpy(tmpstr, top->data, top_x);
- free(top->data);
- top->data = tmpstr;
+
+ if (destructive) {
+ free(top->data);
+ top->data = tmpstr;
+ }
do {
next = tmp->next;
- add_to_cutbuffer(tmp);
+ if (destructive)
+ add_to_cutbuffer(tmp);
+ else {
+ filestruct *tmpcopy = NULL;
+
+ tmpcopy = copy_node(tmp);
+ add_to_cutbuffer(tmpcopy);
+ }
totlines--;
totsize--; /* newline (add_to_cutbuffer doesn't count newlines) */
tmp = next;
dump_buffer(cutbuffer);
if (next == NULL)
return;
- /* Now, paste bot[bot_x] into top[top_x] */
- tmpstr = charalloc(strlen(top->data) + strlen(&bot->data[bot_x]));
- strncpy(tmpstr, top->data, top_x);
- strcpy(&tmpstr[top_x], &bot->data[bot_x]);
- free(top->data);
- top->data = tmpstr;
- null_at(bot->data, bot_x);
- next = bot->next;
+ /* Now, paste bot[bot_x] into top[top_x] */
+ if (destructive) {
- /* We explicitly don't decrement totlines here because we don't snarf
- * up a newline when we're grabbing the last line of the mark. For
- * the same reason, we don't do an extra totsize decrement. */
+ tmpstr = charalloc(strlen(top->data) + strlen(&bot->data[bot_x]));
+ strncpy(tmpstr, top->data, top_x);
+ strcpy(&tmpstr[top_x], &bot->data[bot_x]);
+ free(top->data);
+ top->data = tmpstr;
+ /* We explicitly don't decrement totlines here because we don't snarf
+ * up a newline when we're grabbing the last line of the mark. For
+ * the same reason, we don't do an extra totsize decrement. */
+ }
/* I honestly do not know why this is needed. After many hours of
- using gdb on an OpenBSD box, I can honestly say something is
- screwed somewhere. Not doing this causes update_line to annihilate
- the last line copied into the cutbuffer when the mark is set ?!?!? */
+ using gdb on an OpenBSD box, I can honestly say something is
+ screwed somewhere. Not doing this causes update_line to annihilate
+ the last line copied into the cutbuffer when the mark is set ?!?!? */
botcopy = copy_node(bot);
+ null_at(botcopy->data, bot_x);
+ next = botcopy->next;
add_to_cutbuffer(botcopy);
- free(bot);
- top->next = next;
- if (next != NULL)
- next->prev = top;
- dump_buffer(cutbuffer);
- renumber(top);
- current = top;
- current_x = top_x;
-
- /* If we're hitting the end of the buffer, we should clean that up. */
- if (bot == filebot) {
- if (next != NULL) {
- filebot = next;
- } else {
- filebot = top;
+ if (destructive) {
+ free(bot);
+
+ top->next = next;
+ if (next != NULL)
+ next->prev = top;
+
+ dump_buffer(cutbuffer);
+ renumber(top);
+ current = top;
+ current_x = top_x;
+
+ /* If we're hitting the end of the buffer, we should clean that up. */
+ if (bot == filebot) {
+ if (next != NULL) {
+ filebot = next;
+ } else {
+ filebot = top;
+ }
}
+ if (top->lineno < edittop->lineno)
+ edit_update(top, CENTER);
}
- if (top->lineno < edittop->lineno)
- edit_update(top, CENTER);
}
#endif
align(¤t->data);
} else if (current->lineno < mark_beginbuf->lineno)
cut_marked_segment(current, current_x, mark_beginbuf,
- mark_beginx);
+ mark_beginx, 1);
else
cut_marked_segment(mark_beginbuf, mark_beginx, current,
- current_x);
+ current_x, 1);
placewewant = xplustabs();
UNSET(MARK_ISSET);
wrap_reset();
#ifndef DISABLE_MOUSE
- currshortcut = writefile_list;
- currslen = WRITEFILE_LIST_LEN;
+ currshortcut = insertfile_list;
+ currslen = INSERTFILE_LIST_LEN;
#endif
- i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "",
+ i = statusq(1, insertfile_list, INSERTFILE_LIST_LEN, "",
_("File to insert [from ./] "));
if (i != -1) {
char *tmp = do_browse_from(realname);
#ifndef DISABLE_MOUSE
- currshortcut = writefile_list;
- currslen = WRITEFILE_LIST_LEN;
+ currshortcut = insertfile_list;
+ currslen = INSERTFILE_LIST_LEN;
#endif
#ifdef DISABLE_TABCOMP
*
* tmp means we are writing a tmp file in a secure fashion. We use
* it when spell checking or dumping the file on an error.
+ *
+ * append means, not surprisingly, whether we are appending instead
+ * of overwriting.
*/
-int write_file(char *name, int tmp)
+int write_file(char *name, int tmp, int append)
{
long size, lineswritten = 0;
static char *buf = NULL;
else if (ISSET(FOLLOW_SYMLINKS) || !S_ISLNK(lst.st_mode) || tmp) {
/* Use O_EXCL if tmp == 1. This is now copied from joe, because
wiggy says so *shrug*. */
- if (tmp)
+ if (append)
+ fd = open(realname, O_WRONLY | O_APPEND, (S_IRUSR|S_IWUSR));
+ else if (tmp)
fd = open(realname, O_WRONLY | O_CREAT | O_EXCL, (S_IRUSR|S_IWUSR));
else
fd = open(realname, O_WRONLY | O_CREAT | O_TRUNC, (S_IRUSR|S_IWUSR));
if (fd == -1) {
if (!tmp && ISSET(TEMP_OPT)) {
UNSET(TEMP_OPT);
- return do_writeout(filename, 1);
+ return do_writeout(filename, 1, 0);
}
statusbar(_("Could not open file for writing: %s"),
strerror(errno));
if ((fd = mkstemp(buf)) == -1) {
if (ISSET(TEMP_OPT)) {
UNSET(TEMP_OPT);
- return do_writeout(filename, 1);
+ return do_writeout(filename, 1, 0);
}
statusbar(_("Could not open file for writing: %s"),
strerror(errno));
return 1;
}
-int do_writeout(char *path, int exiting)
+int do_writeout(char *path, int exiting, int append)
{
int i = 0;
if ((exiting) && (ISSET(TEMP_OPT))) {
if (filename[0]) {
- i = write_file(answer, 0);
+ i = write_file(answer, 0, 0);
display_main_list();
return i;
} else {
}
while (1) {
- i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer,
- _("File Name to write"));
+ if (ISSET(MARK_ISSET) && !exiting)
+ i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer,
+ _("%s Selection to File"), append ? _("Append") : _("Write"));
+ else
+ i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer,
+ _("File Name to %s"), append ? _("Append") : _("Write"));
if (i != -1) {
currslen = WRITEFILE_LIST_LEN;
#endif
- if (tmp != NULL)
+ if (tmp != NULL) {
answer = mallocstrcpy(answer, tmp);
- else
- return do_writeout(answer, exiting);
- }
+ } else
+ return do_writeout(answer, exiting, append);
+ } else
#endif
+ if (i == NANO_APPEND_KEY)
+ return(do_writeout(answer, exiting, 1 - append));
#ifdef DEBUG
fprintf(stderr, _("filename is %s"), answer);
return -1;
}
#endif
- if (strcmp(answer, filename)) {
+ if (!append && strcmp(answer, filename)) {
struct stat st;
if (!stat(answer, &st)) {
i = do_yesno(0, 0, _("File exists, OVERWRITE ?"));
continue;
}
}
- i = write_file(answer, 0);
+#ifndef NANO_SMALL
+
+ /* Here's where we allow the selected text to be written to
+ a separate file. */
+ if (ISSET(MARK_ISSET) && !exiting) {
+ char *backup = NULL;
+ filestruct *fileagebak = fileage;
+ filestruct *filebotbak = filebot;
+ filestruct *cutback = cutbuffer;
+ int oldmod = 0;
+
+ /* Okay, since write_file changes the filename, back it up */
+ backup = mallocstrcpy(backup, filename);
+ if (ISSET(MODIFIED))
+ oldmod = 1;
+
+ /* Now, non-destructively add the marked text to the
+ cutbuffer, and write the file out using the cutbuffer ;) */
+ if (current->lineno < mark_beginbuf->lineno)
+ cut_marked_segment(current, current_x, mark_beginbuf,
+ mark_beginx, 0);
+ else
+ cut_marked_segment(mark_beginbuf, mark_beginx, current,
+ current_x, 0);
+ fileage = cutbuffer;
+ for (filebot = cutbuffer; filebot->next != NULL;
+ filebot = filebot->next)
+ ;
+ i = write_file(answer, 0, append);
+
+ /* Now restore everything */
+ backup = mallocstrcpy(filename, backup);
+ fileage = fileagebak;
+ filebot = filebotbak;
+ cutbuffer = cutback;
+ if (oldmod)
+ set_modified();
+ } else
+#endif
+ i = write_file(answer, 0, append);
+
display_main_list();
return i;
} else {
int do_writeout_void(void)
{
- return do_writeout(filename, 0);
+ return do_writeout(filename, 0, 0);
}
#ifndef DISABLE_TABCOMP
shortcut goto_list[GOTO_LIST_LEN];
shortcut gotodir_list[GOTODIR_LIST_LEN];
shortcut writefile_list[WRITEFILE_LIST_LEN];
+shortcut insertfile_list[INSERTFILE_LIST_LEN];
shortcut help_list[HELP_LIST_LEN];
shortcut spell_list[SPELL_LIST_LEN];
#ifndef DISABLE_BROWSER
"", *nano_mark_msg = "", *nano_delete_msg =
"", *nano_backspace_msg = "", *nano_tab_msg =
"", *nano_enter_msg = "", *nano_case_msg =
- "", *nano_cancel_msg = "", *nano_unjustify_msg = "";
+ "", *nano_cancel_msg = "", *nano_unjustify_msg =
+ "", *nano_append_msg = "";
#ifndef NANO_SMALL
char *nano_tofiles_msg = "";
nano_tofiles_msg = _("Go to file browser");
nano_gotodir_msg = _("Goto Directory");
nano_cancel_msg = _("Cancel the current function");
+ nano_append_msg = _("Append to the current file");
#endif
sc_init_one(&main_list[0], NANO_HELP_KEY, _("Get Help"),
nano_tofiles_msg, 0, 0, 0, NOVIEW, 0);
#endif
+ sc_init_one(&writefile_list[WRITEFILE_LIST_LEN - 2], NANO_APPEND_KEY, _("Append"),
+ nano_append_msg, 0, 0, 0, NOVIEW, 0);
+
sc_init_one(&writefile_list[WRITEFILE_LIST_LEN - 1], NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0);
+#ifndef DISABLE_BROWSER
+ sc_init_one(&insertfile_list[0], NANO_TOFILES_KEY, _("To Files"),
+ nano_tofiles_msg, 0, 0, 0, NOVIEW, 0);
+#endif
+
+ sc_init_one(&insertfile_list[INSERTFILE_LIST_LEN - 1], NANO_CANCEL_KEY, _("Cancel"),
+ nano_cancel_msg, 0, 0, 0, VIEW, 0);
+
sc_init_one(&spell_list[0], NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0);
#endif
if (i == 1) {
- if (do_writeout(filename, 1) > 0)
+ if (do_writeout(filename, 1, 0) > 0)
finish(0);
} else if (i == 0)
finish(0);
#define NANO_ENTER_KEY NANO_CONTROL_M
#define NANO_FROMSEARCHTOGOTO_KEY NANO_CONTROL_T
#define NANO_TOFILES_KEY NANO_CONTROL_T
+#define NANO_APPEND_KEY NANO_CONTROL_A
#define TOGGLE_CONST_KEY NANO_ALT_C
#define TOGGLE_AUTOINDENT_KEY NANO_ALT_I
#define SPELL_LIST_LEN 1
#ifndef DISABLE_BROWSER
-#define WRITEFILE_LIST_LEN 2
+#define WRITEFILE_LIST_LEN 3
+#define INSERTFILE_LIST_LEN 2
#define BROWSER_LIST_LEN 4
#else
-#define WRITEFILE_LIST_LEN 1
+#define WRITEFILE_LIST_LEN 3
+#define IMSERTFILE_LIST_LEN 1
#endif
#ifdef HAVE_REGEX_H
extern shortcut *shortcut_list;
extern shortcut main_list[MAIN_LIST_LEN], whereis_list[WHEREIS_LIST_LEN];
extern shortcut replace_list[REPLACE_LIST_LEN], goto_list[GOTO_LIST_LEN];
-extern shortcut writefile_list[WRITEFILE_LIST_LEN], help_list[HELP_LIST_LEN];
+extern shortcut writefile_list[WRITEFILE_LIST_LEN], insertfile_list[INSERTFILE_LIST_LEN];
extern shortcut spell_list[SPELL_LIST_LEN], replace_list_2[REPLACE_LIST_LEN];
+extern shortcut help_list[HELP_LIST_LEN];
#ifndef DISABLE_BROWSER
extern shortcut browser_list[BROWSER_LIST_LEN], gotodir_list[GOTODIR_LIST_LEN];
#endif
int actual_x(filestruct * fileptr, int xplus);
int strlenpt(char *buf);
int statusq(int allowtabs, shortcut s[], int slen, char *def, char *msg, ...);
-int write_file(char *name, int tmpfile);
+int write_file(char *name, int tmpfile, int append);
int do_cut_text(void);
int do_uncut_text(void);
int no_help(void);
int renumber_all(void);
int open_file(char *filename, int insert, int quiet);
-int do_writeout(char *path, int exiting);
+int do_writeout(char *path, int exiting, int append);
int do_gotoline(long defline);
int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
int wholewords, int *i);
void window_init(void);
void do_mouse(void);
void print_view_warning(void);
+void cut_marked_segment(filestruct * top, int top_x, filestruct * bot,
+ int bot_x, int destructive);
#ifdef ENABLE_NANORC
void do_rcfile(void);