aboutsummaryrefslogtreecommitdiffstats
path: root/src/mds-kbdc.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-09-28 01:12:08 +0200
committerMattias Andrée <maandree@operamail.com>2014-09-28 01:12:08 +0200
commitf3cd020f30644bbf3b175c09bc8aadcdeabfd44e (patch)
tree04c27fcb2f01dceb3c13c2007a92ff5df2a9f5ef /src/mds-kbdc.c
parentmkd-kbdc: split lines (diff)
downloadmds-f3cd020f30644bbf3b175c09bc8aadcdeabfd44e.tar.gz
mds-f3cd020f30644bbf3b175c09bc8aadcdeabfd44e.tar.bz2
mds-f3cd020f30644bbf3b175c09bc8aadcdeabfd44e.tar.xz
m
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-kbdc.c')
-rw-r--r--src/mds-kbdc.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/mds-kbdc.c b/src/mds-kbdc.c
index 54590b1..7785102 100644
--- a/src/mds-kbdc.c
+++ b/src/mds-kbdc.c
@@ -107,8 +107,7 @@ static char* read_file(const char* restrict pathname, size_t* restrict size)
*/
static size_t remove_comments(char* restrict content, size_t size)
{
-#define t content[n_ptr++] = c
-#define last content[n_ptr - 1]
+#define t content[n_ptr++] = c
size_t n_ptr = 0, o_ptr = 0;
int comment = 0, quote = 0, escape = 0;
@@ -116,10 +115,12 @@ static size_t remove_comments(char* restrict content, size_t size)
while (o_ptr < size)
{
char c = content[o_ptr++];
+ /* Remove comment */
if (comment)
{
if (c == '\n') t, comment = 0;
}
+ /* Quotes can contain comment symbols, quotes by also contain escapes. */
else if (escape) t, escape = 0;
else if (quote)
{
@@ -127,15 +128,16 @@ static size_t remove_comments(char* restrict content, size_t size)
if (c == '\\') escape = 1;
else if (c == '"') quote = 0;
}
+ /* # is the comment symbol. */
else if (c == '#') comment = 1;
+ /* " is the quote symbol. */
else if (c == '"') t, quote = 1;
- else
- t;
+ /* Code and whitespace. */
+ else t;
}
return n_ptr;
-#undef last
#undef t
}