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 pathshortlist.sh
executable file
·182 lines (179 loc) · 6.24 KB
/
shortlist.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
176
177
178
179
180
181
182
#!/bin/bash
DIR=`dirname $0`
source "$DIR/db/common.sh"
LLIST=$LIST.info
MAKEDIR
if [ ! -z $1 ]; then
# command: clean
if [ "$1" == "reset" ] || [ "$1" == "r" ]; then
rm -rf $DATA
echo ""
echo "All Marks Reset"
echo ""
elif [ "$1" == "length" ] || [ "$1" == "l" ]; then
if [ ! -e $LIST ]; then
echo $LIST
exit 1
fi
LEN=0
LINES="`cat $LIST`"
OLDIFS=$IFS
IFS=$'\n'
for line in $LINES; do
DIC="`echo $line | awk -F '=' '{print $2}'`"
NUM=`echo $DIC | awk -F ' ' '{print NF}'`
LEN=`expr $LEN + $NUM`
done
IFS=$OLDIFS
echo $LEN
elif [ "$1" == "old" ] || [ "$1" == "o" ]; then
if [ ! -e $LIST ]; then
exit 1
fi
OLDIFS=$IFS
IFS=$'\n'
LINES="`cat $LIST`"
for line in $LINES; do
ID=`echo $line | awk -F '=' '{print $1}'`
DIC="`echo $line | awk -F '=' '{print $2}'`"
if [ -z $DIC ]; then
$SHOW $ID
continue
fi
LEN=`$DIR/en/list.sh $ID -10`
pos=0
while [ $pos -lt $LEN ]; do
pos=`expr $pos + 1`
if [[ ! $DIC =~ (^| )$pos($| ) ]]; then
$SHOW $ID $pos ec
fi
done
done
IFS=$OLDIFS
else
if [ ! -e $LIST ]; then
exit 1
fi
OLDIFS=$IFS
IFS=$'\n'
LINES="`cat $LIST`"
if [[ ! "$1" == *[!0-9]* ]]; then
POS=$1
LEN=0
CUR=0
for line in $LINES; do
IFS=$OLDIFS
ID=`echo $line | awk -F '=' '{print $1}'`
DIC="`echo $line | awk -F '=' '{print $2}'`"
if [ ! -z "$DIC" ]; then
NUM=`echo "$DIC" | awk -F ' ' '{print NF}'`
BUND=`expr $CUR + $NUM`
if [ $POS -lt $BUND ] || [ $POS -eq $BUND ]; then
for pos in $DIC; do
CUR=`expr $CUR + 1`
if [ "$CUR" == "$POS" ]; then
LID=$ID
LPOS=$pos
SET $LLIST POS $POS
fi
done
else
CUR=`expr $CUR + $NUM`
fi
else
NUM=0
fi
LEN=`expr $LEN + $NUM`
IFS=$'\n'
done
SET $LLIST LEN $LEN
if [ -z $2 ]; then
$SHOW $LID $LPOS
else
$SHOW $LID $LPOS $2
if [ "$2" == "unmark" ] || [ "$2" == "u" ]; then
$SHOW $LID save
POS=`expr $POS - 1`
SET $LLIST POS $POS
fi
fi
IFS=$OLDIFS
elif [ "$1" == "head" ] || [ "$1" == "h" ]; then
LEN=`$DIR/$0 length`
POS=1
if [ "$2" == "mark" ] || [ "$2" == "m" ] || [ "$2" == "unmark" ] || [ "$2" == "u" ]; then
exit 1
fi
clear
echo "#($POS/$LEN)"
echo ""
$DIR/$0 $POS $2
echo ""
elif [ "$1" == "tail" ] || [ "$1" == "t" ]; then
LEN=`$DIR/$0 length`
POS=$LEN
if [ "$2" == "mark" ] || [ "$2" == "m" ] || [ "$2" == "unmark" ] || [ "$2" == "u" ]; then
exit 1
fi
clear
echo "#($POS/$LEN)"
echo ""
$DIR/$0 $POS $2
echo ""
elif [ "$1" == "next" ] || [ "$1" == "n" ]; then
LEN=`$DIR/$0 length`
POS=$(GET $LLIST POS)
if [ -z "$POS" ]; then
POS=0
fi
if [ $POS -lt $LEN ]; then
POS=`expr $POS + 1`
fi
if [ "$2" == "mark" ] || [ "$2" == "m" ] || [ "$2" == "unmark" ] || [ "$2" == "u" ]; then
exit 1
fi
clear
echo "#($POS/$LEN)"
echo ""
$DIR/$0 $POS $2
echo ""
elif [ "$1" == "prev" ] || [ "$1" == "p" ]; then
LEN=`$DIR/$0 length`
POS=$(GET $LLIST POS)
if [ -z "$POS" ]; then
POS=1
fi
if [ $POS -gt 1 ]; then
POS=`expr $POS - 1`
fi
if [ "$2" == "mark" ] || [ "$2" == "m" ] || [ "$2" == "unmark" ] || [ "$2" == "u" ]; then
exit 1
fi
clear
echo "#($POS/$LEN)"
echo ""
$DIR/$0 $POS $2
echo ""
elif [ "$1" == "unmark" ] || [ "$1" == "u" ]; then
POS=$(GET $LLIST POS)
if [ -z "$POS" ]; then
POS=1
fi
$DIR/$0 $POS unmark
fi
fi
else
OLDIFS=$IFS
IFS=$'\n'
LINES="`cat $LIST`"
for line in $LINES; do
ID=`echo $line | awk -F '=' '{print $1}'`
DIC="`echo $line | awk -F '=' '{print $2}'`"
IFS=$OLDIFS
for pos in $DIC; do
$SHOW $ID $pos ec
done
IFS=$'\n'
done
IFS=$OLDIFS
fi