<commit_before>/*******************************************************************************
 * Reverse Polish Notation calculator.                                         *
 * Copyright (c) 2007, <NAME> <<EMAIL>>                 *
 * All rights reserved.                                                        *
 *                                                                             *
 * Redistribution and use in source and binary forms, with or without          *
 * modification, are permitted provided that the following conditions are met: *
 *     * Redistributions of source code must retain the above copyright        *
 *       notice, this list of conditions and the following disclaimer.         *
 *     * Redistributions in binary form must reproduce the above copyright     *
 *       notice, this list of conditions and the following disclaimer in the   *
 *       documentation and/or other materials provided with the distribution.  *
 *                                                                             *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS *
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED           *
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE      *
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY        *
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES  *
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR          *
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER  *
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          *
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY   *
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
 * DAMAGE.                                                                     *
 ******************************************************************************/

/*******************************************************************************
 * arguments.c -- processes argument options.                                  *
 ******************************************************************************/

#include "rpn.h"
#include <string.h>

#ifndef DOXYGEN_SKIP

bool RPN_argumentVersion(RPNCalculator *calculator, char **args)
{
	RPN_printf("%i.%i.%i.%i",
		__RPN_MAJOR__,
		__RPN_MINOR__,
		__RPN_REVIS__,
		__RPN_BUILD__);

	calculator->status = RPN_STATUS_EXIT;
	return false;
}

bool RPN_argumentHelp(RPNCalculator *calculator, char **args)
{
	RPN_printHelp();
	return false;
}

bool RPN_argumentExec(RPNCalculator *calculator, char **args)
{
	RPN_eval(args[0], calculator);
#ifdef RPN_LONG_DOUBLE
	RPN_printf("%Lf", RPN_peek(calculator->stack));
#elif  RPN_DOUBLE
	RPN_printf("%f", RPN_peek(calculator->stack));
#endif
	calculator->status = RPN_STATUS_EXIT;
	return true;
}

RPNArgument RPN_arguments[] =
{
	{"-v", "--version", 0, RPN_argumentVersion},
	{"-h", "--help", 0, RPN_argumentHelp},
	{"-e", "--exec", 1, RPN_argumentExec},
	{0},
};

RPNArgument *RPN_findArgument(char *name)
{
	int i;
	RPNArgument *argument;

	for(i = 0, argument = &RPN_arguments[i];
		argument->long_name;
		i++, argument = &RPN_arguments[i])
	{
		if(!strcmp(argument->short_name, name) ||
			!strcmp(argument->long_name, name))
			return argument;
	}

	return NULL;
}

#endif // DOXYGEN_SKIP
<commit_msg>Changed the way to check if an argument pointer is useful or is "Null".<commit_after>/*******************************************************************************
 * Reverse Polish Notation calculator.                                         *
 * Copyright (c) 2007, <NAME> <<EMAIL>>                 *
 * All rights reserved.                                                        *
 *                                                                             *
 * Redistribution and use in source and binary forms, with or without          *
 * modification, are permitted provided that the following conditions are met: *
 *     * Redistributions of source code must retain the above copyright        *
 *       notice, this list of conditions and the following disclaimer.         *
 *     * Redistributions in binary form must reproduce the above copyright     *
 *       notice, this list of conditions and the following disclaimer in the   *
 *       documentation and/or other materials provided with the distribution.  *
 *                                                                             *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS *
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED           *
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE      *
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY        *
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES  *
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR          *
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER  *
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          *
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY   *
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
 * DAMAGE.                                                                     *
 ******************************************************************************/

/*******************************************************************************
 * arguments.c -- processes argument options.                                  *
 ******************************************************************************/

#include "rpn.h"
#include <string.h>

#ifndef DOXYGEN_SKIP

bool RPN_argumentVersion(RPNCalculator *calculator, char **args)
{
	RPN_printf("%i.%i.%i.%i",
		__RPN_MAJOR__,
		__RPN_MINOR__,
		__RPN_REVIS__,
		__RPN_BUILD__);

	calculator->status = RPN_STATUS_EXIT;
	return false;
}

bool RPN_argumentHelp(RPNCalculator *calculator, char **args)
{
	RPN_printHelp();
	return false;
}

bool RPN_argumentExec(RPNCalculator *calculator, char **args)
{
	RPN_eval(args[0], calculator);
#ifdef RPN_LONG_DOUBLE
	RPN_printf("%Lf", RPN_peek(calculator->stack));
#elif  RPN_DOUBLE
	RPN_printf("%f", RPN_peek(calculator->stack));
#endif
	calculator->status = RPN_STATUS_EXIT;
	return true;
}

RPNArgument RPN_arguments[] =
{
	{"-v", "--version", 0, RPN_argumentVersion},
	{"-h", "--help", 0, RPN_argumentHelp},
	{"-e", "--exec", 1, RPN_argumentExec},
	{0},
};

inline bool RPN_argumentNotNull(RPNArgument *arg)
{
	if(arg->short_name && arg->long_name && arg->func)
		return true;
	return false;
}

RPNArgument *RPN_findArgument(char *name)
{
	int i;
	RPNArgument *argument;

	for(i = 0, argument = &RPN_arguments[i];
		RPN_argumentNotNull(argument);
		i++, argument = &RPN_arguments[i])
	{
		if(!strcmp(argument->short_name, name) ||
			!strcmp(argument->long_name, name))
			return argument;
	}

	return NULL;
}

#endif // DOXYGEN_SKIP

{'fraction_non_alphanumeric': 0.17626355061241727, 'fraction_numerical': 0.002815711671124877, 'mean_word_length': 2.7057902973395933, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6224981', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1812, 'n_words': 592}