main: rejig control token descriptor handling
This commit is contained in:
parent
90456a5717
commit
50048f5b45
1 changed files with 11 additions and 9 deletions
|
@ -530,9 +530,11 @@ int main(int argc, char ** argv) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool control_token_allowed_on_standard_stream = !params.conversation && sparams.grammar.empty();
|
||||||
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
const bool control_token_descriptor_is_attached = fcntl(CONTROL_TOKEN_FILENO, F_GETFL) != -1;
|
const bool control_token_descriptor_is_attached = fcntl(CONTROL_TOKEN_FILENO, F_GETFL) != -1;
|
||||||
if (!control_token_descriptor_is_attached && !params.conversation && sparams.grammar.empty()) {
|
if (control_token_allowed_on_standard_stream && !control_token_descriptor_is_attached) {
|
||||||
// Control Token File Descriptor has nothing attached to it so make control token file descriptor be an alias of stdout
|
// Control Token File Descriptor has nothing attached to it so make control token file descriptor be an alias of stdout
|
||||||
// This is not done however if we are in conversation mode or grammar mode as that is typically discarded
|
// This is not done however if we are in conversation mode or grammar mode as that is typically discarded
|
||||||
dup2(STDOUT_FILENO, CONTROL_TOKEN_FILENO);
|
dup2(STDOUT_FILENO, CONTROL_TOKEN_FILENO);
|
||||||
|
@ -759,19 +761,19 @@ int main(int argc, char ** argv) {
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fprintf(stdout, "%s", token_str.c_str());
|
fprintf(stdout, "%s", token_str.c_str());
|
||||||
} else if (!params.ctrl_token_no_out) {
|
} else if (!params.ctrl_token_no_out) {
|
||||||
if (!params.conversation && sparams.grammar.empty())
|
|
||||||
{
|
|
||||||
// Stream Control Token To Special Token Output. Useful for debugging control token behaviour
|
|
||||||
fflush(stdout);
|
|
||||||
fprintf(stdout, "%s", token_str.c_str());
|
|
||||||
}
|
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
else {
|
if (control_token_descriptor_is_attached) {
|
||||||
// Stream Control Token To Special Token Output. Useful for debugging control token behaviour
|
// Stream Control Token To Special Token Output. Useful for debugging control token behaviour
|
||||||
ssize_t result = write(CONTROL_TOKEN_FILENO, token_str.c_str(), token_str.length());
|
ssize_t result = write(CONTROL_TOKEN_FILENO, token_str.c_str(), token_str.length());
|
||||||
(void) result;
|
(void) result;
|
||||||
}
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
if (control_token_allowed_on_standard_stream)
|
||||||
|
{
|
||||||
|
// Stream Control Token To Standard Output Stream
|
||||||
|
fflush(stdout);
|
||||||
|
fprintf(stdout, "%s", token_str.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Record Displayed Tokens To Log
|
// Record Displayed Tokens To Log
|
||||||
// Note: Generated tokens are created one by one hence this check
|
// Note: Generated tokens are created one by one hence this check
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue