@@ -2370,250 +2370,6 @@ xbps_plist_dictionary_from_file(const char *path);
23702370
23712371/**@}*/
23722372
2373- /** @addtogroup format */
2374- /**@{*/
2375-
2376- /**
2377- * @struct xbps_fmt xbps.h "xbps.h"
2378- * @brief Structure of parsed format string variable.
2379- */
2380- struct xbps_fmt {
2381- /**
2382- * @private
2383- * @var prefix
2384- * @brief Prefix of the format chunk.
2385- */
2386- char * prefix ;
2387- /**
2388- * @var var
2389- * @brief Variable name.
2390- */
2391- char * var ;
2392- /**
2393- * @var def
2394- * @brief Default value.
2395- */
2396- struct xbps_fmt_def * def ;
2397- /**
2398- * @var conv
2399- * @brief Format conversion.
2400- */
2401- struct xbps_fmt_conv * conv ;
2402- /**
2403- * @var spec
2404- * @brief Format specification.
2405- */
2406- struct xbps_fmt_spec * spec ;
2407- };
2408-
2409- /**
2410- * @struct xbps_fmt_def xbps.h "xbps.h"
2411- * @brief Structure of parsed format specifier.
2412- */
2413- struct xbps_fmt_def {
2414- enum {
2415- XBPS_FMT_DEF_STR = 1 ,
2416- XBPS_FMT_DEF_NUM ,
2417- XBPS_FMT_DEF_BOOL ,
2418- } type ;
2419- union {
2420- char * str ;
2421- int64_t num ;
2422- bool boolean ;
2423- } val ;
2424- };
2425-
2426- /**
2427- * @struct xbps_fmt_spec xbps.h "xbps.h"
2428- * @brief Structure of parsed format specifier.
2429- */
2430- struct xbps_fmt_spec {
2431- /**
2432- * @var fill
2433- * @brief Padding character.
2434- */
2435- char fill ;
2436- /**
2437- * @var align
2438- * @brief Alignment modifier.
2439- *
2440- * Possible values are:
2441- * - `<`: left align.
2442- * - `>`: right align.
2443- * - `=`: place padding after the sign.
2444- */
2445- char align ;
2446- /**
2447- * @var sign
2448- * @brief Sign modifier.
2449- *
2450- * Possible values are:
2451- * - `-`: sign negative numbers.
2452- * - `+`: sign both negative and positive numbers.
2453- * - space: sign negative numbers and add space before positive numbers.
2454- */
2455- char sign ;
2456- /**
2457- * @var width
2458- * @brief Minimum width.
2459- */
2460- unsigned int width ;
2461- /**
2462- * @var precision
2463- * @brief Precision.
2464- */
2465- unsigned int precision ;
2466- /**
2467- * @var type
2468- * @brief Type specifier usually to change the output format type.
2469- *
2470- * Can contain any character, xbps_fmt_number() uses the following:
2471- * - `u`: Unsigned decimal.
2472- * - `d`: Decimal.
2473- * - `x`: Hex with lowercase letters.
2474- * - `X`: hex with uppercase letters.
2475- * - `h`: Human readable using humanize_number(3).
2476- */
2477- char type ;
2478- };
2479-
2480- /**
2481- * @brief Format callback, called for each variable in the format string.
2482- *
2483- * A callback function should write data associated with \a var to \a fp and use
2484- * \a w as alignment specifier.
2485- *
2486- * @param[in] fp The file to print to.
2487- * @param[in] spec The format specifier.
2488- * @param[in] var The format string variable name.
2489- * @param[in] data Userdata passed to the xbps_fmt() function.
2490- */
2491- typedef int (xbps_fmt_cb )(FILE * fp , const struct xbps_fmt * fmt , void * data );
2492-
2493- /**
2494- * @brief Parses the format string \a format.
2495- *
2496- * @param[in] format The format string.
2497- *
2498- * @return The parsed format structure, or NULL on error.
2499- * The returned buffer must be freed with xbps_fmt_free().
2500- * @retval EINVAL Invalid format string.
2501- * @retval ERANGE Invalid alignment specifier.
2502- * @retval ENOMEM Memory allocation failure.
2503- */
2504- struct xbps_fmt * xbps_fmt_parse (const char * format );
2505-
2506- /**
2507- * @brief Releases memory associated with \a fmt.
2508- *
2509- * @param[in] fmt The format string.
2510- */
2511- void xbps_fmt_free (struct xbps_fmt * fmt );
2512-
2513- /**
2514- * @brief Print formatted text to \a fp.
2515- *
2516- * @param[in] fmt Format returned by struct xbps_fmt_parse().
2517- * @param[in] cb Callback function called for each variable in the format.
2518- * @param[in] data Userdata passed to the callback \a cb.
2519- * @param[in] fp File to print to.
2520- *
2521- * @return 0 on success or a negative errno.
2522- * @retval 0 Success
2523- */
2524- int xbps_fmt (const struct xbps_fmt * fmt , xbps_fmt_cb * cb , void * data , FILE * fp );
2525-
2526- /**
2527- * @brief Print formatted dictionary values to \a fp.
2528- *
2529- * Prints formatted dictionary values as specified by the parsed \a fmt
2530- * format string to \a fp.
2531- *
2532- * @param[in] fmt Format returned by struct xbps_fmt_parse().
2533- * @param[in] dict Dictionary to print values from.
2534- * @param[in] fp File to print to.
2535- *
2536- * @return 0 on success or value returned by \a cb.
2537- * @retval 0 Success
2538- */
2539- int xbps_fmt_dictionary (const struct xbps_fmt * fmt , xbps_dictionary_t dict , FILE * fp );
2540-
2541- /**
2542- * @brief Print formatted dictionary values to \a fp.
2543- *
2544- * Prints formatted dictionary values as specified by the format string
2545- * \a format to \a fp.
2546- *
2547- * @param[in] format Format string.
2548- * @param[in] dict Dictionary to print values from.
2549- * @param[in] fp File to print to.
2550- *
2551- * @return 0 on success or value returned by \a cb.
2552- * @retval 0 Success
2553- */
2554- int xbps_fmts_dictionary (const char * format , xbps_dictionary_t dict , FILE * fp );
2555-
2556- /**
2557- * @brief Print formatted dictionary to \a fp.
2558- *
2559- * Print the formatted dictionary according to the \a format format string
2560- * to \a fp.
2561- *
2562- * @param[in] format Format string.
2563- * @param[in] cb Callback function called for each variable in the format.
2564- * @param[in] data Userdata passed to the callback \a cb.
2565- * @param[in] fp File to print to.
2566- *
2567- * @return 0 on success.
2568- * @retval 0 Success.
2569- * @retval -EINVAL Invalid format string.
2570- * @retval -ERANGE Invalid alignment specifier.
2571- * @retval -ENOMEM Memory allocation failure.
2572- */
2573- int xbps_fmts (const char * format , xbps_fmt_cb * cb , void * data , FILE * fp );
2574-
2575- /**
2576- * @brief Print formatted number to \a fp.
2577- *
2578- * Prints the number \a num to \a fp according to the specification \a spec.
2579- *
2580- * @param[in] spec Format specification.
2581- * @param[in] num Number to print.
2582- * @param[in] fp File to print to.
2583- *
2584- * @return Returns 0 on success.
2585- */
2586- int xbps_fmt_print_number (const struct xbps_fmt * fmt , int64_t num , FILE * fp );
2587-
2588- /**
2589- * @brief Print formatted string to \a fp.
2590- *
2591- * Prints the string \a str to \a fp according to the specification \a spec.
2592- *
2593- * @param[in] spec Format specification.
2594- * @param[in] str String to print.
2595- * @param[in] len Length of the string or 0.
2596- * @param[in] fp File to print to.
2597- *
2598- * @return Returns 0 on success.
2599- */
2600- int xbps_fmt_print_string (const struct xbps_fmt * fmt , const char * str , size_t len , FILE * fp );
2601-
2602- /**
2603- * @brief Print formatted ::xbps_object_t to \a fp.
2604- *
2605- * Prints the ::xbps_object_t \a obj to \a fp according to the specification \a spec.
2606- *
2607- * @param[in] spec Format specification.
2608- * @param[in] obj The object to print.
2609- * @param[in] fp File to print to.
2610- *
2611- * @return Returns 0 on success.
2612- */
2613- int xbps_fmt_print_object (const struct xbps_fmt * fmt , xbps_object_t obj , FILE * fp );
2614-
2615- /**@}*/
2616-
26172373#ifdef __cplusplus
26182374}
26192375#endif
0 commit comments