Beispiel #1
0
char *word_find_any(char *s)
{
	for(; *s; s++){
		switch(*s){
			case '"':
			case '\'':
				s = str_quotefin2(s + 1, *s);
				if(!s)
					return NULL;
				break;
		}
		if(iswordpart(*s))
			return s;
	}
	return NULL;
}
Beispiel #2
0
static char *strip_comment(char *line)
{
	const int is_directive = *str_spc_skip(line) == '#';
	char *s;

	if(strip_in_block == IN_BLOCK_BEGIN)
		strip_in_block = IN_BLOCK_FULL;
	else if(strip_in_block == IN_BLOCK_END)
		strip_in_block = NOT_IN_BLOCK;

	for(s = line; *s; s++){
		if(strip_in_block == IN_BLOCK_FULL || strip_in_block == IN_BLOCK_BEGIN){
			const int clear_comments = (strip_comments == STRIP_ALL);

			if(*s == '*' && s[1] == '/'){
				strip_in_block = IN_BLOCK_END;
				if(clear_comments)
					*s++ = ' ';
			}
			if(clear_comments)
				*s = ' ';

		}else if(*s == '"' || *s == '\''){
			/* read until the end of the string */
			char *end = str_quotefin2(s + 1, *s);

			if(!end){
				CPP_WARN(WQUOTE, "no terminating quote to string");
				/* skip to eol */
				s = strchr(s, '\0') - 1;
			}else{
				s = end;
			}

		}else if(*s == '/'){
			if(cpp_std >= STD_C99 && s[1] == '/'){
				switch(strip_comments){
					case STRIP_EXCEPT_DIRECTIVE:
						if(is_directive)
							goto strip_1line;
						/* fall */
					case STRIP_NONE:
					{
						/* convert to a block comment */
						const unsigned pos_slash = s - line;
						const unsigned len = strlen(line);

						line = urealloc1(line, len + 2 + 1);

						s = line + pos_slash;
						s[1] = '*';
						strcpy(line + len, "*/");
						break;
					}
strip_1line:
					case STRIP_ALL:
						/* ignore //.* */
						*s = '\0';
						break;
				}
				break;
			}else if(s[1] == '*'){
				strip_in_block = IN_BLOCK_BEGIN;

				switch(strip_comments){
					case STRIP_EXCEPT_DIRECTIVE:
						if(!is_directive)
							break;
						/* fall */
					case STRIP_ALL:
						/* wait for terminator elsewhere (i'll be back) */
						*s = s[1] = ' ';
						s++;
					case STRIP_NONE:
						break;
				}
			}
		}
	}

	return line;
}