#!/usr/local/bin/ruby -Ke
# ttt.rb ver.0.1 2001/11/01
# ttt.rb ver.0.1.2 2001/11/02 rhtml only.
# ttt.rb => Rtds. ver.0.1.2 (Carrol)
# Rtds means "Ruby Tiny Diary System."
# CodeName are from cocktail.
# Rtds. ver.0.1.4 (Princess Mary) 2001/11/04
# -merge Namazu- -mkdir "todo" "ttt(basehtml=$.html-non)"-
# Rtds. ver.0.1.5 (Blue Eyes Blue) 2001/11/17-18
# -merge index diarytable-autowritable-
# -"~" is
escape-
# Rtds. ver.0.1.5.2 2001/11/20 -bugfix-
# ver.0.1.5.3 2001/11/23 -Location-bugfix-
# Rtds. ver.0.1.6 (Egg Nog) 2001/12/06
# -with anchor & create Rtds class & readcount method-
# Rtds. ver.0.1.7 (Look For The Future) 2001/12/30
# -create fileopen method & create diarytable method-
# - require "kconv"(toeuc)-
require "cgi"
require "kconv"
form = CGI.new
$version = "Rtds version 0.1.7 (Look For The Future)"
#//////////////////////////////////////////////////////////
class Rtds
def initialize
@name = "00"
@stream = ""
@zero = ""; @one = ""; @two = ""
end
def fileopen(filename,mode,str)
if mode == "r"
@file = open(filename,"r").read
return(@file)
elsif mode == "w"
@file = open(filename,"w").write str
end
end
def readcount(str,time)
str.each_line { |@line|
if @line =~ /^--/
@name = @name.succ!
end
@line.gsub!(/^--/,"¢§ ")
@line.gsub!(/--\r\n/,"\r\n")
@line.gsub!("\r\n","
\n")
@line.gsub!("~
\n","\n")
#@line.gsub!("^
\n","
\n")
@stream += @line
}
return(@stream)
end
def diarytable(str,addmonth,year)
if addmonth == "01a"
@zero = "01"; @one = "02"; @two = "03"
elsif addmonth == "04a"
@zero = "04"; @one = "05"; @two = "06"
elsif addmonth == "07a"
@zero = "07"; @one = "08"; @two = "09"
elsif addmonth == "10a"
@zero = "10"; @one = "11"; @two = "12"
end
str.gsub!("","\n#{year}/#{@zero}a | #{year}/#{@zero}b | #{year}/#{@one}a | #{year}/#{@one}b | #{year}/#{@two}a | #{year}/#{@two}b
")
end
end
#//////////////////////////////////////////////////////////
fyear = form['year'][0]
fmonth = form['month'][0]
fday = form['day'][0]
fdayc = fday.to_i
if fdayc < 16
fdayf = "a"
fdayt = "b"
else
fdayf = "b"
fdayt = "a"
end
ffile = fyear + fmonth
tomoko = ffile + fday
kotone = ffile + fdayf
mikage = fmonth + fdayf
ftime = "
\n"
str0 = form['comment'][0]
str1 = Kconv.toeuc(str0)
fstr = Rtds.new
fstr0 = fstr.readcount(str1,tomoko)
str2 = "\n\n#{ftime}
"
#//////////////////////////////////////////////////////////
begin
hmx12 = fstr.fileopen("#{kotone}.rhtml","r","dammy")
hmx12.gsub!("",str2)
fstr.fileopen("#{kotone}.rhtml","w",hmx12)
print "Location: ./\n\n"
#//////////////////////////////////////////////////////////
rescue
ayaka = fstr.fileopen("./ttt/base","r","dammy")
ayaka.gsub!("rrrrmonth","#{fyear}/#{fmonth}#{fdayf}")
ayaka.gsub!("rrrrtime","#{kotone}")
ayaka.gsub!("rrrrversion","#{$version}")
ayaka.gsub!("","#{str2}")
rhtml = fstr.fileopen("#{kotone}.rhtml","w",ayaka)
File.chmod(0755,"#{kotone}.rhtml")
shiho = fstr.fileopen("./ttt/indexbase","r","dammy")
table = fstr.fileopen("./ttt/diarytable","r","dammy")
if mikage == "01a"
table = fstr.diarytable(table,"01a",fyear)
elsif mikage == "04a"
table = fstr.diarytable(table,"04a",fyear)
elsif mikage == "07a"
table = fstr.diarytable(table,"07a",fyear)
elsif mikage == "10a"
table = fstr.diarytable(table,"10a",fyear)
end
table.gsub!("#{fyear}/#{fmonth}#{fdayf}","#{fyear}/#{fmonth}#{fdayf}")
shiho.gsub!("rrrrrtime",kotone)
shiho.gsub!("rrrrrversion",$version)
shiho.gsub!("",table)
fstr.fileopen("./ttt/diarytable","w",table)
fstr.fileopen("index.rhtml","w",shiho)
File.chmod(0755,"index.rhtml")
rinzi = "\nTo Do.
\n" + "To Do.¤Î·îÅÙ±Û¤·" + "\n
"
fstr.fileopen("./todo/#{kotone}.todo","w",rinzi)
print "Location: ./\n\n"
end