File: ncpluginpath.c

package info (click to toggle)
netcdf-parallel 1%3A4.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 116,192 kB
  • sloc: ansic: 279,265; sh: 14,143; cpp: 5,971; yacc: 2,612; makefile: 2,075; lex: 1,218; javascript: 280; xml: 173; awk: 2
file content (165 lines) | stat: -rw-r--r-- 3,477 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 *	Copyright 2018, University Corporation for Atmospheric Research
 *      See netcdf/COPYRIGHT file for copying and redistribution conditions.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef _WIN32
#include <windows.h>
#include <fcntl.h>
#endif

#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

#if defined(_WIN32) && !defined(__MINGW32__)
#include "XGetopt.h"
#else
#include <getopt.h>
#endif

#include "netcdf.h"
#include "netcdf_filter.h"
#include "netcdf_aux.h"
#include "ncplugins.h"

extern int NCstdbinary(void);

static const char* USAGE =
"ncpluginpath [-f global|hdf5|nczarr][-h][-n]"
"Options\n"
"  -f which plugin path to print.\n"
"     global - print the global plugin path\n"
"     hdf5 - print the hdf5 plugin path\n"
"     nczarr - print the nczarr plugin path\n"
"     If -f is not specified, then it defaults to 'global'\n"
"  -h print the usage message\n"
"  -n print the length of the current internal plugin path list\n"
"\n"
;

#undef DEBUG

static void usage(const char* msg);

static void
usage(const char* msg)
{
    if(msg != NULL) fprintf(stderr,"%s\n",msg);
    fprintf(stderr,"%s",USAGE);
    if(msg == NULL) exit(0); else exit(1);
}

static int
getformatx(const char* sformat)
{
    if(sformat != NULL && strlen(sformat) > 0) {
	if(strcmp(sformat,"global")==0) return NC_FORMATX_UNDEFINED;
        if(strcmp(sformat,"hdf5")==0) return NC_FORMATX_NC_HDF5;
        if(strcmp(sformat,"nczarr")==0) return NC_FORMATX_NCZARR;
    }
    return NC_FORMATX_UNDEFINED;
}

#if 0
static const char*
getsource(int formatx)
{
    switch (formatx) {
    case NC_FORMATX_NC_HDF5: return "hdf5";
    case NC_FORMATX_NCZARR: return "nczarr";
    default: break;
    }
    return "global";
}
#endif

static int
getfrom(int formatx, char** textp)
{
    int stat = NC_NOERR;
    NCPluginList dirs = {0,NULL};
    char* text = NULL;
   
    /* Get a plugin path */
    switch (formatx) {
    case 0: /* Global */
        if((stat=nc_plugin_path_get(&dirs))) goto done;
	break;
#ifdef NETCDF_ENABLE_NCZARR_FILTERS
    case NC_FORMATX_NCZARR:
        if((stat=NCZ_plugin_path_get(&dirs))) goto done;
	break;
#endif
#ifdef USE_HDF5
    case NC_FORMATX_NC_HDF5:
	if((stat=NC4_hdf5_plugin_path_get(&dirs))) goto done;
	break;
#endif
    default: abort();
    }
    if((stat = ncaux_plugin_path_tostring(&dirs,';',&text))) goto done;
    *textp = text; text = NULL;
done:
    if(text != NULL) free(text);
    ncaux_plugin_path_clear(&dirs);
    return stat;
}

int
main(int argc, char** argv)
{
    int stat = NC_NOERR;
    int c;
    int formatx = NC_FORMATX_UNDEFINED;
    char* text = NULL;
    int ndirsflag = 0;

    NCstdbinary(); /* avoid \r\n on windows */

    nc_initialize();

    while ((c = getopt(argc, argv, "f:hn")) != EOF) {
	switch(c) {
	case 'f':
	    formatx = getformatx(optarg);
	    break;
	case 'n':
	    ndirsflag = 1;
	    break;
	case '?':
	   usage("unknown option");
	   break;
	}
    }

    if(ndirsflag) {
	size_t ndirs = 0;
	char sndirs[64];
	if((stat = nc_plugin_path_ndirs(&ndirs))) goto done;
	snprintf(sndirs,sizeof(sndirs),"%zu",ndirs);
	text = strdup(sndirs);
    } else {
        if((stat = getfrom(formatx,&text))) goto done;
    }
    printf("%s",text); /* suppress trailing eol */
done:
    if(text != NULL) free(text);
    nc_finalize();
    return (stat?1:0);
}