Replace string arrays with const char * and allocated space (part 1)
This commit deals with default_programmer, default_serial, default_parallel and default_spi. The long term objective is to remove all fixed-size buffers from the structures that lexer.l and config_gram.y deal with.
This commit is contained in:
parent
22c4dbf23e
commit
7375477f70
|
@ -33,10 +33,10 @@
|
||||||
|
|
||||||
#include "config_gram.h"
|
#include "config_gram.h"
|
||||||
|
|
||||||
char default_programmer[MAX_STR_CONST];
|
const char *default_programmer;
|
||||||
char default_parallel[PATH_MAX];
|
const char *default_parallel;
|
||||||
char default_serial[PATH_MAX];
|
const char *default_serial;
|
||||||
char default_spi[PATH_MAX];
|
const char *default_spi;
|
||||||
double default_bitclock;
|
double default_bitclock;
|
||||||
|
|
||||||
LISTID string_list;
|
LISTID string_list;
|
||||||
|
|
|
@ -30,8 +30,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define MAX_STR_CONST 1024
|
|
||||||
|
|
||||||
enum { V_NONE, V_NUM, V_NUM_REAL, V_STR };
|
enum { V_NONE, V_NUM, V_NUM_REAL, V_STR };
|
||||||
typedef struct value_t {
|
typedef struct value_t {
|
||||||
int type;
|
int type;
|
||||||
|
|
|
@ -246,26 +246,22 @@ def :
|
||||||
part_def TKN_SEMI |
|
part_def TKN_SEMI |
|
||||||
|
|
||||||
K_DEFAULT_PROGRAMMER TKN_EQUAL TKN_STRING TKN_SEMI {
|
K_DEFAULT_PROGRAMMER TKN_EQUAL TKN_STRING TKN_SEMI {
|
||||||
strncpy(default_programmer, $3->value.string, MAX_STR_CONST);
|
default_programmer = cache_string($3->value.string);
|
||||||
default_programmer[MAX_STR_CONST-1] = 0;
|
|
||||||
free_token($3);
|
free_token($3);
|
||||||
} |
|
} |
|
||||||
|
|
||||||
K_DEFAULT_PARALLEL TKN_EQUAL TKN_STRING TKN_SEMI {
|
K_DEFAULT_PARALLEL TKN_EQUAL TKN_STRING TKN_SEMI {
|
||||||
strncpy(default_parallel, $3->value.string, PATH_MAX);
|
default_parallel = cache_string($3->value.string);
|
||||||
default_parallel[PATH_MAX-1] = 0;
|
|
||||||
free_token($3);
|
free_token($3);
|
||||||
} |
|
} |
|
||||||
|
|
||||||
K_DEFAULT_SERIAL TKN_EQUAL TKN_STRING TKN_SEMI {
|
K_DEFAULT_SERIAL TKN_EQUAL TKN_STRING TKN_SEMI {
|
||||||
strncpy(default_serial, $3->value.string, PATH_MAX);
|
default_serial = cache_string($3->value.string);
|
||||||
default_serial[PATH_MAX-1] = 0;
|
|
||||||
free_token($3);
|
free_token($3);
|
||||||
} |
|
} |
|
||||||
|
|
||||||
K_DEFAULT_SPI TKN_EQUAL TKN_STRING TKN_SEMI {
|
K_DEFAULT_SPI TKN_EQUAL TKN_STRING TKN_SEMI {
|
||||||
strncpy(default_spi, $3->value.string, PATH_MAX);
|
default_spi = cache_string($3->value.string);
|
||||||
default_spi[PATH_MAX-1] = 0;
|
|
||||||
free_token($3);
|
free_token($3);
|
||||||
} |
|
} |
|
||||||
|
|
||||||
|
|
|
@ -992,10 +992,10 @@ void walk_programmer_types(/*LISTID programmer_types,*/ walk_programmer_types_cb
|
||||||
|
|
||||||
extern LISTID part_list;
|
extern LISTID part_list;
|
||||||
extern LISTID programmers;
|
extern LISTID programmers;
|
||||||
extern char default_programmer[];
|
extern const char *default_programmer;
|
||||||
extern char default_parallel[];
|
extern const char *default_parallel;
|
||||||
extern char default_serial[];
|
extern const char *default_serial;
|
||||||
extern char default_spi[];
|
extern const char *default_spi;
|
||||||
extern double default_bitclock;
|
extern double default_bitclock;
|
||||||
|
|
||||||
/* This name is fixed, it's only here for symmetry with
|
/* This name is fixed, it's only here for symmetry with
|
||||||
|
|
15
src/main.c
15
src/main.c
|
@ -314,9 +314,10 @@ int main(int argc, char * argv [])
|
||||||
else
|
else
|
||||||
progname = argv[0];
|
progname = argv[0];
|
||||||
|
|
||||||
default_parallel[0] = 0;
|
default_programmer = "";
|
||||||
default_serial[0] = 0;
|
default_parallel = "";
|
||||||
default_spi[0] = 0;
|
default_serial = "";
|
||||||
|
default_spi = "";
|
||||||
default_bitclock = 0.0;
|
default_bitclock = 0.0;
|
||||||
|
|
||||||
init_config();
|
init_config();
|
||||||
|
@ -351,7 +352,7 @@ int main(int argc, char * argv [])
|
||||||
quell_progress = 0;
|
quell_progress = 0;
|
||||||
exitspecs = NULL;
|
exitspecs = NULL;
|
||||||
pgm = NULL;
|
pgm = NULL;
|
||||||
programmer = default_programmer;
|
programmer = cfg_strdup("main()", default_programmer);
|
||||||
verbose = 0;
|
verbose = 0;
|
||||||
baudrate = 0;
|
baudrate = 0;
|
||||||
bitclock = 0.0;
|
bitclock = 0.0;
|
||||||
|
@ -755,7 +756,7 @@ int main(int argc, char * argv [])
|
||||||
int dev_opts = 0;
|
int dev_opts = 0;
|
||||||
// Developer option -c <wildcard>/[ASsrt] prints programmer description(s) and exits
|
// Developer option -c <wildcard>/[ASsrt] prints programmer description(s) and exits
|
||||||
if(programmer && (strcmp(programmer, "*") == 0 || strchr(programmer, '/'))) {
|
if(programmer && (strcmp(programmer, "*") == 0 || strchr(programmer, '/'))) {
|
||||||
dev_output_pgm_defs(programmer);
|
dev_output_pgm_defs(cfg_strdup("main()", programmer));
|
||||||
dev_opts = 1;
|
dev_opts = 1;
|
||||||
}
|
}
|
||||||
// Developer option -p <wildcard>/[dASsrcow*t] prints part description(s) and exits
|
// Developer option -p <wildcard>/[dASsrcow*t] prints part description(s) and exits
|
||||||
|
@ -849,11 +850,11 @@ int main(int argc, char * argv [])
|
||||||
switch (pgm->conntype)
|
switch (pgm->conntype)
|
||||||
{
|
{
|
||||||
case CONNTYPE_PARALLEL:
|
case CONNTYPE_PARALLEL:
|
||||||
port = default_parallel;
|
port = cfg_strdup("main()", default_parallel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CONNTYPE_SERIAL:
|
case CONNTYPE_SERIAL:
|
||||||
port = default_serial;
|
port = cfg_strdup("main()", default_serial);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CONNTYPE_USB:
|
case CONNTYPE_USB:
|
||||||
|
|
Loading…
Reference in New Issue