move advanced text operations (command execution in a buffer, wrapping,

spell checking, justifying, and word counting) to their own source file,
text.c


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2919 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2005-07-24 19:57:51 +00:00
parent 2a73131f0e
commit 691698a954
18 changed files with 2051 additions and 2009 deletions

View File

@ -88,6 +88,19 @@ CVS code -
mbwidth(), make_mbchar(), parse_mbchar(), mbstrncasecmp(),
mbstrcasestr(), mbrevstrcasestr(), mbstrchr(), and
display_string(). (DLR)
- Move advanced text operations (command execution in a buffer,
wrapping, spell checking, justifying, and word counting) to
their own source file, and adjust related variables
accordingly. New file text.c; changes to cancel_command(),
execute_command(), wrap_reset(), do_wrap(),
do_int_spell_fix(), do_int_speller(), do_alt_speller(),
do_spell(), break_line(), indent_length(), justify_format(),
quote_length(), quotes_match(), indents_match(), begpar(),
inpar(), backup_lines(), find_paragraph(), do_justify(),
do_justify_void(), do_full_justify(), and do_word_count() (all
moved to text.c). (DLR)
- color.c:
- Remove unneeded string.h and fcntl.h includes. (DLR)
- chars.c:
mbstrchr()
- Don't count matches between valid and invalid multibyte
@ -157,6 +170,8 @@ CVS code -
HAVE_SNPRINTF. (DLR)
- Remove TOP from the topmidnone enum, and rename it centernone.
(DLR)
- Move stdlib.h, dirent.h, regex.h, and assert.h includes here,
as every source file needs them. (DLR)
proto.h:
- Add declarations for bad_mbchar and bad_mbchar_len, so that we
can use them in display_string() as well as chars.c. (DLR)
@ -219,6 +234,8 @@ CVS code -
tweaks by DLR)
- doc/man/fr/nano.1, doc/man/fr/nanorc.1:
- Updated translation by Jean-Philippe Gérard.
- src/Makefile.am:
- Add text.c to nano_SOURCES. (DLR)
GNU nano 1.3.8 - 2005.06.30
- General:

View File

@ -1,3 +1,7 @@
2005-07-24 David Lawrence Ramsey <pooka_regent@sluggy.net>
* POTFILES.in: Add text.c.
2005-07-19 Jordi Mallach <jordi@gnu.org>
* ms.po: Updated Malay translation by

View File

@ -6,5 +6,6 @@ src/global.c
src/nano.c
src/rcfile.c
src/search.c
src/text.c
src/utils.c
src/winio.c

View File

@ -15,6 +15,7 @@ nano_SOURCES = chars.c \
proto.h \
rcfile.c \
search.c \
text.c \
utils.c \
winio.c

View File

@ -24,10 +24,8 @@
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "proto.h"
#ifdef ENABLE_UTF8

View File

@ -24,12 +24,7 @@
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <assert.h>
#include "proto.h"
#ifdef ENABLE_COLOR

View File

@ -24,10 +24,8 @@
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "proto.h"
static bool keep_cutbuffer = FALSE;

View File

@ -24,7 +24,6 @@
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
@ -34,7 +33,6 @@
#include <errno.h>
#include <ctype.h>
#include <pwd.h>
#include <assert.h>
#include "proto.h"
/* Add an entry to the openfile openfilestruct. This should only be

View File

@ -24,25 +24,28 @@
#include <config.h>
#endif
#include <stdlib.h>
#include <assert.h>
#include "proto.h"
/* Global variables */
#ifndef DISABLE_WRAPJUSTIFY
/* wrap_at might be set in rcfile.c or nano.c. */
ssize_t wrap_at = -CHARS_FROM_EOL; /* Right justified fill value,
allows resize */
ssize_t fill = 0; /* Where we will wrap lines. */
ssize_t wrap_at = -CHARS_FROM_EOL;
/* The position that corresponds to
* fill. If it's greater than zero,
* fill is equal to it. Otherwise, fill
* is equal to the number of screen
* columns less it. This allows
* dynamic wrapping based on the current
* screen width. */
#endif
char *last_search = NULL; /* Last string we searched for */
char *last_replace = NULL; /* Last replacement string */
long flags = 0; /* Our flag containing many options */
WINDOW *topwin; /* Top buffer */
WINDOW *topwin; /* Top subwindow */
WINDOW *edit; /* The file portion of the editor */
WINDOW *bottomwin; /* Bottom buffer */
WINDOW *bottomwin; /* Bottom subwindow */
int editwinrows = 0; /* How many rows long is the edit
window? */

View File

@ -24,10 +24,8 @@
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "proto.h"
void do_first_line(void)

1883
src/nano.c

File diff suppressed because it is too large Load Diff

View File

