summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host
diff options
context:
space:
mode:
authorDeepak Panickal <deepak@codeplay.com>2014-01-31 18:48:46 +0000
committerDeepak Panickal <deepak@codeplay.com>2014-01-31 18:48:46 +0000
commit914b8d989b0ea9f0da066773c7ca703eaa013f6b (patch)
tree670cb2885c1a859d2f53f3539c52590675c25267 /lldb/source/Host
parent322ce39e39186aaea01c7b8ebfa14ff537721ea9 (diff)
downloadbcm5719-llvm-914b8d989b0ea9f0da066773c7ca703eaa013f6b.tar.gz
bcm5719-llvm-914b8d989b0ea9f0da066773c7ca703eaa013f6b.zip
Fixing the Windows build for the changes brought in from the iohandler merge.
llvm-svn: 200565
Diffstat (limited to 'lldb/source/Host')
-rw-r--r--lldb/source/Host/common/OptionParser.cpp8
-rw-r--r--lldb/source/Host/windows/CMakeLists.txt2
-rw-r--r--lldb/source/Host/windows/EditLineWin.cpp422
-rw-r--r--lldb/source/Host/windows/GetOptInc.cpp (renamed from lldb/source/Host/windows/msvc/getopt.inc)283
4 files changed, 526 insertions, 189 deletions
diff --git a/lldb/source/Host/common/OptionParser.cpp b/lldb/source/Host/common/OptionParser.cpp
index ead044f53cf..cf133597cb8 100644
--- a/lldb/source/Host/common/OptionParser.cpp
+++ b/lldb/source/Host/common/OptionParser.cpp
@@ -9,14 +9,10 @@
#include "lldb/Host/OptionParser.h"
-#ifdef _MSC_VER
-#include "../windows/msvc/getopt.inc"
-#else
-#ifdef _WIN32
+#if (!defined( _MSC_VER ) && defined( _WIN32 ))
#define _BSD_SOURCE // Required so that getopt.h defines optreset
#endif
-#include <getopt.h>
-#endif
+#include "lldb/Host/HostGetOpt.h"
using namespace lldb_private;
diff --git a/lldb/source/Host/windows/CMakeLists.txt b/lldb/source/Host/windows/CMakeLists.txt
index 0ffe73439c8..604cfd6c0ca 100644
--- a/lldb/source/Host/windows/CMakeLists.txt
+++ b/lldb/source/Host/windows/CMakeLists.txt
@@ -6,4 +6,6 @@ add_lldb_library(lldbHostWindows
Mutex.cpp
Condition.cpp
Windows.cpp
+ EditLineWin.cpp
+ GetOptInc.cpp
)
diff --git a/lldb/source/Host/windows/EditLineWin.cpp b/lldb/source/Host/windows/EditLineWin.cpp
new file mode 100644
index 00000000000..da3a9eac857
--- /dev/null
+++ b/lldb/source/Host/windows/EditLineWin.cpp
@@ -0,0 +1,422 @@
+//===-- ELWrapper.cpp -------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// this file is only relevant for Visual C++
+#if defined( _MSC_VER )
+
+#include "lldb/Host/windows/windows.h"
+
+#include "lldb/Host/windows/editlinewin.h"
+#include <vector>
+#include <assert.h>
+
+// index one of the variable arguments
+// presuming "(EditLine *el, ..." is first in the argument list
+#define GETARG( X ) ( (void* ) *( ( (int**) &el ) + ((X) + 2) ) )
+
+// edit line EL_ADDFN function pointer type
+typedef unsigned char (*el_addfn_func)(EditLine *e, int ch);
+
+// edit line wrapper binding container
+struct el_binding
+{
+ //
+ const char *name;
+ const char *help;
+ // function pointer to callback routine
+ el_addfn_func func;
+ // ascii key this function is bound to
+ const char *key;
+};
+
+// stored key bindings
+static std::vector<el_binding*> _bindings;
+
+//TODO: this should infact be related to the exact edit line context we create
+static void *clientData = NULL;
+
+// store the current prompt string
+// default to what we expect to receive anyway
+static const char *_prompt = "(lldb) ";
+
+#if !defined( _WIP_INPUT_METHOD )
+
+static char *
+el_get_s (char *buffer, int chars)
+{
+ return gets_s(buffer, chars);
+}
+#else
+
+static void
+con_output (char _in)
+{
+ HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
+ DWORD written = 0;
+ // get the cursor position
+ CONSOLE_SCREEN_BUFFER_INFO info;
+ GetConsoleScreenBufferInfo( hout, &info );
+ // output this char
+ WriteConsoleOutputCharacterA( hout, &_in, 1, info.dwCursorPosition, &written );
+ // advance cursor position
+ info.dwCursorPosition.X++;
+ SetConsoleCursorPosition( hout, info.dwCursorPosition );
+}
+
+static void
+con_backspace (void)
+{
+ HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
+ DWORD written = 0;
+ // get cursor position
+ CONSOLE_SCREEN_BUFFER_INFO info;
+ GetConsoleScreenBufferInfo( hout, &info );
+ // nudge cursor backwards
+ info.dwCursorPosition.X--;
+ SetConsoleCursorPosition( hout, info.dwCursorPosition );
+ // blank out the last character
+ WriteConsoleOutputCharacterA( hout, " ", 1, info.dwCursorPosition, &written );
+}
+
+static void
+con_return (void)
+{
+ HANDLE hout = GetStdHandle( STD_OUTPUT_HANDLE );
+ DWORD written = 0;
+ // get cursor position
+ CONSOLE_SCREEN_BUFFER_INFO info;
+ GetConsoleScreenBufferInfo( hout, &info );
+ // move onto the new line
+ info.dwCursorPosition.X = 0;
+ info.dwCursorPosition.Y++;
+ SetConsoleCursorPosition( hout, info.dwCursorPosition );
+}
+
+static bool
+runBind (char _key)
+{
+ for ( int i=0; i<_bindings.size(); i++ )
+ {
+ el_binding *bind = _bindings[i];
+ if ( bind->key[0] == _key )
+ {
+ bind->func( (EditLine*) -1, _key );
+ return true;
+ }
+ }
+ return false;
+}
+
+// replacement get_s which is EL_BIND aware
+static char *
+el_get_s (char *buffer, int chars)
+{
+ //
+ char *head = buffer;
+ //
+ for ( ;; Sleep( 10 ) )
+ {
+ //
+ INPUT_RECORD _record;
+ //
+ DWORD _read = 0;
+ if ( ReadConsoleInputA( GetStdHandle( STD_INPUT_HANDLE ), &_record, 1, &_read ) == FALSE )
+ break;
+ // if we didnt read a key
+ if ( _read == 0 )
+ continue;
+ // only interested in key events
+ if ( _record.EventType != KEY_EVENT )
+ continue;
+ // is the key down
+ if (! _record.Event.KeyEvent.bKeyDown )
+ continue;
+ // read the ascii key character
+ char _key = _record.Event.KeyEvent.uChar.AsciiChar;
+ // non ascii conformant key press
+ if ( _key == 0 )
+ {
+ // check the scan code
+ // if VK_UP scroll back through history
+ // if VK_DOWN scroll forward through history
+ continue;
+ }
+ // try to execute any bind this key may have
+ if ( runBind( _key ) )
+ continue;
+ // if we read a return key
+ if ( _key == '\n' || _key == '\r' )
+ {
+ con_return( );
+ break;
+ }
+ // key is backspace
+ if ( _key == 0x8 )
+ {
+ // avoid deleting past beginning
+ if ( head > buffer )
+ {
+ con_backspace( );
+ head--;
+ }
+ continue;
+ }
+
+ // add this key to the input buffer
+ if ( (head-buffer) < (chars-1) )
+ {
+ con_output( _key );
+ *(head++) = _key;
+ }
+ }
+ // insert end of line character
+ *head = '\0';
+
+ return buffer;
+}
+#endif
+
+// edit line initalise
+EditLine *
+el_init (const char *, FILE *, FILE *, FILE *)
+{
+ //
+ SetConsoleTitleA( "lldb" );
+ // return dummy handle
+ return (EditLine*) -1;
+}
+
+const char *
+el_gets (EditLine *el, int *length)
+{
+ // print the prompt if we have one
+ if ( _prompt != NULL )
+ printf( _prompt );
+ // create a buffer for the user input
+ char *buffer = new char[ MAX_PATH ];
+ // try to get user input string
+ if ( el_get_s( buffer, MAX_PATH ) )
+ {
+ // get the string length in 'length'
+ while ( buffer[ *length ] != '\0' )
+ (*length)++;
+ // return the input buffer
+ // remember that this memory has the be free'd somewhere
+ return buffer;
+ }
+ else
+ {
+ // on error
+ delete [] buffer;
+ return NULL;
+ }
+}
+
+int
+el_set (EditLine *el, int code, ...)
+{
+ int **arg = (int**) &el;
+ //
+ switch ( code )
+ {
+ // edit line set prompt message
+ case ( EL_PROMPT ):
+ {
+ // EL_PROMPT, char *(*f)( EditLine *)
+ // define a prompt printing function as 'f', which is to return a string that
+ // contains the prompt.
+
+ // get the function pointer from the arg list
+ void *func_vp = (void*) *(arg+2);
+ // cast to suitable prototype
+ const char* (*func_fp)(EditLine*) = (const char*(*)(EditLine *)) func_vp;
+ // call to get the prompt as a string
+ _prompt = func_fp( el );
+ }
+ break;
+ case ( EL_EDITOR ):
+ {
+ // EL_EDITOR, const char *mode
+ // set editing mode to "emacs" or "vi"
+ }
+ break;
+ case ( EL_HIST ):
+ {
+ // EL_HIST, History *(*fun)(History *, int op, ... ), const char *ptr
+ // defines which histroy function to use, which is usualy history(). Ptr should be the
+ // value returned by history_init().
+ }
+ break;
+ case ( EL_ADDFN ):
+ {
+ // EL_ADDFN, const char *name, const char *help, unsigned char (*func)(EditLine *e, int ch)
+ // add a user defined function, func), referred to as 'name' which is invoked when a key which is bound to 'name' is
+ // entered. 'help' is a description of 'name'. at involcation time, 'ch' is the key which caused the invocation. the
+ // return value of 'func()' should be one of:
+ // CC_NORM add a normal character
+ // CC_NEWLINE end of line was entered
+ // CC_EOF EOF was entered
+ // CC_ARGHACK expecting further command input as arguments, do nothing visually.
+ // CC_REFRESH refresh display.
+ // CC_REFRESH_BEEP refresh display and beep.
+ // CC_CURSOR cursor moved so update and perform CC_REFRESH
+ // CC_REDISPLAY redisplay entire input line. this is usefull if a key binding outputs extra information.
+ // CC_ERROR an error occured. beep and flush tty.
+ // CC_FATAL fatal error, reset tty to known state.
+
+ el_binding *binding = new el_binding;
+ binding->name = (const char *) GETARG( 0 );
+ binding->help = (const char *) GETARG( 1 );
+ binding->func = (el_addfn_func) GETARG( 2 );
+ binding->key = 0;
+ // add this to the bindings list
+ _bindings.push_back( binding );
+ }
+ break;
+ case ( EL_BIND ):
+ {
+ // EL_BIND, const char *, ..., NULL
+ // perform the BIND buildin command. Refer to editrc(5) for more information.
+
+ const char *name = (const char*) GETARG( 1 );
+
+ for ( int i=0; i<_bindings.size(); i++ )
+ {
+ el_binding *bind = _bindings[i];
+ if ( strcmp( bind->name, name ) == 0 )
+ {
+ bind->key = (const char *) GETARG( 0 );
+ break;
+ }
+ }
+
+ }
+ break;
+ case ( EL_CLIENTDATA ):
+ {
+ clientData = GETARG( 0 );
+ }
+ break;
+// default:
+// assert( !"Not Implemented!" );
+ }
+ return 0;
+}
+
+void
+el_end (EditLine *el)
+{
+ assert( !"Not implemented!" );
+}
+
+void
+el_reset (EditLine *)
+{
+ assert( !"Not implemented!" );
+}
+
+int
+el_getc (EditLine *, char *)
+{
+ assert( !"Not implemented!" );
+ return 0;
+}
+
+void
+el_push (EditLine *, const char *)
+{
+// assert( !"Not implemented!" );
+}
+
+void
+el_beep (EditLine *)
+{
+ Beep( 1000, 500 );
+}
+
+int
+el_parse (EditLine *, int, const char **)
+{
+ assert( !"Not implemented!" );
+ return 0;
+}
+
+int
+el_get (EditLine *el, int code, ...)
+{
+ switch ( code )
+ {
+ case ( EL_CLIENTDATA ):
+ {
+ void **dout = (void**) GETARG( 0 );
+ *dout = clientData;
+ }
+ break;
+ default:
+ assert( !"Not implemented!" );
+ }
+ return 0;
+}
+
+int
+el_source (EditLine *el, const char *file)
+{
+ // init edit line by reading the contents of 'file'
+ // nothing to do here on windows...
+ return 0;
+}
+
+void
+el_resize (EditLine *)
+{
+ assert( !"Not implemented!" );
+}
+
+const LineInfo *
+el_line (EditLine *el)
+{
+ assert( !"Not implemented!" );
+ return 0;
+}
+
+int
+el_insertstr (EditLine *, const char *)
+{
+ assert( !"Not implemented!" );
+ return 0;
+}
+
+void
+el_deletestr (EditLine *, int)
+{
+ assert( !"Not implemented!" );
+}
+
+History *
+history_init (void)
+{
+ // return dummy handle
+ return (History*) -1;
+}
+
+void
+history_end (History *)
+{
+ assert( !"Not implemented!" );
+}
+
+int
+history (History *, HistEvent *, int op, ...)
+{
+ // perform operation 'op' on the history list with optional argumetns as needed by
+ // the operation.
+ return 0;
+}
+
+#endif
diff --git a/lldb/source/Host/windows/msvc/getopt.inc b/lldb/source/Host/windows/GetOptInc.cpp
index 9af237eb192..3be3700f9a4 100644
--- a/lldb/source/Host/windows/msvc/getopt.inc
+++ b/lldb/source/Host/windows/GetOptInc.cpp
@@ -1,91 +1,4 @@
-/* $OpenBSD: getopt_long.c,v 1.25 2011/03/05 22:10:11 guenther Exp $ */
-/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
-
-/*
- * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Sponsored in part by the Defense Advanced Research Projects
- * Agency (DARPA) and Air Force Research Laboratory, Air Force
- * Materiel Command, USAF, under agreement number F39502-99-1-0512.
- */
-/*-
- * Copyright (c) 2000 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Dieter Baron and Thomas Klausner.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``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 FOUNDATION OR CONTRIBUTORS
- * 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.
- */
-
-#ifdef _MSC_VER
-
-// getopt.h
-enum {
- no_argument = 0,
- required_argument,
- optional_argument
-};
-
-struct option {
- /* name of long option */
- const char *name;
- /*
- * one of no_argument, required_argument, and optional_argument:
- * whether option takes an argument
- */
- int has_arg;
- /* if not NULL, set *flag to val when option found */
- int *flag;
- /* if flag not NULL, value to set *flag to; else return value */
- int val;
-};
-
-int getopt(int argc, char * const argv[],
- const char *optstring);
-
-extern char *optarg;
-extern int optind, opterr, optopt;
-
-int getopt_long(int argc, char * const *argv,
- const char *optstring,
- const struct option *longopts, int *longindex);
-
-int getopt_long_only(int argc, char * const *argv,
- const char *optstring,
- const struct option *longopts, int *longindex);
-extern int optreset;
+#include "lldb/Host/windows/GetOptInc.h"
// getopt.cpp
#include <errno.h>
@@ -112,9 +25,9 @@ char *optarg; /* argument associated with option */
#define EMSG ""
static int getopt_internal(int, char * const *, const char *,
- const struct option *, int *, int);
+ const struct option *, int *, int);
static int parse_long_options(char * const *, const char *,
- const struct option *, int *, int);
+ const struct option *, int *, int);
static int gcd(int, int);
static void permute_args(int, int, int, char * const *);
@@ -133,8 +46,8 @@ static const char illoptchar[] = "unknown option -- %c";
static const char illoptstring[] = "unknown option -- %s";
/*
- * Compute the greatest common divisor of a and b.
- */
+* Compute the greatest common divisor of a and b.
+*/
static int
gcd(int a, int b)
{
@@ -154,27 +67,27 @@ static void pass() {}
#define warnx(a, ...) pass();
/*
- * Exchange the block from nonopt_start to nonopt_end with the block
- * from nonopt_end to opt_end (keeping the same order of arguments
- * in each block).
- */
+* Exchange the block from nonopt_start to nonopt_end with the block
+* from nonopt_end to opt_end (keeping the same order of arguments
+* in each block).
+*/
static void
permute_args(int panonopt_start, int panonopt_end, int opt_end,
- char * const *nargv)
+char * const *nargv)
{
int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
char *swap;
/*
- * compute lengths of blocks and number and size of cycles
- */
+ * compute lengths of blocks and number and size of cycles
+ */
nnonopts = panonopt_end - panonopt_start;
nopts = opt_end - panonopt_end;
ncycle = gcd(nnonopts, nopts);
cyclelen = (opt_end - panonopt_start) / ncycle;
for (i = 0; i < ncycle; i++) {
- cstart = panonopt_end+i;
+ cstart = panonopt_end + i;
pos = cstart;
for (j = 0; j < cyclelen; j++) {
if (pos >= panonopt_end)
@@ -183,7 +96,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end,
pos += nopts;
swap = nargv[pos];
/* LINTED const cast */
- ((char **) nargv)[pos] = nargv[cstart];
+ ((char **)nargv)[pos] = nargv[cstart];
/* LINTED const cast */
((char **)nargv)[cstart] = swap;
}
@@ -191,13 +104,13 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end,
}
/*
- * parse_long_options --
- * Parse long options in argc/argv argument vector.
- * Returns -1 if short_too is set and the option does not match long_options.
- */
+* parse_long_options --
+* Parse long options in argc/argv argument vector.
+* Returns -1 if short_too is set and the option does not match long_options.
+*/
static int
parse_long_options(char * const *nargv, const char *options,
- const struct option *long_options, int *idx, int short_too)
+const struct option *long_options, int *idx, int short_too)
{
char *current_argv, *has_equal;
size_t current_argv_len;
@@ -212,7 +125,8 @@ parse_long_options(char * const *nargv, const char *options,
/* argument found (--option=arg) */
current_argv_len = has_equal - current_argv;
has_equal++;
- } else
+ }
+ else
current_argv_len = strlen(current_argv);
for (i = 0; long_options[i].name; i++) {
@@ -227,9 +141,9 @@ parse_long_options(char * const *nargv, const char *options,
break;
}
/*
- * If this is a known short option, don't allow
- * a partial match of a single character.
- */
+ * If this is a known short option, don't allow
+ * a partial match of a single character.
+ */
if (short_too && current_argv_len == 1)
continue;
@@ -239,7 +153,7 @@ parse_long_options(char * const *nargv, const char *options,
/* ambiguous abbreviation */
if (PRINT_ERROR)
warnx(ambig, (int)current_argv_len,
- current_argv);
+ current_argv);
optopt = 0;
return (BADCH);
}
@@ -249,10 +163,10 @@ parse_long_options(char * const *nargv, const char *options,
&& has_equal) {
if (PRINT_ERROR)
warnx(noarg, (int)current_argv_len,
- current_argv);
+ current_argv);
/*
- * XXX: GNU sets optopt to val regardless of flag
- */
+ * XXX: GNU sets optopt to val regardless of flag
+ */
if (long_options[match].flag == NULL)
optopt = long_options[match].val;
else
@@ -266,23 +180,23 @@ parse_long_options(char * const *nargv, const char *options,
else if (long_options[match].has_arg ==
required_argument) {
/*
- * optional argument doesn't use next nargv
- */
+ * optional argument doesn't use next nargv
+ */
optarg = nargv[optind++];
}
}
if ((long_options[match].has_arg == required_argument)
&& (optarg == NULL)) {
/*
- * Missing argument; leading ':' indicates no error
- * should be generated.
- */
+ * Missing argument; leading ':' indicates no error
+ * should be generated.
+ */
if (PRINT_ERROR)
warnx(recargstring,
- current_argv);
+ current_argv);
/*
- * XXX: GNU sets optopt to val regardless of flag
- */
+ * XXX: GNU sets optopt to val regardless of flag
+ */
if (long_options[match].flag == NULL)
optopt = long_options[match].val;
else
@@ -290,7 +204,8 @@ parse_long_options(char * const *nargv, const char *options,
--optind;
return (BADARG);
}
- } else { /* unknown option */
+ }
+ else { /* unknown option */
if (short_too) {
--optind;
return (-1);
@@ -305,17 +220,18 @@ parse_long_options(char * const *nargv, const char *options,
if (long_options[match].flag) {
*long_options[match].flag = long_options[match].val;
return (0);
- } else
+ }
+ else
return (long_options[match].val);
}
/*
- * getopt_internal --
- * Parse argc/argv argument vector. Called by user level routines.
- */
+* getopt_internal --
+* Parse argc/argv argument vector. Called by user level routines.
+*/
static int
getopt_internal(int nargc, char * const *nargv, const char *options,
- const struct option *long_options, int *idx, int flags)
+const struct option *long_options, int *idx, int flags)
{
const char *oli; /* option letter list index */
int optchar, short_too;
@@ -325,16 +241,16 @@ getopt_internal(int nargc, char * const *nargv, const char *options,
return (-1);
/*
- * XXX Some GNU programs (like cvs) set optind to 0 instead of
- * XXX using optreset. Work around this braindamage.
- */
+ * XXX Some GNU programs (like cvs) set optind to 0 instead of
+ * XXX using optreset. Work around this braindamage.
+ */
if (optind == 0)
optind = optreset = 1;
/*
- * Disable GNU extensions if POSIXLY_CORRECT is set or options
- * string begins with a '+'.
- */
+ * Disable GNU extensions if POSIXLY_CORRECT is set or options
+ * string begins with a '+'.
+ */
if (posixly_correct == -1 || optreset)
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
if (*options == '-')
@@ -360,9 +276,9 @@ start:
}
else if (nonopt_start != -1) {
/*
- * If we skipped non-options, set optind
- * to the first of them.
- */
+ * If we skipped non-options, set optind
+ * to the first of them.
+ */
optind = nonopt_start;
}
nonopt_start = nonopt_end = -1;
@@ -373,17 +289,17 @@ start:
place = EMSG; /* found non-option */
if (flags & FLAG_ALLARGS) {
/*
- * GNU extension:
- * return non-option as argument to option 1
- */
+ * GNU extension:
+ * return non-option as argument to option 1
+ */
optarg = nargv[optind++];
return (INORDER);
}
if (!(flags & FLAG_PERMUTE)) {
/*
- * If no permutation wanted, stop parsing
- * at first non-option.
- */
+ * If no permutation wanted, stop parsing
+ * at first non-option.
+ */
return (-1);
}
/* do permutation */
@@ -404,15 +320,15 @@ start:
nonopt_end = optind;
/*
- * If we have "-" do nothing, if "--" we are done.
- */
+ * If we have "-" do nothing, if "--" we are done.
+ */
if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
optind++;
place = EMSG;
/*
- * We found an option (--), so if we skipped
- * non-options, we have to permute.
- */
+ * We found an option (--), so if we skipped
+ * non-options, we have to permute.
+ */
if (nonopt_end != -1) {
permute_args(nonopt_start, nonopt_end,
optind, nargv);
@@ -424,11 +340,11 @@ start:
}
/*
- * Check long options if:
- * 1) we were passed some
- * 2) the arg is not just "-"
- * 3) either the arg starts with -- we are getopt_long_only()
- */
+ * Check long options if:
+ * 1) we were passed some
+ * 2) the arg is not just "-"
+ * 3) either the arg starts with -- we are getopt_long_only()
+ */
if (long_options != NULL && place != nargv[optind] &&
(*place == '-' || (flags & FLAG_LONGONLY))) {
short_too = 0;
@@ -449,10 +365,10 @@ start:
(optchar == (int)'-' && *place != '\0') ||
(oli = strchr(options, optchar)) == NULL) {
/*
- * If the user specified "-" and '-' isn't listed in
- * options, return -1 (non-option) as per POSIX.
- * Otherwise, it is an unknown option character (or ':').
- */
+ * If the user specified "-" and '-' isn't listed in
+ * options, return -1 (non-option) as per POSIX.
+ * Otherwise, it is an unknown option character (or ':').
+ */
if (optchar == (int)'-' && *place == '\0')
return (-1);
if (!*place)
@@ -472,7 +388,8 @@ start:
warnx(recargchar, optchar);
optopt = optchar;
return (BADARG);
- } else /* white space */
+ }
+ else /* white space */
place = nargv[optind];
optchar = parse_long_options(nargv, options, long_options,
idx, 0);
@@ -482,7 +399,8 @@ start:
if (*++oli != ':') { /* doesn't take argument */
if (!*place)
++optind;
- } else { /* takes (optional) argument */
+ }
+ else { /* takes (optional) argument */
optarg = NULL;
if (*place) /* no white space */
optarg = place;
@@ -493,7 +411,8 @@ start:
warnx(recargchar, optchar);
optopt = optchar;
return (BADARG);
- } else
+ }
+ else
optarg = nargv[optind];
}
place = EMSG;
@@ -504,49 +423,47 @@ start:
}
/*
- * getopt --
- * Parse argc/argv argument vector.
- *
- * [eventually this will replace the BSD getopt]
- */
+* getopt --
+* Parse argc/argv argument vector.
+*
+* [eventually this will replace the BSD getopt]
+*/
int
getopt(int nargc, char * const *nargv, const char *options)
{
/*
- * We don't pass FLAG_PERMUTE to getopt_internal() since
- * the BSD getopt(3) (unlike GNU) has never done this.
- *
- * Furthermore, since many privileged programs call getopt()
- * before dropping privileges it makes sense to keep things
- * as simple (and bug-free) as possible.
- */
+ * We don't pass FLAG_PERMUTE to getopt_internal() since
+ * the BSD getopt(3) (unlike GNU) has never done this.
+ *
+ * Furthermore, since many privileged programs call getopt()
+ * before dropping privileges it makes sense to keep things
+ * as simple (and bug-free) as possible.
+ */
return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
}
/*
- * getopt_long --
- * Parse argc/argv argument vector.
- */
+* getopt_long --
+* Parse argc/argv argument vector.
+*/
int
getopt_long(int nargc, char * const *nargv, const char *options,
- const struct option *long_options, int *idx)
+const struct option *long_options, int *idx)
{
return (getopt_internal(nargc, nargv, options, long_options, idx,
FLAG_PERMUTE));
}
/*
- * getopt_long_only --
- * Parse argc/argv argument vector.
- */
+* getopt_long_only --
+* Parse argc/argv argument vector.
+*/
int
getopt_long_only(int nargc, char * const *nargv, const char *options,
- const struct option *long_options, int *idx)
+const struct option *long_options, int *idx)
{
return (getopt_internal(nargc, nargv, options, long_options, idx,
- FLAG_PERMUTE|FLAG_LONGONLY));
+ FLAG_PERMUTE | FLAG_LONGONLY));
}
-
-#endif
OpenPOWER on IntegriCloud