Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pipe output on windows #852

Merged
merged 4 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ ui_*.h

# vscode related thingss
.vscode/
.theia/
9 changes: 9 additions & 0 deletions tools/ld-chroma-decoder/encoder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
#include <QCommandLineParser>
#include <cstdio>

#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif

#include "lddecodemetadata.h"
#include "logging.h"

Expand All @@ -37,6 +42,10 @@

int main(int argc, char *argv[])
{
#ifdef _WIN32
_setmode(_fileno(stdout), O_BINARY);
_setmode(_fileno(stdin), O_BINARY);
#endif
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
2 changes: 2 additions & 0 deletions tools/ld-chroma-decoder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ static bool loadTransformThresholds(QCommandLineParser &parser, QCommandLineOpti

int main(int argc, char *argv[])
{
//set 'binary mode' for stdin and stdout on windows
setBinaryMode();
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
2 changes: 2 additions & 0 deletions tools/ld-disc-stacker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

int main(int argc, char *argv[])
{
//set 'binary mode' for stdin and stdout on windows
setBinaryMode();
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
2 changes: 2 additions & 0 deletions tools/ld-discmap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

int main(int argc, char *argv[])
{
//set 'binary mode' for stdin and stdout on windows
setBinaryMode();
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
2 changes: 2 additions & 0 deletions tools/ld-dropout-correct/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

int main(int argc, char *argv[])
{
//set 'binary mode' for stdin and stdout on windows
setBinaryMode();
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
2 changes: 2 additions & 0 deletions tools/ld-export-metadata/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

int main(int argc, char *argv[])
{
//set 'binary mode' for stdin and stdout on windows
setBinaryMode();
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
2 changes: 2 additions & 0 deletions tools/ld-lds-converter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

int main(int argc, char *argv[])
{
//set 'binary mode' for stdin and stdout on windows
setBinaryMode();
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
9 changes: 9 additions & 0 deletions tools/ld-process-ac3/decode/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#include <cassert>
#include <cstring>

#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif

#include "../logger.hpp"
#include "AC3Framer.hpp"
#include "ac3_parsing.hpp" // mostly for debug & stats
Expand All @@ -49,6 +54,10 @@ void doHelp(const std::string &app) {
}

int main(int argc, char *argv[]) {
#ifdef _WIN32
_setmode(_fileno(stdout), O_BINARY);
_setmode(_fileno(stdin), O_BINARY);
#endif
while (true) {
switch (getopt(argc, argv, "v:h?")) {
// could have stdin/stdout as defaults, with switches to change them
Expand Down
10 changes: 10 additions & 0 deletions tools/ld-process-ac3/demodulate/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
#include <cstring>
#include <cassert>

#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif

#include "../logger.hpp"
#include "OneBitADC.hpp"
#include "Reclocker.hpp"
Expand All @@ -52,6 +57,11 @@ void doHelp(const std::string &app) {


int main(int argc, char *argv[]) {

#ifdef _WIN32
_setmode(_fileno(stdout), O_BINARY);
_setmode(_fileno(stdin), O_BINARY);
#endif
int slidingAvgLength = 1e3;

// todo 8/16bit and little-/big-endian switches? leave it to sox?
Expand Down
2 changes: 2 additions & 0 deletions tools/ld-process-efm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

int main(int argc, char *argv[])
{
//set 'binary mode' for stdin and stdout on windows
setBinaryMode();
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
2 changes: 2 additions & 0 deletions tools/ld-process-vbi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

int main(int argc, char *argv[])
{
//set 'binary mode' for stdin and stdout on windows
setBinaryMode();
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
2 changes: 2 additions & 0 deletions tools/ld-process-vits/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

int main(int argc, char *argv[])
{
//set 'binary mode' for stdin and stdout on windows
setBinaryMode();
// Install the local debug message handler
setDebug(true);
qInstallMessageHandler(debugOutputHandler);
Expand Down
8 changes: 8 additions & 0 deletions tools/library/tbc/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ void setQuiet(bool state)
quietDebug = state;
}

void setBinaryMode(void)
{
#ifdef _WIN32
_setmode(_fileno(stdout), O_BINARY);
_setmode(_fileno(stdin), O_BINARY);
#endif
}

// Method to add the standard debug options to the command line parser
void addStandardDebugOptions(QCommandLineParser &parser)
{
Expand Down
6 changes: 6 additions & 0 deletions tools/library/tbc/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@
#include <QString>
#include <QCommandLineParser>

#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
#endif

// Prototypes
void debugOutputHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
void setDebug(bool state);
void setQuiet(bool state);
void setBinaryMode(void);
void openDebugFile(QString filename);
void closeDebugFile(void);
void addStandardDebugOptions(QCommandLineParser &parser);
Expand Down