<commit_before>#!/bin/sh

show_usage() {
	cat <<EOT
Usage: docker run [--rm] -v /path/to/outdir:/out bakudankun/ricty-generator [OPTIONS]
       docker run [--rm] bakudankun/ricty-generator --tarball [OPTIONS] > Ricty.tar.gz
       docker run [--rm] bakudankun/ricty-generator --zipball [OPTIONS] > Ricty.zip
       docker run [--rm] bakudankun/ricty-generator [ -h | --help ]

Options:

  --discord-opts=opts      Options for ricty_discord_converter.pe (read Ricty's README for detail)
  --generator-opts=opts    Options for ricty_generator.sh (read Ricty's README for detail)
  --tarball                Vomit .tar.gz archive of generated fonts to stdout
  -h, --help               Show usage
  --zipball                Vomit .zip archive of generated fonts to stdout
EOT
}

OPT=`getopt -o "h" -l "tarball,zipball,help,generator-opts:,discord-opts:" -- "$@"`
if [ $? != 0 ]; then show_usage; exit 1; fi

eval set -- "$OPT"

while [ $# -gt 0 ]; do
	case $1 in
		--tarball) tarball=true; shift ;;
		--zipball) zipball=true; shift ;;
		--generator-opts) shift; generator_opts=$1; shift ;;
		--discord-opts) shift; discord_opts=$1; shift ;;
		-h | --help) show_usage; exit 0 ;;
		--) shift; break ;;
		*) show_usage; exit 1 ;;
	esac
done

cd /Ricty-${RICTY_VERSION}

if [ ! -e Ricty-Regular.ttf ]; then
	if [ ! "$tarball" -a ! "$zipball" ]; then
		eval "./ricty_generator.sh $generator_opts auto"
		if [ $? != 0 ]; then
			echo "ricty_generator.sh returned with error. Exiting..." 1>&2
			exit 1
		fi
		if [ ! -e Ricty-Regular.ttf ]; then
			echo 'Failed to generate Ricty. Exiting...' 1>&2
			exit 1
		fi
		if [ "$discord_opts" ]; then
			eval "fontforge ricty_discord_converter.pe $discord_opts Ricty-Regular.ttf Ricty-Bold.ttf"
		fi
		echo 'Now revise fonts for OS/2 (it may takes a little time).'
		./misc/os2version_reviser.sh Ricty*.ttf
		if [ $? = 0 ]; then
			echo 'Complete!'
		else
			echo 'Failed to revise fonts. The output fonts may have wide spaces.'
		fi
	else
		eval "./ricty_generator.sh $generator_opts auto" 1>&2
		if [ $? != 0 ]; then
			echo "ricty_generator.sh returned with error. Exiting..." 1>&2
			exit 1
		fi
		if [ ! -e Ricty-Regular.ttf ]; then
			echo 'Failed to generate Ricty. Exiting...' 1>&2
			exit 1
		fi
		if [ "$discord_opts" ]; then
			eval "fontforge ricty_discord_converter.pe $discord_opts Ricty-Regular.ttf Ricty-Bold.ttf" >/dev/null 2>&1
		fi
		echo 'Now revise fonts for OS/2 (it may takes a little time).' 1>&2
		./misc/os2version_reviser.sh Ricty*.ttf 1>&2
	fi
fi

if [ -e Ricty-Regular.ttf ]; then
	if [ ! "$tarball" -a ! "$zipball" ]; then
		cp -r Ricty*.ttf LICENSE README.md /out
		echo 'Copied font files. Check the output dir.'
	elif [ "$tarball" -o "$zipball" ]; then
		outdir="Ricty-v${RICTY_VERSION}"
		mkdir $outdir
		cp -r Ricty*.ttf LICENSE README.md $outdir
		if [ "$tarball" ]; then
			tar -czf - $outdir
		elif [ "$zipball" ]; then
			zip -qr - $outdir
		fi
	fi
fi<commit_msg>Show discord_converter's output to stderr in tarball/zipball mode<commit_after>#!/bin/sh

show_usage() {
	cat <<EOT
Usage: docker run [--rm] -v /path/to/outdir:/out bakudankun/ricty-generator [OPTIONS]
       docker run [--rm] bakudankun/ricty-generator --tarball [OPTIONS] > Ricty.tar.gz
       docker run [--rm] bakudankun/ricty-generator --zipball [OPTIONS] > Ricty.zip
       docker run [--rm] bakudankun/ricty-generator [ -h | --help ]

Options:

  --discord-opts=opts      Options for ricty_discord_converter.pe (read Ricty's README for detail)
  --generator-opts=opts    Options for ricty_generator.sh (read Ricty's README for detail)
  --tarball                Vomit .tar.gz archive of generated fonts to stdout
  -h, --help               Show usage
  --zipball                Vomit .zip archive of generated fonts to stdout
EOT
}

OPT=`getopt -o "h" -l "tarball,zipball,help,generator-opts:,discord-opts:" -- "$@"`
if [ $? != 0 ]; then show_usage; exit 1; fi

eval set -- "$OPT"

while [ $# -gt 0 ]; do
	case $1 in
		--tarball) tarball=true; shift ;;
		--zipball) zipball=true; shift ;;
		--generator-opts) shift; generator_opts=$1; shift ;;
		--discord-opts) shift; discord_opts=$1; shift ;;
		-h | --help) show_usage; exit 0 ;;
		--) shift; break ;;
		*) show_usage; exit 1 ;;
	esac
done

cd /Ricty-${RICTY_VERSION}

if [ ! -e Ricty-Regular.ttf ]; then
	if [ ! "$tarball" -a ! "$zipball" ]; then
		eval "./ricty_generator.sh $generator_opts auto"
		if [ $? != 0 ]; then
			echo "ricty_generator.sh returned with error. Exiting..." 1>&2
			exit 1
		fi
		if [ ! -e Ricty-Regular.ttf ]; then
			echo 'Failed to generate Ricty. Exiting...' 1>&2
			exit 1
		fi
		if [ "$discord_opts" ]; then
			eval "fontforge ricty_discord_converter.pe $discord_opts Ricty-Regular.ttf Ricty-Bold.ttf"
		fi
		echo 'Now revise fonts for OS/2 (it may takes a little time).'
		./misc/os2version_reviser.sh Ricty*.ttf
		if [ $? = 0 ]; then
			echo 'Complete!'
		else
			echo 'Failed to revise fonts. The output fonts may have wide spaces.'
		fi
	else
		eval "./ricty_generator.sh $generator_opts auto" 1>&2
		if [ $? != 0 ]; then
			echo "ricty_generator.sh returned with error. Exiting..." 1>&2
			exit 1
		fi
		if [ ! -e Ricty-Regular.ttf ]; then
			echo 'Failed to generate Ricty. Exiting...' 1>&2
			exit 1
		fi
		if [ "$discord_opts" ]; then
			eval "fontforge ricty_discord_converter.pe $discord_opts Ricty-Regular.ttf Ricty-Bold.ttf" 1>&2
		fi
		echo 'Now revise fonts for OS/2 (it may takes a little time).' 1>&2
		./misc/os2version_reviser.sh Ricty*.ttf 1>&2
	fi
fi

if [ -e Ricty-Regular.ttf ]; then
	if [ ! "$tarball" -a ! "$zipball" ]; then
		cp -r Ricty*.ttf LICENSE README.md /out
		echo 'Copied font files. Check the output dir.'
	elif [ "$tarball" -o "$zipball" ]; then
		outdir="Ricty-v${RICTY_VERSION}"
		mkdir $outdir
		cp -r Ricty*.ttf LICENSE README.md $outdir
		if [ "$tarball" ]; then
			tar -czf - $outdir
		elif [ "$zipball" ]; then
			zip -qr - $outdir
		fi
	fi
fi
{'fraction_non_alphanumeric': 0.145998984943326, 'fraction_numerical': 0.011842327863305701, 'mean_word_length': 2.853976531942634, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '768309', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2167, 'n_words': 649}