commit 38ca2a41f4140e50494bca7567f947e2244f0574
parent 6e3b9ac0587243460c1f8a19d3fcc4402f98808d
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Tue, 11 Dec 2018 10:42:45 +0100
tweaks: reduce the scope of two variables, and rename one of them
Also, swap the order of the 'if', and don't bother setting a freed
string pointer to NULL as it will never be used again.
Diffstat:
3 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/src/global.c b/src/global.c
@@ -142,10 +142,6 @@ char *quotestr = NULL;
/* The quoting string. The default value is set in main(). */
regex_t quotereg;
/* The compiled regular expression from the quoting string. */
-int quoterc;
- /* Whether it was compiled successfully. */
-char *quoteerr = NULL;
- /* The error message, if it didn't. */
#endif
char *word_chars = NULL;
diff --git a/src/nano.c b/src/nano.c
@@ -1954,6 +1954,10 @@ int main(int argc, char **argv)
bool forced_wrapping = FALSE;
/* Should long lines be automatically hard wrapped? */
#endif
+#ifdef ENABLE_JUSTIFY
+ int quoterc;
+ /* Whether the quoting regex was compiled successfully. */
+#endif
const struct option long_options[] = {
{"boldtext", 0, NULL, 'D'},
#ifdef ENABLE_MULTIBUFFER
@@ -2470,20 +2474,16 @@ int main(int argc, char **argv)
if (quotestr == NULL)
quotestr = mallocstrcpy(NULL, "^([ \t]*([#:>|}]|/{2}))+");
- /* Compile the quoting regex, and free it when it's good; otherwise,
- * retrieve and store the error message, to be shown when justifying. */
+ /* Compile the quoting regex, and exit when it's invalid. */
quoterc = regcomp("ereg, quotestr, NANO_REG_EXTENDED);
- if (quoterc == 0) {
- free(quotestr);
- quotestr = NULL;
- } else {
+ if (quoterc != 0) {
size_t size = regerror(quoterc, "ereg, NULL, 0);
+ char *message = charalloc(size);
- quoteerr = charalloc(size);
- regerror(quoterc, "ereg, quoteerr, size);
-
- die(_("Bad quoting regex \"%s\": %s\n"), quotestr, quoteerr);
- }
+ regerror(quoterc, "ereg, message, size);
+ die(_("Bad quoting regex \"%s\": %s\n"), quotestr, message);
+ } else
+ free(quotestr);
#endif /* ENABLE_JUSTIFY */
#ifdef ENABLE_SPELLER
diff --git a/src/proto.h b/src/proto.h
@@ -108,8 +108,6 @@ extern char *punct;
extern char *brackets;
extern char *quotestr;
extern regex_t quotereg;
-extern int quoterc;
-extern char *quoteerr;
#endif
extern char *word_chars;