diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-23 21:57:30 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-23 22:01:31 +0300 |
commit | 11afe84b218bda29db088d8dd4e16e79c03099ef (patch) | |
tree | cdf9f6992482c6cec34ab771d497c4b04dce5a84 | |
parent | e503a7f56ca38efc1886e04be0dbeb380db3934a (diff) | |
download | idest-11afe84b218bda29db088d8dd4e16e79c03099ef.tar.gz idest-11afe84b218bda29db088d8dd4e16e79c03099ef.tar.bz2 |
Implement new formats: framelist & lyrics.
* scheme/format.scm: Set actual format script name as argv[0]
* src/cmdline.opt <format>: Use `stop' to stop
argument processing.
* src/getopt.m4 (GETOPT): New local variable `stop'.
* scheme/idest/format/framelist.scm: New file.
* scheme/idest/format/lyrics.scm: New file.
-rw-r--r-- | scheme/format.scm | 2 | ||||
-rw-r--r-- | scheme/idest/format/framelist.scm | 97 | ||||
-rw-r--r-- | scheme/idest/format/lyrics.scm | 101 | ||||
-rw-r--r-- | src/cmdline.opt | 3 | ||||
-rw-r--r-- | src/getopt.m4 | 6 | ||||
-rw-r--r-- | src/guile.c | 2 | ||||
-rw-r--r-- | src/idop.c | 2 |
7 files changed, 206 insertions, 7 deletions
diff --git a/scheme/format.scm b/scheme/format.scm index 61a98cc..9ce8026 100644 --- a/scheme/format.scm +++ b/scheme/format.scm | |||
@@ -26,7 +26,7 @@ | |||
26 | (set! %load-hook saved-load-hook))) | 26 | (set! %load-hook saved-load-hook))) |
27 | 27 | ||
28 | (let ((mod-name (list-ref cmd 1))) | 28 | (let ((mod-name (list-ref cmd 1))) |
29 | (set-program-arguments (cons (car cmd) (list-tail cmd 2))) | 29 | (set-program-arguments (list-tail cmd 1)) |
30 | (set! idest-main | 30 | (set! idest-main |
31 | (module-ref | 31 | (module-ref |
32 | (resolve-module (list 'idest 'format (string->symbol mod-name))) | 32 | (resolve-module (list 'idest 'format (string->symbol mod-name))) |
diff --git a/scheme/idest/format/framelist.scm b/scheme/idest/format/framelist.scm new file mode 100644 index 0000000..2445a59 --- /dev/null +++ b/scheme/idest/format/framelist.scm | |||
@@ -0,0 +1,97 @@ | |||
1 | ;; This file is part of Idest | ||
2 | ;; Copyright (C) 2011 Sergey Poznyakoff | ||
3 | ;; | ||
4 | ;; Idest is free software; you can redistribute it and/or modify | ||
5 | ;; it under the terms of the GNU General Public License as published by | ||
6 | ;; the Free Software Foundation; either version 3, or (at your option) | ||
7 | ;; any later version. | ||
8 | ;; | ||
9 | ;; Idest is distributed in the hope that it will be useful, | ||
10 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | ;; GNU General Public License for more details. | ||
13 | ;; | ||
14 | ;; You should have received a copy of the GNU General Public License | ||
15 | ;; along with Idest. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | (define-module (idest format framelist)) | ||
18 | |||
19 | (use-modules (ice-9 getopt-long)) | ||
20 | |||
21 | (define-public idest-main #f) | ||
22 | |||
23 | (let* ((cmd (command-line)) | ||
24 | (progname (car cmd)) | ||
25 | (delim #\newline) | ||
26 | (addinfo #f) | ||
27 | (frame-list #f) ; FIXME: Need a way to access filter_list from idest | ||
28 | (grammar `((full (single-char #\F)) | ||
29 | (qualified (single-char #\Q)) | ||
30 | (frames (single-char #\f) (value #t)) | ||
31 | (single-line (single-char #\l)) | ||
32 | (help (single-char #\h))))) | ||
33 | |||
34 | (catch 'misc-error | ||
35 | (lambda () | ||
36 | (for-each | ||
37 | (lambda (x) | ||
38 | (case (car x) | ||
39 | ((full) | ||
40 | (set! addinfo | ||
41 | (lambda (attr-list) | ||
42 | (for-each | ||
43 | (lambda (attr) | ||
44 | (if (not (eq? (car attr) 'text)) | ||
45 | (format #t " ~A=\"~A\"" | ||
46 | (car attr) (cdr attr)))) | ||
47 | attr-list)))) | ||
48 | ((qualified) | ||
49 | (set! addinfo | ||
50 | (lambda (attr-list) | ||
51 | (for-each | ||
52 | (lambda (attr) | ||
53 | (if (not (or (eq? (car attr) 'text) | ||
54 | (eq? (car attr) 'descr))) | ||
55 | (format #t ":~A" (cdr attr)))) | ||
56 | attr-list)))) | ||
57 | ((single-line) | ||
58 | (set! delim #\,)) | ||
59 | ((frames) | ||
60 | (set! frame-list (string-split (cdr x) #\,))) | ||
61 | ((help) | ||
62 | (format #t "usage: idest --format=~A [OPTIONS] FILE...\n" | ||
63 | progname) | ||
64 | (format #t "displays the frame list\n") | ||
65 | (format #t "OPTIONS are:\n") | ||
66 | (format #t " -F, --full display all qualifiers\n") | ||
67 | (format #t " -f, --frames FLIST display only frames from FLIST\n") | ||
68 | (format #t " -Q, --qualified display frames in qualified form\n") | ||
69 | (format #t " -l, --single-line fit output on single-line\n") | ||
70 | (format #t " -h, --help show this help summary\n") | ||
71 | (exit 0)) | ||
72 | (else | ||
73 | (set-program-arguments (cons progname (cdr x)))))) | ||
74 | (getopt-long cmd grammar))) | ||
75 | (lambda (key . args) | ||
76 | (with-output-to-port | ||
77 | (current-error-port) | ||
78 | (lambda () | ||
79 | (format #t "~A: " progname) | ||
80 | (apply format #t (list-ref args 1) (list-ref args 2)) | ||
81 | (newline) | ||
82 | (exit 1))))) | ||
83 | |||
84 | (set! idest-main | ||
85 | (lambda (name frames) | ||
86 | (do ((tail frames (cdr tail))) | ||
87 | ((null? tail)) | ||
88 | (let ((elt (car tail))) | ||
89 | (cond | ||
90 | ((or (not frame-list) (member (car elt) frame-list)) | ||
91 | (display (car elt)) | ||
92 | (if addinfo (addinfo (cdr elt))) | ||
93 | (if (null? (cdr tail)) | ||
94 | (newline) | ||
95 | (display delim))))))))) | ||
96 | |||
97 | |||
diff --git a/scheme/idest/format/lyrics.scm b/scheme/idest/format/lyrics.scm new file mode 100644 index 0000000..7fb5b1c --- /dev/null +++ b/scheme/idest/format/lyrics.scm | |||
@@ -0,0 +1,101 @@ | |||
1 | ;; This file is part of Idest | ||
2 | ;; Copyright (C) 2011 Sergey Poznyakoff | ||
3 | ;; | ||
4 | ;; Idest is free software; you can redistribute it and/or modify | ||
5 | ;; it under the terms of the GNU General Public License as published by | ||
6 | ;; the Free Software Foundation; either version 3, or (at your option) | ||
7 | ;; any later version. | ||
8 | ;; | ||
9 | ;; Idest is distributed in the hope that it will be useful, | ||
10 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | ;; GNU General Public License for more details. | ||
13 | ;; | ||
14 | ;; You should have received a copy of the GNU General Public License | ||
15 | ;; along with Idest. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | (define-module (idest format lyrics)) | ||
18 | |||
19 | (use-modules (ice-9 getopt-long) | ||
20 | (ice-9 popen)) | ||
21 | |||
22 | (define-public idest-main #f) | ||
23 | |||
24 | (let* ((cmd (command-line)) | ||
25 | (progname (car cmd)) | ||
26 | (lang #f) | ||
27 | (condesc #f) | ||
28 | (grammar `((lang (single-char #\l) (value #t)) | ||
29 | (content (single-char #\c) (value #t)) | ||
30 | (help (single-char #\h))))) | ||
31 | (catch 'misc-error | ||
32 | (lambda () | ||
33 | (for-each | ||
34 | (lambda (x) | ||
35 | (case (car x) | ||
36 | ((file) | ||
37 | (set! file (cdr x))) | ||
38 | ((lang) | ||
39 | (set! lang (cdr x))) | ||
40 | ((content) | ||
41 | (set! condesc (cdr x))) | ||
42 | ((help) | ||
43 | (format #t "usage: idest --format=~A [OPTIONS] FILE...\n" | ||
44 | progname) | ||
45 | (format #t "displays the USLT (unsynchronised lyric text) frame\n") | ||
46 | (format #t "OPTIONS are:\n") | ||
47 | (format #t " -l, --lang NAME set language in which the lyrics is writen (default: eng)\n") | ||
48 | (format #t " -c, --content TEXT set content description\n") | ||
49 | (exit 0)) | ||
50 | (else | ||
51 | (set-program-arguments (cons progname (cdr x)))))) | ||
52 | (getopt-long cmd grammar))) | ||
53 | (lambda (key . args) | ||
54 | (with-output-to-port | ||
55 | (current-error-port) | ||
56 | (lambda () | ||
57 | (format #t "~A: " progname) | ||
58 | (apply format #t (list-ref args 1) (list-ref args 2)) | ||
59 | (newline) | ||
60 | (exit 1))))) | ||
61 | (set! idest-main | ||
62 | (lambda (name frames) | ||
63 | (force-output (current-output-port)) | ||
64 | (force-output (current-error-port)) | ||
65 | (letrec ((title #f) | ||
66 | (print-lyrics (lambda (text) | ||
67 | (display (or title name)) | ||
68 | (newline) | ||
69 | (newline) | ||
70 | (display text) | ||
71 | (newline)))) | ||
72 | (call-with-current-continuation | ||
73 | (lambda (return) | ||
74 | (for-each | ||
75 | (lambda (elt) | ||
76 | (let ((frame-name (car elt)) | ||
77 | (frame-attr (cdr elt))) | ||
78 | (cond | ||
79 | ((string=? frame-name "TIT2") | ||
80 | (set! title (assoc-ref frame-attr 'text))) | ||
81 | ((and (string=? frame-name "USLT") | ||
82 | (or (not lang) | ||
83 | (string=? lang (assoc-ref frame-attr 'lang))) | ||
84 | (or (not condesc) | ||
85 | (string=? condesc | ||
86 | (assoc-ref frame-attr 'condesc)))) | ||
87 | (let ((text (assoc-ref frame-attr 'text))) | ||
88 | (cond | ||
89 | ((getenv "PAGER") => | ||
90 | (lambda (pag) | ||
91 | (let ((port (open-output-pipe pag))) | ||
92 | (with-output-to-port | ||
93 | port | ||
94 | (lambda () | ||
95 | (print-lyrics text))) | ||
96 | (close-pipe port)))) | ||
97 | (else | ||
98 | (print-lyrics text))) | ||
99 | (return)))))) | ||