Skip to Content.
Sympa Menu

sm-commit - [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (3878b12ffb62bac37375e5764e26457e84b45575)

sm-commit AT lists.ibiblio.org

Subject: Source Mage code commit list

List archive

Chronological Thread  
  • From: Justin Boffemmyer <scm AT sourcemage.org>
  • To: sm-commit AT lists.ibiblio.org
  • Subject: [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (3878b12ffb62bac37375e5764e26457e84b45575)
  • Date: Sat, 14 May 2011 20:35:37 -0500

GIT changes to master cauldron by Justin Boffemmyer <flux AT sourcemage.org>:

ward/libruntime | 88 +++++++++
ward/libsource | 545
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ward/libward | 535 +++---------------------------------------------------
3 files changed, 663 insertions(+), 505 deletions(-)

New commits:
commit 3878b12ffb62bac37375e5764e26457e84b45575
Author: Justin Boffemmyer <flux AT sourcemage.org>
Commit: Justin Boffemmyer <flux AT sourcemage.org>

ward: refactor as a more general test harness

Remove Cauldron-specific hardcoding, and make it a more general test
harness. Currently the refactoring only applies to libward.

User-level commands are still Cauldron-specific, but perhaps eventually
libward, libruntime, and libsource (as well as liberror and libcolor)
will be moved out into their own repository if other components also
start making use of them, in which case leaving the user-level commands
as is will be fine since they are in the Cauldron repository.

diff --git a/ward/libruntime b/ward/libruntime
new file mode 100644
index 0000000..8cc225e
--- /dev/null
+++ b/ward/libruntime
@@ -0,0 +1,88 @@
+#!/bin/bash
+#-------------------------------------------------------------------------------
+##
+##=head1 SYNOPSIS
+##
+## Runtime testing harness functionality.
+##
+##=head1 COPYRIGHT
+##
+## Copyright 2010 by the Cauldron Team
+##
+##=head1 FUNCTIONS
+##
+##=over 4
+##
+#-------------------------------------------------------------------------------
+
+function ward_file() {
+ local dir="$1"
+
+ [[ -f "$dir" ]] || return 1
+}
+
+function ward_dir() {
+ local dir="$1"
+
+ [[ -d "$dir" ]] || return 1
+}
+
+function ward_symlink() {
+ local link="$1"
+
+ [[ -h "$link" ]] || return 1
+}
+
+function ward_symlink_file() {
+ local link="$1"
+
+ ward_symlink "$link" || return 1
+
+ ward_file "$link" || return 1
+}
+
+function ward_symlink_dir() {
+ local link="$1"
+
+ ward_symlink "$link" || return 1
+
+ ward_dir "$link" || return 1
+}
+
+#-------------------------------------------------------------------------------
+## @param base path to sys target (optional)
+##
+## Tests for the presence of the usr/src/linux symlink, relative to a base
path.
+## If the base path isn't supplied as the first argument, then it defaults
to /
+## (root).
+##
+#-------------------------------------------------------------------------------
+function ward_kernel_symlink() {
+ local base="$1"
+
+ ward_symlink_dir "$base/usr/src/linux"
+ then
+ libcolor_error "error: kernel symlink not found in "
+ libcolor_file "$base"
+ fi
+}
+
+#-------------------------------------------------------------------------------
+##
+## This software is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This software is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this software; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+#-------------------------------------------------------------------------------
+
+# vim:ai:tw=80:tabstop=2:softtabstop=2:shiftwidth=2:expandtab
diff --git a/ward/libsource b/ward/libsource
new file mode 100644
index 0000000..1fdb618
--- /dev/null
+++ b/ward/libsource
@@ -0,0 +1,545 @@
+#!/bin/bash
+#-------------------------------------------------------------------------------
+##
+##=head1 SYNOPSIS
+##
+## Static analysis testing harness functionality.
+##
+##=head1 COPYRIGHT
+##
+## Copyright 2010 by the Cauldron Team
+##
+##=head1 FUNCTIONS
+##
+##=over 4
+##
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+## @param -p path to sources (optional)
+## @param project (required)
+##
+## Pulls in the definitions of which source files to ward for the given
project.
+## If passed -p as an optional flag, the argument to -p is used as the base
path
+## for pulling in the source file definitons from. This path defaults to
+## WARD_PATH.
+##
+#-------------------------------------------------------------------------------
+function ward_get_sources() {
+ local path="$WARD_PATH"
+ local project=""
+
+ # process any optional parameters
+ while [[ "${1:0:1}" == "-" ]]
+ do
+ case "$1" in
+ "-p")
+ path="${2%/}"
+ shift 2
+ ;;
+ *)
+ libcolor_error "error: invalid function parameter $1"
+ echo ""
+ liberror_die $ERR_FATAL
+ ;;
+ esac
+ done
+
+ # make sure we have a good source file path component
+ if [[ ! -d "$path" ]]
+ then
+ echo "error: source file search path not recognized"
+ liberror_die $ERR_FATAL
+ fi
+
+ project="$1"
+
+ # if file is not given with an absolute path, add the base path prefix
+ [[ "${project:0:1}" != "/" ]] && project="$path/$project"
+
+ # source the list of source files to examine
+ if ! . "$project"
+ then
+ echo "error: could not load $project"
+ exit $ERR_FATAL
+ fi
+}
+
+#-------------------------------------------------------------------------------
+## @param definition file to parse (required)
+##
+## Gets a list of include files sourced by the definition file passed as the
+## first parameter.
+##
+#-------------------------------------------------------------------------------
+function ward_parse_includes() {
+ local include="$1"
+
+ [[ -z "$include" ]] && liberror_die $ERR_FATAL
+
+ # for every line starting with "source" or ".", grab the argument to be
+ # sourced
+ grep '^[[:space:]]*\(source \|\. \)' "${include[@]}" |
+ sed 's/.*\(source\|\.\) //'
+}
+
+#-------------------------------------------------------------------------------
+## @param definition file to parse (required)
+##
+## Implements a recursive descent parser of include files, scanning each
file in
+## turn and building a list of all sourced include files.
+##
+#-------------------------------------------------------------------------------
+function ward_descend_includes() {
+ local defines=( "$1" )
+ local includes=()
+ local file=""
+
+ [[ "${#defines[@]}" -eq 0 ]] && liberror_die $ERR_FATAL
+
+ # seed the includes by doing a single pass
+ eval includes=( "$(ward_parse_includes ${defines[0]})" )
+
+ # if there aren't any further includes, nothing is sourced so we can stop
+ # descending
+ [[ "${#includes[@]}" -eq 0 ]] && return $ERR_OK
+
+ for file in "${includes[@]}"
+ do
+ if ! echo "${defines[@]}" | grep "$file"
+ then
+ eval defines=( "${defines[@]}" "$file" "$(ward_descend_includes
$file)" )
+ fi
+ done
+
+ echo "${defines[@]}"
+}
+
+#-------------------------------------------------------------------------------
+## @param -p base path to sources (optional)
+## @param -d base path to definition file (optional)
+## @param definition file (required)
+## @param source1 [source2 source3...] (required)
+##
+## Tests whether any variables used in source1 (source2, source3, etc.) are
+## defined in the definition file. Any variables that are used but not
defined
+## in the definition file are output via libcolor_warn, preceded by the file
+## they were found in via libcolor_file. Both base paths default to the
current
+## working directory if not supplied.
+##
+#-------------------------------------------------------------------------------
+function ward_global_variables() {
+ local fpath="."
+ local dpath="."
+ local defines=()
+ local inc=""
+ local vars=()
+ local file=""
+
+ # process any optional parameters
+ while [[ "${1:0:1}" == "-" ]]
+ do
+ case "$1" in
+ "-p")
+ fpath="${2%/}"
+ shift 2
+ ;;
+ "-d")
+ dpath="${2%/}"
+ shift 2
+ ;;
+ *)
+ libcolor_error "error: invalid function parameter $1"
+ echo ""
+ liberror_die $ERR_FATAL
+ ;;
+ esac
+ done
+
+ # make sure we have a good source file path component
+ if [[ ! -d "$fpath" ]]
+ then
+ echo "error: source file search path not recognized"
+ liberror_die $ERR_FATAL
+ fi
+
+ # make sure we have a good definition file path component
+ if [[ ! -d "$dpath" ]]
+ then
+ echo "error: variable definition file search path not recognized"
+ liberror_die $ERR_FATAL
+ fi
+
+ # get the defines file, then drop it from the argument list
+ defines=( "$1" )
+ shift
+
+ # if defines is not given with an absolute path, add the base path prefix
+ [[ "${defines:0:1}" != "/" ]] && defines="$dpath/$defines"
+
+ # make sure the defines file exists, otherwise we can't check anything
+ if [[ ! -f "$defines" ]]
+ then
+ echo "error: definition file not found"
+ liberror_die $ERR_FATAL
+ fi
+
+ # recursively descend the definitions files to scan for any files they in
turn
+ # include/source
+ for inc in "${defines[@]}"
+ do
+ #eval defines=( "${defines[@]}" $(ward_descend_includes "$inc") )
+ defines=( "${defines[@]}" $(ward_descend_includes "$inc") )
+ done
+ # pass the data to sort so it can sort and remove duplicates
+ defines=(
+ "$(echo ${defines[@]} | gawk '{for(i=1;i<=NF;i++){print $i}}' | sort -u)"
+ )
+
+ # get a list of all variables defined in the definition file(s)
+ for file in ${defines[@]}
+ do
+ #eval vars=( "${vars[@]}" $(grep '[A-Z][A-Z_]*[0-9]*=' "$file" | cut -d=
-f1) )
+ vars=( "${vars[@]}" $(grep '[A-Z][A-Z_]*[0-9]*=' "$file" | cut -d= -f1) )
+ done
+ # pass the data to sort so it can sort and remove duplicates
+ vars=(
+ "$(echo ${vars[@]} | gawk '{for(i=1;i<=NF;i++){print $i}}' | sort -u)"
+ )
+
+ while [[ $# -gt 0 ]]
+ do
+ file="$1"
+ shift
+
+ # if file is not given with an absolute path, add the base path prefix
+ [[ "${file:0:1}" != "/" ]] && file="$fpath/$file"
+
+ [[ -f "$file" ]] || continue
+
+ # as per the API specification, all global variables are required to be
+ # uppercase, and must begin with a letter, containing only letters,
+ # underscores, and trailing numbers
+ for search in $(grep -o '${\?[A-Z][A-Z_]*[0-9]*' "$file" | sed
's/^\${\?//' | sort -u)
+ do
+ if ! echo "${vars[@]}" | grep -q "$search"
+ then
+ echo "$(libcolor_file $file): $(libcolor_warn $search)"
+ fi
+ done
+ done
+}
+
+#-------------------------------------------------------------------------------
+## @param -p base path to sources (optional)
+## @param error code file (required)
+##
+## Ensures that the error code file itself is properly defined, making sure
that
+## for every error code there is a matching error message, and for every
error
+## message there is a matching error code. The base path defaults to the
current
+## working directory if not supplied.
+##
+#-------------------------------------------------------------------------------
+function ward_error_codes() {
+ local path="."
+ local errorcodes=""
+ local leader=" "
+ local codes=()
+ local msgcode=""
+ local count=""
+ local codes=""
+
+ # process any optional parameters
+ while [[ "${1:0:1}" == "-" ]]
+ do
+ case "$1" in
+ "-p")
+ path="${2%/}"
+ shift 2
+ ;;
+ *)
+ libcolor_error "error: invalid function parameter $1"
+ echo ""
+ liberror_die $ERR_FATAL
+ ;;
+ esac
+ done
+
+ # make sure we have a good errorcodes file path component
+ if [[ ! -d "$path" ]]
+ then
+ echo "error: error code file search path not recognized"
+ liberror_die $ERR_FATAL
+ fi
+
+ errorcodes="$1"
+
+ # if errorcodes is not given with an absolute path, add the base path
prefix
+ [[ "${errorcodes:0:1}" != "/" ]] && errorcodes="$path/$errorcodes"
+
+ # make sure the defines file exists, otherwise we can't check anything
+ if [[ ! -f "$errorcodes" ]]
+ then
+ libcolor_error "error: error code file "
+ libcolor_file "$errorcodes"
+ libcolor_error " not found"
+ echo ""
+ liberror_die $ERR_FATAL
+ fi
+
+ # get the list of defined error codes
+ codes=( $(gawk '/liberror_add_error/ {print $2}' "$errorcodes") )
+
+ # get the list of defined error messages
+ eval msgs=(
+ $(gawk \
+ '/liberror_add_error/ {if($3 == "\\"){getline} sub(/^[^"]*"/,"\"");
print}' \
+ "$errorcodes"
+ )
+ )
+
+ # test if the number of messages matches the number of error codes
+ if [[ "${#codes[@]}" -ne "${#msgs[@]}" ]]
+ then
+ libcolor_error "error: "
+ libcolor_error "number of error codes not equal to number of messages"
+ echo ""
+ libcolor_error "${leader}codes: ${#codes[@]}"
+ echo ""
+ libcolor_error "${leader}messages: ${#msgs[@]}"
+ echo ""
+ fi
+}
+
+#-------------------------------------------------------------------------------
+## @param -p base path to sources (optional)
+## @param -d base path to definition file (optional)
+## @param definition file (required)
+## @param source1 [source2 source3...] (required)
+##
+## Tests whether any error variables used in source1 (source2, source3, etc.)
+## are defined in the errorr definition file. Any error variables that are
used
+## but not defined in the definition file are output via libcolor_warn,
preceded
+## by the file they were found in via libcolor_file. Both base paths default
to
+## the current working directory if not supplied.
+##
+#-------------------------------------------------------------------------------
+function ward_error_variables() {
+ local fpath="."
+ local epath="."
+ local errorcodes=""
+ local file=""
+ local codes=""
+
+ # process any optional parameters
+ while [[ "${1:0:1}" == "-" ]]
+ do
+ case "$1" in
+ "-p")
+ fpath="${2%/}"
+ shift 2
+ ;;
+ "-d")
+ epath="${2%/}"
+ shift 2
+ ;;
+ *)
+ libcolor_error "error: invalid function parameter $1"
+ echo ""
+ liberror_die $ERR_FATAL
+ ;;
+ esac
+ done
+
+ # make sure we have a good source file path component
+ if [[ ! -d "$fpath" ]]
+ then
+ echo "error: source file search path not recognized"
+ liberror_die $ERR_FATAL
+ fi
+
+ # make sure we have a good definition file path component
+ if [[ ! -d "$epath" ]]
+ then
+ echo "error: error code file search path not recognized"
+ liberror_die $ERR_FATAL
+ fi
+
+ # get the defines file, then drop it from the argument list
+ errorcodes="$1"
+ shift
+
+ # if defines is not given with an absolute path, add the base path prefix
+ [[ "${errorcodes:0:1}" != "/" ]] && errorcodes="$epath/$errorcodes"
+
+ # make sure the defines file exists, otherwise we can't check anything
+ if [[ ! -f "$errorcodes" ]]
+ then
+ echo "error: error code file not found"
+ liberror_die $ERR_FATAL
+ fi
+
+ # get the list of defined error codes
+ codes=( $(gawk '/liberror_add_error/ {print $2}' "$errorcodes") )
+
+ while [[ $# -gt 0 ]]
+ do
+ file="$1"
+ shift
+
+ # if file is not given with an absolute path, add the base path prefix
+ [[ "${file:0:1}" != "/" ]] && file="$fpath/$file"
+
+ [[ -f "$file" ]] || continue
+
+ # as per the API specification, all global variables are required to be
+ # uppercase, and must begin with a letter, containing only letters,
+ # underscores, and trailing numbers
+ for search in $(grep -o '${\?[A-Z][A-Z_]*[0-9]*' "$file" | sed
's/^\${\?//' | sort -u)
+ do
+ [[ "$search" == "ERR_OK" || "$search" == "ERR_FATAL" ]] && continue
+
+ if ! echo " ${codes[*]} " | grep -q " $search "
+ then
+ echo "$(libcolor_file $file): $(libcolor_warn $search)"
+ fi
+ done
+ done
+}
+
+#-------------------------------------------------------------------------------
+## @param -p base path to sources (optional)
+## @param -l base path to libraries (optional)
+## @param source1 [source2 source3...] (required)
+##
+## Tests whether any functions used in source1 (source2, source3, etc.) are
+## defined. Any functions that are used but not defined in the corresponding
+## definition file are output via libcolor_warn, preceded by the file they
were
+## found in via libcolor_file. Both base paths default to the current working
+## directory if not supplied.
+##
+#-------------------------------------------------------------------------------
+function ward_functions() {
+ local fpath="."
+ local lpath="."
+ local file=""
+ local prefix=""
+ local list=""
+ local matched=""
+
+ # make sure we have a minimum number of arguments
+ if [[ $# -lt 2 ]]
+ then
+ echo "error: improper number of arguments"
+ liberror_die $ERR_FATAL
+ fi
+
+ # process any optional parameters
+ while [[ "${1:0:1}" == "-" ]]
+ do
+ case "$1" in
+ "-p")
+ fpath="${2%/}"
+ shift 2
+ ;;
+ "-l")
+ lpath="${2%/}"
+ shift 2
+ ;;
+ *)
+ libcolor_error "error: invalid function parameter $1"
+ echo ""
+ liberror_die $ERR_FATAL
+ ;;
+ esac
+ done
+
+ # make sure we have a good source file path component
+ if [[ ! -d "$fpath" ]]
+ then
+ echo "error: source file search path not recognized"
+ liberror_die $ERR_FATAL
+ fi
+
+ # make sure we have a good library path component
+ if [[ ! -d "$lpath" ]]
+ then
+ echo "error: library search path not recognized"
+ liberror_die $ERR_FATAL
+ fi
+
+ while [[ $# -gt 0 ]]
+ do
+ file="$1"
+ shift
+
+ # if file is not given with an absolute path, add the base path prefix
+ [[ "${file:0:1}" != "/" ]] && file="$fpath/$file"
+
+ [[ -f "$file" ]] || continue
+
+ list=($(grep -o "^[ ]*[a-z]\+_[a-z_]\+" "$file" | sed 's/^ *//' | sort
-u))
+ # for each called function, check prefix by prefix
+ for function in "${list[@]}"
+ do
+ # check if the function is defined somewhere in the file it came from
+ grep -q "^function $function() {" "$file" && continue
+
+ # seed the defines variable for the loop below
+ local mangle="$function"
+
+ # check against the prefixes, one at a time
+ while $(echo $mangle | grep -q '^[a-z]\+_[a-z_]\+')
+ do
+ prefix="${mangle%%_*}"
+ [[ "$prefix" == "enchant" ]] && prefix="enchantment"
+
+ # check for the function in a library file matching the prefix
+ if [[ -f "$lpath/lib$prefix" ]]
+ then
+ if grep -q "^function $function() {" "$lpath/lib$prefix"
+ then
+ matched="yes"
+ break
+ fi
+ elif [[ -f "$lpath/lib.$prefix" ]]
+ then
+ if grep -q "^function $function() {" "$lpath/lib.$prefix"
+ then
+ matched="yes"
+ break
+ fi
+ fi
+
+ # no match yet, strip the prefix and repeat
+ mangle="${mangle#*_}"
+ done
+
+ # if the function isn't defined in the corresponding file, warn the
user
+ if [[ -z "$matched" ]]
+ then
+ echo "$(libcolor_file $file): $(libcolor_warn $function)"
+ fi
+ done
+ done
+}
+
+#-------------------------------------------------------------------------------
+##
+## This software is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This software is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this software; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+#-------------------------------------------------------------------------------
+
+# vim:ai:tw=80:tabstop=2:softtabstop=2:shiftwidth=2:expandtab
diff --git a/ward/libward b/ward/libward
index 8b4fe82..a8fd6dd 100644
--- a/ward/libward
+++ b/ward/libward
@@ -19,534 +19,59 @@
# when grepping, sorting, etc.
export LC_COLLATE="C"

+# shorthand and non-hardcoded /dev/null for output dumping
+WARD_NULL="${WARD_NULL:-/dev/null}"
+
# ensure that WARD_PATH has a value
WARD_PATH="${WARD_PATH:-$(dirname $0)}"

-###
-# TODO: these paths should not be hardcoded in the future
-###
-# load liberror (this is not optional)
-if ! . "$WARD_PATH/../lib/liberror"
-then
- echo "error: could not load $WARD_PATH/../lib/liberror"
- exit 1
-fi
-
-# load libcolor (there should be an option for this later)
-if ! . "$WARD_PATH/../lib/libcolor"
-then
- echo "error: could not load $WARD_PATH/../lib/libcolor"
- exit 1
-fi
-
-#-------------------------------------------------------------------------------
-## @param -p path to sources (optional)
-## @param project (required)
-##
-## Pulls in the definitions of which source files to ward for the given
project.
-## If passed -p as an optional flag, the argument to -p is used as the base
path
-## for pulling in the source file definitons from. This path defaults to
-## WARD_PATH.
-##
-#-------------------------------------------------------------------------------
-function ward_get_sources() {
- local path="$WARD_PATH"
- local project=""
-
- # process any optional parameters
- while [[ "${1:0:1}" == "-" ]]
- do
- case "$1" in
- "-p")
- path="${2%/}"
- shift 2
- ;;
- *)
- libcolor_error "error: invalid function parameter $1"
- echo ""
- liberror_die $ERR_FATAL
- ;;
- esac
- done
-
- # make sure we have a good source file path component
- if [[ ! -d "$path" ]]
- then
- echo "error: source file search path not recognized"
- liberror_die $ERR_FATAL
- fi
-
- project="$1"
-
- # if file is not given with an absolute path, add the base path prefix
- [[ "${project:0:1}" != "/" ]] && project="$path/$project"
-
- # source the list of source files to examine
- if ! . "$project"
- then
- echo "error: could not load $project"
- exit $ERR_FATAL
- fi
-}
-
-#-------------------------------------------------------------------------------
-## @param definition file to parse (required)
-##
-## Gets a list of include files sourced by the definition file passed as the
-## first parameter.
-##
-#-------------------------------------------------------------------------------
-function ward_parse_includes() {
- local include="$1"
-
- [[ -z "$include" ]] && liberror_die $ERR_FATAL
-
- # for every line starting with "source" or ".", grab the argument to be
- # sourced
- grep '^[[:space:]]*\(source \|\. \)' "${include[@]}" |
- sed 's/.*\(source\|\.\) //'
-}
-
-#-------------------------------------------------------------------------------
-## @param definition file to parse (required)
-##
-## Implements a recursive descent parser of include files, scanning each
file in
-## turn and building a list of all sourced include files.
-##
-#-------------------------------------------------------------------------------
-function ward_descend_includes() {
- local defines=( "$1" )
- local includes=()
- local file=""
-
- [[ "${#defines[@]}" -eq 0 ]] && liberror_die $ERR_FATAL
-
- # seed the includes by doing a single pass
- eval includes=( "$(ward_parse_includes ${defines[0]})" )
-
- # if there aren't any further includes, nothing is sourced so we can stop
- # descending
- [[ "${#includes[@]}" -eq 0 ]] && return $ERR_OK
-
- for file in "${includes[@]}"
- do
- if ! echo "${defines[@]}" | grep "$file"
- then
- eval defines=( "${defines[@]}" "$file" "$(ward_descend_includes
$file)" )
- fi
- done
-
- echo "${defines[@]}"
-}
+WARD_LIB_PATH="${WARD_LIB_PATH:-$WARD_PATH/../lib}"


