json print revert
This commit is contained in:
parent
601d79b972
commit
fe91ba707d
3 changed files with 46 additions and 35 deletions
|
|
@ -137,6 +137,7 @@ enum list_element_type{
|
|||
LIST_MIDDLE,
|
||||
LIST_LAST
|
||||
};
|
||||
|
||||
static enum list_element_type
|
||||
list_eval(cxobj *x)
|
||||
{
|
||||
|
|
@ -179,11 +180,8 @@ list_eval(cxobj *x)
|
|||
return list;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* @param[in] pretty set if the output should be pretty-printed
|
||||
|
||||
|
||||
* List only if adjacent,
|
||||
* ie <a>1</a><a>2</a><b>3</b> -> {"a":[1,2],"b":3}
|
||||
* ie <a>1</a><b>3</b><a>2</a> -> {"a":1,"b":3,"a":2}
|
||||
|
|
@ -252,22 +250,29 @@ xml2json1_cbuf(cbuf *cb,
|
|||
}
|
||||
switch (list){
|
||||
case LIST_NO:
|
||||
if (!tleaf(x))
|
||||
if (!tleaf(x)){
|
||||
if (pretty)
|
||||
cprintf(cb, "%*s}\n",
|
||||
(level*JSON_INDENT), "");
|
||||
else
|
||||
cprintf(cb, "}");
|
||||
}
|
||||
break;
|
||||
case LIST_MIDDLE:
|
||||
case LIST_FIRST:
|
||||
if (pretty)
|
||||
cprintf(cb, "\n%*s}",
|
||||
(level*JSON_INDENT), "");
|
||||
else
|
||||
cprintf(cb, "}");
|
||||
break;
|
||||
case LIST_LAST:
|
||||
if (!tleaf(x)){
|
||||
if (pretty)
|
||||
cprintf(cb, "\n%*s}\n",
|
||||
(level*JSON_INDENT), "");
|
||||
else
|
||||
cprintf(cb, "}");
|
||||
level--;
|
||||
}
|
||||
cprintf(cb, "%*s]%s",
|
||||
|
|
@ -309,15 +314,16 @@ xml2json_cbuf(cbuf *cb,
|
|||
int pretty)
|
||||
{
|
||||
int retval = 1;
|
||||
int level = 0;
|
||||
int i;
|
||||
cxobj *xc;
|
||||
int level = 1;
|
||||
|
||||
for (i=0; i<xml_child_nr(x); i++){
|
||||
xc = xml_child_i(x, i);
|
||||
if (xml2json1_cbuf(cb, xc, level, pretty) < 0)
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "%*s{%s",
|
||||
pretty?(level*JSON_INDENT):0,"",
|
||||
pretty?"\n":"");
|
||||
if (xml2json1_cbuf(cb, x, level+1, pretty) < 0)
|
||||
goto done;
|
||||
cprintf(cb, "%*s}%s",
|
||||
pretty?(level*JSON_INDENT):0,"",
|
||||
pretty?"\n":"");
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
|
|||
|
|
@ -38,11 +38,15 @@
|
|||
#include "clixon_log.h"
|
||||
#include "clixon_sig.h"
|
||||
|
||||
/*
|
||||
* Set a signal handler.
|
||||
/*! Set a signal handler.
|
||||
* @param[in] signo Signal number
|
||||
* @param[in] handler Function to call when signal occurs
|
||||
* @param[out] oldhandler Pointer to old handler
|
||||
*/
|
||||
int
|
||||
set_signal(int signo, void (*handler)(int), void (**oldhandler)(int))
|
||||
set_signal(int signo,
|
||||
void (*handler)(int),
|
||||
void (**oldhandler)(int))
|
||||
{
|
||||
#if defined(HAVE_SIGACTION)
|
||||
struct sigaction sold, snew;
|
||||
|
|
@ -64,8 +68,8 @@ set_signal(int signo, void (*handler)(int), void (**oldhandler)(int))
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* Block signal. If 'sig' is 0, block all signals
|
||||
/*! Block signal.
|
||||
* @param[in] sig Signal number to block, If 0, block all signals
|
||||
*/
|
||||
void
|
||||
clicon_signal_block (int sig)
|
||||
|
|
@ -82,8 +86,8 @@ clicon_signal_block (int sig)
|
|||
sigprocmask (SIG_BLOCK, &set, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unblock signal. If 'sig' is 0, unblock all signals
|
||||
/*! Unblock signal.
|
||||
* @param[in] sig Signal number to unblock. If 0, unblock all signals
|
||||
*/
|
||||
void
|
||||
clicon_signal_unblock (int sig)
|
||||
|
|
@ -108,7 +112,8 @@ clicon_signal_unblock (int sig)
|
|||
* @retval -1 Error, and clicon_err() called
|
||||
*/
|
||||
int
|
||||
pidfile_get(char *pidfile, pid_t *pid0)
|
||||
pidfile_get(char *pidfile,
|
||||
pid_t *pid0)
|
||||
{
|
||||
FILE *f;
|
||||
char *ptr;
|
||||
|
|
@ -156,7 +161,6 @@ pidfile_zapold(pid_t pid)
|
|||
/*! Write a pid-file
|
||||
*
|
||||
* @param[in] pidfile Name of pidfile
|
||||
* @param[in] kill_it If set, kill existing process otherwise return pid
|
||||
*/
|
||||
int
|
||||
pidfile_write(char *pidfile)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue