Some smaller changes concerning the scanning of the settings file to make it behave more like BeOS.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2412 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2003-01-12 14:42:09 +00:00
parent bb87c791cb
commit 4a05764e4b

View File

@ -187,8 +187,10 @@ static status_t
get_word(char **_pos, char **_word, bool allowNewLine) get_word(char **_pos, char **_word, bool allowNewLine)
{ {
char *pos = *_pos; char *pos = *_pos;
bool quoted = false, newLine = false, end = false; char quoted = 0;
bool escaped = false; bool newLine = false, end = false;
int escaped = 0;
bool charEscaped = false;
// Skip any white space and comments // Skip any white space and comments
while (pos[0] && ((allowNewLine && (isspace(pos[0]) || pos[0] == '#')) while (pos[0] && ((allowNewLine && (isspace(pos[0]) || pos[0] == '#'))
@ -205,31 +207,31 @@ get_word(char **_pos, char **_word, bool allowNewLine)
return B_NO_ERROR; return B_NO_ERROR;
// Read in a word - might contain escaped (\) spaces, or it // Read in a word - might contain escaped (\) spaces, or it
// might also be quoted ("). // might also be quoted (" or ').
if (pos[0] == '"') { if (pos[0] == '"' || pos[0] == '\'') {
quoted = true; quoted = pos[0];
pos++; pos++;
} }
*_word = pos; *_word = pos;
while (pos[0]) { while (pos[0]) {
if (pos[0] == '\\' && pos[1] == ' ') { if (charEscaped)
escaped = true; charEscaped = false;
pos++; else if (pos[0] == '\\') {
} else if (quoted && pos[0] == '\\' && pos[1] == '"') { charEscaped = true;
escaped = true; escaped++;
pos++; } else if ((!quoted && isspace(pos[0])) || (quoted && pos[0] == quoted))
} else if (pos[0] == '\n')
break; break;
else if ((!quoted && isspace(pos[0])) || (quoted && pos[0] == '"'))
break;
pos++; pos++;
} }
// "String exceeds line" - missing end quote // "String exceeds line" - missing end quote
if (quoted && pos[0] != '"') if (quoted && pos[0] != quoted)
return B_BAD_DATA;
// last character is a backslash
if (charEscaped)
return B_BAD_DATA; return B_BAD_DATA;
end = pos[0] == '\0'; end = pos[0] == '\0';
@ -239,12 +241,13 @@ get_word(char **_pos, char **_word, bool allowNewLine)
// Correct name if there were any escaped characters // Correct name if there were any escaped characters
if (escaped) { if (escaped) {
char *word = *_word; char *word = *_word;
while (word < pos) { int offset = 0;
if (word[0] == '\\' while (word <= pos) {
&& ((quoted && word[1] == '"') if (word[0] == '\\') {
|| (!quoted && word[1] == ' '))) offset--;
memmove(word, word + 1, pos - word); word++;
}
word[offset] = word[0];
word++; word++;
} }
} }
@ -489,6 +492,7 @@ get_driver_boolean_parameter(void *handle, const char *keyName, bool unknownValu
// ToDo: This takes just the first argument/value, and checks that one; // ToDo: This takes just the first argument/value, and checks that one;
// I don't know if they are used to work that way in BeOS, though. // I don't know if they are used to work that way in BeOS, though.
// bonefish: Yep, exactly like that.
// check for the argument // check for the argument
if (parameter->value_count <= 0) if (parameter->value_count <= 0)