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
master
Benno Schulenberg 2014-04-08 18:59:30 +00:00
parent d19be5aafa
commit db7064b8e6
4 changed files with 21 additions and 7 deletions

View File

@ -1,3 +1,11 @@
2014-04-08 Hans Alves <fonsvandeachterburen@gmail.com>
* 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 <pooka109@gmail.com>
* src/*.c: More editing of comment blocks and trimming of blank lines.

View File

@ -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. */

View File

@ -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 <dir>"), _("--operatingdir=<dir>"),
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);

View File

@ -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. */