mirror of
git://git.sv.gnu.org/nano.git
synced 2025-01-11 11:59:24 +03:00
add restricted mode, per IO ERROR's patch
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1723 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
e5b2f83031
commit
d893fa946d
33
ChangeLog
33
ChangeLog
@ -9,14 +9,42 @@ CVS code -
|
||||
- Add better explanations for and in the "Terminal breakage"
|
||||
comments, and handle missing key #ifdefs inside the functions
|
||||
that use those keys. (DLR)
|
||||
- Add restricted mode, accessible via the -Z/--restricted
|
||||
command line option or by invoking nano with any name
|
||||
beginning with 'r' (e.g. "rnano"). In restricted mode, nano
|
||||
will not read or write to any file not specified on the
|
||||
command line, read any nanorc files, allow suspending, or
|
||||
allow a file to be appended to, prepended to, or saved under a
|
||||
different name if it already has one. (IO ERROR) DLR: Also
|
||||
disable backup files and spell checking (since the latter can
|
||||
leave a pre-spell-checked version of the file in a temporary
|
||||
directory), use tail() to get the program name so that the
|
||||
check for its beginning with 'r' will work when a path is
|
||||
specified, disable toggles that are only useful with options
|
||||
that are disabled in restricted mode, call nano_disabled_msg()
|
||||
when trying to read or spell check a file instead of leaving
|
||||
the shortcuts out of the main list, and instead of acting as
|
||||
though TEMP_OPT is enabled when exiting with a modified file
|
||||
(which caused problems if the filename was blank), only allow
|
||||
a filename to be modified at the writeout prompt if it's blank
|
||||
beforehand. Changes to do_writeout(), toggle_init(),
|
||||
shortcut_init(), die_save_file(), and nanogetstr().
|
||||
- Call nano_disabled_msg() directly from the shortcut list
|
||||
instead of inside the disabled functions. (David Benbennick)
|
||||
- files.c:
|
||||
add_open_file()
|
||||
- Rearrange the NANO_SMALL #ifdef so that the code to set the
|
||||
MODIFIED flag in open_files->flags is included only once.
|
||||
(DLR)
|
||||
do_writeout()
|
||||
- Refactor so that no recursion is needed if we try to exit with
|
||||
a modified file that has no name when TEMP_OPT is set. (DLR)
|
||||
- nano.c:
|
||||
do_delete()
|
||||
- Tweak for efficiency. (David Benbennick)
|
||||
do_exit()
|
||||
- Refactor so that no recursion is needed if we try to exit with
|
||||
a modified file that has no name when TEMP_OPT is set. (DLR)
|
||||
print_numlock_warning()
|
||||
- Removed, as it's no longer needed and was never called
|
||||
anywhere after the input overhaul. (DLR)
|
||||
@ -72,9 +100,14 @@ CVS code -
|
||||
- Use napms() instead of nanosleep(), as it does the same thing
|
||||
(aside from taking an argument in milliseconds instead of
|
||||
microseconds) and curses includes it. (DLR)
|
||||
- nano.1:
|
||||
- Document restricted mode. (IO ERROR) DLR: Add minor
|
||||
modifications to account for the above changes.
|
||||
- nano.texi:
|
||||
- Fix inaccuracies: Meta-L now toggles line wrapping, and Meta-<
|
||||
and Meta-> aren't toggles. (DLR)
|
||||
- Document restricted mode. (IO ERROR) DLR: Add minor
|
||||
modifications to account for the above changes.
|
||||
- faq.html:
|
||||
- Removed question about the NumLock glitch, as it's no longer
|
||||
needed. (DLR)
|
||||
|
@ -92,6 +92,13 @@ Specify a specific syntax highlighting from the
|
||||
.I .nanorc
|
||||
to use, if available.
|
||||
.TP
|
||||
.B \-Z (\-\-restricted)
|
||||
Restricted mode: Don't read or write to any file not specified on the
|
||||
command line, read any nanorc files, allow suspending, or allow a file
|
||||
to be appended to, prepended to, or saved under a different name if it
|
||||
already has one. Also accessible by invoking \fBnano\fP with any name
|
||||
beginning with 'r' (e.g. "rnano").
|
||||
.TP
|
||||
.B \-c (\-\-const)
|
||||
Constantly show the cursor position.
|
||||
.TP
|
||||
|
@ -157,6 +157,13 @@ Print the version number and copyright and quit.
|
||||
Specify a specific syntax highlighting from the .nanorc to use, if
|
||||
available.
|
||||
|
||||
@item -Z, --restricted
|
||||
Restricted mode: Don't read or write to any file not specified on the
|
||||
command line, read any nanorc files, allow suspending, or allow a file
|
||||
to be appended to, prepended to, or saved under a different name if it
|
||||
already has one. Also accessible by invoking @code{nano} with any name
|
||||
beginning with 'r' (e.g. "rnano").
|
||||
|
||||
@item -c, --const
|
||||
Constantly display the cursor position and line number on the statusbar.
|
||||
|
||||
|
32
src/files.c
32
src/files.c
@ -1808,24 +1808,12 @@ int do_writeout(int exiting)
|
||||
currshortcut = writefile_list;
|
||||
#endif
|
||||
|
||||
if (exiting && ISSET(TEMP_OPT)) {
|
||||
i = -1;
|
||||
if (filename[0] != '\0') {
|
||||
i = write_file(filename, FALSE, 0, FALSE);
|
||||
if (i == 1) {
|
||||
/* Write succeeded. */
|
||||
display_main_list();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* No filename or the write above failed. */
|
||||
if (i == -1) {
|
||||
UNSET(TEMP_OPT);
|
||||
do_exit();
|
||||
|
||||
/* They cancelled; abort quit. */
|
||||
return -1;
|
||||
if (exiting && filename[0] != '\0' && ISSET(TEMP_OPT)) {
|
||||
i = write_file(filename, FALSE, 0, FALSE);
|
||||
if (i == 1) {
|
||||
/* Write succeeded. */
|
||||
display_main_list();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1941,9 +1929,9 @@ int do_writeout(int exiting)
|
||||
i = do_yesno(FALSE, _("File exists, OVERWRITE ?"));
|
||||
if (i == 0 || i == -1)
|
||||
continue;
|
||||
} else if (filename[0] != '\0'
|
||||
} else if (!ISSET(RESTRICTED) && filename[0] != '\0'
|
||||
#ifndef NANO_SMALL
|
||||
&& (!ISSET(MARK_ISSET) || exiting)
|
||||
&& (exiting || !ISSET(MARK_ISSET))
|
||||
#endif
|
||||
) {
|
||||
i = do_yesno(FALSE, _("Save file under DIFFERENT NAME ?"));
|
||||
@ -1955,7 +1943,7 @@ int do_writeout(int exiting)
|
||||
#ifndef NANO_SMALL
|
||||
/* Here's where we allow the selected text to be written to
|
||||
* a separate file. */
|
||||
if (ISSET(MARK_ISSET) && !exiting)
|
||||
if (!ISSET(RESTRICTED) && !exiting && ISSET(MARK_ISSET))
|
||||
i = write_marked(answer, FALSE, append, FALSE);
|
||||
else
|
||||
#endif /* !NANO_SMALL */
|
||||
@ -2432,7 +2420,6 @@ char *input_tab(char *buf, int place, int *lastwastab, int *newplace, int *list)
|
||||
}
|
||||
#endif /* !DISABLE_TABCOMP */
|
||||
|
||||
#if !defined(DISABLE_BROWSER) || !defined(NANO_SMALL)
|
||||
/* Only print the last part of a path; isn't there a shell
|
||||
* command for this? */
|
||||
const char *tail(const char *foo)
|
||||
@ -2447,7 +2434,6 @@ const char *tail(const char *foo)
|
||||
|
||||
return tmp;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef DISABLE_BROWSER
|
||||
/* Our sort routine for file listings -- sort directories before
|
||||
|
155
src/global.c
155
src/global.c
@ -275,7 +275,8 @@ void toggle_init(void)
|
||||
|
||||
toggle_init_one(TOGGLE_NOHELP_KEY, toggle_nohelp_msg, NO_HELP);
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
toggle_init_one(TOGGLE_MULTIBUFFER_KEY, toggle_multibuffer_msg, MULTIBUFFER);
|
||||
if (!ISSET(RESTRICTED))
|
||||
toggle_init_one(TOGGLE_MULTIBUFFER_KEY, toggle_multibuffer_msg, MULTIBUFFER);
|
||||
#endif
|
||||
toggle_init_one(TOGGLE_CONST_KEY, toggle_const_msg, CONSTUPDATE);
|
||||
toggle_init_one(TOGGLE_AUTOINDENT_KEY, toggle_autoindent_msg, AUTOINDENT);
|
||||
@ -283,14 +284,17 @@ void toggle_init(void)
|
||||
toggle_init_one(TOGGLE_WRAP_KEY, toggle_wrap_msg, NO_WRAP);
|
||||
#endif
|
||||
toggle_init_one(TOGGLE_CUTTOEND_KEY, toggle_cuttoend_msg, CUT_TO_END);
|
||||
toggle_init_one(TOGGLE_SUSPEND_KEY, toggle_suspend_msg, SUSPEND);
|
||||
if (!ISSET(RESTRICTED))
|
||||
toggle_init_one(TOGGLE_SUSPEND_KEY, toggle_suspend_msg, SUSPEND);
|
||||
#ifndef DISABLE_MOUSE
|
||||
toggle_init_one(TOGGLE_MOUSE_KEY, toggle_mouse_msg, USE_MOUSE);
|
||||
#endif
|
||||
toggle_init_one(TOGGLE_NOCONVERT_KEY, toggle_noconvert_msg, NO_CONVERT);
|
||||
toggle_init_one(TOGGLE_DOS_KEY, toggle_dos_msg, DOS_FILE);
|
||||
toggle_init_one(TOGGLE_MAC_KEY, toggle_mac_msg, MAC_FILE);
|
||||
toggle_init_one(TOGGLE_BACKUP_KEY, toggle_backup_msg, BACKUP_FILE);
|
||||
if (!ISSET(RESTRICTED)) {
|
||||
toggle_init_one(TOGGLE_NOCONVERT_KEY, toggle_noconvert_msg, NO_CONVERT);
|
||||
toggle_init_one(TOGGLE_DOS_KEY, toggle_dos_msg, DOS_FILE);
|
||||
toggle_init_one(TOGGLE_MAC_KEY, toggle_mac_msg, MAC_FILE);
|
||||
toggle_init_one(TOGGLE_BACKUP_KEY, toggle_backup_msg, BACKUP_FILE);
|
||||
}
|
||||
toggle_init_one(TOGGLE_SMOOTH_KEY, toggle_smooth_msg, SMOOTHSCROLL);
|
||||
#ifdef ENABLE_COLOR
|
||||
toggle_init_one(TOGGLE_SYNTAX_KEY, toggle_syntax_msg, COLOR_SYNTAX);
|
||||
@ -437,7 +441,13 @@ void shortcut_init(int unjustify)
|
||||
/* Translators: try to keep this string under 10 characters long */
|
||||
sc_init_one(&main_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
if (open_files != NULL && (open_files->prev != NULL || open_files->next != NULL))
|
||||
@ -461,7 +471,13 @@ void shortcut_init(int unjustify)
|
||||
/* Translators: try to keep this string under 10 characters long */
|
||||
sc_init_one(&main_list, NANO_JUSTIFY_KEY, _("Justify"),
|
||||
IFHELP(nano_justify_msg, NANO_NO_KEY),
|
||||
NANO_JUSTIFY_FKEY, NANO_NO_KEY, NOVIEW, do_justify);
|
||||
NANO_JUSTIFY_FKEY, NANO_NO_KEY, NOVIEW,
|
||||
#ifndef NANO_SMALL
|
||||
do_justify
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
/* this is so we can view multiple files */
|
||||
/* Translators: try to keep this string under 10 characters long */
|
||||
@ -473,7 +489,7 @@ void shortcut_init(int unjustify)
|
||||
#else
|
||||
NOVIEW
|
||||
#endif
|
||||
, do_insertfile_void);
|
||||
, !ISSET(RESTRICTED) ? do_insertfile_void : nano_disabled_msg);
|
||||
|
||||
/* Translators: try to keep this string under 10 characters long */
|
||||
sc_init_one(&main_list, NANO_WHEREIS_KEY, _("Where Is"),
|
||||
@ -514,7 +530,11 @@ void shortcut_init(int unjustify)
|
||||
/* Translators: try to keep this string under 10 characters long */
|
||||
sc_init_one(&main_list, NANO_SPELL_KEY, _("To Spell"),
|
||||
IFHELP(nano_spell_msg, NANO_NO_KEY), NANO_SPELL_FKEY,
|
||||
NANO_NO_KEY, NOVIEW, do_spell);
|
||||
NANO_NO_KEY, NOVIEW,
|
||||
#ifndef DISABLE_SPELLER
|
||||
!ISSET(RESTRICTED) ? do_spell :
|
||||
#endif
|
||||
nano_disabled_msg);
|
||||
|
||||
sc_init_one(&main_list, NANO_GOTO_KEY, _("Go To Line"),
|
||||
IFHELP(nano_goto_msg, NANO_ALT_GOTO_KEY), NANO_GOTO_FKEY,
|
||||
@ -554,7 +574,13 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&main_list, NANO_MARK_KEY, _("Mark Text"),
|
||||
IFHELP(nano_mark_msg, NANO_ALT_MARK_KEY),
|
||||
NANO_NO_KEY, NANO_NO_KEY, NOVIEW, do_mark);
|
||||
NANO_NO_KEY, NANO_NO_KEY, NOVIEW,
|
||||
#ifndef NANO_SMALL
|
||||
do_mark
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
sc_init_one(&main_list, NANO_DELETE_KEY, _("Delete"),
|
||||
IFHELP(nano_delete_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
@ -610,7 +636,13 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&whereis_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
/* Translators: try to keep this string under 10 characters long */
|
||||
sc_init_one(&whereis_list, NANO_CANCEL_KEY, _("Cancel"),
|
||||
@ -680,7 +712,13 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&replace_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
sc_init_one(&replace_list, NANO_CANCEL_KEY, _("Cancel"),
|
||||
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
@ -727,7 +765,13 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&replace_list_2, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
sc_init_one(&replace_list_2, NANO_CANCEL_KEY, _("Cancel"),
|
||||
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
@ -751,7 +795,13 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&goto_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
sc_init_one(&goto_list, NANO_CANCEL_KEY, _("Cancel"),
|
||||
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
@ -785,40 +835,52 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&writefile_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
#ifndef DISABLE_BROWSER
|
||||
/* Translators: try to keep this string under 16 characters long */
|
||||
sc_init_one(&writefile_list, NANO_TOFILES_KEY, _("To Files"),
|
||||
if (!ISSET(RESTRICTED))
|
||||
sc_init_one(&writefile_list, NANO_TOFILES_KEY, _("To Files"),
|
||||
IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, NOVIEW, 0);
|
||||
#endif
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Translators: try to keep this string under 16 characters long */
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("DOS Format"),
|
||||
if (!ISSET(RESTRICTED))
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("DOS Format"),
|
||||
IFHELP(nano_dos_msg, TOGGLE_DOS_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, NOVIEW, 0);
|
||||
|
||||
/* Translators: try to keep this string under 16 characters long */
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("Mac Format"),
|
||||
if (!ISSET(RESTRICTED))
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("Mac Format"),
|
||||
IFHELP(nano_mac_msg, TOGGLE_MAC_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, NOVIEW, 0);
|
||||
#endif
|
||||
|
||||
/* Translators: try to keep this string under 16 characters long */
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("Append"),
|
||||
if (!ISSET(RESTRICTED))
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("Append"),
|
||||
IFHELP(nano_append_msg, NANO_APPEND_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, NOVIEW, 0);
|
||||
|
||||
/* Translators: try to keep this string under 16 characters long */
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("Prepend"),
|
||||
if (!ISSET(RESTRICTED))
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("Prepend"),
|
||||
IFHELP(nano_prepend_msg, NANO_PREPEND_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, NOVIEW, 0);
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Translators: try to keep this string under 16 characters long */
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("Backup File"),
|
||||
if (!ISSET(RESTRICTED))
|
||||
sc_init_one(&writefile_list, NANO_NO_KEY, _("Backup File"),
|
||||
IFHELP(nano_backup_msg, TOGGLE_BACKUP_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, NOVIEW, 0);
|
||||
#endif
|
||||
@ -831,27 +893,36 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&insertfile_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
sc_init_one(&insertfile_list, NANO_CANCEL_KEY, _("Cancel"),
|
||||
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, VIEW, 0);
|
||||
|
||||
#ifndef DISABLE_BROWSER
|
||||
sc_init_one(&insertfile_list, NANO_TOFILES_KEY, _("To Files"),
|
||||
if (!ISSET(RESTRICTED))
|
||||
sc_init_one(&insertfile_list, NANO_TOFILES_KEY, _("To Files"),
|
||||
IFHELP(nano_tofiles_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, NOVIEW, 0);
|
||||
#endif
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* Translators: try to keep this string under 22 characters long */
|
||||
sc_init_one(&insertfile_list, NANO_EXTCMD_KEY, _("Execute Command"),
|
||||
if (!ISSET(RESTRICTED))
|
||||
sc_init_one(&insertfile_list, NANO_EXTCMD_KEY, _("Execute Command"),
|
||||
IFHELP(nano_execute_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, NOVIEW, 0);
|
||||
|
||||
#ifdef ENABLE_MULTIBUFFER
|
||||
/* Translators: try to keep this string under 22 characters long */
|
||||
sc_init_one(&insertfile_list, NANO_NO_KEY, _("New Buffer"),
|
||||
if (!ISSET(RESTRICTED))
|
||||
sc_init_one(&insertfile_list, NANO_NO_KEY, _("New Buffer"),
|
||||
IFHELP(nano_multibuffer_msg, TOGGLE_MULTIBUFFER_KEY), NANO_NO_KEY,
|
||||
NANO_NO_KEY, NOVIEW, 0);
|
||||
#endif
|
||||
@ -862,7 +933,13 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&spell_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
sc_init_one(&spell_list, NANO_CANCEL_KEY, _("Cancel"),
|
||||
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
@ -874,7 +951,13 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&extcmd_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
sc_init_one(&extcmd_list, NANO_CANCEL_KEY, _("Cancel"),
|
||||
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
@ -886,7 +969,13 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&browser_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
sc_init_one(&browser_list, NANO_CANCEL_KEY, _("Cancel"),
|
||||
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
@ -909,7 +998,13 @@ void shortcut_init(int unjustify)
|
||||
|
||||
sc_init_one(&gotodir_list, NANO_HELP_KEY, _("Get Help"),
|
||||
IFHELP(nano_help_msg, NANO_NO_KEY), NANO_HELP_FKEY,
|
||||
NANO_NO_KEY, VIEW, do_help);
|
||||
NANO_NO_KEY, VIEW,
|
||||
#ifndef DISABLE_HELP
|
||||
do_help
|
||||
#else
|
||||
nano_disabled_msg
|
||||
#endif
|
||||
);
|
||||
|
||||
sc_init_one(&gotodir_list, NANO_CANCEL_KEY, _("Cancel"),
|
||||
IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY,
|
||||
|
50
src/nano.c
50
src/nano.c
@ -151,6 +151,10 @@ void die_save_file(const char *die_filename)
|
||||
char *ret;
|
||||
int i = -1;
|
||||
|
||||
/* No emergency files in restricted mode! */
|
||||
if (ISSET(RESTRICTED))
|
||||
return;
|
||||
|
||||
/* If we can't save, we have REAL bad problems, but we might as well
|
||||
TRY. */
|
||||
if (die_filename[0] == '\0')
|
||||
@ -656,6 +660,7 @@ void usage(void)
|
||||
#ifdef ENABLE_COLOR
|
||||
print1opt(_("-Y [str]"), _("--syntax [str]"), _("Syntax definition to use"));
|
||||
#endif
|
||||
print1opt(_("-Z"), _("--restricted"), _("Restricted mode"));
|
||||
print1opt("-c", "--const", _("Constantly show cursor position"));
|
||||
#ifndef NANO_SMALL
|
||||
print1opt("-d", "--rebinddelete", _("Fix Backspace/Delete confusion problem"));
|
||||
@ -765,12 +770,11 @@ int no_help(void)
|
||||
return ISSET(NO_HELP) ? 2 : 0;
|
||||
}
|
||||
|
||||
#if defined(DISABLE_JUSTIFY) || defined(DISABLE_SPELLER) || defined(DISABLE_HELP) || defined(NANO_SMALL)
|
||||
void nano_disabled_msg(void)
|
||||
int nano_disabled_msg(void)
|
||||
{
|
||||
statusbar(_("Sorry, support for this function has been disabled"));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
static int pid; /* This is the PID of the newly forked process
|
||||
@ -1231,13 +1235,9 @@ int do_prev_word(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* !NANO_SMALL */
|
||||
|
||||
int do_mark(void)
|
||||
{
|
||||
#ifdef NANO_SMALL
|
||||
nano_disabled_msg();
|
||||
#else
|
||||
TOGGLE(MARK_ISSET);
|
||||
if (ISSET(MARK_ISSET)) {
|
||||
statusbar(_("Mark Set"));
|
||||
@ -1247,9 +1247,9 @@ int do_mark(void)
|
||||
statusbar(_("Mark UNset"));
|
||||
edit_refresh();
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
#endif /* !NANO_SMALL */
|
||||
|
||||
#ifndef DISABLE_WRAPPING
|
||||
void wrap_reset(void)
|
||||
@ -1829,14 +1829,9 @@ char *do_alt_speller(char *tempfile_name)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
int do_spell(void)
|
||||
{
|
||||
#ifdef DISABLE_SPELLER
|
||||
nano_disabled_msg();
|
||||
return 1;
|
||||
#else
|
||||
int i;
|
||||
char *temp, *spell_msg;
|
||||
|
||||
@ -1879,8 +1874,8 @@ int do_spell(void)
|
||||
|
||||
statusbar(_("Finished checking spelling"));
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
#endif /* !DISABLE_SPELLER */
|
||||
|
||||
#if !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY)
|
||||
/* The "indentation" of a line is the white-space between the quote part
|
||||
@ -2404,15 +2399,10 @@ int do_para_end(void)
|
||||
{
|
||||
return do_para_search(2, NULL, NULL, NULL, TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Justify a paragraph. */
|
||||
int do_justify(void)
|
||||
{
|
||||
#ifdef DISABLE_JUSTIFY
|
||||
nano_disabled_msg();
|
||||
return 1;
|
||||
#else
|
||||
size_t quote_len;
|
||||
/* Length of the initial quotation of the paragraph we
|
||||
* justify. */
|
||||
@ -2706,8 +2696,8 @@ int do_justify(void)
|
||||
display_main_list();
|
||||
|
||||
return 0;
|
||||
#endif /* !DISABLE_JUSTIFY */
|
||||
}
|
||||
#endif /* !DISABLE_JUSTIFY */
|
||||
|
||||
int do_exit(void)
|
||||
{
|
||||
@ -3088,6 +3078,7 @@ int main(int argc, char *argv[])
|
||||
{"mac", 0, 0, 'M'},
|
||||
{"noconvert", 0, 0, 'N'},
|
||||
{"smooth", 0, 0, 'S'},
|
||||
{"restricted", 0, 0, 'Z'},
|
||||
{"autoindent", 0, 0, 'i'},
|
||||
{"cut", 0, 0, 'k'},
|
||||
#endif
|
||||
@ -3109,11 +3100,11 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
while ((optchr = getopt_long(argc, argv, "h?BDE:FHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz",
|
||||
while ((optchr = getopt_long(argc, argv, "h?BDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz",
|
||||
long_options, NULL)) != -1) {
|
||||
#else
|
||||
while ((optchr =
|
||||
getopt(argc, argv, "h?BDE:FHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz")) != -1) {
|
||||
getopt(argc, argv, "h?BDE:FHIMNQ:RST:VY:Zabcdefgijklmo:pr:s:tvwxz")) != -1) {
|
||||
#endif
|
||||
|
||||
switch (optchr) {
|
||||
@ -3201,6 +3192,9 @@ int main(int argc, char *argv[])
|
||||
syntaxstr = mallocstrcpy(syntaxstr, optarg);
|
||||
break;
|
||||
#endif
|
||||
case 'Z':
|
||||
SET(RESTRICTED);
|
||||
break;
|
||||
case 'c':
|
||||
SET(CONSTUPDATE);
|
||||
break;
|
||||
@ -3275,6 +3269,18 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
/* If filename starts with 'r', we use restricted mode. */
|
||||
if (*(tail(argv[0])) == 'r')
|
||||
SET(RESTRICTED);
|
||||
|
||||
/* If we're using restricted mode, disable suspending, backup files,
|
||||
* and reading rcfiles. */
|
||||
if (ISSET(RESTRICTED)) {
|
||||
UNSET(SUSPEND);
|
||||
UNSET(BACKUP_FILE);
|
||||
SET(NO_RCFILE);
|
||||
}
|
||||
|
||||
/* We've read through the command line options. Now back up the flags
|
||||
and values that are set, and read the rcfile(s). If the values
|
||||
haven't changed afterward, restore the backed-up values. */
|
||||
|
@ -268,6 +268,7 @@ typedef struct historyheadtype {
|
||||
#define PRESERVE (1<<27)
|
||||
#define HISTORY_CHANGED (1<<28)
|
||||
#define HISTORYLOG (1<<29)
|
||||
#define RESTRICTED (1<<30)
|
||||
|
||||
/* Control key sequences, changing these would be very very bad. */
|
||||
#define NANO_CONTROL_SPACE 0
|
||||
|
12
src/proto.h
12
src/proto.h
@ -199,9 +199,7 @@ char **username_tab_completion(char *buf, int *num_matches);
|
||||
char **cwd_tab_completion(char *buf, int *num_matches);
|
||||
char *input_tab(char *buf, int place, int *lastwastab, int *newplace, int *list);
|
||||
#endif
|
||||
#if !defined(DISABLE_BROWSER) || !defined(NANO_SMALL)
|
||||
const char *tail(const char *foo);
|
||||
#endif
|
||||
#ifndef DISABLE_BROWSER
|
||||
int diralphasort(const void *va, const void *vb);
|
||||
void free_charptrarray(char **array, int len);
|
||||
@ -272,9 +270,7 @@ void usage(void);
|
||||
void version(void);
|
||||
void do_early_abort(void);
|
||||
int no_help(void);
|
||||
#if defined(DISABLE_JUSTIFY) || defined(DISABLE_SPELLER) || defined(DISABLE_HELP) || defined(NANO_SMALL)
|
||||
void nano_disabled_msg(void);
|
||||
#endif
|
||||
int nano_disabled_msg(void);
|
||||
#ifndef NANO_SMALL
|
||||
RETSIGTYPE cancel_fork(int signal);
|
||||
int open_pipe(const char *command);
|
||||
@ -291,8 +287,8 @@ int do_enter(void);
|
||||
#ifndef NANO_SMALL
|
||||
int do_next_word(void);
|
||||
int do_prev_word(void);
|
||||
#endif
|
||||
int do_mark(void);
|
||||
#endif
|
||||
#ifndef DISABLE_WRAPPING
|
||||
void wrap_reset(void);
|
||||
int do_wrap(filestruct *inptr);
|
||||
@ -301,8 +297,8 @@ int do_wrap(filestruct *inptr);
|
||||
int do_int_spell_fix(const char *word);
|
||||
char *do_int_speller(char *tempfile_name);
|
||||
char *do_alt_speller(char *tempfile_name);
|
||||
#endif
|
||||
int do_spell(void);
|
||||
#endif
|
||||
#if !defined(DISABLE_WRAPPING) && !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY)
|
||||
size_t indent_length(const char *line);
|
||||
#endif
|
||||
@ -330,8 +326,8 @@ int do_para_search(int search_type, size_t *quote, size_t *par, size_t
|
||||
*indent, int do_refresh);
|
||||
int do_para_begin(void);
|
||||
int do_para_end(void);
|
||||
#endif /* !DISABLE_JUSTIFY */
|
||||
int do_justify(void);
|
||||
#endif /* !DISABLE_JUSTIFY */
|
||||
int do_exit(void);
|
||||
void signal_init(void);
|
||||
RETSIGTYPE handle_hupterm(int signal);
|
||||
|
35
src/winio.c
35
src/winio.c
@ -1311,22 +1311,28 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
|
||||
x++;
|
||||
break;
|
||||
case NANO_DELETE_KEY:
|
||||
if (x < xend) {
|
||||
charmove(answer + x, answer + x + 1, xend - x);
|
||||
xend--;
|
||||
if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) {
|
||||
if (x < xend) {
|
||||
charmove(answer + x, answer + x + 1, xend - x);
|
||||
xend--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NANO_CUT_KEY:
|
||||
case NANO_UNCUT_KEY:
|
||||
null_at(&answer, 0);
|
||||
xend = 0;
|
||||
x = 0;
|
||||
if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) {
|
||||
null_at(&answer, 0);
|
||||
xend = 0;
|
||||
x = 0;
|
||||
}
|
||||
break;
|
||||
case NANO_BACKSPACE_KEY:
|
||||
if (x > 0) {
|
||||
charmove(answer + x - 1, answer + x, xend - x + 1);
|
||||
x--;
|
||||
xend--;
|
||||
if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) {
|
||||
if (x > 0) {
|
||||
charmove(answer + x - 1, answer + x, xend - x + 1);
|
||||
x--;
|
||||
xend--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NANO_TAB_KEY:
|
||||
@ -1465,7 +1471,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
|
||||
return kbinput;
|
||||
}
|
||||
|
||||
if (is_cntrl_char(kbinput))
|
||||
if (is_cntrl_char(kbinput) || (ISSET(RESTRICTED) && filename[0] != '\0' && s == writefile_list))
|
||||
break;
|
||||
answer = charealloc(answer, xend + 2);
|
||||
charmove(answer + x + 1, answer + x, xend - x + 1);
|
||||
@ -2471,11 +2477,11 @@ int line_len(const char *ptr)
|
||||
return j;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_HELP
|
||||
/* Our shortcut-list-compliant help function, which is better than
|
||||
* nothing, and dynamic! */
|
||||
int do_help(void)
|
||||
{
|
||||
#ifndef DISABLE_HELP
|
||||
int i, page = 0, kbinput = ERR, meta_key, no_more = 0;
|
||||
int no_help_flag = 0;
|
||||
const shortcut *oldshortcut;
|
||||
@ -2572,12 +2578,9 @@ int do_help(void)
|
||||
free(help_text);
|
||||
help_text = NULL;
|
||||
|
||||
#elif defined(DISABLE_HELP)
|
||||
nano_disabled_msg();
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* !DISABLE_HELP */
|
||||
|
||||
/* Highlight the current word being replaced or spell checked. We
|
||||
* expect word to have tabs and control characters expanded. */
|
||||
|
Loading…
Reference in New Issue
Block a user