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