<commit_before>/* lsx_getopt for SoX
 *
 * (c) 2011 <NAME> and SoX contributors
 *
 * This 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.
 *
 * This 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 this library; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "sox.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>

void
LSX_API lsx_getopt_init(
    LSX_PARAM_IN             int argc,                      /* Number of arguments in argv */
    LSX_PARAM_IN_COUNT(argc) char * const * argv,           /* Array of arguments */
    LSX_PARAM_IN_Z           char const * shortopts,        /* Short option characters */
    LSX_PARAM_IN_OPT         lsx_option_t const * longopts, /* Array of long option descriptors */
    LSX_PARAM_IN             lsx_getopt_flags_t flags,      /* Flags for longonly and opterr */
    LSX_PARAM_IN             int first,                     /* First argument to check (usually 1) */
    LSX_PARAM_OUT            lsx_getopt_t * state)          /* State object to initialize */
{
    assert(argc >= 0);
    assert(argv != NULL);
    assert(shortopts);
    assert(first >= 0);
    assert(first <= argc);
    assert(state);
    if (state)
    {
        if (argc < 0 ||
            !argv ||
            !shortopts ||
            first < 0 ||
            first > argc)
        {
            memset(state, 0, sizeof(*state));
        }
        else
        {
            state->argc = argc;
            state->argv = argv;
            state->shortopts =
                (shortopts[0] == '+' || shortopts[0] == '-') /* Requesting GNU special behavior? */
                ? shortopts + 1 /* Ignore request. */
                : shortopts; /* No special behavior requested. */
            state->longopts = longopts;
            state->flags = flags;
            state->curpos = NULL;
            state->ind = first;
            state->opt = '?';
            state->arg = NULL;
            state->lngind = -1;
        }
    }
}

static void CheckCurPosEnd(
    LSX_PARAM_INOUT lsx_getopt_t * state)
{
    if (!state->curpos[0])
    {
        state->curpos = NULL;
        state->ind++;
    }
}

int
LSX_API lsx_getopt(
    LSX_PARAM_INOUT lsx_getopt_t * state)
{
    int oerr;
    assert(state);
    if (!state)<commit_msg>Fix warning about ignored cdecl.<commit_after>/* lsx_getopt for SoX
 *
 * (c) 2011 <NAME> and SoX contributors
 *
 * This 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.
 *
 * This 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 this library; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "sox.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>

void
lsx_getopt_init(
    LSX_PARAM_IN             int argc,                      /* Number of arguments in argv */
    LSX_PARAM_IN_COUNT(argc) char * const * argv,           /* Array of arguments */
    LSX_PARAM_IN_Z           char const * shortopts,        /* Short option characters */
    LSX_PARAM_IN_OPT         lsx_option_t const * longopts, /* Array of long option descriptors */
    LSX_PARAM_IN             lsx_getopt_flags_t flags,      /* Flags for longonly and opterr */
    LSX_PARAM_IN             int first,                     /* First argument to check (usually 1) */
    LSX_PARAM_OUT            lsx_getopt_t * state)          /* State object to initialize */
{
    assert(argc >= 0);
    assert(argv != NULL);
    assert(shortopts);
    assert(first >= 0);
    assert(first <= argc);
    assert(state);
    if (state)
    {
        if (argc < 0 ||
            !argv ||
            !shortopts ||
            first < 0 ||
            first > argc)
        {
            memset(state, 0, sizeof(*state));
        }
        else
        {
            state->argc = argc;
            state->argv = argv;
            state->shortopts =
                (shortopts[0] == '+' || shortopts[0] == '-') /* Requesting GNU special behavior? */
                ? shortopts + 1 /* Ignore request. */
                : shortopts; /* No special behavior requested. */
            state->longopts = longopts;
            state->flags = flags;
            state->curpos = NULL;
            state->ind = first;
            state->opt = '?';
            state->arg = NULL;
            state->lngind = -1;
        }
    }
}

static void CheckCurPosEnd(
    LSX_PARAM_INOUT lsx_getopt_t * state)
{
    if (!state->curpos[0])
    {
        state->curpos = NULL;
        state->ind++;
    }
}

int
lsx_getopt(
    LSX_PARAM_INOUT lsx_getopt_t * state)
{
    int oerr;
    assert(state);
    if (!state)
{'fraction_non_alphanumeric': 0.0996648438878109, 'fraction_numerical': 0.009878285411889223, 'mean_word_length': 1.953125, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '707816', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1624, 'n_words': 545}