9 name = File::basename $0
11 #{name}: ͽÄê¤ä todo ¤Î°ìÍ÷¤ò½ÐÎÏ
13 #{name} *.memo ¢ª ¥«¥ì¥ó¥À¡¼(ͽÄꡦ¡ºÀÚ¡¦ºÑ¤ß¤Î°ìÍ÷)¤ò½ÐÎÏ
14 #{name} -l *.memo ¢ª ½ÜÅÙ½ç¤Î todo °ìÍ÷¤ò½ÐÎÏ
15 #{name} -i *.memo ¢ª iCalendar ·Á¼°¤Ç½ÐÎÏ (ºîÀ®Ãæ)
16 #{name} -h ¤Þ¤¿¤Ï #{name} -help ¢ª ¤³¤Î¥á¥Ã¥»¡¼¥¸¤ò½ÐÎÏ
18 http://howm.sourceforge.jp/ »²¾È
22 ############################################
25 $schedule_types ||= '[@!.]'
26 $type_alias = {'' => '-'}
29 def item_regexp(types)
32 $todo_types ||= '[-+~!.]?'
33 %r|(@\[(\d\d\d\d)#{x}(\d\d)#{x}(\d\d)\](#{types})(\d*)\s+(.*))$|
35 $todo_types ||= '[-+~!.]'
36 %r|(\[(\d\d\d\d)#{x}(\d\d)#{x}(\d\d)\](#{types})(\d*)\s+(.*))$|
43 $comment_width = $comment_width.to_i
45 $schedule_mark ||= '@'
46 $deadline_mark ||= '!'
49 '@' => $schedule_mark,
50 '!' => $deadline_mark,
54 $type_order = {'@' => 2, '!' => 1, '.' => 3, '?' => 4}
55 $today_mark ||= ' <<<<##>>>>'
56 $same_day_mark ||= ' #>>>>'
61 # '' => lambda{|lt, lz| pr_normal lt, lz},
62 '-' => lambda{|lt, lz| pr_normal lt, lz},
63 '+' => lambda{|lt, lz| pr_todo lt, lz},
64 '~' => lambda{|lt, lz| pr_defer lt, lz},
65 '!' => lambda{|lt, lz| pr_deadline lt, lz},
66 '@' => lambda{|lt, lz| pr_schedule lt, lz},
67 '.' => lambda{|lt, lz| pr_done lt, lz},
68 '?' => lambda{|lt, lz| 0},
85 $pr_normal_bottom = - $huge
86 $pr_todo_bottom = - $huge
87 $pr_defer_bottom = - $huge
88 $pr_deadline_bottom = - $huge
89 $pr_deadline_top = $huge
90 $pr_done_bottom = - $huger
95 $daysec = 60 * 60 * 24
97 ############################################
101 ($now - time.to_f) / $daysec
104 # def late(y, m, d, now)
105 # ($now - Time::local(y,m,d,0,0,0).to_f) / $daysec
108 def relative_late(late, laziness, default)
109 laziness = default if laziness == 0
113 def pr_normal(lt, lz)
114 r = relative_late lt, lz, $lz_normal
115 r >= 0 ? - r : $pr_normal_bottom + r
119 r = relative_late lt, lz, $lz_todo
121 r >= 0 ? c * (r - 1) : $pr_todo_bottom + r
125 r = relative_late lt, lz, $lz_defer
126 c = $pr_defer_peak - $pr_defer
127 v = 2 * (((r % 1) - 0.5).abs)
128 r >= 0 ? $pr_defer_peak - c * v : $pr_defer_bottom + r
131 def pr_deadline(lt, lz)
132 r = relative_late lt, lz, $lz_deadline
137 $pr_deadline_bottom + r
144 def pr_schedule(lt, lz)
152 ############################################
161 ARGF.grep(item_regexp(types)){|x|
164 y, m, d = [$2, $3, $4].map{|s| s.to_i}
165 # h[:y] = y = $2.to_i
166 # h[:m] = m = $3.to_i
167 # h[:d] = d = $4.to_i
168 h[:time] = time = Time::mktime(y, m, d)
169 h[:type] = type = $type_alias[$5] || $5
170 h[:laziness] = laziness = $6.to_i
172 h[:priority] = - $priority_func[type].call(late(time), laziness)
173 h[:file] = ARGF.filename
174 h[:line] = ARGF.file.lineno
179 # def select_type(item, types)
180 # item.select{|h| types.member? h[:type]}
186 item($todo_types).sort{
187 |a, b| a[:priority] <=> b[:priority]
189 puts "#{a[:file]}:#{a[:line]}:#{a[:text]}"
195 $conv = Iconv.new("UTF-8", "EUC-JP")
201 PRODID:-//howm.sourceforge.jp//hcal.rb $Revision: 1.12 $//EN
203 #{item($schedule_types).map{|h| ical_item h}.select{|z| z}.join.chomp}
209 # if !Date.valid_date?(h[:y], h[:m], 1)
210 # $stderr.puts 'Invalid date:#{h[:file]}:#{h[:line]}:#{h[:text]}'
213 # # convert 2005-09-31 to 2005-10-01
214 # d = Date.new(h[:y], h[:m], 1) + (h[:d] - 1)
215 # d = Date.new h[:y], h[:m], h[:d]
216 # s, e = [d, d+1].map{|z| z.strftime '%Y%m%d'}
217 s, e = [h[:time], h[:time] + 86400].map{|z| z.strftime '%Y%m%d'}
222 SUMMARY:#{$conv.iconv(h[:type] + h[:comment])}
231 item($schedule_types).each{|h|
233 cal[t] ||= Array::new
235 # [2004-12-25]@3 ==> [2004-12-25]@ [2004-12-26]@ [2004-12-27]@
236 if h[:type] == '@' && h[:laziness] > 1
237 (1...h[:laziness]).each{|d|
238 td = t + 60 * 60 * 24 * d
239 cal[td] ||= Array::new
244 min_time = cal.keys.min
245 max_time = cal.keys.max
250 puts "----------------<#{t.month}>---------------- #{t.year}" if t.day == 1
251 day = t.strftime '%d %a'
253 x, y = [a, b].map{|z| [$type_order[z[:type]], z[:comment]]}
255 # $type_order[a[:type]] <=> $type_order[b[:type]]
257 h[:comment].sub!(%r|^(cancel)? *\[[#{$date_sep}0-9]+\][!+]?[0-9]*\s*|){|s| $1 ? 'x' : ''} if h[:type] == '.' # adhoc!
258 $type_display[h[:type]] + h[:comment].split(//)[0, $comment_width].join
260 mark = if t.strftime('%Y%m%d') == Time::now.strftime('%Y%m%d')
262 elsif t.strftime('%m%d') == Time::now.strftime('%m%d')
267 puts "#{day} #{text}#{mark}"