diff --git a/sources/CONTRIBUTION.md b/sources/CONTRIBUTION.md new file mode 100644 index 0000000..329858f --- /dev/null +++ b/sources/CONTRIBUTION.md @@ -0,0 +1,4 @@ +# Contribution Guide + +It is suggested for the new contributors to use the following tools: +- `shfmt -ci -i 4 -ln posix` for shell format with the following parameters. diff --git a/sources/autogen.sh b/sources/autogen.sh index 712e2b0..be56d06 100755 --- a/sources/autogen.sh +++ b/sources/autogen.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # # autogen.sh - Tools for manipulating Jalali representation of Iranian calendar # and necessary conversations to Gregorian calendar. @@ -25,147 +25,160 @@ OPTS="anch" LONG_OPTS="nocolor,clean,help,alternative" # @USAGE -function usage() { - echo -e "Jalali calendar library autogen build script." - echo -e "usage: autogen.sh [-nch]" - echo -e "try \`autogen.sh --help\' for more information." +usage() { + printf "Jalali calendar library autogen build script. +usage: autogen.sh [-nch] +try \`autogen.sh --help\' for more information. +" } # @HELP -function help() { - echo -e "usage: autogen.sh [-nch]..." - echo -ne "Invokes GNU build system tools in order to create" - echo -e " necessary configuration scripts.\n" - echo -e "Operation modes:" - echo -e " -a, --alternative\tdo not invoke autoreconf" - echo -e " -n, --nocolor\t\tdisable output colors" - echo -ne " -c, --clean\t\tremove all auto-generated scripts" - echo -e " and files from source tree" - echo -e " -h, --help\t\tprint this help, then exit\n" - echo -e "Report bugs to ." - echo -e "Jalali calendar home page: ." +help() { + printf "usage: autogen.sh [-nch]... +Invokes GNU build system tools in order to create necessary configuration scripts. + +Operation modes: + -a, --alternative\tdo not invoke autoreconf + -n, --nocolor\t\tdisable output colors + -c, --clean\t\tremove all auto-generated scripts and files from source tree + -h, --help\t\tprint this help, then exit + +Report bugs to . +Jalali calendar home page: . +" } -# echoes ``ok'' if parameter is zero, ''failed'' otherwise. -function printk() { - local STAT=$1 +# prints text in green +print_ok() { + printf "%s%s%s" "$green" "$1" "$zcolor" +} - if [ $1 -eq 0 ]; then - echo -e "${GREEN}ok${RESET}" +# prints text in red +print_fail() { + printf "%s%s%s" "$red" "$1" "$zcolor" +} + +# echoes ``ok'' if parameter is zero, ''failed'' otherwise. +printk() { + if [ "$1" = "0" ]; then + print_ok "ok\n" else - echo -e "${RED}failed${RESET}" + print_fail "failed\n" fi + return "$1" +} + +# prints text in a highlight +print_highlight() { + printf "%s%s%s" "$yellow" "$1" "$zcolor" +} + +# prints the value with a starting green `* `. +print_bullet() { + printf "%s*%s %s" "$green" "$zcolor" "$(print_highlight "$1")" +} - return ${STAT} +# prints a red error and a following value +print_error() { + printf "%serror%s: %s" "$red" "$zcolor" "$(print_highlight "$1")" } # performs make distclean and removes auto-generated files by GNU build system. -function clean() { - local STAT - # files - local FUBARS=( "autom4te.cache" "Makefile.in" "m4" "aclocal.m4" - "configure" "config.sub" "config.guess" "config.log" - "config.status" "depcomp" "install-sh" "libtool" "ltmain.sh" - "missing" "src/Makefile.in" "man/Makefile.in" - "test_kit/jalali/Makefile.in" "test_kit/jalali/Makefile" - "test_kit/Makefile.in" "test_kit/Makefile" - "test_kit/jalali/.deps" "test_kit/jtime/.deps" - "test_kit/jtime/Makefile.in" "test_kit/jalali/Makefile" - "libjalali/Makefile.in" "INSTALL" ) - - echo -e "${GREEN}*${RESET} ${YELLOW}cleaning source tree...${RESET}" +clean() { + print_bullet "cleaning source tree...\n" # Makefile is present. if test -f Makefile; then - echo -ne "${GREEN}* ${RESET}${YELLOW}performing distclean on" - echo -ne " sources if possible...${RESET} " + print_bullet "performing distclean on sources if possible... " make distclean >/dev/null 2>&1 - let STAT=$? - - printk ${STAT} - if [ ${STAT} -ne 0 ]; then - echo -ne "${RED}error${RESET}: cannot perform make distclean." - echo -e " run make distclean manually and check for erros." + stat=$? + printk "$stat" + if [ "$stat" != "0" ]; then + print_error "cannot perform make distclean. run make distclean manually and check for erros.\n" fi fi - for i in ${FUBARS[@]}; do - if [ -f $i ] || [ -d $i ]; then - echo -ne "${GREEN}*${RESET} ${YELLOW}deleting $i...${RESET} " - rm -rf $i + files="autom4te.cache Makefile.in m4 aclocal.m4 configure config.sub + config.guess config.log config.status depcomp install-sh libtool + ltmain.sh missing src/Makefile.in man/Makefile.in + test_kit/jalali/Makefile.in test_kit/jalali/Makefile + test_kit/Makefile.in test_kit/Makefile test_kit/jalali/.deps + test_kit/jtime/.deps test_kit/jtime/Makefile.in test_kit/jalali/Makefile + libjalali/Makefile.in INSTALL" + for i in $files; do + if [ -f "$i" ] || [ -d "$i" ]; then + print_bullet "deleting $i... " + rm -rf "$i" printk 0 fi done - echo -e "${GREEN}* done${RESET}" + print_bullet + print_ok "done\n" } # Setting colors to vt100 standard values, NULL if 0 gets passed to set_color() -function set_colors() { - local HAS_COLOR=$1 - - if [ ${HAS_COLOR} -eq 1 ]; then - RED="\033[1;31m" - GREEN="\033[1;32m" - YELLOW="\033[1;33m" - CYAN="\033[1;36m" - RESET="\033[0m" +set_colors() { + if [ "$1" = "1" ]; then + red="\033[1;31m" + green="\033[1;32m" + yellow="\033[1;33m" + cyan="\033[1;36m" + zcolor="\033[0m" else - RED="" - GREEN="" - YELLOW="" - CYAN="" - RESET="" + red="" + green="" + yellow="" + cyan="" + zcolor="" fi } -# @is_present() $SERVICE $NAME $OUTPUT $EXIT +# @is_present() $service $name $output $exit # Checks whether a service is present on system. -# $SERVICE is the path to service. -# $NAME is the service name. -# $OUTPUT specifies whether is_present() should work silently or not. -# $EXIT specifies whther is_present() should exit on the event of +# $service is the path to service. +# $name is the service name. +# $output specifies whether is_present() should work silently or not. +# $exit specifies whther is_present() should exit on the event of # service not found. -function is_present() { - local SERVICE=$1 - local NAME=$2 - local OUTPUT=$3 - local EXIT=$4 - local PRESENT=0 - - if [ -n "${SERVICE}" ]; then - let PRESENT=1 +is_present() { + service="$1" + name="$2" + output="$3" + exit="$4" + present="0" + + if [ -n "$service" ]; then + present=1 fi - if [ ${OUTPUT} -eq 1 ]; then - echo -ne "${GREEN}*${RESET} checking for ${YELLOW}${NAME}${RESET}... " - if [ ${PRESENT} -eq 1 ]; then - echo -e "${GREEN}yes${RESET}" + if [ "$output" = "1" ]; then + print_bullet "checking for $name... " + if [ "$present" = "1" ]; then + print_ok "yes\n" else - echo -e "${RED}no${RESET}" + print_fail "no\n" fi fi - if [ ${PRESENT} -eq 0 ] && [ ${EXIT} -eq 1 ]; then - echo -ne "${RED}error${RESET}: ${YELLOW}${NAME}${RESET} was not found" - echo -e "on your system. autogen.sh cannot continue." + if [ "$present" = "0" ] && [ "$exit" = "1" ]; then + print_error "$name was not found on your system. autogen.sh cannot continue.\n" exit 1 fi - return ${PRESENT} + return "$present" } # Checking for tools # aclocal, libtoolize, autoconf, automake and autoreconf -function check_services() { - local STAT +check_services() { ACLOCAL="$(which aclocal 2>/dev/null)" is_present "${ACLOCAL}" "aclocal" 1 1 # glibtoolize glue-patch LIBTOOLIZE="$(which glibtoolize 2>/dev/null)" - STAT=$? + stat=$? is_present "${LIBTOOLIZE}" "glibtoolize" 1 0 - if [ ${STAT} -ne 0 ]; then + if [ ${stat} -ne 0 ]; then LIBTOOLIZE="$(which libtoolize 2>/dev/null)" is_present "${LIBTOOLIZE}" "libtoolize" 1 1 fi @@ -175,80 +188,79 @@ function check_services() { is_present "${AUTOMAKE}" "automake" 1 1 AUTORECONF="$(which autoreconf 2>/dev/null)" is_present "${AUTORECONF}" "autoreconf" 1 0 - echo -e "${GREEN}* done${RESET}\n" + + print_bullet + print_ok "done\n" } -# @perform() $SERVICE $NAME $EXIT $PARAMS +# @perform() $service $name $exit $params # runs a service with a set of parameters. -# $SERVICE is the path to the service. -# $NAME is the service name. -# $EXIT specifies whether perform() should exit on the event of +# $service is the path to the service. +# $name is the service name. +# $exit specifies whether perform() should exit on the event of # encoutering any errors or not. -# $PARAMS are the parameters passed to the service. -function perform() { - local SERVICE=$1 - local NAME=$2 - local EXIT=$3 - local PARAMS=$4 - local SSTAT - - echo -ne "${GREEN}*${RESET} running ${YELLOW}${NAME}${RESET} ${CYAN}${PARAMS}${RESET}... " - ${SERVICE} ${PARAMS} >/dev/null 2>&1 - let STAT=$? - - printk ${STAT} - - if [ ${STAT} -ne 0 ]; then - echo -ne "${RED}error${RESET}: cannot run ${YELLOW}${NAME}${RESET}." - echo -e " please run ${NAME} manually and check for errors." +# $params are the parameters passed to the service. +perform() { + service="$1" + name="$2" + exit="$3" + params="$4" + + print_bullet "running \`$name $params\`... " + $service $params >/dev/null 2>&1 + + stat="$?" + printk "$stat" + + if [ "$stat" != "0" ]; then + print_error "cannot run \`$name\`. please run $name manually and check for errors.\n" fi - if [ ${EXIT} -eq 1 ] && [ ${STAT} -ne 0 ]; then + if [ "$exit" = "1" ] && [ "$stat" != "0" ]; then exit 1 fi } # Operation modes. -CLEAN=0 -HELP=0 -COLOR=1 -ALTERN=0 - -which which 1>/dev/null 2>&1 -if [ $? -ne 0 ]; then - echo -e "cannot find \`\`which''. autogen cannot continue." +CLEAN="0" +HELP="0" +COLOR="1" +ALTERN="0" + + +if ! which which 1>/dev/null 2>&1; then + printf "cannot find \`\`which''. autogen cannot continue.\n" exit 1 fi # Parsing command-line arguments -GETOPT=`which getopt 2>/dev/null` -if [ -z ${GETOPT} ]; then - echo -ne "warning: getopt(1) was not found on your system." - echo -e " command line arguments will be ignored." +GETOPT=$(which getopt 2>/dev/null) +if [ -z "$GETOPT" ]; then + printf "warning: getopt(1) was not found on your system. command line arguments will be ignored.\n" else - TEMP=`${GETOPT} -o ${OPTS} -l ${LONG_OPTS} -n 'autogen.sh' -- "$@"` + TEMP=$(${GETOPT} -o ${OPTS} -l ${LONG_OPTS} -n 'autogen.sh' -- "$@") for i in $TEMP; do case $i in - -c|--clean) let CLEAN=1;; - -n|--nocolor) let COLOR=0;; - -h|--help) let HELP=1;; - -a|--alternative) let ALTERN=1;; + -c|--clean) CLEAN=1;; + -n|--nocolor) COLOR=0;; + -h|--help) HELP=1;; + -a|--alternative) ALTERN=1;; esac done fi # Setting colors. -set_colors ${COLOR} +set_colors "$COLOR" # HELP -if [ ${HELP} -eq 1 ]; then +if [ "$HELP" = "1" ]; then help exit 0 fi # CLEAN -if [ ${CLEAN} -eq 1 ]; then +if [ "$CLEAN" = "1" ]; then clean exit 0 fi @@ -257,19 +269,23 @@ fi check_services # alternative method. -if [ -z "${AUTORECONF}" ] || [ ${ALTERN} -eq 1 ]; then - echo -e "using alternative method: ${YELLO}manual${RESET}" +if [ -z "$AUTORECONF" ] || [ "$ALTERN" = "1" ]; then + printf "using alternative method: " + print_highlight "manual\n" + perform "${LIBTOOLIZE}" "libtoolize" "1" "--force --copy --install" perform "${ACLOCAL}" "aclocal" "1" "--force" perform "${AUTOMAKE}" "automake" "1" "--add-missing --force-missing --copy" perform "${AUTOCONF}" "autoconf" "1" "--force" - echo -e "${GREEN}* done${RESET}" # autoreconf method else - echo -e "using prefered method: ${YELLOW}autoreconf${RESET}" + printf "using preferred method: " + print_highlight "autoreconf\n" perform "${LIBTOOLIZE}" "libtoolize" "1" "--force --copy --install" perform "${AUTORECONF}" "autoreconf" "1" "--force --install" - echo -e "${GREEN}* done${RESET}" fi +print_bullet +print_ok "done\n" + exit 0