summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qfile/stdinprocess/main.cpp
blob: 0f92ba2670880559fd7c14393c6583d21cde836a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only


#include <QtCore/QCoreApplication>
#include <QtCore/QFile>

int main(int argc, char *argv[])
{
    if (argc < 2) {
        printf("usage: stdinprocess_helper <all|line <0|1>>\n");
        printf("echos all its input to its output.\n");
        return 1;
    }

    QFile file;

    if (strcmp(argv[1], "all") == 0) {
        if (!file.open(stdin, QFile::ReadWrite))
            return 1;
        printf("%s", file.readAll().constData());
    } else if (strcmp(argv[1], "line") == 0) {
        if (strcmp(argv[2], "0") == 0) {
            if (!file.open(stdin, QFile::ReadWrite))
                return 1;
        } else {
            if (!file.open(0, QFile::ReadWrite))
                return 1;
        }

        char line[1024];
        while (file.readLine(line, sizeof(line)) > 0) {
            printf("%s", line);
            fflush(stdout);
        }
    }
    return 0;
}