view th_args.h @ 584:390c66af09cf

Move th_print_wrap() and th_print_pad() to th_args from th_string.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 12 Jan 2020 14:27:09 +0200
parents d60e1d751b5b
children 98812eb78d8e
line wrap: on
line source

/*
 * Simple commandline argument processing functions
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2002-2020 Tecnic Software productions (TNSP)
 *
 * Please read file 'COPYING' for information on license and distribution.
 */
/// @file
/// @brief Simple commandline argument processing functions
#ifndef TH_ARGS_H
#define TH_ARGS_H

#include "th_util.h"
#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

/** @def Option argument flags
 */
#define OPT_NONE             (0)    ///< Simple option with no arguments
#define OPT_ARGREQ           (1)    ///< Option requires an argument
#define OPT_ARGMASK          (1)    ///< Mask for option argument flags

/** @def Option processing flags
 */
#define OPTH_BAILOUT         0x0001 ///< Bail out on errors
#define OPTH_ONLY_OPTS       0x0010 ///< Handle only options
#define OPTH_ONLY_OTHER      0x0020 ///< Handle only "non-options"
#define OPTH_ONLY_MASK       0x00f0 ///< Mask


/** Option argument structure
 */
typedef struct
{
    int id;           ///< Option ID (should be unique for each option)
    char o_short;     ///< Short option name (one character, can be 0 for none)
    char *o_long;     ///< Long option name (can be NULL for none)
    char *desc;       ///< Option description
    int flags;        ///< Flags (see OPT_*)
} th_optarg;


BOOL     th_args_process(int argc, char *argv[],
         const th_optarg *opts, const int nopts,
         BOOL (*handle_option)(int id, char *, char *),
         BOOL (*handle_other)(char *), const int flags);

void     th_args_help(FILE *fh, const th_optarg *opts,
         const int nopts, const int flags);

void     th_print_wrap(FILE *fh, const char *str,
         const int spad, const int rpad, const int width);

#ifdef __cplusplus
}
#endif
#endif // TH_ARGS_H