fix: fix error when " not pair

This commit is contained in:
iridiumR 2023-03-30 18:36:56 +08:00
parent bf9d74db8e
commit 58bc0c37d1
No known key found for this signature in database
GPG key ID: 49735733EB1A32C8

17
line.c
View file

@ -42,26 +42,25 @@ char **splitLine(char *line) {
int pair_flag = 0; int pair_flag = 0;
while (1) { while (1) {
token = strtok(NULL, " \t\r\n\a"); token = strtok(NULL, " \t\r\n\a");
if (token[strlen(token) - 1] == '"') { if (token == NULL && pair_flag == 0) {
fprintf(stderr, "error: no pair \"\n");
return NULL;
}
/*if there exists a pair of "", break the loop*/
if ((strlen(token)>1 && token[strlen(token) - 1] == '"') || (strlen(token)==1 && token[0] == '"')) {
/*delete the last " */ /*delete the last " */
token[strlen(token) - 1] = '\0'; token[strlen(token) - 1] = '\0';
strcat(temp, " "); strcat(temp, " ");
strcat(temp, token); strcat(temp, token);
token = temp; token = temp;
pair_flag = 1;
break; break;
} else { } else {
strcat(temp, " "); strcat(temp, " ");
strcat(temp, token); strcat(temp, token);
pair_flag = 1;
}
if(token==NULL&&pair_flag==0){
fprintf(stderr,"error: no pair \"\n");
return NULL;
} }
} }
} } else {
else
{
char *temp = malloc(bufsize * sizeof(char *)); char *temp = malloc(bufsize * sizeof(char *));
strcpy(temp, token); strcpy(temp, token);
token = temp; token = temp;