Fix isspace() and other isxxx() calls in term.c
This commit is contained in:
parent
f8145ae1c4
commit
ea226936b7
src
41
src/term.c
41
src/term.c
|
@ -124,19 +124,19 @@ static int spi_mode = 0;
|
||||||
|
|
||||||
static int nexttok(char * buf, char ** tok, char ** next)
|
static int nexttok(char * buf, char ** tok, char ** next)
|
||||||
{
|
{
|
||||||
char * q, * n;
|
unsigned char *q, *n;
|
||||||
|
|
||||||
q = buf;
|
q = (unsigned char *) buf;
|
||||||
while (isspace((int)*q))
|
while (isspace(*q))
|
||||||
q++;
|
q++;
|
||||||
|
|
||||||
/* isolate first token */
|
/* isolate first token */
|
||||||
n = q;
|
n = q;
|
||||||
uint8_t quotes = 0;
|
uint8_t quotes = 0;
|
||||||
while (*n && (!isspace((int)*n) || quotes)) {
|
while (*n && (!isspace(*n) || quotes)) {
|
||||||
if (*n == '\"')
|
if (*n == '\"')
|
||||||
quotes++;
|
quotes++;
|
||||||
else if (isspace((int)*n) && *(n-1) == '\"')
|
else if (isspace(*n) && *(n-1) == '\"')
|
||||||
break;
|
break;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
@ -147,11 +147,11 @@ static int nexttok(char * buf, char ** tok, char ** next)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find start of next token */
|
/* find start of next token */
|
||||||
while (isspace((int)*n))
|
while (isspace(*n))
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
*tok = q;
|
*tok = (char *) q;
|
||||||
*next = n;
|
*next = (char *) n;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -190,14 +190,17 @@ static int hexdump_line(char * buffer, unsigned char * p, int n, int pad)
|
||||||
static int chardump_line(char * buffer, unsigned char * p, int n, int pad)
|
static int chardump_line(char * buffer, unsigned char * p, int n, int pad)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char b [ 128 ];
|
unsigned char b[128];
|
||||||
|
|
||||||
|
// sanity check
|
||||||
|
n = n < 1? 1: n > sizeof b? sizeof b: n;
|
||||||
|
|
||||||
|
memcpy(b, p, n);
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
memcpy(b, p, n);
|
|
||||||
buffer[i] = '.';
|
buffer[i] = '.';
|
||||||
if (isalpha((int)(b[i])) || isdigit((int)(b[i])) || ispunct((int)(b[i])))
|
if (isalpha(b[i]) || isdigit(b[i]) || ispunct(b[i]))
|
||||||
buffer[i] = b[i];
|
buffer[i] = b[i];
|
||||||
else if (isspace((int)(b[i])))
|
else if (isspace(b[i]))
|
||||||
buffer[i] = ' ';
|
buffer[i] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +347,7 @@ static int cmd_dump(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
|
|
||||||
|
|
||||||
// Convert the next n hex digits of s to a hex number
|
// Convert the next n hex digits of s to a hex number
|
||||||
static unsigned int tohex(const char *s, unsigned int n) {
|
static unsigned int tohex(const unsigned char *s, unsigned int n) {
|
||||||
int ret, c;
|
int ret, c;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -362,7 +365,7 @@ static unsigned int tohex(const char *s, unsigned int n) {
|
||||||
* Permissive for some invalid unicode sequences but not for those with
|
* Permissive for some invalid unicode sequences but not for those with
|
||||||
* high bit set). Returns numbers of characters written (0-6).
|
* high bit set). Returns numbers of characters written (0-6).
|
||||||
*/
|
*/
|
||||||
static int wc_to_utf8str(unsigned int wc, char *str) {
|
static int wc_to_utf8str(unsigned int wc, unsigned char *str) {
|
||||||
if(!(wc & ~0x7fu)) {
|
if(!(wc & ~0x7fu)) {
|
||||||
*str = (char) wc;
|
*str = (char) wc;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -406,8 +409,8 @@ static int wc_to_utf8str(unsigned int wc, char *str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unescape C-style strings, destination d must hold enough space (and can be source s)
|
// Unescape C-style strings, destination d must hold enough space (and can be source s)
|
||||||
static char *unescape(char *d, const char *s) {
|
static unsigned char *unescape(unsigned char *d, const unsigned char *s) {
|
||||||
char *ret = d;
|
unsigned char *ret = d;
|
||||||
int n, k;
|
int n, k;
|
||||||
|
|
||||||
while(*s) {
|
while(*s) {
|
||||||
|
@ -650,7 +653,7 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
// Data info
|
// Data info
|
||||||
int bytes_grown;
|
int bytes_grown;
|
||||||
uint8_t size;
|
uint8_t size;
|
||||||
char * str_ptr;
|
char *str_ptr;
|
||||||
// Data union
|
// Data union
|
||||||
union {
|
union {
|
||||||
float f;
|
float f;
|
||||||
|
@ -793,7 +796,7 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
}
|
}
|
||||||
// Strip start and end quotes, and unescape C string
|
// Strip start and end quotes, and unescape C string
|
||||||
strncpy(s, argi+1, arglen-2);
|
strncpy(s, argi+1, arglen-2);
|
||||||
unescape(s, s);
|
unescape((unsigned char *) s, (unsigned char *) s);
|
||||||
if (*argi == '\'') { // Single C-style character
|
if (*argi == '\'') { // Single C-style character
|
||||||
if(*s && s[1])
|
if(*s && s[1])
|
||||||
avrdude_message(MSG_INFO, "%s (write): only using first character of %s\n",
|
avrdude_message(MSG_INFO, "%s (write): only using first character of %s\n",
|
||||||
|
@ -1463,7 +1466,7 @@ int terminal_mode(PROGRAMMER * pgm, struct avrpart * p)
|
||||||
* find the start of the command, skipping any white space
|
* find the start of the command, skipping any white space
|
||||||
*/
|
*/
|
||||||
q = cmdbuf;
|
q = cmdbuf;
|
||||||
while (*q && isspace((int)*q))
|
while (*q && isspace((unsigned char) *q))
|
||||||
q++;
|
q++;
|
||||||
|
|
||||||
/* skip blank lines and comments */
|
/* skip blank lines and comments */
|
||||||
|
|
Loading…
Reference in New Issue