Add quote handling

This commit is contained in:
caskd 2019-10-22 17:29:37 +02:00
parent 6edf3378f9
commit b40959eb68
No known key found for this signature in database
GPG Key ID: 79DB21404E300A27
1 changed files with 22 additions and 19 deletions

View File

@ -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 {