Skip to content

Commit 754fae2

Browse files
committed
lib/format.c: refactor a bit
1 parent ea189d1 commit 754fae2

File tree

3 files changed

+189
-159
lines changed

3 files changed

+189
-159
lines changed

include/xbps.h.in

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,19 +2372,35 @@ xbps_plist_dictionary_from_file(const char *path);
23722372
* @struct xbps_fmt xbps.h "xbps.h"
23732373
* @brief Structure of parsed format string.
23742374
*/
2375-
struct xbps_fmt;
2375+
struct xbps_fmt {
2376+
/**
2377+
* @private
2378+
* @var prefix
2379+
* @brief Prefix of the format chunk.
2380+
*/
2381+
char *prefix;
2382+
/**
2383+
* @var var
2384+
* @brief Variable name.
2385+
*/
2386+
char *var;
2387+
/**
2388+
* @var conv
2389+
* @brief Format conversion.
2390+
*/
2391+
struct xbps_fmt_conv *conv;
2392+
/**
2393+
* @var spec
2394+
* @brief Format specification.
2395+
*/
2396+
struct xbps_fmt_spec *spec;
2397+
};
23762398

23772399
/**
23782400
* @struct xbps_fmt xbps.h "xbps.h"
23792401
* @brief Structure of parsed format specifier.
23802402
*/
23812403
struct xbps_fmt_spec {
2382-
/**
2383-
* @private
2384-
* @var conversion
2385-
* @brief Output conversion.
2386-
*/
2387-
struct conversion *conversion;
23882404
/**
23892405
* @var fill
23902406
* @brief Padding character.
@@ -2445,7 +2461,7 @@ struct xbps_fmt_spec {
24452461
* @param[in] var The format string variable name.
24462462
* @param[in] data Userdata passed to the xbps_fmt() function.
24472463
*/
2448-
typedef int (xbps_fmt_cb)(FILE *fp, const struct xbps_fmt_spec *spec, const char *var, void *data);
2464+
typedef int (xbps_fmt_cb)(FILE *fp, const struct xbps_fmt *fmt, void *data);
24492465

24502466
/**
24512467
* @brief Parses the format string \a format.
@@ -2532,15 +2548,15 @@ int xbps_fmts(const char *format, xbps_fmt_cb *cb, void *data, FILE *fp);
25322548
/**
25332549
* @brief Print formatted number to \a fp.
25342550
*
2535-
* Prints the number \d to \a fp according to the specification \a spec.
2551+
* Prints the number \a num to \a fp according to the specification \a spec.
25362552
*
25372553
* @param[in] spec Format specification.
25382554
* @param[in] num Number to print.
25392555
* @param[in] fp File to print to.
25402556
*
25412557
* @return Returns 0 on success.
25422558
*/
2543-
int xbps_fmt_number(const struct xbps_fmt_spec *spec, int64_t num, FILE *fp);
2559+
int xbps_fmt_print_number(const struct xbps_fmt *fmt, int64_t num, FILE *fp);
25442560

25452561
/**
25462562
* @brief Print formatted string to \a fp.
@@ -2554,7 +2570,20 @@ int xbps_fmt_number(const struct xbps_fmt_spec *spec, int64_t num, FILE *fp);
25542570
*
25552571
* @return Returns 0 on success.
25562572
*/
2557-
int xbps_fmt_string(const struct xbps_fmt_spec *spec, const char *str, size_t len, FILE *fp);
2573+
int xbps_fmt_print_string(const struct xbps_fmt *fmt, const char *str, size_t len, FILE *fp);
2574+
2575+
/**
2576+
* @brief Print formatted ::xbps_object_t to \a fp.
2577+
*
2578+
* Prints the ::xbps_object_t \a obj to \a fp according to the specification \a spec.
2579+
*
2580+
* @param[in] spec Format specification.
2581+
* @param[in] obj The object to print.
2582+
* @param[in] fp File to print to.
2583+
*
2584+
* @return Returns 0 on success.
2585+
*/
2586+
int xbps_fmt_print_object(const struct xbps_fmt *fmt, xbps_object_t obj, FILE *fp);
25582587

25592588
/**@}*/
25602589

0 commit comments

Comments
 (0)