finalize cmd record
This commit is contained in:
parent
6191e2df9b
commit
25d852e1b2
3 changed files with 28 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
bin
|
bin
|
||||||
config
|
config
|
||||||
|
bee
|
||||||
|
|
|
@ -32,9 +32,20 @@ static bool get_words(char* buf, char** words, int count) {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for(i = 0; i < count; i++) {
|
while(1) {
|
||||||
char c;
|
char c;
|
||||||
while(c = buf[offset], c != ' ' && c != '\0' && c != '\n') {
|
while(1) {
|
||||||
|
if (offset == MAX_LEN) return false;
|
||||||
|
c = buf[offset];
|
||||||
|
|
||||||
|
if (c == '\0' || c == '\n') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == ' ' && i + 1 != count) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,8 +59,11 @@ static bool get_words(char* buf, char** words, int count) {
|
||||||
|
|
||||||
if (c == '\0' || c == '\n') {
|
if (c == '\0' || c == '\n') {
|
||||||
break;
|
break;
|
||||||
|
} else if (i + 1 == count) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return i + 1 == count;
|
return i + 1 == count;
|
||||||
}
|
}
|
||||||
|
|
|
@ -357,8 +357,12 @@ static void write_caa_record(PacketBuffer* buffer, CAARecord* data) {
|
||||||
|
|
||||||
static void write_string(TXTRecord* record, uint8_t* capacity, const char* string, uint8_t len) {
|
static void write_string(TXTRecord* record, uint8_t* capacity, const char* string, uint8_t len) {
|
||||||
if (len < 1) return;
|
if (len < 1) return;
|
||||||
if (record->len == *capacity) {
|
if (record->len >= *capacity) {
|
||||||
*capacity *= 2;
|
if (*capacity >= 128) {
|
||||||
|
*capacity = 255;
|
||||||
|
} else {
|
||||||
|
*capacity *= 2;
|
||||||
|
}
|
||||||
record->text = realloc(record->text, sizeof(uint8_t*) * *capacity);
|
record->text = realloc(record->text, sizeof(uint8_t*) * *capacity);
|
||||||
}
|
}
|
||||||
record->text[record->len] = malloc(len + 1);
|
record->text[record->len] = malloc(len + 1);
|
||||||
|
@ -394,8 +398,11 @@ static void write_cmd_record(PacketBuffer* buffer, CMDRecord* data) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if ((c = getc(output)) == EOF) {
|
if (res.len >= 255) break;
|
||||||
write_string(&res, &capacity, in, i + 1);
|
|
||||||
|
c = getc(output);
|
||||||
|
if (c == EOF || c == '\0') {
|
||||||
|
write_string(&res, &capacity, in, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue