Skip to content

Commit e2aeef2

Browse files
committed
NFC: untabify clang format
1 parent 00d61e0 commit e2aeef2

File tree

4 files changed

+69
-71
lines changed

4 files changed

+69
-71
lines changed

LICENSE

100644100755
File mode changed.

README.md

100644100755
File mode changed.

src/Makefile

100644100755
File mode changed.

src/q2radio.cpp

100644100755
+69-71
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// Control the Q2 Internet Wi-Fi Radio by command line
22
// Q2Radio is free software; you can redistribute it and/or modify it under
3-
// the terms of the GNU General Public License as published by the Free
3+
// the terms of the GNU General Public License as published by the Free
44
// Software Foundation; either version 3, or (at your option) any later
55
// version.
6-
//
7-
// Q2Radio is distributed in the hope that it will be useful, but WITHOUT ANY
8-
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
9-
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10-
// for more details.
11-
//
6+
//
7+
// Q2Radio is distributed in the hope that it will be useful, but WITHOUT ANY
8+
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
9+
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10+
// for more details.
11+
//
1212
// You should have received a copy of the GNU General Public License
13-
// along with Q2Radio; see the file COPYING3. If not see
14-
// <http://www.gnu.org/licenses/>.
13+
// along with Q2Radio; see the file COPYING3. If not see
14+
// <http://www.gnu.org/licenses/>.
1515

1616
// #define DBG(CMD) CMD
1717
#define DBG(CMD)
1818

19+
#include <assert.h>
20+
#include <getopt.h>
21+
#include <iomanip> // setfill(), setw()
1922
#include <iostream>
2023
#include <libusb-1.0/libusb.h>
21-
#include <stdlib.h>
22-
#include <iomanip> // setfill(), setw()
2324
#include <stdio.h>
25+
#include <stdlib.h>
2426
#include <string.h>
25-
#include <assert.h>
2627
#include <unistd.h>
27-
#include <getopt.h>
2828

2929
int ENDPOINT = 2;
3030

@@ -34,8 +34,9 @@ void printDev(libusb_device *dev) {
3434
std::cerr << "libusb_get_device_descriptor() failed\n";
3535
return;
3636
}
37-
std::cout << "Num of configurations: " << (int) desc.bNumConfigurations << "\n";
38-
std::cout << "Device class: " << (int) desc.bDeviceClass << "\n";
37+
std::cout << "Num of configurations: " << (int)desc.bNumConfigurations
38+
<< "\n";
39+
std::cout << "Device class: " << (int)desc.bDeviceClass << "\n";
3940
fprintf(stdout, "%04x:%04x\n", desc.idVendor, desc.idProduct);
4041
libusb_config_descriptor *config;
4142
libusb_get_config_descriptor(dev, 0, &config);
@@ -52,9 +53,11 @@ void printDev(libusb_device *dev) {
5253
int numOfEndpoints = (int)IFdesc->bNumEndpoints;
5354
std::cout << " Num of Endpoints: " << numOfEndpoints << "\n";
5455
for (int EP = 0; EP < numOfEndpoints; ++EP) {
55-
const libusb_endpoint_descriptor *EPdesc = &IFdesc->endpoint[EP];
56-
std::cout << " Descriptor Type: " << (int)EPdesc->bDescriptorType << "\n";
57-
std::cout << " EP Address: " << (int)EPdesc->bEndpointAddress << "\n";
56+
const libusb_endpoint_descriptor *EPdesc = &IFdesc->endpoint[EP];
57+
std::cout << " Descriptor Type: " << (int)EPdesc->bDescriptorType
58+
<< "\n";
59+
std::cout << " EP Address: " << (int)EPdesc->bEndpointAddress
60+
<< "\n";
5861
}
5962
}
6063
}
@@ -67,59 +70,60 @@ void printAllDevs(libusb_device **devs, ssize_t dev_cnt) {
6770
}
6871
}
6972

70-
71-
unsigned char end1 = (unsigned char) '\r';
72-
unsigned char end2 = (unsigned char) '\n';
73+
unsigned char end1 = (unsigned char)'\r';
74+
unsigned char end2 = (unsigned char)'\n';
7375

