11ee3a76363a3ef50c3c8f53f87f2902b8122b47
commit 11ee3a76363a3ef50c3c8f53f87f2902b8122b47
Author: Simon Watson <spesk@pm.me>
Date: Tue Dec 21 12:42:13 2021 -0500

Some more adjustments

diff --git a/fin-lisp.lisp b/fin-lisp.lisp
index 7761393..2d042f1 100644
--- a/fin-lisp.lisp
+++ b/fin-lisp.lisp
@@ -72,18 +72,11 @@
while line
collect line)))
(mre (ppcre:create-scanner "^(.*)[0-9]{4}$"))
- ;;(ere (ppcre:create-scanner "^([A-Za-z].*).*$([0-9]{1,4}).*"))
(ere (ppcre:create-scanner "^([A-Z].*)\ -\ \\\$([0-9]{1,4}) - PAID"))
(cur-mon)
(cur-exp))
(loop for line in old-file-lines
do (progn
-;;; (if (ppcre:scan mre line) (progn
-;;; (let ((result)
-;;; (month-num))
-;;; (setf result (ppcre:register-groups-bind (first second) (mre line) :sharedp t (list first second)))
-;;; (setf month-num (cdr (assoc '(first result) *month-table*)))
-;;; (setf cur-mon (concatenate (second result) month-num)))))
(if (ppcre:scan mre line) (setf cur-mon line))
(if (ppcre:scan ere line)
(progn
@@ -98,31 +91,45 @@
(let ((innerhash (gethash cur-mon *records*)))
(setf (gethash (first cur-exp) innerhash) (second cur-exp)))))))))))

-
+
+(defmacro generic-handler (form error-string)
+ `(handler-case ,form
+ (error (e)
+ (format t "Invalid input: ~a ~%" ,error-string)
+ (values 0 e))))

;; Entry point
(defun main ()
- (format t "Available options:~C" #\linefeed)
- (format t "1. Enter expense~C" #\linefeed)
- (format t "2. Display month~C" #\linefeed)
- (format t "3. Write records~C" #\linefeed)
- (format t "4. Read records~C" #\linefeed)
- (format t "5. Quit~C" #\linefeed)
- (format t "6. Import Records~C" #\linefeed)
+ (format t "~%")
+ (format t "Available options:~%")
+ (format t "1. Enter expense~%")
+ (format t "2. Display month~%")
+ (format t "3. Write records~%")
+ (format t "4. Read records~%")
+ (format t "5. Quit~%")
+ (format t "6. Import Records~%")
(let
((answer (prompt-read "Select an option")))
(if (string= answer "1")
- (add-expense-to-month
- (prompt-read "Enter month")))
+ (generic-handler
+ (add-expense-to-month (prompt-read "Enter month"))
+ "Invalid Input"))
(if (string= answer "2")
- (dump-month
- (prompt-read "Enter month")))
+ (generic-handler
+ (dump-month (prompt-read "Enter month"))
+ "Invalid month"))
(if (string= answer "3")
- (serialize-records (prompt-read "Enter filename")))
+ (generic-handler
+ (serialize-records (prompt-read "Enter filename"))
+ "Serialization error or invalid filename"))
(if (string= answer "4")
- (deserialize-records (prompt-read "Enter filename")))
+ (generic-handler
+ (deserialize-records (prompt-read "Enter filename"))
+ "Deserialization error or invalid filename"))
(if (string= answer "5")
(quit))
(if (string= answer "6")
- (import-records (prompt-read "Enter filename"))))
- (main))
+ (generic-handler
+ (import-records (prompt-read "Enter filename"))
+ "Parsing error or invalid filename"))
+ (main)))