| 
									
										
										
										
											2009-01-03 22:59:27 +00:00
										 |  |  |  | # leaptable-compiler/scripts/functions.sh | 
					
						
							|  |  |  |  | # | 
					
						
							| 
									
										
										
										
											2012-01-07 17:39:43 +00:00
										 |  |  |  | #  Copyright: ©2009–2012, Laurence Withers | 
					
						
							|  |  |  |  | #  Author: Laurence Withers, <l@lwithers.me.uk> | 
					
						
							|  |  |  |  | #  License: GPLv3 | 
					
						
							| 
									
										
										
										
											2009-01-03 22:59:27 +00:00
										 |  |  |  | # | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | # Common functions | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | # Print a success message | 
					
						
							|  |  |  |  | print_success() { | 
					
						
							|  |  |  |  |     if [ -z "${TERM}" -o "${TERM}" == "dumb" ] | 
					
						
							|  |  |  |  |     then | 
					
						
							|  |  |  |  |         echo -n " - " | 
					
						
							|  |  |  |  |     else | 
					
						
							|  |  |  |  |         (echo -n -e " \E[32m* "; tput sgr0) | 
					
						
							|  |  |  |  |     fi | 
					
						
							|  |  |  |  |     echo $* | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | # Print a failure message | 
					
						
							|  |  |  |  | print_failure() { | 
					
						
							|  |  |  |  |     if [ -z "${TERM}" -o "${TERM}" == "dumb" ] | 
					
						
							|  |  |  |  |     then | 
					
						
							|  |  |  |  |         echo -n " *** " | 
					
						
							|  |  |  |  |     else | 
					
						
							|  |  |  |  |         (echo -n -e " \E[31m*** "; tput sgr0) | 
					
						
							|  |  |  |  |     fi | 
					
						
							|  |  |  |  |     echo $* | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | # This function carries out a command, but reports its failure if | 
					
						
							|  |  |  |  | # necessary. | 
					
						
							|  |  |  |  | do_cmd() { | 
					
						
							|  |  |  |  |     [ "${VERBOSE}" != "0" ] && echo "$@" | 
					
						
							|  |  |  |  |     "$@" | 
					
						
							|  |  |  |  |     if [ $? -ne 0 ] | 
					
						
							|  |  |  |  |     then | 
					
						
							|  |  |  |  |         print_failure "'$@' failed." | 
					
						
							|  |  |  |  |         return 1 | 
					
						
							|  |  |  |  |     fi | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | # This function carries out a command, but reports its failure if | 
					
						
							|  |  |  |  | # necessary. | 
					
						
							|  |  |  |  | do_cmd_redir() { | 
					
						
							|  |  |  |  |     DEST=$1 | 
					
						
							|  |  |  |  |     shift | 
					
						
							|  |  |  |  |     [ "${VERBOSE}" != "0" ] && echo "$@ >> ${DEST}" | 
					
						
							|  |  |  |  |     "$@" >> ${DEST} | 
					
						
							|  |  |  |  |     if [ $? -ne 0 ] | 
					
						
							|  |  |  |  |     then | 
					
						
							|  |  |  |  |         print_failure "'$@' failed." | 
					
						
							|  |  |  |  |         return 1 | 
					
						
							|  |  |  |  |     fi | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | # vim: expandtab:ts=4:sw=4 |