diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-11-23 13:39:56 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-11-23 13:39:56 +0100 |
commit | 8c7fd0a0b2e1abc72d67a1bd3a838054b3938f1f (patch) | |
tree | d7c339f5da946a9e205321f9bbeb63c6e31169c8 /utils | |
parent | fixes (diff) | |
download | travnik-8c7fd0a0b2e1abc72d67a1bd3a838054b3938f1f.tar travnik-8c7fd0a0b2e1abc72d67a1bd3a838054b3938f1f.tar.gz travnik-8c7fd0a0b2e1abc72d67a1bd3a838054b3938f1f.tar.bz2 travnik-8c7fd0a0b2e1abc72d67a1bd3a838054b3938f1f.tar.lz travnik-8c7fd0a0b2e1abc72d67a1bd3a838054b3938f1f.tar.xz travnik-8c7fd0a0b2e1abc72d67a1bd3a838054b3938f1f.tar.zst travnik-8c7fd0a0b2e1abc72d67a1bd3a838054b3938f1f.zip |
Diffstat (limited to 'utils')
-rw-r--r-- | utils/bencoding.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/utils/bencoding.c b/utils/bencoding.c index ae80546..1e90737 100644 --- a/utils/bencoding.c +++ b/utils/bencoding.c @@ -8,7 +8,7 @@ #define S0(x) (x ? x : "") int main (int argc, char ** argv) { if (argc < 1+1) - error_at_line(1, 0, __FILE__, __LINE__, "%s encode < json || %s decode < bencoding || %s path path/to/obj < bencoding || %s foreach < bencoding", S0(argv[0]), S0(argv[0]), S0(argv[0]), S0(argv[0])); + error_at_line(1, 0, __FILE__, __LINE__, "%s encode < json || %s decode < bencoding || %s path path/to/obj < bencoding || %s foreach < bencoding || %s val value < bencoding (should output null or value as JSON string if found in array)", S0(argv[0]), S0(argv[0]), S0(argv[0]), S0(argv[0]), S0(argv[0])); if (argv[1][0] == 'p' && argc != 1+2) error_at_line(1, 0, __FILE__, __LINE__, "set path!"); int size = 2048; @@ -23,7 +23,7 @@ int main (int argc, char ** argv) { } if (argv[1][0] == 'e') error_at_line(3, 0, __FILE__, __LINE__, "N/I"); - struct bencoding * bencoding = bdecode(in, size, terminate); + struct bencoding * bencoding = bdecode(in, size, 0); if (argv[1][0] == 'd') { len = b2json_length(bencoding); char out[len+1]; @@ -44,6 +44,16 @@ int main (int argc, char ** argv) { error_at_line(4, 0, __FILE__, __LINE__, "b2json wrote %ld instead of %d bytes.", end-out, len); fprintf(stderr, "len: %d\n", len); } + if (argv[1][0] == 'v') { + len = b2json_length(bval(bencoding, argv[2])); + char out[len+1]; + char * end = b2json(out, bval(bencoding, argv[2])); + *end = '\0'; + puts(out); + if (end - out != len) + error_at_line(4, 0, __FILE__, __LINE__, "b2json wrote %ld instead of %d bytes.", end-out, len); + fprintf(stderr, "len: %d\n", len); + } if (argv[1][0] == 'f') { bforeach (value, bencoding) { len = b2json_length(value->key); |