stderr
stream.
General messages -- function message() is meant to format and print normal messages, for example to trace the program's normal processing. A message also specifies a level and the message is only printed, if its level is equal or lower than the current message verbosity level as set with setmsglevel(). Messages are printed to the stream as set with setmsgfile(), default it is stdout
.
Debug messages -- function debug() is meant to format and print debug messages, for example to trace the program's data handling. A debug message also specifies a level and the message is only printed, if its level is equal or lower than the current debug message verbosity level as set with setdbglevel(). Messages are printed to the stream as set with setdbgfile(), default it is stdout
.
Filenames -- parts of a filename path can be obtained with basename(), dirname() and extname(). Function exist() tells if the specified filename exists.
User interaction -- funtion prompt() lets you request a user to supply a non-empty string. With pick() you ask a user to accept or reject its argument. ttyin() reads a single character from the terminal.
Module tools is written by Martin J. Moene, Leiden University. It was inspired by the books:
The Unix Programming Environment Brian W. Kernighan and Rob Pike. Prentice Hall, Inc., 1984. ISBN 0-13-937681-X (paperback), 0-13-937699-2 (hardback). The Practice of Programming. Brian W. Kernighan and Rob Pike. Addison-Wesley, Reading, Massachusetts, 1999. ISBN 0-201-61586-X.
Module tools is released into the public domain. You are free to use it in any way you like.
This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.
Defines | |
#define | SLASH '\\' |
filename separation slash | |
Enumerations | |
enum | { E_OK, E_OPT, E_PS, E_INT, E_ITL } |
application return codes. More... | |
enum | { MSG_L0, MSG_L1, MSG_L2 } |
application message level codes. More... | |
enum | { DBG_L0, DBG_L1, DBG_L2 } |
application debug level codes. More... | |
Functions | |
const char * | getprogname () |
return the program's name as set with setprogname(). | |
void | setprogname (const char *name) |
set the program's name as used with error() etc. | |
int | getmsglevel () |
get the current message verbosity level. | |
void | setmsglevel (int level) |
set the message verbosity level. | |
FILE * | getmsgfile () |
get the current file messages will be written to. | |
void | setmsgfile (FILE *file) |
set the file to write messages to. | |
int | getdbglevel () |
get the current debug message verbosity level. | |
void | setdbglevel (int level) |
set the debug message verbosity level. | |
FILE * | getdbgfile () |
get the current file debug messages are written to. | |
void | setdbgfile (FILE *file) |
set the file to write the debug messages to. | |
int | error (int status, const char *format...) |
format and print error message, return status. | |
int | debug (int level, const char *format...) |
format and print debug message, if level permits. | |
int | message (int level, const char *format...) |
format and print message, if level permits. | |
const char * | dirname (const char *pathname) |
return directory part of pathname. | |
const char * | basename (const char *pathname) |
return filename without directory part and extension. | |
const char * | extname (const char *pathname) |
return extension of filename. | |
int | exist (const char *filename) |
tell if specified filename exists. | |
string | prompt (const char *ps) |
prompt for non-empty string input. | |
int | pick (int isInteractive, const char *arg, const char *set) |
select or skip argument. | |
int | ttyin () |
read a character from the terminal. | |
Variables | |
char * | progname = NULL |
program name (default not set) | |
int | dbglevel = 0 |
current debug message level | |
int | msglevel = 0 |
current message level | |
FILE * | dbgfile = stdout |
file to write debug messages to | |
FILE * | msgfile = stdout |
file to write messages to |
|
|
|
|
|
|
|
basename() returns the filename part of the given path without the extension. The returned string does not contain a trailing slash. If you specify a pathname of NULL, the program's path is used as set with setprogname().
|
|
debug() formats and prints the message if the specified level is equal or less than the current debug level. The message has the following format: [progname: ]message[: system-message]\n progname is included when a colon starts the format and it has been set via setprogname(); system-message is included when the format string ends with a colon (:). debug() returns the specified level.
|
|
dirname() returns the directory part of the given path. The returned string does not contain a trailing slash. If you specify a pathname of NULL, the program's path is used as set with setprogname().
|
|
error() formats and prints and error message. The error message has the following format: [progname: ]message[: system-message]\n progname is included when it has been set via setprogname(); system-message is included when the format string ends with a colon (:). error() returns the specified status.
|
|
exist() returns true if the specified filename is "-" (stdin) or exists as diskfile, exist() returns false otherwise.
|
|
extname() returns the extension part of the given path without a dot. If you specify a pathname of NULL, the program's path is used as set with setprogname().
|
|
getdbgfile() returns the current file to write the debug messages to. Default it is stdout.
|
|
getdbglevel() returns the current level for debug messages to be printed.
|
|
getmsgfile() returns the current file to write the messages to. Default it is stdout.
|
|
getmsglevel() returns the current level for messages to be printed.
|
|
getprogname() returns the program's name as it has been set with setprogname(). If setprogname() has not been called, getprogname() returns NULL.
|
|
message() formats and print the specified message if its level is equal or less than the current verbosity level as set with setmsglevel(). The message has the following format: [progname: ]message[: system-message]\n progname is included when a colon starts the format and it has been set via setprogname(); system-message is included when the format string ends with a colon (:). message() returns the specified level.
|
|
If
If
|
|
prompt() issues the prompt prompt() keeps prompting until a non-empty resonse is provided.
|
|
setdbgfile() sets the file to write the debug messages to. Default it is stdout.
|
|
setdbglevel() sets the level for debug messages to be printed. Debug messages with a level equal or less than the current verbosity level as set with setdbglevel() will be printed. The debug level is default 0.
|
|
setmsgfile() sets the file to write the messages to. Default it is stdout.
|
|
setmsglevel() sets the level for messages to be printed. Messages with a level equal or less than the current verbosity level as set with setmsglevel() will be printed. The message level is default 0.
|
|
setprogname() sets the program's name to the one specified. It is used with error(), message() and debug().
|
|
ttyin() reads a single character from the terminal, echoes and returns it.
|