-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.inc
278 lines (253 loc) · 4.71 KB
/
opts.inc
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/bash
# czytam parametry wywolania
SHORTOPTS="i:o:f:c:r:s:b:dkh:w:x:y:g:p:m:"
LONGOPTS="mx:,my:,help,list,status,landscape,reverse,debug,keep,gapx:,gapy:,page:,rotate:,rmup:,rmdown:,rmright:,rmleft:,crop,mask:,"
# Execute getopt on the arguments passed to this program, identified by the special character $@
#PARSED_OPTIONS=$(getopt -n "$0" -o $SHORTOPTS --long "$LONGOPTS" -- "$@")
PARSED_OPTIONS=$(getopt -n "$0" --options $SHORTOPTS --longoptions "$LONGOPTS" -- "$@")
#Bad arguments, something has gone wrong with the getopt command.
if [ $? -ne 0 ];
then
exit 1
fi
# A little magic, necessary when using getopt.
eval set -- "$PARSED_OPTIONS"
while true; do
case $1 in
--help)
usage
exit 0
;;
--list)
list_files
exit 0
;;
--landscape)
ORIENTATION='L'
;;
--reverse)
REVERSE=1
;;
--keep)
KEEP_TEMPORARY=1
;;
--page)
PAGE_SIZE=`tr '[:lower:]' '[:upper:]' <<< ${2}`
;;
--status)
show_overlays
show_scripts
exit 0
;;
-o)
OUTPUT="$2"
shift
;;
-i)
INPUT="$2"
shift
;;
-f)
FRAME="$2"
shift
;;
-c)
COLUMN="$2"
shift
;;
-r)
ROW="$2"
shift
;;
-s)
PROCESSING_SCRIPT="$2"
shift
;;
-b)
BACKGROUND="$2 "
shift
;;
-d|--debug)
DEBUG=1
echo "Writing debug to arrange.log."
rm -f arrange.log
exec 19>arrange.log
export BASH_XTRACEFD=19
set -x
#DEBUG="$2"
#shift
;;
-k)
KEEP_TEMPORARY=1
;;
-h)
HEIGHT="$2"
RESIZE=1
shift
;;
-w)
WIDTH="$2"
RESIZE=1
shift
;;
-p)
RESIZE_PERCENT="$2"
RESIZE=2
shift
;;
-x)
START_X="$2"
shift
;;
-y)
START_Y="$2"
shift
;;
--gapx)
GAPX="$2"
shift
;;
--gapy)
GAPY="$2"
shift
;;
--rmup)
RMUP="$2"
RMIMG=1
shift
;;
--rmdown)
RMDOWN="$2"
RMIMG=1
shift
;;
--rmright)
RMRIGHT="$2"
RMIMG=1
shift
;;
--rmleft)
RMLEFT="$2"
RMIMG=1
shift
;;
--crop)
CROPIMG=1
;;
--mask)
MASK="$2 "
shift
;;
-m)
MARKER="$2"
shift
;;
--mx)
MARKER_X="$2"
MARKER_ENABLED=1
shift
;;
--my)
MARKER_Y="$2"
MARKER_ENABLED=1
shift
;;
--rotate)
ROTATE="$2"
shift
;;
--)
shift
break
;;
*)
shift
break
;;
esac
shift
done
COUNT=$(($ROW * $COLUMN))
# sprawdzam poprawnosc i ew braki w parametrach
if [ "$INPUT" == "" ];
then
echo "Missing parameter -i [filename.txt]"
echo "Currently only files in a current directory are supported"
#usage
echo "Using default file arrange.txt"
INPUT="arrange.txt"
#exit
fi
if [ "$OUTPUT" == "" ];
then
echo "Missing parameter -o [filename.pdf]. Check --help."
#usage
exit
fi
if ([[ $MARKER_X == ?(-)+([0-9]) ]] && [[ $MARKER_Y == ?(-)+([0-9]) ]]);
then
echo -ne ""
else
echo "Both marker values have to be intiger"
exit
fi
if [ "$FRAME" == "" ];
then
echo "Missing parameter -f [filename.png]. Check --help."
#show_overlays
#usage
exit
fi
if [ $COUNT -eq 0 ];
then
echo "Unspecified ROW or/and COLUMN parameter -c [columns], -r [rows]. Check --help."
re='^[0-9]+$'
if ! [[ $ROW =~ $re ]] ; then
echo "error: ROW is not a number"
fi
if ! [[ $COLUMN =~ $re ]] ; then
echo "error: COLUMN is not a number"
fi
#usage
exit
fi
if [ "$PROCESSING_SCRIPT" == "" ];
then
echo "Missing parameter -s [script.sh]. Check --help."
#show_scripts
#usage
echo ''
echo "using \"default.sh\""
PROCESSING_SCRIPT='default.sh'
fi
#if [ "$BACKGROUND" == "" ];
# then
# echo "Missing parameter -b [color]"
# echo "Using default white"
# BACKGROUND="FFFFFF"
#fi
#if [ "$DEBUG" == "1" ];
# then
# echo "Writing debug to arrange.log."
# rm -f arrange.log
# exec 19>arrange.log
# export BASH_XTRACEFD=19
# set -x
#fi
if [ "$KEEP_TEMPORARY" == "" ];
then
#echo "Missing parameter -k [0|1]"
KEEP_TEMPORARY=0
fi
#if [ "$HEIGHT" != "" ];
# then
# RESIZE=1
#fi
#if [ "$WIDTH" != "" ];
# then
# RESIZE=1
#fi
if [ "$GAP" == "" ];
then
GAP=$DEFAULT_GAP
fi