Skip to content

Commit 49f43be

Browse files
committed
make determining file type more easy to understand
replace magic numbers with enum (slightly confusing reuse)
1 parent a752735 commit 49f43be

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

include/napi_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ extern "C" {
7979
NXstatus ( *nxnativeisexternallink)(NXhandle handle, CONSTCHAR* name, char* url, int urllen);
8080
int stripFlag;
8181
int checkNameSyntax;
82+
int access_mode;
8283
} NexusFunction, *pNexusFunction;
8384
/*---------------------*/
8485
extern long nx_cacheSize;

src/napi.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,19 @@ static int determineFileTypeImpl(CONSTCHAR * filename)
418418
#ifdef WITH_HDF5
419419
iRet = H5Fis_hdf5((const char *)filename);
420420
if (iRet > 0) {
421-
return 2;
421+
return NXACC_CREATE5;
422422
}
423423
#endif
424424
#ifdef WITH_HDF4
425425
iRet = Hishdf((const char *)filename);
426426
if (iRet > 0) {
427-
return 1;
427+
return NXACC_CREATE4;
428428
}
429429
#endif
430430
#ifdef WITH_MXML
431431
iRet = NXisXML(filename);
432432
if (iRet == NX_OK) {
433-
return 3;
433+
return NXACC_CREATEXML;
434434
}
435435
#endif
436436
/*
@@ -483,9 +483,8 @@ NXstatus NXopen(CONSTCHAR * userfilename, NXaccess am, NXhandle * gHandle)
483483
static NXstatus NXinternalopenImpl(CONSTCHAR * userfilename, NXaccess am,
484484
pFileStack fileStack)
485485
{
486-
int hdf_type = 0;
486+
int backend_type = 0;
487487
int iRet = 0;
488-
NXhandle hdf5_handle = NULL;
489488
pNexusFunction fHandle = NULL;
490489
NXstatus retstat = NX_ERROR;
491490
char error[1024];
@@ -523,19 +522,19 @@ static NXstatus NXinternalopenImpl(CONSTCHAR * userfilename, NXaccess am,
523522

524523
if (my_am == NXACC_CREATE) {
525524
/* HDF4 will be used ! */
526-
hdf_type = 1;
525+
backend_type = NXACC_CREATE4;
527526
filename = strdup(userfilename);
528527
} else if (my_am == NXACC_CREATE4) {
529528
/* HDF4 will be used ! */
530-
hdf_type = 1;
529+
backend_type = NXACC_CREATE4;
531530
filename = strdup(userfilename);
532531
} else if (my_am == NXACC_CREATE5) {
533532
/* HDF5 will be used ! */
534-
hdf_type = 2;
533+
backend_type = NXACC_CREATE5;
535534
filename = strdup(userfilename);
536535
} else if (my_am == NXACC_CREATEXML) {
537536
/* XML will be used ! */
538-
hdf_type = 3;
537+
backend_type = NXACC_CREATEXML;
539538
filename = strdup(userfilename);
540539
} else {
541540
filename = locateNexusFileInPath((char *)userfilename);
@@ -562,14 +561,14 @@ static NXstatus NXinternalopenImpl(CONSTCHAR * userfilename, NXaccess am,
562561
free(fHandle);
563562
return NX_ERROR;
564563
}
565-
hdf_type = iRet;
564+
backend_type = iRet;
566565
}
567566
if (filename == NULL) {
568567
NXReportError("Out of memory in NeXus-API");
569568
return NX_ERROR;
570569
}
571570

572-
if (hdf_type == 1) {
571+
if (backend_type == NXACC_CREATE4) {
573572
/* HDF4 type */
574573
#ifdef WITH_HDF4
575574
NXhandle hdf4_handle = NULL;
@@ -589,9 +588,10 @@ static NXstatus NXinternalopenImpl(CONSTCHAR * userfilename, NXaccess am,
589588
#endif /* HDF4 */
590589
free(filename);
591590
return retstat;
592-
} else if (hdf_type == 2) {
591+
} else if (backend_type == NXACC_CREATE5) {
593592
/* HDF5 type */
594593
#ifdef WITH_HDF5
594+
NXhandle hdf5_handle = NULL;
595595
retstat = NX5open(filename, am, &hdf5_handle);
596596
if (retstat != NX_OK) {
597597
free(fHandle);
@@ -608,7 +608,7 @@ static NXstatus NXinternalopenImpl(CONSTCHAR * userfilename, NXaccess am,
608608
#endif /* HDF5 */
609609
free(filename);
610610
return retstat;
611-
} else if (hdf_type == 3) {
611+
} else if (backend_type == NXACC_CREATEXML) {
612612
/*
613613
XML type
614614
*/

0 commit comments

Comments
 (0)