Add quote handling
This commit is contained in:
parent
6edf3378f9
commit
b40959eb68
|
@ -3,36 +3,39 @@
|
|||
int incomment = 0;
|
||||
|
||||
int uncomment(char s[],int lim) {
|
||||
int c, i, nw = 0, lastchar;
|
||||
int c, i, nw = 0, qu = 0, lastchar;
|
||||
for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n';) {
|
||||
// Check the state of the comment, 0 being "not in a comment", 1 being "in a comment" and 2 being "exiting from a comment", reset 2 afterwards
|
||||
if (incomment == 2) {
|
||||
incomment = 0;
|
||||
};
|
||||
if (c == '/') {
|
||||
if (lastchar == '/') {
|
||||
nw = 1;
|
||||
s[i--] = ' ';
|
||||
} else if(lastchar == '*') {
|
||||
incomment = 2;
|
||||
if (qu == 0) {
|
||||
if (c == '/') {
|
||||
if (lastchar == '/') {
|
||||
nw = 1;
|
||||
i--;
|
||||
} else if(lastchar == '*') {
|
||||
incomment = 2;
|
||||
}
|
||||
} else if (c == '*' && lastchar == '/') {
|
||||
incomment = 1;
|
||||
i--;
|
||||
} else if (c == '\'' || (c == '"' && lastchar != '\'')) {
|
||||
qu = 1;
|
||||
}
|
||||
} else {
|
||||
if ((c == '"' && lastchar != '\'') || c == '\'') {
|
||||
qu = 0;
|
||||
}
|
||||
} else if (c == '*' && lastchar == '/') {
|
||||
incomment = 1;
|
||||
s[i--] = ' ';
|
||||
}
|
||||
if (incomment == 0 && nw == 0) {
|
||||
s[i] = c;
|
||||
++i;
|
||||
s[i++] = c;
|
||||
}
|
||||
lastchar = c;
|
||||
}
|
||||
if (incomment == 1 || nw == 1) {
|
||||
s[i] = '\0';
|
||||
} else {
|
||||
s[i] = '\n';
|
||||
s[i+1] = '\0';
|
||||
}
|
||||
/* If we have hit the end of the line, tell the previous function, else return the lenght */
|
||||
s[i] = '\n';
|
||||
s[i+1] = '\0';
|
||||
// If we have hit the end of the line, tell the previous function, else return the lenght
|
||||
if (c == EOF) {
|
||||
return EOF;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue