Commit a8c22578 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

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
No related merge requests found
Showing with 643 additions and 417 deletions
+643 -417
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).
......
......@@ -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);
......
......@@ -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
......
This diff is collapsed.
......@@ -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)
sofar = snprintf(buf, BUFSIZ,
"M-%c ", toggles[i].override_ch);
else
for (t = toggles; t != NULL; t = t->next) {
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;
}
}
......
......@@ -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
......
......@@ -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();
......
......@@ -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 Knig",
......@@ -1909,7 +1920,6 @@ void do_credits(void)
"Joshua Jensen",
"Ryan Krebs",
"Albert Chin",
"David Lawrence Ramsey",
"",
specialthx,
"Plattsburgh State University",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment