stuserio3
User interaction
Usage
#include <config.h>
#include <sttk.h.h>
void stLog (char *logMsg, int logType);
int stQuietFlag;
int stShutupFlag;
char* stProgramName;
char stMessage[];
char* stGetFromStdin (int termChar);
int stAskConfirm (char *message, char *defaultAnswer);
int stGetTermWidth (int fdes);
Overview
These functions do the dialogue with the user. stLog outputs a message to the user's terminal. The message text is given in the logMsg buffer. logType is one of
- ST_LOG_MSG
-
Message to be sent to standard output.
- ST_LOG_MSGERR
-
Message to be sent to standard error.
- ST_LOG_WARNING
-
Warning message, preceded by the string `programName - warning:', going to standard error.
- ST_LOG_ERROR
-
Error message, preceded by the string `programName - error:', going to standard error.
Additionally, when the flag
- ST_LOG_NONL
-
is ored to the message type (e.g. `ST_LOG_MSG | ST_LOG_NONL'), the message is printed without adding a newline character. Otherwise, a newline is always added.
Whether a message really makes it's way to the user, depends on the variables stQuietFlag and stShutupFlag. When stQuietFlag is set to a non null value, all messages except error messages (ST_LOG_ERROR) will be suppressed. With the stShutupFlag set to a null value, all messages will be suppressed. Initially, both flags are set to NULL.
The stProgramName pointer should be set pointing to a buffer containing the name how the program was called. It is used for composing proper error messages and warnings (see above).
stMessage is a buffer for constructing messages using sprintf(3). It is designed to be large enough to hold a file's pathname and an additional short message. It's size is MAXPATHLEN+128.
stGetFromStdin reads from stdin a text terminated by ^D or by the specified single character termChar at the beginning of a new line. If termChar is -1 text is terminated by ^D.
stAskConfirm returns true if the answer is equivalent to defaultAnswer (assumption).
stGetTermWidth returns the actual with of the user's termainal in columns.
Releases
13 releases since Debian 2.1 (Slink); the text changed 1 time.