This repository has been archived by the owner on Jul 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticle.sh
executable file
·175 lines (171 loc) · 4.87 KB
/
article.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
DIR=`dirname $0`
source "$DIR/db/common.sh"
MAKEDIR
if [ ! -z $1 ]; then
# article ID is provided in $1
if [[ ! "$1" == *[!0-9]* ]]; then
ID=$1
FILE="$DATA/posts/$ID.info"
fi
fi
if [ -z $1 ]; then
$DIR/en/list.sh -l
elif [ -z $2 ]; then
EN=`$DIR/en/list.sh $1`
CN=`$DIR/cn/list.sh $1`
NUM=`echo "$EN"|wc -l`
POS=0
while [ $POS -lt $NUM ]; do
POS=`expr $POS + 1`
DIC=$(GET $FILE DIC)
if [ ! -z "$DIC" ]; then
if [[ $DIC =~ (^| )$POS($| ) ]]; then
$0 $1 $2 $POS ec
fi
else
$0 $1 $2 $POS ec
fi
done
else
LEN=$(GET $FILE LEN)
DIC=$(GET $FILE DIC)
if [ "$LEN" == "" ]; then
LEN=`$DIR/en/list.sh $1 -10` # -10 indicates to get size
SET $FILE LEN $LEN
fi
if [[ "$2" == *[!0-9]* ]]; then
POS=$(GET $FILE POS)
if [ -z $POS ]; then
POS=0
SET $FILE POS $POS
fi
if [ "$2" == "reset" ] || [ "$2" == "r" ]; then
if [ "$3" == "mark" ] || [ "$3" == "m" ] || [ "$3" == "unmark" ] || [ "$3" == "u" ]; then
exit 1
fi
rm -rf $FILE
echo ""
echo "Marks Reset"
echo ""
exit 0
elif [ "$2" == "save" ] || [ "$2" == "s" ]; then
if [ "$3" == "mark" ] || [ "$3" == "m" ] || [ "$3" == "unmark" ] || [ "$3" == "u" ]; then
exit 1
fi
DIC=$(GET $FILE DIC)
SET $LIST $ID "$DIC"
echo ""
echo "Marks Saved"
echo ""
exit 0
elif [ "$2" == "mark" ] || [ "$2" == "m" ]; then
if [ "$3" == "mark" ] || [ "$3" == "m" ] || [ "$3" == "unmark" ] || [ "$3" == "u" ]; then
exit 1
fi
if [[ ! $DIC =~ (^| )$POS($| ) ]]; then
if [ -z "$DIC" ]; then
DIC="$POS"
else
DIC="$DIC $POS"
fi
SET $FILE DIC "$DIC"
fi
echo ""
echo "Word Marked"
echo ""
exit 0
elif [ "$2" == "head" ] || [ "$2" == "h" ]; then
if [ "$3" == "mark" ] || [ "$3" == "m" ] || [ "$3" == "unmark" ] || [ "$3" == "u" ]; then
exit 1
fi
clear
echo ""
POS=1
elif [ "$2" == "tail" ] || [ "$2" == "t" ]; then
if [ "$3" == "mark" ] || [ "$3" == "m" ] || [ "$3" == "unmark" ] || [ "$3" == "u" ]; then
exit 1
fi
clear
echo ""
POS=$LEN
elif [ "$2" == "prev" ] || [ "$2" == "p" ]; then
if [ "$3" == "mark" ] || [ "$3" == "m" ] || [ "$3" == "unmark" ] || [ "$3" == "u" ]; then
exit 1
fi
clear
echo ""
if [ $POS -gt 1 ]; then
POS=`expr $POS - 1`
fi
elif [ "$2" == "next" ] || [ "$2" == "n" ]; then
if [ "$3" == "mark" ] || [ "$3" == "m" ] || [ "$3" == "unmark" ] || [ "$3" == "u" ]; then
exit 1
fi
clear
echo ""
if [ $POS -ne $LEN ]; then
POS=`expr $POS + 1`
fi
else
clear
echo ""
fi
SET $FILE POS $POS
echo "#($POS/$LEN)"
echo ""
EN=`$DIR/en/list.sh $1 $POS`
CN=`$DIR/cn/list.sh $1 $POS`
else
EN=`$DIR/en/list.sh $1 $2`
CN=`$DIR/cn/list.sh $1 $2`
POS=$2
SET $FILE POS $POS
fi
if [ -z "$3" ] || [ "$3" == "en" ] || [ "$3" == "n" ]; then
echo $EN
elif [ "$3" == "cn" ] || [ "$3" == "c" ]; then
echo $CN
elif [ "$3" == "ec" ]; then
printf "%16s\t\t\t%s\n" "$EN" "$CN"
elif [ "$3" == "ce" ]; then
printf "%16s\t\t\t%s\n" "$CN" "$EN"
fi
if [ -z "$2" ] || [[ "$2" == *[!0-9]* ]]; then
echo ""
else
DIC=`GET $FILE DIC`
POS=$2
if [ "$3" == "mark" ] || [ "$3" == "m" ]; then
if [[ ! $DIC =~ (^| )$POS($| ) ]]; then
if [ -z "$DIC" ]; then
DIC="$POS"
else
DIC="$DIC $POS"
fi
SET $FILE DIC "$DIC"
echo ""
echo "Word Marked"
fi
elif [ "$3" == "unmark" ] || [ "$3" == "u" ]; then
if [[ $DIC =~ (^| )$POS($| ) ]]; then
NEWDIC=""
for pos in $DIC; do
if [ "$pos" != "$POS" ]; then
if [ -z "$NEWDIC" ]; then
NEWDIC="$pos"
else
NEWDIC="$NEWDIC $pos"
fi
fi
done
DIC="$NEWDIC"
SET $FILE DIC "$DIC"
echo ""
echo "Word Unmarked"
else
exit 0
fi
fi
fi
fi