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

- Preliminary quoting support for justify. New arg -Q, --quotestr, changes...

 - Preliminary quoting support for justify.  New arg -Q, --quotestr, changes to do_justify(), global variable quotestr()


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1092 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 5f87021c
Showing with 61 additions and 12 deletions
+61 -12
...@@ -23,6 +23,8 @@ CVS code - ...@@ -23,6 +23,8 @@ CVS code -
name!) & free_toggles(), and big cleanup program name!) & free_toggles(), and big cleanup program
thanks_for_all_the_fish() (originally thanks_for_all_the_fish() (originally
thanks_for_the_memories()). Mods to shortcut_init() by Chris. thanks_for_the_memories()). Mods to shortcut_init() by Chris.
- Preliminary quoting support for justify. New arg -Q, --quotestr,
changes to do_justify(), global variable quotestr().
- Makefile.am: - Makefile.am:
- Add SYSCONFDIR to DEFS, so we can have an /etc/nanorc. - Add SYSCONFDIR to DEFS, so we can have an /etc/nanorc.
- Change localedir line to 1.0's version. - Change localedir line to 1.0's version.
......
...@@ -59,6 +59,10 @@ filestruct *cutbuffer = NULL; /* A place to store cut text */ ...@@ -59,6 +59,10 @@ filestruct *cutbuffer = NULL; /* A place to store cut text */
filestruct *open_files = NULL; /* The list of open files */ filestruct *open_files = NULL; /* The list of open files */
#endif #endif
#ifndef DISABLE_JUSTIFY
char *quotestr = "> "; /* Quote string */
#endif
char *answer = NULL; /* Answer str to many questions */ char *answer = NULL; /* Answer str to many questions */
int totlines = 0; /* Total number of lines in the file */ int totlines = 0; /* Total number of lines in the file */
long totsize = 0; /* Total number of bytes in the file */ long totsize = 0; /* Total number of bytes in the file */
......
...@@ -438,6 +438,11 @@ void usage(void) ...@@ -438,6 +438,11 @@ void usage(void)
(_ (_
(" -N --noconvert Don't convert files from DOS/Mac format\n")); (" -N --noconvert Don't convert files from DOS/Mac format\n"));
#endif #endif
#ifndef DISABLE_JUSTIFY
printf
(_
(" -Q [str] --quotestr [num] Quoting string, default \"> \"\n"));
#endif
#ifndef NANO_SMALL #ifndef NANO_SMALL
printf(_ printf(_
(" -S --smooth Smooth scrolling\n")); (" -S --smooth Smooth scrolling\n"));
...@@ -506,6 +511,9 @@ void usage(void) ...@@ -506,6 +511,9 @@ void usage(void)
printf(_(" -K Use alternate keypad routines\n")); printf(_(" -K Use alternate keypad routines\n"));
#ifndef NANO_SMALL #ifndef NANO_SMALL
printf(_(" -M Write file in Mac format\n")); printf(_(" -M Write file in Mac format\n"));
#endif
#ifndef DISABLE_JUSTIFY
printf(_(" -Q [str] Quoting string, default \"> \"\n"));
#endif #endif
printf(_(" -R Use regular expressions for search\n")); printf(_(" -R Use regular expressions for search\n"));
#ifndef NANO_SMALL #ifndef NANO_SMALL
...@@ -2220,8 +2228,14 @@ int do_justify(void) ...@@ -2220,8 +2228,14 @@ int do_justify(void)
int slen = 0; /* length of combined lines on one line. */ int slen = 0; /* length of combined lines on one line. */
int initial_y, kbinput = 0, totbak; int initial_y, kbinput = 0, totbak;
filestruct *initial = NULL, *tmpjust = NULL, *cutbak, *tmptop, *tmpbot; filestruct *initial = NULL, *tmpjust = NULL, *cutbak, *tmptop, *tmpbot;
filestruct *samecheck = current;
int qdepth = 0;
/* Compute quote depth level */
while (!strncmp(&current->data[qdepth], quotestr, strlen(quotestr)))
qdepth += strlen(quotestr);
if (empty_line(current->data)) { if (empty_line(&current->data[qdepth])) {
/* Justify starting at first non-empty line. */ /* Justify starting at first non-empty line. */
do { do {
if (!current->next) if (!current->next)
...@@ -2230,14 +2244,23 @@ int do_justify(void) ...@@ -2230,14 +2244,23 @@ int do_justify(void)
current = current->next; current = current->next;
current_y++; current_y++;
} }
while (empty_line(current->data)); while (strlen(current->data) >= qdepth
&& !strncmp(current->data, samecheck->data, qdepth)
&& empty_line(&current->data[qdepth]));
} else { } else {
/* Search back for the beginning of the paragraph, where /* Search back for the beginning of the paragraph, where
* Paragraph is 1) A line with leading whitespace * Paragraph is 1) A line with leading whitespace
* or 2) A line following an empty line. * or 2) A line following an empty line.
*/ */
while (current->prev != NULL) { while (current->prev != NULL) {
if (isspace((int) current->data[0]) || !current->data[0]) if (strncmp(current->data, samecheck->data, qdepth)
/* Don't keep going back if the previous line is more
intented quotestr-wise than samecheck */
|| !strncmp(&current->data[qdepth], quotestr, strlen(quotestr))
|| isspace((int) current->data[qdepth])
|| empty_line(&current->data[qdepth]))
break; break;
current = current->prev; current = current->prev;
...@@ -2245,7 +2268,9 @@ int do_justify(void) ...@@ -2245,7 +2268,9 @@ int do_justify(void)
} }
/* First line with leading whitespace may be empty. */ /* First line with leading whitespace may be empty. */
if (empty_line(current->data)) { if (strncmp(current->data, samecheck->data, qdepth)
|| !strncmp(&current->data[qdepth], quotestr, strlen(quotestr))
|| empty_line(&current->data[qdepth])) {
if (current->next) { if (current->next) {
current = current->next; current = current->next;
current_y++; current_y++;
...@@ -2263,16 +2288,18 @@ int do_justify(void) ...@@ -2263,16 +2288,18 @@ int do_justify(void)
tmptop = current; tmptop = current;
tmpjust = copy_node(current); tmpjust = copy_node(current);
samecheck = tmpjust;
/* This is annoying because it mucks with totsize */ /* This is annoying because it mucks with totsize */
add_to_cutbuffer(tmpjust); add_to_cutbuffer(tmpjust);
/* Put the whole paragraph into one big line. */ /* Put the whole paragraph into one big line. */
while (current->next && !isspace((int) current->next->data[0]) while (current->next && !isspace((int) current->next->data[0])
&& current->next->data[0]) { && !strncmp(current->next->data, samecheck->data, qdepth)
&& !empty_line(&current->next->data[qdepth])) {
filestruct *tmpnode = current->next; filestruct *tmpnode = current->next;
int len = strlen(current->data); int len = strlen(current->data);
int len2 = strlen(current->next->data); int len2 = strlen(current->next->data) - qdepth;
tmpjust = NULL; tmpjust = NULL;
tmpjust = copy_node(current->next); tmpjust = copy_node(current->next);
...@@ -2286,7 +2313,7 @@ int do_justify(void) ...@@ -2286,7 +2313,7 @@ int do_justify(void)
current->data[len++] = ' '; current->data[len++] = ' ';
current->data[len] = '\0'; current->data[len] = '\0';
strncat(current->data, current->next->data, len2); strncat(current->data, &current->next->data[qdepth], len2);
unlink_node(tmpnode); unlink_node(tmpnode);
delete_node(tmpnode); delete_node(tmpnode);
...@@ -2300,7 +2327,7 @@ int do_justify(void) ...@@ -2300,7 +2327,7 @@ int do_justify(void)
if ((strlenpt(current->data) > (fill)) if ((strlenpt(current->data) > (fill))
&& !no_spaces(current->data)) { && !no_spaces(current->data)) {
do { do {
int i = 0; int i = 0, j = 0;
int len2 = 0; int len2 = 0;
filestruct *tmpline = nmalloc(sizeof(filestruct)); filestruct *tmpline = nmalloc(sizeof(filestruct));
...@@ -2325,10 +2352,14 @@ int do_justify(void) ...@@ -2325,10 +2352,14 @@ int do_justify(void)
current->data[i] = '\0'; current->data[i] = '\0';
len2 = strlen(current->data + i + 1); len2 = strlen(current->data + i + 1);
tmpline->data = charalloc(len2 + 1); tmpline->data = charalloc(len2 + 1 + qdepth);
tmpline->data[0] = '\0';
for (j = 0; j < qdepth; j += strlen(quotestr))
strcpy(&tmpline->data[j], quotestr);
/* Skip the white space in current. */ /* Skip the white space in current. */
memcpy(tmpline->data, current->data + i + 1, len2); memcpy(&tmpline->data[j], current->data + i + 1, len2);
tmpline->data[len2] = '\0'; tmpline->data[len2] = '\0';
current->data = nrealloc(current->data, i + 1); current->data = nrealloc(current->data, i + 1);
...@@ -2786,11 +2817,11 @@ int main(int argc, char *argv[]) ...@@ -2786,11 +2817,11 @@ int main(int argc, char *argv[])
#endif /* ENABLE_NANORC */ #endif /* ENABLE_NANORC */
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
while ((optchr = getopt_long(argc, argv, "h?DFKMNRST:Vabcefgijklmo:pr:s:tvwxz", while ((optchr = getopt_long(argc, argv, "h?DFKMNQ:RST:Vabcefgijklmo:pr:s:tvwxz",
long_options, &option_index)) != EOF) { long_options, &option_index)) != EOF) {
#else #else
while ((optchr = while ((optchr =
getopt(argc, argv, "h?DFKMNRST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) { getopt(argc, argv, "h?DFKMNQ:RST:Vabcefgijklmo:pr:s:tvwxz")) != EOF) {
#endif #endif
switch (optchr) { switch (optchr) {
...@@ -2815,6 +2846,14 @@ int main(int argc, char *argv[]) ...@@ -2815,6 +2846,14 @@ int main(int argc, char *argv[])
case 'N': case 'N':
SET(NO_CONVERT); SET(NO_CONVERT);
break; break;
#endif
case 'Q':
#ifndef DISABLE_JUSTIFY
quotestr = optarg;
break;
#else
usage(); /* To stop bogus data for tab width */
finish(1);
#endif #endif
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
case 'R': case 'R':
......
...@@ -39,6 +39,10 @@ extern int fill, wrap_at, flags,tabsize; ...@@ -39,6 +39,10 @@ extern int fill, wrap_at, flags,tabsize;
extern int search_last_line; extern int search_last_line;
extern int currslen; extern int currslen;
#ifndef DISABLE_JUSTIFY
char *quotestr;
#endif
extern WINDOW *edit, *topwin, *bottomwin; extern WINDOW *edit, *topwin, *bottomwin;
extern char *filename; extern char *filename;
extern char *answer; extern char *answer;
......
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