File: at.tf

package info (click to toggle)
tf5 5.0beta8-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,800 kB
  • sloc: ansic: 25,492; perl: 103; makefile: 82; sh: 79
file content (46 lines) | stat: -rw-r--r-- 1,480 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;;; AT - run a command at a given time
;; syntax:  /at [-v] [<date> ]<time> <commands>
;; <commands> will be executed at <date> <time>.

/loaded __TFLIB__/at.tf

/def -i at = \
    /if (!getopts("v", "")) /return 0%; /endif%; \
    /let warn=%warn_curly_re%; \
    /set warn_curly_re=off%; \
    /if (regmatch("^(?:(\\d{2})(\\d{2})?-)?(\\d{1,2})[-/](\\d{1,2})$", {1})) \
	/let explicityear=$[!!{P2}]%; \
	/let explicitday=1%; \
	/let year=%{P1-$[ftime("%Y")/100]}%{P2-$[ftime("%y")]}%; \
	/let mon=%P3%; \
	/let day=%P4%; \
	/shift%; \
    /else \
	/let explicityear=0%; \
	/let explicitday=0%; \
	/let year=$[ftime("%Y")]%; \
	/let mon=$[ftime("%m")]%; \
	/let day=$[ftime("%d")]%; \
    /endif%; \
    /if (!regmatch("^(\\d{1,2}):(\\d{2})(?::(\\d{2}(?:\\.(\\d{0,6}))?))?$", {1})) \
	/echo -e %% Usage: /%0 [-v] [[yyyy-]mm-dd] hh:mm[:ss[.uuuuuu]] command%; \
	/set warn_curly_re=%warn%; \
	/return 0%; \
    /endif%; \
    /set warn_curly_re=%warn%; \
    /shift%; \
    /let usec=$[substr(strcat({P4}, "000000"), 0, 6)]%; \
    /let t=$[mktime(year, mon, day, {P1}, {P2}, {P3}, usec)]%; \
    /if (t <= time()) \
	/if (!explicitday) \
	    /test t += 24:00:00%; \
	/elseif (!explicityear) \
	    /let t=$[mktime(year+1, mon, day, {P1}, {P2}, {P3}, usec)]%; \
	/else \
	    /echo -e %% /%0: date and time must be in the future.%; \
	    /return 0%; \
	/endif%; \
    /endif%; \
    /if (opt_v) /echo -e %% /%0: $[ftime("%F %T.%.", t)]%; /endif%; \
    /repeat -$[t-time()] 1 %*