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
This commit is contained in:
Christopher Lam 2019-10-11 21:26:49 +08:00
parent 530f778dbb
commit 4c790b2084
4 changed files with 31 additions and 11 deletions

View File

@ -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);

View File

@ -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

View File

@ -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)

View File

@ -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.