From f379783d28e73b4613852fca58e0af3f8ea6ab87 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Sat, 29 Dec 2012 02:54:58 +0100 Subject: [PATCH] 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. --- src/Makefile | 8 +++++--- src/common.scm | 30 ++++++++++++++++++++++++++++++ src/convert.scm | 39 +++++++++++++++++++++++++++++++++++---- src/linkwave.scm | 7 ++----- 4 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 src/common.scm diff --git a/src/Makefile b/src/Makefile index c0a9ee8..f64fb7f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,11 +1,13 @@ +objects = paths.o common.o + .PHONY: all all: linkwave convert -linkwave: linkwave.scm paths.o +linkwave: linkwave.scm $(objects) csc $^ -o $@ -convert: convert.scm paths.o +convert: convert.scm $(objects) csc $^ -o $@ -paths.o: paths.scm +$(objects): %.o: %.scm csc -c $^ diff --git a/src/common.scm b/src/common.scm new file mode 100644 index 0000000..7d4fec2 --- /dev/null +++ b/src/common.scm @@ -0,0 +1,30 @@ +;;; linkwave -- Store/retrieve/manage bookmarks +;; Copyright (C) 2012 Tom Willemsen + +;; 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 . + +;;; 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)) diff --git a/src/convert.scm b/src/convert.scm index 99f42b7..45e3101 100644 --- a/src/convert.scm +++ b/src/convert.scm @@ -22,7 +22,8 @@ ;;; Code: -(declare (uses paths)) +(declare (uses paths + common)) (require-extension sqlite3) (require-library srfi-4) @@ -78,6 +79,36 @@ (rename-file (data-file "nlinkwave.db") (data-file "linkwave.db")) (format #t "Database converted.~%"))) -(if (file-exists? "/home/slash/.local/share/linkwave/nlinkwave.db") - (format #t "Converted database already exists.~%") - (convert)) +(define (display-help) + ;; 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)) + (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)) diff --git a/src/linkwave.scm b/src/linkwave.scm index 12a2a9b..a84e3ee 100644 --- a/src/linkwave.scm +++ b/src/linkwave.scm @@ -21,7 +21,8 @@ ;;; Code: -(declare (uses paths)) +(declare (uses paths + common)) (require-extension sqlite3) (require-library posix srfi-4) @@ -76,10 +77,6 @@ (or (string= (substring str 0 7) "http://") (string= (substring str 0 8) "https://")))) -(define (display-version) - ;; Display linkwave's version number. - (format #t "linkwave v~a~%" version)) - (define (display-help) ;; Display linkwave's help message. (format #t (string-append