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