7476
void sendStr(libusb_device_handle *handle, const char *dataStr) {
7577
DBG(std::cout << "sendStr: " << dataStr << "\n");
7678
int dataLen = strlen((const char *)dataStr);
77-
unsigned char *data = (unsigned char *) dataStr;
79+
unsigned char *data = (unsigned char *)dataStr;
7880
int actual;
79-
if (! (libusb_bulk_transfer(handle, (ENDPOINT | LIBUSB_ENDPOINT_OUT),
80-
data, dataLen, &actual, 0) == 0) && actual == dataLen) {
81+
if (!(libusb_bulk_transfer(handle, (ENDPOINT | LIBUSB_ENDPOINT_OUT), data,
82+
dataLen, &actual, 0) == 0) &&
83+
actual == dataLen) {
8184
std::cerr << "Error writing data\n";
8285
exit(1);
8386
}
8487

85-
if (! (libusb_bulk_transfer(handle, (ENDPOINT | LIBUSB_ENDPOINT_OUT),
86-
&end1, 1, &actual, 0) == 0) && actual == 1) {
88+
if (!(libusb_bulk_transfer(handle, (ENDPOINT | LIBUSB_ENDPOINT_OUT), &end1, 1,
89+
&actual, 0) == 0) &&
90+
actual == 1) {
8791
std::cerr << "Error writing 0xd\n";
8892
exit(1);
8993
}
9094

91-
if (! (libusb_bulk_transfer(handle, (ENDPOINT | LIBUSB_ENDPOINT_OUT),
92-
&end2, 1, &actual, 0) == 0) && actual == 1) {
95+
if (!(libusb_bulk_transfer(handle, (ENDPOINT | LIBUSB_ENDPOINT_OUT), &end2, 1,
96+
&actual, 0) == 0) &&
97+
actual == 1) {
9398
std::cerr << "Error writing 0xa\n";
9499
exit(1);
95100
}
96-
97101
}
98102

99-
100103
bool getStr(libusb_device_handle *handle, char *buf, size_t size) {
101104
int i = 0;
102105

103106
while (1) {
104-
#define TMPSIZE 400
107+
#define TMPSIZE 400
105108
unsigned char tmpBuf[TMPSIZE];
106109

107110
int actual;
108111
int succ = libusb_bulk_transfer(handle, (ENDPOINT | LIBUSB_ENDPOINT_IN),
109-
tmpBuf, TMPSIZE, &actual, 100);
112+
tmpBuf, TMPSIZE, &actual, 100);
110113
if (succ != 0) {
111114
// std::cerr << "libusb_bulk_transfer(IN) failed!\n";
112115
return 0;
113116
}
114117
if (actual > TMPSIZE) {
115-
// std::cerr << "ERROR: actual (=" << actual << ") > TMPSIZE (=" << TMPSIZE << ")\n";
118+
// std::cerr << "ERROR: actual (=" << actual << ") > TMPSIZE (=" <<
119+
// TMPSIZE << ")\n";
116120
return 0;
117121
}
118122

119123
memcpy(buf + i, tmpBuf, actual);
120-
i+=actual;
124+
i += actual;
121125

122-
if (i >= 3 && buf[i-2] == '\r' && buf[i-1] == '\n') {
126+
if (i >= 3 && buf[i - 2] == '\r' && buf[i - 1] == '\n') {
123127
break;
124128
}
125129
}
@@ -129,14 +133,12 @@ bool getStr(libusb_device_handle *handle, char *buf, size_t size) {
129133

130134
void printStrV(const char *buf) {
131135
for (int i = 0; i < strlen(buf); ++i) {
132-
fprintf(stderr, "%c(=%02x)\n", (buf[i] >= 32 && buf[i] <= 126) ? buf[i] : ' ', buf[i]);
136+
fprintf(stderr, "%c(=%02x)\n",
137+
(buf[i] >= 32 && buf[i] <= 126) ? buf[i] : ' ', buf[i]);
133138
}
134139
}
135140

136-
void printStr(const char *buf) {
137-
fprintf(stderr, "%s", buf);
138-
}
139-
141+
void printStr(const char *buf) { fprintf(stderr, "%s", buf); }
140142

141143
struct Args {
142144
Args(void) {
@@ -154,17 +156,17 @@ struct Args {
154156

155157
void check(void) {
156158
if (side != -1) {
157-
if (! stationName) {
158-
std::cerr << "ERROR: Name empty!\n";
159-
exit(1);
159+
if (!stationName) {
160+
std::cerr << "ERROR: Name empty!\n";
161+
exit(1);
160162
}
161-
if (! stationUrl) {
162-
std::cerr << "ERROR: URL empty!\n";
163-
exit(1);
163+
if (!stationUrl) {
164+
std::cerr << "ERROR: URL empty!\n";
165+
exit(1);
164166
}
165167
}
166168
}
167-
169+
168170
void dump(void) {
169171
std::cout << "--------------\n";
170172
std::cout << "Side: " << side << "\n";
@@ -187,21 +189,17 @@ struct Args {
187189
std::cout << "\n";
188190
std::cout << "--------------\n";
189191
}
190-
bool isEmpty(void) {
191-
return side == -1;
192-
}
192+
bool isEmpty(void) { return side == -1; }
193193
};
194194

195-
196195
static struct option long_options[] = {
197-
{"side", required_argument, 0, 's'},
198-
{"name", required_argument, 0, 'n'},
199-
{"url", required_argument, 0, 'u'},
200-
{"list", no_argument, 0, 'l'},
201-
{"custom", required_argument, 0, 'c'},
202-
// WARNING: Keep "help" last for automatically generated usage() message
203-
{"help", no_argument, 0, 'h'}
204-
};
196+
{"side", required_argument, 0, 's'},
197+
{"name", required_argument, 0, 'n'},
198+
{"url", required_argument, 0, 'u'},
199+
{"list", no_argument, 0, 'l'},
200+
{"custom", required_argument, 0, 'c'},
201+
// WARNING: Keep "help" last for automatically generated usage() message
202+
{"help", no_argument, 0, 'h'}};
205203

206204
void usage(char **argv) {
207205
std::cerr << "Available options:\n";
@@ -227,7 +225,8 @@ void usage(char **argv) {
227225
}
228226
++i;
229227
}
230-
std::cerr << "Example: --side 0 --name \"Rebel State Radio\" --url \"http://eco.onestreaming.com:8142\"\n";
228+
std::cerr << "Example: --side 0 --name \"Rebel State Radio\" --url "
229+
"\"http://eco.onestreaming.com:8142\"\n";
231230
std::cerr << "Example: --custom \"gpre 0 name\":\n";
232231
}
233232

@@ -244,8 +243,8 @@ void parseArgs(int argc, char **argv, Args *args) {
244243
case 's':
245244
args->side = atoi(optarg);
246245
if (!(args->side >= 0 && args->side < 4)) {
247-
std::cerr << "Bad side: " << args->side << ". Should be 0-4\n";
248-
exit(1);
246+
std::cerr << "Bad side: " << args->side << ". Should be 0-4\n";
247+
exit(1);
249248
}
250249
break;
251250
case 'n':
@@ -277,16 +276,15 @@ void parseArgs(int argc, char **argv, Args *args) {
277276
}
278277
}
279278

280-
281279
#define SIZE 400
282280

283281
void printResponse(libusb_device_handle *handle, bool out = true) {
284282
char buf[SIZE];
285283

286-
while(1) {
284+
while (1) {
287285
memset(buf, 0, SIZE);
288-
bool ok = getStr(handle, buf, SIZE-1);
289-
if (! ok) {
286+
bool ok = getStr(handle, buf, SIZE - 1);
287+
if (!ok) {
290288
break;
291289
}
292290
if (out) {
@@ -308,7 +306,7 @@ int main(int argc, char **argv) {
308306
args.check();
309307
// args.dump();
310308

311-
libusb_device **devs; // list of devices
309+
libusb_device **devs; // list of devices
312310
libusb_context *ctx = NULL;
313311
int r;
314312
if ((r = libusb_init(&ctx)) < 0) {
@@ -328,7 +326,8 @@ int main(int argc, char **argv) {
328326
int VID = 0x1f2e;
329327
int PID = 0x000a;
330328
if ((handle = libusb_open_device_with_vid_pid(ctx, VID, PID)) == NULL) {
331-
DBG(fprintf(stderr, "libusb_open_device_with_vid_pid(%04x:%04x)\n", VID, PID));
329+
DBG(fprintf(stderr, "libusb_open_device_with_vid_pid(%04x:%04x)\n", VID,
330+
PID));
332331
exit(1);
333332
}
334333
// libusb_free_device_list(devs, 1);
@@ -351,7 +350,7 @@ int main(int argc, char **argv) {
351350
printResponse(handle);
352351
return 0;
353352
}
354-
353+
355354
// Query radio for all sides and print them
356355
if (args.list || args.side == -1) {
357356
printResponse(handle, false); // skip any outstanding output
@@ -370,7 +369,7 @@ int main(int argc, char **argv) {
370369
}
371370

372371
if (args.side != -1) {
373-
#define BUFSIZE 400
372+
#define BUFSIZE 400
374373
char buf[BUFSIZE];
375374
snprintf(buf, BUFSIZE, "spre %d name \"%s\"", args.side, args.stationName);
376375
sendStr(handle, buf);
@@ -381,7 +380,6 @@ int main(int argc, char **argv) {
381380
printResponse(handle);
382381
return 0;
383382
}
384-
385383

386384
if (libusb_release_interface(handle, 0) != 0) {
387385
std::cerr << "libusb_release_interface() failed!\n";

0 commit comments

Comments
 (0)