#-------------------------------------------------------------------------------
-## @param -p base path to sources (optional)
-## @param -d base path to definition file (optional)
-## @param definition file (required)
-## @param source1 [source2 source3...] (required)
##
-## Tests whether any variables used in source1 (source2, source3, etc.) are
-## defined in the definition file. Any variables that are used but not
defined
-## in the definition file are output via libcolor_warn, preceded by the file
-## they were found in via libcolor_file. Both base paths default to the
current
-## working directory if not supplied.
+## Used only when checking initialization of the library and a fatal error
+## occurs. Afterwards, functions from liberror are used instead.
##

#-------------------------------------------------------------------------------
-function ward_global_variables() {
- local fpath="."
- local dpath="."
- local defines=()
- local inc=""
- local vars=()
- local file=""
-
- # process any optional parameters
- while [[ "${1:0:1}" == "-" ]]
- do
- case "$1" in
- "-p")
- fpath="${2%/}"
- shift 2
- ;;
- "-d")
- dpath="${2%/}"
- shift 2
- ;;
- *)
- libcolor_error "error: invalid function parameter $1"
- echo ""
- liberror_die $ERR_FATAL
- ;;
- esac
- done
-
- # make sure we have a good source file path component
- if [[ ! -d "$fpath" ]]
- then
- echo "error: source file search path not recognized"
- liberror_die $ERR_FATAL
- fi
-
- # make sure we have a good definition file path component
- if [[ ! -d "$dpath" ]]
- then
- echo "error: variable definition file search path not recognized"
- liberror_die $ERR_FATAL
- fi
-
- # get the defines file, then drop it from the argument list
- defines=( "$1" )
- shift
-
- # if defines is not given with an absolute path, add the base path prefix
- [[ "${defines:0:1}" != "/" ]] && defines="$dpath/$defines"
-
- # make sure the defines file exists, otherwise we can't check anything
- if [[ ! -f "$defines" ]]
- then
- echo "error: definition file not found"
- liberror_die $ERR_FATAL
- fi
-
- # recursively descend the definitions files to scan for any files they in
turn
- # include/source
- for inc in "${defines[@]}"
- do
- #eval defines=( "${defines[@]}" $(ward_descend_includes "$inc") )
- defines=( "${defines[@]}" $(ward_descend_includes "$inc") )
- done
- # pass the data to sort so it can sort and remove duplicates
- defines=(
- "$(echo ${defines[@]} | gawk '{for(i=1;i<=NF;i++){print $i}}' | sort -u)"
- )
-
- # get a list of all variables defined in the definition file(s)
- for file in ${defines[@]}
- do
- #eval vars=( "${vars[@]}" $(grep '[A-Z][A-Z_]*[0-9]*=' "$file" | cut -d=
-f1) )
- vars=( "${vars[@]}" $(grep '[A-Z][A-Z_]*[0-9]*=' "$file" | cut -d= -f1) )
- done
- # pass the data to sort so it can sort and remove duplicates
- vars=(
- "$(echo ${vars[@]} | gawk '{for(i=1;i<=NF;i++){print $i}}' | sort -u)"
- )
-
- while [[ $# -gt 0 ]]
- do
- file="$1"
- shift
-
- # if file is not given with an absolute path, add the base path prefix
- [[ "${file:0:1}" != "/" ]] && file="$fpath/$file"
-
- [[ -f "$file" ]] || continue
-
- # as per the API specification, all global variables are required to be
- # uppercase, and must begin with a letter, containing only letters,
- # underscores, and trailing numbers
- for search in $(grep -o '${\?[A-Z][A-Z_]*[0-9]*' "$file" | sed
's/^\${\?//' | sort -u)
- do
- if ! echo "${vars[@]}" | grep -q "$search"
- then
- echo "$(libcolor_file $file): $(libcolor_warn $search)"
- fi
- done
- done
+function ward_fatal_error() {
+ echo "$1"
+ exit 1
}

-#-------------------------------------------------------------------------------
-## @param -p base path to sources (optional)
-## @param error code file (required)
-##
-## Ensures that the error code file itself is properly defined, making sure
that
-## for every error code there is a matching error message, and for every
error
-## message there is a matching error code. The base path defaults to the
current
-## working directory if not supplied.
-##
-#-------------------------------------------------------------------------------
-function ward_error_codes() {
- local path="."
- local errorcodes=""
- local leader=" "
- local codes=()
- local msgcode=""
- local count=""
- local codes=""
-
- # process any optional parameters
- while [[ "${1:0:1}" == "-" ]]
- do
- case "$1" in
- "-p")
- path="${2%/}"
- shift 2
- ;;
- *)
- libcolor_error "error: invalid function parameter $1"
- echo ""
- liberror_die $ERR_FATAL
- ;;
- esac
- done
-
- # make sure we have a good errorcodes file path component
- if [[ ! -d "$path" ]]
- then
- echo "error: error code file search path not recognized"
- liberror_die $ERR_FATAL
- fi
-
- errorcodes="$1"
-
- # if errorcodes is not given with an absolute path, add the base path
prefix
- [[ "${errorcodes:0:1}" != "/" ]] && errorcodes="$path/$errorcodes"
-
- # make sure the defines file exists, otherwise we can't check anything
- if [[ ! -f "$errorcodes" ]]
- then
- libcolor_error "error: error code file "
- libcolor_file "$errorcodes"
- libcolor_error " not found"
- echo ""
- liberror_die $ERR_FATAL
- fi
+# load liberror (this is not optional)
+. "$WARD_LIB_PATH/liberror" 2>"$WARD_NULL" ||
+ ward_fatal_error "error: could not load $WARD_LIB_PATH/liberror"

- # get the list of defined error codes
- codes=( $(gawk '/liberror_add_error/ {print $2}' "$errorcodes") )
+# load libcolor (there should be an option for this later)
+. "$WARD_LIB_PATH/libcolor" 2>"$WARD_NULL" ||
+ ward_fatal_error "error: could not load $WARD_LIB_PATH/libcolor"

- # get the list of defined error messages
- eval msgs=(
- $(gawk \
- '/liberror_add_error/ {if($3 == "\\"){getline} sub(/^[^"]*"/,"\"");
print}' \
- "$errorcodes"
- )
- )
+unset ward_fatal_error

- # test if the number of messages matches the number of error codes
- if [[ "${#codes[@]}" -ne "${#msgs[@]}" ]]
- then
- libcolor_error "error: "
- libcolor_error "number of error codes not equal to number of messages"
- echo ""
- libcolor_error "${leader}codes: ${#codes[@]}"
- echo ""
- libcolor_error "${leader}messages: ${#msgs[@]}"
- echo ""
- fi
-}
+# test/set whether color output should be enabled
+[[ $WARD_COLOR != "yes" ]] && LIBCOLOR_NOCOLOR="yes"


#-------------------------------------------------------------------------------
-## @param -p base path to sources (optional)
-## @param -d base path to definition file (optional)
-## @param definition file (required)
-## @param source1 [source2 source3...] (required)
+## @param library name to load (no path, just basename)
##
-## Tests whether any error variables used in source1 (source2, source3, etc.)
-## are defined in the errorr definition file. Any error variables that are
used
-## but not defined in the definition file are output via libcolor_warn,
preceded
-## by the file they were found in via libcolor_file. Both base paths default
to
-## the current working directory if not supplied.
+## Loads the library given as the first argument. liberror_check_fatal_error
is
+## called to check if there was a problem loading the library, and if there
was
+## it will print a corresponding error message and then exit with the error
+## $ERR_LOAD_LIBRARY.
##

#-------------------------------------------------------------------------------
-function ward_error_variables() {
- local fpath="."
- local epath="."
- local errorcodes=""
- local file=""
- local codes=""
-
- # process any optional parameters
- while [[ "${1:0:1}" == "-" ]]
- do
- case "$1" in
- "-p")
- fpath="${2%/}"
- shift 2
- ;;
- "-d")
- epath="${2%/}"
- shift 2
- ;;
- *)
- libcolor_error "error: invalid function parameter $1"
- echo ""
- liberror_die $ERR_FATAL
- ;;
- esac
- done
-
- # make sure we have a good source file path component
- if [[ ! -d "$fpath" ]]
- then
- echo "error: source file search path not recognized"
- liberror_die $ERR_FATAL
- fi
-
- # make sure we have a good definition file path component
- if [[ ! -d "$epath" ]]
- then
- echo "error: error code file search path not recognized"
- liberror_die $ERR_FATAL
- fi
-
- # get the defines file, then drop it from the argument list
- errorcodes="$1"
- shift
-
- # if defines is not given with an absolute path, add the base path prefix
- [[ "${errorcodes:0:1}" != "/" ]] && errorcodes="$epath/$errorcodes"
+function ward_load_library() {
+ local lib="$1"

- # make sure the defines file exists, otherwise we can't check anything
- if [[ ! -f "$errorcodes" ]]
- then
- echo "error: error code file not found"
- liberror_die $ERR_FATAL
- fi
-
- # get the list of defined error codes
- codes=( $(gawk '/liberror_add_error/ {print $2}' "$errorcodes") )
-
- while [[ $# -gt 0 ]]
- do
- file="$1"
- shift
-
- # if file is not given with an absolute path, add the base path prefix
- [[ "${file:0:1}" != "/" ]] && file="$fpath/$file"
-
- [[ -f "$file" ]] || continue
-
- # as per the API specification, all global variables are required to be
- # uppercase, and must begin with a letter, containing only letters,
- # underscores, and trailing numbers
- for search in $(grep -o '${\?[A-Z][A-Z_]*[0-9]*' "$file" | sed
's/^\${\?//' | sort -u)
- do
- [[ "$search" == "ERR_OK" || "$search" == "ERR_FATAL" ]] && continue
-
- if ! echo " ${codes[*]} " | grep -q " $search "
- then
- echo "$(libcolor_file $file): $(libcolor_warn $search)"
- fi
- done
- done
+ . "$WARD_PATH/$lib" 2>$CAULDRON_NULL
+ liberror_check_fatal_error
}


#-------------------------------------------------------------------------------
-## @param -p base path to sources (optional)
-## @param -l base path to libraries (optional)
-## @param source1 [source2 source3...] (required)
-##
-## Tests whether any functions used in source1 (source2, source3, etc.) are
-## defined. Any functions that are used but not defined in the corresponding
-## definition file are output via libcolor_warn, preceded by the file they
were
-## found in via libcolor_file. Both base paths default to the current working
-## directory if not supplied.
-##
+# ward includes

#-------------------------------------------------------------------------------
-function ward_functions() {
- local fpath="."
- local lpath="."
- local file=""
- local prefix=""
- local list=""
- local matched=""
-
- # make sure we have a minimum number of arguments
- if [[ $# -lt 2 ]]
- then
- echo "error: improper number of arguments"
- liberror_die $ERR_FATAL
- fi
-
- # process any optional parameters
- while [[ "${1:0:1}" == "-" ]]
- do
- case "$1" in
- "-p")
- fpath="${2%/}"
- shift 2
- ;;
- "-l")
- lpath="${2%/}"
- shift 2
- ;;
- *)
- libcolor_error "error: invalid function parameter $1"
- echo ""
- liberror_die $ERR_FATAL
- ;;
- esac
- done
-
- # make sure we have a good source file path component
- if [[ ! -d "$fpath" ]]
- then
- echo "error: source file search path not recognized"
- liberror_die $ERR_FATAL
- fi
-
- # make sure we have a good library path component
- if [[ ! -d "$lpath" ]]
- then
- echo "error: library search path not recognized"
- liberror_die $ERR_FATAL
- fi
-
- while [[ $# -gt 0 ]]
- do
- file="$1"
- shift
-
- # if file is not given with an absolute path, add the base path prefix
- [[ "${file:0:1}" != "/" ]] && file="$fpath/$file"
-
- [[ -f "$file" ]] || continue
-
- list=($(grep -o "^[ ]*[a-z]\+_[a-z_]\+" "$file" | sed 's/^ *//' | sort
-u))
- # for each called function, check prefix by prefix
- for function in "${list[@]}"
- do
- # check if the function is defined somewhere in the file it came from
- grep -q "^function $function() {" "$file" && continue
-
- # seed the defines variable for the loop below
- local mangle="$function"
-
- # check against the prefixes, one at a time
- while $(echo $mangle | grep -q '^[a-z]\+_[a-z_]\+')
- do
- prefix="${mangle%%_*}"
- [[ "$prefix" == "enchant" ]] && prefix="enchantment"
-
- # check for the function in a library file matching the prefix
- if [[ -f "$lpath/lib$prefix" ]]
- then
- if grep -q "^function $function() {" "$lpath/lib$prefix"
- then
- matched="yes"
- break
- fi
- elif [[ -f "$lpath/lib.$prefix" ]]
- then
- if grep -q "^function $function() {" "$lpath/lib.$prefix"
- then
- matched="yes"
- break
- fi
- fi
-
- # no match yet, strip the prefix and repeat
- mangle="${mangle#*_}"
- done
-
- # if the function isn't defined in the corresponding file, warn the
user
- if [[ -z "$matched" ]]
- then
- echo "$(libcolor_file $file): $(libcolor_warn $function)"
- fi
- done
- done
-}
+ward_load_library "libsource"
+ward_load_library "libruntime"


#-------------------------------------------------------------------------------
##



  • [SM-Commit] GIT changes to master cauldron by Justin Boffemmyer (3878b12ffb62bac37375e5764e26457e84b45575), Justin Boffemmyer, 05/14/2011

Archive powered by MHonArc 2.6.24.

Top of Page