[Code formatting: Change indentation style to space](https://github.com/clicon/clixon/issues/379)

* Applies to all c/h/y/l/sh files and .editorconfig
This commit is contained in:
Olof hagsand 2022-10-27 14:21:17 +02:00
parent a9d1ab006c
commit d84c529ff1
376 changed files with 38147 additions and 38133 deletions

View file

@ -65,21 +65,21 @@ static int
usage(char *argv0)
{
fprintf(stderr, "usage:%s [options]\n"
"where options are\n"
"where options are\n"
"\t-h \t\tHelp\n"
"\t-D <level> \tDebug\n"
"\t-f <file> \tXML file\n"
"\t-a \t\tUse API-PATH (default INSTANCE-ID)\n"
"\t-p <xpath> \tPATH string\n"
"\t-y <filename> \tYang filename or dir (load all files)\n"
"\t-Y <dir> \tYang dirs (can be several)\n"
"\t-n <n> \tRepeat the call n times(for profiling)\n"
"and the following extra rules:\n"
"\tif -f is not given, XML input is expected on stdin\n"
"\tif -p is not given, <path> is expected as the first line on stdin\n"
"This means that with no arguments, <api-path> and XML is expected on stdin.\n",
argv0
);
"\t-D <level> \tDebug\n"
"\t-f <file> \tXML file\n"
"\t-a \t\tUse API-PATH (default INSTANCE-ID)\n"
"\t-p <xpath> \tPATH string\n"
"\t-y <filename> \tYang filename or dir (load all files)\n"
"\t-Y <dir> \tYang dirs (can be several)\n"
"\t-n <n> \tRepeat the call n times(for profiling)\n"
"and the following extra rules:\n"
"\tif -f is not given, XML input is expected on stdin\n"
"\tif -p is not given, <path> is expected as the first line on stdin\n"
"This means that with no arguments, <api-path> and XML is expected on stdin.\n",
argv0
);
exit(0);
}
@ -111,106 +111,106 @@ main(int argc,
cxobj *xerr = NULL; /* malloced must be freed */
int nr = 1;
int dbg = 0;
/* In the startup, logs to stderr & debug flag set later */
clicon_log_init("api-path", LOG_DEBUG, CLICON_LOG_STDERR);
/* Initialize clixon handle */
if ((h = clicon_handle_init()) == NULL)
goto done;
goto done;
/* Initialize config tree (needed for -Y below) */
if ((xcfg = xml_new("clixon-config", NULL, CX_ELMNT)) == NULL)
goto done;
goto done;
if (clicon_conf_xml_set(h, xcfg) < 0)
goto done;
goto done;
optind = 1;
opterr = 0;
while ((c = getopt(argc, argv, UTIL_PATH_OPTS)) != -1)
switch (c) {
case 'h':
usage(argv0);
break;
case 'D':
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv0);
break;
case 'f': /* XML file */
filename = optarg;
if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "fopen(%s)", optarg);
goto done;
}
break;
case 'a': /* API-PATH instead of INSTANCE-ID */
api_path_p++;
break;
case 'p': /* API-PATH string */
path = optarg;
break;
case 'y':
yang_file_dir = optarg;
break;
case 'Y':
if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
goto done;
break;
case 'n':
nr = atoi(optarg);
break;
default:
usage(argv[0]);
break;
}
switch (c) {
case 'h':
usage(argv0);
break;
case 'D':
if (sscanf(optarg, "%d", &dbg) != 1)
usage(argv0);
break;
case 'f': /* XML file */
filename = optarg;
if ((fp = fopen(filename, "r")) == NULL){
clicon_err(OE_UNIX, errno, "fopen(%s)", optarg);
goto done;
}
break;
case 'a': /* API-PATH instead of INSTANCE-ID */
api_path_p++;
break;
case 'p': /* API-PATH string */
path = optarg;
break;
case 'y':
yang_file_dir = optarg;
break;
case 'Y':
if (clicon_option_add(h, "CLICON_YANG_DIR", optarg) < 0)
goto done;
break;
case 'n':
nr = atoi(optarg);
break;
default:
usage(argv[0]);
break;
}
clicon_debug_init(dbg, NULL);
yang_init(h);
/* Parse yang */
if (yang_file_dir){
if ((yspec = yspec_new()) == NULL)
goto done;
if (stat(yang_file_dir, &st) < 0){
clicon_err(OE_YANG, errno, "%s not found", yang_file_dir);
goto done;
}
if (S_ISDIR(st.st_mode)){
if (yang_spec_load_dir(h, yang_file_dir, yspec) < 0)
goto done;
}
else{
if (yang_spec_parse_file(h, yang_file_dir, yspec) < 0)
goto done;
}
if ((yspec = yspec_new()) == NULL)
goto done;
if (stat(yang_file_dir, &st) < 0){
clicon_err(OE_YANG, errno, "%s not found", yang_file_dir);
goto done;
}
if (S_ISDIR(st.st_mode)){
if (yang_spec_load_dir(h, yang_file_dir, yspec) < 0)
goto done;
}
else{
if (yang_spec_parse_file(h, yang_file_dir, yspec) < 0)
goto done;
}
}
if (path==NULL){
/* First read api-path from file */
len = 1024; /* any number is fine */
if ((buf = malloc(len)) == NULL){
perror("pt_file malloc");
return -1;
}
memset(buf, 0, len);
i = 0;
while (1){
if ((ret = read(0, &c, 1)) < 0){
perror("read");
goto done;
}
if (ret == 0)
break;
if (c == '\n')
break;
if (len==i){
if ((buf = realloc(buf, 2*len)) == NULL){
fprintf(stderr, "%s: realloc: %s\n", __FUNCTION__, strerror(errno));
return -1;
}
memset(buf+len, 0, len);
len *= 2;
}
buf[i++] = (char)(c&0xff);
}
path = buf;
/* First read api-path from file */
len = 1024; /* any number is fine */
if ((buf = malloc(len)) == NULL){
perror("pt_file malloc");
return -1;
}
memset(buf, 0, len);
i = 0;
while (1){
if ((ret = read(0, &c, 1)) < 0){
perror("read");
goto done;
}
if (ret == 0)
break;
if (c == '\n')
break;
if (len==i){
if ((buf = realloc(buf, 2*len)) == NULL){
fprintf(stderr, "%s: realloc: %s\n", __FUNCTION__, strerror(errno));
return -1;
}
memset(buf+len, 0, len);
len *= 2;
}
buf[i++] = (char)(c&0xff);
}
path = buf;
}
/*
@ -218,90 +218,90 @@ main(int argc,
* XXX Note 0 above, stdin here
*/
if (clixon_xml_parse_file(fp, YB_NONE, NULL, &x, NULL) < 0){
fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason);
return -1;
fprintf(stderr, "Error: parsing: %s\n", clicon_err_reason);
return -1;
}
/* Validate XML as well */
if (yang_file_dir){
/* Populate */
if ((ret = xml_bind_yang(x, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){
if ((cb = cbuf_new()) ==NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (netconf_err2cb(xerr, cb) < 0)
goto done;
fprintf(stderr, "xml validation error: %s\n", cbuf_get(cb));
goto done;
}
/* sort */
if (xml_sort_recurse(x) < 0)
goto done;
if (xml_apply0(x, -1, xml_sort_verify, h) < 0)
clicon_log(LOG_NOTICE, "%s: sort verify failed", __FUNCTION__);
/* Add default values */
if (xml_default_recurse(x, 0) < 0)
goto done;
if ((ret = xml_yang_validate_all_top(h, x, &xerr)) < 0)
goto done;
if (ret > 0 && (ret = xml_yang_validate_add(h, x, &xerr)) < 0)
goto done;
if (ret == 0){
if ((cb = cbuf_new()) ==NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (netconf_err2cb(xerr, cb) < 0)
goto done;
fprintf(stderr, "xml validation error: %s\n", cbuf_get(cb));
goto done;
}
/* Populate */
if ((ret = xml_bind_yang(x, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if (ret == 0){
if ((cb = cbuf_new()) ==NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (netconf_err2cb(xerr, cb) < 0)
goto done;
fprintf(stderr, "xml validation error: %s\n", cbuf_get(cb));
goto done;
}
/* sort */
if (xml_sort_recurse(x) < 0)
goto done;
if (xml_apply0(x, -1, xml_sort_verify, h) < 0)
clicon_log(LOG_NOTICE, "%s: sort verify failed", __FUNCTION__);
/* Add default values */
if (xml_default_recurse(x, 0) < 0)
goto done;
if ((ret = xml_yang_validate_all_top(h, x, &xerr)) < 0)
goto done;
if (ret > 0 && (ret = xml_yang_validate_add(h, x, &xerr)) < 0)
goto done;
if (ret == 0){
if ((cb = cbuf_new()) ==NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (netconf_err2cb(xerr, cb) < 0)
goto done;
fprintf(stderr, "xml validation error: %s\n", cbuf_get(cb));
goto done;
}
}
/* Repeat for performance profiling (default is nr = 1) */
xvec = NULL;
for (i=0; i<nr; i++){
if (api_path_p){
if ((ret = clixon_xml_find_api_path(x, yspec, &xvec, &xlen, "%s", path)) < 0)
goto done;
}
else{
if ((ret = clixon_xml_find_instance_id(x, yspec, &xvec, &xlen, "%s", path)) < 0)
goto done;
}
if (ret == 0){
fprintf(stderr, "Fail %d %s\n", clicon_errno, clicon_err_reason);
goto done;
}
if (api_path_p){
if ((ret = clixon_xml_find_api_path(x, yspec, &xvec, &xlen, "%s", path)) < 0)
goto done;
}
else{
if ((ret = clixon_xml_find_instance_id(x, yspec, &xvec, &xlen, "%s", path)) < 0)
goto done;
}
if (ret == 0){
fprintf(stderr, "Fail %d %s\n", clicon_errno, clicon_err_reason);
goto done;
}
}
/* Print results */
for (i = 0; i < xlen; i++){
xc = xvec[i];
fprintf(stdout, "%d: ", i);
clixon_xml2file(stdout, xc, 0, 0, fprintf, 0, 0);
fprintf(stdout, "\n");
fflush(stdout);
xc = xvec[i];
fprintf(stdout, "%d: ", i);
clixon_xml2file(stdout, xc, 0, 0, fprintf, 0, 0);
fprintf(stdout, "\n");
fflush(stdout);
}
retval = 0;
done:
if (yspec != NULL)
ys_free(yspec);
ys_free(yspec);
if (cb)
cbuf_free(cb);
cbuf_free(cb);
if (xvec)
free(xvec);
free(xvec);
if (buf)
free(buf);
free(buf);
if (x)
xml_free(x);
xml_free(x);
if (xcfg)
xml_free(xcfg);
xml_free(xcfg);
if (fp)
fclose(fp);
fclose(fp);
if (h)
clicon_handle_exit(h);
clicon_handle_exit(h);
return retval;
}