|
|
@ -25,11 +25,18 @@ char* fetch_from_string(char* message, char* indicator) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char* fetch_message_string(char* message) {
|
|
|
|
char* fetch_message_string(char* message) {
|
|
|
|
|
|
|
|
int num_of_terminators;
|
|
|
|
|
|
|
|
|
|
|
|
char* start = strstr(message,"START_OF_MESSAGE");
|
|
|
|
char* start = strstr(message,"START_OF_MESSAGE");
|
|
|
|
if (start == NULL) {
|
|
|
|
if (start == NULL) {
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int start_index = start - message;
|
|
|
|
int start_index = start - message;
|
|
|
|
|
|
|
|
start_index += strlen("START_OF_MESSAGE");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (*(message + start_index) == '\n' || *(message + start_index) == '\r') {
|
|
|
|
|
|
|
|
start_index++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char* end = strstr(message,"END_OF_MESSAGE");
|
|
|
|
char* end = strstr(message,"END_OF_MESSAGE");
|
|
|
|
if (end == NULL) {
|
|
|
|
if (end == NULL) {
|
|
|
@ -37,9 +44,20 @@ char* fetch_message_string(char* message) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int end_index = end - message;
|
|
|
|
int end_index = end - message;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (*(message+ end_index-2) = '\r') {
|
|
|
|
|
|
|
|
num_of_terminators = 2;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
num_of_terminators = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int message_length = end_index - start_index;
|
|
|
|
int message_length = end_index - start_index;
|
|
|
|
char* message_string = malloc(message_length + 1);
|
|
|
|
char* message_string = malloc(message_length + 1);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0;i < message_length; i++) {
|
|
|
|
for (int i=0;i < message_length-num_of_terminators; i++) { /* The reason the upper-bound is message_length-1 is because the last
|
|
|
|
*(message_string + i) = *(message_
|
|
|
|
character is a new-line, which the user would not have typed. */
|
|
|
|
|
|
|
|
*(message_string + i) = *(message + start_index + i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*(message_string + (message_length - num_of_terminators)) = '\0';
|
|
|
|
|
|
|
|
return message_string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|