Top Up Prev Next Bottom Contents Index Search

1.3 Non-class utility procedures

The kernel provides several useful ordinary (non-class) procedures, primarily for manipulating strings and path names. Some are defined in miscFuncs.h, others in paths.h.

char* savestring(const char* text); 
Create a copy of the text argument with new and return a pointer to it. It is the caller's responsibility to assure that the string is eventually deleted by using the delete [] operator. The argument text must not be a null pointer.

const char* hashstring(const char* text); 
Enters a copy of text into a hash table and return a pointer to the entry. If two strings compare equal when passed to strcmp, then if both are passed to hashstring, the return values will be the same pointer.

const char* expandPathName(const char* fileName); 
Expand a path name that may begin with an environment variable or a user's home directory. If the string does not begin with a ~ or $ character, the string itself is returned. A leading "~/" is replaced by the user's home directory; a leading "~user " is replaced by the home directory for user, unless there is no such user, in which case the original string is returned. Finally, a leading "$env" is replaced by the value of the environment variable env; if there is no such environment variable, the original string is returned. Note that references to environment variables other than at the beginning are not substituted. If any substitutions are made, the return value is actually a pointer into a static buffer. This means that a second call to this function may write on top of a value returned by a previous call.

const char* pathSearch(const char* file, const char* path=0);
For this function, path is a series of Unix-style directory names, separated by colons. If no second argument is supplied or if the value is null, the value of the PATH environment variable is used instead. For each of the colon-separated directory strings, the function checks to see whether the file exists in the named directory. If it finds a match, it returns a pointer to an internal buffer containing the full path of the match. If it does not find a match, it returns a null pointer.

int progNotFound(const char* program,const char* extra=0); 
This function searches for program in the user's PATH using the pathSearch function. If a match is found, the function returns false (0). Otherwise it returns true (1) and also generates an error message with the Error::abortRun function. If the extra argument is given, it forms the second line of the error message.

Top Up Prev Next Bottom Contents Index Search
Copyright © 1990-1997, University of California. All rights reserved.