Re: [Parser-devel] [token.c] A new functionality
Status: Beta
Brought to you by:
jineshkj
From: Jinesh K J <jin...@gm...> - 2006-10-05 07:30:43
|
> Hmm, now I can appreciate the usefulness of exceptions... I really miss that one here. > OK, fixed it, I was returning a non-malloc'd string. The error didn't > show up unless I set the environment variable MALLOC_CHECK_ so I didn't > notice. It seem to be working now. There are a few more work to be done as follows: =====1===== So, firstly let us make a modification over our gettoken - there need to have a slight change in its prototype: char * gettoken(const char *str, const char **end); When gettoken returns, *end need to have the address of the next character after the current token in str. For example, for an input of [Hello World], gettoken would be returning the malloc'ed [Hello], whereas *end should contain the address of the ' ' (space) character after 'Hello'. Even if it has reached the end of line, the address of the last '\0' should be returned. Note: *end need to be assigned only if we have found a valid token. ie, if gettoken() is returning NULL, *end need not be modified. ======2======= Secondly, we need a new function to dissect a comment from a line: char *cutcomment(char *str); The function searches in a string to find a comment (starting with '#'). If one is found, these are the steps to be performed: 1. Replace '#' with a '\0' in the original string (str) 2. Return a malloc'ed string that contains the contents after '#'(whatever it is) If no comment could be found, then the function need to return NULL. PS: The original string in this case get modified if a comment is found. =====end===== Try these and let me know. Jinesh. |