Skip to content

Commit

Permalink
Bug 412151 - Not handling exception when guile is compiled w/o regexp…
Browse files Browse the repository at this point in the history
… support

disable qif-import and make-regexp if guile is compiled without regex
  • Loading branch information
christopherlam committed Oct 12, 2019
1 parent 530f778 commit 4c790b2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
7 changes: 7 additions & 0 deletions gnucash/import-export/qif-imp/assistant-qif-import.c
Expand Up @@ -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);

Expand Down
24 changes: 17 additions & 7 deletions gnucash/import-export/qif-imp/qif-parse.scm
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions gnucash/report/report-system/eguile-gnc.scm
Expand Up @@ -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 \"")
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion gnucash/report/report-system/eguile-html-utilities.scm
Expand Up @@ -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.
Expand Down

0 comments on commit 4c790b2

Please sign in to comment.