bladeRF-cli: Fixed struct field initializers and removed use of unistd.h

This commit is contained in:
Jon Szymaniak 2013-09-01 02:39:29 -04:00
commit 9252dea908
5 changed files with 23 additions and 22 deletions

View file

@ -89,13 +89,13 @@
/* Rename a few functions and types */
#include <Windows.h>
#define strtok_r strtok_s
#define strtoull _strtoui64
//#define snprintf _snprintf
//#define vsnprintf _vsnprintf
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define usleep Sleep
#define strtok_r strtok_s
#define strtoull _strtoui64
#define snprintf _snprintf_s
#define vsnprintf _vsnprintf_s
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define usleep Sleep
/* ssize_t lives elsewhere */
#include <BaseTsd.h>

View file

@ -39,7 +39,7 @@ static int load_fx3(struct cli_state *s, char *file)
int lib_status;
if ((expanded_path = interactive_expand_path(file)) == NULL) {
cli_err(s, "Unable to expand firmware file path: \%s\"", file);
cli_err(s, "Unable to expand firmware file path: \"%s\"", file);
cmd_status = CMD_RET_INVPARAM;
} else {
printf("Flashing firmware from %s...\n", expanded_path);

View file

@ -5,7 +5,11 @@
#include "conversions.h"
#define PRINTSET_DECL(x) int print_##x(struct cli_state *, int, char **); int set_##x(struct cli_state *, int, char **);
#define PRINTSET_ENTRY(x) { .print = print_##x, .set = set_##x, .name = #x }
#define PRINTSET_ENTRY(x) { \
FIELD_INIT(.print, print_##x), \
FIELD_INIT(.set, set_##x), \
FIELD_INIT(.name, #x) \
}
/* An entry in the printset table */
struct printset_entry {
@ -56,7 +60,9 @@ struct printset_entry printset_table[] = {
PRINTSET_ENTRY(trimdac),
PRINTSET_ENTRY(txvga1),
PRINTSET_ENTRY(txvga2),
{ .print = NULL, .set = NULL, .name = "" }
/* End of table marked by entry with NULL/empty fields */
{ FIELD_INIT(.print, NULL), FIELD_INIT(.set, NULL), FIELD_INIT(.name, "") }
};
bladerf_module get_module( char *mod, bool *ok )

View file

@ -16,7 +16,6 @@
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include "cmd.h"
#include "conversions.h"
#include "minmax.h"
@ -345,9 +344,8 @@ static int rx_write_csv_c16(struct cli_state *s, size_t n_samples)
size_t i;
struct rx_cfg *rx = &s->rxtx_data->rx;
struct common_cfg *common = &rx->common;
const size_t line_sz = 32;
const size_t to_write = n_samples * 2;
char line[line_sz];
char line[32] = { 0 };
/* We assume we have pairs... */
assert((common->buff_size & 1) == 0);
@ -355,7 +353,7 @@ static int rx_write_csv_c16(struct cli_state *s, size_t n_samples)
rx_sc16q12_sample_fixup(common->buff, common->buff_size/2);
for (i = 0; i < to_write; i += 2) {
snprintf(line, line_sz, "%d, %d" EOL,
snprintf(line, sizeof(line), "%d, %d" EOL,
common->buff[i], common->buff[i + 1]);
if (fputs(line, common->file) < 0) {
@ -461,8 +459,7 @@ static ssize_t tx_read_bin_c16(struct cli_state *s, unsigned int *repeats_left)
static int tx_csv_to_sc16q12(struct cli_state *s)
{
const char delim[] = " \r\n\t,.:";
const size_t buff_size = 81;
char buff[buff_size];
char buff[81] = { 0 };
enum rxtx_fmt fmt = RXTX_FMT_BIN_SC16Q12;
struct tx_cfg *tx = &s->rxtx_data->tx;
char *token, *saveptr;
@ -486,7 +483,7 @@ static int tx_csv_to_sc16q12(struct cli_state *s)
return CMD_RET_FILEOP;
}
while (fgets(buff, buff_size, tx->common.file))
while (fgets(buff, sizeof(buff), tx->common.file))
{
/* I */
token = strtok_r(buff, delim, &saveptr);

View file

@ -1,7 +1,6 @@
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <limits.h>
@ -58,15 +57,14 @@ bool cli_device_in_use(struct cli_state *s)
void cli_err(struct cli_state *s, const char *pfx, const char *format, ...)
{
va_list arg_list;
const size_t lbuf_sz = 32;
char lbuf[lbuf_sz];
char lbuf[32];
char *err;
memset(lbuf, 0, lbuf_sz);
memset(lbuf, 0, sizeof(lbuf));
/* If we're in a script, we can provide line number info */
if (s->script) {
snprintf(lbuf, lbuf_sz, " (line %d)", s->lineno);
snprintf(lbuf, sizeof(lbuf), " (line %d)", s->lineno);
}
/* +6 --> 3 newlines, 2 chars padding, NUL terminator */