mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 13:27:01 +08:00
Fix getopt bug
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3310 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -1463,5 +1463,9 @@
|
|||||||
a USB host HID keyboard configuraion.
|
a USB host HID keyboard configuraion.
|
||||||
* drivers/usbhost/hid_parser.c -- Leverages the LUFA HID parser written by
|
* drivers/usbhost/hid_parser.c -- Leverages the LUFA HID parser written by
|
||||||
Dean Camera.
|
Dean Camera.
|
||||||
|
* lib/lib_getopt() -- Correct an error in the getopt() logic: On certain error
|
||||||
|
return cases, the state was not being reset correcly and incorrect behaviors
|
||||||
|
could occur on subsequent calls to getopt().
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<tr align="center" bgcolor="#e4e4e4">
|
<tr align="center" bgcolor="#e4e4e4">
|
||||||
<td>
|
<td>
|
||||||
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
|
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
|
||||||
<p>Last Updated: February 19, 2011</p>
|
<p>Last Updated: February 21, 2011</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -2040,6 +2040,9 @@ nuttx-5.18 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
|||||||
a USB host HID keyboard configuraion.
|
a USB host HID keyboard configuraion.
|
||||||
* drivers/usbhost/hid_parser.c -- Leverages the LUFA HID parser written by
|
* drivers/usbhost/hid_parser.c -- Leverages the LUFA HID parser written by
|
||||||
Dean Camera.
|
Dean Camera.
|
||||||
|
* lib/lib_getopt() -- Correct an error in the getopt() logic: On certain error
|
||||||
|
return cases, the state was not being reset correcly and incorrect behaviors
|
||||||
|
could occur on subsequent calls to getopt().
|
||||||
|
|
||||||
pascal-2.1 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
pascal-2.1 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* configs/demo9s12ne64/src/up_boot.c
|
* configs/demo9s12ne64/src/up_boot.c
|
||||||
* arch/arm/src/board/up_boot.c
|
* arch/arm/src/board/up_boot.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
* Name: hcs12_boardinitialize
|
* Name: hcs12_boardinitialize
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* All INCLUDE_HCS12_ARCH architectures must provide the following entry point. This entry point
|
* All HCS12 architectures must provide the following entry point. This entry point
|
||||||
* is called early in the intitialization -- after all memory has been configured
|
* is called early in the intitialization -- after all memory has been configured
|
||||||
* and mapped but before any devices have been initialized.
|
* and mapped but before any devices have been initialized.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* drivers/lcd/nokia6100.c
|
* drivers/lcd/nokia6100.c
|
||||||
* Nokia 6100 LCD Display Driver
|
* Nokia 6100 LCD Display Driver
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
*
|
*
|
||||||
* References:
|
* References:
|
||||||
@@ -928,7 +928,7 @@ static int nokia_putrun(fb_coord_t row, fb_coord_t col, FAR const uint8_t *buffe
|
|||||||
#if NOKIA_XBIAS > 0
|
#if NOKIA_XBIAS > 0
|
||||||
col += NOKIA_XBIAS;
|
col += NOKIA_XBIAS;
|
||||||
#endif
|
#endif
|
||||||
#if NOKIA_XBIAS > 0
|
#if NOKIA_YBIAS > 0
|
||||||
row += NOKIA_YBIAS;
|
row += NOKIA_YBIAS;
|
||||||
#endif
|
#endif
|
||||||
DEBUGASSERT(buffer && col >=0 && (col + npixels) <= NOKIA_XRES && row >= 0 && row < NOKIA_YRES);
|
DEBUGASSERT(buffer && col >=0 && (col + npixels) <= NOKIA_XRES && row >= 0 && row < NOKIA_YRES);
|
||||||
|
|||||||
+39
-28
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* lib/lib_getopt.c
|
* lib/lib_getopt.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -85,7 +85,7 @@ static bool g_binitialized = false;
|
|||||||
* If there are no more option characters, getopt() returns -1. Then optind
|
* 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.
|
* 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
|
* The 'optstring' argument is a string containing the legitimate option
|
||||||
* characters. If such a character is followed by a colon, this indicates
|
* 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
|
* 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
|
* option so getopt() places a pointer to the following text in the same
|
||||||
@@ -104,6 +104,19 @@ static bool g_binitialized = false;
|
|||||||
* first character in optstring: if it is ':', then ':' is returned;
|
* first character in optstring: if it is ':', then ':' is returned;
|
||||||
* otherwise '?' is returned.
|
* otherwise '?' is returned.
|
||||||
*
|
*
|
||||||
|
* Assumptions:
|
||||||
|
* - getopt() uses global varialbles and, hence, can only be used on a single
|
||||||
|
* thread.
|
||||||
|
* - This version of getopt() implements a state machine with certain, strict
|
||||||
|
* rules. If these rules are not obeyed, the state machine will get out of
|
||||||
|
* sync and incorrect results will occur. The rules:
|
||||||
|
* 1. getopt() must be called repeatedly until a terminating value is
|
||||||
|
* returned. Terminating values include: {-1, ?, : }.
|
||||||
|
* 2. After a terminating value is returned, getopt() resets the global
|
||||||
|
* data and is ready for the next command line.
|
||||||
|
* 3. If the program chooses to violate rule #1, it may do so if it sets
|
||||||
|
* optind == -1.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int getopt(int argc, FAR char *const argv[], FAR const char *optstring)
|
int getopt(int argc, FAR char *const argv[], FAR const char *optstring)
|
||||||
@@ -162,9 +175,6 @@ int getopt(int argc, FAR char *const argv[], FAR const char *optstring)
|
|||||||
/* There are no more arguments, we are finished */
|
/* There are no more arguments, we are finished */
|
||||||
|
|
||||||
g_binitialized = false;
|
g_binitialized = false;
|
||||||
|
|
||||||
/* Return -1 with optind == all of the arguments */
|
|
||||||
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,38 +186,38 @@ int getopt(int argc, FAR char *const argv[], FAR const char *optstring)
|
|||||||
{
|
{
|
||||||
/* The argument does not start with '-', we are finished */
|
/* The argument does not start with '-', we are finished */
|
||||||
|
|
||||||
g_optptr = NULL;
|
|
||||||
g_binitialized = false;
|
g_binitialized = false;
|
||||||
|
|
||||||
/* Return the -1 with optind set to the non-option argument */
|
|
||||||
|
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Skip over the '-' */
|
/* Skip over the '-' */
|
||||||
|
|
||||||
g_optptr++;
|
g_optptr++;
|
||||||
|
|
||||||
|
/* Special case handling of "-" */
|
||||||
|
|
||||||
|
if (!*g_optptr)
|
||||||
|
{
|
||||||
|
optopt = '\0';
|
||||||
|
g_binitialized = false;
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Special case handling of "-" and "-:" */
|
/* Handle the case of ":" or '?' in the option list. We need to pick
|
||||||
|
* these off so that the return values cannot be confused with errors.
|
||||||
|
*/
|
||||||
|
|
||||||
if (!*g_optptr)
|
if (*g_optptr == ':' || *g_optptr == '?')
|
||||||
{
|
{
|
||||||
optopt = '\0'; /* We'll fix up g_optptr the next time we are called */
|
optopt = *g_optptr;
|
||||||
return '?';
|
g_binitialized = false;
|
||||||
}
|
|
||||||
|
|
||||||
/* Handle the case of "-:" */
|
|
||||||
|
|
||||||
if (*g_optptr == ':')
|
|
||||||
{
|
|
||||||
optopt = ':';
|
|
||||||
g_optptr++;
|
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* g_optptr now points at the next option and it is not something crazy.
|
/* g_optptr now points at the next option and it is not something crazy
|
||||||
* check if the option is in the list of valid options.
|
* (like NULL or ? or :). Check if the option is in the list of valid
|
||||||
|
* options.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
optchar = strchr(optstring, *g_optptr);
|
optchar = strchr(optstring, *g_optptr);
|
||||||
@@ -216,7 +226,7 @@ int getopt(int argc, FAR char *const argv[], FAR const char *optstring)
|
|||||||
/* No this character is not in the list of valid options */
|
/* No this character is not in the list of valid options */
|
||||||
|
|
||||||
optopt = *g_optptr;
|
optopt = *g_optptr;
|
||||||
g_optptr++;
|
g_binitialized = false;
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +242,9 @@ int getopt(int argc, FAR char *const argv[], FAR const char *optstring)
|
|||||||
return *optchar;
|
return *optchar;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Yes. Is the required argument after the command in this same argument? */
|
/* Yes... It has a required argument. Is the required argument after
|
||||||
|
* the command in this same argument?
|
||||||
|
*/
|
||||||
|
|
||||||
if (g_optptr[1] != '\0')
|
if (g_optptr[1] != '\0')
|
||||||
{
|
{
|
||||||
@@ -258,12 +270,11 @@ int getopt(int argc, FAR char *const argv[], FAR const char *optstring)
|
|||||||
|
|
||||||
/* No argument was supplied */
|
/* No argument was supplied */
|
||||||
|
|
||||||
optarg = NULL;
|
|
||||||
optopt = *optchar;
|
optopt = *optchar;
|
||||||
optind++;
|
g_binitialized = false;
|
||||||
return noarg_ret;
|
return noarg_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
optind = 1;
|
g_binitialized = false;
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user