Skip to content

Commit 73430f6

Browse files
committed
fix(import): use cond statement instead of if
1 parent d2435e8 commit 73430f6

File tree

2 files changed

+62
-50
lines changed

2 files changed

+62
-50
lines changed

src/import.lisp

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,41 @@
3030
(loop for line = (read-line stream nil nil) for index from 0
3131
while line
3232
do (progn
33-
(if (= 0 index)
34-
(checkICS line))
35-
(if (and (checkForBEGINEVENT line)
36-
(not inVEVENT))
37-
(setf inVEVENT t))
38-
(if (and (checkForStart line) inVEVENT)
39-
(progn
40-
(setf startTimeFound t)
41-
(setf startTime (getStartTime line))))
42-
(if (and (checkForEndOrDuration line) inVEVENT)
43-
(progn
44-
(setf endTimeFound t)
45-
(setf endTime (getEndTime startTime line))))
46-
(if (and (checkForSummary line) inVEVENT)
47-
(progn
48-
(setf summaryFound t)
49-
(setf summary (getSummaryDesc line))))
50-
(if (and (checkForDesc line) inVEVENT)
51-
(progn
52-
(setf descFound t)
53-
(setf desc (getSummaryDesc line))))
54-
(if (and (checkForENDEVENT line) inVEVENT)
55-
(progn
56-
(if (and startTimeFound endTimeFound summaryFound)
57-
(progn
58-
(with-standard-io-syntax
59-
(if descFound
60-
(setf output (format nil "~$::~$::~$::~$" startTime endTime summary desc))
61-
(setf output (format nil "~$::~$::~$" startTime endTime summary)))
62-
(addEvent output)
63-
(format t "Imported event (start, end, summary): ~a, ~a, ~a~%" startTime endTime summary))))
64-
(setf inVEVENT nil)
65-
(setf startTimeFound nil)
66-
(setf endTimeFound nil)
67-
(setf summaryFound nil)
68-
(setf descFound nil))))))
33+
(cond ((= 0 index)
34+
(checkICS line))
35+
((and (checkForBEGINEVENT line) (not inVEVENT))
36+
(setf inVEVENT t))
37+
((and (checkForStart line) inVEVENT)
38+
(setf startTimeFound t)
39+
(setf startTime (getStartTime line)))
40+
((and (checkForEndOrDuration line) inVEVENT)
41+
(setf endTimeFound t)
42+
(setf endTime (getEndTime startTime line)))
43+
((and (checkForSummary line) inVEVENT)
44+
(setf summaryFound t)
45+
(setf summary (getSummaryDesc line)))
46+
((and (checkForDesc line) inVEVENT)
47+
(setf descFound t)
48+
(setf desc (getSummaryDesc line)))
49+
((and (checkForENDEVENT line) inVEVENT)
50+
(cond ((not startTimeFound)
51+
(format t "Found an event with missing start time ending at line ~a, skipping import.~%" index))
52+
((not endTimeFound)
53+
(format t "Found an event with missing end time ending at line ~a, skipping import.~%" index))
54+
((not summaryFound)
55+
(format t "Found an event with missing summary ending at line ~a, skipping import.~%" index))
56+
(t
57+
(with-standard-io-syntax
58+
(if descFound
59+
(setf output (format nil "~$::~$::~$::~$" startTime endTime summary desc))
60+
(setf output (format nil "~$::~$::~$" startTime endTime summary)))
61+
(addEvent output)
62+
(format t "Imported event (start, end, summary): ~a, ~a, ~a~%" startTime endTime summary))))
63+
(setf inVEVENT nil)
64+
(setf startTimeFound nil)
65+
(setf endTimeFound nil)
66+
(setf summaryFound nil)
67+
(setf descFound nil))))))
6968
(format t "Import finished.~%")))
7069

7170
(defun import/command ()

src/import.lisp~

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
do (progn
3333
(if (= 0 index)
3434
(checkICS line))
35-
(if (and (checkForVEVENT line)
35+
(if (and (checkForBEGINEVENT line)
3636
(not inVEVENT))
3737
(setf inVEVENT t))
3838
(if (and (checkForStart line) inVEVENT)
@@ -50,16 +50,23 @@
5050
(if (and (checkForDesc line) inVEVENT)
5151
(progn
5252
(setf descFound t)
53-
(setf desc (getSummaryDesc line)))))))
54-
(if (and inVEVENT startTimeFound endTimeFound summaryFound)
55-
(progn
56-
(with-standard-io-syntax
57-
(if descFound
58-
(setf output (format nil "~$::~$::~$::~$" startTime endTime summary desc))
59-
(setf output (format nil "~$::~$::~$" startTime endTime summary)))
60-
(addEvent output)
61-
(format t "Imported Event (start, end, summary): ~a, ~a, ~a~%" startTime endTime summary)))
62-
(format t "ICS file is either missing start time, end time or summary."))))
53+
(setf desc (getSummaryDesc line))))
54+
(if (and (checkForENDEVENT line) inVEVENT)
55+
(progn
56+
(if (and startTimeFound endTimeFound summaryFound)
57+
(progn
58+
(with-standard-io-syntax
59+
(if descFound
60+
(setf output (format nil "~$::~$::~$::~$" startTime endTime summary desc))
61+
(setf output (format nil "~$::~$::~$" startTime endTime summary)))
62+
(addEvent output)
63+
(format t "Imported event (start, end, summary): ~a, ~a, ~a~%" startTime endTime summary))))
64+
(setf inVEVENT nil)
65+
(setf startTimeFound nil)
66+
(setf endTimeFound nil)
67+
(setf summaryFound nil)
68+
(setf descFound nil))))))
69+
(format t "Import finished.~%")))
6370

6471
(defun import/command ()
6572
(clingon:make-command
@@ -78,12 +85,18 @@
7885
(format t "The specified file to import is not a true ICS file, exiting program.~%")
7986
(SB-EXT:QUIT))))
8087

81-
(defun checkForVEVENT (line)
82-
"Checks if the line contains a VEVENT property."
88+
(defun checkForBEGINEVENT (line)
89+
"Checks if the line contains a BEGIN:VEVENT property."
8390
(if (search "BEGIN:VEVENT" line)
8491
t
8592
nil))
8693

94+
(defun checkForENDEVENT (line)
95+
"Checks if the line contains a END:VEVENT property."
96+
(if (search "END:VEVENT" line)
97+
t
98+
nil))
99+
87100
(defun checkForStart (line)
88101
"Checks if the line contains a DTSTART property."
89102
(if (search "DTSTART" line)
@@ -122,4 +135,4 @@
122135

123136
(defun getSummaryDesc (line)
124137
"Gets the summary or description from the line and returns it as a string."
125-
(subseq (subseq line (+ (position #\: line :test #'equal) 1)) 0 (- (length (subseq line (+ (position #\: line :test #'equal) 1))) 1)))
138+
(remove #\\ (subseq (subseq line (+ (position #\: line :test #'equal) 1)) 0 (length (subseq line (+ (position #\: line :test #'equal) 1))))))

0 commit comments

Comments
 (0)