gen-win32.h revision 47b7dfffe5d806c6a5e99ef17f07bcde812c2132
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson/*
431a83fb29482c5170b3e4026e59bb14849a6707Tinderbox User * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
a7038d1a0513c8e804937ebc95fc9cb3a46c04f5Mark Andrews * Copyright (C) 1999-2001 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
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.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
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.
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson */
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/*
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Copyright (c) 1987, 1993, 1994
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * The Regents of the University of California. All rights reserved.
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence *
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson * Redistribution and use in source and binary forms, with or without
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson * modification, are permitted provided that the following conditions
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson * are met:
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 *
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.
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson */
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews/* $Id: gen-win32.h,v 1.24 2009/01/17 14:24:25 fdupont Exp $ */
ec3f1d35170225c74d11c27bb184e250d150b209Tatuya JINMEI 神明達哉
ec3f1d35170225c74d11c27bb184e250d150b209Tatuya JINMEI 神明達哉/*! \file
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson * \author Principal Authors: Computer Systems Research Group at UC Berkeley
b356893425f18a2399771faa875e91318f204fb5Andreas Gustafsson * \author Principal ISC caretaker: DCL
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews */
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews/*
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
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews *
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 *
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
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson * be used.
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson *
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.
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews */
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#ifndef DNS_GEN_WIN32_H
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson#define DNS_GEN_WIN32_H 1
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson#include <stdio.h>
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson#include <string.h>
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#include <windows.h>
c53a5699c8242636fd913a4d07b4447efebe3bbfMark Andrews
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews#include <isc/boolean.h>
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews#include <isc/lang.h>
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonint isc_commandline_index = 1; /* Index into parent argv vector. */
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrenceint isc_commandline_option; /* Character checked for validity. */
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonchar *isc_commandline_argument; /* Argument associated with option. */
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonchar *isc_commandline_progname; /* For printing error messages. */
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
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
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson#define BADOPT '?'
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson#define BADARG ':'
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson#define ENDOPT ""
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas GustafssonISC_LANG_BEGINDECLS
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence/*
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence * getopt --
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson * Parse argc/argv argument vector.
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson */
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonint
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonisc_commandline_parse(int argc, char * const *argv, const char *options) {
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson static char *place = ENDOPT;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson char *option; /* Index into *options of option. */
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson /*
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson * Update scanning pointer, either because a reset was requested or
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson * the previous argv was finished.
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson */
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson if (isc_commandline_reset || *place == '\0') {
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson isc_commandline_reset = ISC_FALSE;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson if (isc_commandline_progname == NULL)
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson isc_commandline_progname = argv[0];
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson if (isc_commandline_index >= argc ||
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson *(place = argv[isc_commandline_index]) != '-') {
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson /*
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson * Index out of range or points to non-option.
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson */
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson place = ENDOPT;
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson return (-1);
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson }
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson /*
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews * Found '--' to signal end of options. Advance
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson * index to next argv, the first non-option.
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews */
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson isc_commandline_index++;
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson place = ENDOPT;
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson return (-1);
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews }
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews }
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews isc_commandline_option = *place++;
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews option = strchr(options, isc_commandline_option);
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews /*
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 */
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews if (isc_commandline_option == ':' || option == NULL) {
66a12302e12be6813c3e16e6c05e4a7871e78e6eMark Andrews if (*place == '\0')
66a12302e12be6813c3e16e6c05e4a7871e78e6eMark Andrews isc_commandline_index++;
66a12302e12be6813c3e16e6c05e4a7871e78e6eMark Andrews
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews if (isc_commandline_errprint && *options != ':')
4423c99613db1399dbb5c51e86ef0d351a1418c2Mark Andrews fprintf(stderr, "%s: illegal option -- %c\n",
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews isc_commandline_progname,
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews isc_commandline_option);
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews return (BADOPT);
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson }
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson if (*++option != ':') {
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson /*
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson * Option does not take an argument.
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson */
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews isc_commandline_argument = NULL;
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews /*
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews * Skip to next argv if at the end of the current argv.
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews */
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews if (*place == '\0')
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews ++isc_commandline_index;
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews } else {
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson /*
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Option needs an argument.
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson */
6526fd032fc418411da3af4201214e95c113d3e2Mark Andrews if (*place != '\0')
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson /*
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson * Option is in this argv, -D1 style.
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson */
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson isc_commandline_argument = place;
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson
28e509b145c3d241d1d2d9102fea38afad95bbd4Andreas Gustafsson else if (argc > ++isc_commandline_index)
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson /*
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson * Option is next argv, -D 1 style.
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson */
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson isc_commandline_argument = argv[isc_commandline_index];
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson else {
4c577cbd1efc14156751e5b2ced7a866871a2f1aMark Andrews /*
4c577cbd1efc14156751e5b2ced7a866871a2f1aMark Andrews * Argument needed, but no more argv.
4c577cbd1efc14156751e5b2ced7a866871a2f1aMark Andrews */
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson place = ENDOPT;
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson /*
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson * Silent failure with "missing argument" return
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson * when ':' starts options string, per historical spec.
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson */
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson if (*options == ':')
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson return (BADARG);
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (isc_commandline_errprint)
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson fprintf(stderr,
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson "%s: option requires an argument -- %c\n",
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence isc_commandline_progname,
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence isc_commandline_option);
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson return (BADOPT);
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson }
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson place = ENDOPT;
8eaa51a6991ea6bc6c9db0b907beacde8dd1fed2Andreas Gustafsson
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews /*
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews * Point to argv that follows argument.
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews */
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews isc_commandline_index++;
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews }
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews return (isc_commandline_option);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews}
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrewstypedef struct {
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews HANDLE handle;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews WIN32_FIND_DATA find_data;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews isc_boolean_t first_file;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews char *filename;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews} isc_dir_t;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrewsisc_boolean_t
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrewsstart_directory(const char *path, isc_dir_t *dir) {
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews char pattern[_MAX_PATH], *p;
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews /*
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews * Need space for slash-splat and final NUL.
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews */
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews if (strlen(path) + 3 > sizeof(pattern))
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews return (ISC_FALSE);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
bfbd478cdbd57c1e03c49932cad15b7d6344d709Mark Andrews strcpy(pattern, path);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews /*
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews * Append slash (if needed) and splat.
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews */
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews p = pattern + strlen(pattern);
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews if (p != pattern && p[-1] != '\\' && p[-1] != ':')
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews *p++ = '\\';
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews *p++ = '*';
4844ed026a9b5a91044e76399cee80a6514cbf0dMark Andrews *p++ = '\0';
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence dir->first_file = ISC_TRUE;
0874abad14e3e9ecfc3dc1a1a2b9969f2f027724Mark Andrews
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence dir->handle = FindFirstFile(pattern, &dir->find_data);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson if (dir->handle == INVALID_HANDLE_VALUE) {
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson dir->filename = NULL;
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence return (ISC_FALSE);
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson } else {
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson dir->filename = dir->find_data.cFileName;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson return (ISC_TRUE);
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence }
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson}
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonisc_boolean_t
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonnext_file(isc_dir_t *dir) {
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson if (dir->first_file)
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson dir->first_file = ISC_FALSE;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
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;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson else
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson dir->filename = NULL;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson } else
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson dir->filename = NULL;
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson if (dir->filename != NULL)
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson return (ISC_TRUE);
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson else
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson return (ISC_FALSE);
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson}
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonvoid
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafssonend_directory(isc_dir_t *dir) {
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson if (dir->handle != INVALID_HANDLE_VALUE)
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson FindClose(dir->handle);
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson}
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas GustafssonISC_LANG_ENDDECLS
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrence
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson#endif /* DNS_GEN_WIN32_H */
5d82424f5d3c77c092c111b935041fd3dc4b3e98Andreas Gustafsson