From ac3c7babf734e340c2e79e33ccd8e640e892b2e1 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Wed, 10 Jun 2015 14:48:26 +0000 Subject: [PATCH] Correct Fortran - C interop in wsprd code git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5571 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- lib/wsprd/nhash.c | 17 +++++++++++------ lib/wsprd/nhash.h | 13 +++++++++++++ lib/wsprd/unpk.c | 7 +++---- lib/wsprd/wsprd.c | 1 - lib/wsprd/wsprd_utils.c | 7 ++++--- lib/wsprd/wsprd_utils.h | 4 +--- 6 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 lib/wsprd/nhash.h diff --git a/lib/wsprd/nhash.c b/lib/wsprd/nhash.c index 1985da9ef..caa529b11 100644 --- a/lib/wsprd/nhash.c +++ b/lib/wsprd/nhash.c @@ -70,13 +70,10 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #define SELF_TEST 1 +#include "nhash.h" + #include /* defines printf for tests */ #include /* defines time_t for timings in the test */ -#ifdef Win32 -#include "win_stdint.h" /* defines uint32_t etc */ -#else -#include /* defines uint32_t etc */ -#endif //#include /* attempt to define endianness */ //#ifdef linux //# include /* attempt to define endianness */ @@ -205,7 +202,7 @@ acceptable. Do NOT use for cryptographic purposes. ------------------------------------------------------------------------------- */ -uint32_t nhash_( const void *key, size_t length, uint32_t initval) +uint32_t nhash( const void *key, size_t length, uint32_t initval) { uint32_t a,b,c; /* internal state */ union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */ @@ -374,3 +371,11 @@ uint32_t nhash_( const void *key, size_t length, uint32_t initval) return c; } + +/* + * Fortran argument compatible wrapper + */ +uint32_t nhash_( const void * key, size_t const * length, uint32_t const * initval) +{ + return nhash (key, *length, *initval); +} diff --git a/lib/wsprd/nhash.h b/lib/wsprd/nhash.h new file mode 100644 index 000000000..096ade65e --- /dev/null +++ b/lib/wsprd/nhash.h @@ -0,0 +1,13 @@ +#ifndef NHASH_H_ +#define NHASH_H_ + +#ifdef Win32 +#include "win_stdint.h" /* defines uint32_t etc */ +#else +#include /* defines uint32_t etc */ +#endif + +uint32_t nhash( const void * key, size_t length, uint32_t initval); +uint32_t nhash_( void const * key, size_t const * length, uint32_t const * initval); + +#endif diff --git a/lib/wsprd/unpk.c b/lib/wsprd/unpk.c index 51207cb98..dcae675e1 100644 --- a/lib/wsprd/unpk.c +++ b/lib/wsprd/unpk.c @@ -6,10 +6,9 @@ #include #include +#include "nhash.h" #include "wsprd_utils.h" -unsigned int nhash_( const void *key, size_t length, uint32_t initval); - void unpk_(signed char message[], int *nhashtab, char call_loc_pow[]) { int i,n1,n2,n3,ndbm,ihash,nadd,noprint,nh; @@ -74,7 +73,7 @@ void unpk_(signed char message[], int *nhashtab, char call_loc_pow[]) strncat(call_loc_pow," ",1); strncat(call_loc_pow,cdbm,2); strncat(call_loc_pow,"\0",1); - ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); strcpy(*hashtab+ihash*13,callsign); } else { nadd=nu; @@ -89,7 +88,7 @@ void unpk_(signed char message[], int *nhashtab, char call_loc_pow[]) strncat(call_loc_pow," ",1); strncat(call_loc_pow,cdbm,2); strncat(call_loc_pow,"\0",1); - ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); strcpy(*hashtab+ihash*13,callsign); noprint=0; } diff --git a/lib/wsprd/wsprd.c b/lib/wsprd/wsprd.c index db0c29ecf..4bd019478 100644 --- a/lib/wsprd/wsprd.c +++ b/lib/wsprd/wsprd.c @@ -723,7 +723,6 @@ int main(int argc, char *argv[]) memset(cdbm,0,sizeof(char)*3); char hashtab[32768][13]; memset(hashtab,0,sizeof(char)*32768*13); - uint32_t nhash_( const void *, size_t, uint32_t); int nh; if( usehashtable ) { diff --git a/lib/wsprd/wsprd_utils.c b/lib/wsprd/wsprd_utils.c index 37f6b8351..3bf965817 100644 --- a/lib/wsprd/wsprd_utils.c +++ b/lib/wsprd/wsprd_utils.c @@ -27,6 +27,7 @@ along with this program. If not, see . */ #include "wsprd_utils.h" +#include "nhash.h" #ifndef int32_t #define int32_t int @@ -261,7 +262,7 @@ int unpk_(signed char *message, char hashtab[32768][13], char *call_loc_pow, cha strncat(call_loc_pow," ",1); strncat(call_loc_pow,cdbm,2); strncat(call_loc_pow,"\0",1); - ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); strcpy(*hashtab+ihash*13,callsign); } else { nadd=nu; @@ -278,7 +279,7 @@ int unpk_(signed char *message, char hashtab[32768][13], char *call_loc_pow, cha strncat(call_loc_pow,"\0",1); int nu=ndbm%10; if( nu == 0 || nu == 3 || nu == 7 || nu == 10 ) { //make sure power is OK - ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); strcpy(*hashtab+ihash*13,callsign); } else noprint=1; } @@ -294,7 +295,7 @@ int unpk_(signed char *message, char hashtab[32768][13], char *call_loc_pow, cha // not testing 4'th and 5'th chars because of this case: JO33 40 // grid is only 4 chars even though this is a hashed callsign... // isalpha(grid6[4]) && isalpha(grid6[5]) ) ) { - ihash=nhash_(callsign,strlen(callsign),(uint32_t)146); + ihash=nhash(callsign,strlen(callsign),(uint32_t)146); strcpy(*hashtab+ihash*13,callsign); } else noprint=1; diff --git a/lib/wsprd/wsprd_utils.h b/lib/wsprd/wsprd_utils.h index b24e9044d..aef057093 100644 --- a/lib/wsprd/wsprd_utils.h +++ b/lib/wsprd/wsprd_utils.h @@ -19,6 +19,4 @@ void deinterleave(unsigned char *sym); // used by qsort int floatcomp(const void* elem1, const void* elem2); -unsigned int nhash_( const void *key, size_t length, uint32_t initval); - -int unpk_( signed char *message, char hashtab[32768][13], char *call_loc_pow, char *callsign); \ No newline at end of file +int unpk_( signed char *message, char hashtab[32768][13], char *call_loc_pow, char *callsign);