diff --git a/sh/program.sh b/sh/program.sh index 7b28559..f76ba9c 100755 --- a/sh/program.sh +++ b/sh/program.sh @@ -1,40 +1,42 @@ -##### -# Program Information -##### +# -------------------------------------------------------------------------- # +# Program Information # +# -------------------------------------------------------------------------- # COPYRIGHT="__COPYRIGHT__" PROGNAME="__PROJECTNAME__" -##### -# Script Interface Definition -#### -# +# -------------------------------------------------------------------------- # +# Script Interface Definition # +# -------------------------------------------------------------------------- # + +##### # Inputs And Command Line Arguments -# +##### # -h Prints help information # -v Prints program version information -# +##### # Outputs -# +##### + # - Error output is written to stderr -# +##### # Side Effects -# - - -##### -# Variables, Constants, Literals, And Strings ##### -# + +# -------------------------------------------------------------------------- # +# Variables, Constants, Literals, And Strings # +# -------------------------------------------------------------------------- # + +##### # Program Related Stuff -# +##### HELPTEXT="${CVSID} \n\ Usage: ${PROGNAME} -XYZh \n\ @@ -47,58 +49,28 @@ -v Print Version Information \n\ " - -# +##### # Error Messages -# +##### eBADARGS="Invalid Command Line Argument!" -# +##### # Stuff Needed By promptuser() Function Below -# +##### ORIGIFS=$IFS # Save current field separator DL=';' # Prompt field delimiter YN="Y y N n Yes yes No no YES NO" -# Prompt Records - -# Layout Of Fields In Prompt Record: -# -# PromptDefault Response (If user just hits Enter)Legal Answers (space separated) -# Notes: -# -# 1) An empty Prompt field means there will be no prompt displayed -# -# 2) An empty Default Response field means that, if the user hits enter, -# the response is blank -# -# 3) An empty Legal Answers field mean the routine will accept *any* input -# -# 4) It's up to you to make sure the Default Response is a legit answer. -# It is NOT checked against the Legal Answers list. - - -# Examples - -foo="Would you like to foo?${DL}Y${DL}" # Empty last field means accept anything -bar="Would you like to bar?${DL}\!${DL}${YN}" -baz="Would you like to baz?${DL}n${DL}${YN} yup" -bat="Would you like to bat?${DL}${DL}nope" - - -PROMPTLIST="foo bar baz bat" - +# -------------------------------------------------------------------------- # +# Function Definitions # +# -------------------------------------------------------------------------- # ##### -# Function Definitions -##### - -# # Print An Error Message -# +##### ErrorMsg() { @@ -108,9 +80,9 @@ # End of 'ErrorMsg()' -# +##### # Print An Informative Message -# +##### PrintMsg() { @@ -120,17 +92,48 @@ # End of 'PrintMsg()' -# -# PromptUser() - Shell Function To Prompt And Validate User Input -# +##### +# Print Usage Information +##### -# From: promptuser.sh,v 1.104 2010/10/07 19:27:37 tdaneli Exp -PromptUser() +Usage() +{ + PrintMsg "${HELPTEXT}" +} + +# End of 'Usage()" + + +##### +# Prompt User With Optional Response Validatation +##### + +# tpromptuser.sh - User Prompting From Shell With validation +# Copyright (c) 2010-2012, TundraWare Inc, Des Plaines, IL USA +# All Rights Reserved. +# For Updates: http://www.tundraware.com/Software/tpromptuser +# Id: tpromptuser.sh,v 1.112 2012/06/05 20:11:04 tundra Exp + +##### +# You are hereby granted a non-exclusive license to do whatever you +# like with this software so long as you understand this is +# *EXPERMENTAL SOFTWARE* that has not been thoroughly tested. It may +# cause harm to your systems, data, and/or network. It may compromise +# your security. I may cause other, unspecified, kinds of harm to +# your IT environment or business. In other words: +# +# USE THIS AT YOUR OWN RISK!!!!!! +##### + + +# Takes a list of prompts as arguments + +tPromptUser() { - for x in $PROMPTLIST + for x in $* do eval record=\$$x # Get the prompt record IFS=$DL # Get individual fields @@ -169,7 +172,7 @@ if [ _$DONE = _False ] then - echo "Invalid Response! Must Be One Of $answers" + printf "Invalid Response! Must Be One Of: $answers\n" fi fi @@ -185,20 +188,12 @@ } -# End Of 'PromptUser()' +# End Of 'tPromptUser()' -# -# Print Usage Information -# - -Usage() -{ - PrintMsg "${HELPTEXT}" -} - -# End of 'Usage()" - +# -------------------------------------------------------------------------- # +# Program Entry Point # +# -------------------------------------------------------------------------- # ##### # Command Line Processing @@ -233,3 +228,42 @@ ###### # Program Entry Point ##### + +##### +# Example of user prompting +##### + +# Prompt Records + +# Layout Of Fields In Prompt Record: +# +# PromptDefault Response (If user just hits Enter)Legal Answers (space separated) +# Notes: +# +# 1) An empty Prompt field means there will be no prompt displayed +# +# 2) An empty Default Response field means that, if the user hits enter, +# the response is blank +# +# 3) An empty Legal Answers field mean the routine will accept *any* input +# +# 4) It's up to you to make sure the Default Response is a legit answer. +# It is NOT checked against the Legal Answers list. +# +# When the call to tPromptUser returns, the user's response will be stored +# *in the variable* that contained the prompting information. + + +# Examples + +foo="Would you like to foo?${DL}Y${DL}" # Empty last field means accept anything +bar="Would you like to bar?${DL}\!${DL}${YN}" +baz="Would you like to baz?${DL}n${DL}${YN} yup" +bat="Would you like to bat?${DL}${DL}nope" + + +tPromptUser "foo bat" +PrintMsg "foo: ${foo}, bat: ${bat}" +tPromptUser "bar baz" +PrintMsg "bar: ${bar}, baz: ${baz}" +