Clean indentation

This commit is contained in:
caskd 2019-10-30 23:54:11 +01:00
parent ee26ca9c27
commit a300e1cc32
No known key found for this signature in database
GPG Key ID: 79DB21404E300A27
2 changed files with 122 additions and 128 deletions

View File

@ -3,20 +3,20 @@
#include "shared/functions/synthaxcheck.c" #include "shared/functions/synthaxcheck.c"
int main() { int main() {
char errors[6][30] = { char errors[6][30] = {
"none", "none",
"unmatched round bracket", "unmatched round bracket",
"unmatched curly bracket", "unmatched curly bracket",
"unmatched single quote", "unmatched single quote",
"unmatched double quote", "unmatched double quote",
"unmatched square bracket" "unmatched square bracket"
}; };
int result; int result;
if ((result = synthaxcheck()) == 0) { if ((result = synthaxcheck()) == 0) {
printf("No synthax errors found!\n"); printf("No synthax errors found!\n");
return 0; return 0;
} else { } else {
printf("Sythax error found at line %i column %i\nReason: %s\n", unmline, unmcol, errors[result]); printf("Sythax error found at line %i column %i\nReason: %s\n", unmline, unmcol, errors[result]);
return result; return result;
} }
} }

View File

@ -3,120 +3,114 @@
int unmline, unmcol; int unmline, unmcol;
int synthaxcheck(void) { int synthaxcheck(void) {
int c, // Character integer int c, // Character integer
lastchar = 0, // Last character buffers, for escapes lastchar = 0, // Last character buffers, for escapes
dq = 0, // Double quote status dq = 0, // Double quote status
sq = 0, // Single quote status sq = 0, // Single quote status
cb = 0, // Curly bracket count cb = 0, // Curly bracket count
sb = 0, // Square bracket count sb = 0, // Square bracket count
rb = 0, // Round bracket count rb = 0, // Round bracket count
mc = 0, // Multi-line comment status mc = 0, // Multi-line comment status
sc = 0, // Single line comment status sc = 0, // Single line comment status
line = 0, // Current line line = 0, // Current line
col = 0, // Current column col = 0, // Current column
lce = 0, // Last character escape lce = 0, // Last character escape
result = 0; // Result of evaluation result = 0; // Result of evaluation
while ((c=getchar()) != EOF && result == 0) { while ((c=getchar()) != EOF && result == 0) {
if (lastchar != '\\' || lce != 0) { if (lastchar != '\\' || lce != 0) {
switch (c) { switch (c) {
case '"': { case '"': {
if (sq == 0 && mc == 0 && sc == 0) { if (sq == 0 && mc == 0 && sc == 0) {
if (dq == 1) { dq = !dq;
dq = 0; }
} else { break;
dq = 1; }
case '\'': {
if (dq == 0 && mc == 0 && sc == 0) {
sq = !sq;
}
break;
}
case '\n': {
if (dq == 0 && sq == 0) {
col = 0;
line++;
} else if (dq != 0) {
result = 4;
} else if (sq != 0) {
result = 3;
}
if (sc != 0) {
sc = 0;
}
break;
}
default: break;
}
if (sq == 0 && dq == 0) {
if (mc == 0 && sc == 0) {
switch (c) {
case '{': {
cb++;
break;
}
case '}': {
cb--;
break;
}
case '[': {
sb++;
break;
}
case ']': {
sb--;
break;
}
case '(': {
rb++;
break;
}
case ')': {
rb--;
break;
}
default: break;
}
}
switch (c) {
case '/': {
if (lastchar == '/') {
sc = 1;
} else if (lastchar == '*') {
mc = 0;
}
break;
}
case '*': {
if (lastchar == '/' && mc == 0) {
mc = 1;
}
break;
}
default: break;
}
} }
}
break;
} }
case '\'': { col++;
if (dq == 0 && mc == 0 && sc == 0) { lce = (lastchar == '\\');
if (sq == 1) { lastchar = c;
sq = 0;
} else {
sq = 1;
}
}
break;
}
if (sq == 0 && dq == 0) {
if (mc == 0 && sc == 0) {
case '{': {
cb++;
break;
}
case '}': {
cb--;
break;
}
case '[': {
sb++;
break;
}
case ']': {
sb--;
break;
}
case '(': {
rb++;
break;
}
case ')': {
rb--;
break;
}
}
case '/': {
if (lastchar == '/') {
sc = 1;
} else if (lastchar == '*') {
mc = 0;
}
break;
}
case '*': {
if (lastchar == '/' && mc == 0) {
mc = 1;
}
break;
}
}
case '\n': {
if (dq == 0 && sq == 0) {
col = 0;
line++;
} else if (dq != 0) {
result = 4;
} else if (sq != 0) {
result = 3;
}
if (sc != 0) {
sc = 0;
}
break;
}
default: break;
}
} }
col++; unmcol = col;
if (lastchar == '\\') { unmline = line;
lce = 1; // Don't overwrite results if previous loop finished with a error
} else { if (result == 0) {
lce = 0; if (cb != 0) {
result = 2;
} else if (sb != 0) {
result = 5;
} else if (rb != 0) {
result = 1;
}
} }
lastchar = c; return result;
}
unmcol = col;
unmline = line;
// Don't overwrite results if previous loop finished with a error
if (result == 0) {
if (cb != 0) {
result = 2;
} else if (sb != 0) {
result = 5;
} else if (rb != 0) {
result = 1;
}
}
return result;
} }