From db7064b8e6f846d48df33eaa6ce4205819011c68 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 8 Apr 2014 18:59:30 +0000 Subject: [PATCH] Adding the command-line option --noread to treat any name on the command line as a new file. Patch by Hans Alves. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4754 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 8 ++++++++ src/files.c | 8 ++++---- src/nano.c | 9 +++++++-- src/nano.h | 3 ++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index b617d5a3..d837d36c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2014-04-08 Hans Alves + * nano.h, files.c, nano.c: Adding the command-line option --noread + to treat any name on the command line as a new file. This allows + nano to write to named pipes -- it will start with a blank buffer, + and will write to the pipe when the user saves the file. This way + nano can be used as an editor in combination with for instance gpg + without having to write sensitive data to disk first. + 2014-04-08 David Lawrence Ramsey * src/*.c: More editing of comment blocks and trimming of blank lines. diff --git a/src/files.c b/src/files.c index 7eb3f113..f876dd8c 100644 --- a/src/files.c +++ b/src/files.c @@ -328,10 +328,10 @@ void open_buffer(const char *filename, bool undoable) if (new_buffer) make_new_buffer(); - /* If the filename isn't blank, open the file. Otherwise, treat it - * as a new file. */ - rc = (filename[0] != '\0') ? open_file(filename, new_buffer, &f) : - -2; + /* If the filename isn't blank, and we are not in NOREAD_MODE, + * open the file. Otherwise, treat it as a new file. */ + rc = (filename[0] != '\0' && !ISSET(NOREAD_MODE)) ? + open_file(filename, new_buffer, &f) : -2; /* If we have a file, and we're loading into a new buffer, update * the filename. */ diff --git a/src/nano.c b/src/nano.c index c949ca08..67c97cac 100644 --- a/src/nano.c +++ b/src/nano.c @@ -916,6 +916,7 @@ void usage(void) #ifndef DISABLE_MOUSE print_opt("-m", "--mouse", N_("Enable the use of the mouse")); #endif + print_opt("-n", "--noread", N_("Do not read the file (only write it)")); #ifndef DISABLE_OPERATINGDIR print_opt(_("-o "), _("--operatingdir="), N_("Set operating directory")); @@ -2121,6 +2122,7 @@ int main(int argc, char **argv) #ifndef DISABLE_MOUSE {"mouse", 0, NULL, 'm'}, #endif + {"noread", 0, NULL, 'n'}, #ifndef DISABLE_OPERATINGDIR {"operatingdir", 1, NULL, 'o'}, #endif @@ -2193,11 +2195,11 @@ int main(int argc, char **argv) while ((optchr = #ifdef HAVE_GETOPT_LONG getopt_long(argc, argv, - "h?ABC:DEFGHIKLNOPQ:RST:UVWY:abcdefgijklmo:pqr:s:tuvwxz$", + "h?ABC:DEFGHIKLNOPQ:RST:UVWY:abcdefgijklmno:pqr:s:tuvwxz$", long_options, NULL) #else getopt(argc, argv, - "h?ABC:DEFGHIKLNOPQ:RST:UVWY:abcdefgijklmo:pqr:s:tuvwxz$") + "h?ABC:DEFGHIKLNOPQ:RST:UVWY:abcdefgijklmno:pqr:s:tuvwxz$") #endif ) != -1) { switch (optchr) { @@ -2325,6 +2327,9 @@ int main(int argc, char **argv) SET(USE_MOUSE); break; #endif + case 'n': + SET(NOREAD_MODE); + break; #ifndef DISABLE_OPERATINGDIR case 'o': operating_dir = mallocstrcpy(operating_dir, optarg); diff --git a/src/nano.h b/src/nano.h index 7976a6b4..6d51a2cf 100644 --- a/src/nano.h +++ b/src/nano.h @@ -532,7 +532,8 @@ enum UNDOABLE, SOFTWRAP, POS_HISTORY, - LOCKING + LOCKING, + NOREAD_MODE }; /* Flags for the menus in which a given function should be present. */