Skip to content

Commit

Permalink
kernel: remove redundant isstream booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jun 15, 2021
1 parent 71d2632 commit f056364
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
48 changes: 22 additions & 26 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ UInt OpenInput(TypInputFile * input, const Char * filename)
/* enter the file identifier and the file name */
memset(input, 0, sizeof(TypInputFile));
input->prev = IO()->Input;
input->isstream = FALSE;
input->stream = 0;
input->file = file;

// enable echo for stdin and errin
Expand Down Expand Up @@ -412,8 +412,8 @@ UInt OpenInputStream(TypInputFile * input, Obj stream, BOOL echo)
/* enter the file identifier and the file name */
memset(input, 0, sizeof(TypInputFile));
input->prev = IO()->Input;
input->isstream = TRUE;
input->stream = stream;
input->file = -1;
input->isstringstream = (CALL_1ARGS(IsInputStringStream, stream) == True);
if (input->isstringstream) {
input->sline = CONST_ADDR_OBJ(stream)[2];
Expand All @@ -422,7 +422,6 @@ UInt OpenInputStream(TypInputFile * input, Obj stream, BOOL echo)
else {
input->sline = 0;
}
input->file = -1;
input->echo = echo;
strlcpy(input->name, "stream", sizeof(input->name));
input->gapnameid = 0;
Expand Down Expand Up @@ -461,7 +460,7 @@ UInt CloseInput(TypInputFile * input)
GAP_ASSERT(input == IO()->Input);

// close the input file
if (!input->isstream) {
if (!input->stream) {
SyFclose(input->file);
}

Expand Down Expand Up @@ -511,7 +510,7 @@ UInt OpenLog (

/* try to open the file */
IO()->OutputLogFileOrStream.file = SyFopen(filename, "w", FALSE);
IO()->OutputLogFileOrStream.isstream = FALSE;
IO()->OutputLogFileOrStream.stream = 0;
if (IO()->OutputLogFileOrStream.file == -1)
return 0;

Expand All @@ -538,7 +537,6 @@ UInt OpenLogStream (
return 0;

/* try to open the file */
IO()->OutputLogFileOrStream.isstream = TRUE;
IO()->OutputLogFileOrStream.stream = stream;
IO()->OutputLogFileOrStream.file = -1;

Expand Down Expand Up @@ -569,7 +567,7 @@ UInt CloseLog ( void )
return 0;

/* close the logfile */
if (!IO()->InputLog->isstream) {
if (!IO()->InputLog->stream) {
SyFclose(IO()->InputLog->file);
}
IO()->InputLog = 0;
Expand Down Expand Up @@ -605,7 +603,7 @@ UInt OpenInputLog (

/* try to open the file */
IO()->InputLogFileOrStream.file = SyFopen(filename, "w", FALSE);
IO()->InputLogFileOrStream.isstream = FALSE;
IO()->InputLogFileOrStream.stream = 0;
if (IO()->InputLogFileOrStream.file == -1)
return 0;

Expand All @@ -631,7 +629,6 @@ UInt OpenInputLogStream (
return 0;

/* try to open the file */
IO()->InputLogFileOrStream.isstream = TRUE;
IO()->InputLogFileOrStream.stream = stream;
IO()->InputLogFileOrStream.file = -1;

Expand Down Expand Up @@ -664,7 +661,7 @@ UInt CloseInputLog ( void )
return 0;

/* close the logfile */
if (!IO()->InputLog->isstream) {
if (!IO()->InputLog->stream) {
SyFclose(IO()->InputLog->file);
}

Expand Down Expand Up @@ -700,7 +697,7 @@ UInt OpenOutputLog (

/* try to open the file */
memset(&IO()->OutputLogFileOrStream, 0, sizeof(TypOutputFile));
IO()->OutputLogFileOrStream.isstream = FALSE;
IO()->OutputLogFileOrStream.stream = 0;
IO()->OutputLogFileOrStream.file = SyFopen(filename, "w", FALSE);
if (IO()->OutputLogFileOrStream.file == -1)
return 0;
Expand Down Expand Up @@ -728,7 +725,6 @@ UInt OpenOutputLogStream (

/* try to open the file */
memset(&IO()->OutputLogFileOrStream, 0, sizeof(TypOutputFile));
IO()->OutputLogFileOrStream.isstream = TRUE;
IO()->OutputLogFileOrStream.stream = stream;
IO()->OutputLogFileOrStream.file = -1;

Expand Down Expand Up @@ -761,7 +757,7 @@ UInt CloseOutputLog ( void )
return 0;

/* close the logfile */
if (!IO()->OutputLog->isstream) {
if (!IO()->OutputLog->stream) {
SyFclose(IO()->OutputLog->file);
}

Expand Down Expand Up @@ -831,7 +827,7 @@ UInt OpenOutput(TypOutputFile * output, const Char * filename, BOOL append)
/* put the file on the stack, start at position 0 on an empty line */
output->prev = IO()->Output;
IO()->Output = output;
output->isstream = FALSE;
output->stream = 0;
output->file = file;
output->line[0] = '\0';
output->pos = 0;
Expand Down Expand Up @@ -861,9 +857,9 @@ UInt OpenOutputStream(TypOutputFile * output, Obj stream)
/* put the file on the stack, start at position 0 on an empty line */
output->prev = IO()->Output;
IO()->Output = output;
output->isstream = TRUE;
output->isstringstream = (CALL_1ARGS(IsOutputStringStream, stream) == True);
output->stream = stream;
output->file = -1;
output->line[0] = '\0';
output->pos = 0;
output->format = (CALL_1ARGS(PrintFormattingStatus, stream) == True);
Expand Down Expand Up @@ -908,7 +904,7 @@ UInt CloseOutput(TypOutputFile * output)

/* refuse to close the initial output file '*stdout*' */
#ifdef HPCGAP
if (output->prev == 0 && output->isstream &&
if (output->prev == 0 && output->stream &&
IO()->DefaultOutputStream == output->stream)
return 0;
#else
Expand All @@ -918,7 +914,7 @@ UInt CloseOutput(TypOutputFile * output)

/* flush output and close the file */
Pr("%c", (Int)'\03', 0);
if (!output->isstream) {
if (!output->stream) {
SyFclose(output->file);
}

Expand Down Expand Up @@ -959,7 +955,7 @@ static Int GetLine2(TypInputFile * input)
Char * buffer = input->line + 1;
UInt length = sizeof(input->line) - 1;

if ( input->isstream ) {
if ( input->stream ) {
if (input->sline == 0 ||
(IS_STRING_REP(input->sline) &&
GET_LEN_STRING(input->sline) <= input->spos)) {
Expand Down Expand Up @@ -1036,7 +1032,7 @@ static Char GetLine(TypInputFile * input)
/* if file is '*stdin*' or '*errin*' print the prompt and flush it */
/* if the GAP function `PrintPromptHook' is defined then it is called */
/* for printing the prompt, see also `EndLineHook' */
if (!input->isstream) {
if (!input->stream) {
if (input->file == 0 && SyQuiet) {
Pr("%c", (Int)'\03', 0);
}
Expand Down Expand Up @@ -1101,7 +1097,7 @@ static void PutLine2(TypOutputFile * output, const Char * line, UInt len)
ConvString(str);
AppendCStr(str, line, len);
}
else if (output->isstream) {
else if (output->stream) {
// delegate to library level
str = MakeImmStringWithLen(line, len);
CALL_2ARGS(WriteAllFunc, output->stream, str);
Expand Down Expand Up @@ -1129,7 +1125,7 @@ static void PutLineTo(TypOutputFile * stream, UInt len)
PutLine2( stream, stream->line, len );

/* if necessary echo it to the logfile */
if (IO()->OutputLog != 0 && !stream->isstream) {
if (IO()->OutputLog != 0 && !stream->stream) {
if (stream->file == 1 || stream->file == 3) {
PutLine2(IO()->OutputLog, stream->line, len);
}
Expand Down Expand Up @@ -1874,7 +1870,7 @@ static Obj FuncSET_PRINT_FORMATTING_STDOUT(Obj self, Obj val)
{
TypOutputFile * output = IO()->Output;
while (output) {
if (!output->isstream && output->file == 1)
if (!output->stream && output->file == 1)
output->format = (val != False);
output = output->prev;
}
Expand All @@ -1885,7 +1881,7 @@ static Obj FuncPRINT_FORMATTING_STDOUT(Obj self)
{
TypOutputFile * output = IO()->Output;
while (output) {
if (!output->isstream && output->file == 1)
if (!output->stream && output->file == 1)
return output->format ? True : False;
output = output->prev;
}
Expand All @@ -1899,7 +1895,7 @@ static Obj FuncSET_PRINT_FORMATTING_CURRENT(Obj self, Obj val)
if (!output)
ErrorMayQuit("SET_PRINT_FORMATTING_CURRENT called while no output is open", 0, 0);
output->format = (val != False);
if (output->isstream)
if (output->stream)
CALL_2ARGS(SetPrintFormattingStatus, output->stream, val);
return 0;
}
Expand All @@ -1915,15 +1911,15 @@ static Obj FuncPRINT_FORMATTING_CURRENT(Obj self)
static Obj FuncIS_INPUT_TTY(Obj self)
{
GAP_ASSERT(IO()->Input);
if (IO()->Input->isstream)
if (IO()->Input->stream)
return False;
return SyBufIsTTY(IO()->Input->file) ? True : False;
}

static Obj FuncIS_OUTPUT_TTY(Obj self)
{
GAP_ASSERT(IO()->Output);
if (IO()->Output->isstream)
if (IO()->Output->stream)
return False;
return SyBufIsTTY(IO()->Output->file) ? True : False;
}
Expand Down
4 changes: 0 additions & 4 deletions src/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ struct TypInputFile {
// pointer to the previously active input
struct TypInputFile * prev;

// non-zero if input comes from a stream
BOOL isstream;

// non-zero if input come from a string stream
BOOL isstringstream;

Expand Down Expand Up @@ -113,7 +110,6 @@ struct TypOutputFile {
// pointer to the previously active output
struct TypOutputFile * prev;

BOOL isstream;
BOOL isstringstream;
Obj stream;
Int file;
Expand Down

0 comments on commit f056364

Please sign in to comment.