Commit a027f33b authored by rforder's avatar rforder

Adding string notation

parent a3645d23
......@@ -36,48 +36,92 @@ domino *parse_dominos(char *buffer, long size)
current->next = NULL;
}
j = 0;
while (!isspace(buffer[i]))
int string_mode;
string_mode = (buffer[i] == '"');
if (string_mode) i++;
while ((!string_mode && !isspace(buffer[i])) || (string_mode && buffer[i] != '"'))
{
current->a[j] = buffer[i];
i++;
j++;
if (string_mode && (buffer[i] == '\\') && (i < size - 1))
{
switch (buffer[i + 1])
{
case '"':
current->a[j] = '"';
break;
case 'n':
current->a[j] = '\n';
break;
case '\\':
current->a[j] = '\\';
break;
}
j++;
i += 2;
}
else
{
current->a[j] = buffer[i];
j++;
i++;
}
if (i >= size)
{
fprintf(stderr, "parsing error\n");
fprintf(stderr, "parsing error (end of file)\n");
exit(1);
}
if (j >= 1023)
{
fprintf(stderr, "parsing error\n");
fprintf(stderr, "parsing error (domino too long)\n");
exit(1);
}
}
current->a[j] = 0;
if (string_mode) i++;
while (isspace(buffer[i]))
{
i++;
if (i >= size)
{
fprintf(stderr, "parsing error\n");
fprintf(stderr, "parsing error (end of file in middle of domino)\n");
exit(1);
}
}
j = 0;
while (!isspace(buffer[i]))
string_mode = (buffer[i] == '"');
if (string_mode) i++;
while ((!string_mode && !isspace(buffer[i])) || (string_mode && buffer[i] != '"'))
{
current->b[j] = buffer[i];
i++;
j++;
if (i >= size)
{
return head;
}
if (string_mode && (buffer[i] == '\\') && (i < size - 1))
{
switch (buffer[i + 1])
{
case '"':
current->b[j] = '"';
break;
case 'n':
current->b[j] = '\n';
break;
case '\\':
current->b[j] = '\\';
break;
}
j++;
i += 2;
}
else
{
current->b[j] = buffer[i];
j++;
i++;
}
if (j >= 1023)
{
fprintf(stderr, "parsing error\n");
fprintf(stderr, "parsing error (domino too long)\n");
exit(1);
}
}
if (string_mode) i++;
current->b[j] = 0;
}
}
......@@ -233,7 +277,7 @@ int main(int argc, char **argv)
fread(input_buffer, file_size, 1, input);
fclose(input);
domino *domino_list = parse_dominos(input_buffer, file_size);
int k = 1;
int accepted = 0;
while (k != (argc == 3 ? strlen(argv[2]) : -1))
......
No preview for this file type
"Hello, World! " "Hello, World! "
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment