gen-win32.h revision ec5347e2c775f027573ce5648b910361aa926c01
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2004-2006 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * copyright notice and this permission notice appear in all copies.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * PERFORMANCE OF THIS SOFTWARE.
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * Copyright (c) 1987, 1993, 1994
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * The Regents of the University of California. All rights reserved.
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * Redistribution and use in source and binary forms, with or without
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * modification, are permitted provided that the following conditions
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * 1. Redistributions of source code must retain the above copyright
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * notice, this list of conditions and the following disclaimer.
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * 2. Redistributions in binary form must reproduce the above copyright
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * notice, this list of conditions and the following disclaimer in the
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * documentation and/or other materials provided with the distribution.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * 3. All advertising materials mentioning features or use of this software
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * must display the following acknowledgement:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * This product includes software developed by the University of
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * California, Berkeley and its contributors.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * 4. Neither the name of the University nor the names of its contributors
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * may be used to endorse or promote products derived from this software
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * without specific prior written permission.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c6b65dff5123de7229b281329928a3b457338f0aAutomatic Updater * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * SUCH DAMAGE.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister/* $Id: gen-win32.h,v 1.22 2007/06/18 23:47:40 tbox Exp $ */
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * \author Principal Authors: Computer Systems Research Group at UC Berkeley
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * \author Principal ISC caretaker: DCL
a6ad80dd084a217fcfd93c8e4976b6ac7410ccbfEvan Hunt * \note This file was adapted from the NetBSD project's source tree, RCS ID:
a6ad80dd084a217fcfd93c8e4976b6ac7410ccbfEvan Hunt * NetBSD: getopt.c,v 1.15 1999/09/20 04:39:37 lukem Exp
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * The primary change has been to rename items to the ISC namespace
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * and format in the ISC coding style.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * This file is responsible for defining two operations that are not
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * directly portable between Unix-like systems and Windows NT, option
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * parsing and directory scanning. It is here because it was decided
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * that the "gen" build utility was not to depend on libisc.a, so
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * the functions delcared in isc/commandline.h and isc/dir.h could not
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * The commandline stuff is pretty much a straight copy from the initial
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * isc/commandline.c. The dir stuff was shrunk to fit the needs of gen.c.
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffint isc_commandline_index = 1; /* Index into parent argv vector. */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffint isc_commandline_option; /* Character checked for validity. */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffchar *isc_commandline_argument; /* Argument associated with option. */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffchar *isc_commandline_progname; /* For printing error messages. */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffisc_boolean_t isc_commandline_errprint = ISC_TRUE; /* Print error messages. */
a193a7a1f098d91919ffee935a715aeb7019637cMichael Graffisc_boolean_t isc_commandline_reset = ISC_TRUE; /* Reset processing. */
52d06580bd522aa193de65c62e2142ab32f18398James Brister * Parse argc/argv argument vector.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrenceisc_commandline_parse(int argc, char * const *argv, const char *options) {
52d06580bd522aa193de65c62e2142ab32f18398James Brister char *option; /* Index into *options of option. */
52d06580bd522aa193de65c62e2142ab32f18398James Brister * Update scanning pointer, either because a reset was requested or
52d06580bd522aa193de65c62e2142ab32f18398James Brister * the previous argv was finished.
52d06580bd522aa193de65c62e2142ab32f18398James Brister if (isc_commandline_reset || *place == '\0') {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *(place = argv[isc_commandline_index]) != '-') {
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * Index out of range or points to non-option.
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * Found '--' to signal end of options. Advance
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * index to next argv, the first non-option.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein return (-1);
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister option = strchr(options, isc_commandline_option);
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * Ensure valid option has been passed as specified by options string.
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * '-:' is never a valid command line option because it could not
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister * distinguish ':' from the argument specifier in the options string.
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister if (isc_commandline_option == ':' || option == NULL) {
e03329a3878634cc75d94e5a69661fcbc4981e52James Brister if (isc_commandline_errprint && *options != ':')
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Option does not take an argument.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Skip to next argv if at the end of the current argv.
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Graff * Option needs an argument.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Option is in this argv, -D1 style.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Option is next argv, -D 1 style.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister isc_commandline_argument = argv[isc_commandline_index];
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Argument needed, but no more argv.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Silent failure with "missing argument" return
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff * when ':' starts options string, per historical spec.
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence "%s: option requires an argument -- %c\n",
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Point to argv that follows argument.
9ca3879f7178004e2350f74dc7a1a85145b0a5ccMichael Grafftypedef struct {
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Bristerstart_directory(const char *path, isc_dir_t *dir) {
4e7973990c2aaec391cf307a7e60583331568e01Evan Hunt * Need space for slash-splat and final NUL.
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister * Append slash (if needed) and splat.
915723e4007e177b10c0e1c9d1bfe77ac2bfe853Michael Graff if (p != pattern && p[-1] != '\\' && p[-1] != ':')
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister dir->handle = FindFirstFile(pattern, &dir->find_data);
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson dir->filename = dir->find_data.cFileName;
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister else if (dir->handle != INVALID_HANDLE_VALUE) {
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister if (FindNextFile(dir->handle, &dir->find_data) == TRUE)
ffbec84459fe3863cc7ccf8e6c91fc66248144d7James Brister#endif /* DNS_GEN_WIN32_H */