From 4c790b2084f904a5b8db10e4d8d5a23449a10005 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 11 Oct 2019 21:26:49 +0800 Subject: [PATCH] Bug 412151 - Not handling exception when guile is compiled w/o regexp support disable qif-import and make-regexp if guile is compiled without regex --- .../qif-imp/assistant-qif-import.c | 7 ++++++ gnucash/import-export/qif-imp/qif-parse.scm | 24 +++++++++++++------ gnucash/report/report-system/eguile-gnc.scm | 8 ++++--- .../report-system/eguile-html-utilities.scm | 3 ++- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/gnucash/import-export/qif-imp/assistant-qif-import.c b/gnucash/import-export/qif-imp/assistant-qif-import.c index 282400f0758..ada03f855cd 100644 --- a/gnucash/import-export/qif-imp/assistant-qif-import.c +++ b/gnucash/import-export/qif-imp/assistant-qif-import.c @@ -3877,6 +3877,13 @@ gnc_file_qif_import (void) { QIFImportWindow *qif_win; gint component_id; + SCM has_regex = scm_c_eval_string ("(defined? 'make-regexp)"); + + if (scm_is_false(has_regex) == 1) + { + gnc_warning_dialog(NULL, _("QIF import requires guile with regex support.")); + return; + } qif_win = g_new0 (QIFImportWindow, 1); diff --git a/gnucash/import-export/qif-imp/qif-parse.scm b/gnucash/import-export/qif-imp/qif-parse.scm index c79959f9184..0350a31a453 100644 --- a/gnucash/import-export/qif-imp/qif-parse.scm +++ b/gnucash/import-export/qif-imp/qif-parse.scm @@ -26,6 +26,8 @@ (use-modules (gnucash import-export string)) (use-modules (srfi srfi-13)) +(define regexp-enabled? + (defined? 'make-regexp)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; qif-split:parse-category ;; this one just gets nastier and nastier. @@ -40,7 +42,9 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define qif-category-compiled-rexp - (make-regexp "^ *(\\[)?([^]/|]*)(]?)(/?)([^|]*)(\\|(\\[)?([^]/]*)(]?)(/?)(.*))? *$")) + (and regexp-enabled? + (make-regexp "^ *(\\[)?([^]/|]*)(]?)(/?)([^|]*)(\\|(\\[)?([^]/]*)(]?)(/?)(.*))? *$"))) + (define (qif-split:parse-category self value) ;; example category regex matches (excluding initial 'L'): ;; field1 @@ -267,13 +271,16 @@ ;; of possibilities. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define qif-date-compiled-rexp - (make-regexp "^ *([0-9]+) *[-/.'] *([0-9]+) *[-/.'] *([0-9]+).*$|^ *([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]).*$")) + (and regexp-enabled? + (make-regexp "^ *([0-9]+) *[-/.'] *([0-9]+) *[-/.'] *([0-9]+).*$|^ *([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]).*$"))) (define qif-date-mdy-compiled-rexp - (make-regexp "([0-9][0-9])([0-9][0-9])([0-9][0-9][0-9][0-9])")) + (and regexp-enabled? + (make-regexp "([0-9][0-9])([0-9][0-9])([0-9][0-9][0-9][0-9])"))) (define qif-date-ymd-compiled-rexp - (make-regexp "([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])")) + (and regexp-enabled? + (make-regexp "([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])"))) (define (qif-parse:check-date-format date-string possible-formats) (and (string? date-string) @@ -358,15 +365,18 @@ ;; eg 1000.00 or 1,500.00 or 2'000.00 (define decimal-radix-regexp - (make-regexp "^ *[$]?[+-]?[$]?[0-9]+[+-]?$|^ *[$]?[+-]?[$]?[0-9]?[0-9]?[0-9]?([,'][0-9][0-9][0-9])*(\\.[0-9]*)?[+-]? *$|^ *[$]?[+-]?[$]?[0-9]+\\.[0-9]*[+-]? *$")) + (and regexp-enabled? + (make-regexp "^ *[$]?[+-]?[$]?[0-9]+[+-]?$|^ *[$]?[+-]?[$]?[0-9]?[0-9]?[0-9]?([,'][0-9][0-9][0-9])*(\\.[0-9]*)?[+-]? *$|^ *[$]?[+-]?[$]?[0-9]+\\.[0-9]*[+-]? *$"))) ;; eg 5.000,00 or 4'500,00 (define comma-radix-regexp - (make-regexp "^ *[$]?[+-]?[$]?[0-9]+[+-]?$|^ *[$]?[+-]?[$]?[0-9]?[0-9]?[0-9]?([\\.'][0-9][0-9][0-9])*(,[0-9]*)?[+-]? *$|^ *[$]?[+-]?[$]?[0-9]+,[0-9]*[+-]? *$")) + (and regexp-enabled? + (make-regexp "^ *[$]?[+-]?[$]?[0-9]+[+-]?$|^ *[$]?[+-]?[$]?[0-9]?[0-9]?[0-9]?([\\.'][0-9][0-9][0-9])*(,[0-9]*)?[+-]? *$|^ *[$]?[+-]?[$]?[0-9]+,[0-9]*[+-]? *$"))) ;; eg 456 or 123 (define integer-regexp - (make-regexp "^[$]?[+-]?[$]?[0-9]+[+-]? *$")) + (and regexp-enabled? + (make-regexp "^[$]?[+-]?[$]?[0-9]+[+-]? *$"))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; qif-parse:check-number-format diff --git a/gnucash/report/report-system/eguile-gnc.scm b/gnucash/report/report-system/eguile-gnc.scm index 1731ca6aeda..f37b95dd36f 100644 --- a/gnucash/report/report-system/eguile-gnc.scm +++ b/gnucash/report/report-system/eguile-gnc.scm @@ -108,8 +108,8 @@ (#\& . "&")))) ;; regexps used to find start and end of code segments -(define startre (make-regexp "<\\?scm(:d)?[[:space:]]")) -(define endre (make-regexp "(^|[[:space:]])\\?>")) +(define startre (and (defined? 'make-regexp) (make-regexp "<\\?scm(:d)?[[:space:]]"))) +(define endre (and (defined? 'make-regexp) (make-regexp "(^|[[:space:]])\\?>"))) ;; Guile code to mark starting and stopping text or code modes (define textstart "(display \"") @@ -170,7 +170,9 @@ (loop inp needle other code? ""))))) (display textstart) - (loop (current-input-port) startre endre #f "") + (if (defined? 'make-regexp) + (loop (current-input-port) startre endre #f "") + (display "eguile requires guile with regex.")) (display stop)) ;end of (template->script) diff --git a/gnucash/report/report-system/eguile-html-utilities.scm b/gnucash/report/report-system/eguile-html-utilities.scm index d123f6109a3..7ff8a94d67f 100644 --- a/gnucash/report/report-system/eguile-html-utilities.scm +++ b/gnucash/report/report-system/eguile-html-utilities.scm @@ -88,7 +88,8 @@ ;; (thanks to Peter Brett for this regexp and the use of match:prefix) (define fontre - (make-regexp "([[:space:]]+(bold|semi-bold|book|regular|medium|light))?([[:space:]]+(normal|roman|italic|oblique))?([[:space:]]+(condensed))?[[:space:]]+([[:digit:]]+)" regexp/icase)) + (and (defined? 'make-regexp) + (make-regexp "([[:space:]]+(bold|semi-bold|book|regular|medium|light))?([[:space:]]+(normal|roman|italic|oblique))?([[:space:]]+(condensed))?[[:space:]]+([[:digit:]]+)" regexp/icase))) (define-public (font-name-to-style-info font-name) ;;; Convert a font name as return by a font option to CSS format.