arthur.bebou

Le site arthur.bebou.netlib.re - retour accueil

git clone git://bebou.netlib.re/arthur.bebou
Log | Files | Refs |

respl (1530B)


      1 #! /usr/bin/awk -f
      2 # vim: noet
      3 # respl: a repetitive schedule programming langage
      4 # a constructive response to how mind-numbing web apps are.
      5 
      6 # comlete example for the documentation
      7 # <<. respl | sort -t+ -k2 | date -f- +%s
      8 # s jun 9 2pm; d+ 5; w* 4
      9 # s jun 9 9am; d+ 5; w* 4
     10 
     11 # the program:
     12 # say april 1 8pm # say/set the date is apr 1, 8pm
     13 # days+ 2 4       # or 2 days later or 4 days later
     14 # week* 2         # or the same weekdays for 2 more weeks
     15 
     16 # could be shorten like this
     17 # s april 1 8pm ; d+ 2 4 ; w* 2
     18 # typical usecase is framadate datepoll generation
     19 # <<. respl | date -f- +%Y-%m-%d
     20 # s apr 1; w* 3 ; d+ 1 2
     21 
     22 function too_old_for(ver) {
     23 	print "respl is too old, update to version "ver | ">&2 cat"
     24 	exit 1;
     25 }
     26 
     27 function printdates() {
     28 	if (date) for ( cweek=0; cweek<weeks; ++cweek ) {
     29 		sub(/[\t ,]+$/,"",days) # remove tailing separators
     30 		split(days,DAYS,/[\t ,]+/)
     31 		split(hours,HOURS,/[\t ,]+/)
     32 		for ( d in DAYS )
     33 			for ( h in HOURS )
     34 				print date \
     35 				"+"  cweek "weeks" \
     36 				"+" DAYS[d] "days" \
     37 				"+" HOURS[h] "hours"
     38 	}
     39 	date=""
     40 }
     41 
     42 BEGIN {
     43 	VERSION=0
     44 	FS=";"
     45 }
     46 
     47 {
     48 	gsub(/#.*/,"") # comments allowed
     49 	for (f=1;f<=NF;++f) {
     50 		if (sub(/^ *v(ersion)? */ ,"",$f) && $f > VERSION ) too_old_for($f)
     51 		if      (sub(/^ *s(ay)? */      ,"",$f)) { printdates(); date=$f ; hours=0; days=0; weeks=1 }
     52 		else if (sub(/^ *h(ours)?[+] */ ,"",$f)) { hours=hours" "$f }
     53 		else if (sub(/^ *d(ays)?[+] */  ,"",$f)) { days=days" "$f }
     54 		else if (sub(/^ *w(week)?[*] */ ,"",$f)) { weeks=$f }
     55 	}
     56 }
     57 END { printdates() }
     58