| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | #!/usr/bin/env bash | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  | # Copyright 2014 Vladimir Ivanov <ivvl82@gmail.com> | 
					
						
							|  |  |  |  | # Distributed under the terms of the GNU General Public License v2 | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | # REPO_DIR="https://github.com/fat0troll/lorchess" | 
					
						
							|  |  |  |  | REPO_DIR=`dirname "$0"` | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | # Specify the tournament here | 
					
						
							|  |  |  |  | TOURNAMENT= | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-20 14:13:14 +04:00
										 |  |  |  | # Version information | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | VERSION="0.5" | 
					
						
							| 
									
										
										
										
											2014-04-20 14:13:14 +04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | argv0=${0##*/} | 
					
						
							| 
									
										
										
										
											2014-04-20 14:13:14 +04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function usage { | 
					
						
							| 
									
										
										
										
											2014-04-20 14:13:14 +04:00
										 |  |  |  |     cat <<EOF | 
					
						
							|  |  |  |  | List games on tours of tournament | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | Usage: $argv0 [options] [tours] | 
					
						
							|  |  |  |  |   Tournament tours are restricted to sequence \`tours' given in | 
					
						
							|  |  |  |  |   Bash-style syntax, i.e., \`tours' may include explicit numbers | 
					
						
							|  |  |  |  |   (tours=1 3), intervals (tours={1..5}), or any combination of them. | 
					
						
							|  |  |  |  |   If no tours are specified, display each tour until an empty | 
					
						
							|  |  |  |  |   \`tour_info' is found. By default, only unaccomplished games are | 
					
						
							|  |  |  |  |   listed. | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-28 13:45:40 +03:00
										 |  |  |  |   Inner variable REPO points to the root of repository; its default | 
					
						
							|  |  |  |  |   value of \`dirname \$0\` can be replaced by a URL link, absolute or | 
					
						
							|  |  |  |  |   relative path. Inner variable TOURNAMENT specifies the sub-directory | 
					
						
							|  |  |  |  |   of tournament. | 
					
						
							| 
									
										
										
										
											2014-04-20 14:13:14 +04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | Options: | 
					
						
							|  |  |  |  |   -a            List accomplished games too | 
					
						
							| 
									
										
										
										
											2014-04-20 19:08:12 +03:00
										 |  |  |  |   -p PLAYER     Show game if PLAYER is a part of a player's name | 
					
						
							| 
									
										
										
										
											2014-04-20 14:13:14 +04:00
										 |  |  |  |   -f FORMAT     Specify the output format; FORMAT is \`term' | 
					
						
							|  |  |  |  |                 (default), \`html', or \`lor' | 
					
						
							|  |  |  |  |   -l            Add the URL link to game (if accomplished) | 
					
						
							|  |  |  |  |   -h            Show this help output | 
					
						
							|  |  |  |  |   -v            Show version information | 
					
						
							|  |  |  |  | EOF | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |     exit "${1:-0}" | 
					
						
							| 
									
										
										
										
											2014-04-20 14:13:14 +04:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function version { | 
					
						
							|  |  |  |  |     exec echo "${argv0}-${VERSION}" | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function setup_repo { | 
					
						
							|  |  |  |  |     CURL_OPTS="-q --fail --location --silent" | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     # If no tournament given, set it to the last one | 
					
						
							|  |  |  |  |     if [[ -z $TOURNAMENT ]]; then | 
					
						
							|  |  |  |  |         if [[ $REPO_DIR =~ ^https://github\.com/(.*) ]]; then | 
					
						
							|  |  |  |  |             REPO_NAME=${BASH_REMATCH[1]} | 
					
						
							|  |  |  |  |             local year=$(curl $CURL_OPTS \ | 
					
						
							|  |  |  |  |                 https://api.github.com/repos/${REPO_NAME}/contents \ | 
					
						
							| 
									
										
										
										
											2014-08-31 23:21:03 +04:00
										 |  |  |  |                 | sed -En "/\"path\":/h;/\"type\": \"dir\"/{g;p;}" \ | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |                 | sed -En "s|.*\"([0-9]{4})\".*|\1|p" | tail -1) | 
					
						
							|  |  |  |  |             TOURNAMENT=$(curl $CURL_OPTS \ | 
					
						
							|  |  |  |  |                 https://api.github.com/repos/${REPO_NAME}/contents/${year} \ | 
					
						
							| 
									
										
										
										
											2014-08-31 23:21:03 +04:00
										 |  |  |  |                 | sed -En "/\"path\":/h;/\"type\": \"dir\"/{g;p;}" \ | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |                 | sed -En "s|.*\"(${year}/[0-9]-.*)\".*|\1|p" | tail -1) | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |             # Convert REPO_DIR to an absolute path | 
					
						
							|  |  |  |  |             [[ $REPO_DIR =~ ^/ ]] || REPO_DIR=$(cd ${REPO_DIR}; pwd) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             local year_dir=$(ls -1 -d ${REPO_DIR}/[0-9][0-9][0-9][0-9]/ | tail -1) | 
					
						
							|  |  |  |  |             TOURNAMENT=$(ls -1 -d ${year_dir}[0-9]-*/ | tail -1 \ | 
					
						
							|  |  |  |  |                 | sed -E "s|${REPO_DIR}/(.*)|\1|") | 
					
						
							|  |  |  |  |             # Remove the trailing slash | 
					
						
							|  |  |  |  |             TOURNAMENT=${TOURNAMENT%/} | 
					
						
							|  |  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function show_tour_sequence { | 
					
						
							|  |  |  |  |     local tour_seq=$@ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     # If no tour sequence given, set it to all tours | 
					
						
							|  |  |  |  |     if [[ -z $tour_seq ]]; then | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |         if [[ $REPO_DIR =~ ^https://github\.com/ ]]; then | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |             tour_seq=$(curl $CURL_OPTS \ | 
					
						
							|  |  |  |  |                 https://api.github.com/repos/${REPO_NAME}/contents/${TOURNAMENT}/tours \ | 
					
						
							| 
									
										
										
										
											2014-08-31 23:21:03 +04:00
										 |  |  |  |                 | sed -En "/\"path\":/h;/\"type\": \"dir\"/{g;p;}" \ | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |                 | sed -En "s|.*\"${TOURNAMENT}/tours/([0-9]{2})\".*|\1|p") | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |             tour_seq=$(ls -1 -d ${REPO_DIR}/${TOURNAMENT}/tours/[0-9][0-9]/ \ | 
					
						
							|  |  |  |  |                 | sed -E "s|${REPO_DIR}/${TOURNAMENT}/tours/([0-9]{2})/|\1|") | 
					
						
							|  |  |  |  |         fi | 
					
						
							|  |  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |     for tour in $tour_seq; do | 
					
						
							|  |  |  |  |         # Change tour numbers: '1' -> '01', '2' -> '02', and so on | 
					
						
							|  |  |  |  |         tour=$(printf "%02g" $tour) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         # *NOTE* The incorporation of a newline at the end of | 
					
						
							|  |  |  |  |         # 'tour_info' is important and allows one to read the last | 
					
						
							|  |  |  |  |         # line with no trailing '\n' | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |         if [[ $REPO_DIR =~ ^https://github\.com/ ]]; then | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |             local tour_info=$(curl $CURL_OPTS --write-out '\n' \ | 
					
						
							|  |  |  |  |                 ${REPO_DIR}/raw/master/${TOURNAMENT}/tours/${tour}/tour_info) | 
					
						
							|  |  |  |  |             [[ -n $tour_info ]] && output_tour_info | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |             local info_file=${REPO_DIR}/${TOURNAMENT}/tours/${tour}/tour_info | 
					
						
							|  |  |  |  |             if [[ -f $info_file ]]; then | 
					
						
							|  |  |  |  |                 local tour_info=$(cat $info_file; echo) | 
					
						
							|  |  |  |  |                 output_tour_info | 
					
						
							|  |  |  |  |             fi | 
					
						
							|  |  |  |  |         fi | 
					
						
							|  |  |  |  |     done | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function output_tour_info { | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |     local date_re="([0-9?]{2})\.([0-9?]{2})\.([0-9?]{4})" | 
					
						
							|  |  |  |  |     local white= black= result= game_date= | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  |     # Lines with game info | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |     local output_lines= | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     while read line; do | 
					
						
							| 
									
										
										
										
											2014-04-30 22:38:43 +03:00
										 |  |  |  |         # Read 'tour_num' | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |         if [[ -z $tour_num ]]; then | 
					
						
							|  |  |  |  |             [[ $line =~ ^"Тур №"([0-9]+) ]] && local tour_num=${BASH_REMATCH[1]} | 
					
						
							|  |  |  |  |             continue | 
					
						
							|  |  |  |  |         fi | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-30 22:38:43 +03:00
										 |  |  |  |         # Read 'date_beg' and 'date_end' | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |         if [[ -z $date_beg || -z $date_end ]]; then | 
					
						
							|  |  |  |  |             if [[ $line =~ ^"Время проведения:"\ +$date_re\ +-\ +$date_re ]]; then | 
					
						
							|  |  |  |  |                 # Use short dates | 
					
						
							|  |  |  |  |                 local date_beg=${BASH_REMATCH[1]}.${BASH_REMATCH[2]} | 
					
						
							|  |  |  |  |                 local date_end=${BASH_REMATCH[4]}.${BASH_REMATCH[5]} | 
					
						
							|  |  |  |  |             fi | 
					
						
							|  |  |  |  |             continue | 
					
						
							|  |  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         # Keep game info if needed, and store it in variables 'white', | 
					
						
							|  |  |  |  |         # 'black', 'result', and 'game_date' | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |         if keep_game_info; then | 
					
						
							|  |  |  |  |             output_lines+=$(sed -E "s/^$date_re\ +//" <<< "$line") | 
					
						
							|  |  |  |  |             # Append the link of game to the end of output line | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  |             if $SHOW_LINK; then | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |                 [[ -n $result ]] && append_game_url | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  |             fi | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |             output_lines+="\n" | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2014-04-30 00:31:28 +03:00
										 |  |  |  |     done <<< "$tour_info" | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |     [[ -n $output_lines ]] && eval "info_output_$FORMAT \"${output_lines}\"" | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function keep_game_info { | 
					
						
							|  |  |  |  |     local res_re="(1|1/2|0)-(1|1/2|0)" | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |     local keep=1 | 
					
						
							| 
									
										
										
										
											2013-10-20 12:28:50 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |     if [[ $line =~ ^$date_re\ +([^\ ]+)\ +-\ +([^\ ]+)(\ +$res_re)? ]]; then | 
					
						
							|  |  |  |  |         white=${BASH_REMATCH[4]} black=${BASH_REMATCH[5]} result=${BASH_REMATCH[6]// /} | 
					
						
							|  |  |  |  |         game_date=${BASH_REMATCH[3]}-${BASH_REMATCH[2]}-${BASH_REMATCH[1]} | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-20 19:08:12 +03:00
										 |  |  |  |         # If the player was passed as an argument, check if it is his game or not | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |         if [[ -z $PLAYER || $white =~ $PLAYER || $black =~ $PLAYER ]]; then | 
					
						
							| 
									
										
										
										
											2014-04-20 19:08:12 +03:00
										 |  |  |  |             if $SHOW_ALL; then | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |                 keep=0 | 
					
						
							| 
									
										
										
										
											2014-04-20 19:08:12 +03:00
										 |  |  |  |             else | 
					
						
							|  |  |  |  |                 # Keep line if the game is not finished | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |                 [[ -z $result ]] && keep=0 | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |             fi | 
					
						
							|  |  |  |  |         fi | 
					
						
							|  |  |  |  |     fi | 
					
						
							| 
									
										
										
										
											2013-10-20 12:28:50 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |     return $keep | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-10-20 12:28:50 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  | function append_game_url { | 
					
						
							| 
									
										
										
										
											2014-04-30 22:38:43 +03:00
										 |  |  |  |     local tour=$(printf "%02g" "$tour_num") | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |     local game_dir=${game_date}-${white}-vs-${black} | 
					
						
							| 
									
										
										
										
											2014-03-27 20:54:45 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |     if [[ $REPO_DIR =~ ^https://github\.com/ ]]; then | 
					
						
							|  |  |  |  |         local pgn_text=$(curl $CURL_OPTS \ | 
					
						
							|  |  |  |  |             ${REPO_DIR}/raw/master/${TOURNAMENT}/tours/${tour}/${game_dir}/1.pgn) | 
					
						
							|  |  |  |  |     else | 
					
						
							|  |  |  |  |         local pgn_text=$(cat ${REPO_DIR}/${TOURNAMENT}/tours/${tour}/${game_dir}/1.pgn) | 
					
						
							|  |  |  |  |     fi | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     local game_url=$(echo "$pgn_text" | grep -Eo "\[Site \"[a-z]+:[^\"]+\"\]" \ | 
					
						
							|  |  |  |  |         | sed -E "s/\[Site \"([a-z]+:[^\"]+)\"\]/\1/") | 
					
						
							|  |  |  |  |     output_lines+=" $game_url" | 
					
						
							| 
									
										
										
										
											2014-03-27 20:54:45 +02:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function info_output_term { | 
					
						
							| 
									
										
										
										
											2014-03-27 13:26:01 +02:00
										 |  |  |  |     echo -n "$(tput setaf 2)${tour_num} тур " | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |     echo "$(tput setaf 6)(${date_beg} - ${date_end})$(tput sgr0)" | 
					
						
							| 
									
										
										
										
											2013-10-20 12:28:50 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-27 13:26:01 +02:00
										 |  |  |  |     echo -en "$1" | column -t | while IFS= read line; do | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |         # Highlight player's name | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |         if [[ -n $PLAYER ]]; then | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |             players=$(grep -o "[^ ]*${PLAYER}[^ ]*" <<< "$line") | 
					
						
							|  |  |  |  |             for name in $players; do | 
					
						
							| 
									
										
										
										
											2014-04-23 00:33:13 +03:00
										 |  |  |  |                 # PLAYER is a part of 'game_url' or 'result' | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |                 [[ $name =~ ^http:// || $name =~ ^(1-0|1/2-1/2|0-1|)$ ]] && continue | 
					
						
							| 
									
										
										
										
											2014-04-23 00:33:13 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-27 19:34:14 +04:00
										 |  |  |  |                 line=$(sed -E "s/(${name})/$(tput setaf 1)\1$(tput sgr0)/g" <<< "$line") | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |             done | 
					
						
							|  |  |  |  |         fi | 
					
						
							| 
									
										
										
										
											2013-10-20 12:28:50 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |         # Highlight result | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |         line=$(sed -E "s/ (1-0|1\/2-1\/2|0-1)( |$)/ $(tput setaf 6)\1$(tput sgr0)\2/g" <<< "$line") | 
					
						
							| 
									
										
										
										
											2013-10-20 12:28:50 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |         echo "$line" | 
					
						
							|  |  |  |  |     done | 
					
						
							| 
									
										
										
										
											2013-10-20 12:28:50 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |     echo | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-10-20 12:28:50 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function info_output_lor { | 
					
						
							| 
									
										
										
										
											2014-03-27 16:21:15 +02:00
										 |  |  |  |     echo "[b]${tour_num} тур (${date_beg} - ${date_end})[/b]" | 
					
						
							| 
									
										
										
										
											2014-03-27 13:26:01 +02:00
										 |  |  |  |     echo "[list]" | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |     echo -en "$1" | while read white hyphen black result url; do | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |         [[ -n $url ]] && result="[url=${url}]${result}[/url]" | 
					
						
							| 
									
										
										
										
											2014-03-27 16:21:15 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-20 22:11:22 +04:00
										 |  |  |  |         echo "  [*] [user]${white}[/user] - [user]${black}[/user] ${result}" | 
					
						
							| 
									
										
										
										
											2014-03-27 13:26:01 +02:00
										 |  |  |  |     done | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     echo "[/list]" | 
					
						
							|  |  |  |  |     echo | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function info_output_html { | 
					
						
							| 
									
										
										
										
											2014-03-27 17:31:56 +02:00
										 |  |  |  |     echo "<div class=\"tour-info\">" | 
					
						
							| 
									
										
										
										
											2014-03-27 21:52:49 +02:00
										 |  |  |  |     echo "  <table class=\"table table-condensed\">" | 
					
						
							| 
									
										
										
										
											2014-03-27 17:31:56 +02:00
										 |  |  |  |     echo "    <caption>" | 
					
						
							|  |  |  |  |     echo "      <strong>${tour_num} тур (${date_beg} - ${date_end})</strong>" | 
					
						
							|  |  |  |  |     echo "    </caption>" | 
					
						
							|  |  |  |  |     echo "    <tbody>" | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-02 20:40:08 +04:00
										 |  |  |  |     echo -en "$1" | while read white hyphen black result url; do | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |         [[ -n $url ]] && result="<a href=\"${url}\">${result}</a>" | 
					
						
							| 
									
										
										
										
											2014-03-27 20:54:45 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-27 17:31:56 +02:00
										 |  |  |  |         echo "      <tr>" | 
					
						
							| 
									
										
										
										
											2014-03-27 17:59:37 +02:00
										 |  |  |  |         echo "        <td>${white} - ${black}</td><td class=\"result\">${result}</td>" | 
					
						
							| 
									
										
										
										
											2014-03-27 17:31:56 +02:00
										 |  |  |  |         echo "      </tr>" | 
					
						
							|  |  |  |  |     done | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     echo "    </tbody>" | 
					
						
							|  |  |  |  |     echo "  </table>" | 
					
						
							|  |  |  |  |     echo "</div>" | 
					
						
							|  |  |  |  |     echo | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | function die { | 
					
						
							|  |  |  |  |     echo "$@" 1>&2 | 
					
						
							|  |  |  |  |     exit 1 | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | function checkargs { | 
					
						
							|  |  |  |  |     [[ $OPTARG =~ ^-[apflhv]$ ]] && die "Option -${opt}: argument not found" | 
					
						
							|  |  |  |  |     [[ $opt == f && ! $OPTARG =~ ^(term|html|lor)$ ]] && die "Incorrect FORMAT specified" | 
					
						
							| 
									
										
										
										
											2014-04-20 14:42:19 +04:00
										 |  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-10-20 12:28:50 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  | FORMAT=term | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | SHOW_ALL=false | 
					
						
							| 
									
										
										
										
											2014-03-27 20:54:45 +02:00
										 |  |  |  | SHOW_LINK=false | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | while getopts ap:f:lhv opt; do | 
					
						
							|  |  |  |  |     case $opt in | 
					
						
							| 
									
										
										
										
											2014-04-20 14:42:19 +04:00
										 |  |  |  |         a)  SHOW_ALL=true | 
					
						
							|  |  |  |  |             ;; | 
					
						
							|  |  |  |  |         p)  checkargs | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |             PLAYER=$OPTARG | 
					
						
							| 
									
										
										
										
											2014-04-20 14:42:19 +04:00
										 |  |  |  |             ;; | 
					
						
							|  |  |  |  |         f)  checkargs | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |             FORMAT=$OPTARG | 
					
						
							| 
									
										
										
										
											2014-04-20 14:42:19 +04:00
										 |  |  |  |             ;; | 
					
						
							|  |  |  |  |         l)  SHOW_LINK=true | 
					
						
							|  |  |  |  |             ;; | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |         h)  usage | 
					
						
							|  |  |  |  |             ;; | 
					
						
							|  |  |  |  |         v)  version | 
					
						
							| 
									
										
										
										
											2014-04-20 14:42:19 +04:00
										 |  |  |  |             ;; | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  |         *)  usage 1 | 
					
						
							| 
									
										
										
										
											2014-04-20 14:42:19 +04:00
										 |  |  |  |             ;; | 
					
						
							| 
									
										
										
										
											2014-03-27 09:52:44 +02:00
										 |  |  |  |     esac | 
					
						
							| 
									
										
										
										
											2013-09-21 02:20:19 +03:00
										 |  |  |  | done | 
					
						
							| 
									
										
										
										
											2013-09-25 23:11:13 +03:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-20 14:42:19 +04:00
										 |  |  |  | shift $(($OPTIND - 1)) | 
					
						
							| 
									
										
										
										
											2014-08-31 21:08:09 +04:00
										 |  |  |  | setup_repo | 
					
						
							|  |  |  |  | show_tour_sequence $@ | 
					
						
							| 
									
										
										
										
											2014-04-20 14:42:19 +04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 23:11:13 +03:00
										 |  |  |  | exit 0 |