Add version and help options to convert

Place the `version' and `display-version' items in `common.scm' so
they can be easily used by both executables.
This commit is contained in:
Tom Willemsen 2012-12-29 02:54:58 +01:00
parent 27bdb9bdd1
commit f379783d28
4 changed files with 72 additions and 12 deletions

View file

@ -1,11 +1,13 @@
objects = paths.o common.o
.PHONY: all .PHONY: all
all: linkwave convert all: linkwave convert
linkwave: linkwave.scm paths.o linkwave: linkwave.scm $(objects)
csc $^ -o $@ csc $^ -o $@
convert: convert.scm paths.o convert: convert.scm $(objects)
csc $^ -o $@ csc $^ -o $@
paths.o: paths.scm $(objects): %.o: %.scm
csc -c $^ csc -c $^

30
src/common.scm Normal file
View file

@ -0,0 +1,30 @@
;;; linkwave -- Store/retrieve/manage bookmarks
;; Copyright (C) 2012 Tom Willemsen <tom at ryuslash dot org>
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Common variables and procedures, used by several or all parts of
;; this program.
;;; Code:
(declare (unit common))
(define version "0.1.0")
(define (display-version)
;; Display linkwave's version number.
(format #t "linkwave v~a~%" version))

View file

@ -22,7 +22,8 @@
;;; Code: ;;; Code:
(declare (uses paths)) (declare (uses paths
common))
(require-extension sqlite3) (require-extension sqlite3)
(require-library srfi-4) (require-library srfi-4)
@ -78,6 +79,36 @@
(rename-file (data-file "nlinkwave.db") (data-file "linkwave.db")) (rename-file (data-file "nlinkwave.db") (data-file "linkwave.db"))
(format #t "Database converted.~%"))) (format #t "Database converted.~%")))
(if (file-exists? "/home/slash/.local/share/linkwave/nlinkwave.db") (define (display-help)
(format #t "Converted database already exists.~%") ;; Display linkwave's help message.
(format #t (string-append
"Usage: convert [options]...~%"
"~%"
"Possible options:~%"
"~%"
"--help, -h Display this help and exit~%"
"--version, -v Output version information and exit~%")))
(define (main args)
;; Convert an old database file unless a conversion database already
;; exists.
(if (null? args)
(if (file-exists? (data-file "nlinkwave.db"))
(format #t (string-append "Conversion database already exists. "
"Something may have gone wrong during the last run~%"))
(convert)) (convert))
(do ((arg (car args) (and (not (null? args))
(car args))))
((or (null? arg) (not arg)))
(cond
((or (string= arg "-v") (string= arg "--version"))
(display-version)
(exit 0))
((or (string= arg "-h") (string= arg "--help"))
(display-help)
(exit 0))
(else
(format #t "Unrecognized option: ~a~%" (car args))))
(set! args (cdr args)))))
(main (command-line-arguments))

View file

@ -21,7 +21,8 @@
;;; Code: ;;; Code:
(declare (uses paths)) (declare (uses paths
common))
(require-extension sqlite3) (require-extension sqlite3)
(require-library posix srfi-4) (require-library posix srfi-4)
@ -76,10 +77,6 @@
(or (string= (substring str 0 7) "http://") (or (string= (substring str 0 7) "http://")
(string= (substring str 0 8) "https://")))) (string= (substring str 0 8) "https://"))))
(define (display-version)
;; Display linkwave's version number.
(format #t "linkwave v~a~%" version))
(define (display-help) (define (display-help)
;; Display linkwave's help message. ;; Display linkwave's help message.
(format #t (string-append (format #t (string-append