1
1

DLR's patch merged, Static toggles and shortcut gone, lots of stuff changed

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1073 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
Chris Allegretta 2002-02-15 19:17:02 +00:00
родитель 025a42c67f
Коммит a8c225787b
11 изменённых файлов: 643 добавлений и 417 удалений

Просмотреть файл

@ -1,15 +1,39 @@
CVS code -
- General
- malloc->calloc, etc cleanups (DLR).
- New option, noconvert (-N, --noconvert) to completely stop
the translation of files from DOS or Mac format (DLR).
- New functions wheck_writable_directory() and safe_tempnam()
to get around the tempnam warning. (DLR) Needs testing
- Added DOS and Mac format options to write file routine.
Changes to shortcut_init() and do_writeout().
- Removed stupid static definitions of toggles and shortcut
lists. Many changes to shortcut_init(), toggle_init(),
statusq(), nanogetstr(), main(), and many other places.
FIXME: Mouse support broken by this change.
- Makefile.am:
- Add SYSCONFDIR to DEFS, so we can have an /etc/nanorc.
- Change localedir line to 1.0's version.
- files.c:
read_byte()
- Added check for conrol characters (indicative of a binary
file), set NO_CONVERT if found.
- global.c:
- Move openprev and opennext functions to shortcuts, they really
aren't toggles (DLR).
- rcfile.c:
parse_next_rege()
parse_next_regex()
- Allow " symbol to be in regex without leading \ by checking
for *ptr+1 is not the end of the regex.
- nano.c:
help_init()
- Added message re: having multiple blank buffers (DLR).
- winio.c:
do_cursorpos()
- Rewritten to show col place as well as charcter place, without
needing an entirely separate flag.
bottombars(), onekey()
- Make bottom list dynamic with screen size (Guus Sliepen & Chris).
- utils.c:
strstrwrapper()
- NANO_SMALL test was backwards (Ken Tyler).

2
cut.c
Просмотреть файл

@ -232,7 +232,7 @@ int do_cut_text(void)
junk = NULL;
junk = make_new_node(current);
junk->data = nmalloc(1 * sizeof (char));
junk->data = charalloc(1);
junk->data[0] = 0;
add_to_cutbuffer(junk);

211
files.c
Просмотреть файл

@ -108,7 +108,6 @@ void new_file(void)
}
int read_byte(int fd, char *filename, char *input)
{
static char buf[BUFSIZ];
@ -141,8 +140,9 @@ filestruct *read_line(char *buf, filestruct * prev, int *line1ins)
strcpy(fileptr->data, buf);
#ifndef NANO_SMALL
/* If it's a DOS file (CRLF), strip out the CR part*/
if (buf[strlen(buf) - 1] == '\r') {
/* If it's a DOS file (CRLF), and file conversion isn't disabled,
strip out the CR part */
if (!ISSET(NO_CONVERT) && buf[strlen(buf) - 1] == '\r') {
fileptr->data[strlen(buf) - 1] = 0;
totsize--;
@ -179,7 +179,6 @@ filestruct *read_line(char *buf, filestruct * prev, int *line1ins)
return fileptr;
}
int read_file(int fd, char *filename, int quiet)
{
long size;
@ -211,8 +210,15 @@ int read_file(int fd, char *filename, int quiet)
buf[0] = 0;
i = 0;
#ifndef NANO_SMALL
/* If it's a Mac file (no LF just a CR), handle it! */
} else if (i > 0 && buf[i-1] == '\r') {
} else if (!ISSET(NO_CONVERT) && input[0] < 32
&& input[0] != '\r' && input[0] != '\n')
/* If the file has binary chars in it, don't stupidly
assume it's a DOS or Mac formatted file! */
SET(NO_CONVERT);
/* If it's a Mac file (no LF just a CR), and file conversion
isn't disabled, handle it! */
else if (!ISSET(NO_CONVERT) && i > 0 && buf[i-1] == '\r') {
fileformat = 2;
fileptr = read_line(buf, fileptr, &line1ins);
num_lines++;
@ -335,11 +341,9 @@ int do_insertfile(int loading_file)
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
currshortcut = insertfile_list;
currslen = INSERTFILE_LIST_LEN;
#endif
i = statusq(1, insertfile_list, INSERTFILE_LIST_LEN, "",
_("File to insert [from ./] "));
i = statusq(1, insertfile_list, "", _("File to insert [from ./] "));
if (i != -1) {
#ifdef DEBUG
@ -358,7 +362,6 @@ int do_insertfile(int loading_file)
char *tmp = do_browse_from(realname);
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
currshortcut = insertfile_list;
currslen = INSERTFILE_LIST_LEN;
#endif
#ifdef DISABLE_TABCOMP
@ -770,6 +773,13 @@ int open_prevfile(int closing_file)
return 0;
}
/* This function is used by the shortcut list. */
int open_prevfile_void(void)
{
open_prevfile(0);
return 0;
}
/*
* Open the next entry in the open_files structure. If closing_file is
* zero, update the current entry before switching from it. Otherwise, we
@ -825,6 +835,13 @@ int open_nextfile(int closing_file)
return 0;
}
/* This function is used by the shortcut list. */
int open_nextfile_void(void)
{
open_nextfile(0);
return 0;
}
/*
* Delete an entry from the open_files filestruct. After deletion of an
* entry, the next or previous entry is opened, whichever is found first.
@ -852,9 +869,9 @@ int close_open_file(void)
display_main_list();
return 0;
}
#endif
#endif /* MULTIBUFFER */
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_OPERATINGDIR)
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER) || !defined (DISABLE_OPERATINGDIR)
/*
* When passed "[relative path]" or "[relative path][filename]" in
* origpath, return "[full path]" or "[full path][filename]" on success,
@ -863,7 +880,7 @@ int close_open_file(void)
* yet on disk); it is not done if the relative path doesn't exist (since
* the first call to chdir() will fail then).
*/
char *get_full_path(char *origpath)
char *get_full_path(const char *origpath)
{
char *newpath = NULL, *last_slash, *d_here, *d_there, *d_there_file, tmp;
int path_only, last_slash_index;
@ -1003,7 +1020,127 @@ char *get_full_path(char *origpath)
return newpath;
}
#endif /* ENABLE_MULTIBUFFER || !DISABLE_OPERATINGDIR */
#endif /* ENABLE_MULTIBUFFER || !DISABLE_SPELLER || !DISABLE_OPERATINGDIR */
#ifndef DISABLE_SPELLER
/*
* This function accepts a path and a pointer to an integer, and returns
* the full path (via get_full_path()). It also sets the integer
* pointer's referenced value to 1 if the full path is writable, and 0
* otherwise. On error, it returns NULL, and sets the pointer's
* referenced value to 0.
*/
char *check_writable_directory(const char *path, int *writable) {
char *full_path = get_full_path(path);
struct stat fileinfo;
/* if get_full_path() failed, set *writable to 0 and return NULL */
if (!full_path) {
*writable = 0;
return NULL;
}
else {
/* otherwise, stat() the full path to see if it's writable by the
user; set *writable to 1 if it is, or 0 if it isn't */
stat(path, &fileinfo);
if (fileinfo.st_mode & S_IWUSR)
*writable = 1;
else
*writable = 0;
}
/* if the full path doesn't end in a slash (meaning get_full_path()
found that it isn't a directory) or isn't writable, return NULL */
if (full_path[strlen(full_path) - 1] != '/' || *writable == 0)
return NULL;
/* otherwise, return the full path */
return full_path;
}
/*
* This function accepts a directory name and filename prefix the same
* way that tempnam() does, determines the location for its temporary
* file the same way that tempnam() does, safely creates the temporary
* file there via mkstemp(), and returns the name of the temporary file
* the same way that tempnam() does.
*/
char *safe_tempnam(const char *dirname, const char *filename_prefix) {
char *buf, *tempdir = NULL, *full_tempdir = NULL;
int writable = 0, filedesc;
/* if $TMPDIR is set and non-empty, set tempdir to it, run it through
get_full_path(), and save the result in full_tempdir; otherwise,
leave full_tempdir set to to NULL */
if (getenv("TMPDIR") && strcmp(getenv("TMPDIR"),"")) {
/* store the value of $TMPDIR in tempdir, run its value through
get_full_path(), and save the result in full_tempdir */
tempdir = charalloc(strlen(getenv("TMPDIR")) + 1);
sprintf(tempdir, "%s", getenv("TMPDIR"));
full_tempdir = check_writable_directory(tempdir, &writable);
/* we don't need the value of tempdir anymore */
free(tempdir);
}
if (!full_tempdir) {
/* if $TMPDIR is blank or isn't set, or isn't a writable
directory, and dirname isn't NULL, try it; otherwise, leave
full_tempdir set to NULL */
if (dirname) {
tempdir = charalloc(strlen(dirname) + 1);
strcpy(tempdir, dirname);
full_tempdir = check_writable_directory(tempdir, &writable);
/* we don't need the value of tempdir anymore */
free(tempdir);
}
}
/* if $TMPDIR is blank or isn't set, or if it isn't a writable
directory, and dirname is NULL, try P_tmpdir instead */
if (!full_tempdir) {
tempdir = charalloc(strlen(P_tmpdir) + 1);
strcpy(tempdir, P_tmpdir);
full_tempdir = check_writable_directory(tempdir, &writable);
/* we don't need the value of tempdir anymore */
free(tempdir);
}
/* if P_tmpdir didn't work, use /tmp instead */
if (!full_tempdir) {
full_tempdir = charalloc(6);
strcpy(full_tempdir, "/tmp/");
}
buf = charalloc(strlen(full_tempdir) + 12);
sprintf(buf, "%s", full_tempdir);
/* like tempnam(), use only the first 5 characters of the prefix */
strncat(buf, filename_prefix, 5);
strcat(buf, "XXXXXX");
filedesc = mkstemp(buf);
/* if mkstemp() failed, get out */
if (filedesc == -1)
return NULL;
/* otherwise, close the resulting file; afterwards, it'll be 0 bytes
long, so delete it; finally, return the filename (all that's left
of it) */
else {
close(filedesc);
unlink(buf);
return buf;
}
}
#endif /* !DISABLE_SPELLER */
#ifndef DISABLE_OPERATINGDIR
/*
@ -1308,6 +1445,7 @@ int write_file(char *name, int tmp, int append, int nonamechange)
int do_writeout(char *path, int exiting, int append)
{
int i = 0;
char *formatstr;
#ifdef NANO_EXTRA
static int did_cred = 0;
@ -1315,7 +1453,6 @@ int do_writeout(char *path, int exiting, int append)
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
currshortcut = writefile_list;
currslen = WRITEFILE_LIST_LEN;
#endif
answer = mallocstrcpy(answer, path);
@ -1336,24 +1473,32 @@ int do_writeout(char *path, int exiting, int append)
while (1) {
/* Be nice to the translation folks */
#ifndef NANO_SMALL
if (ISSET(MAC_FILE))
formatstr = _(" [Mac Format]");
else if (ISSET(DOS_FILE))
formatstr = _(" [DOS Format]");
else
formatstr = "";
/* Be nice to the translation folks */
if (ISSET(MARK_ISSET) && !exiting) {
if (append)
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "",
_("Append Selection to File"));
i = statusq(1, writefile_list, "",
"%s%s", _("Append Selection to File"), formatstr);
else
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, "",
_("Write Selection to File"));
i = statusq(1, writefile_list, "",
"%s%s", _("Write Selection to File"), formatstr);
} else
#endif
{
if (append)
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer,
_("File Name to Append"));
i = statusq(1, writefile_list, answer,
"%s%s", _("File Name to Append"), formatstr);
else
i = statusq(1, writefile_list, WRITEFILE_LIST_LEN, answer,
_("File Name to Write"));
i = statusq(1, writefile_list, answer,
"%s%s", _("File Name to Write"), formatstr);
}
@ -1366,7 +1511,6 @@ int do_writeout(char *path, int exiting, int append)
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE)
currshortcut = writefile_list;
currslen = WRITEFILE_LIST_LEN;
#endif
if (tmp != NULL) {
@ -1375,7 +1519,15 @@ int do_writeout(char *path, int exiting, int append)
return do_writeout(answer, exiting, append);
} else
#endif
if (i == NANO_APPEND_KEY)
if (i == TOGGLE_DOS_KEY) {
UNSET(MAC_FILE);
TOGGLE(DOS_FILE);
return(do_writeout(answer, exiting, append));
} else if (i == TOGGLE_MAC_KEY) {
UNSET(DOS_FILE);
TOGGLE(MAC_FILE);
return(do_writeout(answer, exiting, append));
} else if (i == NANO_APPEND_KEY)
return(do_writeout(answer, exiting, 1 - append));
#ifdef DEBUG
@ -2101,7 +2253,7 @@ char *do_browser(char *inpath)
kb = keypad_on(edit, 1);
titlebar(path);
bottombars(browser_list, BROWSER_LIST_LEN);
bottombars(browser_list);
curs_set(0);
wmove(edit, 0, 0);
i = 0;
@ -2116,7 +2268,6 @@ char *do_browser(char *inpath)
#if !defined DISABLE_HELP || !defined(DISABLE_MOUSE)
currshortcut = browser_list;
currslen = BROWSER_LIST_LEN;
#endif
editline = 0;
@ -2287,8 +2438,8 @@ char *do_browser(char *inpath)
case NANO_GOTO_KEY:
curs_set(1);
j = statusq(0, gotodir_list, GOTODIR_LIST_LEN, "", _("Goto Directory"));
bottombars(browser_list, BROWSER_LIST_LEN);
j = statusq(0, gotodir_list, "", _("Goto Directory"));
bottombars(browser_list);
curs_set(0);
#ifndef DISABLE_OPERATINGDIR

