]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/bar
.vimrc: Tweak goyo settings
[dotfiles.git] / bin / bar
1 #! /bin/sh
2
3 # bar
4 # 'cat' with ASCII progress bar
5 # (c) Henrik Theiling
6 BAR_VERSION=1.4
7
8 # Synopsis:
9 # 'bar' works just like 'cat', but shows a progress bar in ASCII art on stderr.
10 # The script's main function is meant to be usable in any Bourne shell to be
11 # suitable for install scripts without the need for any additional tool.
12 #
13 # Shell Script Usage: bar [options] [files]
14 # Options:
15 # -h displays help
16 # ...
17 #
18 # Examples:
19 # Normal pipe:
20 #
21 # : bar mypack.tar.bz2 | tar xjpf -
22 #
23 # Individual pipe for each file:
24 #
25 # : bar -c 'tar xjpf -' mypack1.tar.bz2 mypack2.tar.bz2
26 #
27 # Individual pipe, using ${bar_file} variable:
28 #
29 # : bar -c 'echo ${bar_file}: ; gzip -dc | tar tvf -' \
30 # : -e .tar.gz \
31 # : file1 file2 file3 file4 file5 \
32 # : > package-list.txt
33
34 #####################################################
35 # Programs and shell commands:
36 #
37 # Required (otherwise this fails):
38 #
39 # if, then, else, fi, expr, test, cat, eval, exec
40 # shell functions
41 #
42 # test:
43 # a = b
44 # a -lt b
45 # a -gt b
46 # a -le b
47 # -f a
48 # -n a
49 # -z a
50 #
51 # expr:
52 # a + b
53 # a - b
54 # a '*' b
55 # a / b
56 # a : b
57 #
58 # Optional (otherwise this does not show the bar):
59 #
60 # grep, dd, echo, ls, sed, cut
61 #
62 # ls:
63 # must output the file size at fifth position.
64 #
65 # The command line interface also uses:
66 #
67 # awk
68 #
69
70 ####>-SCHNIPP-<########################################################
71 bar_cat()
72 {
73 # Use this shell function in your own install scripts.
74
75 #####################################################
76 # Options:
77
78 # Width of the bar (in ten characters). The default is 76 characters.
79 test -z "${BAR_WIDTH}" && test -n "${COLUMNS}" && BAR_WIDTH=${COLUMNS}
80
81 # Check syntax:
82 ( expr "${BAR_WIDTH}" + 0 >/dev/null 2>&1 ) || BAR_WIDTH=0
83 BAR_WIDTH=`expr ${BAR_WIDTH} + 0` || BAR_WIDTH=0
84 test "x${BAR_WIDTH}" = x0 && BAR_WIDTH=76
85
86 # Maximal block size to use for dd.
87 test -n "${BAR_BS}" || BAR_BS=1048567
88
89 # BEGIN PERC
90 # Whether to show a percentage.
91 test -n "${BAR_PERC}" || BAR_PERC=1
92 # END PERC
93
94 # BEGIN ETA
95 # Whether to show estimated time of arrival (ETA).
96 test -n "${BAR_ETA}" || BAR_ETA=1
97 # END ETA
98
99 # Width of the trace display:
100 # BEGIN TRACE
101 test -n "${BAR_TRACE_WIDTH}" || BAR_TRACE_WIDTH=10
102 # END TRACE
103
104 # The command to execute for every given file. Each file
105 # is piped into this command individually. By default, the
106 # files are simply dumped to stdout.
107 test -n "${BAR_CMD}" || BAR_CMD=cat
108
109 # The characters to be used in the bar
110 test -n "${BAR_L}" || BAR_L='['
111 test -n "${BAR_R}" || BAR_R=']'
112 test -n "${BAR_C0}" || BAR_C0='.'
113 test -n "${BAR_C1}" || BAR_C1='='
114
115 # Additional extension to add to each file:
116 #BAR_EXT=${BAR_EXT-}
117
118 # Whether to clear bar after termination. Otherwise keep the full bar.
119 #BAR_CLEAR=${BAR_CLEAR-0}
120
121 # Unless switched off by user, use the bar by default:
122 test -n "${BAR_OK}" || BAR_OK=1
123
124 #####################################################
125 BAR_WIDTH=`expr ${BAR_WIDTH} - 3`
126
127 bar_trace=''
128 # BEGIN TRACE
129 if test "x${BAR_TRACE}" = x1
130 then
131 BAR_WIDTH=`expr ${BAR_WIDTH} - ${BAR_TRACE_WIDTH}`
132 bar_lauf=${BAR_TRACE_WIDTH}
133 bar_t_space=''
134 bar_t_dot=''
135 while test "${bar_lauf}" -gt 1
136 do
137 bar_t_space="${bar_t_space} "
138 bar_t_dot="${bar_t_dot}."
139 bar_lauf=`expr ${bar_lauf} - 1`
140 done
141 bar_trace="${bar_t_space} "
142 fi
143 # END TRACE
144
145 bar_eta=''
146 BAR_GET_TIME='echo'
147 # BEGIN ETA
148 ( expr 1 + ${SECONDS} >/dev/null 2>&1 ) || BAR_ETA=0
149 if test "x${BAR_ETA}" = x1
150 then
151 BAR_GET_TIME='( echo ${SECONDS} )'
152 BAR_WIDTH=`expr ${BAR_WIDTH} - 6`
153 bar_eta='--:-- '
154 fi
155 # END ETA
156
157 bar_perc=''
158 # BEGIN PERC
159 if test "x${BAR_PERC}" = x1
160 then
161 BAR_WIDTH=`expr ${BAR_WIDTH} - 5`
162 bar_perc=' 0% '
163 fi
164 # END PERC
165
166 BAR_GET_SIZE='( ls -l "${BAR_DIR}${bar_file}${BAR_EXT}" | sed "s@ *@ @g" | cut -d " " -f 5 ) 2>/dev/null'
167 # portable?
168
169 # check features:
170 ( ( echo a ) >/dev/null 2>&1 ) || BAR_OK=0
171 ( ( echo a | dd bs=2 count=2 ) >/dev/null 2>&1 ) || BAR_OK=0
172 ( ( echo a | grep a ) >/dev/null 2>&1 ) || BAR_OK=0
173 ( ( echo a | sed 's@ *@ @g' ) >/dev/null 2>&1 ) || BAR_OK=0
174 ( ( echo a | cut -d ' ' -f 1 ) >/dev/null 2>&1 ) || BAR_OK=0
175
176 # check ranges:
177 test "${BAR_WIDTH}" -ge 4 || BAR_OK=0
178
179 BAR_ECHO='echo'
180 BAR_E_C1=''
181 BAR_E_C2=''
182 BAR_E_NL='echo'
183
184 # Does echo accept -n without signalling an error?
185 if echo -n abc >/dev/null 2>&1
186 then
187 BAR_E_C1='-n'
188 fi
189
190 # Check how to print a line without newline:
191 if ( ( ${BAR_ECHO} "${BAR_E_C1}" abc ; echo 1,2,3 ) | grep n ) >/dev/null 2>&1
192 then
193 # Try echo \c:
194 if ( ( ${BAR_ECHO} 'xyz\c' ; echo 1,2,3 ) | grep c ) >/dev/null 2>&1
195 then
196 # Try printf:
197 if ( ( printf 'ab%s' c ; echo 1,2,3 ) | grep abc ) >/dev/null 2>&1
198 then
199 BAR_ECHO='printf'
200 BAR_E_C1='%s'
201 else
202 BAR_ECHO=':'
203 BAR_E_C1=''
204 BAR_E_NL=':'
205 BAR_OK=0
206 fi
207 else
208 BAR_E_C1=''
209 BAR_E_C2='\c'
210 fi
211 fi
212
213 # prepare initial bar:
214 bar_shown=0
215 if test "${BAR_OK}" = 1
216 then
217 bar_lauf=0
218 bar_graph=''
219 while test `expr ${bar_lauf} + 5` -le "${BAR_WIDTH}"
220 do
221 bar_graph="${bar_graph}${BAR_C0}${BAR_C0}${BAR_C0}${BAR_C0}${BAR_C0}"
222 bar_lauf=`expr ${bar_lauf} + 5`
223 done
224 while test "${bar_lauf}" -lt "${BAR_WIDTH}"
225 do
226 bar_graph="${bar_graph}${BAR_C0}"
227 bar_lauf=`expr ${bar_lauf} + 1`
228 done
229 ${BAR_ECHO} "${BAR_E_C1}" " ${bar_trace}${bar_eta}${bar_perc}${BAR_L}${bar_graph}${BAR_R} ${BAR_E_C2}" 1>&2
230 bar_shown=1
231 fi
232
233 # for shifting large numbers so that expr can handle them:
234 # Assume we can compute up to 2147483647, thus 9 arbitrary digits.
235 # We must be able to do + of two numbers of 9 digits length. Ok.
236 # BEGIN LARGE
237 ( ( test 1999999998 = `expr 999999999 + 999999999` ) >/dev/null 2>&1 ) || BAR_OK=0
238 bar_large_num="........."
239 bar_div=""
240 # END LARGE
241 bar_numsuff=""
242
243 # find size:
244 bar_size=0
245 if test -n "${BAR_SIZE}"
246 then
247 bar_size=${BAR_SIZE}
248 # BEGIN LARGE
249 while expr "${bar_size}" : "${bar_large_num}" >/dev/null 2>&1
250 do
251 bar_div="${bar_div}."
252 bar_numsuff="${bar_numsuff}0"
253 bar_size=`expr "${bar_size}" : '\(.*\).$'`
254 done
255 # END LARGE
256 BAR_GET_SIZE="echo '${BAR_SIZE}'"
257 else
258 for bar_file
259 do
260 bar_size1=0
261 if test -f "${BAR_DIR}${bar_file}${BAR_EXT}"
262 then
263 bar_size1=`eval "${BAR_GET_SIZE}"`
264
265 # BEGIN LARGE
266 # divide and upround by pattern matching:
267 if test -n "${bar_div}"
268 then
269 bar_size1=`expr "${bar_size1}" : '\(.*\)'${bar_div}'$'` || bar_size1=0
270 fi
271
272 # adjust if still too large:
273 while expr "${bar_size1}" : "${bar_large_num}" >/dev/null 2>&1
274 do
275 bar_div="${bar_div}."
276 bar_numsuff="${bar_numsuff}0"
277 bar_size1=`expr "${bar_size1}" : '\(.*\).$'`
278 bar_size=`expr "${bar_size}" : '\(.*\).$'` || bar_size=0
279 done
280
281 # upround if necessary:
282 if test -n "${bar_div}"
283 then
284 bar_size1=`expr "${bar_size1}" + 1`
285 fi
286 # END LARGE
287
288 # add to total size:
289 bar_size=`expr ${bar_size} + ${bar_size1}`
290
291 # BEGIN LARGE
292 # adjust if still too large:
293 while expr "${bar_size}" : "${bar_large_num}" >/dev/null 2>&1
294 do
295 bar_div="${bar_div}."
296 bar_numsuff="${bar_numsuff}0"
297 bar_size=`expr "${bar_size}" : '\(.*\).$'`
298 done
299 # END LARGE
300 else
301 BAR_OK=0
302 fi
303 done
304 fi
305
306 bar_quad=`expr ${BAR_WIDTH} '*' ${BAR_WIDTH}`
307 test "${bar_size}" -gt "${bar_quad}" || BAR_OK=0
308
309 if test "${BAR_OK}" = 0
310 then
311 # For some reason, we cannot display the bar. Thus plain operation:
312 for bar_file
313 do
314 if test "${bar_file}" = "/dev/stdin"
315 then
316 eval "${BAR_CMD}"
317 else
318 eval "${BAR_CMD}" < "${BAR_DIR}${bar_file}${BAR_EXT}"
319 fi
320 done
321 else
322 # Compute wanted bytes per step:
323 bar_want_bps=`expr ${bar_size} + ${BAR_WIDTH}`
324 bar_want_bps=`expr ${bar_want_bps} - 1`
325 bar_want_bps=`expr ${bar_want_bps} / ${BAR_WIDTH}`
326
327 # Compute block count per step to keep within maximum block size:
328 bar_count=1
329 if test "${bar_want_bps}" -gt "${BAR_BS}"
330 then
331 bar_count=`expr ${bar_want_bps} + ${BAR_BS}`
332 bar_count=`expr ${bar_count} - 1`
333 bar_count=`expr ${bar_count} / ${BAR_BS}`
334 fi
335
336 # Compute block size for given count:
337 bar_wc=`expr ${BAR_WIDTH} '*' ${bar_count}`
338
339 bar_bs=`expr ${bar_size} + ${bar_wc}`
340 bar_bs=`expr ${bar_bs} - 1`
341 bar_bs=`expr ${bar_bs} / ${bar_wc}`
342
343 # Compute bs * count, the bytes per step:
344 bar_bps=`expr ${bar_bs} '*' ${bar_count}`
345
346 # Compute bytes per hundredth:
347 bar_bph=`expr ${bar_size} + 99`
348 bar_bph=`expr ${bar_bph} / 100`
349
350
351 # Run loop:
352 bar_pos=0
353 bar_graph="${BAR_L}"
354 bar_cur_char=0
355 bar_t0=`eval "${BAR_GET_TIME}" 2>/dev/null` || bar_t0=0
356 for bar_file
357 do
358 # BEGIN TRACE
359 if test "x${BAR_TRACE}" = x1
360 then
361 bar_trace=`expr "${bar_file}" : '.*/\([^/][^/]*\)$'` || bar_trace="${bar_file}"
362 bar_trace=`expr "${bar_trace}${bar_t_space}" : '\('${bar_t_dot}'\)'`
363 bar_trace="${bar_trace} "
364 fi
365 # END TRACE
366 # Initial character position in bar for file:
367 bar_char=`expr ${bar_pos} / ${bar_want_bps}` || bar_char=0
368 while test "${bar_char}" -gt `expr ${bar_cur_char} + 4`
369 do
370 bar_graph="${bar_graph}${BAR_C1}${BAR_C1}${BAR_C1}${BAR_C1}${BAR_C1}"
371 bar_cur_char=`expr ${bar_cur_char} + 5`
372 done
373 while test "${bar_char}" -gt "${bar_cur_char}"
374 do
375 bar_graph="${bar_graph}${BAR_C1}"
376 bar_cur_char=`expr ${bar_cur_char} + 1`
377 done
378
379 # Get file size. This must work now (we checked with test -f before).
380 bar_size1=`eval "${BAR_GET_SIZE}" 2>/dev/null` || bar_size1=0
381
382 # BEGIN LARGE
383 # Divide and upround by pattern matching:
384 if test -n "${bar_div}"
385 then
386 bar_size1=`expr "${bar_size1}" : '\(.*\)'${bar_div}'$'` || bar_size1=0
387 bar_size1=`expr "${bar_size1}" + 1`
388 fi
389 # END LARGE
390
391 # loop:
392 bar_total=0
393 (
394 exec 6>&1
395 exec 5<"${BAR_DIR}${bar_file}${BAR_EXT}"
396 while test "${bar_total}" -lt "${bar_size1}"
397 do
398 dd bs="${bar_bs}" count="${bar_count}${bar_numsuff}" <&5 >&6 2>/dev/null
399 bar_total=`expr ${bar_total} + ${bar_bps}`
400 if test "${bar_total}" -gt "${bar_size1}"
401 then
402 bar_total="${bar_size1}"
403 fi
404 bar_pos1=`expr ${bar_pos} + ${bar_total}`
405 bar_proz=`expr ${bar_pos1} / ${bar_bph}` || bar_proz=0
406 # BEGIN PERC
407 if test "x${BAR_PERC}" = x1
408 then
409 bar_perc=" ${bar_proz}% "
410 bar_perc=`expr "${bar_perc}" : '.*\(.....\)$'`
411 fi
412 # END PERC
413 # BEGIN ETA
414 if test "x${BAR_ETA}" = x1
415 then
416 bar_diff=`eval "${BAR_GET_TIME}" 2>/dev/null` || bar_diff=0
417 bar_diff=`expr ${bar_diff} - ${bar_t0} 2>/dev/null` || bar_diff=0
418 bar_100p=`expr 100 - ${bar_proz}` || bar_100p=0
419 bar_diff=`expr ${bar_diff} '*' ${bar_100p}` || bar_diff=0
420 bar_diff=`expr ${bar_diff} + ${bar_proz}` || bar_diff=0
421 bar_diff=`expr ${bar_diff} - 1` || bar_diff=0
422 bar_diff=`expr ${bar_diff} / ${bar_proz} 2>/dev/null` || bar_diff=0
423 if test "${bar_diff}" -gt 0
424 then
425 bar_t_unit=":"
426 if test "${bar_diff}" -gt 2700
427 then
428 bar_t_uni="h"
429 bar_diff=`expr ${bar_diff} / 60`
430 fi
431 bar_diff_h=`expr ${bar_diff} / 60` || bar_diff_h=0
432 if test "${bar_diff_h}" -gt 99
433 then
434 bar_eta=" ${bar_diff_h}${bar_t_unit} "
435 else
436 bar_diff_hi=`expr ${bar_diff_h} '*' 60` || bar_diff_hi=0
437 bar_diff=`expr ${bar_diff} - ${bar_diff_hi}` || bar_diff=0
438 bar_diff=`expr "00${bar_diff}" : '.*\(..\)$'`
439 bar_eta=" ${bar_diff_h}${bar_t_unit}${bar_diff} "
440 fi
441 bar_eta=`expr "${bar_eta}" : '.*\(......\)$'`
442 fi
443 fi
444 # END ETA
445
446 bar_char=`expr ${bar_pos1} / ${bar_want_bps}` || bar_char=0
447 while test "${bar_char}" -gt "${bar_cur_char}"
448 do
449 bar_graph="${bar_graph}${BAR_C1}"
450 ${BAR_ECHO} "${BAR_E_C1}" " ${bar_trace}${bar_eta}${bar_perc}${bar_graph}${BAR_E_C2}" 1>&2
451 bar_cur_char=`expr ${bar_cur_char} + 1`
452 done
453 done
454 ) | eval "${BAR_CMD}"
455 bar_pos=`expr ${bar_pos} + ${bar_size1}`
456 done
457 # ${BAR_ECHO} "${BAR_E_C1}" "${BAR_R}${BAR_E_C2}" 1>&2
458 fi
459
460 if test "${bar_shown}" = 1
461 then
462 # BEGIN TRACE
463 test "x${BAR_TRACE}" = x1 && bar_trace="${bar_t_space} "
464 # END TRACE
465 # BEGIN ETA
466 test "x${BAR_ETA}" = x1 && bar_eta=' '
467 # END ETA
468 if test "x${BAR_CLEAR}" = x1
469 then
470 # BEGIN PERC
471 test "x${BAR_PERC}" = x1 && bar_perc=' '
472 # END PERC
473 bar_lauf=0
474 bar_graph=''
475 while test `expr ${bar_lauf} + 5` -le "${BAR_WIDTH}"
476 do
477 bar_graph="${bar_graph} "
478 bar_lauf=`expr ${bar_lauf} + 5`
479 done
480 while test "${bar_lauf}" -lt "${BAR_WIDTH}"
481 do
482 bar_graph="${bar_graph} "
483 bar_lauf=`expr ${bar_lauf} + 1`
484 done
485 ${BAR_ECHO} "${BAR_E_C1}" " ${bar_trace}${bar_eta}${bar_perc} ${bar_graph} ${BAR_E_C2}" 1>&2
486 else
487 # BEGIN PERC
488 test "x${BAR_PERC}" = x1 && bar_perc='100% '
489 # END PERC
490 bar_lauf=0
491 bar_graph=''
492 while test `expr ${bar_lauf} + 5` -le "${BAR_WIDTH}"
493 do
494 bar_graph="${bar_graph}${BAR_C1}${BAR_C1}${BAR_C1}${BAR_C1}${BAR_C1}"
495 bar_lauf=`expr ${bar_lauf} + 5`
496 done
497 while test "${bar_lauf}" -lt "${BAR_WIDTH}"
498 do
499 bar_graph="${bar_graph}${BAR_C1}"
500 bar_lauf=`expr ${bar_lauf} + 1`
501 done
502 ${BAR_ECHO} "${BAR_E_C1}" " ${bar_trace}${bar_eta}${bar_perc}${BAR_L}${bar_graph}${BAR_R}${BAR_E_C2}" 1>&2
503 ${BAR_E_NL} 1>&2
504 fi
505 fi
506 }
507 ####>-SCHNAPP-<########################################################
508
509
510 BAR_AWK_0=''
511 # Command line interface:
512 while test -n "$1"
513 do
514 case "$1" in
515 -o|-c|-w|-0|-1|-e|-d|-b|-s|-\[\]|-\[|-\]|-T)
516 if test -z "$2"
517 then
518 echo "$0: Error: A non-empty argument was expected after $1" 1>&2
519 fi
520 BAR_ARG="$1"
521 BAR_OPT="$2"
522 shift
523 shift
524 ;;
525 -o*|-c*|-w*|-0*|-1*|-e*|-d*|-b*|-T*)
526 BAR_ARG=`expr "$1" : '\(-.\)'`
527 BAR_OPT=`expr "$1" : '-.\(.*\)$'`
528 shift
529 ;;
530 -h|-n|-p|-D|-D-|-q|-V|-t|-E|-L)
531 BAR_ARG="$1"
532 BAR_OPT=""
533 shift
534 ;;
535 --) shift
536 break
537 ;;
538 -*) echo "$0: Error: Unrecognized option: $1" 1>&2
539 exit 1
540 ;;
541 *)
542 break
543 ;;
544 esac
545
546 case "${BAR_ARG}" in
547 -h) echo 'Usage: bar [-n] [-p] [-q] [-o FILE] [-c CMD] [-s SIZE] [-b SIZE]'
548 echo ' [-w WIDTH] [-0/1/[/] CHAR] [-d DIR] [-e EXT] [Files]'
549 echo ' bar -V'
550 echo ' bar -D'
551 echo ' bar -D-'
552 echo 'Options:'
553 echo ' -h displays help'
554 echo ' -o FILE sets output file'
555 echo ' -c CMD sets individual execution command'
556 echo ' -e EXT append an extension to each file'
557 echo ' -d DIR prepend this prefix to each file (a directory must end in /)'
558 echo ' -s SIZE expected number of bytes. Use for pipes. This is a hint'
559 echo ' only that must be greater or equal to the amount actually'
560 echo ' processed. Further, this only works for single files.'
561 echo ' -b SIZE maximal block size (bytes) (default: 1048567)'
562 echo ' -w WIDTH width in characters (default: terminal width-3 or 76)'
563 echo ' -0 CHAR character for empty bar (default: .)'
564 echo ' -1 CHAR character for full bar (default: =)'
565 echo ' -[ CHAR first character of bar (default: [)'
566 echo ' -] CHAR last character of bar (default: ])'
567 echo ' -n clears bar after termination'
568 echo ' -t traces (=displays) which file is processed'
569 echo ' -T WIDTH no of characters reserved for the file display of -t'
570 echo ' -p hides percentage'
571 echo ' -E hides estimated time display'
572 echo ' -q hides the whole bar, be quiet'
573 echo ' -D tries to dump the bar_cat() shell function, then exit.'
574 echo ' Here, -t, -p, -E remove the corresponding feature completely.'
575 echo ' Further, -L removes large file support from the code.'
576 echo ' -D- same as -D, but dumps the function body only'
577 echo ' -V displays version number'
578 echo ' -- end of options: only file names follow'
579 exit 0
580 ;;
581 -n) BAR_CLEAR=1
582 ;;
583 -L) BAR_LARGE=0
584 BAR_AWK_0="${BAR_AWK_0} /END *LARGE/ {x=1} ;"
585 BAR_AWK_0="${BAR_AWK_0} /BEGIN *LARGE/ {x=0} ;"
586 ;;
587 -t) BAR_TRACE=1
588 BAR_AWK_0="${BAR_AWK_0} /END *TRACE/ {x=1} ;"
589 BAR_AWK_0="${BAR_AWK_0} /BEGIN *TRACE/ {x=0} ;"
590 ;;
591 -T) BAR_TRACE_WIDTH="${BAR_OPT}"
592 ;;
593 -q) BAR_OK=0
594 ;;
595 -p) BAR_PERC=0
596 BAR_AWK_0="${BAR_AWK_0} /END *PERC/ {x=1} ;"
597 BAR_AWK_0="${BAR_AWK_0} /BEGIN *PERC/ {x=0} ;"
598 ;;
599 -E) BAR_ETA=0
600 BAR_AWK_0="${BAR_AWK_0} /END *ETA/ {x=1} ;"
601 BAR_AWK_0="${BAR_AWK_0} /BEGIN *ETA/ {x=0} ;"
602 ;;
603 -V) echo "bar v${BAR_VERSION}"
604 exit 0
605 ;;
606 -D) echo "BAR_VERSION=${BAR_VERSION}"
607 awk "${BAR_AWK_0}"'{sub(/ *#.*$/,"")} ; /^bar_cat/ {x=1} ; {sub(/^ */,"")} ; /./ {if(x)print} ; /^}/ {x=0}' "$0"
608 exit 0
609 ;;
610 -D-) echo "BAR_VERSION=${BAR_VERSION}"
611 awk "${BAR_AWK_0}"'{sub(/ *#.*$/,"")} ; /^}/ {x=0} ; {sub(/^ */,"")} ; /./ {if(x)print} ; /^{/ {x=1}' "$0"
612 exit 0
613 ;;
614 -o) exec 1>"${BAR_OPT}"
615 ;;
616 -c) BAR_CMD="${BAR_OPT}"
617 ;;
618 -b) BAR_BS="${BAR_OPT}"
619 if BAR_RAW=`expr "${BAR_BS}" : '\(.*\)k$'`
620 then
621 BAR_BS=`expr ${BAR_RAW} '*' 1024`
622 elif BAR_RAW=`expr "${BAR_BS}" : '\(.*\)M$'`
623 then
624 BAR_BS=`expr ${BAR_RAW} '*' 1048567`
625 fi
626 ;;
627 -s) BAR_SIZE="${BAR_OPT}"
628 if BAR_RAW=`expr "${BAR_SIZE}" : '\(.*\)k$'`
629 then
630 BAR_SIZE=`expr ${BAR_RAW} '*' 1024`
631 elif BAR_RAW=`expr "${BAR_SIZE}" : '\(.*\)M$'`
632 then
633 BAR_SIZE=`expr ${BAR_RAW} '*' 1048567`
634 fi
635 if test "$#" -gt 1
636 then
637 echo "Error: -s cannot be specified for multiple input files." 1>&2
638 exit 1
639 fi
640 ;;
641 -e) BAR_EXT="${BAR_OPT}"
642 ;;
643 -d) BAR_DIR="${BAR_OPT}"
644 ;;
645 -0) BAR_C0="${BAR_OPT}"
646 ;;
647 -1) BAR_C1="${BAR_OPT}"
648 ;;
649 -\[) BAR_L="${BAR_OPT}"
650 ;;
651 -\]) BAR_R="${BAR_OPT}"
652 ;;
653 -\[\])
654 BAR_L="${BAR_OPT}"
655 BAR_R="${BAR_OPT}"
656 ;;
657 -w) BAR_WIDTH="${BAR_OPT}"
658 ;;
659 esac
660 done
661
662 # Invoke main function:
663 if test "$#" = 0
664 then
665 bar_cat /dev/stdin
666 else
667 bar_cat "$@"
668 fi