summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-23 18:57:30 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-07-23 19:01:31 (GMT)
commit11afe84b218bda29db088d8dd4e16e79c03099ef (patch) (side-by-side diff)
treecdf9f6992482c6cec34ab771d497c4b04dce5a84
parente503a7f56ca38efc1886e04be0dbeb380db3934a (diff)
downloadidest-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.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--scheme/format.scm2
-rw-r--r--scheme/idest/format/framelist.scm97
-rw-r--r--scheme/idest/format/lyrics.scm101
-rw-r--r--src/cmdline.opt3
-rw-r--r--src/getopt.m46
-rw-r--r--src/guile.c2
-rw-r--r--src/idop.c2
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 @@
(set! %load-hook saved-load-hook)))
(let ((mod-name (list-ref cmd 1)))
- (set-program-arguments (cons (car cmd) (list-tail cmd 2)))
+ (set-program-arguments (list-tail cmd 1))
(set! idest-main
(module-ref
(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
--- a/dev/null
+++ b/scheme/idest/format/framelist.scm
@@ -0,0 +1,97 @@
+;; This file is part of Idest
+;; Copyright (C) 2011 Sergey Poznyakoff
+;;
+;; Idest 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, or (at your option)
+;; any later version.
+;;
+;; Idest 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 Idest. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (idest format framelist))
+
+(use-modules (ice-9 getopt-long))
+
+(define-public idest-main #f)
+
+(let* ((cmd (command-line))
+ (progname (car cmd))
+ (delim #\newline)
+ (addinfo #f)
+ (frame-list #f) ; FIXME: Need a way to access filter_list from idest
+ (grammar `((full (single-char #\F))
+ (qualified (single-char #\Q))
+ (frames (single-char #\f) (value #t))
+ (single-line (single-char #\l))
+ (help (single-char #\h)))))
+
+ (catch 'misc-error
+ (lambda ()
+ (for-each
+ (lambda (x)
+ (case (car x)
+ ((full)
+ (set! addinfo
+ (lambda (attr-list)
+ (for-each
+ (lambda (attr)
+ (if (not (eq? (car attr) 'text))
+ (format #t " ~A=\"~A\""
+ (car attr) (cdr attr))))
+ attr-list))))
+ ((qualified)
+ (set! addinfo
+ (lambda (attr-list)
+ (for-each
+ (lambda (attr)
+ (if (not (or (eq? (car attr) 'text)
+ (eq? (car attr) 'descr)))
+ (format #t ":~A" (cdr attr))))
+ attr-list))))
+ ((single-line)
+ (set! delim #\,))
+ ((frames)
+ (set! frame-list (string-split (cdr x) #\,)))
+ ((help)
+ (format #t "usage: idest --format=~A [OPTIONS] FILE...\n"
+ progname)
+ (format #t "displays the frame list\n")
+ (format #t "OPTIONS are:\n")
+ (format #t " -F, --full display all qualifiers\n")
+ (format #t " -f, --frames FLIST display only frames from FLIST\n")
+ (format #t " -Q, --qualified display frames in qualified form\n")
+ (format #t " -l, --single-line fit output on single-line\n")
+ (format #t " -h, --help show this help summary\n")
+ (exit 0))
+ (else
+ (set-program-arguments (cons progname (cdr x))))))
+ (getopt-long cmd grammar)))
+ (lambda (key . args)
+ (with-output-to-port
+ (current-error-port)
+ (lambda ()
+ (format #t "~A: " progname)
+ (apply format #t (list-ref args 1) (list-ref args 2))
+ (newline)
+ (exit 1)))))
+
+ (set! idest-main
+ (lambda (name frames)
+ (do ((tail frames (cdr tail)))
+ ((null? tail))
+ (let ((elt (car tail)))
+ (cond
+ ((or (not frame-list) (member (car elt) frame-list))
+ (display (car elt))
+ (if addinfo (addinfo (cdr elt)))
+ (if (null? (cdr tail))
+ (newline)
+ (display delim)))))))))
+
+
diff --git a/scheme/idest/format/lyrics.scm b/scheme/idest/format/lyrics.scm
new file mode 100644
index 0000000..7fb5b1c
--- a/dev/null
+++ b/scheme/idest/format/lyrics.scm
@@ -0,0 +1,101 @@
+;; This file is part of Idest
+;; Copyright (C) 2011 Sergey Poznyakoff
+;;
+;; Idest 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, or (at your option)
+;; any later version.
+;;
+;; Idest 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 Idest. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (idest format lyrics))
+
+(use-modules (ice-9 getopt-long)
+ (ice-9 popen))
+
+(define-public idest-main #f)
+
+(let* ((cmd (command-line))
+ (progname (car cmd))
+ (lang #f)
+ (condesc #f)
+ (grammar `((lang (single-char #\l) (value #t))
+ (content (single-char #\c) (value #t))
+ (help (single-char #\h)))))
+ (catch 'misc-error
+ (lambda ()
+ (for-each
+ (lambda (x)
+ (case (car x)
+ ((file)
+ (set! file (cdr x)))
+ ((lang)
+ (set! lang (cdr x)))
+ ((content)
+ (set! condesc (cdr x)))
+ ((help)
+ (format #t "usage: idest --format=~A [OPTIONS] FILE...\n"
+ progname)
+ (format #t "displays the USLT (unsynchronised lyric text) frame\n")
+ (format #t "OPTIONS are:\n")
+ (format #t " -l, --lang NAME set language in which the lyrics is writen (default: eng)\n")
+ (format #t " -c, --content TEXT set content description\n")
+ (exit 0))
+ (else
+ (set-program-arguments (cons progname (cdr x))))))
+ (getopt-long cmd grammar)))
+ (lambda (key . args)
+ (with-output-to-port
+ (current-error-port)
+ (lambda ()
+ (format #t "~A: " progname)
+ (apply format #t (list-ref args 1) (list-ref args 2))
+ (newline)
+ (exit 1)))))
+ (set! idest-main
+ (lambda (name frames)
+ (force-output (current-output-port))
+ (force-output (current-error-port))
+ (letrec ((title #f)
+ (print-lyrics (lambda (text)
+ (display (or title name))
+ (newline)
+ (newline)
+ (display text)
+ (newline))))
+ (call-with-current-continuation
+ (lambda (return)
+ (for-each
+ (lambda (elt)
+ (let ((frame-name (car elt))
+ (frame-attr (cdr elt)))
+ (cond
+ ((string=? frame-name "TIT2")
+ (set! title (assoc-ref frame-attr 'text)))
+ ((and (string=? frame-name "USLT")
+ (or (not lang)
+ (string=? lang (assoc-ref frame-attr 'lang)))
+ (or (not condesc)
+ (string=? condesc
+ (assoc-ref frame-attr 'condesc))))
+ (let ((text (assoc-ref frame-attr 'text)))
+ (cond
+ ((getenv "PAGER") =>
+ (lambda (pag)
+ (let ((port (open-output-pipe pag)))
+ (with-output-to-port
+ port
+ (lambda ()
+ (print-lyrics text)))
+ (close-pipe port))))
+ (else
+ (print-lyrics text)))
+ (return))))))
+ frames)
+ (format (current-error-port) "~A: no lyrics~%" name))))))) \ No newline at end of file
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 9ba0e81..f2d891d 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -190,9 +190,10 @@ BEGIN
END
OPTION(format,H,NAME,
- [<apply external format NAME>])
+ [<apply external format NAME; this stops further argument processing>])
BEGIN
format_name = optarg;
+ stop = 1; /* Stop argument processing */
END
OPTION(function,f,NAME,
diff --git a/src/getopt.m4 b/src/getopt.m4
index 54ef9c1..19ee33c 100644
--- a/src/getopt.m4
+++ b/src/getopt.m4
@@ -200,10 +200,10 @@ dnl
define([<GETOPT>],[<
{
int c;
-
+ int stop = 0;
ifelse([<$#>],3,opterr = 0;)
- while ((c = getopt_long($1, $2, SHORT_OPTS,
- long_options, NULL)) != EOF)
+ while (!stop && (c = getopt_long($1, $2, SHORT_OPTS,
+ long_options, NULL)) != EOF)
{
switch (c)
{
diff --git a/src/guile.c b/src/guile.c
index b4339c3..3934837 100644
--- a/src/guile.c
+++ b/src/guile.c
@@ -487,7 +487,7 @@ scm_to_tag(SCM scm, struct id3_tag *tag)
}
return modified;
}
-
+
SCM
guile_apply_main(const char *file, struct id3_tag *tag)
{
diff --git a/src/idop.c b/src/idop.c
index 316cd9c..e10a295 100644
--- a/src/idop.c
+++ b/src/idop.c
@@ -51,7 +51,7 @@ parse_ed_items(gl_list_t *plist, const char *arg)
arg += strspn(arg, " \t,");
}
}
-
+
void
parse_filter_items(const char *arg)
{

Return to:

Send suggestions and report system problems to the System administrator.