-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_hpp.sh
executable file
·100 lines (84 loc) · 1.97 KB
/
make_hpp.sh
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
#!/usr/bin/env bash
if [ ! $# -eq 1 ]; then
echo "Usage: $0 <input file>"
exit 1
fi
INSTPATH=`dirname $0`
. ${INSTPATH}/colors.sh
HEADER=$1
if [ ! -e ${HEADER} ]; then
#echo "cannot find header file: ${HEADER}"
exit 1
fi
UNAME=$(uname -s)
SED=sed
if [ $UNAME = "Darwin" ]; then
SED=${SED:-gsed}
fi
if [ -z "${HTML2TEXT}" ]; then
echo "don't know html2text!"
HTML2TEXT=html2text
elif [ ! -e ${HTML2TEXT} ]; then
echo "unknown html2text: ${HTML2TEXT}!"
HTML2TEXT=html2text
fi
if [ ! -e ${HTML2TEXT} ]; then
echo "unknown html2text: ${HTML2TEXT}!"
exit 1
fi
BASENM=`basename ${HEADER} .md`
if [ ${BASENM} -nt ${HEADER} ]; then
prtLightGray "no new update to file ${BASENM}"; echo
exit 1
fi
if [ -e ${BASENM}_t ]; then
rm ${BASENM}_t
fi
# test for <fpaste >
patpaste='<fpaste '
nl -ba ${HEADER} | {
read n l
echo "\\#line $n \"${HEADER}\""
echo
while [ -n "$n" ]; do
if [[ $l =~ $patpaste ]]; then
FN=`echo "$l" | $SED -ne 's/[<]fpaste[ ]*\(.*\)[>].*/\1/p'`
if [ -f "$FN" ]; then
echo "#line 1 \"${FN}\""
cat "$FN"
echo "\\#line $((n+1)) \"${HEADER}\""
echo
else
echo "// missing file: ${FN}"
echo
fi
else
echo "$l"
fi
read n l
done
} >> ${BASENM}_t
pandoc -f markdown -t html --ascii ${BASENM}_t -o ${BASENM}.html
$SED -i -e 's/̶[01];/"/g;s/ȁ[CD];/"/g;' ${BASENM}.html
if [ ! -e ${BASENM} ]; then
touch ${BASENM}
fi
${HTML2TEXT} -nobs -to_encoding ASCII -width 232 -o ${BASENM} ${BASENM}.html
# replace some annoying characters
$SED -i -e 's/̶[01];/"/g;s/ȁ[CD];/"/g;' ${BASENM}
$SED -i -e 's/^\*\*\*\*\*\* //;' ${BASENM}
$SED -i -e 's/^\*\*\*\*\* //;' ${BASENM}
$SED -i -e 's/ \*\*\*\*\*\*$//;' ${BASENM}
$SED -i -e 's/ \*\*\*\*\*$//;' ${BASENM}
if [ -e ${BASENM}_t ]; then
rm ${BASENM}_t
fi
if [ -e ${BASENM}-e ]; then
rm ${BASENM}-e
fi
if [ -e ${BASENM}.html ]; then
rm ${BASENM}.html
fi
if [ -e ${BASENM}.html-e ]; then
rm ${BASENM}.html-e
fi