@ -90,8 +90,14 @@
/* Mark a string that will be sent to gettext() later. */
#include <stddef.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#ifdef HAVE_REGEX_H
#include <regex.h>
#endif
#include <assert.h>
/* If no vsnprintf(), use the version from glib 2.x. */
#ifndef HAVE_VSNPRINTF

View File

@ -24,16 +24,10 @@
#define PROTO_H 1
/* Externs. */
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#ifdef HAVE_REGEX_H
#include <regex.h>
#endif
#include "nano.h"
#ifndef DISABLE_WRAPJUSTIFY
extern ssize_t fill;
extern ssize_t wrap_at;
#endif
extern int editwinrows;
@ -394,51 +388,14 @@ void version(void);
int no_more_space(void);
int no_help(void);
void nano_disabled_msg(void);
#ifndef NANO_SMALL
void cancel_command(int signal);
bool execute_command(const char *command);
#endif
void do_verbatim_input(void);
void do_backspace(void);
void do_delete(void);
void do_tab(void);
void do_enter(void);
#ifndef NANO_SMALL
void do_word_count(void);
void do_mark(void);
#endif
#ifndef DISABLE_WRAPPING
void wrap_reset(void);
bool do_wrap(filestruct *line);
#endif
#ifndef DISABLE_SPELLER
bool do_int_spell_fix(const char *word);
const char *do_int_speller(const char *tempfile_name);
const char *do_alt_speller(char *tempfile_name);
void do_spell(void);
#endif
#if !defined(DISABLE_HELP) || !defined(DISABLE_JUSTIFY) || !defined(DISABLE_WRAPPING)
ssize_t break_line(const char *line, ssize_t goal, bool newline);
#endif
#if !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY)
size_t indent_length(const char *line);
#endif
#ifndef DISABLE_JUSTIFY
void justify_format(filestruct *paragraph, size_t skip);
size_t quote_length(const char *line);
bool quotes_match(const char *a_line, size_t a_quote, const char
*b_line);
bool indents_match(const char *a_line, size_t a_indent, const char
*b_line, size_t b_indent);
bool begpar(const filestruct *const foo);
bool inpar(const filestruct *const foo);
filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t
quote_len);
bool find_paragraph(size_t *const quote, size_t *const par);
void do_justify(bool full_justify);
void do_justify_void(void);
void do_full_justify(void);
#endif /* !DISABLE_JUSTIFY */
void do_exit(void);
void signal_init(void);
void handle_hupterm(int signal);
@ -491,7 +448,6 @@ void not_found_msg(const char *str);
void search_abort(void);
void search_init_globals(void);
int search_init(bool replacing, bool use_answer);
bool is_whole_word(size_t pos, const char *buf, const char *word);
bool findnextstr(bool can_display_wrap, bool wholeword, bool
no_sameline, const filestruct *begin, size_t begin_x, const char
*needle, size_t *needle_len);
@ -535,14 +491,48 @@ char *get_history_completion(filestruct **h, const char *s, size_t len);
#endif
#endif /* !NANO_SMALL */
/* Public functions in text.c. */
#ifndef NANO_SMALL
void cancel_command(int signal);
bool execute_command(const char *command);
#endif
#ifndef DISABLE_WRAPPING
void wrap_reset(void);
bool do_wrap(filestruct *line);
#endif
#ifndef DISABLE_SPELLER
bool do_int_spell_fix(const char *word);
const char *do_int_speller(const char *tempfile_name);
const char *do_alt_speller(char *tempfile_name);
void do_spell(void);
#endif
#if !defined(DISABLE_HELP) || !defined(DISABLE_JUSTIFY) || !defined(DISABLE_WRAPPING)
ssize_t break_line(const char *line, ssize_t goal, bool newline);
#endif
#if !defined(NANO_SMALL) || !defined(DISABLE_JUSTIFY)
size_t indent_length(const char *line);
#endif
#ifndef DISABLE_JUSTIFY
void justify_format(filestruct *paragraph, size_t skip);
size_t quote_length(const char *line);
bool quotes_match(const char *a_line, size_t a_quote, const char
*b_line);
bool indents_match(const char *a_line, size_t a_indent, const char
*b_line, size_t b_indent);
bool begpar(const filestruct *const foo);
bool inpar(const filestruct *const foo);
filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t
quote_len);
bool find_paragraph(size_t *const quote, size_t *const par);
void do_justify(bool full_justify);
void do_justify_void(void);
void do_full_justify(void);
#endif /* !DISABLE_JUSTIFY */
#ifndef NANO_SMALL
void do_word_count(void);
#endif
/* Public functions in utils.c. */
#ifdef HAVE_REGEX_H
#ifdef BROKEN_REGEXEC
int safe_regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags);
#endif
int regexp_bol_or_eol(const regex_t *preg, const char *string);
#endif
int digits(size_t n);
void get_homedir(void);
bool parse_num(const char *str, ssize_t *val);
@ -559,6 +549,14 @@ ssize_t ngetline(char **lineptr, size_t *n, FILE *stream);
ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream);
#endif
#endif /* !NANO_SMALL && ENABLE_NANORC */
#ifdef HAVE_REGEX_H
#ifdef BROKEN_REGEXEC
int safe_regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags);
#endif
int regexp_bol_or_eol(const regex_t *preg, const char *string);
#endif
bool is_whole_word(size_t pos, const char *buf, const char *word);
const char *strstrwrapper(const char *haystack, const char *needle,
const char *start);
void nperror(const char *s);

