. "$BST_LIB" require indent indent/present tmp=${TMPDIR:-/tmp}/bst-indent.$$ in="$tmp.c"; gnu="$tmp.gnu.c"; kr="$tmp.kr.c" # one-line input the formatter must restructure printf '%s\n' 'int main(void){int x=1;if(x){return 0;}return 1;}' > "$in" # --version prints the banner then exits nonzero by design ("zero exit values # are returned only when code has been successfully formatted"), so match the # banner without requiring rc 0. v=$(indent --version 2>&1) case "$v" in *"GNU indent"*) bst_ok indent/version ;; *) bst_notok indent/version "unexpected: $v" ;; esac # GNU style (the default): return type on its own line, space before the parens check indent/gnu-run indent "$in" -o "$gnu" check_out indent/gnu-style "main (void)" cat "$gnu" check_out indent/gnu-body "return 0;" cat "$gnu" # K&R style: function name stays on the type line, no space before the parens check indent/kr-run indent -kr "$in" -o "$kr" check_out indent/kr-style "int main(void)" cat "$kr" # idempotence: re-indenting already-formatted output is a no-op (cmp = diffutils) check indent/stable sh -c "indent -st '$gnu' | cmp -s - '$gnu'" rm -f "$in" "$gnu" "$kr" "$in.BAK" "$gnu.BAK" "$kr.BAK"