summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Pelz <pelzflorian@pelzflorian.de>2017-12-14 11:38:42 +0100
committerFlorian Pelz <pelzflorian@pelzflorian.de>2017-12-14 11:38:42 +0100
commit68b57649d9c3167630c5bf192bedafdccc542ea0 (patch)
tree7f05c0218209d62c36c990d5f69303d60f9a20ef
parente861a7e316d0c2ff2239a40fe0fc1fbe04e5673c (diff)
Add proper Gettext xerror handlers.
-rw-r--r--haunt.scm45
1 files changed, 40 insertions, 5 deletions
diff --git a/haunt.scm b/haunt.scm
index 18c5d3b..88dcce4 100644
--- a/haunt.scm
+++ b/haunt.scm
@@ -51,8 +51,37 @@
(list "de"
"en"))
-(define (xerror-handler severity message filename lineno column multiline-p1 message-text)
- (display "xerror occurred!"))
+(define (xerror-severity->string severity)
+ "Returns the enum name for an integer specifying xerror severity."
+ (cond ((= severity 0) "PO_SEVERITY_WARNING")
+ ((= severity 1) "PO_SEVERITY_ERROR")
+ ((= severity 2) "PO_SEVERITY_FATAL_ERROR")
+ (else "")))
+
+(define (xerror-output-proc-for-severity severity)
+ "Given an xerror severity, returns which procedure to use to signal an xerror."
+ (if (= severity 2)
+ error
+ ;; otherwise:
+ (lambda args
+ (begin
+ (apply simple-format #t args)
+ (newline)))))
+
+(define (xerror-handler
+ severity
+ message
+ filename
+ lineno
+ column
+ multiline-p1
+ message-text)
+ (let ((output (xerror-output-proc-for-severity severity)))
+ (output "Gettext xerror occurred! ~A “~A” in ~A:~A."
+ (xerror-severity->string severity)
+ (ffi:pointer->string message-text)
+ (ffi:pointer->string filename)
+ lineno)))
(define ~xerror-handler
(ffi:procedure->pointer
ffi:void
@@ -65,12 +94,18 @@
ffi:int
'*)))
-;;; TODO USE SIMPLE-FORMAT AND DISPLAY ERRORS PROPERLY
-
(define (xerror2-handler severity message
filename1 lineno1 column1 multiline-p1 message-text1
filename2 lineno2 column2 multiline-p2 message-text2)
- (display "xerror occurred!"))
+ (let ((output (xerror-output-proc-for-severity severity)))
+ (output "Gettext xerror occurred! ~A “~A” in ~A:~A, “~A” in ~A:~A."
+ (xerror-severity->string severity)
+ (ffi:pointer->string message-text1)
+ (ffi:pointer->string filename1)
+ lineno1
+ (ffi:pointer->string message-text2)
+ (ffi:pointer->string filename2)
+ lineno2)))
(define ~xerror2-handler
(ffi:procedure->pointer
ffi:void