patacongo commented on a change in pull request #2326:
URL: https://github.com/apache/incubator-nuttx/pull/2326#discussion_r527859737



##########
File path: libs/libc/unistd/lib_getopt.c
##########
@@ -39,257 +39,565 @@
 
 #include <nuttx/config.h>
 
-#include <stdbool.h>
-#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <getopt.h>
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
+#define PERMUTE                 0
+#define RETURN_IN_ORDER         1
+#define REQUIRE_ORDER           2
+
 /****************************************************************************
- * Public Data
+ * Private Type Definitions
  ****************************************************************************/
 
-FAR char *optarg; /* Optional argument following option */
-int optind = 1;   /* Index into argv */
-int optopt = '?'; /* unrecognized option character */
+typedef struct getopt_data_s
+{
+  FAR char *optarg;
+  int optind;
+  int opterr;
+  int optopt;
+  int optwhere;
+  int permute_from;
+  int num_nonopts;
+} getopt_data_t;
 
 /****************************************************************************
  * Private Data
  ****************************************************************************/
 
-static FAR char         *g_optptr       = NULL;
-static FAR char * const *g_argv         = NULL;
-static int               g_argc         = 0;
-static bool              g_binitialized = false;
+static int optwhere = 1;
+static int permute_from = 0;
+static int num_nonopts = 0;
+
+static int prev_argc;
+static FAR char *const *prev_argv;
 
 /****************************************************************************
- * Public Functions
+ * Public Data
  ****************************************************************************/
 
+FAR char *optarg; /* Optional argument following option */
+int opterr = 1;   /* Print error message */
+int optind = 1;   /* Index into argv */
+int optopt = '?'; /* unrecognized option character */
+
 /****************************************************************************
- * Name: getopt
- *
- * Description:
- *   getopt() parses command-line arguments.  Its arguments argc and argv
- *   are the argument count and array as passed to the main() function on
- *   program invocation.  An element of argv that starts with '-' is an
- *   option element. The characters of this element (aside from the initial
- *   '-') are option characters. If getopt() is called repeatedly, it
- *   returns successively each of the option characters from each of the
- *   option elements.
- *
- *   If getopt() finds another option character, it returns that character,
- *   updating the external variable optind and a static variable nextchar so
- *   that the next call to getopt() can resume the scan with the following
- *   option character or argv-element.
- *
- *   If there are no more option characters, getopt() returns -1. Then optind
- *   is the index in argv of the first argv-element that is not an option.
- *
- *   The 'optstring' argument is a string containing the legitimate option
- *   characters. If such a character is followed by a colon, this indicates
- *   that the option requires an argument.  If an argument is required for an
- *   option so getopt() places a pointer to the following text in the same
- *   argv-element, or the text of the following argv-element, in optarg.
- *
- *   NOTES:
- *   1. opterr is not supported and this implementation of getopt() never
- *      printfs error messages.
- *   2. getopt is NOT threadsafe!
- *   3. This version of getopt() does not reset global variables until
- *      -1 is returned.  As a result, your command line parsing loops
- *      must call getopt() repeatedly and continue to parse if other
- *      errors are returned ('?' or ':') until getopt() finally returns -1.
- *     (You can also set optind to -1 to force a reset).
- *
- * Returned Value:
- *   If an option was successfully found, then getopt() returns the option
- *   character. If all command-line options have been parsed, then getopt()
- *   returns -1.  If getopt() encounters an option character that was not
- *   in optstring, then '?' is returned. If getopt() encounters an option
- *   with a missing argument, then the return value depends on the first
- *   character in optstring: if it is ':', then ':' is returned; otherwise
- *   '?' is returned.
- *
+ * Private Functions
  ****************************************************************************/
 
-int getopt(int argc, FAR char * const argv[], FAR const char *optstring)
+/* reverse_argv_elements:  reverses num elements starting at argv */
+
+static void reverse_argv_elements(FAR char **argv, int num)
 {

Review comment:
       This function requires a proper function header per the coding standard. 
 The function header is often omitted for small simple functions but really is 
needed for larger, more complex functions.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to