From f0563647cf25000f3e50028f2ceeab8cd3c53164 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 9 Jun 2021 17:38:44 +0200 Subject: [PATCH] kernel: remove redundant isstream booleans --- src/io.c | 48 ++++++++++++++++++++++-------------------------- src/io.h | 4 ---- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/io.c b/src/io.c index 12ebcc36919..dee8e95d66a 100644 --- a/src/io.c +++ b/src/io.c @@ -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 @@ -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]; @@ -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; @@ -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); } @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -664,7 +661,7 @@ UInt CloseInputLog ( void ) return 0; /* close the logfile */ - if (!IO()->InputLog->isstream) { + if (!IO()->InputLog->stream) { SyFclose(IO()->InputLog->file); } @@ -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; @@ -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; @@ -761,7 +757,7 @@ UInt CloseOutputLog ( void ) return 0; /* close the logfile */ - if (!IO()->OutputLog->isstream) { + if (!IO()->OutputLog->stream) { SyFclose(IO()->OutputLog->file); } @@ -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; @@ -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); @@ -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 @@ -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); } @@ -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)) { @@ -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); } @@ -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); @@ -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); } @@ -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; } @@ -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; } @@ -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; } @@ -1915,7 +1911,7 @@ 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; } @@ -1923,7 +1919,7 @@ static Obj FuncIS_INPUT_TTY(Obj self) 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; } diff --git a/src/io.h b/src/io.h index ee26f31ac19..51888143b13 100644 --- a/src/io.h +++ b/src/io.h @@ -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; @@ -113,7 +110,6 @@ struct TypOutputFile { // pointer to the previously active output struct TypOutputFile * prev; - BOOL isstream; BOOL isstringstream; Obj stream; Int file;