View File

@ -24,14 +24,12 @@
#include <config.h>
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <ctype.h>
#include <assert.h>
#include "proto.h"
#ifdef ENABLE_NANORC

View File

@ -24,13 +24,11 @@
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#include "proto.h"
static bool search_last_line = FALSE;
@ -256,30 +254,6 @@ int search_init(bool replacing, bool use_answer)
return 0;
}
bool is_whole_word(size_t pos, const char *buf, const char *word)
{
char *p = charalloc(mb_cur_max()), *r = charalloc(mb_cur_max());
size_t word_end = pos + strlen(word);
bool retval;
assert(buf != NULL && pos <= strlen(buf) && word != NULL);
parse_mbchar(buf + move_mbleft(buf, pos), p, NULL, NULL);
parse_mbchar(buf + word_end, r, NULL, NULL);
/* If we're at the beginning of the line or the character before the
* word isn't a non-punctuation "word" character, and if we're at
* the end of the line or the character after the word isn't a
* non-punctuation "word" character, we have a whole word. */
retval = (pos == 0 || !is_word_mbchar(p, FALSE)) &&
(word_end == strlen(buf) || !is_word_mbchar(r, FALSE));
free(p);
free(r);
return retval;
}
/* Look for needle, starting at (current, current_x). If no_sameline is
* TRUE, skip over begin when looking for needle. begin is the line
* where we first started searching, at column begin_x. If

1915
src/text.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -24,37 +24,14 @@
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#include "proto.h"
#ifdef HAVE_REGEX_H
#ifdef BROKEN_REGEXEC
/* Work around a potential segfault in glibc 2.2.3's regexec(). */
int safe_regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags)
{
if (string != NULL && *string != '\0')
return regexec(preg, string, nmatch, pmatch, eflags);
return REG_NOMATCH;
}
#endif
int regexp_bol_or_eol(const regex_t *preg, const char *string)
{
return (regexec(preg, string, 0, NULL, 0) == 0 &&
regexec(preg, string, 0, NULL, REG_NOTBOL | REG_NOTEOL) ==
REG_NOMATCH);
}
#endif /* HAVE_REGEX_H */
int digits(size_t n)
{
int i = 1;
@ -240,6 +217,52 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream)
#endif
#endif /* !NANO_SMALL && ENABLE_NANORC */
#ifdef HAVE_REGEX_H
#ifdef BROKEN_REGEXEC
/* Work around a potential segfault in glibc 2.2.3's regexec(). */
int safe_regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags)
{
if (string != NULL && *string != '\0')
return regexec(preg, string, nmatch, pmatch, eflags);
return REG_NOMATCH;
}
#endif
int regexp_bol_or_eol(const regex_t *preg, const char *string)
{
return (regexec(preg, string, 0, NULL, 0) == 0 &&
regexec(preg, string, 0, NULL, REG_NOTBOL | REG_NOTEOL) ==
REG_NOMATCH);
}
#endif /* HAVE_REGEX_H */
/* Is the word starting at position pos in buf a whole word? */
bool is_whole_word(size_t pos, const char *buf, const char *word)
{
char *p = charalloc(mb_cur_max()), *r = charalloc(mb_cur_max());
size_t word_end = pos + strlen(word);
bool retval;
assert(buf != NULL && pos <= strlen(buf) && word != NULL);
parse_mbchar(buf + move_mbleft(buf, pos), p, NULL, NULL);
parse_mbchar(buf + word_end, r, NULL, NULL);
/* If we're at the beginning of the line or the character before the
* word isn't a non-punctuation "word" character, and if we're at
* the end of the line or the character after the word isn't a
* non-punctuation "word" character, we have a whole word. */
retval = (pos == 0 || !is_word_mbchar(p, FALSE)) &&
(word_end == strlen(buf) || !is_word_mbchar(r, FALSE));
free(p);
free(r);
return retval;
}
/* If we are searching backwards, we will find the last match that
* starts no later than start. Otherwise we find the first match
* starting no earlier than start. If we are doing a regexp search, we

View File

@ -26,10 +26,8 @@
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <assert.h>
#include "proto.h"
static int *key_buffer = NULL;