File: action-run.c

package info (click to toggle)
snoopy 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,016 kB
  • sloc: ansic: 7,169; sh: 4,514; makefile: 1,095
file content (131 lines) | stat: -rw-r--r-- 3,831 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * SNOOPY COMMAND LOGGER
 *
 * Copyright (c) 2022 Bostjan Skufca Jese <bostjan@a2o.si>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */



/*
 * Includes order: from local to global
 */
#include "snoopy.h"

#include "action-common.h"

#ifdef SNOOPY_CONFIGFILE_ENABLED
#include "action-run-configfile.h"
#endif
#include "action-run-datasource.h"
#ifdef SNOOPY_FILTERING_ENABLED
#include "action-run-filter.h"
#include "action-run-filterchain.h"
#endif
#include "action-run-messageformat.h"
#include "action-run-output.h"

#include "action-run-everything.h"


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>



void snoopyTestCli_action_run_showHelp ()
{
    char * helpContent =
        "Snoopy TEST SUITE CLI utility :: Action `run`\n"
        "\n"
        "Usage:\n"
        "    snoopy run SUBSYSTEM [ARGS]\n"
        "\n"
        "Available subsystems:\n"
#ifdef SNOOPY_CONFIGFILE_ENABLED
        "    configfile,cf      Run a configfile (.ini) parser\n"
#endif
        "    datasource,ds      Run a data source\n"
#ifdef SNOOPY_FILTERING_ENABLED
        "    filter,f           Run a filter\n"
        "    filterchain,fc     Run a filter chain (as if it would be configured in snoopy.ini)\n"
#endif
        "    messageformat,mf   Run the message formatter\n"
        "    output,o           Run an output\n"
        "\n"
        "    everything         Runs every subsystem, as much as possible (for Valgrind)\n"
        "\n"
        "    help,h             Show this help\n"
        "    SUBSYSTEM help     Show SUBSYSTEM's help\n"
        "\n";

    printf("%s", helpContent);
}



int snoopyTestCli_action_run (int argc, char ** argv)
{
    if (argc < 1) {
        snoopyTestCli_action_run_showHelp();
        fatalError("No subsystem specified.");
    }


#ifdef SNOOPY_CONFIGFILE_ENABLED
    if ((0 == strcmp(argv[0], "configfile")) || (0 == strcmp(argv[0], "cf"))) {
        return snoopyTestCli_action_run_configfile(argc-1, &argv[1]);
    }
#endif

    if ((0 == strcmp(argv[0], "datasource")) || (0 == strcmp(argv[0], "ds"))) {
        return snoopyTestCli_action_run_datasource(argc-1, &(argv[1]));
    }

#ifdef SNOOPY_FILTERING_ENABLED
    if ((0 == strcmp(argv[0], "filter")) || (0 == strcmp(argv[0], "f"))) {
        return snoopyTestCli_action_run_filter(argc-1, &argv[1]);
    }
    if ((0 == strcmp(argv[0], "filterchain")) || (0 == strcmp(argv[0], "fc"))) {
        return snoopyTestCli_action_run_filterchain(argc-1, &argv[1]);
    }
#endif

    if ((0 == strcmp(argv[0], "messageformat")) || (0 == strcmp(argv[0], "mf"))) {
        return snoopyTestCli_action_run_messageformat(argc-1, &argv[1]);
    }

    if ((0 == strcmp(argv[0], "output")) || (0 == strcmp(argv[0], "o"))) {
        return snoopyTestCli_action_run_output(argc-1, &argv[1]);
    }

    if (0 == strcmp(argv[0], "everything")) {
        return snoopyTestCli_action_run_everything();
    }


    if ((0 == strcmp(argv[0], "help")) || (0 == strcmp(argv[0], "h"))) {
        snoopyTestCli_action_run_showHelp();
        return 0;
    }


    snoopyTestCli_action_run_showHelp();
    fatalErrorValue("Unknown subsystem", argv[0]);
    return 127;
}