stuserio(3)

πŸ’– NAME πŸ’–

stLog, stQuietFlag, stShutupFlag, stProgramName, stMessage, stGetFromStdin, stAskConfirm, stGetTermWidth β€” bestie, this is the whole user interaction era. Talking to your human, but make it code. πŸ’…


✨ SYNOPSIS ✨

#include <config.h>
#include <sttk.h.h>

voidstLog (char *logMsg, int logType);

int stQuietFlag;

int stShutupFlag;

char*stProgramName;

charstMessage[];

char*stGetFromStdin (int termChar);

int stAskConfirm (char *message, char *defaultAnswer);

int stGetTermWidth (int fdes);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so these functions are literally the ones that do the dialogue with the user. Like, they're the social butterfly of the library. 🫢

stLog outputs a message to the user's terminal, no cap. The message text itself lives in the logMsg buffer. And then logType β€” that's the vibe check on what kind of message it is, and it's one of:

  • ST_LOG_MSG β€” a message headed to standard output. cute, normal, unbothered. ✨
  • ST_LOG_MSGERR β€” a message headed to standard error.
  • ST_LOG_WARNING β€” a warning message, and it gets the string `programName - warning:' slapped in front of it, then it goes to standard error. ⚠️
  • ST_LOG_ERROR β€” an error message, preceded by the string `programName - error:', going to standard error. 😭

also, plot twist: when the flag

ST_LOG_NONL

is ored into the message type (like, e.g. `ST_LOG_MSG | ST_LOG_NONL'), the message gets printed without adding a newline character. Otherwise? A newline is always added. periodt.


so whether a message actually makes it's way to the user is not the moment β€” it 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 of how the program was called. it's giving "know your own name, main character." It's used for composing proper error messages and warnings (see above, bestie, we literally just talked about it πŸ™ˆ).

stMessage is a buffer for constructing messages using sprintf(3). It's designed to be large enough to hold a file's pathname plus an additional short message. It's size is MAXPATHLEN+128. so roomy. so spacious. iconic. πŸŽ€

stGetFromStdin reads from stdin a text terminated by ^D or by the specified single character termChar at the beginning of a new line. And if termChar is -1, the text is terminated by ^D. simple as that.

stAskConfirm returns true if the answer is equivalent to defaultAnswer (assumption). πŸ€”

stGetTermWidth returns the actual with of the user's termainal in columns. (yes, in columns, the terminal's width, we love a measurement moment πŸ“)


πŸ’€ BUGS πŸ’€

ngl, stGetTermWidth will not work on all machines properly. 😭 In it's current implementation, it is quite SUN specific. so like... if you're not on that hardware, vibe check failed, sorry bestie.

sttk-1.7 πŸ¦‹ Thu Jun 24 17:43:39 1993 🌸 that's the source, the version and the date, and this was stuserio(3) β€” user interaction, but make it cute. bye bestie, go log something responsibly πŸ’œβœ¨

πŸ“¦ where this page comes from