Diff for /libelwix/example/test_json.c between versions 1.1.2.4 and 1.1.2.5

version 1.1.2.4, 2017/11/28 11:14:00 version 1.1.2.5, 2017/11/28 11:45:05
Line 2 Line 2
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
 #include <fcntl.h>  #include <fcntl.h>
   #include <errno.h>
 #include <sys/types.h>  #include <sys/types.h>
 #include <elwix.h>  #include <elwix.h>
   
Line 96  run_simple(json_t *json) Line 97  run_simple(json_t *json)
 }  }
   
 int  int
   run_dump(json_t *json)
   {
           int rlen, toksnum, wait4eof = 0;
           char buf[BUFSIZ];
           ait_val_t v;
           jtok_t *toks, *t;
   
           toks = e_malloc(sizeof(jtok_t));
           if (!toks)
                   return 1;
           else
                   toksnum = 1;
           AIT_SET_STRSIZ(&v, 1);
           while (42) {
                   memset(buf, 0, sizeof buf);
                   rlen = fread(buf, 1, sizeof buf, stdin);
                   switch (rlen) {
                           case -1:
                                   printf("Error:: fread() #%d - %s\n", errno, strerror(errno));
                                   AIT_FREE_VAL(&v);
                                   e_free(toks);
                                   return 2;
                           case 0:
                                   if (wait4eof)
                                           return 0;
                                   printf("Error:: Unexpected termination!\n");
                                   AIT_FREE_VAL(&v);
                                   e_free(toks);
                                   return 3;
                           default:
                                   AIT_SET_STRCAT(&v, buf);
                                   break;
                   }
   again:
                   rlen = json_parse(json, AIT_GET_STR(&v), AIT_LEN(&v), toks, toksnum);
                   if (rlen == (u_int) -1) {
                           if (elwix_GetErrno() == J_ERR_NOMEM) {
                                   toksnum *= 2;
                                   t = e_realloc(toks, sizeof(jtok_t) * toksnum);
                                   if (t) {
                                           toks = t;
                                           goto again;
                                   }
                           }
                   } else {
                           dump(AIT_GET_STR(&v), toks, json->h_next, 0);
                           wait4eof = 1;
                   }
           }
           AIT_FREE_VAL(&v);
           e_free(toks);
   
           return 0;
   }
   
   int
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
         json_t json;          json_t json;
   
         if (argc < 2)          if (argc < 2)
                 return run_simple(&json);                  return run_simple(&json);
           else
                   return run_dump(&json);
   
         return 0;          return 0;
 }  }

Removed from v.1.1.2.4  
changed lines
  Added in v.1.1.2.5


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>