bcode_print: swap parameters order
Better aligns with printf-family of functions.
This commit is contained in:
parent
40b57f9b32
commit
a7ea02282f
20
bcode.c
20
bcode.c
@ -86,8 +86,8 @@ static size_t parse_dictionary(struct bcode_dictionary *, const uint8_t *,
|
|||||||
size_t);
|
size_t);
|
||||||
static size_t parse_internal(struct bcode *, const uint8_t *, size_t);
|
static size_t parse_internal(struct bcode *, const uint8_t *, size_t);
|
||||||
static void free_internal(struct bcode *);
|
static void free_internal(struct bcode *);
|
||||||
static void print_string(const struct bcode_string *, FILE *);
|
static void print_string(FILE *, const struct bcode_string *);
|
||||||
static void print_internal(const struct bcode *, FILE *, size_t);
|
static void print_internal(FILE *, const struct bcode *, size_t);
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -446,7 +446,7 @@ bcode_free(struct bcode *bcode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_string(const struct bcode_string *s, FILE *fp)
|
print_string(FILE *fp, const struct bcode_string *s)
|
||||||
{
|
{
|
||||||
char buf[5];
|
char buf[5];
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -466,13 +466,13 @@ print_string(const struct bcode_string *s, FILE *fp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_internal(const struct bcode *bcode, FILE *fp, size_t lvl)
|
print_internal(FILE *fp, const struct bcode *bcode, size_t lvl)
|
||||||
{
|
{
|
||||||
size_t i, k;
|
size_t i, k;
|
||||||
|
|
||||||
switch (bcode->type) {
|
switch (bcode->type) {
|
||||||
case BCODE_STRING:
|
case BCODE_STRING:
|
||||||
print_string(&bcode->string, fp);
|
print_string(fp, &bcode->string);
|
||||||
break;
|
break;
|
||||||
case BCODE_INTEGER:
|
case BCODE_INTEGER:
|
||||||
fprintf(fp, "%" PRIi64, bcode->integer);
|
fprintf(fp, "%" PRIi64, bcode->integer);
|
||||||
@ -483,7 +483,7 @@ print_internal(const struct bcode *bcode, FILE *fp, size_t lvl)
|
|||||||
for (i = 0; i < bcode->list.sz; i++) {
|
for (i = 0; i < bcode->list.sz; i++) {
|
||||||
for (k = 0; k < lvl; k++)
|
for (k = 0; k < lvl; k++)
|
||||||
fputs(" ", fp);
|
fputs(" ", fp);
|
||||||
print_internal(&bcode->list.elems[i], fp, lvl);
|
print_internal(fp, &bcode->list.elems[i], lvl);
|
||||||
fputs(",\n", fp);
|
fputs(",\n", fp);
|
||||||
}
|
}
|
||||||
lvl--;
|
lvl--;
|
||||||
@ -498,9 +498,9 @@ print_internal(const struct bcode *bcode, FILE *fp, size_t lvl)
|
|||||||
for (i = 0; i < bcode->dictionary.sz; i++) {
|
for (i = 0; i < bcode->dictionary.sz; i++) {
|
||||||
for (k = 0; k < lvl; k++)
|
for (k = 0; k < lvl; k++)
|
||||||
fputs(" ", fp);
|
fputs(" ", fp);
|
||||||
print_string(&bcode->dictionary.elems[i].k, fp);
|
print_string(fp, &bcode->dictionary.elems[i].k);
|
||||||
fputs(": ", fp);
|
fputs(": ", fp);
|
||||||
print_internal(&bcode->dictionary.elems[i].v, fp, lvl);
|
print_internal(fp, &bcode->dictionary.elems[i].v, lvl);
|
||||||
fputs(",\n", fp);
|
fputs(",\n", fp);
|
||||||
}
|
}
|
||||||
lvl--;
|
lvl--;
|
||||||
@ -516,8 +516,8 @@ print_internal(const struct bcode *bcode, FILE *fp, size_t lvl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bcode_print(const struct bcode *bcode, FILE *fp)
|
bcode_print(FILE *fp, const struct bcode *bcode)
|
||||||
{
|
{
|
||||||
print_internal(bcode, fp, 0);
|
print_internal(fp, bcode, 0);
|
||||||
fputc('\n', fp);
|
fputc('\n', fp);
|
||||||
}
|
}
|
||||||
|
2
bt.c
2
bt.c
@ -79,7 +79,7 @@ main(int argc, char *argv[])
|
|||||||
bcode = bcode_parse(buf, bufsz);
|
bcode = bcode_parse(buf, bufsz);
|
||||||
if (bcode == NULL)
|
if (bcode == NULL)
|
||||||
errx(1, "bcode_parse: parse error");
|
errx(1, "bcode_parse: parse error");
|
||||||
bcode_print(bcode, stdout);
|
bcode_print(stdout, bcode);
|
||||||
bcode_free(bcode);
|
bcode_free(bcode);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
6
bt.h
6
bt.h
@ -33,6 +33,6 @@ struct bcode;
|
|||||||
|
|
||||||
/* bencode */
|
/* bencode */
|
||||||
|
|
||||||
struct bcode * bcode_parse(const uint8_t *, size_t);
|
struct bcode *bcode_parse(const uint8_t *, size_t);
|
||||||
void bcode_free(struct bcode *);
|
void bcode_free(struct bcode *);
|
||||||
void bcode_print(const struct bcode *, FILE *);
|
void bcode_print(FILE *, const struct bcode *);
|
||||||
|
Loading…
Reference in New Issue
Block a user