From b46793938598358a9ab5249bd97e8999d5ac67e6 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Sat, 29 Dec 2012 16:54:16 +0100 Subject: Rename linkwave to markam --- Makefile | 9 ++-- README.org | 10 +---- conkeror/linkwave.js | 77 --------------------------------- conkeror/markam.js | 77 +++++++++++++++++++++++++++++++++ doc/Makefile | 4 +- doc/linkwave.texi | 106 ---------------------------------------------- doc/markam.texi | 106 ++++++++++++++++++++++++++++++++++++++++++++++ src/.gitignore | 2 +- src/Makefile | 4 +- src/common.scm | 6 +-- src/convert.scm | 20 ++++----- src/linkwave.scm | 117 --------------------------------------------------- src/markam.scm | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/paths.scm | 23 +++++----- 14 files changed, 336 insertions(+), 342 deletions(-) delete mode 100644 conkeror/linkwave.js create mode 100644 conkeror/markam.js delete mode 100644 doc/linkwave.texi create mode 100644 doc/markam.texi delete mode 100644 src/linkwave.scm create mode 100644 src/markam.scm diff --git a/Makefile b/Makefile index 6bcd90a..e796ed8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ -.PHONY: all +dirs = src doc -all: - $(MAKE) -C src/ +.PHONY: all $(dirs) + +all: $(dirs) +$(dirs): + $(MAKE) -C $@ diff --git a/README.org b/README.org index 6b71e45..24bf6c7 100644 --- a/README.org +++ b/README.org @@ -1,9 +1,3 @@ -* nlinkwave +* Markam - I'm working on replacing [[http://code.ryuslash.org/cgit.cgi/linkwave/][linkwave]] with this project soon, with the - hope of making development on/for Windows easier and becaus scheme - is fun! - - *Note:* Once I determine that ~nlinkwave~ is capable of everything - linkwave is I will change the name of this repository, keep this in - mind when you are having trouble pulling changes in the future. + Collects bookmarks. diff --git a/conkeror/linkwave.js b/conkeror/linkwave.js deleted file mode 100644 index 75e3735..0000000 --- a/conkeror/linkwave.js +++ /dev/null @@ -1,77 +0,0 @@ -/* 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: - -// A wrapper script that should allow conkeror to interface with -// linkwave. Does not yet allow searching through collected -// bookmarks, only adding new ones. - -/// Code: - -define_variable("linkwave_program", "linkwave", - "The location of the linkwave executable."); - -function linkwave_add_url(I, url, title) -{ // Add URL to linkwave, ask for a title (provide TITLE as a - // default), description and any number of tags. - let url_string = load_spec_uri_string(load_spec(url)); - let title = yield I.minibuffer.read($prompt="name (required): ", - $initial_value=title); - let description = yield I.minibuffer.read( - $prompt="extended description: " - ); - let tags = yield I.minibuffer.read( - $prompt="tags (comma delimited): " - ); - let command = linkwave_program + ' "' + url_string + '" "' + title - + '" "' + description + '" \'' - + tags.split(',').map(function (str) - { return str.trim(); }).join("' '") - + "'"; - yield shell_command(command); -} - -function linkwave_add(I) { - check_buffer(I.buffer, content_buffer); - let result = yield linkwave_add_url(I, I.buffer.top_frame, - I.buffer.title); - - if (!result) - I.window.minibuffer.message('Added to linkwave'); - else - I.window.minibuffer.message('Couldn\'t add to linkwave'); -} -interactive("linkwave-add", - "Bookmark the current page in linkwave", - linkwave_add); - -function linkwave_add_link(I) { - check_buffer(I.buffer, content_buffer); - bo = yield read_browser_object(I); - let result = yield linkwave_add_url(I, encodeURIComponent(bo), - bo.textContent); - - if (!result) - I.window.minibuffer.message('Added to linkwave'); - else - I.window.minibuffer.message('Couldn\'t add to linkwave'); -} -interactive("linkwave-add-link", - "Select and bookmark a link in linkwave", - linkwave_add_link); - -provide("linkwave"); diff --git a/conkeror/markam.js b/conkeror/markam.js new file mode 100644 index 0000000..2151b17 --- /dev/null +++ b/conkeror/markam.js @@ -0,0 +1,77 @@ +/* markam -- 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: + +// A wrapper script that should allow conkeror to interface with +// markam. Does not yet allow searching through collected bookmarks, +// only adding new ones. + +/// Code: + +define_variable("markam_program", "markam", + "The location of the markam executable."); + +function markam_add_url(I, url, title) +{ // Add URL to markam, ask for a title (provide TITLE as a + // default), description and any number of tags. + let url_string = load_spec_uri_string(load_spec(url)); + let title = yield I.minibuffer.read($prompt="name (required): ", + $initial_value=title); + let description = yield I.minibuffer.read( + $prompt="extended description: " + ); + let tags = yield I.minibuffer.read( + $prompt="tags (comma delimited): " + ); + let command = markam_program + ' "' + url_string + '" "' + title + + '" "' + description + '" \'' + + tags.split(',').map(function (str) + { return str.trim(); }).join("' '") + + "'"; + yield shell_command(command); +} + +function markam_add(I) { + check_buffer(I.buffer, content_buffer); + let result = yield markam_add_url(I, I.buffer.top_frame, + I.buffer.title); + + if (!result) + I.window.minibuffer.message('Added to markam'); + else + I.window.minibuffer.message('Couldn\'t add to markam'); +} +interactive("markam-add", + "Bookmark the current page in markam", + markam_add); + +function markam_add_link(I) { + check_buffer(I.buffer, content_buffer); + bo = yield read_browser_object(I); + let result = yield markam_add_url(I, encodeURIComponent(bo), + bo.textContent); + + if (!result) + I.window.minibuffer.message('Added to markam'); + else + I.window.minibuffer.message('Couldn\'t add to markam'); +} +interactive("markam-add-link", + "Select and bookmark a link in markam", + markam_add_link); + +provide("markam"); diff --git a/doc/Makefile b/doc/Makefile index 07079e8..29d7269 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -1,4 +1,4 @@ .PHONY: all -all: linkwave.info -linkwave.info: linkwave.texi +all: markam.info +markam.info: markam.texi diff --git a/doc/linkwave.texi b/doc/linkwave.texi deleted file mode 100644 index 348dbd5..0000000 --- a/doc/linkwave.texi +++ /dev/null @@ -1,106 +0,0 @@ -\input texinfo @c -*-texinfo-*- -@c %**start of header -@setfilename linkwave.info -@settitle linkwave User Manual -@c %**end of header -@copying -The user manual for linkwave. - -Copyright @copyright{} 2012 Tom Willemsen - -@quotation -Permission is granted to copy, distribute and/or modify this document -under the terms of the GNU Free Documentation License, Version 1.3 -or any later version published by the Free Software Foundation; -with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. -A copy of the license is included in the section entitled ``GNU -Free Documentation License''. - -A copy of the license is also available from the Free Software -Foundation Web site at @url{http://www.gnu.org/licenses/fdl.html}. - -@end quotation - -The document was typeset with -@uref{http://www.texinfo.org/, GNU Texinfo}. - -@end copying - -@titlepage -@title linkwave User Manual -@subtitle The user manual for linkwave -@author Tom Willemsen -@page -@vskip 0pt plus 1filll -@insertcopying -@end titlepage - -@c Output the table of the contents at the beginning. -@contents - -@ifnottex -@node Top, Usage, (dir), (dir) -@top linkwave User Manual - -@insertcopying -@end ifnottex - -@c Generate the nodes for this menu with `C-c C-u C-m'. -@menu -* Usage:: How to use linkwave -* Copying This Manual:: -* Index:: -@end menu - -@c Update all node entries with `C-c C-u C-n'. -@c Insert new nodes with `C-c C-c n'. -@node Usage, Copying This Manual, Top, Top -@chapter How to use - -For the moment linkwave is a simple program, it has 2 functions. In -order to view a list of all your bookmarks you can use: - -@example -linkwave -@end example - -This will show the list of all stored bookmarks, showing the URL, name -and description. This list is unsorted and unpaged. - -The other function is to add a new bookmark, which can be done with: - -@example -linkwave http://example.org Example \ - "Some description about Example" \ - example some more tags -@end example - -This will store the bookmark with the URL of ``http://example.org'', -name ``Example'', description ``Some description about Example'' and -the tags ``example'', ``some'', ``more'' and ``tags''. Any arguments -following the description will be considered tags. - -For the moment linkwave is rather stupid, assuming that all URLs start -with @code{http://} or @code{https://}, so other bookmarks can't be -added (yet). - -@node Copying This Manual, Index, Usage, Top -@appendix Copying This Manual - -@menu -* GNU Free Documentation License:: License for copying this manual. -@end menu - -@c Get fdl.texi from http://www.gnu.org/licenses/fdl.html -@node GNU Free Documentation License, , Copying This Manual, Copying This Manual -@appendixsec -@include fdl.texi - -@node Index, , Copying This Manual, Top -@unnumbered Index - -@printindex cp - -@bye - -@c linkwave.texi ends here diff --git a/doc/markam.texi b/doc/markam.texi new file mode 100644 index 0000000..3093f8d --- /dev/null +++ b/doc/markam.texi @@ -0,0 +1,106 @@ +\input texinfo @c -*-texinfo-*- +@c %**start of header +@setfilename markam.info +@settitle markam User Manual +@c %**end of header +@copying +The user manual for markam. + +Copyright @copyright{} 2012 Tom Willemsen + +@quotation +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 +or any later version published by the Free Software Foundation; +with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. +A copy of the license is included in the section entitled ``GNU +Free Documentation License''. + +A copy of the license is also available from the Free Software +Foundation Web site at @url{http://www.gnu.org/licenses/fdl.html}. + +@end quotation + +The document was typeset with +@uref{http://www.texinfo.org/, GNU Texinfo}. + +@end copying + +@titlepage +@title markam User Manual +@subtitle The user manual for markam +@author Tom Willemsen +@page +@vskip 0pt plus 1filll +@insertcopying +@end titlepage + +@c Output the table of the contents at the beginning. +@contents + +@ifnottex +@node Top, Usage, (dir), (dir) +@top markam User Manual + +@insertcopying +@end ifnottex + +@c Generate the nodes for this menu with `C-c C-u C-m'. +@menu +* Usage:: How to use markam +* Copying This Manual:: +* Index:: +@end menu + +@c Update all node entries with `C-c C-u C-n'. +@c Insert new nodes with `C-c C-c n'. +@node Usage, Copying This Manual, Top, Top +@chapter How to use + +For the moment markam is a simple program, it has 2 functions. In +order to view a list of all your bookmarks you can use: + +@example +markam +@end example + +This will show the list of all stored bookmarks, showing the URL, name +and description. This list is unsorted and unpaged. + +The other function is to add a new bookmark, which can be done with: + +@example +markam http://example.org Example \ + "Some description about Example" \ + example some more tags +@end example + +This will store the bookmark with the URL of ``http://example.org'', +name ``Example'', description ``Some description about Example'' and +the tags ``example'', ``some'', ``more'' and ``tags''. Any arguments +following the description will be considered tags. + +For the moment markam is rather stupid, assuming that all URLs start +with @code{http://} or @code{https://}, so other bookmarks can't be +added (yet). + +@node Copying This Manual, Index, Usage, Top +@appendix Copying This Manual + +@menu +* GNU Free Documentation License:: License for copying this manual. +@end menu + +@c Get fdl.texi from http://www.gnu.org/licenses/fdl.html +@node GNU Free Documentation License, , Copying This Manual, Copying This Manual +@appendixsec +@include fdl.texi + +@node Index, , Copying This Manual, Top +@unnumbered Index + +@printindex cp + +@bye + +@c markam.texi ends here diff --git a/src/.gitignore b/src/.gitignore index 36833f1..83dc013 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,3 +1,3 @@ convert -linkwave +markam *.o diff --git a/src/Makefile b/src/Makefile index f64fb7f..95baea2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,8 +2,8 @@ objects = paths.o common.o .PHONY: all -all: linkwave convert -linkwave: linkwave.scm $(objects) +all: markam convert +markam: markam.scm $(objects) csc $^ -o $@ convert: convert.scm $(objects) diff --git a/src/common.scm b/src/common.scm index 7d4fec2..20baece 100644 --- a/src/common.scm +++ b/src/common.scm @@ -1,4 +1,4 @@ -;;; linkwave -- Store/retrieve/manage bookmarks +;;; markam -- Store/retrieve/manage bookmarks ;; Copyright (C) 2012 Tom Willemsen ;; This program is free software: you can redistribute it and/or modify @@ -26,5 +26,5 @@ (define version "0.1.0") (define (display-version) - ;; Display linkwave's version number. - (format #t "linkwave v~a~%" version)) + ;; Display markam's version number. + (format #t "markam version ~a~%" version)) diff --git a/src/convert.scm b/src/convert.scm index 45e3101..199a2a5 100644 --- a/src/convert.scm +++ b/src/convert.scm @@ -1,4 +1,4 @@ -;;; linkwave -- Store/retrieve/manage bookmarks +;;; markam -- Store/retrieve/manage bookmarks ;; Copyright (C) 2012 Tom Willemsen ;; This program is free software: you can redistribute it and/or modify @@ -17,7 +17,7 @@ ;;; Commentary: ;; Convert any old database file to one usable with this version of -;; linkwave. If you're just starting to use linkwave there should be +;; markam. If you're just starting to use markam there should be ;; no need to use this. ;;; Code: @@ -31,7 +31,7 @@ (define (blob->seconds blob) ;; Convert BLOB to an integer representing the seconds since ;; 01-01-1970 (standard unix timstamp). This has to be done because - ;; in the previous version of linkwave I stored the timestamp as a + ;; in the previous version of markam I stored the timestamp as a ;; blob and CHICKEN doesn't seem to like blobs much. (if (u32vector? blob) (u32vector-ref (blob->u32vector blob) 0) @@ -53,8 +53,8 @@ (define (convert) ;; Convert an old database into a new one and then replace the old ;; with the new. - (let ((old-db (open-database (data-file "linkwave.db"))) - (new-db (open-database (data-file "nlinkwave.db")))) + (let ((old-db (open-database (data-file "linkwave.db" "linkwave"))) + (new-db (open-database (data-file "markam.db")))) (execute new-db "CREATE TABLE bookmark (url VARCHAR(255) UNIQUE, date INTEGER, name VARCHAR(255), description TEXT)") (execute new-db "CREATE TABLE tag (name VARCHAR(255) UNIQUE)") (execute new-db "CREATE TABLE bookmark_tag (bookmark_id INTEGER REFERENCES bookmark(rowid), tag_id INTEGER REFERENCES tag(rowid), PRIMARY KEY (bookmark_id, tag_id))") @@ -75,12 +75,10 @@ (first-result new-db "SELECT rowid FROM tag WHERE name = ?" tag))) "SELECT url, name FROM bookmark_tag JOIN tag ON (tag_id = tag.rowid)") - (rename-file (data-file "linkwave.db") (data-file "old-linkwave.db")) - (rename-file (data-file "nlinkwave.db") (data-file "linkwave.db")) (format #t "Database converted.~%"))) (define (display-help) - ;; Display linkwave's help message. + ;; Display markam's help message. (format #t (string-append "Usage: convert [options]...~%" "~%" @@ -93,9 +91,9 @@ ;; 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~%")) + (if (file-exists? (data-file "markam.db")) + (format #t (string-append "Converted database already exists, or something may have gone " + "wrong during the last run~%")) (convert)) (do ((arg (car args) (and (not (null? args)) (car args)))) diff --git a/src/linkwave.scm b/src/linkwave.scm deleted file mode 100644 index a84e3ee..0000000 --- a/src/linkwave.scm +++ /dev/null @@ -1,117 +0,0 @@ -;;; 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: - -;; The main program. For documentation you should consult the -;; README.org and/or any Texinfo documentation provided. - -;;; Code: - -(declare (uses paths - common)) - -(require-extension sqlite3) -(require-library posix srfi-4) - -(define version "0.1.0") - -(: string-no-null (string -> string)) -(define (string-no-null str) - ;; If STR contains a \0 byte at the end, remove it, otherwise return - ;; STR unchanged. - (if (and (> (string-length str) 0) - (char=? (string-ref str (- (string-length str) 1)) #\nul)) - (substring str 0 (- (string-length str) 1)) - str)) - -(: print-row (string fixnum string string -> void)) -(define (print-row url seconds name description) - ;; Print URL, SECONDS, NAME and DESCRIPTION to the standard output - ;; stream. - (format #t "~a~% ~a~% ~a~% ~a~%~%" (string-no-null name) (string-no-null description) - (string-no-null url) (seconds->string seconds))) - -(define (add-tag db name) - ;; Add NAME to the `tag' table in DB. - (execute db "INSERT INTO tag VALUES (?)" name) - (last-insert-rowid db)) - -(define (add-bookmark db url name description tags) - ;; Add a bookmark to the `bookmark' table in DB. URL is the url of - ;; the bookmark, NAME the title, DESCRIPTION a (possibly longer) - ;; description of the bookmark and TAGS is a list of tags to assign - ;; to it. Each tag will be created if necessary. - (execute db "INSERT INTO bookmark VALUES (?, STRFTIME('%s'), ?, ?)" - url name description) - (let ((bookmark-id (last-insert-rowid db))) - (for-each (lambda (tag) - (let ((tag-id '())) - (condition-case - (set! tag-id (first-result db "SELECT rowid FROM tag WHERE name = ?" tag)) - (exn (exn sqlite3) - (if (eq? (get-condition-property exn 'sqlite3 'status) 'done) - (set! tag-id (add-tag db tag)) - (signal exn)))) - (execute db "INSERT INTO bookmark_tag VALUES (?, ?)" - bookmark-id tag-id))) - tags))) - -(define (url-string? str) - ;; Is STR a URL? Very naïve, assumes all URLs begin with either - ;; `http://' or `https://', should be improved. - (and (> (string-length str) 7) - (or (string= (substring str 0 7) "http://") - (string= (substring str 0 8) "https://")))) - -(define (display-help) - ;; Display linkwave's help message. - (format #t (string-append - "Usage: linkwave [options]...~%" - " linkwave [...]~%" - "~%" - "Possible options:~%" - "~%" - "--help, -h Display this help and exit~%" - "--version, -v Output version information and exit~%"))) - -(define (main args) - ;; Open a database connection, do what the user asked and close it - ;; again. - (let ((db (open-database (data-file "linkwave.db")))) - (if (null? args) - (for-each-row print-row db "select * from bookmark") - (if (url-string? (car args)) - (with-transaction - db (lambda () (add-bookmark db (car args) (cadr args) (caddr args) (cdddr args)) #t)) - ;; If the first argument is not a URL, loop through all - ;; arguments and proceed accordingly. - (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))))) - (finalize! db #t))) - -(main (command-line-arguments)) diff --git a/src/markam.scm b/src/markam.scm new file mode 100644 index 0000000..38bfc42 --- /dev/null +++ b/src/markam.scm @@ -0,0 +1,117 @@ +;;; markam -- 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: + +;; The main program. For documentation you should consult the +;; README.org and/or any Texinfo documentation provided. + +;;; Code: + +(declare (uses paths + common)) + +(require-extension sqlite3) +(require-library posix srfi-4) + +(define version "0.1.0") + +(: string-no-null (string -> string)) +(define (string-no-null str) + ;; If STR contains a \0 byte at the end, remove it, otherwise return + ;; STR unchanged. + (if (and (> (string-length str) 0) + (char=? (string-ref str (- (string-length str) 1)) #\nul)) + (substring str 0 (- (string-length str) 1)) + str)) + +(: print-row (string fixnum string string -> void)) +(define (print-row url seconds name description) + ;; Print URL, SECONDS, NAME and DESCRIPTION to the standard output + ;; stream. + (format #t "~a~% ~a~% ~a~% ~a~%~%" (string-no-null name) (string-no-null description) + (string-no-null url) (seconds->string seconds))) + +(define (add-tag db name) + ;; Add NAME to the `tag' table in DB. + (execute db "INSERT INTO tag VALUES (?)" name) + (last-insert-rowid db)) + +(define (add-bookmark db url name description tags) + ;; Add a bookmark to the `bookmark' table in DB. URL is the url of + ;; the bookmark, NAME the title, DESCRIPTION a (possibly longer) + ;; description of the bookmark and TAGS is a list of tags to assign + ;; to it. Each tag will be created if necessary. + (execute db "INSERT INTO bookmark VALUES (?, STRFTIME('%s'), ?, ?)" + url name description) + (let ((bookmark-id (last-insert-rowid db))) + (for-each (lambda (tag) + (let ((tag-id '())) + (condition-case + (set! tag-id (first-result db "SELECT rowid FROM tag WHERE name = ?" tag)) + (exn (exn sqlite3) + (if (eq? (get-condition-property exn 'sqlite3 'status) 'done) + (set! tag-id (add-tag db tag)) + (signal exn)))) + (execute db "INSERT INTO bookmark_tag VALUES (?, ?)" + bookmark-id tag-id))) + tags))) + +(define (url-string? str) + ;; Is STR a URL? Very naïve, assumes all URLs begin with either + ;; `http://' or `https://', should be improved. + (and (> (string-length str) 7) + (or (string= (substring str 0 7) "http://") + (string= (substring str 0 8) "https://")))) + +(define (display-help) + ;; Display markam's help message. + (format #t (string-append + "Usage: markam [options]...~%" + " markam [...]~%" + "~%" + "Possible options:~%" + "~%" + "--help, -h Display this help and exit~%" + "--version, -v Output version information and exit~%"))) + +(define (main args) + ;; Open a database connection, do what the user asked and close it + ;; again. + (let ((db (open-database (data-file "markam.db")))) + (if (null? args) + (for-each-row print-row db "select * from bookmark") + (if (url-string? (car args)) + (with-transaction + db (lambda () (add-bookmark db (car args) (cadr args) (caddr args) (cdddr args)) #t)) + ;; If the first argument is not a URL, loop through all + ;; arguments and proceed accordingly. + (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))))) + (finalize! db #t))) + +(main (command-line-arguments)) diff --git a/src/paths.scm b/src/paths.scm index 5f4f2d2..cfd8838 100644 --- a/src/paths.scm +++ b/src/paths.scm @@ -1,4 +1,4 @@ -;;; linkwave -- Store/retrieve/manage bookmarks +;;; markam -- Store/retrieve/manage bookmarks ;; Copyright (C) 2012 Tom Willemsen ;; This program is free software: you can redistribute it and/or modify @@ -22,25 +22,24 @@ (declare (unit paths)) -(define (stored-file xdg-env file) - ;; Get FILE either from `XDG-ENV/linkwave/' or from - ;; `$HOME/.linkwave/'. Prefer any existing file over any other, but - ;; prefer files using XDG-ENV over `$HOME'. - (let ((xdg (get-environment-variable xdg-env)) - (stored-file (string-append (get-environment-variable "HOME") "/.linkwave/" file))) +(define (stored-file xdg-env file #!optional dir) + ;; Get FILE either from `XDG-ENV/markam/' or from `$HOME/.markam/'. + ;; Prefer any existing file over any other, but prefer files using + ;; XDG-ENV over `$HOME'. + (let* ((xdg (get-environment-variable xdg-env)) + (dir (or dir "markam")) + (stored-file (string-append (get-environment-variable "HOME") "/." dir "/" file))) (unless (or (file-exists? stored-file) (not xdg)) - (set! stored-file (string-append xdg "/linkwave/" file))) + (set! stored-file (string-append xdg "/" dir "/" file))) stored-file)) -(: config-file (string -> string)) (define (config-file file) ;; Use `stored-file' to get configuration file FILE. Configuration ;; files are stored under `$XDG_CONFIG_HOME' if the XDG standard is ;; used. (stored-file "XDG_CONFIG_HOME" file)) -(: data-file (string -> string)) -(define (data-file file) +(define (data-file file #!optional dir) ;; Use `stored-file' to get data file FILE. Data files are stored ;; under `$XDG_DATA_HOME' if the XDG standard is used. - (stored-file "XDG_DATA_HOME" file)) + (stored-file "XDG_DATA_HOME" file dir)) -- cgit v1.3-2-g0d8e