Remove $void CPS expression type
[bpt/guile.git] / module / scripts / summarize-guile-TODO.scm
CommitLineData
89c87759
TTN
1;;; summarize-guile-TODO --- Display Guile TODO list in various ways
2
a1a2ed53 3;; Copyright (C) 2002, 2006, 2010, 2011 Free Software Foundation, Inc.
89c87759
TTN
4;;
5;; This program is free software; you can redistribute it and/or
83ba2d37
NJ
6;; modify it under the terms of the GNU Lesser General Public License
7;; as published by the Free Software Foundation; either version 3, or
89c87759
TTN
8;; (at your option) any later version.
9;;
10;; This program is distributed in the hope that it will be useful,
11;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
83ba2d37 13;; Lesser General Public License for more details.
89c87759 14;;
83ba2d37
NJ
15;; You should have received a copy of the GNU Lesser General Public
16;; License along with this software; see the file COPYING.LESSER. If
17;; not, write to the Free Software Foundation, Inc., 51 Franklin
18;; Street, Fifth Floor, Boston, MA 02110-1301 USA
89c87759
TTN
19
20;;; Author: Thien-Thi Nguyen <ttn@gnu.org>
21
22;;; Commentary:
23
24;; Usage: summarize-guile-TODO TODOFILE
25;;
26;; The TODOFILE is typically Guile's (see workbook/tasks/README)
27;; presumed to serve as our signal to ourselves (lest we want real
28;; bosses hassling us) wrt to the overt message "items to do" as well as
29;; the messages that can be inferred from its structure.
30;;
31;; This program reads TODOFILE and displays interpretations on its
32;; structure, including registered markers and ownership, in various
b2625385 33;; ways.
89c87759
TTN
34;;
35;; A primary interest in any task is its parent task. The output
36;; summarization by default lists every item and its parent chain.
b2625385
TTN
37;; Top-level parents are not items. You can use these command-line
38;; options to modify the selection and display (selection criteria
39;; are ANDed together):
40;;
41;; -i, --involved USER -- select USER-involved items
42;; -p, --personal USER -- select USER-responsible items
43;; -t, --todo -- select unfinished items (status "-")
a8119762 44;; -d, --done -- select finished items (status "+")
b2625385
TTN
45;; -r, --review -- select review items (marker "R")
46;;
47;; -w, --who -- also show who is associated w/ the item
48;; -n, --no-parent -- do not show parent chain
89c87759
TTN
49;;
50;;
51;; Usage from a Scheme program:
4b93c263 52;; (summarize-guile-TODO . args) ; uses first arg only
fb1cdefe
TTN
53;;
54;;
55;; Bugs: (1) Markers are scanned in sequence: D R X N%. This means "XD"
56;; and the like are completely dropped. However, such strings
57;; are unlikely to be used if the markers are chosen to be
58;; somewhat exclusive, which is currently the case for D R X.
59;; N% used w/ these needs to be something like: "D25%" (this
60;; means discussion accounts for 1/4 of the task).
b2625385
TTN
61;;
62;; TODO: Implement more various ways. (Patches welcome.)
63;; Add support for ORing criteria.
89c87759
TTN
64
65;;; Code:
3932bdb3 66(debug-enable 'backtrace)
89c87759
TTN
67
68(define-module (scripts summarize-guile-TODO)
69 :use-module (scripts read-text-outline)
b2625385 70 :use-module (ice-9 getopt-long)
fb1cdefe 71 :autoload (srfi srfi-13) (string-tokenize) ; string library
201e7da7 72 :autoload (srfi srfi-14) (char-set) ; string library
b2625385 73 :autoload (ice-9 common-list) (remove-if-not)
89c87759
TTN
74 :export (summarize-guile-TODO))
75
a1a2ed53
AW
76(define %include-in-guild-list #f)
77(define %summary "A quaint relic of the past.")
78
89c87759
TTN
79(define put set-object-property!)
80(define get object-property)
81
fb1cdefe
TTN
82(define (as-leaf x)
83 (cond ((get x 'who)
84 => (lambda (who)
85 (put x 'who
86 (map string->symbol
201e7da7 87 (string-tokenize who (char-set #\:)))))))
fb1cdefe
TTN
88 (cond ((get x 'pct-done)
89 => (lambda (pct-done)
90 (put x 'pct-done (string->number pct-done)))))
91 x)
92
89c87759
TTN
93(define (hang-by-the-leaves trees)
94 (let ((leaves '()))
95 (letrec ((hang (lambda (tree parent)
96 (if (list? tree)
97 (begin
98 (put (car tree) 'parent parent)
99 (for-each (lambda (child)
100 (hang child (car tree)))
101 (cdr tree)))
102 (begin
103 (put tree 'parent parent)
fb1cdefe 104 (set! leaves (cons (as-leaf tree) leaves)))))))
89c87759
TTN
105 (for-each (lambda (tree)
106 (hang tree #f))
107 trees))
108 leaves))
109
89c87759
TTN
110(define (read-TODO file)
111 (hang-by-the-leaves
fb1cdefe
TTN
112 ((make-text-outline-reader
113 "(([ ][ ])*)([-+])(D*)(R*)(X*)(([0-9]+)%)* *([^[]*)(\\[(.*)\\])*"
114 '((level-substring-divisor . 2)
115 (body-submatch-number . 9)
116 (extra-fields . ((status . 3)
117 (design? . 4)
118 (review? . 5)
119 (extblock? . 6)
120 (pct-done . 8)
121 (who . 11)))))
89c87759
TTN
122 (open-file file "r"))))
123
b2625385
TTN
124(define (select-items p items)
125 (let ((sub '()))
126 (cond ((option-ref p 'involved #f)
127 => (lambda (u)
128 (let ((u (string->symbol u)))
129 (set! sub (cons
130 (lambda (x)
131 (and (get x 'who)
132 (memq u (get x 'who))))
133 sub))))))
134 (cond ((option-ref p 'personal #f)
135 => (lambda (u)
136 (let ((u (string->symbol u)))
137 (set! sub (cons
138 (lambda (x)
139 (cond ((get x 'who)
140 => (lambda (ls)
141 (eq? (car (reverse ls))
142 u)))
143 (else #f)))
144 sub))))))
145 (for-each (lambda (pair)
146 (cond ((option-ref p (car pair) #f)
147 (set! sub (cons (cdr pair) sub)))))
148 `((todo . ,(lambda (x) (string=? (get x 'status) "-")))
149 (done . ,(lambda (x) (string=? (get x 'status) "+")))
150 (review . ,(lambda (x) (get x 'review?)))))
151 (let loop ((sub (reverse sub)) (items items))
152 (if (null? sub)
153 (reverse items)
154 (loop (cdr sub) (remove-if-not (car sub) items))))))
155
156(define (make-display-item show-who? show-parent?)
4b93c263
TTN
157 (let ((show-who
158 (if show-who?
159 (lambda (item)
160 (cond ((get item 'who)
161 => (lambda (who) (format #f " ~A" who)))
162 (else "")))
163 (lambda (item) "")))
164 (show-parents
165 (if show-parent?
166 (lambda (item)
167 (let loop ((parent (get item 'parent)) (indent 2))
168 (and parent
169 (begin
170 (format #t "under : ~A~A\n"
171 (make-string indent #\space)
172 parent)
173 (loop (get parent 'parent) (+ 2 indent))))))
174 (lambda (item) #t))))
175 (lambda (item)
176 (format #t "status: ~A~A~A~A~A~A\nitem : ~A\n"
177 (get item 'status)
178 (if (get item 'design?) "D" "")
179 (if (get item 'review?) "R" "")
180 (if (get item 'extblock?) "X" "")
181 (cond ((get item 'pct-done)
182 => (lambda (pct-done)
183 (format #f " ~A%" pct-done)))
184 (else ""))
185 (show-who item)
186 item)
187 (show-parents item))))
b2625385
TTN
188
189(define (display-items p items)
190 (let ((display-item (make-display-item (option-ref p 'who #f)
191 (not (option-ref p 'no-parent #f))
192 )))
193 (for-each display-item items)))
89c87759
TTN
194
195(define (summarize-guile-TODO . args)
b2625385
TTN
196 (let ((p (getopt-long (cons "summarize-guile-TODO" args)
197 '((who (single-char #\w))
198 (no-parent (single-char #\n))
199 (involved (single-char #\i)
200 (value #t))
201 (personal (single-char #\p)
202 (value #t))
203 (todo (single-char #\t))
204 (done (single-char #\d))
7e352174 205 (review (single-char #\r))
b2625385
TTN
206 ;; Add options here.
207 ))))
208 (display-items p (select-items p (read-TODO (car (option-ref p '() #f))))))
89c87759
TTN
209 #t) ; exit val
210
211(define main summarize-guile-TODO)
212
213;;; summarize-guile-TODO ends here