Page 1 of 6 12345 ... LastLast
Results 1 to 25 of 150
  1. #1
    Boring = 4 Rings SA210's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Oct 2005
    Post Count
    14,286
    .
    An open message to Terrorist Obama..for murdering over 4700 men, women and children with his illegal drone program with 98% of the casualties being innocent non-combatants, not to mention the extension of the Afghanistan war and illegal intervention in Libya.

    Obama, who exactly do you think you're fooling at this point?...By your definition, you are a terrorist and should be the one rotting in Guantanamo Bay

    An Open Message to Barack Obama




    Props to Storm Clouds Gathering for another excellent video

  2. #2
    57-Chambers Woo Bum-kon's Avatar
    My Team
    Houston Rockets
    Join Date
    Mar 2012
    Post Count
    1,603
    still can't explain why Tamerlan would trust the FBI
    failing completely the first time you actually post your very own conspiracy theory

  3. #3
    Boring = 4 Rings SA210's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Oct 2005
    Post Count
    14,286
    I troll topics bc I'm angry SA210 owned me too
    Wrong thread, pussy. You can go troll the other one where I owned you and the others badly. This is about Terrorist Obama and the the fact about his mass murder of almost 5,000 human beings with his illegal war criminal drone program. Thanks

  4. #4
    57-Chambers Woo Bum-kon's Avatar
    My Team
    Houston Rockets
    Join Date
    Mar 2012
    Post Count
    1,603
    I can turn threads about school shootings, Boston Bombings, Christmas, etc. into threads about Barack Obama and drones because I'm raising awareness! But when you try to change the subject of a thread, you're a troll!
    failed utterly when you presented your first conspiracy theory

  5. #5
    Boring = 4 Rings SA210's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Oct 2005
    Post Count
    14,286
    I failed utterly when SA210 presented facts about my conspiracy theory

    I was right, proved you wrong and you're still butthurt about it.

    19 yr old boy was unarmed in an "hour long back and forth shootout with police"

    trolling topics out of desperation and butthurt, and lying.

  6. #6
    57-Chambers Woo Bum-kon's Avatar
    My Team
    Houston Rockets
    Join Date
    Mar 2012
    Post Count
    1,603
    I didn't present a conspiracy theory, moron.

    I was right, proved you wrong and you're still butthurt about it.
    You claimed that the government was behind the bombings. You haven't proven that at all.

    19 yr old boy was unarmed in an "hour long back and forth shootout with police"
    That doesn't make any sense. Even if what you said is 100% true, that doesn't mean he wasn't behind the bombings.

    Your conspiracy theories make no sense whatsoever, and the conclusions that you get from your "evidence" aren't logical at all. Maybe it's because you came to your conclusion, then started to looking for evidence supporting it, like you always do.

    And... still can't explain why Tamerlan would trust the FBI.
    still can't explain why the FBI would kill Tamerlan and not his brother.

  7. #7
    Boring = 4 Rings SA210's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Oct 2005
    Post Count
    14,286
    excessive emotions and lying to compensate for being a wuss
    still trolling topics that have nothing to do with the topic your were owned in
    avatar of a mass murderer

  8. #8
    57-Chambers Woo Bum-kon's Avatar
    My Team
    Houston Rockets
    Join Date
    Mar 2012
    Post Count
    1,603
    excessive emotions and lying to compensate for being a wuss
    lol excessive emotions. You are the one who cries " ," "sheep," and "liar" whenever somebody disagrees with you.

    still trolling topics that have nothing to do with the topic your were owned in
    lol giant hypocrite who turns everything into a discussion about drones doesn't like it when somebody else changes the subject
    lol still can't explain how I was owned
    lol still dodging questions

    avatar of a mass murderer
    You know what's funny? If Woo was an American citizen who went on a killing spree in 2013, you'd be taking his side and claiming that the government was responsible.

    Next, you'll call me an Obama-supporter, and your entire insult repertoire will be depleted.

  9. #9
    Boring = 4 Rings SA210's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Oct 2005
    Post Count
    14,286
    *yawn* more lies from the troll, and butthurt mass murder supporter lol. If you'd like to discuss your lies over a cup of coffee, let me know

    For now, back to the topic..


    .
    An open message to Terrorist Obama..for murdering over 4700 men, women and children with his illegal drone program with 98% of the casualties being innocent non-combatants, not to mention the extension of the Afghanistan war and illegal intervention in Libya.



    An Open Message to Barack Obama




    Props to Storm Clouds Gathering for another excellent video

  10. #10
    57-Chambers Woo Bum-kon's Avatar
    My Team
    Houston Rockets
    Join Date
    Mar 2012
    Post Count
    1,603
    the guy who defended two people who murdered four people in the span of a week, is calling somebody else a supporter of mass murder

  11. #11
    right about pizzagate Blake's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Jan 2006
    Post Count
    83,650
    Because Obama watches YouTube.

    And the background of storm clouds + blood splatter = instant credibility

  12. #12
    All Hail the Legatron The Reckoning's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Sep 2008
    Post Count
    10,568
    lol didnt watch. no gif needed.
    Last edited by The Reckoning; 04-28-2013 at 08:43 AM.

  13. #13
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881

  14. #14
    Boring = 4 Rings SA210's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Oct 2005
    Post Count
    14,286
    Yup, I'm also part of the butthurt crew that SA210 owned. Btw, I know SA210 posted facts about Obama being a mass murderer, so I'll try and change the subject to divert attention from that. I support child murder and state sponsored terrorism like some of my fellow butthurt posters

  15. #15
    Banned
    My Team
    San Antonio Spurs
    Join Date
    May 2012
    Post Count
    49,723
    Obama a terrorist...hahahaha!!!!!!!!!! Obviously OP doesn't know the meaning of the word.

  16. #16
    Boring = 4 Rings SA210's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Oct 2005
    Post Count
    14,286
    Obama a terrorist...hahahaha!!!!!!!!!! Obviously OP doesn't know the meaning of the word.
    nah, it's obvious you haven't studied the illegal drone program, or you choose to ignore it. Children and families are being terrorized and murdered. He's a terrorist. He's a war criminal. He's a mass child murderer. It's just a fact.

    In before the lie gets spewed about how they are all terrorists over there including kids and terrorists use kids as shields so it isn't our fault even though we are in illegal wars and shouldn't be there to begin with, etc blah blah blah..

    Ignorance

  17. #17
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    /* Hierarchial argument parsing, layered over getopt.
    Copyright (C) 1995-1999, 2003, 2004, 2005, 2006, 2007, 2009, 2012
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <[email protected]>.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>. */

    #ifndef _ARGP_H
    #define _ARGP_H

    #include <stdio.h>
    #include <ctype.h>
    #include <getopt.h>
    #include <limits.h>

    #define __need_error_t
    #include <errno.h>

    #ifndef __THROW
    # define __THROW
    #endif
    #ifndef __NTH
    # define __NTH(fct) fct __THROW
    #endif

    #ifndef __attribute__
    /* This feature is available in gcc versions 2.5 and later. */
    # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
    # define __attribute__(Spec) /* empty */
    # endif
    /* The __-protected variants of `format' and `printf' attributes
    are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
    # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || __STRICT_ANSI__
    # define __format__ format
    # define __printf__ printf
    # endif
    #endif

    /* GCC 2.95 and later have "__restrict"; C99 compilers have
    "restrict", and "configure" may have defined "restrict". */
    #ifndef __restrict
    # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
    # if defined restrict || 199901L <= __STDC_VERSION__
    # define __restrict restrict
    # else
    # define __restrict
    # endif
    # endif
    #endif

    #ifndef __error_t_defined
    typedef int error_t;
    # define __error_t_defined
    #endif

    #ifdef __cplusplus
    extern "C" {
    #endif

    /* A description of a particular option. A pointer to an array of
    these is passed in the OPTIONS field of an argp structure. Each option
    entry can correspond to one long option and/or one short option; more
    names for the same option can be added by following an entry in an option
    array with options having the OPTION_ALIAS flag set. */
    struct argp_option
    {
    /* The long option name. For more than one name for the same option, you
    can use following options with the OPTION_ALIAS flag set. */
    const char *name;

    /* What key is returned for this option. If > 0 and printable, then it's
    also accepted as a short option. */
    int key;

    /* If non-NULL, this is the name of the argument associated with this
    option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */
    const char *arg;

    /* OPTION_ flags. */
    int flags;

    /* The doc string for this option. If both NAME and KEY are 0, This string
    will be printed outdented from the normal option column, making it
    useful as a group header (it will be the first thing printed in its
    group); in this usage, it's conventional to end the string with a `:'. */
    const char *doc;

    /* The group this option is in. In a long help message, options are sorted
    alphabetically within each group, and the groups presented in the order
    0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with
    if this field 0 will inherit the group number of the previous entry, or
    zero if it's the first one, unless its a group header (NAME and KEY both
    0), in which case, the previous entry + 1 is the default. Automagic
    options such as --help are put into group -1. */
    int group;
    };

    /* The argument associated with this option is optional. */
    #define OPTION_ARG_OPTIONAL 0x1

    /* This option isn't displayed in any help messages. */
    #define OPTION_HIDDEN 0x2

    /* This option is an alias for the closest previous non-alias option. This
    means that it will be displayed in the same help entry, and will inherit
    fields other than NAME and KEY from the aliased option. */
    #define OPTION_ALIAS 0x4

    /* This option isn't actually an option (and so should be ignored by the
    actual option parser), but rather an arbitrary piece of do entation that
    should be displayed in much the same manner as the options. If this flag
    is set, then the option NAME field is displayed unmodified (e.g., no `--'
    prefix is added) at the left-margin (where a *short* option would normally
    be displayed), and the do entation string in the normal place. For
    purposes of sorting, any leading whitespace and punctuation is ignored,
    except that if the first non-whitespace character is not `-', this entry
    is displayed after all options (and OPTION_DOC entries with a leading `-')
    in the same group. */
    #define OPTION_DOC 0x8

    /* This option shouldn't be included in `long' usage messages (but is still
    included in help messages). This is mainly intended for options that are
    completely do ented in an argp's ARGS_DOC field, in which case including
    the option in the generic usage list would be redundant. For instance,
    if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to
    distinguish these two cases, -x should probably be marked
    OPTION_NO_USAGE. */
    #define OPTION_NO_USAGE 0x10

    struct argp; /* fwd declare this type */
    struct argp_state; /* " */
    struct argp_child; /* " */

    /* The type of a pointer to an argp parsing function. */
    typedef error_t (*argp_parser_t) (int __key, char *__arg,
    struct argp_state *__state);

    /* What to return for unrecognized keys. For special ARGP_KEY_ keys, such
    returns will simply be ignored. For user keys, this error will be turned
    into EINVAL (if the call to argp_parse is such that errors are propagated
    back to the user instead of exiting); returning EINVAL itself would result
    in an immediate stop to parsing in *all* cases. */
    #define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */

    /* Special values for the KEY argument to an argument parsing function.
    ARGP_ERR_UNKNOWN should be returned if they aren't understood.

    The sequence of keys to a parsing function is either (where each
    uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key):

    INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all
    or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed
    or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized

    The third case is where every parser returned ARGP_KEY_UNKNOWN for an
    argument, in which case parsing stops at that argument (returning the
    unparsed arguments to the caller of argp_parse if requested, or stopping
    with an error message if not).

    If an error occurs (either detected by argp, or because the parsing
    function returned an error value), then the parser is called with
    ARGP_KEY_ERROR, and no further calls are made. */

    /* This is not an option at all, but rather a command line argument. If a
    parser receiving this key returns success, the fact is recorded, and the
    ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the
    argument, a parser function decrements the NEXT field of the state it's
    passed, the option won't be considered processed; this is to allow you to
    actually modify the argument (perhaps into an option), and have it
    processed again. */
    #define ARGP_KEY_ARG 0
    /* There are remaining arguments not parsed by any parser, which may be found
    starting at (STATE->argv + STATE->next). If success is returned, but
    STATE->next left untouched, it's assumed that all arguments were consume,
    otherwise, the parser should adjust STATE->next to reflect any arguments
    consumed. */
    #define ARGP_KEY_ARGS 0x1000006
    /* There are no more command line arguments at all. */
    #define ARGP_KEY_END 0x1000001
    /* Because it's common to want to do some special processing if there aren't
    any non-option args, user parsers are called with this key if they didn't
    successfully process any non-option arguments. Called just before
    ARGP_KEY_END (where more general validity checks on previously parsed
    arguments can take place). */
    #define ARGP_KEY_NO_ARGS 0x1000002
    /* Passed in before any parsing is done. Afterwards, the values of each
    element of the CHILD_INPUT field, if any, in the state structure is
    copied to each child's state to be the initial value of the INPUT field. */
    #define ARGP_KEY_INIT 0x1000003
    /* Use after all other keys, including SUCCESS & END. */
    #define ARGP_KEY_FINI 0x1000007
    /* Passed in when parsing has successfully been completed (even if there are
    still arguments remaining). */
    #define ARGP_KEY_SUCCESS 0x1000004
    /* Passed in if an error occurs. */
    #define ARGP_KEY_ERROR 0x1000005

    /* An argp structure contains a set of options declarations, a function to
    deal with parsing one, do entation string, a possible vector of child
    argp's, and perhaps a function to filter help output. When actually
    parsing options, getopt is called with the union of all the argp
    structures chained together through their CHILD pointers, with conflicts
    being resolved in favor of the first occurrence in the chain. */
    struct argp
    {
    /* An array of argp_option structures, terminated by an entry with both
    NAME and KEY having a value of 0. */
    const struct argp_option *options;

    /* What to do with an option from this structure. KEY is the key
    associated with the option, and ARG is any associated argument (NULL if
    none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be
    returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then
    parsing is stopped immediately, and that value is returned from
    argp_parse(). For special (non-user-supplied) values of KEY, see the
    ARGP_KEY_ definitions below. */
    argp_parser_t parser;

    /* A string describing what other arguments are wanted by this program. It
    is only used by argp_usage to print the `Usage:' message. If it
    contains newlines, the strings separated by them are considered
    alternative usage patterns, and printed on separate lines (lines after
    the first are prefix by ` or: ' instead of `Usage:'). */
    const char *args_doc;

    /* If non-NULL, a string containing extra text to be printed before and
    after the options in a long help message (separated by a vertical tab
    `\v' character). */
    const char *doc;

    /* A vector of argp_children structures, terminated by a member with a 0
    argp field, pointing to child argps should be parsed with this one. Any
    conflicts are resolved in favor of this argp, or early argps in the
    CHILDREN list. This field is useful if you use libraries that supply
    their own argp structure, which you want to use in conjunction with your
    own. */
    const struct argp_child *children;

    /* If non-zero, this should be a function to filter the output of help
    messages. KEY is either a key from an option, in which case TEXT is
    that option's help text, or a special key from the ARGP_KEY_HELP_
    defines, below, describing which other help text TEXT is. The function
    should return either TEXT, if it should be used as-is, a replacement
    string, which should be malloced, and will be freed by argp, or NULL,
    meaning `print nothing'. The value for TEXT is *after* any translation
    has been done, so if any of the replacement text also needs translation,
    that should be done by the filter function. INPUT is either the input
    supplied to argp_parse, or NULL, if argp_help was called directly. */
    char *(*help_filter) (int __key, const char *__text, void *__input);

    /* If non-zero the strings used in the argp library are translated using
    the domain described by this string. Otherwise the currently installed
    default domain is used. */
    const char *argp_domain;
    };

    /* Possible KEY arguments to a help filter function. */
    #define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */
    #define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */
    #define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */
    #define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other do entation;
    TEXT is NULL for this key. */
    /* Explanatory note emitted when duplicate option arguments have been
    suppressed. */
    #define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005
    #define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */

    /* When an argp has a non-zero CHILDREN field, it should point to a vector of
    argp_child structures, each of which describes a subsidiary argp. */
    struct argp_child
    {
    /* The child parser. */
    const struct argp *argp;

    /* Flags for this child. */
    int flags;

    /* If non-zero, an optional header to be printed in help output before the
    child options. As a side-effect, a non-zero value forces the child
    options to be grouped together; to achieve this effect without actually
    printing a header string, use a value of "". */
    const char *header;

    /* Where to group the child options relative to the other (`consolidated')
    options in the parent argp; the values are the same as the GROUP field
    in argp_option structs, but all child-groupings follow parent options at
    a particular group level. If both this field and HEADER are zero, then
    they aren't grouped at all, but rather merged with the parent options
    (merging the child's grouping levels with the parents). */
    int group;
    };

    /* Parsing state. This is provided to parsing functions called by argp,
    which may examine and, as noted, modify fields. */
    struct argp_state
    {
    /* The top level ARGP being parsed. */
    const struct argp *root_argp;

    /* The argument vector being parsed. May be modified. */
    int argc;
    char **argv;

    /* The index in ARGV of the next arg that to be parsed. May be modified. */
    int next;

    /* The flags supplied to argp_parse. May be modified. */
    unsigned flags;

    /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the
    number of the current arg, starting at zero, and incremented after each
    such call returns. At all other times, this is the number of such
    arguments that have been processed. */
    unsigned arg_num;

    /* If non-zero, the index in ARGV of the first argument following a special
    `--' argument (which prevents anything following being interpreted as an
    option). Only set once argument parsing has proceeded past this point. */
    int quoted;

    /* An arbitrary pointer passed in from the user. */
    void *input;
    /* Values to pass to child parsers. This vector will be the same length as
    the number of children for the current parser. */
    void **child_inputs;

    /* For the parser's use. Initialized to 0. */
    void *hook;

    /* The name used when printing messages. This is initialized to ARGV[0],
    or PROGRAM_INVOCATION_NAME if that is unavailable. */
    char *name;

    /* Streams used when argp prints something. */
    FILE *err_stream; /* For errors; initialized to stderr. */
    FILE *out_stream; /* For information; initialized to stdout. */

    void *pstate; /* Private, for use by argp. */
    };

    /* Flags for argp_parse (note that the defaults are those that are
    convenient for program command line parsing): */

    /* Don't ignore the first element of ARGV. Normally (and always unless
    ARGP_NO_ERRS is set) the first element of the argument vector is
    skipped for option parsing purposes, as it corresponds to the program name
    in a command line. */
    #define ARGP_PARSE_ARGV0 0x01

    /* Don't print error messages for unknown options to stderr; unless this flag
    is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program
    name in the error messages. This flag implies ARGP_NO_EXIT (on the
    assumption that silent exiting upon errors is bad behaviour). */
    #define ARGP_NO_ERRS 0x02

    /* Don't parse any non-option args. Normally non-option args are parsed by
    calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg
    as the value. Since it's impossible to know which parse function wants to
    handle it, each one is called in turn, until one returns 0 or an error
    other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the
    argp_parse returns prematurely (but with a return value of 0). If all
    args have been parsed without error, all parsing functions are called one
    last time with a key of ARGP_KEY_END. This flag needn't normally be set,
    as the normal behavior is to stop parsing as soon as some argument can't
    be handled. */
    #define ARGP_NO_ARGS 0x04

    /* Parse options and arguments in the same order they occur on the command
    line -- normally they're rearranged so that all options come first. */
    #define ARGP_IN_ORDER 0x08

    /* Don't provide the standard long option --help, which causes usage and
    option help information to be output to stdout, and exit (0) called. */
    #define ARGP_NO_HELP 0x10

    /* Don't exit on errors (they may still result in error messages). */
    #define ARGP_NO_EXIT 0x20

    /* Use the gnu getopt `long-only' rules for parsing arguments. */
    #define ARGP_LONG_ONLY 0x40

    /* Turns off any message-printing/exiting options. */
    #define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP)

    /* Parse the options strings in ARGC & ARGV according to the options in ARGP.
    FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the
    index in ARGV of the first unparsed option is returned in it. If an
    unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser
    routine returned a non-zero value, it is returned; otherwise 0 is
    returned. This function may also call exit unless the ARGP_NO_HELP flag
    is set. INPUT is a pointer to a value to be passed in to the parser. */
    extern error_t argp_parse (const struct argp *__restrict __argp,
    int __argc, char **__restrict __argv,
    unsigned __flags, int *__restrict __arg_index,
    void *__restrict __input);
    extern error_t __argp_parse (const struct argp *__restrict __argp,
    int __argc, char **__restrict __argv,
    unsigned __flags, int *__restrict __arg_index,
    void *__restrict __input);

    /* Global variables. */

    /* If defined or set by the user program to a non-zero value, then a default
    option --version is added (unless the ARGP_NO_HELP flag is used), which
    will print this string followed by a newline and exit (unless the
    ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
    extern const char *argp_program_version;

    /* If defined or set by the user program to a non-zero value, then a default
    option --version is added (unless the ARGP_NO_HELP flag is used), which
    calls this function with a stream to print the version to and a pointer to
    the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
    used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
    extern void (*argp_program_version_hook) (FILE *__restrict __stream,
    struct argp_state *__restrict
    __state);

    /* If defined or set by the user program, it should point to string that is
    the bug-reporting address for the program. It will be printed by
    argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various
    standard help messages), embedded in a sentence that says something like
    `Report bugs to ADDR.'. */
    extern const char *argp_program_bug_address;

    /* The exit status that argp will use when exiting due to a parsing error.
    If not defined or set by the user program, this defaults to EX_USAGE from
    <sysexits.h>. */
    extern error_t argp_err_exit_status;

    /* Flags for argp_help. */
    #define ARGP_HELP_USAGE 0x01 /* a Usage: message. */
    #define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */
    #define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */
    #define ARGP_HELP_LONG 0x08 /* a long help message. */
    #define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */
    #define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */
    #define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)

  18. #18
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    #define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */
    #define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to
    reflect ARGP_LONG_ONLY mode. */

    /* These ARGP_HELP flags are only understood by argp_state_help. */
    #define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */
    #define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */

    /* The standard thing to do after a program command line parsing error, if an
    error message has already been printed. */
    #define ARGP_HELP_STD_ERR \
    (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
    /* The standard thing to do after a program command line parsing error, if no
    more specific error message has been printed. */
    #define ARGP_HELP_STD_USAGE \
    (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
    /* The standard thing to do in response to a --help option. */
    #define ARGP_HELP_STD_HELP \
    (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \
    | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR)

    /* Output a usage message for ARGP to STREAM. FLAGS are from the set
    ARGP_HELP_*. */
    extern void argp_help (const struct argp *__restrict __argp,
    FILE *__restrict __stream,
    unsigned __flags, char *__restrict __name);
    extern void __argp_help (const struct argp *__restrict __argp,
    FILE *__restrict __stream, unsigned __flags,
    char *__name);

    /* The following routines are intended to be called from within an argp
    parsing routine (thus taking an argp_state structure as the first
    argument). They may or may not print an error message and exit, depending
    on the flags in STATE -- in any case, the caller should be prepared for
    them *not* to exit, and should return an appropiate error after calling
    them. [argp_usage & argp_error should probably be called argp_state_...,
    but they're used often enough that they should be short] */

    /* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are
    from the set ARGP_HELP_*. */
    extern void argp_state_help (const struct argp_state *__restrict __state,
    FILE *__restrict __stream,
    unsigned int __flags);
    extern void __argp_state_help (const struct argp_state *__restrict __state,
    FILE *__restrict __stream,
    unsigned int __flags);

    /* Possibly output the standard usage message for ARGP to stderr and exit. */
    extern void argp_usage (const struct argp_state *__state);
    extern void __argp_usage (const struct argp_state *__state);

    /* If appropriate, print the printf string FMT and following args, preceded
    by the program name and `:', to stderr, and followed by a `Try ... --help'
    message, then exit (1). */
    extern void argp_error (const struct argp_state *__restrict __state,
    const char *__restrict __fmt, ...)
    __attribute__ ((__format__ (__printf__, 2, 3)));
    extern void __argp_error (const struct argp_state *__restrict __state,
    const char *__restrict __fmt, ...)
    __attribute__ ((__format__ (__printf__, 2, 3)));

    /* Similar to the standard gnu error-reporting function error(), but will
    respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
    to STATE->err_stream. This is useful for argument parsing code that is
    shared between program startup (when exiting is desired) and runtime
    option parsing (when typically an error code is returned instead). The
    difference between this function and argp_error is that the latter is for
    *parsing errors*, and the former is for other problems that occur during
    parsing but don't reflect a (syntactic) problem with the input. */
    extern void argp_failure (const struct argp_state *__restrict __state,
    int __status, int __errnum,
    const char *__restrict __fmt, ...)
    __attribute__ ((__format__ (__printf__, 4, 5)));
    extern void __argp_failure (const struct argp_state *__restrict __state,
    int __status, int __errnum,
    const char *__restrict __fmt, ...)
    __attribute__ ((__format__ (__printf__, 4, 5)));

    /* Returns true if the option OPT is a valid short option. */
    extern int _option_is_short (const struct argp_option *__opt) __THROW;
    extern int __option_is_short (const struct argp_option *__opt) __THROW;

    /* Returns true if the option OPT is in fact the last (unused) entry in an
    options array. */
    extern int _option_is_end (const struct argp_option *__opt) __THROW;
    extern int __option_is_end (const struct argp_option *__opt) __THROW;

    /* Return the input field for ARGP in the parser corresponding to STATE; used
    by the help routines. */
    extern void *_argp_input (const struct argp *__restrict __argp,
    const struct argp_state *__restrict __state)
    __THROW;
    extern void *__argp_input (const struct argp *__restrict __argp,
    const struct argp_state *__restrict __state)
    __THROW;

    #ifdef __USE_EXTERN_INLINES

    # if !_LIBC
    # define __argp_usage argp_usage
    # define __argp_state_help argp_state_help
    # define __option_is_short _option_is_short
    # define __option_is_end _option_is_end
    # endif

    # ifndef ARGP_EI
    # define ARGP_EI __extern_inline
    # endif

    ARGP_EI void
    __argp_usage (const struct argp_state *__state)
    {
    __argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
    }

    ARGP_EI int
    __NTH (__option_is_short (const struct argp_option *__opt))
    {
    if (__opt->flags & OPTION_DOC)
    return 0;
    else
    {
    int __key = __opt->key;
    return __key > 0 && __key <= UCHAR_MAX && isprint (__key);
    }
    }

    ARGP_EI int
    __NTH (__option_is_end (const struct argp_option *__opt))
    {
    return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
    }

    # if !_LIBC
    # undef __argp_usage
    # undef __argp_state_help
    # undef __option_is_short
    # undef __option_is_end
    # endif
    #endif /* Use extern inlines. */

    #ifdef __cplusplus
    }
    #endif

    #endif /* argp.h */

  19. #19
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    /* Default definition for ARGP_PROGRAM_BUG_ADDRESS.
    Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <[email protected]>.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>. */

    /* If set by the user program, it should point to string that is the
    bug-reporting address for the program. It will be printed by argp_help if
    the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help
    messages), embedded in a sentence that says something like `Report bugs to
    ADDR.'. */
    const char *argp_program_bug_address;

  20. #20
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    /* Default definition for ARGP_ERR_EXIT_STATUS
    Copyright (C) 1997 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <[email protected]>.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>. */

    #ifdef HAVE_CONFIG_H
    # include <config.h>
    #endif

    #include <sysexits.h>

    #include "argp.h"

    /* The exit status that argp will use when exiting due to a parsing error.
    If not defined or set by the user program, this defaults to EX_USAGE from
    <sysexits.h>. */
    error_t argp_err_exit_status = EX_USAGE;

  21. #21
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    /* Word-wrapping and line-truncating streams
    Copyright (C) 1997-1999,2001-2003,2005,2011 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <[email protected]>.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>. */

    /* This package emulates glibc `line_wrap_stream' semantics for systems that
    don't have that. */

    #ifdef HAVE_CONFIG_H
    # include <config.h>
    #endif

    #include <stdlib.h>
    #include <string.h>
    #include <errno.h>
    #include <stdarg.h>
    #include <ctype.h>

    #include "argp-fmtstream.h"
    #include "argp-namefrob.h"

    #ifndef ARGP_FMTSTREAM_USE_LINEWRAP

    #ifndef isblank
    #define isblank(ch) ((ch)==' ' || (ch)=='\t')
    #endif

    #ifdef _LIBC
    # include <wchar.h>
    # include <libio/libioP.h>
    # define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
    #endif

    #define INIT_BUF_SIZE 200
    #define PRINTF_SIZE_GUESS 150

    /* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
    written on it with LMARGIN spaces and limits them to RMARGIN columns
    total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
    replacing the whitespace before them with a newline and WMARGIN spaces.
    Otherwise, chars beyond RMARGIN are simply dropped until a newline.
    Returns NULL if there was an error. */
    argp_fmtstream_t
    __argp_make_fmtstream (FILE *stream,
    size_t lmargin, size_t rmargin, ssize_t wmargin)
    {
    argp_fmtstream_t fs;

    fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
    if (fs != NULL)
    {
    fs->stream = stream;

    fs->lmargin = lmargin;
    fs->rmargin = rmargin;
    fs->wmargin = wmargin;
    fs->point_col = 0;
    fs->point_offs = 0;

    fs->buf = (char *) malloc (INIT_BUF_SIZE);
    if (! fs->buf)
    {
    free (fs);
    fs = 0;
    }
    else
    {
    fs->p = fs->buf;
    fs->end = fs->buf + INIT_BUF_SIZE;
    }
    }

    return fs;
    }
    #if 0
    /* Not exported. */
    #ifdef weak_alias
    weak_alias (__argp_make_fmtstream, argp_make_fmtstream)
    #endif
    #endif

    /* Flush FS to its stream, and free it (but don't close the stream). */
    void
    __argp_fmtstream_free (argp_fmtstream_t fs)
    {
    __argp_fmtstream_update (fs);
    if (fs->p > fs->buf)
    {
    __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
    }
    free (fs->buf);
    free (fs);
    }
    #if 0
    /* Not exported. */
    #ifdef weak_alias
    weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
    #endif
    #endif

    /* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
    end of its buffer. This code is mostly from glibc stdio/linewrap.c. */
    void
    __argp_fmtstream_update (argp_fmtstream_t fs)
    {
    char *buf, *nl;
    size_t len;

    /* Scan the buffer for newlines. */
    buf = fs->buf + fs->point_offs;
    while (buf < fs->p)
    {
    size_t r;

    if (fs->point_col == 0 && fs->lmargin != 0)
    {
    /* We are starting a new line. Print spaces to the left margin. */
    const size_t pad = fs->lmargin;
    if (fs->p + pad < fs->end)
    {
    /* We can fit in them in the buffer by moving the
    buffer text up and filling in the beginning. */
    memmove (buf + pad, buf, fs->p - buf);
    fs->p += pad; /* Compensate for bigger buffer. */
    memset (buf, ' ', pad); /* Fill in the spaces. */
    buf += pad; /* Don't bother searching them. */
    }
    else
    {
    /* No buffer space for spaces. Must flush. */
    size_t i;
    for (i = 0; i < pad; i++)
    {
    if (_IO_fwide (fs->stream, 0) > 0)
    putwc_unlocked (L' ', fs->stream);
    else
    putc_unlocked (' ', fs->stream);
    }
    }
    fs->point_col = pad;
    }

    len = fs->p - buf;
    nl = memchr (buf, '\n', len);

    if (fs->point_col < 0)
    fs->point_col = 0;

    if (!nl)
    {
    /* The buffer ends in a partial line. */

    if (fs->point_col + len < fs->rmargin)
    {
    /* The remaining buffer text is a partial line and fits
    within the maximum line width. Advance point for the
    characters to be written and stop scanning. */
    fs->point_col += len;
    break;
    }
    else
    /* Set the end-of-line pointer for the code below to
    the end of the buffer. */
    nl = fs->p;
    }
    else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
    {
    /* The buffer contains a full line that fits within the maximum
    line width. Reset point and scan the next line. */
    fs->point_col = 0;
    buf = nl + 1;
    continue;
    }

    /* This line is too long. */
    r = fs->rmargin - 1;

    if (fs->wmargin < 0)
    {
    /* Truncate the line by overwriting the excess with the
    newline and anything after it in the buffer. */
    if (nl < fs->p)
    {
    memmove (buf + (r - fs->point_col), nl, fs->p - nl);
    fs->p -= buf + (r - fs->point_col) - nl;
    /* Reset point for the next line and start scanning it. */
    fs->point_col = 0;
    buf += r + 1; /* Skip full line plus \n. */
    }
    else
    {
    /* The buffer ends with a partial line that is beyond the
    maximum line width. Advance point for the characters
    written, and discard those past the max from the buffer. */
    fs->point_col += len;
    fs->p -= fs->point_col - r;
    break;
    }
    }
    else
    {
    /* Do word wrap. Go to the column just past the maximum line
    width and scan back for the beginning of the word there.
    Then insert a line break. */

    char *p, *nextline;
    int i;

    p = buf + (r + 1 - fs->point_col);
    while (p >= buf && !isblank (*p))
    --p;
    nextline = p + 1; /* This will begin the next line. */

    if (nextline > buf)
    {
    /* Swallow separating blanks. */
    if (p >= buf)
    do
    --p;
    while (p >= buf && isblank (*p));
    nl = p + 1; /* The newline will replace the first blank. */
    }
    else
    {
    /* A single word that is greater than the maximum line width.
    Oh well. Put it on an overlong line by itself. */
    p = buf + (r + 1 - fs->point_col);
    /* Find the end of the long word. */
    do
    ++p;
    while (p < nl && !isblank (*p));
    if (p == nl)
    {
    /* It already ends a line. No fussing required. */
    fs->point_col = 0;
    buf = nl + 1;
    continue;
    }
    /* We will move the newline to replace the first blank. */
    nl = p;
    /* Swallow separating blanks. */
    do
    ++p;
    while (isblank (*p));
    /* The next line will start here. */
    nextline = p;
    }

    /* Note: There are a bunch of tests below for
    NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall
    at the end of the buffer, and NEXTLINE is in fact empty (and so
    we need not be careful to maintain its contents). */

    if ((nextline == buf + len + 1
    ? fs->end - nl < fs->wmargin + 1
    : nextline - (nl + 1) < fs->wmargin)
    && fs->p > nextline)
    {
    /* The margin needs more blanks than we removed. */
    if (fs->end - fs->p > fs->wmargin + 1)
    /* Make some space for them. */
    {
    size_t mv = fs->p - nextline;
    memmove (nl + 1 + fs->wmargin, nextline, mv);
    nextline = nl + 1 + fs->wmargin;
    len = nextline + mv - buf;
    *nl++ = '\n';
    }
    else
    /* Output the first line so we can use the space. */
    {
    #ifdef _LIBC
    __fxprintf (fs->stream, "%.*s\n",
    (int) (nl - fs->buf), fs->buf);
    #else
    if (nl > fs->buf)
    fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream);
    putc_unlocked ('\n', fs->stream);
    #endif

    len += buf - fs->buf;
    nl = buf = fs->buf;
    }
    }
    else
    /* We can fit the newline and blanks in before
    the next word. */
    *nl++ = '\n';

    if (nextline - nl >= fs->wmargin
    || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin))
    /* Add blanks up to the wrap margin column. */
    for (i = 0; i < fs->wmargin; ++i)
    *nl++ = ' ';
    else
    for (i = 0; i < fs->wmargin; ++i)
    if (_IO_fwide (fs->stream, 0) > 0)
    putwc_unlocked (L' ', fs->stream);
    else
    putc_unlocked (' ', fs->stream);

    /* Copy the tail of the original buffer into the current buffer
    position. */
    if (nl < nextline)
    memmove (nl, nextline, buf + len - nextline);
    len -= nextline - buf;

    /* Continue the scan on the remaining lines in the buffer. */
    buf = nl;

    /* Restore bufp to include all the remaining text. */
    fs->p = nl + len;

    /* Reset the counter of what has been output this line. If wmargin
    is 0, we want to avoid the lmargin getting added, so we set
    point_col to a magic value of -1 in that case. */
    fs->point_col = fs->wmargin ? fs->wmargin : -1;
    }
    }

    /* Remember that we've scanned as far as the end of the buffer. */
    fs->point_offs = fs->p - fs->buf;
    }

    /* Ensure that FS has space for AMOUNT more bytes in its buffer, either by
    growing the buffer, or by flushing it. True is returned iff we succeed. */
    int
    __argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
    {
    if ((size_t) (fs->end - fs->p) < amount)
    {
    ssize_t wrote;

    /* Flush FS's buffer. */
    __argp_fmtstream_update (fs);

    #ifdef _LIBC
    __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
    wrote = fs->p - fs->buf;
    #else
    wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
    #endif
    if (wrote == fs->p - fs->buf)
    {
    fs->p = fs->buf;
    fs->point_offs = 0;
    }
    else
    {
    fs->p -= wrote;
    fs->point_offs -= wrote;
    memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf);
    return 0;
    }

    if ((size_t) (fs->end - fs->buf) < amount)
    /* Gotta grow the buffer. */
    {
    size_t old_size = fs->end - fs->buf;
    size_t new_size = old_size + amount;
    char *new_buf;

    if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size)))
    {
    __set_errno (ENOMEM);
    return 0;
    }

    fs->buf = new_buf;
    fs->end = new_buf + new_size;
    fs->p = fs->buf;
    }
    }

    return 1;
    }

    ssize_t
    __argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
    {
    int out;
    size_t avail;
    size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */

    do
    {
    va_list args;

    if (! __argp_fmtstream_ensure (fs, size_guess))
    return -1;

    va_start (args, fmt);
    avail = fs->end - fs->p;
    out = __vsnprintf (fs->p, avail, fmt, args);
    va_end (args);
    if ((size_t) out >= avail)
    size_guess = out + 1;
    }
    while ((size_t) out >= avail);

    fs->p += out;

    return out;
    }
    #if 0
    /* Not exported. */
    #ifdef weak_alias
    weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf)
    #endif
    #endif

    #endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */

  22. #22
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    /* Word-wrapping and line-truncating streams.
    Copyright (C) 1997, 2011, 2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <[email protected]>.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>. */

    /* This package emulates glibc `line_wrap_stream' semantics for systems that
    don't have that. If the system does have it, it is just a wrapper for
    that. This header file is only used internally while compiling argp, and
    shouldn't be installed. */

    #ifndef _ARGP_FMTSTREAM_H
    #define _ARGP_FMTSTREAM_H

    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>

    #ifndef __attribute__
    /* This feature is available in gcc versions 2.5 and later. */
    # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
    # define __attribute__(Spec) /* empty */
    # endif
    /* The __-protected variants of `format' and `printf' attributes
    are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
    # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || __STRICT_ANSI__
    # define __format__ format
    # define __printf__ printf
    # endif
    #endif

    #if defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H)
    /* line_wrap_stream is available, so use that. */
    #define ARGP_FMTSTREAM_USE_LINEWRAP
    #endif

    #ifdef ARGP_FMTSTREAM_USE_LINEWRAP
    /* Just be a simple wrapper for line_wrap_stream; the semantics are
    *slightly* different, as line_wrap_stream doesn't actually make a new
    object, it just modifies the given stream (reversibly) to do
    line-wrapping. Since we control who uses this code, it doesn't matter. */

    #include <linewrap.h>

    typedef FILE *argp_fmtstream_t;

    #define argp_make_fmtstream line_wrap_stream
    #define __argp_make_fmtstream line_wrap_stream
    #define argp_fmtstream_free line_unwrap_stream
    #define __argp_fmtstream_free line_unwrap_stream

    #define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
    #define argp_fmtstream_putc(fs,ch) putc(ch,fs)
    #define __argp_fmtstream_puts(fs,str) fputs(str,fs)
    #define argp_fmtstream_puts(fs,str) fputs(str,fs)
    #define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
    #define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
    #define __argp_fmtstream_printf fprintf
    #define argp_fmtstream_printf fprintf

    #define __argp_fmtstream_lmargin line_wrap_lmargin
    #define argp_fmtstream_lmargin line_wrap_lmargin
    #define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
    #define argp_fmtstream_set_lmargin line_wrap_set_lmargin
    #define __argp_fmtstream_rmargin line_wrap_rmargin
    #define argp_fmtstream_rmargin line_wrap_rmargin
    #define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
    #define argp_fmtstream_set_rmargin line_wrap_set_rmargin
    #define __argp_fmtstream_wmargin line_wrap_wmargin
    #define argp_fmtstream_wmargin line_wrap_wmargin
    #define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
    #define argp_fmtstream_set_wmargin line_wrap_set_wmargin
    #define __argp_fmtstream_point line_wrap_point
    #define argp_fmtstream_point line_wrap_point

    #else /* !ARGP_FMTSTREAM_USE_LINEWRAP */
    /* Guess we have to define our own version. */


    struct argp_fmtstream
    {
    FILE *stream; /* The stream we're outputting to. */

    size_t lmargin, rmargin; /* Left and right margins. */
    ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */

    /* Point in buffer to which we've processed for wrapping, but not output. */
    size_t point_offs;
    /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */
    ssize_t point_col;

    char *buf; /* Output buffer. */
    char *p; /* Current end of text in BUF. */
    char *end; /* Absolute end of BUF. */
    };

    typedef struct argp_fmtstream *argp_fmtstream_t;

    /* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
    written on it with LMARGIN spaces and limits them to RMARGIN columns
    total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
    replacing the whitespace before them with a newline and WMARGIN spaces.
    Otherwise, chars beyond RMARGIN are simply dropped until a newline.
    Returns NULL if there was an error. */
    extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
    size_t __lmargin,
    size_t __rmargin,
    ssize_t __wmargin);
    extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream,
    size_t __lmargin,
    size_t __rmargin,
    ssize_t __wmargin);

    /* Flush __FS to its stream, and free it (but don't close the stream). */
    extern void __argp_fmtstream_free (argp_fmtstream_t __fs);
    extern void argp_fmtstream_free (argp_fmtstream_t __fs);

    extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
    const char *__fmt, ...)
    __attribute__ ((__format__ (printf, 2, 3)));
    extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
    const char *__fmt, ...)
    __attribute__ ((__format__ (printf, 2, 3)));

    extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
    extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);

    extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
    extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);

    extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
    const char *__str, size_t __len);
    extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
    const char *__str, size_t __len);

    /* Access macros for various bits of state. */
    #define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
    #define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
    #define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
    #define __argp_fmtstream_lmargin argp_fmtstream_lmargin
    #define __argp_fmtstream_rmargin argp_fmtstream_rmargin
    #define __argp_fmtstream_wmargin argp_fmtstream_wmargin

    /* Set __FS's left margin to LMARGIN and return the old value. */
    extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
    size_t __lmargin);
    extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
    size_t __lmargin);

    /* Set __FS's right margin to __RMARGIN and return the old value. */
    extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
    size_t __rmargin);
    extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
    size_t __rmargin);

    /* Set __FS's wrap margin to __WMARGIN and return the old value. */
    extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
    size_t __wmargin);
    extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
    size_t __wmargin);

    /* Return the column number of the current output point in __FS. */
    extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
    extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);

    /* Internal routines. */
    extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
    extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
    extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
    extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);

    #ifdef __OPTIMIZE__
    /* Inline versions of above routines. */

    #if !_LIBC
    #define __argp_fmtstream_putc argp_fmtstream_putc
    #define __argp_fmtstream_puts argp_fmtstream_puts
    #define __argp_fmtstream_write argp_fmtstream_write
    #define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
    #define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
    #define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
    #define __argp_fmtstream_point argp_fmtstream_point
    #define __argp_fmtstream_update _argp_fmtstream_update
    #define __argp_fmtstream_ensure _argp_fmtstream_ensure
    #endif

    #ifndef ARGP_FS_EI
    #define ARGP_FS_EI extern inline
    #endif

    ARGP_FS_EI size_t
    __argp_fmtstream_write (argp_fmtstream_t __fs, const char *__str, size_t __len)
    {
    if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
    {
    memcpy (__fs->p, __str, __len);
    __fs->p += __len;
    return __len;
    }
    else
    return 0;
    }

    ARGP_FS_EI int
    __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str)
    {
    size_t __len = strlen (__str);
    if (__len)
    {
    size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
    return __wrote == __len ? 0 : -1;
    }
    else
    return 0;
    }

    ARGP_FS_EI int
    __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
    {
    if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
    return *__fs->p++ = __ch;
    else
    return EOF;
    }

    /* Set __FS's left margin to __LMARGIN and return the old value. */
    ARGP_FS_EI size_t
    __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
    {
    size_t __old;
    if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
    __argp_fmtstream_update (__fs);
    __old = __fs->lmargin;
    __fs->lmargin = __lmargin;
    return __old;
    }

    /* Set __FS's right margin to __RMARGIN and return the old value. */
    ARGP_FS_EI size_t
    __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
    {
    size_t __old;
    if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
    __argp_fmtstream_update (__fs);
    __old = __fs->rmargin;
    __fs->rmargin = __rmargin;
    return __old;
    }

    /* Set FS's wrap margin to __WMARGIN and return the old value. */
    ARGP_FS_EI size_t
    __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
    {
    size_t __old;
    if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
    __argp_fmtstream_update (__fs);
    __old = __fs->wmargin;
    __fs->wmargin = __wmargin;
    return __old;
    }

    /* Return the column number of the current output point in __FS. */
    ARGP_FS_EI size_t
    __argp_fmtstream_point (argp_fmtstream_t __fs)
    {
    if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
    __argp_fmtstream_update (__fs);
    return __fs->point_col >= 0 ? __fs->point_col : 0;
    }

    #if !_LIBC
    #undef __argp_fmtstream_putc
    #undef __argp_fmtstream_puts
    #undef __argp_fmtstream_write
    #undef __argp_fmtstream_set_lmargin
    #undef __argp_fmtstream_set_rmargin
    #undef __argp_fmtstream_set_wmargin
    #undef __argp_fmtstream_point
    #undef __argp_fmtstream_update
    #undef __argp_fmtstream_ensure
    #endif

    #endif /* __OPTIMIZE__ */

    #endif /* ARGP_FMTSTREAM_USE_LINEWRAP */

    #endif /* argp-fmtstream.h */

  23. #23
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    /* Real definitions for extern inline functions in argp-fmtstream.h
    Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <[email protected]>.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>. */

    #ifdef HAVE_CONFIG_H
    # include <config.h>
    #endif

    #define ARGP_FS_EI
    #undef __OPTIMIZE__
    #define __OPTIMIZE__ 1
    #include "argp-fmtstream.h"

    #if 0
    /* Not exported. */
    /* Add weak aliases. */
    #if _LIBC - 0 && !defined (ARGP_FMTSTREAM_USE_LINEWRAP) && defined (weak_alias)

    weak_alias (__argp_fmtstream_putc, argp_fmtstream_putc)
    weak_alias (__argp_fmtstream_puts, argp_fmtstream_puts)
    weak_alias (__argp_fmtstream_write, argp_fmtstream_write)
    weak_alias (__argp_fmtstream_set_lmargin, argp_fmtstream_set_lmargin)
    weak_alias (__argp_fmtstream_set_rmargin, argp_fmtstream_set_rmargin)
    weak_alias (__argp_fmtstream_set_wmargin, argp_fmtstream_set_wmargin)
    weak_alias (__argp_fmtstream_point, argp_fmtstream_point)

    #endif
    #endif

  24. #24
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    /* Hierarchial argument parsing help output
    Copyright (C) 1995-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <[email protected]>.

    The GNU C Library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>. */

    #ifndef _GNU_SOURCE
    # define _GNU_SOURCE 1
    #endif

    #ifdef HAVE_CONFIG_H
    #include <config.h>
    #endif

    /* AIX requires this to be the first thing in the file. */
    #ifndef __GNUC__
    # if HAVE_ALLOCA_H || defined _LIBC
    # include <alloca.h>
    # else
    # ifdef _AIX
    #pragma alloca
    # else
    # ifndef alloca /* predefined by HP cc +Olibcalls */
    char *alloca ();
    # endif
    # endif
    # endif
    #endif

    #include <stdbool.h>
    #include <stddef.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    #include <stdarg.h>
    #include <ctype.h>
    #include <limits.h>
    #ifdef _LIBC
    # include <../libio/libioP.h>
    # include <wchar.h>
    #endif

    #ifndef _
    /* This is for other GNU distributions with internationalized messages. */
    # if defined HAVE_LIBINTL_H || defined _LIBC
    # include <libintl.h>
    # ifdef _LIBC
    # undef dgettext
    # define dgettext(domain, msgid) \
    __dcgettext (domain, msgid, LC_MESSAGES)
    # endif
    # else
    # define dgettext(domain, msgid) (msgid)
    # endif
    #endif

    #ifndef _LIBC
    # if HAVE_STRERROR_R
    # if !HAVE_DECL_STRERROR_R
    char *strerror_r (int errnum, char *buf, size_t buflen);
    # endif
    # else
    # if !HAVE_DECL_STRERROR
    char *strerror (int errnum);
    # endif
    # endif
    #endif

    #include "argp.h"
    #include "argp-fmtstream.h"
    #include "argp-namefrob.h"

    #ifndef SIZE_MAX
    # define SIZE_MAX ((size_t) -1)
    #endif

    /* User-selectable (using an environment variable) formatting parameters.

    These may be specified in an environment variable called `ARGP_HELP_FMT',
    with a contents like: VAR1=VAL1,VAR2=VAL2,BOOLVAR2,no-BOOLVAR2
    Where VALn must be a positive integer. The list of variables is in the
    UPARAM_NAMES vector, below. */

    /* Default parameters. */
    #define DUP_ARGS 0 /* True if option argument can be duplicated. */
    #define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */
    #define SHORT_OPT_COL 2 /* column in which short options start */
    #define LONG_OPT_COL 6 /* column in which long options start */
    #define DOC_OPT_COL 2 /* column in which doc options start */
    #define OPT_DOC_COL 29 /* column in which option text starts */
    #define HEADER_COL 1 /* column in which group headers are printed */
    #define USAGE_INDENT 12 /* indentation of wrapped usage lines */
    #define RMARGIN 79 /* right margin used for wrapping */

    /* User-selectable (using an environment variable) formatting parameters.
    They must all be of type `int' for the parsing code to work. */
    struct uparams
    {
    /* If true, arguments for an option are shown with both short and long
    options, even when a given option has both, e.g. `-x ARG, --longx=ARG'.
    If false, then if an option has both, the argument is only shown with
    the long one, e.g., `-x, --longx=ARG', and a message indicating that
    this really means both is printed below the options. */
    int dup_args;

    /* This is true if when DUP_ARGS is false, and some duplicate arguments have
    been suppressed, an explanatory message should be printed. */
    int dup_args_note;

    /* Various output columns. */
    int short_opt_col;
    int long_opt_col;
    int doc_opt_col;
    int opt_doc_col;
    int header_col;
    int usage_indent;
    int rmargin;
    };

    /* This is a global variable, as user options are only ever read once. */
    static struct uparams uparams = {
    DUP_ARGS, DUP_ARGS_NOTE,
    SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL,
    USAGE_INDENT, RMARGIN
    };

    /* A particular uparam, and what the user name is. */
    struct uparam_name
    {
    const char name[14]; /* User name. */
    bool is_bool; /* Whether it's `boolean'. */
    uint8_t uparams_offs; /* Location of the (int) field in UPARAMS. */
    };

    /* The name-field mappings we know about. */
    static const struct uparam_name uparam_names[] =
    {
    { "dup-args", true, offsetof (struct uparams, dup_args) },
    { "dup-args-note", true, offsetof (struct uparams, dup_args_note) },
    { "short-opt-col", false, offsetof (struct uparams, short_opt_col) },
    { "long-opt-col", false, offsetof (struct uparams, long_opt_col) },
    { "doc-opt-col", false, offsetof (struct uparams, doc_opt_col) },
    { "opt-doc-col", false, offsetof (struct uparams, opt_doc_col) },
    { "header-col", false, offsetof (struct uparams, header_col) },
    { "usage-indent", false, offsetof (struct uparams, usage_indent) },
    { "rmargin", false, offsetof (struct uparams, rmargin) }
    };
    #define nuparam_names (sizeof (uparam_names) / sizeof (uparam_names[0]))

    /* Read user options from the environment, and fill in UPARAMS appropiately. */
    static void
    fill_in_uparams (const struct argp_state *state)
    {
    const char *var = getenv ("ARGP_HELP_FMT");

    #define SKIPWS(p) do { while (isspace (*p)) p++; } while (0);

    if (var)
    /* Parse var. */
    while (*var)
    {
    SKIPWS (var);

    if (isalpha (*var))
    {
    size_t var_len;
    const struct uparam_name *un;
    int unspec = 0, val = 0;
    const char *arg = var;

    while (isalnum (*arg) || *arg == '-' || *arg == '_')
    arg++;
    var_len = arg - var;

    SKIPWS (arg);

    if (*arg == '\0' || *arg == ',')
    unspec = 1;
    else if (*arg == '=')
    {
    arg++;
    SKIPWS (arg);
    }

    if (unspec)
    {
    if (var[0] == 'n' && var[1] == 'o' && var[2] == '-')
    {
    val = 0;
    var += 3;
    var_len -= 3;
    }
    else
    val = 1;
    }
    else if (isdigit (*arg))
    {
    val = atoi (arg);
    while (isdigit (*arg))
    arg++;
    SKIPWS (arg);
    }

    un = uparam_names;
    size_t u;
    for (u = 0; u < nuparam_names; ++un, ++u)
    if (strlen (un->name) == var_len
    && strncmp (var, un->name, var_len) == 0)
    {
    if (unspec && !un->is_bool)
    __argp_failure (state, 0, 0,
    dgettext (state == NULL ? NULL
    : state->root_argp->argp_domain,
    "\
    %.*s: ARGP_HELP_FMT parameter requires a value"),
    (int) var_len, var);
    else
    *(int *)((char *)&uparams + un->uparams_offs) = val;
    break;
    }
    if (u == nuparam_names)
    __argp_failure (state, 0, 0,
    dgettext (state == NULL ? NULL
    : state->root_argp->argp_domain, "\
    %.*s: Unknown ARGP_HELP_FMT parameter"),
    (int) var_len, var);

    var = arg;
    if (*var == ',')
    var++;
    }
    else if (*var)
    {
    __argp_failure (state, 0, 0,
    dgettext (state == NULL ? NULL
    : state->root_argp->argp_domain,
    "Garbage in ARGP_HELP_FMT: %s"), var);
    break;
    }
    }
    }

    /* Returns true if OPT hasn't been marked invisible. Visibility only affects
    whether OPT is displayed or used in sorting, not option shadowing. */
    #define ovisible(opt) (! ((opt)->flags & OPTION_HIDDEN))

    /* Returns true if OPT is an alias for an earlier option. */
    #define oalias(opt) ((opt)->flags & OPTION_ALIAS)

    /* Returns true if OPT is an do entation-only entry. */
    #define odoc(opt) ((opt)->flags & OPTION_DOC)

    /* Returns true if OPT is the end-of-list marker for a list of options. */
    #define oend(opt) __option_is_end (opt)

    /* Returns true if OPT has a short option. */
    #define oshort(opt) __option_is_short (opt)

    /*
    The help format for a particular option is like:

    -xARG, -yARG, --long1=ARG, --long2=ARG Do entation...

    Where ARG will be omitted if there's no argument, for this option, or
    will be surrounded by "[" and "]" appropiately if the argument is
    optional. The do entation string is word-wrapped appropiately, and if
    the list of options is long enough, it will be started on a separate line.
    If there are no short options for a given option, the first long option is
    indented slighly in a way that's supposed to make most long options appear
    to be in a separate column.

    For example, the following output (from ps):

    -p PID, --pid=PID List the process PID
    --pgrp=PGRP List processes in the process group PGRP
    -P, -x, --no-parent Include processes without parents
    -Q, --all-fields Don't elide unusable fields (normally if there's
    some reason ps can't print a field for any
    process, it's removed from the output entirely)
    -r, --reverse, --gratuitously-long-reverse-option
    Reverse the order of any sort
    --session[=SID] Add the processes from the session SID (which
    defaults to the sid of the current process)

    Here are some more options:
    -f ZOT, --foonly=ZOT Glork a foonly
    -z, --zaza Snit a zar

    -?, --help Give this help list
    --usage Give a short usage message
    -V, --version Print program version

    The struct argp_option array for the above could look like:

    {
    {"pid", 'p', "PID", 0, "List the process PID"},
    {"pgrp", OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"},
    {"no-parent", 'P', 0, 0, "Include processes without parents"},
    {0, 'x', 0, OPTION_ALIAS},
    {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally"
    " if there's some reason ps can't"
    " print a field for any process, it's"
    " removed from the output entirely)" },
    {"reverse", 'r', 0, 0, "Reverse the order of any sort"},
    {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS},
    {"session", OPT_SESS, "SID", OPTION_ARG_OPTIONAL,
    "Add the processes from the session"
    " SID (which defaults to the sid of"
    " the current process)" },

    {0,0,0,0, "Here are some more options:"},
    {"foonly", 'f', "ZOT", 0, "Glork a foonly"},
    {"zaza", 'z', 0, 0, "Snit a zar"},

    {0}
    }

    Note that the last three options are automatically supplied by argp_parse,
    unless you tell it not to with ARGP_NO_HELP.

    */

    /* Returns true if CH occurs between BEG and END. */
    static int
    find_char (char ch, char *beg, char *end)
    {
    while (beg < end)
    if (*beg == ch)
    return 1;
    else
    beg++;
    return 0;
    }

    struct hol_cluster; /* fwd decl */

    struct hol_entry
    {
    /* First option. */
    const struct argp_option *opt;
    /* Number of options (including aliases). */
    unsigned num;

    /* A pointers into the HOL's short_options field, to the first short option
    letter for this entry. The order of the characters following this point
    corresponds to the order of options pointed to by OPT, and there are at
    most NUM. A short option recorded in a option following OPT is only
    valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's
    probably been shadowed by some other entry). */
    char *short_options;

    /* Entries are sorted by their group first, in the order:
    1, 2, ..., n, 0, -m, ..., -2, -1
    and then alphabetically within each group. The default is 0. */
    int group;

    /* The cluster of options this entry belongs to, or 0 if none. */
    struct hol_cluster *cluster;

    /* The argp from which this option came. */
    const struct argp *argp;
    };

    /* A cluster of entries to reflect the argp tree structure. */
    struct hol_cluster
    {
    /* A descriptive header printed before options in this cluster. */
    const char *header;

    /* Used to order clusters within the same group with the same parent,
    according to the order in which they occurred in the parent argp's child
    list. */
    int index;

    /* How to sort this cluster with respect to options and other clusters at the
    same depth (clusters always follow options in the same group). */
    int group;

    /* The cluster to which this cluster belongs, or 0 if it's at the base
    level. */
    struct hol_cluster *parent;

    /* The argp from which this cluster is (eventually) derived. */
    const struct argp *argp;

    /* The distance this cluster is from the root. */
    int depth;

    /* Clusters in a given hol are kept in a linked list, to make freeing them
    possible. */
    struct hol_cluster *next;
    };

    /* A list of options for help. */
    struct hol
    {
    /* An array of hol_entry's. */
    struct hol_entry *entries;
    /* The number of entries in this hol. If this field is zero, the others
    are undefined. */
    unsigned num_entries;

    /* A string containing all short options in this HOL. Each entry contains
    pointers into this string, so the order can't be messed with blindly. */
    char *short_options;

    /* Clusters of entries in this hol. */
    struct hol_cluster *clusters;
    };

    /* Create a struct hol from the options in ARGP. CLUSTER is the
    hol_cluster in which these entries occur, or 0, if at the root. */
    static struct hol *
    make_hol (const struct argp *argp, struct hol_cluster *cluster)
    {
    char *so;
    const struct argp_option *o;
    const struct argp_option *opts = argp->options;
    struct hol_entry *entry;
    unsigned num_short_options = 0;
    struct hol *hol = malloc (sizeof (struct hol));

    assert (hol);

    hol->num_entries = 0;
    hol->clusters = 0;

    if (opts)
    {
    int cur_group = 0;

    /* The first option must not be an alias. */
    assert (! oalias (opts));

  25. #25
    俺はまんこが大好きなんだよ baseline bum's Avatar
    My Team
    San Antonio Spurs
    Join Date
    Mar 2003
    Post Count
    97,881
    /* Calculate the space needed. */
    for (o = opts; ! oend (o); o++)
    {
    if (! oalias (o))
    hol->num_entries++;
    if (oshort (o))
    num_short_options++; /* This is an upper bound. */
    }

    hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries);
    hol->short_options = malloc (num_short_options + 1);

    assert (hol->entries && hol->short_options);
    #if SIZE_MAX <= UINT_MAX
    assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry));
    #endif

    /* Fill in the entries. */
    so = hol->short_options;
    for (o = opts, entry = hol->entries; ! oend (o); entry++)
    {
    entry->opt = o;
    entry->num = 0;
    entry->short_options = so;
    entry->group = cur_group =
    o->group
    ? o->group
    : ((!o->name && !o->key)
    ? cur_group + 1
    : cur_group);
    entry->cluster = cluster;
    entry->argp = argp;

    do
    {
    entry->num++;
    if (oshort (o) && ! find_char (o->key, hol->short_options, so))
    /* O has a valid short option which hasn't already been used.*/
    *so++ = o->key;
    o++;
    }
    while (! oend (o) && oalias (o));
    }
    *so = '\0'; /* null terminated so we can find the length */
    }

    return hol;
    }

    /* Add a new cluster to HOL, with the given GROUP and HEADER (taken from the
    associated argp child list entry), INDEX, and PARENT, and return a pointer
    to it. ARGP is the argp that this cluster results from. */
    static struct hol_cluster *
    hol_add_cluster (struct hol *hol, int group, const char *header, int index,
    struct hol_cluster *parent, const struct argp *argp)
    {
    struct hol_cluster *cl = malloc (sizeof (struct hol_cluster));
    if (cl)
    {
    cl->group = group;
    cl->header = header;

    cl->index = index;
    cl->parent = parent;
    cl->argp = argp;
    cl->depth = parent ? parent->depth + 1 : 0;

    cl->next = hol->clusters;
    hol->clusters = cl;
    }
    return cl;
    }

    /* Free HOL and any resources it uses. */
    static void
    hol_free (struct hol *hol)
    {
    struct hol_cluster *cl = hol->clusters;

    while (cl)
    {
    struct hol_cluster *next = cl->next;
    free (cl);
    cl = next;
    }

    if (hol->num_entries > 0)
    {
    free (hol->entries);
    free (hol->short_options);
    }

    free (hol);
    }

    static int
    hol_entry_short_iterate (const struct hol_entry *entry,
    int (*func)(const struct argp_option *opt,
    const struct argp_option *real,
    const char *domain, void *cookie),
    const char *domain, void *cookie)
    {
    unsigned nopts;
    int val = 0;
    const struct argp_option *opt, *real = entry->opt;
    char *so = entry->short_options;

    for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
    if (oshort (opt) && *so == opt->key)
    {
    if (!oalias (opt))
    real = opt;
    if (ovisible (opt))
    val = (*func)(opt, real, domain, cookie);
    so++;
    }

    return val;
    }

    static inline int
    __attribute__ ((always_inline))
    hol_entry_long_iterate (const struct hol_entry *entry,
    int (*func)(const struct argp_option *opt,
    const struct argp_option *real,
    const char *domain, void *cookie),
    const char *domain, void *cookie)
    {
    unsigned nopts;
    int val = 0;
    const struct argp_option *opt, *real = entry->opt;

    for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
    if (opt->name)
    {
    if (!oalias (opt))
    real = opt;
    if (ovisible (opt))
    val = (*func)(opt, real, domain, cookie);
    }

    return val;
    }

    /* Iterator that returns true for the first short option. */
    static inline int
    until_short (const struct argp_option *opt, const struct argp_option *real,
    const char *domain, void *cookie)
    {
    return oshort (opt) ? opt->key : 0;
    }

    /* Returns the first valid short option in ENTRY, or 0 if there is none. */
    static char
    hol_entry_first_short (const struct hol_entry *entry)
    {
    return hol_entry_short_iterate (entry, until_short,
    entry->argp->argp_domain, 0);
    }

    /* Returns the first valid long option in ENTRY, or 0 if there is none. */
    static const char *
    hol_entry_first_long (const struct hol_entry *entry)
    {
    const struct argp_option *opt;
    unsigned num;
    for (opt = entry->opt, num = entry->num; num > 0; opt++, num--)
    if (opt->name && ovisible (opt))
    return opt->name;
    return 0;
    }

    /* Returns the entry in HOL with the long option name NAME, or 0 if there is
    none. */
    static struct hol_entry *
    hol_find_entry (struct hol *hol, const char *name)
    {
    struct hol_entry *entry = hol->entries;
    unsigned num_entries = hol->num_entries;

    while (num_entries-- > 0)
    {
    const struct argp_option *opt = entry->opt;
    unsigned num_opts = entry->num;

    while (num_opts-- > 0)
    if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0)
    return entry;
    else
    opt++;

    entry++;
    }

    return 0;
    }

    /* If an entry with the long option NAME occurs in HOL, set it's special
    sort position to GROUP. */
    static void
    hol_set_group (struct hol *hol, const char *name, int group)
    {
    struct hol_entry *entry = hol_find_entry (hol, name);
    if (entry)
    entry->group = group;
    }

    /* Order by group: 0, 1, 2, ..., n, -m, ..., -2, -1.
    EQ is what to return if GROUP1 and GROUP2 are the same. */
    static int
    group_cmp (int group1, int group2, int eq)
    {
    if (group1 == group2)
    return eq;
    else if ((group1 < 0 && group2 < 0) || (group1 >= 0 && group2 >= 0))
    return group1 - group2;
    else
    return group2 - group1;
    }

    /* Compare clusters CL1 & CL2 by the order that they should appear in
    output. */
    static int
    hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2)
    {
    /* If one cluster is deeper than the other, use its ancestor at the same
    level, so that finding the common ancestor is straightforward. */
    while (cl1->depth > cl2->depth)
    cl1 = cl1->parent;
    while (cl2->depth > cl1->depth)
    cl2 = cl2->parent;

    /* Now reduce both clusters to their ancestors at the point where both have
    a common parent; these can be directly compared. */
    while (cl1->parent != cl2->parent)
    cl1 = cl1->parent, cl2 = cl2->parent;

    return group_cmp (cl1->group, cl2->group, cl2->index - cl1->index);
    }

    /* Return the ancestor of CL that's just below the root (i.e., has a parent
    of 0). */
    static struct hol_cluster *
    hol_cluster_base (struct hol_cluster *cl)
    {
    while (cl->parent)
    cl = cl->parent;
    return cl;
    }

    /* Return true if CL1 is a child of CL2. */
    static int
    hol_cluster_is_child (const struct hol_cluster *cl1,
    const struct hol_cluster *cl2)
    {
    while (cl1 && cl1 != cl2)
    cl1 = cl1->parent;
    return cl1 == cl2;
    }

    /* Given the name of a OPTION_DOC option, modifies NAME to start at the tail
    that should be used for comparisons, and returns true iff it should be
    treated as a non-option. */
    static int
    canon_doc_option (const char **name)
    {
    int non_opt;
    /* Skip initial whitespace. */
    while (isspace (**name))
    (*name)++;
    /* Decide whether this looks like an option (leading `-') or not. */
    non_opt = (**name != '-');
    /* Skip until part of name used for sorting. */
    while (**name && !isalnum (**name))
    (*name)++;
    return non_opt;
    }

    /* Order ENTRY1 & ENTRY2 by the order which they should appear in a help
    listing. */
    static int
    hol_entry_cmp (const struct hol_entry *entry1,
    const struct hol_entry *entry2)
    {
    /* The group numbers by which the entries should be ordered; if either is
    in a cluster, then this is just the group within the cluster. */
    int group1 = entry1->group, group2 = entry2->group;

    if (entry1->cluster != entry2->cluster)
    {
    /* The entries are not within the same cluster, so we can't compare them
    directly, we have to use the appropiate clustering level too. */
    if (! entry1->cluster)
    /* ENTRY1 is at the `base level', not in a cluster, so we have to
    compare it's group number with that of the base cluster in which
    ENTRY2 resides. Note that if they're in the same group, the
    clustered option always comes laster. */
    return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1);
    else if (! entry2->cluster)
    /* Likewise, but ENTRY2's not in a cluster. */
    return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1);
    else
    /* Both entries are in clusters, we can just compare the clusters. */
    return hol_cluster_cmp (entry1->cluster, entry2->cluster);
    }
    else if (group1 == group2)
    /* The entries are both in the same cluster and group, so compare them
    alphabetically. */
    {
    int short1 = hol_entry_first_short (entry1);
    int short2 = hol_entry_first_short (entry2);
    int doc1 = odoc (entry1->opt);
    int doc2 = odoc (entry2->opt);
    const char *long1 = hol_entry_first_long (entry1);
    const char *long2 = hol_entry_first_long (entry2);

    if (doc1)
    doc1 = long1 != NULL && canon_doc_option (&long1);
    if (doc2)
    doc2 = long2 != NULL && canon_doc_option (&long2);

    if (doc1 != doc2)
    /* `do entation' options always follow normal options (or
    do entation options that *look* like normal options). */
    return doc1 - doc2;
    else if (!short1 && !short2 && long1 && long2)
    /* Only long options. */
    return __strcasecmp (long1, long2);
    else
    /* Compare short/short, long/short, short/long, using the first
    character of long options. Entries without *any* valid
    options (such as options with OPTION_HIDDEN set) will be put
    first, but as they're not displayed, it doesn't matter where
    they are. */
    {
    char first1 = short1 ? short1 : long1 ? *long1 : 0;
    char first2 = short2 ? short2 : long2 ? *long2 : 0;
    #ifdef _tolower
    int lower_cmp = _tolower (first1) - _tolower (first2);
    #else
    int lower_cmp = tolower (first1) - tolower (first2);
    #endif
    /* Compare ignoring case, except when the options are both the
    same letter, in which case lower-case always comes first. */
    return lower_cmp ? lower_cmp : first2 - first1;
    }
    }
    else
    /* Within the same cluster, but not the same group, so just compare
    groups. */
    return group_cmp (group1, group2, 0);
    }

    /* Version of hol_entry_cmp with correct signature for qsort. */
    static int
    hol_entry_qcmp (const void *entry1_v, const void *entry2_v)
    {
    return hol_entry_cmp (entry1_v, entry2_v);
    }

    /* Sort HOL by group and alphabetically by option name (with short options
    taking precedence over long). Since the sorting is for display purposes
    only, the shadowing of options isn't effected. */
    static void
    hol_sort (struct hol *hol)
    {
    if (hol->num_entries > 0)
    qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry),
    hol_entry_qcmp);
    }

    /* Append MORE to HOL, destroying MORE in the process. Options in HOL shadow
    any in MORE with the same name. */
    static void
    hol_append (struct hol *hol, struct hol *more)
    {
    struct hol_cluster **cl_end = &hol->clusters;

    /* Steal MORE's cluster list, and add it to the end of HOL's. */
    while (*cl_end)
    cl_end = &(*cl_end)->next;
    *cl_end = more->clusters;
    more->clusters = 0;

    /* Merge entries. */
    if (more->num_entries > 0)
    {
    if (hol->num_entries == 0)
    {
    hol->num_entries = more->num_entries;
    hol->entries = more->entries;
    hol->short_options = more->short_options;
    more->num_entries = 0; /* Mark MORE's fields as invalid. */
    }
    else
    /* Append the entries in MORE to those in HOL, taking care to only add
    non-shadowed SHORT_OPTIONS values. */
    {
    unsigned left;
    char *so, *more_so;
    struct hol_entry *e;
    unsigned num_entries = hol->num_entries + more->num_entries;
    struct hol_entry *entries =
    malloc (num_entries * sizeof (struct hol_entry));
    unsigned hol_so_len = strlen (hol->short_options);
    char *short_options =
    malloc (hol_so_len + strlen (more->short_options) + 1);

    assert (entries && short_options);
    #if SIZE_MAX <= UINT_MAX
    assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry));
    #endif

    __mempcpy (__mempcpy (entries, hol->entries,
    hol->num_entries * sizeof (struct hol_entry)),
    more->entries,
    more->num_entries * sizeof (struct hol_entry));

    __mempcpy (short_options, hol->short_options, hol_so_len);

    /* Fix up the short options pointers from HOL. */
    for (e = entries, left = hol->num_entries; left > 0; e++, left--)
    e->short_options += (short_options - hol->short_options);

    /* Now add the short options from MORE, fixing up its entries
    too. */
    so = short_options + hol_so_len;
    more_so = more->short_options;
    for (left = more->num_entries; left > 0; e++, left--)
    {
    int opts_left;
    const struct argp_option *opt;

    e->short_options = so;

    for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--)
    {
    int ch = *more_so;
    if (oshort (opt) && ch == opt->key)
    /* The next short option in MORE_SO, CH, is from OPT. */
    {
    if (! find_char (ch, short_options,
    short_options + hol_so_len))
    /* The short option CH isn't shadowed by HOL's options,
    so add it to the sum. */
    *so++ = ch;
    more_so++;
    }
    }
    }

    *so = '\0';

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •