Skip to content

Commit

Permalink
hds: Update wrapper generation code
Browse files Browse the repository at this point in the history
+ Now ignores prolog from hds.h (otherwise it won't ever
  include hds.h).
+ datMove now implemented as copy and erase.
  • Loading branch information
timj committed Oct 31, 2014
1 parent 062fdc3 commit 6c42e74
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 40 deletions.
64 changes: 42 additions & 22 deletions libraries/hds/hds_select.c
@@ -1,14 +1,9 @@
/* Protect against multiple inclusion */
#ifndef STAR_HDS_H_INCLUDED
#define STAR_HDS_H_INCLUDED

#include "dat1.h"
#include "hds_types.h"
#include "dat_par.h"

#include <stdlib.h>
#include <stdio.h>
#include "sae_par.h"
#include "dat_par.h"
#include "dat1.h"
#include "hds_types.h"
#include "ems.h"
#include "hds.h"
#include "dat_err.h"
Expand Down Expand Up @@ -92,18 +87,25 @@ datCcopy(const HDSLoc *locator1, const HDSLoc *locator2, const char *name, HDSLo
/* Requires special code */
int instat = *status;
int isv5 = 0;
int loc1isv5 = 0;
int loc2isv5 = 0;
EnterCheck("datCcopy",*status);
if (*status != SAI__OK) return *status;
if (ISHDSv5(locator1) && ISHDSv5(locator2)) {
loc1isv5 = ISHDSv5(locator1);
loc2isv5 = ISHDSv5(locator2);
if (loc1isv5 && loc2isv5) {
/* Just call the v5 code */
isv5 = 1;
datCcopy_v5(locator1, locator2, name, locator3, status);
} else if ( !ISHDSv5(locator1) && !ISHDSv5(locator2) ) {
} else if ( !loc1isv5 && !loc2isv5 ) {
isv5 = 0;
datCcopy_v4(locator1, locator2, name, locator3, status);
} else {
printf("Aborting. datCcopy: Special code required for copy across different versions of files.\n");
abort();
if (loc1isv5) {
datCcopy5to4(locator1, locator2, name, locator3, status);
} else {
datCcopy4to5(locator1, locator2, name, locator3, status);
}
}
HDS_CHECK_STATUS("datCcopy",(isv5 ? "(v5)" : "(v4)"));
return *status;
Expand Down Expand Up @@ -225,18 +227,25 @@ datCopy(const HDSLoc *locator1, const HDSLoc *locator2, const char *name_c, int
/* Requires special code */
int instat = *status;
int isv5 = 0;
int loc1isv5 = 0;
int loc2isv5 = 0;
EnterCheck("datCopy",*status);
if (*status != SAI__OK) return *status;
if (ISHDSv5(locator1) && ISHDSv5(locator2)) {
loc1isv5 = ISHDSv5(locator1);
loc2isv5 = ISHDSv5(locator2);
if (loc1isv5 && loc2isv5) {
/* Just call the v5 code */
isv5 = 1;
datCopy_v5(locator1, locator2, name_c, status);
} else if ( !ISHDSv5(locator1) && !ISHDSv5(locator2) ) {
} else if ( !loc1isv5 && !loc2isv5 ) {
isv5 = 0;
datCopy_v4(locator1, locator2, name_c, status);
} else {
printf("Aborting. datCopy: Special code required for copy across different versions of files.\n");
abort();
if (loc1isv5) {
datCopy5to4(locator1, locator2, name_c, status);
} else {
datCopy4to5(locator1, locator2, name_c, status);
}
}
HDS_CHECK_STATUS("datCopy",(isv5 ? "(v5)" : "(v4)"));
return *status;
Expand Down Expand Up @@ -1185,18 +1194,31 @@ datMove(HDSLoc **locator1, const HDSLoc *locator2, const char *name_str, int *st
/* Requires special code */
int instat = *status;
int isv5 = 0;
int loc1isv5 = 0;
int loc2isv5 = 0;
EnterCheck("datMove",*status);
if (*status != SAI__OK) return *status;
if (ISHDSv5(*locator1) && ISHDSv5(locator2)) {
loc1isv5 = ISHDSv5(*locator1);
loc2isv5 = ISHDSv5(locator2);
if (loc1isv5 && loc2isv5) {
/* Just call the v5 code */
isv5 = 1;
datMove_v5(locator1, locator2, name_str, status);
} else if ( !ISHDSv5(*locator1) && !ISHDSv5(locator2) ) {
} else if ( !loc1isv5 && !loc2isv5 ) {
isv5 = 0;
datMove_v4(locator1, locator2, name_str, status);
} else {
printf("Aborting. datMove: Special code required for copy across different versions of files.\n");
abort();
HDSLoc * parenloc = NULL;
char namestr[DAT__SZNAM+1];
/* Just do a copy */
datCopy(*locator1, locator2, name_str, status);
/* and then erase - HDS API insists that we can not erase
based on a locator so we need to get the parent and this name. */
datName(*locator1, namestr, status);
datParen(*locator1, &parenloc, status);
datAnnul(locator1, status);
datErase(parenloc, namestr, status);
datAnnul(&parenloc, status);
}
HDS_CHECK_STATUS("datMove",(isv5 ? "(v5)" : "(v4)"));
return *status;
Expand Down Expand Up @@ -3065,5 +3087,3 @@ hdsFind(const HDSLoc *locator1, const char *name, const char *mode, HDSLoc **loc
}


/* STAR_HDS_H_INCLUDED */
#endif
89 changes: 71 additions & 18 deletions libraries/hds/helper/mkhdswrapper.py
Expand Up @@ -136,29 +136,72 @@ def func_v5(func,line):
print(' EnterCheck("'+func+'",-1);')
print(" return " +v5)

def func_move(func,line):
def func_copy(func,line):
(v4,v5) = version_names(line)
v4to5 = line.replace("(", "4to5(")
v5to4 = line.replace("(", "5to4(")
loc1 = "locator1"
if line.startswith("datMove"):
loc1 = "*locator1"
print(""" /* Requires special code */
int instat = *status;
int isv5 = 0;
int loc1isv5 = 0;
int loc2isv5 = 0;
EnterCheck(\"{3}\",*status);
if (*status != SAI__OK) return *status;
if (ISHDSv5({0}) && ISHDSv5(locator2)) {{
loc1isv5 = ISHDSv5({0});
loc2isv5 = ISHDSv5(locator2);
if (loc1isv5 && loc2isv5) {{
/* Just call the v5 code */
isv5 = 1;
{1}
}} else if ( !ISHDSv5({0}) && !ISHDSv5(locator2) ) {{
}} else if ( !loc1isv5 && !loc2isv5 ) {{
isv5 = 0;
{2}
}} else {{
printf(\"Aborting. {3}: Special code required for copy across different versions of files.\\n\");
abort();
if (loc1isv5) {{
{4}
}} else {{
{5}
}}
}}
HDS_CHECK_STATUS(\"{3}\",(isv5 ? "(v5)" : "(v4)"));
return *status;""".format(loc1,v5,v4,func))
return *status;""".format(loc1,v5,v4,func,v5to4,v4to5))

def func_datMove(func,line):
(v4,v5) = version_names(line)
print(""" /* Requires special code */
int instat = *status;
int isv5 = 0;
int loc1isv5 = 0;
int loc2isv5 = 0;
EnterCheck(\"{2}\",*status);
if (*status != SAI__OK) return *status;
loc1isv5 = ISHDSv5(*locator1);
loc2isv5 = ISHDSv5(locator2);
if (loc1isv5 && loc2isv5) {{
/* Just call the v5 code */
isv5 = 1;
{0}
}} else if ( !loc1isv5 && !loc2isv5 ) {{
isv5 = 0;
{1}
}} else {{
HDSLoc * parenloc = NULL;
char namestr[DAT__SZNAM+1];
/* Just do a copy */
datCopy(*locator1, locator2, name_str, status);
/* and then erase - HDS API insists that we can not erase
based on a locator so we need to get the parent and this name. */
datName(*locator1, namestr, status);
datParen(*locator1, &parenloc, status);
datAnnul(locator1, status);
datErase(parenloc, namestr, status);
datAnnul(&parenloc, status);
}}
HDS_CHECK_STATUS(\"{2}\",(isv5 ? "(v5)" : "(v4)"));
return *status;""".format(v5,v4,func))

def func_hdsOpen(line):
print(""" int instat = *status;
Expand Down Expand Up @@ -202,12 +245,12 @@ def func_hdsFlush(line):

# Dictionary indicating special cases
special = dict({
"datCcopy": "move",
"datCcopy": "copy",
"datCctyp": "v5+void",
"datChscn": "v5",
"datCopy": "move",
"datCopy": "copy",
"datErmsg": "v5",
"datMove": "move",
"datMove": "datMove",
"datMsg": "void",
"datTemp": "v5",
"hdsEwild": "special",
Expand All @@ -222,7 +265,7 @@ def func_hdsFlush(line):
"hdsWild": "special"
})

inserted_includes = 0
in_prologue = 1
for line in open("hds.h"):
line = line.strip()
func_match = hfunc_re.search(line)
Expand Down Expand Up @@ -258,24 +301,29 @@ def func_hdsFlush(line):
func_v5void(hds_function,line)
elif mode == "v5":
func_v5(hds_function,line)
elif mode == "datMove":
func_datMove(hds_function,line)
elif mode == "hdsOpen":
func_hdsOpen(line)
elif mode == "hdsGtune":
func_hdsGtune(line)
elif mode == "hdsFlush":
func_hdsFlush(line)
elif mode == "move":
func_move(hds_function,line)
elif mode == "copy":
func_copy(hds_function,line)
else:
raise ValueError("Unrecognized mode {0} for function {1}".format(mode,hds_function))
else:
func_simple(hds_function,line)
print("}")
else:
if not inserted_includes and line.startswith("/*=="):
if in_prologue and line.startswith("/*=="):
print('#include <stdlib.h>') # For abort()
print('#include <stdio.h>') # For printf()
print('#include "sae_par.h"')
print('#include "dat_par.h"')
print('#include "dat1.h"')
print('#include "hds_types.h"')
print('#include "ems.h"')
print('#include "hds.h"')
print('#include "dat_err.h"')
Expand All @@ -290,9 +338,14 @@ def func_hdsFlush(line):
print("# define EnterCheck(A,B) ;")
print('#endif')
print("")
inserted_includes=1
elif line.find("dat_par.h") != -1:
print('#include "dat1.h"')
print('#include "hds_types.h"')
print(line)
print(line)
in_prologue = 0
elif in_prologue:
# We want to ignore the prologue and write our own
pass
elif line.startswith("/* STAR_HDS_H"):
# this is the end of the include file
in_prologue = 1
else:
print(line)

0 comments on commit 6c42e74

Please sign in to comment.