-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
applemcg
committed
Aug 21, 2016
1 parent
ead338d
commit 034882b
Showing
16 changed files
with
770 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# applib all | ||
# These tangles put the three pieces together: | ||
# [[file:~/Dropbox/commonplace/software/applib.org::*applib%20all][applib\ all:1]] | ||
@include appmain.0 | ||
@include applib.1 | ||
@include apptang.0 | ||
app_init 1>&2 | ||
# applib\ all:1 ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
# needed library functions | ||
# [[file:~/Dropbox/commonplace/software/applib.org::*needed%20library%20functions][needed\ library\ functions:1]] | ||
c_fun_extract () | ||
{ | ||
trace_call $*; | ||
declare -f $* | awk '$1 !~ /^:$/' | tr '(){};,/*$' ' ' | tpl | sort -u | grep '^[a-zA-Z0-9_]' | ||
} | ||
cmd () | ||
{ | ||
om_generic cmd $* | ||
} | ||
comment () | ||
{ | ||
echo $* 1>&2 | ||
} | ||
for_nomar () | ||
{ | ||
: continue executing first arg as command,; | ||
: until number of returned arguments is unchanged.; | ||
while true; do | ||
comment NOMAR $# $*; | ||
num=$#; | ||
set $1 $($*); | ||
echo $*; | ||
[[ $num -eq $# ]] && break; | ||
read a; | ||
done | ||
} | ||
foreach () | ||
{ | ||
report_notcommand $1 && return 1; | ||
typeset cmd=$1; | ||
shift; | ||
for arg in "$@"; | ||
do | ||
$cmd $arg; | ||
done | ||
} | ||
fun_extract () | ||
{ | ||
trace_call $*; | ||
c_fun_extract "$@" | ||
} | ||
fun_from () | ||
{ | ||
trace_call $*; | ||
: reconcile patterns to fuse; | ||
cat ${*:--} | awk ' | ||
$2 ~ /^\(\)$/ { print $1 } | ||
/^function / { print $2 } | ||
' | ||
} | ||
fun_uses () | ||
{ | ||
trace_call $*; | ||
foreach type_me $(foreach fun_extract $* | sort -u) | awk ' | ||
|
||
$1 ~ /^function$/ {print $2} | ||
' | ||
} | ||
functions () | ||
{ | ||
trace_call $*; | ||
fun_from $* | printfirst | ||
} | ||
ignore () | ||
{ | ||
$@ > /dev/null | ||
} | ||
isfunction () | ||
{ | ||
trace_call $*; | ||
declare -f $1 > /dev/null | ||
} | ||
myname () | ||
{ | ||
echo ${FUNCNAME[${1:-1}]} | ||
} | ||
needfrom () | ||
{ | ||
: ~ library functions ...; | ||
: now it blythlyt "source"s the library and simply tests; | ||
: for functions existance; | ||
local lib=$(which $1); | ||
shift; | ||
report_notfile $lib && return 1; | ||
trace_call $*; | ||
local fun; | ||
source $lib; | ||
for fun in $*; | ||
do | ||
report_notfunction $fun && return 2; | ||
done | ||
} | ||
printfirst () | ||
{ | ||
trace_call $*; | ||
awk '!printed [$1]++' $* | ||
} | ||
qmoved () | ||
{ | ||
[ "$PWD" == "${1:-$PWD}" ] && return; | ||
echo MOVED to $PWD | ||
} | ||
setenv () | ||
{ | ||
[[ $# -lt 1 ]] && return; | ||
local na=$1; | ||
shift; | ||
eval $na=\"$*\"; | ||
export $na | ||
} | ||
sfg () | ||
{ | ||
trace_call $*; | ||
set | functions | grep -i ${*:-.} | ||
} | ||
source () | ||
{ | ||
set $1 $(basename $1); | ||
set $1 ${2%lib}; | ||
trace_call $*; | ||
isfunction ${2}_init && { | ||
comment SOURCE ${2}lib has been sourced, unset ${2}_init to source; | ||
return | ||
}; | ||
local f; | ||
case $1 in | ||
*/*) | ||
f=$1 | ||
;; | ||
*) | ||
f=$(which $1) | ||
;; | ||
esac; | ||
case $f in | ||
"") | ||
comment NO $1 in PATH; | ||
return | ||
;; | ||
esac; | ||
save_dir=$PWD; | ||
[[ -f $f ]] && command source $f; | ||
: manual PPTLOG:; | ||
date "+%F %a %b %d %T SOURCEd $f from $save_dir $(qmoved $save_dir)" >> ~/lib/source.log | ||
} | ||
tpl () | ||
{ | ||
trace_call $*; | ||
cat ${*:--} | tr -s ' \t' '\n' | ||
} | ||
trace_call () | ||
{ | ||
return | ||
} | ||
trace_stderr () | ||
{ | ||
pa=${FUNCNAME[2]:-COMMANDLINE}; | ||
gr=${FUNCNAME[3]:-COMMANDLINE}; | ||
printf "TRACE %s\t@ %s %d ( %s )\n" "$pa" "$gr" $# "$*" 1>&2 | ||
} | ||
type_me () | ||
{ | ||
printf "%s\t%s\n" $(type -t $1) $1 | ||
} | ||
wpl () | ||
{ | ||
trace_call $*; | ||
cat ${*:--} | tr -cs 'A-Za-z0-9_' '\n' | ||
} | ||
# needed\ library\ functions:1 ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# applib all | ||
# These tangles put the three pieces together: | ||
# [[file:~/Dropbox/commonplace/software/applib.org::*applib%20all][applib\ all:1]] | ||
@include appmain.0 | ||
@include applib.1 | ||
@include apptang.0 | ||
app_init 1>&2 | ||
# applib\ all:1 ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# app_main | ||
# [[file:~/Dropbox/commonplace/software/applib.org::*app_main][app_main:1]] | ||
copyright_app () | ||
{ | ||
comment "Copyright (C) 2005-2016, JYATL - Just Yet Another Testing Lab"; | ||
comment "mailto: mcgowan (at) alum DOT mit DOT edu"; | ||
} | ||
app_fun () | ||
{ | ||
: recursively w/for_nomar and app_uses, find all called functions; | ||
: FIX tracing; | ||
: FIX fuse finding functions behind ":"s.; | ||
set $(for_nomar app_uses $* | tail -1); | ||
shift; | ||
echo $* $(app_trace $*) | wpl | sort -u | ||
} | ||
app_init () | ||
{ | ||
: see if _firsttime should go in om_iam, om_generic; | ||
source auxlib 2> /dev/null; | ||
needfrom fixlib fun_extract; | ||
om_iam; | ||
isfunction app_firsttime && app_firsttime | ||
} | ||
app_trace () | ||
{ | ||
case $* in | ||
*trace_*) | ||
echo trace_on trace_off trace_stderr trace_call | ||
;; | ||
esac | ||
} | ||
app_uses () | ||
{ | ||
: find all used functions w/o smart functions; | ||
: FIX smartf; | ||
: FIX fun_uses, reconcile multiple instances !!!; | ||
trace_call $*; | ||
fun_uses $* | grep -v '^smartf' | ||
} | ||
# app_main:1 ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
@include om.0 | ||
@include report.1 | ||
@include trace.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# om_generic | ||
# This function offers it's users three standard features: | ||
# 1. any function in such a family may be invoked: | ||
# : family subfun arg ... # rather than | ||
# : family_subfun arg ... | ||
# the simple reason being for command line use; the apace bar is much | ||
# more convenient than the underscore. having supplied this gloss, | ||
# it's necessary to point out to use the underscore name when using | ||
# such a function in other functions, simply for name-discovery. | ||
# 1. the default behavior for the head of the /family/, the family-name | ||
# itself, is identical to the the use: | ||
# : family help | ||
# 1. invokes the function: | ||
# : family firsttime | ||
# only the first time the /family/ or one of it's members is called | ||
# thru the family name. This is a way to display a copyright | ||
# notice only once, the default behavior. In this sence, the first | ||
# time means "in the process of the current shell". | ||
# [[file:~/Dropbox/commonplace/software/shreadme.org::*om_generic][om_generic:1]] | ||
copyright_om () | ||
{ | ||
comment "Copyright (C) 2014-2016, JYATL - Just Yet Another Testing Lab"; | ||
comment "mailto: mcgowan (at) alum DOT mit DOT edu"; | ||
} | ||
om_tally () | ||
{ | ||
trace_call $*; | ||
om_list | sort | uniq -c | ||
} | ||
om_help () { echo to see OM functions, om_list; } | ||
om_list () | ||
{ | ||
sfg _ | awk -F_ '{ printf "object\t%s\nmethod\t%s\n", $1, $2 }' | ||
} | ||
om_init () | ||
{ | ||
declare -f om_iam >/dev/null || { comment $(myname) OM_IAM is NOT a function; return 1; } | ||
om_iam | ||
} | ||
om_iam () | ||
{ | ||
: user identifies themself as an OM object; | ||
set $(myname 2); | ||
set ${1%_init}; | ||
report_notcalledby ${1}_init && return 1; | ||
|
||
: create the OM function | ||
eval "$1 () { om_generic $1 \$*; }" | ||
|
||
: every family has a list of members | ||
local l=${1}_list; | ||
declare -f $l > /dev/null 2>&1 || { | ||
eval "$l () { (sfg ^${1}_; sfg _${1}$) 2>/dev/null; }"; | ||
} | ||
: every family may have shell varialbles | ||
local v=${1}_vars; | ||
local V=$(UC $1) | ||
declare -f $v > /dev/null 2>&1 || { | ||
eval "$v () { set | grep ^${V}_ 2>/dev/null; }"; | ||
} | ||
: and a default help function when one doesnt exist | ||
local h=${1}_help; | ||
declare -f $h > /dev/null 2>&1 || { | ||
eval "$h () { echo $1 functions, variables:; ($v; $l) | sed 's/^/ /'; }"; | ||
} | ||
: shows Copyright when library is sourced. | ||
local f=${1}_firsttime; | ||
eval "$f () { copyright_${1}; unset $f; }"; | ||
|
||
: and displays the help | ||
${1}_help | ||
} | ||
om_generic () | ||
{ | ||
: ~ fun { sub arg ... }; | ||
: prefereably executes FUN_SUB arg ...; | ||
: or FUN_HELP; | ||
: ====================================; | ||
local fun=$1; | ||
shift; | ||
: only when a function is first use thru the model; | ||
declare -f ${fun}_firsttime > /dev/null && ${fun}_firsttime; | ||
[[ $# -lt 1 ]] && { | ||
${fun}_help 2> /dev/null; | ||
return | ||
}; | ||
local f=${fun}_$1; | ||
shift; | ||
declare -f $f >/dev/null 2>&1 || { | ||
${fun}_help 2> /dev/null; | ||
return | ||
}; | ||
$f $* | ||
} | ||
# om_generic:1 ends here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# [[file:~/Dropbox/commonplace/software/shreadme.org::*reportlib,%20main][reportlib\,\ main:1]] | ||
copyright_report () | ||
{ | ||
comment "Copyright (C) 2015-2016, JYATL - Just Yet Another Testing Lab"; | ||
comment "mailto: mcgowan (at) alum DOT mit DOT edu"; | ||
} | ||
report_init () | ||
{ | ||
om_iam | ||
} | ||
@include report.1 | ||
report_init 1>&2 | ||
# reportlib\,\ main:1 ends here |
Oops, something went wrong.