Turns a string into an array. Each element of the array is separated in the string by the delimiter. Note: The array you want the fields put into must be declared before you call this function.
EXAMPLE my_array=() explode "a_string_to_explode" "_" "my_array" echo my_array[*] Produces "a" "string" "to" "explode".
API
First argument is a sed command. Second argument is a file.
sedit performs the sed command on the file, modifiying the
original file. For example,
sedit "s/foo/bar/g" /tmp/somefile
will replace all occurances of foo with bar in /tmp/somefile.
This function is often used in spells to make changes to source
files before compiling. See the sed man page for more information.
API
Argument is a string to check if the string contains all digits or not
API
Argument is a string to check if it contains all chars a-zA-Z
API
Asks the user a yes/no question. First argument is the question to ask, second argument is the default answer. If a timeout occurs before the question is answered, the given default answer is applied. Pressing spacebar or enter applies the default answer immediatelly without waiting for timeout. Returns true or false based on the answer given.
Asks user for string, with default answer and timeout (like query)
message
API
echo's the given arguments if SILENT is not set.
message
message
Private
echo's the given arguments if SILENT is not set.
Enters a debug message if the type of debug message != 'no' The 'type' is usually the name of the file the debug statement comes from. i.e. DEBUG_liblock, DEBUG_libsorcery, DEBUG_cast etc.
progress spinner
Displays progress spinner like the one in fsck.
Displays progress bar in the form of [----> ] 100% Or just a dot in the dot format
Clear line
Clears the current line and puts the cursor at the begining of it.
SOUND
Plays a given soundfile if sounds are on and the file exists in the chosen theme.
Runs the editor given by EDITOR on the file given in the first argument. If EDITOR is not set, "nano -w" is used.
escaped string
Adds escape sequences to strings for special characters. Does NOT escape the string ".*". Used for putting escape sequences in regexp strings that should be treated literaly.
esc_str with a minor modification used for escaping provider queries, where only the provider name needs to be escaped. Does NOT escape strings matching ".*(.*".
Properly quotes and backquotes parameters so they can be passed through su at the start of many sorcery commands Expected usage is: PARAMS=$(consolidate_params "$@") su -c "$0 $PARAMS" root
directories.
directories' basenames
Takes newline separated list of directories and outputs their base names.
directories.
directories' basenames
Takes newline separated list of pathnames and outputs their directory names.
error if the input is not a directory, but something else
Checks whether the passed directory exists and if not, tries to create it, first checking if it already exists as something else.
is used when $3 isn't given.
$3 is optional, when it isn't used, stdin is used and only the first letter in $2 is used. Note, using stdin can have odd side effects when your function uses read and stdin itself. Special vars: BREAK: Use this to break out of the loop prematurely, also causes a return of 1. If the function returns the value of the last return Notes: In stdin mode, if the string does not terminate with the delimiter, the last token will be ignored.
gives the user some nice select list and puts the selected item in return_var
Common code for select_list and select_provider The user should have already printed out the menu, this handles getting a valid answer from the user.
sets the terminal title if TERM=xterm|rxvt or the window title if TERM=screen
Removes from the list string(s). Strings are kept to be unique and are separated by spaces
Puts in the list string(s). Strings are kept to be unique and are separated by spaces
return 0 at least one element is in list return 1 none of supplied elements is not in list Finds if at least one of the given elements is in the string. They can be delimited by spaces, tabs or newlines. The search elements must not contain any of these or they won't match. The matching is exact, regular expressions and globbing patterns are not supported. Warning, this function takes a real string, not a variable name as other list_* functions. Use the ${var[*]} form when passing arrays
finds the persistent var for spell and sets variable name to the value of the variable to read
Adds variable names to the list of persistent variables
Removes variable names from the list of persistent variables
Loads persistent variables stored in file "$SPELL_CONFIG"
Saves variables marked as persistent to file "$SPELL_CONFIG". The File is completely overwritten. Also unsets all persistent variables
Unsets all persistent variables. Mainly usable as replacement of persistent_save for functions which can be called by nonroot users ( for example from 'gaze what' )
Retrieves setting from $SPELL_CONFIG file and optionally sets user supplied variable. Function is here to make possible changes to config system easy, since all other functions are using this function and are not working with variables directly
Get value of a persistent variable from the previous cast when there is a -r. The persistent data moves to a seperate directory when cast -r is run, this makes the new persistent config clean but allows us to provide the user defaults from the last cast.
Stores string to given variable and makes the variable persistent Function is here to make possible changes to config system easy, since all other functions are using this function and are not working with variables directly
Asks user for string, with default answer and timeout (like query) Return variable is also marked as persistent
Asks user for string, with default answer and timeout (like query) The string is added to the variable If you want to use empty string, place there dummy string and remove it later by list_remove function. Also for one config variable, all option_yes and option_no have to be different. Return variable is also marked as persistent
Asks user for string, with default answer and timeout (like query) Return variable is also marked as persistent
Asks user for string, with numbered possibilities listed Return variable is also marked as persistent
Output a list of source numbers associated with the current spell. This is the number portion of SOURCE[[:digit:]], eg '', "2", "3", etc. A prefix may be given and it will be prepended to each result value.
misc_is_function
Remove files listed and any directories which become empty after subsequent file removal.
Safely creates $TMP_DIR and exports the variable so we can use it even in subprocesses called through make.
'which' is not in basesystem, heres our own simple version of it it should be just as fast as the real one. Marches through $PATH looking for the executable specified
Finds the make command and complains if its missing (shouldnt ever happen)
This function will probably need to be updated as sorcery variables come in and out of flux, the variables listed are roughly defined as things defined at the point in which a spell file is run, and when it is not run in a seperate subshell, note that the build phase of cast is seperate from the frontend, so a spell could technically modify something like "SPELLS" and not have a major problem. However the philosophy is to not discriminate about what sorcery variables are technically okay to use in what files and ones that arent, instead we'll treat all usages of sorcery variables equally. The rules are of course subject to change without warning and its just easier to be consistent, also theres a good chance that if a variable is safe in some circumstances and not others, and one uses it where its safe, someone will forget and start using it in places that arent safe...
Complain vehemently that a variable name is used by sorcery and the user should file a bug because a spell is using the variable
Sets the SPECFILE glocal variable and the SMGL_COMPAT_ARCHS global array SPECFILE contains the compiler and other arch specifications SMGL_COMPAT_ARCHS is an array that holds architectures which are compatible with the desired architecture. The desired architecture is determined as follows:
1) If function is gien an argument, the argument is used, or 2) If cross-install is on, the TARGET architecture is used, or 3) The local ARCHITECTURE is usedThe least specific arch is in SMGL_COMPAT_ARCHS[0], SMGL_COMPAT_ARCHS[1] is more specific, et cetera. For example: desired architecture="athlon-xp" might result in: SPECFILE=/usr/share/archspecs/ia32/amd/athlon-xp SMGL_COMPAT_ARCHS=("ia32" "amd" "athlon-xp") ARCHITECTURE is also modified to be an array, the reverse of SMGL_COMPAT_ARCHS. The result is an array from most specific arch to least specific. $ARCHITECTURE does not change meaning since $A == ${A[0]}.
Creates functions with identical bodies. It is useful if you need to override a bunch of functions which have already been defined.
Set variable by name, useful for setting variables that were passed by reference. Example:
function uber() { local x unter x 5 echo $x } function unter() { local var=$1 y=$2 read -p "enter value (default $2)" y upvar $var $y }
Like uniq, but doesnt require a sorted list, implemented in awk.
Dirname written in bash, optionally uses an upvar (making it forkless).
basename written in bash, optionally uses upvar (making it forkless). Does not have ability to remove file extension like the real basename.
new path
TODO: remove grimoire functions libgcc gcc_prepend_path and use this one
Appends the input to the notice log, prepending the spell name as a title, appending a newline and teeing the input back unchanged.
Appends the failure reason (input) to a log for use in displaying the final FAILED_LIST and the activity log
Checks if there is an entry for the spell in the failure_reason_log If there is one, set the upvar to the reason
Checks if the file is compressed and displays it
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