Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global lineno, line, seqno
- procedure nextline()
- initial lineno := 0
- return (lineno +:= 1 & line := trim(read()))
- end
- procedure die(args[])
- writes(&errout, &progname, ": ", lineno, ": ")
- stop!args
- end
- record time(h, m, s, ms)
- procedure parsetime()
- local h, m, s, ms
- h := m := ms := 0
- s := tab(many(&digits)) | fail
- if =":" then {
- m := s
- s := tab(many(&digits)) | fail
- }
- if =":" then {
- h := m
- m := s
- s := tab(many(&digits)) | fail
- }
- if tab(any('.,')) then
- {
- ms := tab(many(&digits)) | fail
- ms := left(ms, 3, "0")
- }
- (m < 60 & s < 60 & ms < 1000) | fail
- return time(h, m, s, ms)
- end
- procedure time2str(t)
- return right(t.h, 2, "0") ||
- ":" || right(t.m, 2, "0") ||
- ":" || right(t.s, 2, "0") ||
- "," || left(t.ms, 3, "0")
- end
- procedure caption()
- local t0, t1, op, i
- initial seqno := 0
- while line == "" do
- nextline() | fail
- if line ? (tab(many(&digits)) & pos(0)) then
- nextline() | fail
- seqno +:= 1
- write(seqno)
- line ? {
- t0 := parsetime() |
- die("invalid syntax: ", tab(0))
- tab(many(' \t'))
- op := tab(match("-->" | "for")) |
- die("invalid syntax: ", tab(0))
- tab(many(' \t'))
- t1 := parsetime() |
- die("invalid syntax: ", tab(0))
- pos(0) | die("invalid syntax: ", tab(0))
- if op == "for" then {
- every i := 1 to 4 do t1[i] +:= t0[i]
- t1.s +:= t1.ms / 1000
- t1.ms %:= 1000
- t1.m +:= t1.s / 60
- t1.s %:= 60
- t1.h +:= t1.m / 60
- t1.m %:= 60
- }
- write(time2str(t0), " --> ", time2str(t1))
- }
- nextline() | die("missing caption")
- until line == "" do {
- write(line)
- nextline() | fail
- }
- write()
- return
- end
- procedure main()
- nextline()
- while caption()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement