Skip to content

Commit

Permalink
Changed if to ifdef
Browse files Browse the repository at this point in the history
  • Loading branch information
feasel0 committed Dec 18, 2024
1 parent 9dfed9d commit 5754022
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/lib/support/CHIPArgParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static inline bool IsShortOptionChar(int ch)
return isgraph(ch);
}

#if CONFIG_NON_POSIX_GETOPT_LONG
#ifdef CONFIG_NON_POSIX_GETOPT_LONG
static inline bool IsNotAnOption(char * const argv[], int element, int character)
{
char c = argv[element][character];
Expand Down Expand Up @@ -306,7 +306,7 @@ void (*PrintArgError)(const char * msg, ...) = DefaultPrintArgError;
* ## NON-POSIX IMPLEMENTATIONS OF getopt_long
*
* Some platforms have a version of getopt_long that behaves differently from the POSIX
* version. Set CONFIG_NON_POSIX_LONG_OPT to 1 if the platform's implementation of getopt_long
* version. Define CONFIG_NON_POSIX_GETOPT_LONG if the platform's implementation of getopt_long
* differs from POSIX in the following ways (as is the case for ESP32 and OpenIoT):
* (a) Sets optopt to '?' when encountering an unknown short option, instead of setting it
* to the actual value of the character it encountered.
Expand All @@ -326,7 +326,7 @@ bool ParseArgs(const char * progName, int argc, char * const argv[], OptionSet *
OptionDef * curOpt;
bool handlerRes;
int optIndex = -1;
#if CONFIG_NON_POSIX_GETOPT_LONG
#ifdef CONFIG_NON_POSIX_GETOPT_LONG
// The element and character being looked at during the current iteration's call to getopt_long.
int currentElement = 0;
int currentCharacter;
Expand Down Expand Up @@ -389,7 +389,7 @@ bool ParseArgs(const char * progName, int argc, char * const argv[], OptionSet *
goto done;
}

#if CONFIG_NON_POSIX_GETOPT_LONG
#ifdef CONFIG_NON_POSIX_GETOPT_LONG
// This non-POSIX getopt_long will sometimes permute argv, but not in all the cases that the POSIX version would and not always
// at the same times. This makes it hard to predict when it will permute, which can sometimes break the manual permutation that
// we're trying to do in here. To avoid this we do an initial pass through the full argv and let getopt_long get all its
Expand All @@ -413,7 +413,7 @@ bool ParseArgs(const char * progName, int argc, char * const argv[], OptionSet *
optarg = nullptr;
optopt = 0;

#if CONFIG_NON_POSIX_GETOPT_LONG
#ifdef CONFIG_NON_POSIX_GETOPT_LONG
// Advance to the next element/character that getopt_long will be processing.

// If currentElement has been initialized and currentElement is currently a short option (or short option group).
Expand Down Expand Up @@ -441,7 +441,7 @@ bool ParseArgs(const char * progName, int argc, char * const argv[], OptionSet *

id = getopt_long(argc, argv, shortOpts, longOpts, &optIndex);

#if CONFIG_NON_POSIX_GETOPT_LONG
#ifdef CONFIG_NON_POSIX_GETOPT_LONG
// The POSIX implementation does the sorting as it goes, gradually permuting argv to put the nonoptions towards the end.
// This code attempts to simulate that outcome, the one difference being that the POSIX version will move nonoptions after
// the next time getopt_long is called, whereas this code will only move nonoptions when it either encounters additional
Expand Down Expand Up @@ -510,7 +510,7 @@ bool ParseArgs(const char * progName, int argc, char * const argv[], OptionSet *
continue;
if (optopt != 0)
{
#if CONFIG_NON_POSIX_GETOPT_LONG
#ifdef CONFIG_NON_POSIX_GETOPT_LONG
if (IsShortOption(argv, currentElement))
{
// On this platform an unknown short option sets optopt to '?' instead of the actual option character, so fetch
Expand Down Expand Up @@ -543,7 +543,7 @@ bool ParseArgs(const char * progName, int argc, char * const argv[], OptionSet *
{
// NOTE: with the way getopt_long() works, it is impossible to tell whether the option that
// was missing an argument was a long option or a short option.
#if CONFIG_NON_POSIX_GETOPT_LONG
#ifdef CONFIG_NON_POSIX_GETOPT_LONG
PrintArgError("%s: Missing argument for %s option\n", progName, argv[currentElement]);
#else
PrintArgError("%s: Missing argument for %s option\n", progName, argv[optind - 1]);
Expand Down Expand Up @@ -587,7 +587,7 @@ bool ParseArgs(const char * progName, int argc, char * const argv[], OptionSet *
// If supplied, call the non-option argument handler with the remaining arguments (if any).
if (nonOptArgHandler != nullptr)
{
#if CONFIG_NON_POSIX_GETOPT_LONG
#ifdef CONFIG_NON_POSIX_GETOPT_LONG
// On a POSIX implementation, on the final interation when getopt_long returns -1 indicating it has nothing left to do,
// optind would be set to the location of the first nonoption (all of which by now would have been moved to the end of
// argv). On some non-POSIX implementations this is not true -- it simply sets optind to the location of argv's terminal
Expand Down

0 comments on commit 5754022

Please sign in to comment.