Commit d9fbb88c authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Add necessary logic to Fortran 77 binding generator to handle C++ conditionals.

parent 1cc87b3f
...@@ -88,7 +88,7 @@ Define the reference URI for an unstructured grid. ...@@ -88,7 +88,7 @@ Define the reference URI for an unstructured grid.
\section*{\tt \htmlref{gridDefUUID}{gridDefUUID}} \section*{\tt \htmlref{gridDefUUID}{gridDefUUID}}
\begin{verbatim} \begin{verbatim}
void gridDefUUID (int gridID, const unsigned char *uuid); void gridDefUUID (int gridID, const unsigned char uuid[CDI_UUID_SIZE]);
\end{verbatim} \end{verbatim}
Define the UUID of an unstructured grid. Define the UUID of an unstructured grid.
......
...@@ -88,7 +88,7 @@ Define the reference URI for an unstructured grid. ...@@ -88,7 +88,7 @@ Define the reference URI for an unstructured grid.
\section*{\tt \htmlref{gridDefUUID}{gridDefUUID}} \section*{\tt \htmlref{gridDefUUID}{gridDefUUID}}
\begin{verbatim} \begin{verbatim}
SUBROUTINE gridDefUUID (INTEGER gridID, INTEGER*1(*) uuid) SUBROUTINE gridDefUUID (INTEGER gridID, INTEGER*1(16) uuid)
\end{verbatim} \end{verbatim}
Define the UUID of an unstructured grid. Define the UUID of an unstructured grid.
......
...@@ -842,7 +842,11 @@ void gridDefReference(int gridID, const char *reference); ...@@ -842,7 +842,11 @@ void gridDefReference(int gridID, const char *reference);
int gridInqReference(int gridID, char *reference); int gridInqReference(int gridID, char *reference);
/* gridDefUUID: Define the UUID of an unstructured grid */ /* gridDefUUID: Define the UUID of an unstructured grid */
#ifdef __cplusplus
void gridDefUUID(int gridID, const unsigned char *uuid); void gridDefUUID(int gridID, const unsigned char *uuid);
#else
void gridDefUUID(int gridID, const unsigned char uuid[CDI_UUID_SIZE]);
#endif
/* gridInqUUID: Get the UUID of an unstructured grid */ /* gridInqUUID: Get the UUID of an unstructured grid */
void gridInqUUID(int gridID, unsigned char *uuid); void gridInqUUID(int gridID, unsigned char *uuid);
......
...@@ -1714,7 +1714,7 @@ ...@@ -1714,7 +1714,7 @@
! gridDefUUID ! gridDefUUID
! (INTEGER gridID, ! (INTEGER gridID,
! INTEGER*1(*) uuid) ! INTEGER*1(16) uuid)
EXTERNAL gridDefUUID EXTERNAL gridDefUUID
! gridInqUUID ! gridInqUUID
......
...@@ -296,16 +296,20 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint, ...@@ -296,16 +296,20 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint,
if (reCompile(&docCommentRE, docCommentREString, &line, &lineBufSize)) if (reCompile(&docCommentRE, docCommentREString, &line, &lineBufSize))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* compile keep-conditional regular expression */
/* if(n)def and endif preprocessor conditionals followed by
make_fint keep are copied to the Fortran interface file */
regex_t cppCondRE; regex_t cppCondRE;
{ {
static const char cppCondREString[] static const char cppCondREString[]
= "^"WS"*#"WS"*(ifn?def"WS"+"SYMRE"|endif)"WS"+/\\*"WS"*make_fint keep"WS"*\\*/"; = "^"WS"*#"WS"*((ifn?def)"WS"+"SYMRE"|endif)"WS"*(/\\*[^*]*\\*/|//.*)?";
if (reCompile(&cppCondRE, cppCondREString, &line, &lineBufSize)) if (reCompile(&cppCondRE, cppCondREString, &line, &lineBufSize))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
regex_t cppElseRE;
{
static const char cppElseREString[]
= "^"WS"*#"WS"*else"WS"*(/\\*[^*]*\\*/|//.*)?";
if (reCompile(&cppElseRE, cppElseREString, &line, &lineBufSize))
exit(EXIT_FAILURE);
}
regex_t emptyStringRE; regex_t emptyStringRE;
{ {
static const char emptyStringREString[] = "^"WS"*"; static const char emptyStringREString[] = "^"WS"*";
...@@ -349,6 +353,7 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint, ...@@ -349,6 +353,7 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint,
ssize_t lineLen; ssize_t lineLen;
while ((lineLen = getline(&line, &lineBufSize, fpin)) >= 0) while ((lineLen = getline(&line, &lineBufSize, fpin)) >= 0)
{ {
static const char cplusplus_macro[] = "__cplusplus";
lineno++; lineno++;
functype = ISVOID; functype = ISVOID;
size_t funcargc = 0; size_t funcargc = 0;
...@@ -385,6 +390,8 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint, ...@@ -385,6 +390,8 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint,
funcname[funcnameLen] = 0; funcname[funcnameLen] = 0;
pline += reMatch[0].rm_eo; pline += reMatch[0].rm_eo;
} while (0); } while (0);
int cppSwitchLen, cppSymLen;
if (declType == FUNC_DECL) if (declType == FUNC_DECL)
{ {
funcargname[funcargc].rm_so = (regoff_t)(pline - line); funcargname[funcargc].rm_so = (regoff_t)(pline - line);
...@@ -744,10 +751,17 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint, ...@@ -744,10 +751,17 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint,
" PARAMETER (%-22s = %2d)\n", parname, parname, " PARAMETER (%-22s = %2d)\n", parname, parname,
parvalue); parvalue);
} }
else if (!regexec(&cppCondRE, line, maxMatch, reMatch, 0)) else if (!regexec(&cppCondRE, line, maxMatch, reMatch, 0)
&& ((cppSwitchLen = reMatch[2].rm_eo - reMatch[2].rm_so) == 5)
&& ((size_t)(cppSymLen = reMatch[3].rm_eo - reMatch[3].rm_so)
== sizeof (cplusplus_macro) - 1)
&& !memcmp(line + reMatch[3].rm_so, cplusplus_macro,
sizeof (cplusplus_macro) - 1))
{ {
/* fortran include */ fprintf(stderr, "Found conditional C++ block, skipping to #else\n");
fputs(line, fpint); while ((lineLen = getline(&line, &lineBufSize, fpin)) >= 0)
if (!regexec(&cppElseRE, line, maxMatch, reMatch, 0))
break;
} }
else if (detectComment(&line, &lineLen, &lineBufSize, else if (detectComment(&line, &lineLen, &lineBufSize,
maxMatch, reMatch, maxMatch, reMatch,
...@@ -762,8 +776,8 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint, ...@@ -762,8 +776,8 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint,
} }
} }
fprintf(fpint, "\n"); fputs("\n"
fprintf(fpint, "#endif\n"); "#endif\n", fpint);
fclose(fpin); fclose(fpin);
fclose(fpinc); fclose(fpinc);
......
...@@ -479,6 +479,7 @@ module mo_cdi ...@@ -479,6 +479,7 @@ module mo_cdi
public gridInqPosition public gridInqPosition
public gridDefReference public gridDefReference
public gridInqReference public gridInqReference
public gridDefUUID
public gridDefLCC public gridDefLCC
public gridInqLCC public gridInqLCC
public gridDefLcc2 public gridDefLcc2
...@@ -5572,6 +5573,19 @@ contains ...@@ -5572,6 +5573,19 @@ contains
end do end do
end function gridInqReference end function gridInqReference
subroutine gridDefUUID(gridID_dummy, uuid_dummy)
integer(c_int), value :: gridID_dummy
character(kind = c_char), intent(in) :: uuid_dummy(CDI_UUID_SIZE)
interface
subroutine lib_gridDefUUID(gridID_dummy, uuid_dummy) bind(c, name = 'gridDefUUID')
import c_char, c_int
integer(c_int), value :: gridID_dummy
character(kind = c_char), intent(in) :: uuid_dummy(*)
end subroutine lib_gridDefUUID
end interface
call lib_gridDefUUID(gridID_dummy, uuid_dummy)
end subroutine gridDefUUID
subroutine gridDefLCC(gridID_dummy, originLon_dummy, originLat_dummy, lonParY_dummy, lat1_dummy, lat2_dummy, xinc_dummy, yinc_dumm& subroutine gridDefLCC(gridID_dummy, originLon_dummy, originLat_dummy, lonParY_dummy, lat1_dummy, lat2_dummy, xinc_dummy, yinc_dumm&
&y, projflag_dummy, scanflag_dummy) &y, projflag_dummy, scanflag_dummy)
integer(c_int), value :: gridID_dummy integer(c_int), value :: gridID_dummy
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment