cleaned up the way an item is added to the list. it now creates a (lisp) list and appends the argument to the list, then writes the list to the file

main
m455 2018-04-18 09:42:50 -04:00
parent 0a128707db
commit 64681f005e
1 changed files with 24 additions and 17 deletions

View File

@ -28,16 +28,19 @@
(empty? (rest (file->string-list lst)))) (empty? (rest (file->string-list lst))))
(define (quote-item-in-list lst args) (define (quote-item-in-list lst args)
(cond
[(number? args)
(display (display
(string-append (string-append
"\"" "\""
(list-ref lst (string->number args)) (list-ref lst (string->number args))
"\""))) "\""))]
[(string? args)
(define (quote-item-in-vector args)
(display (display
(string-append (string-append
"\"" args "\""))) "\""
args
"\""))]))
(define (number-list lst) (define (number-list lst)
(map (map
@ -72,23 +75,27 @@
(d-hash-ref messages 'try-init)])) (d-hash-ref messages 'try-init)]))
(define (add-item-to-file args) (define (add-item-to-file args)
(let ([args (string-append args "\n")]) (begin
(d-hash-ref messages 'item-added-prefix)
(quote-item-in-list (file->string-list path) args)
(d-hash-ref messages 'item-added-suffix))
(let ([new-list
(reverse
(append (list args)
(reverse
(file->string-list path))))])
(display-to-file (display-to-file
args (string-join new-list "\n" #:after-last "\n")
path path
#:mode 'text #:mode 'text
#:exists 'append))) #:exists 'replace)))
(define (add-item args) (define (add-item args)
(if (if
(and (and
(check-for-folder) (check-for-folder)
(check-for-file)) (check-for-file))
(begin
(add-item-to-file (vector-ref args 1)) (add-item-to-file (vector-ref args 1))
(d-hash-ref messages 'item-added-prefix)
(quote-item-in-vector (vector-ref args 1))
(d-hash-ref messages 'item-added-suffix))
(begin (begin
(d-hash-ref messages 'file-not-found) (d-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init)))) (d-hash-ref messages 'try-init))))