Directory Function Grep

Table of Contents

1 Abstract

The dfg function and its companion dfg_all return an 4.1 table format of grep results of an argument, defaulting to dfg itself; the grep is performed on the functions of known functions libraries. The table has fields: libname fun context.

The functions dfg{,_all} are distinguished by the later returning results from the retiredlib. The retiredlib contains 600 - 700 functions no longer needed by current function usage.

2 Examples

2.1 default dfg

$ dfg     # returns its default, itself

as here, where justify aligns the columns:


$ dfg | justify

libname    	fun          	context
-------    	---          	-------
functionlib	context_nonsh	dfg . | row 'context ~ /^: /' | column | mytable
functionlib	dated_ornot  	: identify dated or not functions from DFG;
functionlib	dated_ornot  	shd_latest $(dfg $1 | _rquery context ${2:-$1} |
functionlib	dfg          	dfg ()
functionlib	dfg          	dfg_all "${1:-dfg}" | row 'libname !~ /retired/'
functionlib	dfg_all      	dfg_all ()
functionlib	dfg_all      	: related: f2file dfg .;
functionlib	dfg_all      	function dfg_fields ()
functionlib	dfg_all      	function _dfg ()
functionlib	dfg_all      	dfg_fields rdb_hdr;
functionlib	dfg_all      	_dfg "${1:-dfg}" | column;
functionlib	dfg_all      	unset _dfg
functionlib	dfg_fields   	dfg_fields ()
functionlib	dfg_fun      	dfg_fun ()
functionlib	dfg_fun      	dfg $1 | sorttable fun
functionlib	dfg_functions	dfg_functions ()
functionlib	dfg_functions	: list the functions matching a DFG;
functionlib	dfg_help     	dfg_help ()
functionlib	dfg_help     	dfg | justify
functionlib	obsolescent  	dfg obsolescent | row 'libname !~ /retired/' | mytable
functionlib	smart_funs   	dfg . | row 'context ~ /^\${[12*@]:-/' | column | mytable
functionlib	tablemine    	cat $(dfg mytable | mytable) | tiddlylink libname fun | threeColumnTiddly | show_tmpclip
functionlib	tag_context  	dfg "$1:" | compute "
functionlib	whf_all      	: related: dfg;

2.2 sample query

Here's a sample query which returns the first entry from each library. A little ahead of ourselevs, but tag_context function performs a query on the function's 4.2s


$ tag_context related | select_first libname | justify

libname    	fun           	related
-------    	---           	-------
functionlib	dfg_all       	f2file dfg
gitlib     	field_tolc    	rdb
mitlib     	status_filter 	mytable
shdlib     	fun_collection	f2file shd_tagcolumn lib_{changed,process
utillib    	table_me      	mytable

3 Implementation

3.1 Code

dfg () 
{ 
    : without retired lib;
    : date: 2020-12-10;
    dfg_all "${1:-dfg}" | row 'libname !~ /retired/'
}
dfg_all () 
{ 
    : Directory Function Grep;
    : related: f2file dfg .;
    : date: 2020-10-03;
    : date: 2020-12-06;
    : date: 2021-03-06 default is now UNRETIRED;
    runfrom $(fun_db) $@ 2> /dev/null || return;
    : only files -- functions -- in library directories;
    rm -fr $(find */* -type d);
    function dfg_fields () 
    { 
        ${*:-echo} libname fun context
    };
    function _dfg () 
    { 
        dfg_fields rdb_hdr;
        read_devtty $*;
        grep -i "$1" */* | sed 's/\//   /; s/: */       /'
    };
    _dfg "${1:-dfg}" | column;
    unset _dfg
}
f2file () 
{ 
    : copy library Functions inTO separate FILEs,;
    : in directory named for the library;
    : todo: keep an existing functionfile in a backup directory;
    : ... moving them up over an unchanged file of the same name;
    : ... thus retaining last modification time of the function!;
    : date: 2017-07-10;
    : date: 2020-02-04 save DIRECTORY in home/lib;
    if_missingargs 1 $* && return 1;
    report_notfile $1 && return 1;
    set -- $1 $(fun_db echo)/$(lib_name $1) $(awk_file);
    read_devtty set: $*;
    [[ -d $2 ]] && { 
        rm -fr $2/*
    };
    mkdir -p $2;
    cat $1 | awk -v dir=$2 -v quote="'" -f $3 2> ~/tmp/f2file_$(basename $1).err;
    echo $2
}

3.2 View

The function tree is rooted at $(fun_db).

				$(fun_db)
				     |
	  +----------------+-----------+---+-- ...
	  |              |               |
	 alib           blib            clib ...
	  |              |               |
  +---+---+---+ ...  +---+---+- ...  +---+---+ ...
  |   |   |   |      |   |   |       |   |   |
funam |   |   |    funbe |   |     funcx |   |
    funan |   |        funbf |         funcy |
	funao |            funbg           funcz
	    funap
	      ...

so, in explicit terms, dfg performs:

grep -i {arg} {a,b,c,...}lib/fun{a{m,n,o,p},b{e,f,g},c{x,y,z}}

formatting as you see in the results in 2

4 References

4.1 RDB

RDB is the Unix (R) Relational DataBase managment tool. The Software Functions Page documents my ~/rdb ~ implementation and applictions from function libraries. Since /rdb is built on the principle that

the shell is a 4GL, supported by shell tools

the applications highlight that principle

4.2 tag

Author: Marty McGowan

Created: 2021-06-02 Wed 09:58

Validate