changed stuff?
parent
bc64065d72
commit
948d1ff3f0
29
utils.rkt
29
utils.rkt
|
@ -21,21 +21,20 @@
|
||||||
(for ([key key-list])
|
(for ([key key-list])
|
||||||
(display (hash-ref messages:messages key))))
|
(display (hash-ref messages:messages key))))
|
||||||
|
|
||||||
(define (list->ascending-numbers lst)
|
(define (list->ascending-numbers-list lst)
|
||||||
(list:range (length lst)))
|
(list:range (length lst)))
|
||||||
|
|
||||||
(define (list->dotted-ascending-numbers lst)
|
(define (list->dotted-ascending-numbers-list lst)
|
||||||
(map (lambda (x) (string-append x ". "))
|
(map (lambda (x) (string-append x ". "))
|
||||||
(map number->string (list->ascending-numbers lst))))
|
(map number->string (list->ascending-numbers-list lst))))
|
||||||
|
|
||||||
(define (list->numbered-list lst)
|
(define (list->numbered-list lst)
|
||||||
(map (lambda (x y) (string-append x y))
|
(map (lambda (x y) (string-append x y))
|
||||||
(list->dotted-ascending-numbers lst)
|
(list->dotted-ascending-numbers-list lst)
|
||||||
lst))
|
lst))
|
||||||
|
|
||||||
(define (file->vertically-numbered-list a-file)
|
(define (file->vertically-numbered-list a-file)
|
||||||
(string:string-join
|
(string:string-join (list->numbered-list (file:file->lines a-file))
|
||||||
(list->numbered-list (file:file->lines a-file))
|
|
||||||
"\n"
|
"\n"
|
||||||
#:after-last "\n"))
|
#:after-last "\n"))
|
||||||
|
|
||||||
|
@ -50,19 +49,20 @@
|
||||||
|
|
||||||
(define (check-list-conditions)
|
(define (check-list-conditions)
|
||||||
(cond
|
(cond
|
||||||
;; If exists and not empty
|
;; If list exists and not empty
|
||||||
[(and (file-exists? config:list-file)
|
[(and (file-exists? config:list-file)
|
||||||
(not (null? (file:file->lines config:list-file))))
|
(not (null? (file:file->lines config:list-file))))
|
||||||
(display (file->vertically-numbered-list config:list-file))]
|
(display (file->vertically-numbered-list config:list-file))]
|
||||||
|
|
||||||
;; If exists and empty
|
;; If list exists and empty
|
||||||
[(and (file-exists? config:list-file)
|
[(and (file-exists? config:list-file)
|
||||||
(null? (file:file->lines config:list-file)))
|
(null? (file:file->lines config:list-file)))
|
||||||
(display-messages '(empty-list))]
|
(display-messages '(empty-list))]
|
||||||
|
|
||||||
;; If not exist
|
;; If not exist
|
||||||
[(and (not (file-exists? config:list-file)))
|
[(and (not (file-exists? config:list-file)))
|
||||||
(display-messages '(file-not-found try-init))]
|
(display-messages '(file-not-found
|
||||||
|
try-init))]
|
||||||
|
|
||||||
[else (display-messages '(show-usage))]))
|
[else (display-messages '(show-usage))]))
|
||||||
|
|
||||||
|
@ -82,15 +82,13 @@
|
||||||
(if (and (file-exists? config:list-file))
|
(if (and (file-exists? config:list-file))
|
||||||
(add-item-to-list args)
|
(add-item-to-list args)
|
||||||
;; Otherwise
|
;; Otherwise
|
||||||
(display-messages '(file-not-found try-init))))
|
(display-messages '(file-not-found
|
||||||
|
try-init))))
|
||||||
|
|
||||||
(define (remove-item-from-list user-args)
|
(define (remove-item-from-list user-args)
|
||||||
(let* ([item-to-remove (list-ref (file:file->lines config:list-file) user-args)]
|
(let* ([item-to-remove (list-ref (file:file->lines config:list-file) user-args)]
|
||||||
[new-list (remove item-to-remove (file:file->lines config:list-file))])
|
[new-list (remove item-to-remove (file:file->lines config:list-file))])
|
||||||
(file:display-lines-to-file new-list
|
(file:display-lines-to-file new-list config:list-file #:mode 'text #:exists 'truncate)
|
||||||
config:list-file
|
|
||||||
#:mode 'text
|
|
||||||
#:exists 'truncate)
|
|
||||||
(display-item-removed item-to-remove)))
|
(display-item-removed item-to-remove)))
|
||||||
|
|
||||||
(define (check-remove-conditions args)
|
(define (check-remove-conditions args)
|
||||||
|
@ -116,4 +114,5 @@
|
||||||
;; If directory and file don't exist
|
;; If directory and file don't exist
|
||||||
[(and (not (directory-exists? config:program-directory))
|
[(and (not (directory-exists? config:program-directory))
|
||||||
(not (file-exists? config:list-file)))
|
(not (file-exists? config:list-file)))
|
||||||
(display-messages '(file-not-found try-init))]))
|
(display-messages '(file-not-found
|
||||||
|
try-init))]))
|
||||||
|
|
Loading…
Reference in New Issue