logo

Noumena Corporation


Whitmore Lake
Michigan

Some utilities that I've used in the past. Much of this functionality has since been merged into the standard Tcl distribution, but some may still be useful, particularly for folks stuck in pre 8.0 versions of Tcl/Tk.

parseargs

################################################################
# proc parseArgs {stateVar {throwError 1}}--
# Parses $argv into a state array.

# looks for arguments of the form -key val1 ?val2 ... valn?
# and assigns them as ArrayName(key) "val1 ?val2 ... valn?"
# Keys must have a default value to be assigned.
# By default, an error is thrown if an undefaulted key is found.
# If throwError == 0, then the undefaulted keays are appended
# into a list of errors, which will be returned.
# Arguments
# stateVar The name of the associative array to have key/values set
# throwError Optional 0 to turn off errors and return a list.
#
# Results
# Any default values in stateVar are replaced with new values from the
# command line.
#



stringx


# stringx_SetDebug {value} - Sets the debug switch to value. 0 = no output
#
# stringx_After {regExp text} - Returns portion of text after regExp
#
# stringx_Before {regExp text} - Returns portion of text before regExp
#
# stringx_Between {regExp1 regExp2 text} - Returns portion of text
# between
#
# stringx_GetText {regExp text} - Returns the match of the regular expression.
#
# stringx_CaselessGetText {regExp text} -
# Returns the match of the regular expression with no case checking.
#
# stringx_Sequence {actionlist text} - Extracts an item from a text based on
# a set of actions
#
# stringx_FindAll { regexp txt} - returns a list of all the positions where
# a regular expression occurs.
#
# stringx_Count {regExp text} - returns the number of times that {regExp}
# is matched in the text
#

listx


##############################################################################
# trimList --
# Trims each entry of a list, returns the clean list
# Arguments
# lst - The list
# trimval - Characters to trim. defaults to whitespace.
# Results:
# Returns a trimmed list, each entry has no garbage fore or aft.
#

##############################################################################
# lsearchAll --
# Finds each member of a list that matches a glob pattern
# Arguments
# lst - The list
# glob - The glob pattern to search for
# Results:
# Returns a list of all $lst entries that string match $glob.
#

##############################################################################
# lsearchAllPos --
# Finds each member of a list that matches a glob pattern
# Arguments
# lst - The list
# glob - The glob pattern to search for
# Results:
# Returns a list of all $lst positions that string match $glob.
#

##############################################################################
# splitMulti --
# Splits the input on a regular expression
# Arguments
# regExp - The regular expression
# text - The text
# Results:
# Returns a split list, or a null string if there is no valid separator
# in the string.

################################################################
# proc getListElement {lst glob}--
# Returns the list element that contains glob pattern 'glob' or
# empty string.
# Arguments
# lst The list to search for a list element
# glob A glob pattern to search for.
#
# Results
# Returns a subset of $lst or ""