mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-16 06:18:47 +02:00
Add tests for stdout() function.
This commit is contained in:
@@ -3280,6 +3280,21 @@ May 16 and 17. You can go backwards, too, so:
|
||||
takes \fIa\fR back to 2009-05-13.
|
||||
.RE
|
||||
.TP
|
||||
.B stdout()
|
||||
Returns a string representing where Remind's standard output is going.
|
||||
The return values are one of the following: "TTY" if standard-output
|
||||
is a terminal, "BLOCKDEV" if it is a block device (very unlikely),
|
||||
"CHARDEV" if it is a character device (eg, /dev/null), "DIR" if it
|
||||
is a directory (very unlikely), "PIPE" if it is a pipe or FIFO,
|
||||
"SYMLINK" if it is a symlink (very unlikely), "SOCKET" if it is a
|
||||
socket, or "UNKNOWN" if it could not be determined.
|
||||
.RS
|
||||
.PP
|
||||
The purpose of \fBstdout()\fR is mostly to distinguish between TTY
|
||||
and non-TTY output; you may wish to change or disable colors if the
|
||||
output is not going to a TTY.
|
||||
.RE
|
||||
.TP
|
||||
.B strlen(s_str)
|
||||
Returns the length of \fIstr\fR. If the length of \fIstr\fR is too large
|
||||
to represent as an integer, emits a "Number too high" error.
|
||||
|
||||
31
src/funcs.c
31
src/funcs.c
@@ -121,6 +121,7 @@ static int FRealtoday (func_info *);
|
||||
static int FSgn (func_info *);
|
||||
static int FShell (func_info *);
|
||||
static int FSlide (func_info *);
|
||||
static int FStdout (func_info *);
|
||||
static int FStrlen (func_info *);
|
||||
static int FSubstr (func_info *);
|
||||
static int FSunrise (func_info *);
|
||||
@@ -276,6 +277,7 @@ BuiltinFunc Func[] = {
|
||||
{ "shell", 1, 2, 0, FShell },
|
||||
{ "shellescape", 1, 1, 1, FShellescape },
|
||||
{ "slide", 2, NO_MAX, 0, FSlide },
|
||||
{ "stdout", 0, 0, 1, FStdout },
|
||||
{ "strlen", 1, 1, 1, FStrlen },
|
||||
{ "substr", 2, 3, 1, FSubstr },
|
||||
{ "sunrise", 0, 1, 0, FSunrise},
|
||||
@@ -1237,6 +1239,35 @@ static int FLower(func_info *info)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
/* */
|
||||
/* FStdout - return the type of file descriptor for stdout */
|
||||
/* */
|
||||
/***************************************************************/
|
||||
static int FStdout(func_info *info)
|
||||
{
|
||||
struct stat statbuf;
|
||||
int r;
|
||||
|
||||
if (isatty(STDOUT_FILENO)) {
|
||||
return RetStrVal("TTY", info);
|
||||
}
|
||||
if (fstat(STDOUT_FILENO, &statbuf) < 0) {
|
||||
return RetStrVal("UNKNOWN", info);
|
||||
}
|
||||
switch(statbuf.st_mode & S_IFMT) {
|
||||
case S_IFBLK: r = RetStrVal("BLOCKDEV", info); break;
|
||||
case S_IFCHR: r = RetStrVal("CHARDEV", info); break;
|
||||
case S_IFDIR: r = RetStrVal("DIR",info); break;
|
||||
case S_IFIFO: r = RetStrVal("PIPE",info); break;
|
||||
case S_IFLNK: r = RetStrVal("SYMLINK", info); break;
|
||||
case S_IFREG: r = RetStrVal("FILE",info); break;
|
||||
case S_IFSOCK: r = RetStrVal("SOCKET", info); break;
|
||||
default: r = RetStrVal("UNKNOWN", info); break;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
/* */
|
||||
/* FToday - return the system's notion of "today" */
|
||||
|
||||
@@ -133,6 +133,17 @@ REM 4 MSG Normal
|
||||
SET $DefaultColor "256 0 0"
|
||||
EOF
|
||||
|
||||
# Test stdout
|
||||
../src/remind - 1 jan 2012 <<'EOF' >> ../tests/test.out 2>&1
|
||||
BANNER %
|
||||
MSG STDOUT is a: [stdout()]%
|
||||
EOF
|
||||
|
||||
../src/remind - 1 jan 2012 <<'EOF' 2>&1 | cat >> ../tests/test.out
|
||||
BANNER %
|
||||
MSG STDOUT is a: [stdout()]%
|
||||
EOF
|
||||
|
||||
# Test -@ option
|
||||
../src/remind -w,0,0 -@0,,1 -c - 1 Jan 2020 <<'EOF' >> ../tests/test.out 2>&1
|
||||
rem 1 SPECIAL COLOR 0 0 0 BLACK
|
||||
|
||||
1101
tests/test.cmp
1101
tests/test.cmp
File diff suppressed because it is too large
Load Diff
@@ -436,6 +436,7 @@ set a132 trigdatetime()
|
||||
set a133 trigduration()
|
||||
set a134 trigeventstart()
|
||||
set a135 trigeventduration()
|
||||
set a136 stdout()
|
||||
|
||||
# These will issue errors
|
||||
REM Mon OMIT Mon SKIP MSG Never ever ever...
|
||||
|
||||
Reference in New Issue
Block a user