-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.zsh
More file actions
executable file
·146 lines (130 loc) · 3.19 KB
/
script.zsh
File metadata and controls
executable file
·146 lines (130 loc) · 3.19 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/zsh -f
# For security reasons, the actual executable on bespin
# must be updated manually when this file is modified:
# /usr/bin/install -m 755 -o bastiat -g bastiat \
# /serv/bastiat/org/script.zsh /serv/bastiat/bin/script.zsh
# Also, /serv/bastiat/bin/update_bespin is but
# #!/bin/sh
# exec /serv/bastiat/bin/script.zsh LOG update_bespin
### Variables
LOG_FILE=/serv/bastiat/tmp/x.log
((MAX_LOG_SIZE = 2**18))
### Helper function library
DBG() { print -r "$*" >&2; }
abort() { DBG "$2"; exit "$1"; }
no_func_abort() { abort 102 "Unknown function $1"; }
DO() { DBG "$@"; "$@"; }
push() { LIST=$1; shift; eval "$LIST+=(\"\$@\")"; }
function_p() {
case $(whence -v "$1") in
"$1 is a shell function"*)
return 0
;;
*)
return 1
;;
esac
}
call_if_func() {
if function_p "$1"; then
"$@"
else
no_func_abort "$1"
fi
}
### Generic batch functions
LOG() {
check_identity
keep_log_small
{
echo
echo "$USERNAME@$HOST ($UID) $(date)"
echo "$PROG $ARGS"
echo "==> $0 $*"
call_if_func "$@"
echo "<== END $(date)"
} >>& "$LOG_FILE"
}
check_identity() {
if [[ $USERNAME != bastiat ]]; then
abort 10 'Must be user bastiat. Aborting.'
fi
}
keep_log_small() {
if (( $(sizeof "$LOG_FILE") > MAX_LOG_SIZE )); then
mv -f "$LOG_FILE" "$LOG_FILE".old
fi
}
sizeof() {
if [[ -f $1 ]]; then
du -sb "$1" 2> /dev/null | { read A B; echo "$A"; }
else
echo 0; return 1
fi
}
update_bespin() {
local RSYNC_ARGS="--itemize-changes --recursive --links --checksum --delete --exclude .git ./ bastiat.org:~bastiat/html/"
make dep &&
make &&
rsync --dry-run ${=RSYNC_ARGS} &&
echo "\nPress [ENTER] to run the above rsync without --dry-run" &&
read &&
rsync ${=RSYNC_ARGS}
}
txt2scr() {
perl -e '
$_ = join("",<>);
s/\r\n?/\n/gs;
s/XXX\:sic\:/(XXX sicYYY)/gs;
s/XXX\:sic/(XXX YYYsic)/gs;
s/\s*([,.:;?!])/$1/gs;
s/([,.:;?!])([A-Za-zÀ-ÿ])/$1 $2/gs;
s/YYY/:/gs;
s/ +/ /gs;
s/ \n/\n/gs;
s/^ //gm;
s/\n{3,}/\n\]\n(nbsp)\n[\n/gs;
s/\n\n/\n\]\[\n/gs;
# Gérer les itemize avec s/^\- /...
# Gérer les blockquotes avec s/^\i/...
s/\[\*+([^\]]*)\]/,(footnote[$1\])/gs;
s/\/([^0-9\/]*)\//,(emph\[$1\])/gs;
s/(\W)l,\(emph\[/$1\,\(inlatin\[/gs;
s/(\W)i,\(emph\[/$1\,\(initalian\[/gs;
s/(\W)e,\(emph\[/$1\,\(inenglish\[/gs;
s/(\W)t,\(emph\[/$1\,\(cite-title\[/gs;
s/\*([^\*]*)\*/,(strong\[$1\])/gs;
s/\"\s*([^\"]*?\S)?\s*\"/,(q\[$1\])/gs;
s/\«\s*([^\"]*?\S)?\s*\»/,(q\[$1\])/gs;
s/\x93\s*([^\"]*?\S)?\s*\x94/,(q\[$1\])/gs;
s/oe([uil])/,(oe)$1/gs;
s/\-\-/,(--)/gs;
s/NdEEO/,(NdEEO)/gs;
s/NdEEE/,(NdEBO)/gs;
s/NdEBO/,(NdEBO)/gs;
s/\(XXX ([^\)]+)\)/,(XXX [$1])/gs;
s/XXX/,(XXX)/gs;
s/\,\(\,\(XXX\)/,(XXX/gs;
s/\(footnote/\(footnote\*/gs;
s/\)\;/),(pv)/gs;
s/\x9C/,(oe)/gs;
s/\x8C/,(OE)/gs;
s/\x91/\'\''/gs; # Note the shell quoting of a single quote here
s/\x92/\'\''/gm; # Note the shell quoting of a single quote here
s/\x97/,(--)/gm;
s/\x96/,(--)/gm;
s/\xFF//gm;
s/\x85/.../gm; # \&hellip\;
print;
' -- "$@"
}
main() {
if function_p "$1"; then
"$@"
else
no_func_abort "$@"
fi
}
PROG=$0
ARGS=("$@")
main "$@"