+/** Get the next token and indicate whether it is enclosed in "# #".
+*/
+static int get_next_token(char* str, int* pos, char* token, int* is_keyword)
+{
+ int token_pos = 0;
+ int str_len = strlen(str);
+
+ if( (*pos) >= str_len || str[*pos] == '\0' )
+ {
+ return 0;
+ }
+
+ if( str[*pos] == '#' )
+ {
+ *is_keyword = 1;
+ (*pos)++;
+ }
+ else
+ {
+ *is_keyword = 0;
+ }
+
+ while( *pos < str_len && token_pos < MAX_TEXT_LEN - 1)
+ {
+ if( str[*pos] == '\\' && str[(*pos) + 1] == '#' )
+ {
+ // Escape Sequence - "#" preceeded by "\" - copy the # into the token.
+ token[token_pos] = '#';
+ token_pos++;
+ (*pos)++; // skip "\"
+ (*pos)++; // skip "#"
+ }
+ else if( str[*pos] == '#' )
+ {
+ if( *is_keyword )
+ {
+ // Found the end of the keyword
+ (*pos)++;
+ }
+ break;
+ }
+ else
+ {
+ token[token_pos] = str[*pos];
+ token_pos++;
+ (*pos)++;
+ }
+ }
+
+ token[token_pos] = '\0';
+
+ return 1;
+}