From c1828ab2c8b303953e5500b73613c3ff5cae1125 Mon Sep 17 00:00:00 2001 From: djcb Date: Fri, 19 Oct 2012 00:50:22 +0300 Subject: [PATCH] * guile: add support for scripts --- guile/mu/Makefile.am | 8 +++-- guile/mu/plot.scm | 10 +++--- guile/mu/script.scm | 54 +++++++++++++++++++++++++++++++++ guile/scripts/stats/Makefile.am | 10 ++++-- 4 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 guile/mu/script.scm diff --git a/guile/mu/Makefile.am b/guile/mu/Makefile.am index 3fca28c4..31433595 100644 --- a/guile/mu/Makefile.am +++ b/guile/mu/Makefile.am @@ -1,4 +1,4 @@ -## Copyright (C) 2008-2011 Dirk-Jan C. Binnema +## Copyright (C) 2008-2012 Dirk-Jan C. Binnema ## ## 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 @@ -19,6 +19,10 @@ include $(top_srcdir)/gtest.mk # FIXME: GUILE_SITEDIR would be better, but that # breaks 'make distcheck' scmdir=${prefix}/share/guile/site/2.0/mu/ -scm_DATA=stats.scm plot.scm + +scm_DATA= \ + stats.scm \ + plot.scm \ + script.scm EXTRA_DIST=$(scm_DATA) diff --git a/guile/mu/plot.scm b/guile/mu/plot.scm index 49e8c05f..af9329f0 100644 --- a/guile/mu/plot.scm +++ b/guile/mu/plot.scm @@ -33,18 +33,18 @@ return the file name." (close output) datafile)) -(define* (mu:plot data title x-label y-label #:optional (ascii #f)) - "Plot DATA with TITLE, X-LABEL and X-LABEL. If ASCII is true, display -using raw text, otherwise, use a graphical window." +(define* (mu:plot data title x-label y-label #:optional (text-only #f)) + "Plot DATA with TITLE, X-LABEL and X-LABEL. If TEXT-ONLY is true, +display using raw text, otherwise, use a graphical window." (let ((datafile (export-pairs data)) (gnuplot (open-pipe "gnuplot -p" OPEN_WRITE))) (display (string-append "reset\n" - "set term " (if ascii "dumb" "wxt") "\n" + "set term " (if text-only "dumb" "wxt") "\n" "set title \"" title "\"\n" "set xlabel \"" x-label "\"\n" "set ylabel \"" y-label "\"\n" "set boxwidth 0.9\n" "plot \"" datafile "\" using 2:xticlabels(1) with boxes fs solid\n") gnuplot) - (close-pipe gnuplot))) + (close-pipe gnuplot))) diff --git a/guile/mu/script.scm b/guile/mu/script.scm new file mode 100644 index 00000000..77a6d3c0 --- /dev/null +++ b/guile/mu/script.scm @@ -0,0 +1,54 @@ +;; Copyright (C) 2012 Dirk-Jan C. Binnema +;; +;; 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, 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, write to the Free Software Foundation, +;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +(define-module (mu script) + :export (mu:run mu:text-only)) + +(use-modules (ice-9 getopt-long) (ice-9 optargs) (ice-9 popen) (ice-9 format)) +(use-modules (mu) (mu stats) (mu plot)) + +(define (help-and-exit) + "Show some help." + (format #t "usage: script [--help] [--textonly] " + "[--muhome=] [searchexpr]\n") + (exit 0)) + +(define (mu:run args func) + "Interpret argument-list ARGS (like command-line +arguments). Possible arguments are: + --help (show some help and exit) + --muhome (path to alternative mu home directory) + --textonly (don't show any graphical windows) + searchexpr (a search query) +then call FUNC with args SEARCHEXPR and TEXTONLY." + (setlocale LC_ALL "") + (let* ((optionspec '( (muhome (value #t)) + (what (value #t)) + (textonly (value #f)) + (help (single-char #\h) (value #f)))) + (options (getopt-long args optionspec)) + (help (option-ref options 'help #f)) + (textonly (option-ref options 'textonly #f)) + (muhome (option-ref options 'muhome #f)) + (restargs (option-ref options '() #f)) + (expr (if restargs (string-join restargs) ""))) + (if help (help-and-exit)) + (mu:initialize muhome) + (func expr textonly))) + +;; Local Variables: +;; mode: scheme +;; End: diff --git a/guile/scripts/stats/Makefile.am b/guile/scripts/stats/Makefile.am index 38ad81a1..72b6296f 100644 --- a/guile/scripts/stats/Makefile.am +++ b/guile/scripts/stats/Makefile.am @@ -16,8 +16,12 @@ include $(top_srcdir)/gtest.mk -EXTRA_DIST= \ - msg-stats.scm +EXTRA_DIST= \ + msgs-per-year.scm \ + msgs-per-hour.scm \ + msgs-per-month.scm \ + msgs-per-day.scm \ + msgs-per-year-month.scm -muguiledistscriptdir = $(datadir)/$(PACKAGE)/scripts/stats +muguiledistscriptdir = $(pkgdatadir)/scripts/stats muguiledistscript_SCRIPTS = $(EXTRA_DIST)