;; -*- coding:utf-8 -*- (use file.util) (use gauche.process) (use gauche.version) (use srfi.13) (use util.match) ;;; ;;; Call makeinfo to generate various document output ;;; (define (main args) (if (match (cdr args) [("info" input makeinfo gzip) (do-info input makeinfo gzip)] [("html" input makeinfo) (do-html input makeinfo)] [("htmls" input makeinfo version) (do-htmls input makeinfo version)] [("pdf" input makeinfo) (do-pdf input makeinfo)] [("dvi" input makeinfo) (do-dvi input makeinfo)] [("epub" input makeinfo) (do-epub input makeinfo)] [_ (usage)]) 0 1)) (define (usage) (print "Usage: gosh makedoc.scm command args ...") (print "Valid commands (and args):") (print " info input MAKEINFO GZIP - generate info doc") (print " html input MAKEINFO - generate single html") (print " htmls input MAKEINFO VERSION-STRING - generate html files in subdir") (print " pdf input MAKEINFO - generate pdf") (print " dvi input MAKEINFO - generate dvi") (print " epub input MAKEINFO - generate ePub") #f) (define (make-cmd cmd-list) (cond-expand [gauche.os.windows ;; for MSYS (mintty) (if-let1 sh (sys-getenv "SHELL") `("cmd.exe" "/c" ,sh "-c" ,(string-join (map (^c (shell-escape-string (x->string c) 'posix)) cmd-list) " ")) `("cmd.exe" "/c" ,@cmd-list))] [else cmd-list])) (define (check-makeinfo-version makeinfo min-version :optional (quiet? #f)) (and-let* ([ makeinfo ] [msg (process-output->string (make-cmd `(,makeinfo --version)))] [vers (rxmatch->string #/\d+\.\d+(\.\d+)?/ msg)]) (rlet1 b (version<=? min-version vers) (when (and (not b) (not quiet?)) (warn "makeinfo version ~a or greater is required, but ~a's \ version is ~a. Skipping.\n" min-version makeinfo vers))))) (define (do-info input makeinfo gzip) (define info (path-swap-extension input "info")) (or (string-null? makeinfo) (string-null? gzip) (not (check-makeinfo-version makeinfo "5.0")) (and (do-process (make-cmd `(,makeinfo ,input))) (begin (remove-files (glob #"~|info|*.gz")) (do-process (make-cmd `(,gzip "--best" "-n" ,info ,@(glob #"~|info|-[0-9]*")))))))) (define (do-html input makeinfo) (or (string-null? makeinfo) (not (check-makeinfo-version makeinfo "5.0")) (do-process (make-cmd `(,makeinfo "--html" "--no-split" "--set-customization-variable" "TOP_NODE_UP_URL=https://practical-scheme.net/gauche" "-")) :redirects `((<< 0 ,(alter-top-node input)))))) (define (do-htmls input makeinfo version-info) (define draft? (#/DRAFT/ version-info)) (define ja? (#/j\.texi$/ input)) (define top-link (cond [draft? "https://github.com/shirok/Gauche"] [ja? "https://practical-scheme.net/gauche/memo-j.html"] [else "https://practical-scheme.net/gauche/memo.html"])) (define header-style (if draft? "width:100%;background-color:#f88;" "width:100%;background-color:#cfc;")) (define lang (if ja? "ja" "en")) (define draft-search (if draft? "" "")) (define header-div #"