json_pipe.c
Go to the documentation of this file.
1 #include "../csm/csm_all.h"
2 #include <options/options.h>
3 
4 int main(int argc, const char * argv[]) {
5  sm_set_program_name(argv[0]);
6 
7  int n;
8 
9  struct option* ops = options_allocate(3);
10  options_int(ops, "n", &n, 1, "Number of copies");
11  if(!options_parse_args(ops, argc, argv)) {
12  sm_info("%s : reads a JSON stream and copies it multiplied by n."
13  "\n\nOptions:\n", (char*)argv[0]);
14  options_print_help(ops, stderr);
15  return -1;
16  }
17 
18 
19  while(1) {
20  JO jo = json_read_stream(stdin);
21  if(!jo) {
22  if(feof(stdin)) break;
23  sm_error("Malformed JSON\n");
24  return -1;
25  }
26 
27  const char * s = json_object_to_json_string(jo);
28  int i; for(i=0;i<n;i++) {
29  puts(s); puts("\n");
30  }
31  jo_free(jo);
32  }
33 
34  return 0;
35 }
void sm_set_program_name(const char *name)
Definition: logging.c:21
struct option * ops
Definition: rb_sm.c:31
Definition: options.h:49
struct option * options_allocate(int n)
const char * json_object_to_json_string(struct json_object *this)
Definition: json_object.c:199
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
void options_print_help(struct option *options, FILE *f)
Definition: options.c:398
int main(int argc, const char *argv[])
Definition: json_pipe.c:4
void sm_info(const char *msg,...)
Definition: logging.c:71
JO json_read_stream(FILE *f)
void sm_error(const char *msg,...)
Definition: logging.c:49
int options_parse_args(struct option *ops, int argc, const char *argv[])
Definition: options.c:66
#define jo_free


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23