[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] nanothings.patch update
From: |
David Lawrence Ramsey |
Subject: |
[Nano-devel] nanothings.patch update |
Date: |
Fri, 1 Feb 2002 05:19:51 -0800 (PST) |
Changes:
* Made M-] appear on the left as the multibuffer keys M-<
and M-> do, by treating it as a special toggle (as they
are).
Still testing; if this gets any bigger than 15k, I'm going
to start posting it online (at
http://pooka-regent.freeservers.com/patches/main.html).
_____________________________________________________________
Sluggy.Net: The Sluggy Freelance Community!
diff -urN nano-1.1.6-cvs/files.c nano-1.1.6-cvs-fixed/files.c
--- nano-1.1.6-cvs/files.c Fri Jan 4 12:57:40 2002
+++ nano-1.1.6-cvs-fixed/files.c Thu Jan 31 23:23:31 2002
@@ -141,8 +141,9 @@
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--;
@@ -211,8 +212,9 @@
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') {
+ /* 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++;
@@ -852,9 +854,9 @@
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 +865,7 @@
* 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 +1005,124 @@
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 using the same method as tempnam(), safely creates the temporary
+ * file there via mkstemp(), and returns the name of the temporary file
+ * as 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 [filename_prefix]_tmpdir
+ instead */
+ if (!full_tempdir) {
+ tempdir = charalloc(strlen(filename_prefix) + 9);
+ sprintf(tempdir, "%s_tmpdir", filename_prefix);
+ full_tempdir = check_writable_directory(tempdir, &writable);
+
+ /* we don't need the value of tempdir anymore */
+ free(tempdir);
+ }
+
+ /* if [filename_prefix]_tmpdir didn't work, use /tmp instead */
+ if (!full_tempdir) {
+ full_tempdir = charalloc(6);
+ strcpy(full_tempdir, "/tmp/");
+ }
+
+ buf = charalloc(strlen(full_tempdir) + strlen(filename_prefix) + 7);
+ sprintf(buf, "%s%s", full_tempdir, filename_prefix);
+ 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
/*
@@ -1077,7 +1196,7 @@
/* otherwise, we're still inside it */
return 0;
}
-#endif
+#endif /* !DISABLE_OPERATINGDIR */
/*
* Write a file out. If tmp is nonzero, we set the umask to 0600,
diff -urN nano-1.1.6-cvs/global.c nano-1.1.6-cvs-fixed/global.c
--- nano-1.1.6-cvs/global.c Wed Jan 9 19:50:38 2002
+++ nano-1.1.6-cvs-fixed/global.c Thu Jan 31 23:26:15 2002
@@ -160,7 +160,7 @@
#endif
#ifdef HAVE_REGEX_H
- char *toggle_regexp_msg;
+ char *toggle_regexp_msg, *nano_bracket_msg;
#endif
@@ -188,6 +188,10 @@
nano_opennext_msg = _("Open next loaded file");
#endif
+#ifdef HAVE_REGEX_H
+ nano_bracket_msg = "Find other bracket";
+#endif
+
toggle_init_one(&toggles[0], TOGGLE_CONST_KEY, toggle_const_msg,
CONSTUPDATE, 0);
toggle_init_one(&toggles[1], TOGGLE_AUTOINDENT_KEY,
@@ -215,18 +219,20 @@
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, '>');
+#ifdef HAVE_REGEX_H
+ toggle_init_one(&toggles[13], TOGGLE_REGEXP_KEY, toggle_regexp_msg,
+ USE_REGEXP, 0);
+ toggle_init_one(&toggles[14], NANO_BRACKET_KEY, nano_bracket_msg,
+ 0, ']');
#endif
-#ifdef HAVE_REGEX_H
- toggle_init_one(&toggles[TOGGLE_LEN - 1], TOGGLE_REGEXP_KEY,
- toggle_regexp_msg, USE_REGEXP, 0);
+#ifdef ENABLE_MULTIBUFFER
+ toggle_init_one(&toggles[TOGGLE_LEN - 3], TOGGLE_LOAD_KEY,
+ toggle_load_msg, MULTIBUFFER, 0);
+ toggle_init_one(&toggles[TOGGLE_LEN - 2], NANO_OPENPREV_KEY,
+ nano_openprev_msg, 0, '<');
+ toggle_init_one(&toggles[TOGGLE_LEN - 1], NANO_OPENNEXT_KEY,
+ nano_opennext_msg, 0, '>');
#endif
#endif
}
@@ -251,7 +257,7 @@
char *nano_tofiles_msg = "", *nano_gotodir_msg = "", *nano_case_msg =
"", *nano_reverse_msg = "";
#ifdef HAVE_REGEX_H
- char *nano_regexp_msg = "", *nano_bracket_msg = "";
+ char *nano_regexp_msg = "";
#endif
nano_help_msg = _("Invoke the help menu");
@@ -299,7 +305,6 @@
nano_reverse_msg = _("Search backwards");
#ifdef HAVE_REGEX_H
nano_regexp_msg = _("Use Regular expressions");
- nano_bracket_msg = _("Find other bracket");
#endif
#endif
@@ -436,12 +441,6 @@
sc_init_one(&main_list[25], 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"),
- nano_bracket_msg,
- NANO_BRACKET_KEY, 0, 0, VIEW, do_find_bracket);
-#endif
sc_init_one(&whereis_list[0], NANO_HELP_KEY,
diff -urN nano-1.1.6-cvs/nano.c nano-1.1.6-cvs-fixed/nano.c
--- nano-1.1.6-cvs/nano.c Fri Jan 25 16:59:02 2002
+++ nano-1.1.6-cvs-fixed/nano.c Thu Jan 31 23:23:31 2002
@@ -428,6 +428,9 @@
printf
(_
(" -M --mac Write file in Mac format\n"));
+ printf
+ (_
+ (" -N --noconvert Don't convert files from
DOS/Mac format\n"));
#endif
#ifdef HAVE_REGEX_H
printf(_
@@ -1736,7 +1739,7 @@
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;
@@ -2715,6 +2718,7 @@
{"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'},
@@ -2761,11 +2765,11 @@
#endif /* ENABLE_NANORC */
#ifdef HAVE_GETOPT_LONG
- while ((optchr = getopt_long(argc, argv,
"h?CDFKMRST:Vabcefgijklmo:pr:s:tvwxz",
+ while ((optchr = getopt_long(argc, argv,
"h?CDFKMNRST:Vabcefgijklmo:pr:s:tvwxz",
long_options, &option_index)) != EOF) {
#else
while ((optchr =
- getopt(argc, argv, "h?CDFKMRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) {
+ getopt(argc, argv, "h?CDFKMNRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF)
{
#endif
switch (optchr) {
@@ -2790,6 +2794,9 @@
case 'M':
SET(MAC_FILE);
break;
+ case 'N':
+ SET(NO_CONVERT);
+ break;
#endif
case 'T':
tabsize = atoi(optarg);
@@ -3178,6 +3185,8 @@
break;
}
break;
+
+#ifndef NANO_SMALL
#ifdef ENABLE_MULTIBUFFER
case NANO_OPENPREV_KEY:
case NANO_OPENPREV_ALTKEY:
@@ -3189,7 +3198,16 @@
open_nextfile(0);
keyhandled = 1;
break;
-#endif
+#endif /* MULTIBUFFER */
+
+#ifdef HAVE_REGEX_H
+ case NANO_BRACKET_KEY:
+ do_find_bracket();
+ keyhandled = 1;
+ break;
+#endif /* HAVE_REGEX_H */
+#endif /* !NANO_SMALL */
+
default:
/* Check for the altkey defs.... */
for (i = 0; i <= MAIN_LIST_LEN - 1; i++)
diff -urN nano-1.1.6-cvs/nano.h nano-1.1.6-cvs-fixed/nano.h
--- nano-1.1.6-cvs/nano.h Fri Jan 25 16:59:02 2002
+++ nano-1.1.6-cvs-fixed/nano.h Thu Jan 31 23:23:31 2002
@@ -163,6 +163,7 @@
#define DISABLE_CURPOS (1<<24) /* Damn, we still need it */
#define ALT_KEYPAD (1<<25) /* Damn, we still need it */
#define RELATIVECHARS (1<<26)
+#define NO_CONVERT (1<<27)
/* Control key sequences, changing these would be very very bad */
@@ -330,11 +331,14 @@
#ifdef NANO_SMALL
#ifdef HAVE_REGEX_H
#define NO_TOGGLES 3
+#define BRACKET_TOGGLE 0
#else
#define NO_TOGGLES 2
+#define BRACKET_TOGGLE 0
#endif /* HAVE_REGEX_H */
#else
#define NO_TOGGLES 0
+#define BRACKET_TOGGLE 1
#endif /* NANO_SMALL */
#ifdef ENABLE_MULTIBUFFER
@@ -345,11 +349,11 @@
#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 TOGGLE_LEN (14 - NO_REGEX + MULTI_TOGGLES + BRACKET_TOGGLE)
#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_LIST_LEN (26 - NO_REGEX - SMALL_TOO)
#define MAIN_VISIBLE 12
#define REPLACE_LIST_2_LEN 4
#define GOTO_LIST_LEN 4
diff -urN nano-1.1.6-cvs/nanorc.sample nano-1.1.6-cvs-fixed/nanorc.sample
--- nano-1.1.6-cvs/nanorc.sample Fri Jan 25 22:34:06 2002
+++ nano-1.1.6-cvs-fixed/nanorc.sample Thu Jan 31 23:23:31 2002
@@ -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
diff -urN nano-1.1.6-cvs/proto.h nano-1.1.6-cvs-fixed/proto.h
--- nano-1.1.6-cvs/proto.h Tue Jan 8 10:00:24 2002
+++ nano-1.1.6-cvs-fixed/proto.h Thu Jan 31 23:23:31 2002
@@ -194,7 +194,6 @@
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);
@@ -218,8 +217,13 @@
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
diff -urN nano-1.1.6-cvs/rcfile.c nano-1.1.6-cvs-fixed/rcfile.c
--- nano-1.1.6-cvs/rcfile.c Fri Jan 25 16:59:02 2002
+++ nano-1.1.6-cvs-fixed/rcfile.c Thu Jan 31 23:23:31 2002
@@ -41,9 +41,9 @@
#endif
#ifndef DISABLE_WRAPJUSTIFY
-#define NUM_RCOPTS 20
+#define NUM_RCOPTS 21
#else
-#define NUM_RCOPTS 19
+#define NUM_RCOPTS 20
#endif
/* Static stuff for the nanorc file */
@@ -71,7 +71,8 @@
{"multibuffer", MULTIBUFFER},
{"smooth", SMOOTHSCROLL},
{"keypad", ALT_KEYPAD},
- {"relative", RELATIVECHARS}
+ {"relative", RELATIVECHARS},
+ {"noconvert", NO_CONVERT}
};
static int errors = 0;
diff -urN nano-1.1.6-cvs/winio.c nano-1.1.6-cvs-fixed/winio.c
--- nano-1.1.6-cvs/winio.c Fri Jan 25 16:59:02 2002
+++ nano-1.1.6-cvs-fixed/winio.c Thu Jan 31 23:23:31 2002
@@ -1902,6 +1902,7 @@
"Adam Rogoyski",
"Rob Siemborski",
"Rocco Corsi",
+ "David Lawrence Ramsey",
"Ken Tyler",
"Sven Guckes",
"Florian König",
@@ -1916,7 +1917,6 @@
"Joshua Jensen",
"Ryan Krebs",
"Albert Chin",
- "David Lawrence Ramsey",
"",
specialthx,
"Plattsburgh State University",
- [Nano-devel] nanothings.patch update,
David Lawrence Ramsey <=