Switch to unified view

a/scctl_src/scctl.cpp b/scctl_src/scctl.cpp
...
...
121
        out << endl;
121
        out << endl;
122
    }
122
    }
123
    return out.str();
123
    return out.str();
124
}
124
}
125
125
126
#ifdef HAVE_WITHSTATUS_IN_LINN
127
void parseToOutput(bool ok, const vector<string>& reasons, string& out)
128
{
129
    ostringstream oss;
130
    vector<string> error_reasons;
131
    if (!reasons.empty()) {
132
        for (string reason : reasons) {
133
            if (!reason.empty()) {
134
                ok = false;
135
                error_reasons.push_back(reason);
136
            }
137
        }
138
    }
139
    if (ok) {
140
        oss << "Ok\n";
141
    } else {
142
        for (string error_reason : error_reasons) {
143
            oss << "Error: " << error_reason << "\n";
144
        }
145
    }
146
    out = oss.str();
147
    LOGDEB("out: " << out << endl);
148
}
149
#endif
150
126
int dosomething(int opflags, const vector<string>& args, string& out)
151
int dosomething(int opflags, const vector<string>& args, string& out)
127
{
152
{
128
    if (opflags & OPT_l) {
153
    if (opflags & OPT_l) {
129
        out = showReceivers(opflags);
154
        out = showReceivers(opflags);
130
    } else if (opflags & OPT_L) {
155
    } else if (opflags & OPT_L) {
131
        out = showSenders(opflags);
156
        out = showSenders(opflags);
132
    } else if (opflags & OPT_r) {
157
    } else if (opflags & OPT_r) {
133
        if (args.size() < 2)
158
        if (args.size() < 2)
134
            return 1;
159
            return 1;
160
#ifdef HAVE_WITHSTATUS_IN_LINN
161
        vector<string> reasons;
162
        bool ok = setReceiversFromSenderWithStatus(args[0],
163
                                vector<string>(args.begin() + 1, args.end()),
164
                                reasons);
165
        parseToOutput(ok, reasons, out);
166
#else
135
        setReceiversFromSender(args[0], vector<string>(args.begin() + 1,
167
        setReceiversFromSender(args[0], vector<string>(args.begin() + 1,
136
                                                       args.end()));
168
                                                       args.end()));
169
#endif
137
    } else if (opflags & OPT_s) {
170
    } else if (opflags & OPT_s) {
138
        if (args.size() < 2)
171
        if (args.size() < 2)
139
            return 1;
172
            return 1;
173
#ifdef HAVE_WITHSTATUS_IN_LINN
174
        vector<string> reasons;
175
        bool ok = setReceiversFromReceiverWithStatus(args[0],
176
                                vector<string>(args.begin() + 1, args.end()),
177
                                reasons);
178
        parseToOutput(ok, reasons, out);
179
#else
140
        setReceiversFromReceiver(args[0], vector<string>(args.begin() + 1,
180
        setReceiversFromReceiver(args[0], vector<string>(args.begin() + 1,
141
                                                         args.end()));
181
                                                         args.end()));
182
#endif
142
    } else if (opflags & OPT_x) {
183
    } else if (opflags & OPT_x) {
143
        if (args.size() < 1)
184
        if (args.size() < 1)
144
            return 1;
185
            return 1;
186
#ifdef HAVE_WITHSTATUS_IN_LINN
187
        vector<string> reasons;
188
        bool ok = stopReceiversWithStatus(args, reasons);
189
        parseToOutput(ok, reasons, out);
190
#else
145
        stopReceivers(args);
191
        stopReceivers(args);
192
#endif
146
#ifdef HAVE_SETSOURCEINDEX_IN_LINN
193
#ifdef HAVE_SETSOURCEINDEX_IN_LINN
147
    } else if ((opflags & OPT_i)) {
194
    } else if ((opflags & OPT_i)) {
148
        if (args.size() < 2)
195
        if (args.size() < 2)
149
            return 1;
196
            return 1;
150
        setSourceIndex(args[0], std::stoi(args[1]));
197
        bool ok = setSourceIndex(args[0], std::stoi(args[1]));
198
        vector<string> reasons;
199
        parseToOutput(ok, reasons, out);
151
    } else if ((opflags & OPT_I)) {
200
    } else if ((opflags & OPT_I)) {
152
        if (args.size() < 2)
201
        if (args.size() < 2)
153
            return 1;
202
            return 1;
154
        setSourceIndexByName(args[0], args[1]);
203
        bool ok = setSourceIndexByName(args[0], args[1]);
155
#endif
204
        vector<string> reasons;
205
        parseToOutput(ok, reasons, out);
206
#endif /* HAVE_SETRECEIVERSPLAYING_IN_LINN */
156
#ifdef HAVE_SETRECEIVERSPLAYING_IN_LINN
207
#ifdef HAVE_SETRECEIVERSPLAYING_IN_LINN
157
    } else if (opflags & OPT_R) {
208
    } else if (opflags & OPT_R) {
158
        if (args.size() < 1)
209
        if (args.size() < 1)
159
            return 1;
210
            return 1;
211
#ifdef HAVE_WITHSTATUS_IN_LINN
212
        vector<string> reasons;
213
        bool ok = setReceiversPlayingWithStatus(args, reasons);
214
        parseToOutput(ok, reasons, out);
215
#else
160
        setReceiversPlaying(args);
216
        setReceiversPlaying(args);
161
#endif
217
#endif /* HAVE_WITHSTATUS_IN_LINN */
218
#endif /* HAVE_SETRECEIVERSPLAYING_IN_LINN */
162
    }
219
    }
163
    return 0;
220
    return 0;
164
}
221
}
165
222
166
static char *thisprog;
223
static char *thisprog;