355
global.c
Просмотреть файл

@ -84,18 +84,18 @@ char *operating_dir = NULL; /* Operating directory, which we can't go
char *alt_speller; /* Alternative spell command */
#endif
shortcut main_list[MAIN_LIST_LEN];
shortcut whereis_list[WHEREIS_LIST_LEN];
shortcut replace_list[REPLACE_LIST_LEN];
shortcut replace_list_2[REPLACE_LIST_LEN]; /* 2nd half of replace dialog */
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];
shortcut *main_list = NULL;
shortcut *whereis_list = NULL;
shortcut *replace_list = NULL;
shortcut *replace_list_2; /* 2nd half of replace dialog */
shortcut *goto_list = NULL;
shortcut *gotodir_list = NULL;
shortcut *writefile_list = NULL;
shortcut *insertfile_list = NULL;
shortcut *help_list = NULL;
shortcut *spell_list = NULL;
#ifndef DISABLE_BROWSER
shortcut browser_list[BROWSER_LIST_LEN];
shortcut *browser_list = NULL;
#endif
#ifdef ENABLE_COLOR
@ -104,12 +104,11 @@ shortcut browser_list[BROWSER_LIST_LEN];
#endif
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
shortcut *currshortcut = main_list; /* Current shortcut list we're using */
int currslen = MAIN_VISIBLE; /* Length of current shortcut list */
shortcut *currshortcut; /* Current shortcut list we're using */
#endif
#ifndef NANO_SMALL
toggle toggles[TOGGLE_LEN];
toggle *toggles = NULL;
#endif
/* Regular expressions */
@ -120,10 +119,33 @@ regmatch_t regmatches[10]; /* Match positions for parenthetical
subexpressions, max of 10 */
#endif
int length_of_list(shortcut *s)
{
int i = 0;
shortcut *t;
for (t = s; t != NULL; t = t->next)
i++;
return i;
}
/* Initialize a struct *without* our lovely braces =( */
void sc_init_one(shortcut * s, int key, char *desc, char *help, int alt,
void sc_init_one(shortcut **shortcutage, int key, char *desc, char *help, int alt,
int misc1, int misc2, int view, int (*func) (void))
{
shortcut *s;
if (*shortcutage == NULL) {
*shortcutage = nmalloc(sizeof(shortcut));
s = *shortcutage;
} else {
for (s = *shortcutage; s->next != NULL; s = s->next)
;
s->next = nmalloc(sizeof(shortcut));
s = s->next;
}
s->val = key;
s->desc = desc;
s->help = help;
@ -132,17 +154,29 @@ void sc_init_one(shortcut * s, int key, char *desc, char *help, int alt,
s->misc2 = misc2;
s->viewok = view;
s->func = func;
s->next = NULL;
}
#ifndef NANO_SMALL
/* Initialize the toggles in the same manner */
void toggle_init_one(toggle * t, int val, char *desc, int flag,
char override_ch)
void toggle_init_one(int val, char *desc, int flag)
{
t->val = val;
t->desc = desc;
t->flag = flag;
t->override_ch = override_ch;
toggle *u;
if (toggles == NULL) {
toggles = nmalloc(sizeof(toggle));
u = toggles;
} else {
for (u = toggles; u->next != NULL; u = u->next)
;
u->next = nmalloc(sizeof(toggle));
u = u->next;
}
u->val = val;
u->desc = desc;
u->flag = flag;
u->next = NULL;
}
#endif
@ -152,17 +186,16 @@ void toggle_init(void)
char *toggle_const_msg, *toggle_autoindent_msg, *toggle_suspend_msg,
*toggle_nohelp_msg, *toggle_picomode_msg, *toggle_mouse_msg,
*toggle_cuttoend_msg, *toggle_wrap_msg, *toggle_case_msg,
*toggle_backwards_msg, *toggle_dos_msg, *toggle_mac_msg,
*toggle_smooth_msg;
#ifdef ENABLE_MULTIBUFFER
char *toggle_load_msg, *nano_openprev_msg, *nano_opennext_msg;
#endif
*toggle_backwards_msg, *toggle_noconvert_msg, *toggle_dos_msg,
*toggle_mac_msg, *toggle_smooth_msg;
#ifdef HAVE_REGEX_H
char *toggle_regexp_msg;
#endif
#ifdef ENABLE_MULTIBUFFER
char *toggle_load_msg;
#endif
toggle_const_msg = _("Constant cursor position");
toggle_autoindent_msg = _("Auto indent");
@ -173,62 +206,42 @@ void toggle_init(void)
toggle_cuttoend_msg = _("Cut to end");
toggle_backwards_msg = _("Backwards search");
toggle_case_msg = _("Case sensitive search");
#ifdef HAVE_REGEX_H
toggle_regexp_msg = _("Regular expression search");
#endif
toggle_noconvert_msg = _("No conversion from DOS/Mac format");
toggle_dos_msg = _("Writing file in DOS format");
toggle_mac_msg = _("Writing file in Mac format");
toggle_smooth_msg = _("Smooth scrolling");
#ifdef HAVE_REGEX_H
toggle_regexp_msg = _("Regular expressions");
#endif
toggle_wrap_msg = _("Auto wrap");
#ifdef ENABLE_MULTIBUFFER
toggle_load_msg = _("Multiple file buffers");
nano_openprev_msg = _("Open previously loaded file");
nano_opennext_msg = _("Open next loaded file");
#endif
toggle_init_one(&toggles[0], TOGGLE_CONST_KEY, toggle_const_msg,
CONSTUPDATE, 0);
toggle_init_one(&toggles[1], TOGGLE_AUTOINDENT_KEY,
toggle_autoindent_msg, AUTOINDENT, 0);
toggle_init_one(&toggles[2], TOGGLE_SUSPEND_KEY, toggle_suspend_msg,
SUSPEND, 0);
toggle_init_one(&toggles[3], TOGGLE_NOHELP_KEY, toggle_nohelp_msg,
NO_HELP, 0);
toggle_init_one(&toggles[4], TOGGLE_PICOMODE_KEY, toggle_picomode_msg,
PICO_MODE, 0);
toggle_init_one(&toggles[5], TOGGLE_WRAP_KEY, toggle_wrap_msg,
NO_WRAP, 0);
toggle_init_one(&toggles[6], TOGGLE_MOUSE_KEY, toggle_mouse_msg,
USE_MOUSE, 0);
toggle_init_one(&toggles[7], TOGGLE_CUTTOEND_KEY, toggle_cuttoend_msg,
CUT_TO_END, 0);
toggle_init_one(&toggles[8], TOGGLE_BACKWARDS_KEY, toggle_backwards_msg,
REVERSE_SEARCH, 0);
toggle_init_one(&toggles[9], TOGGLE_CASE_KEY, toggle_case_msg,
CASE_SENSITIVE, 0);
toggle_init_one(&toggles[10], TOGGLE_DOS_KEY, toggle_dos_msg,
DOS_FILE, 0);
toggle_init_one(&toggles[11], TOGGLE_MAC_KEY, toggle_mac_msg,
MAC_FILE, 0);
toggle_init_one(&toggles[12], TOGGLE_SMOOTH_KEY, toggle_smooth_msg,
SMOOTHSCROLL, 0);
#ifdef ENABLE_MULTIBUFFER
toggle_init_one(&toggles[13], TOGGLE_LOAD_KEY, toggle_load_msg,
MULTIBUFFER, 0);
toggle_init_one(&toggles[14], NANO_OPENPREV_KEY, nano_openprev_msg,
0, '<');
toggle_init_one(&toggles[15], NANO_OPENNEXT_KEY, nano_opennext_msg,
0, '>');
#endif
toggle_init_one(TOGGLE_CONST_KEY, toggle_const_msg, CONSTUPDATE);
toggle_init_one(TOGGLE_AUTOINDENT_KEY, toggle_autoindent_msg, AUTOINDENT);
toggle_init_one(TOGGLE_SUSPEND_KEY, toggle_suspend_msg, SUSPEND);
toggle_init_one(TOGGLE_NOHELP_KEY, toggle_nohelp_msg, NO_HELP);
toggle_init_one(TOGGLE_PICOMODE_KEY, toggle_picomode_msg, PICO_MODE);
toggle_init_one(TOGGLE_WRAP_KEY, toggle_wrap_msg, NO_WRAP);
toggle_init_one(TOGGLE_MOUSE_KEY, toggle_mouse_msg, USE_MOUSE);
toggle_init_one(TOGGLE_CUTTOEND_KEY, toggle_cuttoend_msg, CUT_TO_END);
toggle_init_one(TOGGLE_BACKWARDS_KEY, toggle_backwards_msg, REVERSE_SEARCH);
toggle_init_one(TOGGLE_CASE_KEY, toggle_case_msg, CASE_SENSITIVE);
#ifdef HAVE_REGEX_H
toggle_init_one(&toggles[TOGGLE_LEN - 1], TOGGLE_REGEXP_KEY,
toggle_regexp_msg, USE_REGEXP, 0);
toggle_init_one(TOGGLE_REGEXP_KEY, toggle_regexp_msg, USE_REGEXP);
#endif
#ifdef ENABLE_MULTIBUFFER
toggle_init_one(TOGGLE_LOAD_KEY, toggle_load_msg, MULTIBUFFER);
#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_SMOOTH_KEY, toggle_smooth_msg, SMOOTHSCROLL);
#endif /* !NANO_SMALL */
}
void shortcut_init(int unjustify)
@ -245,7 +258,8 @@ void shortcut_init(int unjustify)
"", *nano_mark_msg = "", *nano_delete_msg =
"", *nano_backspace_msg = "", *nano_tab_msg =
"", *nano_enter_msg = "", *nano_cancel_msg =
"", *nano_unjustify_msg = "", *nano_append_msg = "";
"", *nano_unjustify_msg = "", *nano_append_msg =
"", *nano_dos_msg = "", *nano_mac_msg = "";
#ifndef NANO_SMALL
char *nano_tofiles_msg = "", *nano_gotodir_msg = "", *nano_case_msg =
@ -253,6 +267,9 @@ void shortcut_init(int unjustify)
#ifdef HAVE_REGEX_H
char *nano_regexp_msg = "", *nano_bracket_msg = "";
#endif
#ifdef ENABLE_MULTIBUFFER
char *nano_openprev_msg = "", *nano_opennext_msg = "";
#endif
nano_help_msg = _("Invoke the help menu");
nano_writeout_msg = _("Write the current file to disk");
@ -297,41 +314,47 @@ void shortcut_init(int unjustify)
nano_cancel_msg = _("Cancel the current function");
nano_append_msg = _("Append to the current file");
nano_reverse_msg = _("Search backwards");
nano_dos_msg = _("Write file out in DOS format");
nano_mac_msg = _("Write file out in Mac format");
#ifdef HAVE_REGEX_H
nano_regexp_msg = _("Use Regular expressions");
nano_bracket_msg = _("Find other bracket");
#endif
#ifdef ENABLE_MULTIBUFFER
nano_openprev_msg = _("Open previously loaded file");
nano_opennext_msg = _("Open next loaded file");
#endif
#endif /* !NANO_SMALL */
sc_init_one(&main_list[0], NANO_HELP_KEY, _("Get Help"),
sc_init_one(&main_list, NANO_HELP_KEY, _("Get Help"),
nano_help_msg, 0, NANO_HELP_FKEY, 0, VIEW, do_help);
#ifdef ENABLE_MULTIBUFFER
if (open_files != NULL && (open_files->prev || open_files->next))
sc_init_one(&main_list[1], NANO_EXIT_KEY, _("Close"),
sc_init_one(&main_list, NANO_EXIT_KEY, _("Close"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit);
else
#endif
sc_init_one(&main_list[1], NANO_EXIT_KEY, _("Exit"),
sc_init_one(&main_list, NANO_EXIT_KEY, _("Exit"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit);
sc_init_one(&main_list[2], NANO_WRITEOUT_KEY, _("WriteOut"),
sc_init_one(&main_list, NANO_WRITEOUT_KEY, _("WriteOut"),
nano_writeout_msg,
0, NANO_WRITEOUT_FKEY, 0, NOVIEW, do_writeout_void);
if (ISSET(PICO_MODE))
sc_init_one(&main_list[3], NANO_JUSTIFY_KEY, _("Justify"),
sc_init_one(&main_list, NANO_JUSTIFY_KEY, _("Justify"),
nano_justify_msg, 0, NANO_JUSTIFY_FKEY, 0,
NOVIEW, do_justify);
else
#ifdef ENABLE_MULTIBUFFER
/* this is so we can view multiple files */
sc_init_one(&main_list[3], NANO_INSERTFILE_KEY, _("Read File"),
sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"),
nano_insert_msg,
0, NANO_INSERTFILE_FKEY, 0, VIEW, do_insertfile_void);
#else
sc_init_one(&main_list[3], NANO_INSERTFILE_KEY, _("Read File"),
sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"),
nano_insert_msg,
0, NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void);
#endif
@ -340,273 +363,295 @@ void shortcut_init(int unjustify)
#ifdef ENABLE_MULTIBUFFER
/* this is so we can view multiple files */
sc_init_one(&main_list[4], NANO_INSERTFILE_KEY, _("Read File"),
sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"),
nano_insert_msg,
0, NANO_INSERTFILE_FKEY, 0, VIEW, do_insertfile_void);
#else
sc_init_one(&main_list[4], NANO_INSERTFILE_KEY, _("Read File"),
sc_init_one(&main_list, NANO_INSERTFILE_KEY, _("Read File"),
nano_insert_msg,
0, NANO_INSERTFILE_FKEY, 0, NOVIEW, do_insertfile_void);
#endif
else
sc_init_one(&main_list[4], NANO_REPLACE_KEY, _("Replace"),
sc_init_one(&main_list, NANO_REPLACE_KEY, _("Replace"),
nano_replace_msg,
NANO_ALT_REPLACE_KEY, NANO_REPLACE_FKEY, 0, NOVIEW, do_replace);
sc_init_one(&main_list[5], NANO_WHEREIS_KEY, _("Where Is"),
sc_init_one(&main_list, NANO_WHEREIS_KEY, _("Where Is"),
nano_whereis_msg,
0, NANO_WHEREIS_FKEY, 0, VIEW, do_search);
sc_init_one(&main_list[6], NANO_PREVPAGE_KEY, _("Prev Page"),
sc_init_one(&main_list, NANO_PREVPAGE_KEY, _("Prev Page"),
nano_prevpage_msg,
0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, do_page_up);
sc_init_one(&main_list[7], NANO_NEXTPAGE_KEY, _("Next Page"),
sc_init_one(&main_list, NANO_NEXTPAGE_KEY, _("Next Page"),
nano_nextpage_msg,
0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, do_page_down);
sc_init_one(&main_list[8], NANO_CUT_KEY, _("Cut Text"),
sc_init_one(&main_list, NANO_CUT_KEY, _("Cut Text"),
nano_cut_msg, 0, NANO_CUT_FKEY, 0, NOVIEW, do_cut_text);
if (unjustify)
sc_init_one(&main_list[9], NANO_UNJUSTIFY_KEY, _("UnJustify"),
sc_init_one(&main_list, NANO_UNJUSTIFY_KEY, _("UnJustify"),
nano_unjustify_msg, 0, 0, 0, NOVIEW, do_uncut_text);
else
sc_init_one(&main_list[9], NANO_UNCUT_KEY, _("UnCut Txt"),
sc_init_one(&main_list, NANO_UNCUT_KEY, _("UnCut Txt"),
nano_uncut_msg,
0, NANO_UNCUT_FKEY, 0, NOVIEW, do_uncut_text);
sc_init_one(&main_list[10], NANO_CURSORPOS_KEY, _("Cur Pos"),
sc_init_one(&main_list, NANO_CURSORPOS_KEY, _("Cur Pos"),
nano_cursorpos_msg,
0, NANO_CURSORPOS_FKEY, 0, VIEW, do_cursorpos_void);
sc_init_one(&main_list[11], NANO_SPELL_KEY, _("To Spell"),
sc_init_one(&main_list, NANO_SPELL_KEY, _("To Spell"),
nano_spell_msg, 0, NANO_SPELL_FKEY, 0, NOVIEW, do_spell);
sc_init_one(&main_list[12], NANO_UP_KEY, _("Up"),
sc_init_one(&main_list, NANO_UP_KEY, _("Up"),
nano_up_msg, 0, KEY_UP, 0, VIEW, do_up);
sc_init_one(&main_list[13], NANO_DOWN_KEY, _("Down"),
sc_init_one(&main_list, NANO_DOWN_KEY, _("Down"),
nano_down_msg, 0, KEY_DOWN, 0, VIEW, do_down);
sc_init_one(&main_list[14], NANO_FORWARD_KEY, _("Forward"),
sc_init_one(&main_list, NANO_FORWARD_KEY, _("Forward"),
nano_forward_msg, 0, KEY_RIGHT, 0, VIEW, do_right);
sc_init_one(&main_list[15], NANO_BACK_KEY, _("Back"),
sc_init_one(&main_list, NANO_BACK_KEY, _("Back"),
nano_back_msg, 0, KEY_LEFT, 0, VIEW, do_left);
sc_init_one(&main_list[16], NANO_HOME_KEY, _("Home"),
sc_init_one(&main_list, NANO_HOME_KEY, _("Home"),
nano_home_msg, 0, KEY_HOME, 362, VIEW, do_home);
sc_init_one(&main_list[17], NANO_END_KEY, _("End"),
sc_init_one(&main_list, NANO_END_KEY, _("End"),
nano_end_msg, 0, KEY_END, 385, VIEW, do_end);
sc_init_one(&main_list[18], NANO_REFRESH_KEY, _("Refresh"),
sc_init_one(&main_list, NANO_REFRESH_KEY, _("Refresh"),
nano_refresh_msg, 0, 0, 0, VIEW, total_refresh);
sc_init_one(&main_list[19], NANO_MARK_KEY, _("Mark Text"),
sc_init_one(&main_list, NANO_MARK_KEY, _("Mark Text"),
nano_mark_msg, NANO_ALT_MARK_KEY, 0, 0, NOVIEW, do_mark);
sc_init_one(&main_list[20], NANO_DELETE_KEY, _("Delete"),
sc_init_one(&main_list, NANO_DELETE_KEY, _("Delete"),
nano_delete_msg, 0, KEY_DC,
NANO_CONTROL_D, NOVIEW, do_delete);
sc_init_one(&main_list[21], NANO_BACKSPACE_KEY, _("Backspace"),
sc_init_one(&main_list, NANO_BACKSPACE_KEY, _("Backspace"),
nano_backspace_msg, 0,
KEY_BACKSPACE, 127, NOVIEW, do_backspace);
sc_init_one(&main_list[22], NANO_TAB_KEY, _("Tab"),
sc_init_one(&main_list, NANO_TAB_KEY, _("Tab"),
nano_tab_msg, 0, 0, 0, NOVIEW, do_tab);
if (ISSET(PICO_MODE))
sc_init_one(&main_list[23], NANO_REPLACE_KEY, _("Replace"),
sc_init_one(&main_list, NANO_REPLACE_KEY, _("Replace"),
nano_replace_msg,
NANO_ALT_REPLACE_KEY, NANO_REPLACE_FKEY, 0, NOVIEW, do_replace);
else
sc_init_one(&main_list[23], NANO_JUSTIFY_KEY, _("Justify"),
sc_init_one(&main_list, NANO_JUSTIFY_KEY, _("Justify"),
nano_justify_msg, 0, NANO_JUSTIFY_FKEY, 0,
NOVIEW, do_justify);
sc_init_one(&main_list[24], NANO_ENTER_KEY, _("Enter"),
sc_init_one(&main_list, NANO_ENTER_KEY, _("Enter"),
nano_enter_msg,
0, KEY_ENTER, NANO_CONTROL_M, NOVIEW, do_enter_void);
sc_init_one(&main_list[25], NANO_GOTO_KEY, _("Goto Line"),
sc_init_one(&main_list, NANO_GOTO_KEY, _("Goto Line"),
nano_goto_msg,
NANO_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0, VIEW, do_gotoline_void);
#if (!defined NANO_SMALL) && (defined HAVE_REGEX_H)
sc_init_one(&main_list[26], -9, _("Find Other Bracket"),
sc_init_one(&main_list, -9, _("Find Other Bracket"),
nano_bracket_msg,
NANO_BRACKET_KEY, 0, 0, VIEW, do_find_bracket);
#endif
#ifdef ENABLE_MULTIBUFFER
sc_init_one(&main_list, -9, _("Previous File"),
nano_openprev_msg,
NANO_OPENPREV_KEY, 0, 0, VIEW, open_prevfile_void);
sc_init_one(&main_list, -9, _("Next File"),
nano_opennext_msg,
NANO_OPENNEXT_KEY, 0, 0, VIEW, open_nextfile_void);
#endif
sc_init_one(&whereis_list[0], NANO_HELP_KEY,
sc_init_one(&whereis_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&whereis_list[1], NANO_CANCEL_KEY,
sc_init_one(&whereis_list, NANO_CANCEL_KEY,
_("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&whereis_list[2], NANO_FIRSTLINE_KEY, _("First Line"),
sc_init_one(&whereis_list, NANO_FIRSTLINE_KEY, _("First Line"),
nano_firstline_msg, 0, 0, 0, VIEW, do_first_line);
sc_init_one(&whereis_list[3], NANO_LASTLINE_KEY, _("Last Line"),
sc_init_one(&whereis_list, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, do_last_line);
sc_init_one(&whereis_list[4], NANO_OTHERSEARCH_KEY, _("Replace"),
sc_init_one(&whereis_list, NANO_OTHERSEARCH_KEY, _("Replace"),
nano_replace_msg, 0, 0, 0, VIEW, do_replace);
sc_init_one(&whereis_list[5], NANO_FROMSEARCHTOGOTO_KEY,
sc_init_one(&whereis_list, NANO_FROMSEARCHTOGOTO_KEY,
_("Goto Line"), nano_goto_msg, 0, 0, 0, VIEW,
do_gotoline_void);
#ifndef NANO_SMALL
sc_init_one(&whereis_list[6], TOGGLE_CASE_KEY, _("Case Sens"),
sc_init_one(&whereis_list, TOGGLE_CASE_KEY, _("Case Sens"),
nano_case_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&whereis_list[7], TOGGLE_BACKWARDS_KEY, _("Direction"),
sc_init_one(&whereis_list, TOGGLE_BACKWARDS_KEY, _("Direction"),
nano_reverse_msg, 0, 0, 0, VIEW, 0);
#ifdef HAVE_REGEX_H
sc_init_one(&whereis_list[REPLACE_LIST_LEN - 1], TOGGLE_REGEXP_KEY,
sc_init_one(&whereis_list, TOGGLE_REGEXP_KEY,
_("Regexp"), nano_regexp_msg, 0, 0, 0, VIEW, 0);
#endif
#endif /* NANO_SMALL */
#endif /* !NANO_SMALL */
sc_init_one(&replace_list[0], NANO_HELP_KEY,
sc_init_one(&replace_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&replace_list[1], NANO_CANCEL_KEY,
sc_init_one(&replace_list, NANO_CANCEL_KEY,
_("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&replace_list[2], NANO_FIRSTLINE_KEY, _("First Line"),
sc_init_one(&replace_list, NANO_FIRSTLINE_KEY, _("First Line"),
nano_firstline_msg, 0, 0, 0, VIEW, do_first_line);
sc_init_one(&replace_list[3], NANO_LASTLINE_KEY, _("Last Line"),
sc_init_one(&replace_list, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, do_last_line);
sc_init_one(&replace_list[4], NANO_OTHERSEARCH_KEY, _("No Replace"),
sc_init_one(&replace_list, NANO_OTHERSEARCH_KEY, _("No Replace"),
nano_whereis_msg, 0, 0, 0, VIEW, do_search);
sc_init_one(&replace_list[5], NANO_FROMSEARCHTOGOTO_KEY,
sc_init_one(&replace_list, NANO_FROMSEARCHTOGOTO_KEY,
_("Goto Line"), nano_goto_msg, 0, 0, 0, VIEW,
do_gotoline_void);
#ifndef NANO_SMALL
sc_init_one(&replace_list[6], TOGGLE_CASE_KEY, _("Case Sens"),
sc_init_one(&replace_list, TOGGLE_CASE_KEY, _("Case Sens"),
nano_case_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&replace_list[7], TOGGLE_BACKWARDS_KEY, _("Direction"),
sc_init_one(&replace_list, TOGGLE_BACKWARDS_KEY, _("Direction"),
nano_reverse_msg, 0, 0, 0, VIEW, 0);
#ifdef HAVE_REGEX_H
sc_init_one(&replace_list[REPLACE_LIST_LEN - 1], TOGGLE_REGEXP_KEY,
sc_init_one(&replace_list, TOGGLE_REGEXP_KEY,
_("Regexp"), nano_regexp_msg, 0, 0, 0, VIEW, 0);
#endif
#endif /* NANO_SMALL */
#endif /* !NANO_SMALL */
sc_init_one(&replace_list_2[0], NANO_HELP_KEY,
sc_init_one(&replace_list_2, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&replace_list_2[1], NANO_CANCEL_KEY,
sc_init_one(&replace_list_2, NANO_CANCEL_KEY,
_("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&replace_list_2[2], NANO_FIRSTLINE_KEY, _("First Line"),
sc_init_one(&replace_list_2, NANO_FIRSTLINE_KEY, _("First Line"),
nano_firstline_msg, 0, 0, 0, VIEW, do_first_line);
sc_init_one(&replace_list_2[3], NANO_LASTLINE_KEY, _("Last Line"),
sc_init_one(&replace_list_2, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, do_last_line);
sc_init_one(&goto_list[0], NANO_HELP_KEY,
sc_init_one(&goto_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&goto_list[1], NANO_CANCEL_KEY, _("Cancel"),
sc_init_one(&goto_list, NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&goto_list[2], NANO_FIRSTLINE_KEY, _("First Line"),
sc_init_one(&goto_list, NANO_FIRSTLINE_KEY, _("First Line"),
nano_firstline_msg, 0, 0, 0, VIEW, &do_first_line);
sc_init_one(&goto_list[3], NANO_LASTLINE_KEY, _("Last Line"),
sc_init_one(&goto_list, NANO_LASTLINE_KEY, _("Last Line"),
nano_lastline_msg, 0, 0, 0, VIEW, &do_last_line);
sc_init_one(&help_list[0], NANO_PREVPAGE_KEY, _("Prev Page"),
sc_init_one(&help_list, NANO_PREVPAGE_KEY, _("Prev Page"),
nano_prevpage_msg,
0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, do_page_up);
sc_init_one(&help_list[1], NANO_NEXTPAGE_KEY, _("Next Page"),
sc_init_one(&help_list, NANO_NEXTPAGE_KEY, _("Next Page"),
nano_nextpage_msg,
0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, do_page_down);
sc_init_one(&help_list[2], NANO_EXIT_KEY, _("Exit"),
sc_init_one(&help_list, NANO_EXIT_KEY, _("Exit"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, do_exit);
sc_init_one(&writefile_list[0], NANO_HELP_KEY,
sc_init_one(&writefile_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&writefile_list[1], NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0);
#ifndef DISABLE_BROWSER
sc_init_one(&writefile_list[2], NANO_TOFILES_KEY, _("To Files"),
sc_init_one(&writefile_list, NANO_TOFILES_KEY, _("To Files"),
nano_tofiles_msg, 0, 0, 0, NOVIEW, 0);
#endif
sc_init_one(&writefile_list[WRITEFILE_LIST_LEN - 1], NANO_APPEND_KEY, _("Append"),
#ifndef NANO_SMALL
sc_init_one(&writefile_list, TOGGLE_DOS_KEY,
_("DOS Format"), nano_dos_msg, 0, 0, 0, NOVIEW, 0);
sc_init_one(&writefile_list, TOGGLE_MAC_KEY,
_("Mac Format"), nano_mac_msg, 0, 0, 0, NOVIEW, 0);
#endif
sc_init_one(&writefile_list,
NANO_APPEND_KEY, _("Append"),
nano_append_msg, 0, 0, 0, NOVIEW, 0);
sc_init_one(&insertfile_list[0], NANO_HELP_KEY,
sc_init_one(&writefile_list, NANO_CANCEL_KEY,
_("Cancel"), nano_cancel_msg, 0, 0, 0, VIEW, 0);
sc_init_one(&insertfile_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&insertfile_list[1], NANO_CANCEL_KEY, _("Cancel"),
sc_init_one(&insertfile_list, NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0);
#ifndef DISABLE_BROWSER
sc_init_one(&insertfile_list[2], NANO_TOFILES_KEY, _("To Files"),
sc_init_one(&insertfile_list, NANO_TOFILES_KEY, _("To Files"),
nano_tofiles_msg, 0, 0, 0, NOVIEW, 0);
#endif
sc_init_one(&spell_list[0], NANO_HELP_KEY,
sc_init_one(&spell_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&spell_list[1], NANO_CANCEL_KEY, _("Cancel"),
sc_init_one(&spell_list, NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0);
#ifndef DISABLE_BROWSER
sc_init_one(&browser_list[0], NANO_HELP_KEY,
sc_init_one(&browser_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&browser_list[1], NANO_EXIT_KEY, _("Exit"),
sc_init_one(&browser_list, NANO_EXIT_KEY, _("Exit"),
nano_exit_msg, 0, NANO_EXIT_FKEY, 0, VIEW, 0);
sc_init_one(&browser_list[2], NANO_PREVPAGE_KEY, _("Prev Page"),
sc_init_one(&browser_list, NANO_PREVPAGE_KEY, _("Prev Page"),
nano_prevpage_msg,
0, NANO_PREVPAGE_FKEY, KEY_PPAGE, VIEW, 0);
sc_init_one(&browser_list[3], NANO_NEXTPAGE_KEY, _("Next Page"),
sc_init_one(&browser_list, NANO_NEXTPAGE_KEY, _("Next Page"),
nano_nextpage_msg,
0, NANO_NEXTPAGE_FKEY, KEY_NPAGE, VIEW, 0);
sc_init_one(&browser_list[4], NANO_GOTO_KEY, _("Goto"),
sc_init_one(&browser_list, NANO_GOTO_KEY, _("Goto"),
nano_gotodir_msg, NANO_ALT_GOTO_KEY, NANO_GOTO_FKEY, 0,
VIEW, 0);
sc_init_one(&gotodir_list[0], NANO_HELP_KEY,
sc_init_one(&gotodir_list, NANO_HELP_KEY,
_("Get Help"), nano_help_msg, 0, 0, 0, VIEW, do_help);
sc_init_one(&gotodir_list[1], NANO_CANCEL_KEY, _("Cancel"),
sc_init_one(&gotodir_list, NANO_CANCEL_KEY, _("Cancel"),
nano_cancel_msg, 0, 0, 0, VIEW, 0);
#endif
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
currshortcut = main_list;
#endif
toggle_init();
}

233
nano.c
Просмотреть файл

@ -64,8 +64,8 @@
#ifndef DISABLE_WRAPJUSTIFY
/* Former globals, now static */
int fill = 0; /* Fill - where to wrap lines, basically */
int wrap_at = 0; /* Right justified fill value, allows resize */
int fill = 0;/* Fill - where to wrap lines, basically */
int wrap_at = 0; /* Right justified fill value, allows resize */
#endif
struct termios oldterm; /* The user's original term settings */
@ -425,10 +425,9 @@ void usage(void)
printf
(_
(" -M --mac Write file in Mac format\n"));
#endif
#ifdef HAVE_REGEX_H
printf(_
(" -R --regexp Use regular expressions for search\n"));
printf
(_
(" -N --noconvert Don't convert files from DOS/Mac format\n"));
#endif
#ifndef NANO_SMALL
printf(_
@ -1488,8 +1487,7 @@ int do_int_spell_fix(char *word)
do_replace_highlight(TRUE, prevanswer);
/* allow replace word to be corrected */
i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace,
_("Edit a replacement"));
i = statusq(0, spell_list, last_replace, _("Edit a replacement"));
do_replace_highlight(FALSE, prevanswer);
@ -1732,7 +1730,7 @@ int do_spell(void)
char *temp;
int spell_res;
if ((temp = tempnam(0, "nano.")) == NULL) {
if ((temp = safe_tempnam(0, "nano.")) == NULL) {
statusbar(_("Could not create a temporary filename: %s"),
strerror(errno));
return 0;
@ -1834,6 +1832,7 @@ void do_mouse(void)
{
MEVENT mevent;
int foo = 0, tab_found = 0;
int currslen;
if (getmouse(&mevent) == ERR)
return;
@ -1905,6 +1904,11 @@ void do_mouse(void)
int k, val = 0;
if (currshortcut == main_list)
currslen = MAIN_VISIBLE;
else
currslen = length_of_list(currshortcut);
if (currslen < 2)
k = COLS / 6;
else
@ -2410,14 +2414,17 @@ int do_justify(void)
#ifndef DISABLE_HELP
void help_init(void)
{
int i, sofar = 0, helplen;
int i, sofar = 0, meta_shortcut = 0, helplen;
long allocsize = 1; /* How much space we're gonna need for the help text */
char buf[BUFSIZ] = "", *ptr = NULL;
toggle *t;
shortcut *s;
if (currslen == MAIN_VISIBLE)
helplen = MAIN_LIST_LEN;
else
helplen = currslen;
/*
if (currshortcut = main_list)
helplen = MAIN_VISIBLE;
else */
helplen = length_of_list(currshortcut);
/* First set up the initial help text for the current function */
if (currshortcut == whereis_list || currshortcut == replace_list
@ -2451,8 +2458,12 @@ void help_init(void)
"or --multibuffer command line flags, the Meta-F toggle or "
"using a nanorc file, inserting a file will cause it to be "
"loaded into a separate buffer (use Meta-< and > to switch "
"between file buffers).\n\n The following function keys are "
"available in Insert File mode:\n\n");
"between file buffers).\n\n In multiple buffer mode, the "
"same file cannot be loaded twice, not even a \"New "
"Buffer.\" A workaround to load another blank buffer is to "
"load a nonexistent filename into a separate buffer.\n\n "
"The following function keys are available in Insert File "
"mode:\n\n");
else if (currshortcut == writefile_list)
ptr = _("Write File Help Text\n\n "
"Type the name that you wish to save the current file "
@ -2498,21 +2509,22 @@ void help_init(void)
/* Compute the space needed for the shortcut lists - we add 15 to
have room for the shortcut abbrev and its possible alternate keys */
for (i = 0; i <= helplen - 1; i++)
if (currshortcut[i].help != NULL)
allocsize += strlen(currshortcut[i].help) + 15;
s = currshortcut;
for (i = 0; i <= helplen - 1; i++) {
if (s->help != NULL)
allocsize += strlen(s->help) + 15;
s = s->next;
}
/* If we're on the main list, we also allocate space for toggle help text. */
if (currshortcut == main_list) {
for (i = 0; i <= TOGGLE_LEN - 1; i++)
if (toggles[i].desc != NULL)
allocsize += strlen(toggles[i].desc) + 30;
for (t = toggles; t != NULL; t = t->next)
if (t->desc != NULL)
allocsize += strlen(t->desc) + 30;
}
allocsize += strlen(ptr);
if (help_text != NULL)
free(help_text);
@ -2523,59 +2535,71 @@ void help_init(void)
strcpy(help_text, ptr);
/* Now add our shortcut info */
s = currshortcut;
for (i = 0; i <= helplen - 1; i++) {
if (currshortcut[i].val > 0 && currshortcut[i].val < 'a')
sofar = snprintf(buf, BUFSIZ, "^%c ", currshortcut[i].val + 64);
else
sofar = snprintf(buf, BUFSIZ, " ");
if (s->val > 0 && s->val < 'a')
sofar = snprintf(buf, BUFSIZ, "^%c ", s->val + 64);
else {
if (s->altval > 0) {
sofar = 0;
meta_shortcut = 1;
}
else
sofar = snprintf(buf, BUFSIZ, " ");
}
if (currshortcut[i].misc1 > KEY_F0 && currshortcut[i].misc1 <= KEY_F(64))
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(F%d) ",
currshortcut[i].misc1 - KEY_F0);
else
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " ");
if (!meta_shortcut) {
if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64))
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(F%d) ",
s->misc1 - KEY_F0);
else
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " ");
}
if (currshortcut[i].altval > 0 && currshortcut[i].altval < 91)
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ",
currshortcut[i].altval - 32);
else if (currshortcut[i].altval > 0)
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ",
currshortcut[i].altval);
if (s->altval > 0 && s->altval < 91
&& (s->altval - 32) > 32)
sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
(meta_shortcut ? "M-%c " : "(M-%c) "),
s->altval - 32);
else if (s->altval > 0)
sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
(meta_shortcut ? "M-%c " : "(M-%c) "),
s->altval);
/* Hack */
else if (currshortcut[i].val >= 'a')
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(M-%c) ",
currshortcut[i].val - 32);
else if (s->val >= 'a')
sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
(meta_shortcut ? "(M-%c) " : "M-%c "),
s->val - 32);
else
sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " ");
if (meta_shortcut) {
if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64))
sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
"(F%d) ", s->misc1 - KEY_F0);
else
sofar += snprintf(&buf[sofar], BUFSIZ - sofar,
" ");
}
if (currshortcut[i].help != NULL)
snprintf(&buf[sofar], BUFSIZ - sofar, "%s", currshortcut[i].help);
if (s->help != NULL)
snprintf(&buf[sofar], BUFSIZ - sofar, "%s", s->help);
strcat(help_text, buf);
strcat(help_text, "\n");
s = s->next;
}
/* And the toggles... */
if (currshortcut == main_list)
for (i = 0; i <= TOGGLE_LEN - 1; i++) {
if (toggles[i].override_ch != 0)
for (t = toggles; t != NULL; t = t->next) {
sofar = snprintf(buf, BUFSIZ,
"M-%c ", toggles[i].override_ch);
else
sofar = snprintf(buf, BUFSIZ,
"M-%c ", toggles[i].val - 32);
if (toggles[i].desc != NULL) {
if (toggles[i].flag != 0)
"M-%c ", t->val - 32);
if (t->desc != NULL) {
snprintf(&buf[sofar], BUFSIZ - sofar, _("%s enable/disable"),
toggles[i].desc);
else
snprintf(&buf[sofar], BUFSIZ - sofar, "%s",
toggles[i].desc);
t->desc);
}
strcat(help_text, buf);
strcat(help_text, "\n");
}
@ -2583,7 +2607,7 @@ void help_init(void)
}
#endif
void do_toggle(int which)
void do_toggle(toggle *which)
{
#ifdef NANO_SMALL
nano_disabled_msg();
@ -2591,7 +2615,7 @@ void do_toggle(int which)
char *enabled = _("enabled");
char *disabled = _("disabled");
switch (toggles[which].val) {
switch (which->val) {
case TOGGLE_BACKWARDS_KEY:
case TOGGLE_CASE_KEY:
case TOGGLE_REGEXP_KEY:
@ -2599,9 +2623,9 @@ void do_toggle(int which)
}
/* Even easier! */
TOGGLE(toggles[which].flag);
TOGGLE(which->flag);
switch (toggles[which].val) {
switch (which->val) {
case TOGGLE_PICOMODE_KEY:
shortcut_init(0);
SET(CLEAR_BACKUPSTRING);
@ -2629,18 +2653,18 @@ void do_toggle(int which)
break;
}
if (!ISSET(toggles[which].flag)) {
if (toggles[which].val == TOGGLE_NOHELP_KEY ||
toggles[which].val == TOGGLE_WRAP_KEY)
statusbar("%s %s", toggles[which].desc, enabled);
if (!ISSET(which->flag)) {
if (which->val == TOGGLE_NOHELP_KEY ||
which->val == TOGGLE_WRAP_KEY)
statusbar("%s %s", which->desc, enabled);
else
statusbar("%s %s", toggles[which].desc, disabled);
statusbar("%s %s", which->desc, disabled);
} else {
if (toggles[which].val == TOGGLE_NOHELP_KEY ||
toggles[which].val == TOGGLE_WRAP_KEY)
statusbar("%s %s", toggles[which].desc, disabled);
if (which->val == TOGGLE_NOHELP_KEY ||
which->val == TOGGLE_WRAP_KEY)
statusbar("%s %s", which->desc, disabled);
else
statusbar("%s %s", toggles[which].desc, enabled);
statusbar("%s %s", which->desc, enabled);
}
#endif
@ -2689,6 +2713,8 @@ int main(int argc, char *argv[])
int keyhandled; /* Have we handled the keystroke yet? */
int i, modify_control_seq;
char *argv0;
shortcut *s;
toggle *t;
#ifdef _POSIX_VDISABLE
struct termios term;
@ -2711,6 +2737,7 @@ int main(int argc, char *argv[])
{"cut", 0, 0, 'k'},
{"dos", 0, 0, 'D'},
{"mac", 0, 0, 'M'},
{"noconvert", 0, 0, 'N'},
{"autoindent", 0, 0, 'i'},
#endif
{"tempfile", 0, 0, 't'},
@ -2756,11 +2783,11 @@ int main(int argc, char *argv[])
#endif /* ENABLE_NANORC */
#ifdef HAVE_GETOPT_LONG
while ((optchr = getopt_long(argc, argv, "h?DFKMRST:Vabcefgijklmo:pr:s:tvwxz",
while ((optchr = getopt_long(argc, argv, "h?DFKMNRST:Vabcefgijklmo:pr:s:tvwxz",
long_options, &option_index)) != EOF) {
#else
while ((optchr =
getopt(argc, argv, "h?DFKMRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) {
getopt(argc, argv, "h?DFKMNRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) {
#endif
switch (optchr) {
@ -2782,14 +2809,10 @@ int main(int argc, char *argv[])
case 'M':
SET(MAC_FILE);
break;
#endif
case 'T':
tabsize = atoi(optarg);
if (tabsize <= 0) {
usage(); /* To stop bogus data for tab width */
finish(1);
}
case 'N':
SET(NO_CONVERT);
break;
#endif
#ifdef HAVE_REGEX_H
case 'R':
SET(USE_REGEXP);
@ -2800,6 +2823,13 @@ int main(int argc, char *argv[])
SET(SMOOTHSCROLL);
break;
#endif
case 'T':
tabsize = atoi(optarg);
if (tabsize <= 0) {
usage(); /* To stop bogus data for tab width */
finish(1);
}
break;
case 'V':
version();
exit(0);
@ -3004,7 +3034,6 @@ int main(int argc, char *argv[])
#ifndef DISABLE_MOUSE
currshortcut = main_list;
currslen = MAIN_VISIBLE;
#endif
#ifndef _POSIX_VDISABLE
@ -3170,6 +3199,7 @@ int main(int argc, char *argv[])
break;
}
break;
#ifdef ENABLE_MULTIBUFFER
case NANO_OPENPREV_KEY:
case NANO_OPENPREV_ALTKEY:
@ -3182,21 +3212,29 @@ int main(int argc, char *argv[])
keyhandled = 1;
break;
#endif
#if !defined (NANO_SMALL) && defined (HAVE_REGEX_H)
case NANO_BRACKET_KEY:
do_find_bracket();
keyhandled = 1;
break;
#endif
default:
/* Check for the altkey defs.... */
for (i = 0; i <= MAIN_LIST_LEN - 1; i++)
if (kbinput == main_list[i].altval ||
kbinput == main_list[i].altval - 32) {
kbinput = main_list[i].val;
for (s = main_list; s != NULL; s = s->next)
if (kbinput == s->altval ||
kbinput == s->altval - 32) {
kbinput = s->val;
break;
}
#ifndef NANO_SMALL
/* And for toggle switches */
for (i = 0; i <= TOGGLE_LEN - 1 && !keyhandled; i++)
if (kbinput == toggles[i].val ||
(toggles[i].val > 'a' &&
kbinput == toggles[i].val - 32)) {
do_toggle(i);
for (t = toggles; t != NULL && !keyhandled; t = t->next)
if (kbinput == t->val ||
(t->val > 'a' &&
kbinput == t->val - 32)) {
do_toggle(t);
keyhandled = 1;
break;
}
@ -3222,14 +3260,15 @@ int main(int argc, char *argv[])
/* Look through the main shortcut list to see if we've hit a
shortcut key */
for (i = 0; i < MAIN_LIST_LEN && !keyhandled; i++) {
if (kbinput == main_list[i].val ||
(main_list[i].misc1 && kbinput == main_list[i].misc1) ||
(main_list[i].misc2 && kbinput == main_list[i].misc2)) {
if (ISSET(VIEW_MODE) && !main_list[i].viewok)
for (s = currshortcut; s != NULL && !keyhandled; s = s->next) {
if (kbinput == s->val ||
(s->misc1 && kbinput == s->misc1) ||
(s->misc2 && kbinput == s->misc2)) {
if (ISSET(VIEW_MODE) && !s->viewok)
print_view_warning();
else
main_list[i].func();
s->func();
keyhandled = 1;
}
}

55
nano.h
Просмотреть файл

@ -97,6 +97,7 @@ typedef struct shortcut {
int (*func) (void); /* Function to call when we catch this key */
char *desc; /* Description, e.g. "Page Up" */
char *help; /* Help file entry text */
struct shortcut *next;
} shortcut;
typedef struct toggle {
@ -105,8 +106,7 @@ typedef struct toggle {
e.g. "Pico Messages"; we'll append Enabled or
Disabled */
int flag; /* What flag actually gets toggled */
char override_ch; /* The character to display on the help screen,
if it isn't NULL */
struct toggle *next;
} toggle;
#ifdef ENABLE_NANORC
@ -162,6 +162,7 @@ typedef struct colortype {
#define SMOOTHSCROLL (1<<23)
#define DISABLE_CURPOS (1<<24) /* Damn, we still need it */
#define ALT_KEYPAD (1<<25)
#define NO_CONVERT (1<<26)
/* Control key sequences, changing these would be very very bad */
@ -305,57 +306,9 @@ know what you're doing */
#define TOGGLE_DOS_KEY NANO_ALT_D
#define TOGGLE_MAC_KEY NANO_ALT_O
#define TOGGLE_SMOOTH_KEY NANO_ALT_S
#define TOGGLE_NOCONVERT_KEY NANO_ALT_N
/* Toggle stuff, these static lengths need to go away RSN */
#ifndef HAVE_REGEX_H
#define NO_REGEX 1
#define SMALL_TOO 0
#else
#define NO_REGEX 0
#ifdef NANO_SMALL
#define SMALL_TOO 1
#else
#define SMALL_TOO 0
#endif /* NANO_SMALL */
#endif /* HAVE_REGEX_H */
#ifdef DISABLE_BROWSER
#define NO_BROWSER 1
#else
#define NO_BROWSER 0
#endif
#ifdef NANO_SMALL
#ifdef HAVE_REGEX_H
#define NO_TOGGLES 3
#else
#define NO_TOGGLES 2
#endif /* HAVE_REGEX_H */
#else
#define NO_TOGGLES 0
#endif /* NANO_SMALL */
#ifdef ENABLE_MULTIBUFFER
#define MULTI_TOGGLES 3
#else
#define MULTI_TOGGLES 0
#endif
#define WHEREIS_LIST_LEN (9 - NO_REGEX - NO_TOGGLES)
#define REPLACE_LIST_LEN (9 - NO_REGEX - NO_TOGGLES)
#define TOGGLE_LEN (14 - NO_REGEX + MULTI_TOGGLES)
#define WRITEFILE_LIST_LEN (4 - NO_BROWSER)
#define INSERTFILE_LIST_LEN (3 - NO_BROWSER)
#define BROWSER_LIST_LEN 5
#define MAIN_LIST_LEN (27 - NO_REGEX - SMALL_TOO)
#define MAIN_VISIBLE 12
#define REPLACE_LIST_2_LEN 4
#define GOTO_LIST_LEN 4
#define GOTODIR_LIST_LEN 2
#define HELP_LIST_LEN 3
#define SPELL_LIST_LEN 2
#define VIEW 1
#define NOVIEW 0

Просмотреть файл

@ -55,6 +55,12 @@
# Use smooth scrolling as the default
# set smooth
# Use alternate keypad routines
# set keypad
# Don't convert files from DOS/Mac format
# set noconvert
# Allow multiple file buffers (using ^R inserts into separate buffer)
# You must have configured with --enable-multibuffer or --enable-extra for
# this to work

30
proto.h
Просмотреть файл

@ -64,13 +64,13 @@ colortype *colorstrings;
#endif
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], 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];
extern shortcut *main_list, *whereis_list;
extern shortcut *replace_list, *goto_list;
extern shortcut *writefile_list, *insertfile_list;
extern shortcut *spell_list, *replace_list_2;
extern shortcut *help_list;
#ifndef DISABLE_BROWSER
extern shortcut browser_list[BROWSER_LIST_LEN], gotodir_list[GOTODIR_LIST_LEN];
extern shortcut *browser_list, *gotodir_list;
#endif
extern shortcut *currshortcut;
@ -80,7 +80,7 @@ extern regex_t search_regexp;
extern regmatch_t regmatches[10];
#endif
extern toggle toggles[TOGGLE_LEN];
extern toggle *toggles;
/* Programs we want available */
@ -95,7 +95,7 @@ int xplustabs(void);
int do_yesno(int all, int leavecursor, char *msg, ...);
int actual_x(filestruct * fileptr, int xplus);
int strlenpt(char *buf);
int statusq(int allowtabs, shortcut s[], int slen, char *def, char *msg, ...);
int statusq(int allowtabs, shortcut s[], char *def, char *msg, ...);
int write_file(char *name, int tmpfile, int append, int nonamechange);
int do_cut_text(void);
int do_uncut_text(void);
@ -103,6 +103,7 @@ int no_help(void);
int renumber_all(void);
int open_file(char *filename, int insert, int quiet);
int do_insertfile(int loading_file);
int length_of_list(shortcut *s);
#ifdef ENABLE_MULTIBUFFER
int add_open_file(int update, int dup_fix);
@ -155,7 +156,7 @@ void blank_statusbar(void);
void titlebar(char *path);
void previous_line(void);
void center_cursor(void);
void bottombars(shortcut s[], int slen);
void bottombars(shortcut *s);
void blank_statusbar_refresh(void);
void *nmalloc (size_t howmuch);
void *mallocstrcpy(char *dest, char *src);
@ -194,7 +195,6 @@ void do_rcfile(void);
void do_credits(void);
#endif
int do_writeout_void(void), do_exit(void), do_gotoline_void(void);
int do_insertfile_void(void), do_search(void);
@ -214,12 +214,18 @@ int keypad_on(WINDOW * win, int newval);
#ifdef ENABLE_MULTIBUFFER
int open_file_dup_fix(int update);
int open_prevfile(int closing_file), open_nextfile(int closing_file);
int open_prevfile_void(void), open_nextfile_void(void);
#endif
char *charalloc (size_t howmuch);
#if defined (ENABLE_MULTIBUFFER) || !defined (ENABLE_OPERATINGDIR)
char *get_full_path(char *origpath);
#if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER) || !defined (DISABLE_OPERATINGDIR)
char *get_full_path(const char *origpath);
#endif
#ifndef DISABLE_SPELLER
char *check_writable_directory(const char *path, int *writable);
char *safe_tempnam(const char *dirname, const char *filename_prefix);
#endif
#ifndef DISABLE_BROWSER

Просмотреть файл

@ -40,11 +40,7 @@
#define _(string) (string)
#endif
#ifndef DISABLE_WRAPJUSTIFY
#define NUM_RCOPTS 20
#else
#define NUM_RCOPTS 19
#endif
#define NUM_RCOPTS 21
/* Static stuff for the nanorc file */
rcoption rcopts[NUM_RCOPTS] = {
@ -57,11 +53,7 @@ rcoption rcopts[NUM_RCOPTS] = {
{"operatingdir", 0},
{"pico", PICO_MODE},
{"tabsize", 0},
#ifndef DISABLE_WRAPJUSTIFY
{"fill", 0},
#endif
{"speller", 0},
{"tempfile", TEMP_OPT},
{"view", VIEW_MODE},
@ -71,7 +63,8 @@ rcoption rcopts[NUM_RCOPTS] = {
{"multibuffer", MULTIBUFFER},
{"smooth", SMOOTHSCROLL},
{"keypad", ALT_KEYPAD},
{"relative", RELATIVECHARS}
{"relative", RELATIVECHARS},
{"noconvert", NO_CONVERT}
};
static int errors = 0;

Просмотреть файл

@ -76,7 +76,7 @@ int search_init(int replacing)
char *buf;
static char *backupstring = NULL;
#ifndef NANO_SMALL
int j;
toggle *t;
#endif
search_init_globals();
@ -126,8 +126,7 @@ int search_init(int replacing)
strcpy(buf, "");
/* This is now one simple call. It just does a lot */
i = statusq(0, replacing ? replace_list : whereis_list,
replacing ? REPLACE_LIST_LEN : WHEREIS_LIST_LEN, backupstring,
i = statusq(0, replacing ? replace_list : whereis_list, backupstring,
"%s%s%s%s%s%s",
_("Search"),
@ -187,9 +186,9 @@ int search_init(int replacing)
backupstring = mallocstrcpy(backupstring, answer);
#ifndef NANO_SMALL
for (j = 0; j <= TOGGLE_LEN - 1; j++)
if (i == toggles[j].val)
TOGGLE(toggles[j].flag);
for (t = toggles; t != NULL; t = t->next)
if (i == t->val)
TOGGLE(t->flag);
#endif
return 1;
@ -743,15 +742,15 @@ int do_replace(void)
} else
sprintf(buf, "%s", last_replace);
i = statusq(0, replace_list_2, REPLACE_LIST_2_LEN, "",
i = statusq(0, replace_list_2, "",
_("Replace with [%s]"), buf);
}
else
i = statusq(0, replace_list_2, REPLACE_LIST_2_LEN, "",
i = statusq(0, replace_list_2, "",
_("Replace with"));
}
else
i = statusq(0, replace_list_2, REPLACE_LIST_2_LEN, last_replace,
i = statusq(0, replace_list_2, last_replace,
_("Replace with"));
/* save where we are */
@ -786,7 +785,7 @@ int do_gotoline(int line, int save_pos)
int j = 0;
j = statusq(0, goto_list, GOTO_LIST_LEN, "", _("Enter line number"));
j = statusq(0, goto_list, "", _("Enter line number"));
if (j != 0) {
statusbar(_("Aborted"));
goto_abort();

110
winio.c
Просмотреть файл

@ -258,16 +258,18 @@ void nanoget_repaint(char *buf, char *inputbuf, int x)
}
/* Get the input from the kb; this should only be called from statusq */
int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
int nanogetstr(int allowtabs, char *buf, char *def, shortcut *s,
int start_x, int list)
{
int kbinput = 0, j = 0, x = 0, xend;
int kbinput = 0, j = 0, x = 0, xend, slen;
int x_left = 0, inputlen, tabbed = 0;
char *inputbuf;
shortcut *t;
#ifndef DISABLE_TABCOMP
int shift = 0;
#endif
slen = length_of_list(s);
inputbuf = charalloc(strlen(def) + 1);
inputbuf[0] = 0;
@ -276,7 +278,6 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
#if !defined(DISABLE_HELP) || !defined(DISABLE_MOUSE)
currshortcut = s;
currslen = slen;
#endif
/* Get the input! */
@ -289,12 +290,12 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
wrefresh(edit);
while ((kbinput = wgetch(bottomwin)) != 13) {
for (j = 0; j <= slen - 1; j++) {
for (t = s; t != NULL; t = t->next) {
#ifdef DEBUG
fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput, kbinput);
#endif
if (kbinput == s[j].val && kbinput < 32) {
if (kbinput == t->val && kbinput < 32) {
#ifndef DISABLE_HELP
/* Have to do this here, it would be too late to do it in statusq */
@ -308,7 +309,7 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
we hit a keystroke, GEEZ! */
answer = mallocstrcpy(answer, inputbuf);
free(inputbuf);
return s[j].val;
return t->val;
}
}
xend = strlen(buf) + strlen(inputbuf);
@ -459,19 +460,19 @@ int nanogetstr(int allowtabs, char *buf, char *def, shortcut s[], int slen,
}
default:
for (j = 0; j <= slen - 1; j++) {
for (t = s; t != NULL; t = t->next) {
#ifdef DEBUG
fprintf(stderr, _("Aha! \'%c\' (%d)\n"), kbinput,
kbinput);
#endif
if (kbinput == s[j].val || kbinput == s[j].val - 32) {
if (kbinput == t->val || kbinput == t->val - 32) {
/* We hit an Alt key. Do like above. We don't
just ungetch the letter and let it get caught
above cause that screws the keypad... */
answer = mallocstrcpy(answer, inputbuf);
free(inputbuf);
return s[j].val;
return t->val;
}
}
@ -573,15 +574,17 @@ void titlebar(char *path)
reset_cursor();
}
void onekey(char *keystroke, char *desc)
void onekey(char *keystroke, char *desc, int len)
{
char description[80];
int i;
snprintf(description, 12 - (strlen(keystroke) - 2), " %-10s", desc);
wattron(bottomwin, A_REVERSE);
waddstr(bottomwin, keystroke);
wattroff(bottomwin, A_REVERSE);
waddstr(bottomwin, description);
waddch(bottomwin, ' ');
waddnstr(bottomwin, desc, len - 3);
for (i = strlen(desc); i < len - 3; i++)
waddch(bottomwin, ' ');
}
void clear_bottomwin(void)
@ -593,10 +596,17 @@ void clear_bottomwin(void)
mvwaddstr(bottomwin, 2, 0, hblank);
}
void bottombars(shortcut s[], int slen)
void bottombars(shortcut *s)
{
int i, j, k;
char keystr[10];
shortcut *t;
int slen;
if (s == main_list)
slen = MAIN_VISIBLE;
else
slen = length_of_list(s);
if (ISSET(NO_HELP))
return;
@ -610,39 +620,42 @@ void bottombars(shortcut s[], int slen)
/* Determine how many extra spaces are needed to fill the bottom of the screen */
if (slen < 2)
k = COLS / 6 - 13;
k = COLS / 6;
else
k = COLS / ((slen + (slen % 2)) / 2) - 13;
k = COLS / ((slen + (slen % 2)) / 2);
clear_bottomwin();
wmove(bottomwin, 1, 0);
for (i = 0; i <= slen - 1; i += 2) {
t = s;
for (i = 0; i < slen / 2; i++) {
if (s[i].val < 97)
snprintf(keystr, 10, "^%c", s[i].val + 64);
wmove(bottomwin, 1, i * k);
if (t->val < 97)
snprintf(keystr, 10, "^%c", t->val + 64);
else
snprintf(keystr, 10, "M-%c", s[i].val - 32);
snprintf(keystr, 10, "M-%c", t->val - 32);
onekey(keystr, s[i].desc);
onekey(keystr, t->desc, k);
for (j = 0; j < k; j++)
waddch(bottomwin, ' ');
}
if (t->next == NULL)
break;
t = t->next;
wmove(bottomwin, 2, 0);
for (i = 1; i <= slen - 1; i += 2) {
wmove(bottomwin, 2, i * k);
if (s[i].val < 97)
snprintf(keystr, 10, "^%c", s[i].val + 64);
if (t->val < 97)
snprintf(keystr, 10, "^%c", t->val + 64);
else
snprintf(keystr, 10, "M-%c", s[i].val - 32);
snprintf(keystr, 10, "M-%c", t->val - 32);
onekey(keystr, s[i].desc);
onekey(keystr, t->desc, k);
for (j = 0; j < k; j++)
waddch(bottomwin, ' ');
if (t->next == NULL)
break;
t = t->next;
}
#ifdef ENABLE_COLOR
@ -1293,17 +1306,17 @@ void update_cursor(void)
*
* New arg tabs tells whether or not to allow tab completion.
*/
int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
int statusq(int tabs, shortcut *s, char *def, char *msg, ...)
{
va_list ap;
char foo[133];
int ret;
int ret, slen;
#ifndef DISABLE_TABCOMP
int list = 0;
#endif
bottombars(s, slen);
bottombars(s);
va_start(ap, msg);
vsnprintf(foo, 132, msg, ap);
@ -1318,11 +1331,11 @@ int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
#ifndef DISABLE_TABCOMP
ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), list);
ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), list);
#else
/* if we've disabled tab completion, the value of list won't be
used at all, so it's safe to use 0 (NULL) as a placeholder */
ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3), 0);
ret = nanogetstr(tabs, foo, def, s, (strlen(foo) + 3), 0);
#endif
#ifdef ENABLE_COLOR
@ -1399,18 +1412,18 @@ int do_yesno(int all, int leavecursor, char *msg, ...)
wmove(bottomwin, 1, 0);
snprintf(shortstr, 3, " %c", yesstr[0]);
onekey(shortstr, _("Yes"));
onekey(shortstr, _("Yes"), 16);
if (all) {
snprintf(shortstr, 3, " %c", allstr[0]);
onekey(shortstr, _("All"));
onekey(shortstr, _("All"), 16);
}
wmove(bottomwin, 2, 0);
snprintf(shortstr, 3, " %c", nostr[0]);
onekey(shortstr, _("No"));
onekey(shortstr, _("No"), 16);
onekey("^C", _("Cancel"));
onekey("^C", _("Cancel"), 16);
}
va_start(ap, msg);
vsnprintf(foo, 132, msg, ap);
@ -1556,7 +1569,7 @@ void statusbar(char *msg, ...)
void display_main_list(void)
{
bottombars(main_list, MAIN_VISIBLE);
bottombars(main_list);
}
int total_refresh(void)
@ -1667,10 +1680,8 @@ int do_help(void)
ptr = help_text;
oldshortcut = currshortcut;
oldslen = currslen;
currshortcut = help_list;
currslen = HELP_LIST_LEN;
kp = keypad_on(edit, 1);
kp2 = keypad_on(bottomwin, 1);
@ -1682,10 +1693,10 @@ int do_help(void)
no_help_flag = 1;
UNSET(NO_HELP);
window_init();
bottombars(help_list, HELP_LIST_LEN);
bottombars(help_list);
} else
bottombars(help_list, HELP_LIST_LEN);
bottombars(help_list);
do {
ptr = help_text;
@ -1766,7 +1777,6 @@ int do_help(void)
kbinput != NANO_EXIT_FKEY);
currshortcut = oldshortcut;
currslen = oldslen;
if (no_help_flag) {
blank_bottombars();
@ -1774,7 +1784,7 @@ int do_help(void)
SET(NO_HELP);
window_init();
} else
bottombars(currshortcut, currslen);
bottombars(currshortcut);
curs_set(1);
edit_refresh();
@ -1895,6 +1905,7 @@ void do_credits(void)
"Adam Rogoyski",
"Rob Siemborski",
"Rocco Corsi",
"David Lawrence Ramsey",
"Ken Tyler",
"Sven Guckes",
"Florian KЎnig",
@ -1909,7 +1920,6 @@ void do_credits(void)
"Joshua Jensen",
"Ryan Krebs",
"Albert Chin",
"David Lawrence Ramsey",
"",
specialthx,
"Plattsburgh State University",