Changeset: a998c533e669 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a998c533e669
Modified Files:
sql/server/sql_scan.c
Branch: Jun2020
Log Message:
keep inline comments only
diffs (67 lines):
diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c
--- a/sql/server/sql_scan.c
+++ b/sql/server/sql_scan.c
@@ -27,10 +27,14 @@
#include "mal.h" /* for have_hge */
#endif
+/**
+ * Removes all comments before the query. In query comments are kept.
+ */
char *
query_cleaned(const char *query)
{
- char *q, *r;
+ char *q, *r, *c;
+ int lines = 0;
int quote = 0; /* inside quotes ('..', "..", {..}) */
bool bs = false; /* seen a backslash in a quoted string
*/
bool incomment1 = false; /* inside traditional C style comment */
@@ -41,11 +45,19 @@ query_cleaned(const char *query)
if(!r)
return NULL;
+ (void) c;
+
for (q = r; *query; query++) {
if (incomment1) {
if (*query == '/' && query[-1] == '*') {
incomment1 = false;
+ if (c == r && lines > 0) {
+ q = r; // reset to beginning
+ lines = 0;
+ continue;
+ }
}
+ if (*query == '\n') lines++;
*q++ = *query;
} else if (incomment2) {
if (*query == '\n') {
@@ -53,8 +65,10 @@ query_cleaned(const char *query)
inline_comment = false;
/* add newline only if comment doesn't
* occupy whole line */
- if (q > r && q[-1] != '\n')
+ if (q > r && q[-1] != '\n'){
*q++ = '\n';
+ lines++;
+ }
} else if (inline_comment){
*q++ = *query; // preserve in line query
comments
}
@@ -81,11 +95,14 @@ query_cleaned(const char *query)
incomment2 = true;
} else if (*query == '/' && query[1] == '*') {
incomment1 = true;
+ c = q;
*q++ = *query;
} else if (*query == '\n') {
/* collapse newlines */
- if (q > r && q[-1] != '\n')
+ if (q > r && q[-1] != '\n') {
*q++ = '\n';
+ lines++;
+ }
} else if (*query == ' ' || *query == '\t') {
/* collapse white space */
if (q > r && q[-1] != ' ')
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list