blob: f8d04c2fed89955e29258ad999dad9153cd94bc7 (
plain)
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
|
#!/usr/bin/env sh
#
# phl-org: manage a phlog with org-mode
#
# KatolaZ <katolaz@freaknet.org> (2018)
#
INFILE=${1:-/dev/stdin}
DESTDIR=${2:-"."}
pad=" "
FILTER="par 68ftp4"
headpad="+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
## if you are under *BSD, you'd probably use SED=gsed
##
#SED=gsed
SED=sed
## function
write_gophermap(){
buff=$1
curdir=$2
curfile=$3
INDEX=$4
if [ ! -d "$curdir" ]; then
mkdir "$curdir";
fi
echo $buff | eval "$FILTER" > "$curfile"
echo "1$curdir\t$curdir" >> $INDEX
}
##function
gophermap_header(){
GOPHERMAP=$1
cat <<EOF>$GOPHERMAP
+++++++++++++++++++++++++++++
+ This is my gopherhole +
+++++++++++++++++++++++++++++
EOF
}
## function
org2phlog(){
FILEIN=$1
INDEX=$2
curfile=""
buff=""
IFS="
"
while read line; do
#echo $wholeline | ${SED} -r -e '/^\* /p'
if [ -n "$(echo $line | ${SED} -r -n -e '/^\* /p')" ]; then
if [ -n "$curfile" ]; then
write_gophermap $buff $curfile "$curfile/gophermap" $INDEX
fi
buff="$headpad\n\n$pad$line\n\n$headpad"
curfile=$(echo $line | ${SED} -r -e 's/^\* //g' -e 's/\ /_/g;s/\t/_/g;s/</-/g;s/>/-/g;s/://g')
if [ -z "$curfile" ]; then
curfile="(blank)"
fi
curfile="$curfile"
else
buff="${buff}\n $line"
fi
done<$FILEIN
if [ -n "$curfile" ]; then
write_gophermap $buff $curfile "$curfile/gophermap" $INDEX
fi
}
#echo "INFILE: $INFILE"
gophermap_header ./gophermap
org2phlog $INFILE ./gophermap
|