1 #!/bin/bash 2 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 # Color output encodings. 7 COL_RED='\E[31;1m' 8 COL_GREEN='\E[32;1m' 9 COL_YELLOW='\E[33;1m' 10 COL_BLUE='\E[34;1m' 11 COL_STOP='\E[0;m' 12 13 # args: [message] 14 green() { 15 echo -e "${COL_GREEN}$*${COL_STOP}" 16 } 17 18 # args: [message] 19 yellow() { 20 echo -e "${COL_YELLOW}WARNING: $*${COL_STOP}" 21 } 22 23 # args: [message] 24 red() { 25 echo -e "${COL_RED}$*${COL_STOP}" 26 } 27 28 # args: [nested level] [message] 29 error() { 30 local lev=${1:-} 31 case "${1:-}" in 32 [0-9]*) 33 lev=$1 34 shift 35 ;; 36 *) lev=0 37 ;; 38 esac 39 local x=$(caller $lev) 40 local cline="${x%% *}" 41 local cfile="${x#* }" 42 cfile="${cfile##*/}" 43 local args="$*" 44 local spacer="${args:+: }" 45 red "at ${cfile}, line ${cline}${spacer}${args}" 1>&2 46 exit 1 47 } 48