Skip to content
Snippets Groups Projects
Commit c2ce91a6 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

tentative fix for #783: parsing of mac-encoded scripts (only \r, no \n's)

parent 0fafa531
No related branches found
No related tags found
No related merge requests found
4.5.5 (Work-in-progress): tooltips in GUI to help discovery of scripting
options; fixed MED IO of high-order elements; fixed OCC attribute search by
bounding box; small bug fixes.
bounding box; fix parsing of mac-encoded scripts; small bug fixes.
4.5.4 (February 29, 2020): periodic mesh optimization now ensures that the
master mesh is not modified; code cleanup; API tutorials; small bug fixes.
......
......@@ -21,41 +21,20 @@ char *strsave(char *ptr);
void skipcomments(void);
void skipline(void);
#if defined(HAVE_COMPRESSED_IO) && defined(HAVE_ZLIB)
#define YY_INPUT(buf,result,max_size) \
{ \
int c = '*', n; \
for ( n = 0; n < (int) max_size && \
(c = gzgetc( yyin )) != EOF && c != '\n'; ++n ) \
for(n = 0; n < (int) max_size && (c = fgetc(yyin)) != EOF && \
c != '\n' && c != '\r'; ++n) \
buf[n] = (char) c; \
if ( c == '\n' ){ \
if(c == '\n' || c == '\r') { \
buf[n++] = (char) c; \
yylineno++; \
} \
if ( c == EOF ) { \
int ernum; \
const char *msg = gzerror(yyin,&ernum); \
if (ernum) \
Msg::Error("Input in flex scanner failed"); \
} \
result = n; \
}
#else
#define YY_INPUT(buf,result,max_size) \
{ \
int c = '*', n; \
for ( n = 0; n < (int) max_size && \
(c = fgetc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
if ( c == '\n' ){ \
buf[n++] = (char) c; \
yylineno++; \
if(c == '\n') yylineno++; \
} \
if(c == EOF && ferror(yyin)) \
Msg::Error("Input in flex scanner failed"); \
result = n; \
}
#endif
#if defined(WIN32)
#define isatty(arg) -1
......@@ -386,7 +365,8 @@ void skipcomments(void)
while (1) {
while ((c = yyinput()) != '*') {
// Test on YY_END_OF_BUFFER_CHAR (0), not on feof(yyin) because whole line in buffer
// Test on YY_END_OF_BUFFER_CHAR (0), not on feof(yyin) because whole line
// in buffer
if(c == '\0') {
Msg::Error("End of file in commented region");
return;
......@@ -403,11 +383,12 @@ void parsestring(char endchar)
int c;
char tmp[1024];
// Note that we keep special characters (end-of-line \n, tabs \t,
// etc.) "as is" in the output string: see yyinput() above
// Note that we keep special characters (end-of-line \n, tabs \t, etc.) "as
// is" in the output string: see yyinput() above
int i = 0;
while ((c = yyinput()) != endchar) {
// Test on YY_END_OF_BUFFER_CHAR (0), not on feof(yyin) because whole line in buffer
// Test on YY_END_OF_BUFFER_CHAR (0), not on feof(yyin) because whole line
// in buffer
if(c == '\0') {
Msg::Error("End of file in string");
break;
......@@ -433,7 +414,8 @@ void skipline()
{
int c;
while ((c = yyinput()) != '\n' && c != '\0') {}
// TODO: would be clever to skip the current buffer because whole line already in it
// TODO: would be clever to skip the current buffer because whole line already
// in it
}
static bool is_alpha(const int c)
......@@ -448,7 +430,7 @@ void skip(const char *skip, const char *until)
char chars[256];
int c_next, c_next_skip, c_next_until, c_previous = 0;
l_skip = (skip)? strlen(skip) : 0;
l_skip = skip ? strlen(skip) : 0;
l_until = strlen(until);
l_max = std::max(l_skip, l_until);
......@@ -530,11 +512,12 @@ void skipTest(const char *skip, const char *until,
int i, nb_skip = 0;
int l_skip, l_until, l_until2, l_max, l;
char chars[256];
int c_next, c_next_skip, c_next_until, c_next_until2, c_previous = 0, flag_EOL_EOF = 0;
int c_next, c_next_skip, c_next_until, c_next_until2, c_previous = 0;
int flag_EOL_EOF = 0;
l_skip = (skip)? strlen(skip) : 0;
l_skip = skip ? strlen(skip) : 0;
l_until = strlen(until);
l_until2 = (until2)? strlen(until2) : 0;
l_until2 = until2 ? strlen(until2) : 0;
l_max = std::max(l_skip, l_until);
l_max = std::max(l_max, l_until2);
......@@ -591,14 +574,16 @@ void skipTest(const char *skip, const char *until,
c_next = 0; c_next_skip = 0; c_next_until = 0; c_next_until2 = 0;
}
if(!nb_skip && !strncmp(chars,until2,l_until2) && !is_alpha(c_next_until2)){
if(!nb_skip && !strncmp(chars, until2, l_until2) &&
!is_alpha(c_next_until2)) {
*type_until2 = 1; // Found word is full until2 (e.g., "ElseIf")
for(int i = 1; i <= l; i++) { // Only correct if l == l_until2
unput(chars[l - i]);
} // New file position points "ElseIf", that will be then analysed by the parser
return;
}
else if(!nb_skip && !strncmp(chars,until2,l_until2_sub) && !is_alpha(chars[l_until2_sub])){
else if(!nb_skip && !strncmp(chars,until2,l_until2_sub) &&
!is_alpha(chars[l_until2_sub])) {
*type_until2 = 2; // Found word is subword from until2 (e.g., "Else")
for(int i = 1; i <= l - l_until2_sub; i++) { // Only correct if l_until2_sub < l
unput(chars[l - i]);
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment