+++ /dev/null
-name: CI
-
-on: [push, pull_request]
-
-jobs:
- direct:
- runs-on: ${{ matrix.os }}-latest
- strategy:
- matrix:
- os: [ubuntu, macos]
- python-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10']
- exclude:
- # Run only the latest 2.x and 3.x on macOS
- - os: macos
- python-version: 3.6
- - os: macos
- python-version: 3.7
- - os: macos
- python-version: 3.8
- - os: macos
- python-version: 3.9
-
- steps:
- - name: Checkout pysam
- uses: actions/checkout@v2
-
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v2
- with:
- python-version: ${{ matrix.python-version }}
-
- - name: Install prerequisite Python libraries
- run: pip install cython pytest pytest-pep8
-
- - name: Install build prerequisites
- if: runner.os == 'Linux'
- run: |
- sudo apt-get update
- sudo apt-get install -q --no-install-recommends --no-install-suggests libcurl4-openssl-dev
-
- - name: Build (directly from checkout)
- run: python setup.py build
-
- - name: Install test prerequisites
- run: |
- case $RUNNER_OS in
- Linux)
- sudo apt-get install -q --no-install-recommends --no-install-suggests samtools bcftools tabix
- ;;
- macOS)
- brew install -q samtools bcftools
- ;;
- esac
-
- - name: Run tests
- run: |
- export PYTHONPATH=$(echo $GITHUB_WORKSPACE/build/lib.*)
- export REF_PATH=':'
- pytest
-
-
- sdist:
- runs-on: ${{ matrix.os }}-latest
- strategy:
- matrix:
- os: [ubuntu, macos]
- python-version: ['3.10']
-
- steps:
- - name: Checkout pysam
- uses: actions/checkout@v2
-
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v2
- with:
- python-version: ${{ matrix.python-version }}
-
- - name: Install prerequisite Python libraries
- run: pip install cython pytest pytest-pep8
-
- - name: Install build prerequisites
- if: runner.os == 'Linux'
- run: |
- sudo apt-get update
- sudo apt-get install -q --no-install-recommends --no-install-suggests libcurl4-openssl-dev
-
- - name: Create source distribution
- run: python setup.py sdist --owner=root --group=root
-
- - name: Build (via sdist tarball)
- run: pip install --verbose --no-deps --no-binary=':all:' pysam-*.tar.gz
- working-directory: dist
-
- - name: Install test prerequisites
- run: |
- case $RUNNER_OS in
- Linux)
- sudo apt-get install -q --no-install-recommends --no-install-suggests samtools bcftools tabix
- ;;
- macOS)
- brew install -q samtools bcftools
- ;;
- esac
-
- - name: Run tests
- run: REF_PATH=':' pytest
-
- - name: Upload sdist tarball
- if: runner.os == 'Linux'
- uses: actions/upload-artifact@v2
- with:
- name: sdist
- path: dist/pysam-*.tar.gz
- retention-days: 14
-
-
- conda:
- timeout-minutes: 20
- runs-on: ${{ matrix.os }}-latest
- strategy:
- matrix:
- os: [ubuntu]
- python-version: ['3.7']
- defaults:
- run:
- shell: bash -l {0} # needed for conda activation
- env:
- HTSLIB_CONFIGURE_OPTIONS: "--disable-libcurl"
-
- steps:
- - name: Checkout pysam
- uses: actions/checkout@v2
-
- - uses: conda-incubator/setup-miniconda@v2
- with:
- channel-priority: strict
- activate-environment: testenv
- auto-activate-base: false
- use-only-tar-bz2: true
-
- - name: Set up Conda and Python ${{ matrix.python-version }}
- run: |
- conda config --add channels bioconda --add channels conda-forge
- conda install python=${{ matrix.python-version }} cython
-
- - name: Build (directly from checkout)
- run: python setup.py install
-
- - name: Install test prerequisites via Conda
- run: conda install "samtools>=1.11" "bcftools>=1.11" "htslib>=1.11" pytest
-
- - name: Run tests
- run: REF_PATH=':' pytest
+++ /dev/null
-name: Publish pysam wheels to PyPI and TestPyPI
-
-on:
- push:
- branches:
- - v[0-9]+.[0-9]+.x
- tags:
- - v*
- release:
- types:
- - published
-
-jobs:
- build_wheels:
- name: Build wheels on ${{ matrix.os }}
- runs-on: ${{ matrix.os }}
- strategy:
- matrix:
- os: [ubuntu-latest, macos-10.15] # windows-2019,
- cibw_archs: ["auto"]
- # include:
- # - os: ubuntu-latest
- # cibw_archs: "aarch64"
-
- steps:
- - name: Checkout pysam
- uses: actions/checkout@v2
-
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v2
- with:
- python-version: '3.8'
-
- - name: Install prerequisite Python libraries
- run: |
- python -m pip install --upgrade pip
- pip install cython pytest pytest-pep8
-
- - name: Build wheels for linux
- if: runner.os == 'Linux'
- uses: pypa/cibuildwheel@v2.2.2
- env:
- CIBW_BUILD: cp36-* cp37-* cp38-* cp39-* cp310-*
- CIBW_SKIP: "*musllinux*"
- CIBW_BEFORE_BUILD: yum install -y libcurl-devel zlib-devel bzip2-devel xz-devel && pip install cython
- CIBW_ARCHS: ${{ matrix.cibw_archs }}
-
- - name: Build wheels for macos
- if: runner.os != 'Linux'
- uses: pypa/cibuildwheel@v2.2.2
- env:
- CIBW_BUILD: cp36-* cp37-* cp38-* cp39-* cp310-*
- CIBW_BEFORE_BUILD: pip install cython
- CIBW_ARCHS: ${{ matrix.cibw_archs }}
-
- - name: Upload artifacts
- uses: actions/upload-artifact@v2
- with:
- path: ./wheelhouse/*.whl
-
- build_sdist:
-
- runs-on: ${{ matrix.os }}-latest
- strategy:
- matrix:
- os: [ubuntu, macos]
- python-version: [3.9]
-
- steps:
- - name: Checkout pysam
- uses: actions/checkout@v2
-
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v2
- with:
- python-version: ${{ matrix.python-version }}
-
- - name: Install prerequisite Python libraries
- run: pip install cython pytest pytest-pep8
-
- - name: Install build prerequisites
- if: runner.os == 'Linux'
- run: |
- sudo apt-get update
- sudo apt-get install -q --no-install-recommends --no-install-suggests libcurl4-openssl-dev
-
- - name: Create source distribution
- run: python setup.py sdist
-
- - uses: actions/upload-artifact@v2
- with:
- path: dist/*.tar.gz
-
- upload_pypi:
-
- needs: [build_wheels, build_sdist]
- runs-on: ubuntu-latest
-
- steps:
- - name: Get Artifacts
- uses: actions/download-artifact@v2
- with:
- name: artifact
- path: dist
-
- - name: Publish distribution to Test PyPI
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
- uses: pypa/gh-action-pypi-publish@master
- with:
- user: __token__
- password: ${{ secrets.TEST_PYPI_API_TOKEN }}
- repository_url: https://test.pypi.org/legacy/
-
- - name: Publish distribution to PyPI
- if: github.event_name == 'release' && github.event.action == 'published'
- uses: pypa/gh-action-pypi-publish@master
- with:
- password: ${{ secrets.PYPI_API_TOKEN }}
-
+++ /dev/null
-# editor files
-*~
-*#
-
-# test directory
-tests/pysam/
-tests/tmp*
-tests/*.bam
-tests/*.bai
-tests/*.gz
-tests/*.c
-tests/*.pyxbldc
-tests/*.sam
-tests/*.fai
-tests/pysam_data
-tests/cbcf_data
-tests/tabix_data
-
-samtools/config.h
-samtools/samtools_config_vars.h
-bcftools/config.h
-htslib/config.status
-htslib/config.h
-htslib/config.log
-htslib/config.mk
-htslib/config_vars.h
-htslib/htscodecs.mk
-htslib/htslib.pc.tmp
-htslib/htslib-uninstalled.pc
-pysam/config.py
-
-# linking tests
-BuildRead.c
-# cython files
-pysam/libc*.c
-
-###### Generic python ignores below ######
-
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-
-# C extensions
-*.so
-
-# Distribution / packaging
-.Python
-env/
-bin/
-build/
-develop-eggs/
-dist/
-eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-*.egg-info/
-.installed.cfg
-*.egg
-doc/_build
-
-# Installer logs
-pip-log.txt
-pip-delete-this-directory.txt
-
-# Unit test / coverage reports
-.tox/
-.coverage
-.cache
-nosetests.xml
-coverage.xml
-
-# Translations
-*.mo
-
-# Mr Developer
-.mr.developer.cfg
-.project
-.pydevproject
-
-# Rope
-.ropeproject
-
-# Django stuff:
-*.log
-*.pot
-
-# Sphinx documentation
-docs/_build/
+++ /dev/null
-/* Getopt for GNU.\r
- NOTE: getopt is now part of the C library, so if you don't know what\r
- "Keep this file name-space clean" means, talk to drepper@gnu.org\r
- before changing it!\r
- Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001\r
- Free Software Foundation, Inc.\r
- This file is part of the GNU C Library.\r
-\r
- The GNU C Library is free software; you can redistribute it and/or\r
- modify it under the terms of the GNU Lesser General Public\r
- License as published by the Free Software Foundation; either\r
- version 2.1 of the License, or (at your option) any later version.\r
-\r
- The GNU C Library is distributed in the hope that it will be useful,\r
- but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- Lesser General Public License for more details.\r
-\r
- You should have received a copy of the GNU Lesser General Public\r
- License along with the GNU C Library; if not, write to the Free\r
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
- 02111-1307 USA. */\r
-\r
-/* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>.\r
- Ditto for AIX 3.2 and <stdlib.h>. */\r
-#ifndef _NO_PROTO\r
-# define _NO_PROTO\r
-#endif\r
-\r
-#ifdef HAVE_CONFIG_H\r
-# include <config.h>\r
-#endif\r
-\r
-#if !defined __STDC__ || !__STDC__\r
-/* This is a separate conditional since some stdc systems\r
- reject `defined (const)'. */\r
-# ifndef const\r
-# define const\r
-# endif\r
-#endif\r
-\r
-#include <stdio.h>\r
-\r
-/* Comment out all this code if we are using the GNU C Library, and are not\r
- actually compiling the library itself. This code is part of the GNU C\r
- Library, but also included in many other GNU distributions. Compiling\r
- and linking in this code is a waste when using the GNU C library\r
- (especially if it is a shared library). Rather than having every GNU\r
- program understand `configure --with-gnu-libc' and omit the object files,\r
- it is simpler to just do this in the source for each such file. */\r
-\r
-#define GETOPT_INTERFACE_VERSION 2\r
-#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2\r
-# include <gnu-versions.h>\r
-# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION\r
-# define ELIDE_CODE\r
-# endif\r
-#endif\r
-\r
-#ifndef ELIDE_CODE\r
-\r
-\r
-/* This needs to come after some library #include\r
- to get __GNU_LIBRARY__ defined. */\r
-#ifdef __GNU_LIBRARY__\r
-/* Don't include stdlib.h for non-GNU C libraries because some of them\r
- contain conflicting prototypes for getopt. */\r
-# include <stdlib.h>\r
-# include <unistd.h>\r
-#endif /* GNU C library. */\r
-\r
-#ifdef VMS\r
-# include <unixlib.h>\r
-# if HAVE_STRING_H - 0\r
-# include <string.h>\r
-# endif\r
-#endif\r
-\r
-#ifndef _\r
-/* This is for other GNU distributions with internationalized messages. */\r
-# if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC\r
-# include <libintl.h>\r
-# ifndef _\r
-# define _(msgid) gettext (msgid)\r
-# endif\r
-# else\r
-# define _(msgid) (msgid)\r
-# endif\r
-# if defined _LIBC && defined USE_IN_LIBIO\r
-# include <wchar.h>\r
-# endif\r
-#endif\r
-\r
-/* This version of `getopt' appears to the caller like standard Unix `getopt'\r
- but it behaves differently for the user, since it allows the user\r
- to intersperse the options with the other arguments.\r
-\r
- As `getopt' works, it permutes the elements of ARGV so that,\r
- when it is done, all the options precede everything else. Thus\r
- all application programs are extended to handle flexible argument order.\r
-\r
- Setting the environment variable POSIXLY_CORRECT disables permutation.\r
- Then the behavior is completely standard.\r
-\r
- GNU application programs can use a third alternative mode in which\r
- they can distinguish the relative order of options and other arguments. */\r
-\r
-#include "getopt.h"\r
-\r
-/* For communication from `getopt' to the caller.\r
- When `getopt' finds an option that takes an argument,\r
- the argument value is returned here.\r
- Also, when `ordering' is RETURN_IN_ORDER,\r
- each non-option ARGV-element is returned here. */\r
-\r
-char *optarg;\r
-\r
-/* Index in ARGV of the next element to be scanned.\r
- This is used for communication to and from the caller\r
- and for communication between successive calls to `getopt'.\r
-\r
- On entry to `getopt', zero means this is the first call; initialize.\r
-\r
- When `getopt' returns -1, this is the index of the first of the\r
- non-option elements that the caller should itself scan.\r
-\r
- Otherwise, `optind' communicates from one call to the next\r
- how much of ARGV has been scanned so far. */\r
-\r
-/* 1003.2 says this must be 1 before any call. */\r
-int optind = 1;\r
-\r
-/* Formerly, initialization of getopt depended on optind==0, which\r
- causes problems with re-calling getopt as programs generally don't\r
- know that. */\r
-\r
-int __getopt_initialized;\r
-\r
-/* The next char to be scanned in the option-element\r
- in which the last option character we returned was found.\r
- This allows us to pick up the scan where we left off.\r
-\r
- If this is zero, or a null string, it means resume the scan\r
- by advancing to the next ARGV-element. */\r
-\r
-static char *nextchar;\r
-\r
-/* Callers store zero here to inhibit the error message\r
- for unrecognized options. */\r
-\r
-int opterr = 1;\r
-\r
-/* Set to an option character which was unrecognized.\r
- This must be initialized on some systems to avoid linking in the\r
- system's own getopt implementation. */\r
-\r
-int optopt = '?';\r
-\r
-/* Describe how to deal with options that follow non-option ARGV-elements.\r
-\r
- If the caller did not specify anything,\r
- the default is REQUIRE_ORDER if the environment variable\r
- POSIXLY_CORRECT is defined, PERMUTE otherwise.\r
-\r
- REQUIRE_ORDER means don't recognize them as options;\r
- stop option processing when the first non-option is seen.\r
- This is what Unix does.\r
- This mode of operation is selected by either setting the environment\r
- variable POSIXLY_CORRECT, or using `+' as the first character\r
- of the list of option characters.\r
-\r
- PERMUTE is the default. We permute the contents of ARGV as we scan,\r
- so that eventually all the non-options are at the end. This allows options\r
- to be given in any order, even with programs that were not written to\r
- expect this.\r
-\r
- RETURN_IN_ORDER is an option available to programs that were written\r
- to expect options and other ARGV-elements in any order and that care about\r
- the ordering of the two. We describe each non-option ARGV-element\r
- as if it were the argument of an option with character code 1.\r
- Using `-' as the first character of the list of option characters\r
- selects this mode of operation.\r
-\r
- The special argument `--' forces an end of option-scanning regardless\r
- of the value of `ordering'. In the case of RETURN_IN_ORDER, only\r
- `--' can cause `getopt' to return -1 with `optind' != ARGC. */\r
-\r
-static enum\r
-{\r
- REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER\r
-} ordering;\r
-\r
-/* Value of POSIXLY_CORRECT environment variable. */\r
-static char *posixly_correct;\r
-\r
-#ifdef __GNU_LIBRARY__\r
-/* We want to avoid inclusion of string.h with non-GNU libraries\r
- because there are many ways it can cause trouble.\r
- On some systems, it contains special magic macros that don't work\r
- in GCC. */\r
-# include <string.h>\r
-# define my_index strchr\r
-#else\r
-\r
-/*\r
-# if HAVE_STRING_H || WIN32 /* Pete Wilson mod 7/28/02 * /\r
-# include <string.h>\r
-# else\r
-# include <strings.h>\r
-# endif\r
-*/\r
-\r
-/* Avoid depending on library functions or files\r
- whose names are inconsistent. */\r
-\r
-#ifndef getenv\r
-extern char *getenv ();\r
-#endif\r
-\r
-static char *\r
-my_index (str, chr)\r
- const char *str;\r
- int chr;\r
-{\r
- while (*str)\r
- {\r
- if (*str == chr)\r
- return (char *) str;\r
- str++;\r
- }\r
- return 0;\r
-}\r
-\r
-/* If using GCC, we can safely declare strlen this way.\r
- If not using GCC, it is ok not to declare it. */\r
-#ifdef __GNUC__\r
-/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h.\r
- That was relevant to code that was here before. */\r
-# if (!defined __STDC__ || !__STDC__) && !defined strlen\r
-/* gcc with -traditional declares the built-in strlen to return int,\r
- and has done so at least since version 2.4.5. -- rms. */\r
-extern int strlen (const char *);\r
-# endif /* not __STDC__ */\r
-#endif /* __GNUC__ */\r
-\r
-#endif /* not __GNU_LIBRARY__ */\r
-\r
-/* Handle permutation of arguments. */\r
-\r
-/* Describe the part of ARGV that contains non-options that have\r
- been skipped. `first_nonopt' is the index in ARGV of the first of them;\r
- `last_nonopt' is the index after the last of them. */\r
-\r
-static int first_nonopt;\r
-static int last_nonopt;\r
-\r
-#ifdef _LIBC\r
-/* Stored original parameters.\r
- XXX This is no good solution. We should rather copy the args so\r
- that we can compare them later. But we must not use malloc(3). */\r
-extern int __libc_argc;\r
-extern char **__libc_argv;\r
-\r
-/* Bash 2.0 gives us an environment variable containing flags\r
- indicating ARGV elements that should not be considered arguments. */\r
-\r
-# ifdef USE_NONOPTION_FLAGS\r
-/* Defined in getopt_init.c */\r
-extern char *__getopt_nonoption_flags;\r
-\r
-static int nonoption_flags_max_len;\r
-static int nonoption_flags_len;\r
-# endif\r
-\r
-# ifdef USE_NONOPTION_FLAGS\r
-# define SWAP_FLAGS(ch1, ch2) \\r
- if (nonoption_flags_len > 0) \\r
- { \\r
- char __tmp = __getopt_nonoption_flags[ch1]; \\r
- __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \\r
- __getopt_nonoption_flags[ch2] = __tmp; \\r
- }\r
-# else\r
-# define SWAP_FLAGS(ch1, ch2)\r
-# endif\r
-#else /* !_LIBC */\r
-# define SWAP_FLAGS(ch1, ch2)\r
-#endif /* _LIBC */\r
-\r
-/* Exchange two adjacent subsequences of ARGV.\r
- One subsequence is elements [first_nonopt,last_nonopt)\r
- which contains all the non-options that have been skipped so far.\r
- The other is elements [last_nonopt,optind), which contains all\r
- the options processed since those non-options were skipped.\r
-\r
- `first_nonopt' and `last_nonopt' are relocated so that they describe\r
- the new indices of the non-options in ARGV after they are moved. */\r
-\r
-#if defined __STDC__ && __STDC__\r
-static void exchange (char **);\r
-#endif\r
-\r
-static void\r
-exchange (argv)\r
- char **argv;\r
-{\r
- int bottom = first_nonopt;\r
- int middle = last_nonopt;\r
- int top = optind;\r
- char *tem;\r
-\r
- /* Exchange the shorter segment with the far end of the longer segment.\r
- That puts the shorter segment into the right place.\r
- It leaves the longer segment in the right place overall,\r
- but it consists of two parts that need to be swapped next. */\r
-\r
-#if defined _LIBC && defined USE_NONOPTION_FLAGS\r
- /* First make sure the handling of the `__getopt_nonoption_flags'\r
- string can work normally. Our top argument must be in the range\r
- of the string. */\r
- if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)\r
- {\r
- /* We must extend the array. The user plays games with us and\r
- presents new arguments. */\r
- char *new_str = malloc (top + 1);\r
- if (new_str == NULL)\r
- nonoption_flags_len = nonoption_flags_max_len = 0;\r
- else\r
- {\r
- memset (__mempcpy (new_str, __getopt_nonoption_flags,\r
- nonoption_flags_max_len),\r
- '\0', top + 1 - nonoption_flags_max_len);\r
- nonoption_flags_max_len = top + 1;\r
- __getopt_nonoption_flags = new_str;\r
- }\r
- }\r
-#endif\r
-\r
- while (top > middle && middle > bottom)\r
- {\r
- if (top - middle > middle - bottom)\r
- {\r
- /* Bottom segment is the short one. */\r
- int len = middle - bottom;\r
- register int i;\r
-\r
- /* Swap it with the top part of the top segment. */\r
- for (i = 0; i < len; i++)\r
- {\r
- tem = argv[bottom + i];\r
- argv[bottom + i] = argv[top - (middle - bottom) + i];\r
- argv[top - (middle - bottom) + i] = tem;\r
- SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);\r
- }\r
- /* Exclude the moved bottom segment from further swapping. */\r
- top -= len;\r
- }\r
- else\r
- {\r
- /* Top segment is the short one. */\r
- int len = top - middle;\r
- register int i;\r
-\r
- /* Swap it with the bottom part of the bottom segment. */\r
- for (i = 0; i < len; i++)\r
- {\r
- tem = argv[bottom + i];\r
- argv[bottom + i] = argv[middle + i];\r
- argv[middle + i] = tem;\r
- SWAP_FLAGS (bottom + i, middle + i);\r
- }\r
- /* Exclude the moved top segment from further swapping. */\r
- bottom += len;\r
- }\r
- }\r
-\r
- /* Update records for the slots the non-options now occupy. */\r
-\r
- first_nonopt += (optind - last_nonopt);\r
- last_nonopt = optind;\r
-}\r
-\r
-/* Initialize the internal data when the first call is made. */\r
-\r
-#if defined __STDC__ && __STDC__\r
-static const char *_getopt_initialize (int, char *const *, const char *);\r
-#endif\r
-static const char *\r
-_getopt_initialize (argc, argv, optstring)\r
- int argc;\r
- char *const *argv;\r
- const char *optstring;\r
-{\r
- /* Start processing options with ARGV-element 1 (since ARGV-element 0\r
- is the program name); the sequence of previously skipped\r
- non-option ARGV-elements is empty. */\r
-\r
- first_nonopt = last_nonopt = optind;\r
-\r
- nextchar = NULL;\r
-\r
- posixly_correct = getenv ("POSIXLY_CORRECT");\r
-\r
- /* Determine how to handle the ordering of options and nonoptions. */\r
-\r
- if (optstring[0] == '-')\r
- {\r
- ordering = RETURN_IN_ORDER;\r
- ++optstring;\r
- }\r
- else if (optstring[0] == '+')\r
- {\r
- ordering = REQUIRE_ORDER;\r
- ++optstring;\r
- }\r
- else if (posixly_correct != NULL)\r
- ordering = REQUIRE_ORDER;\r
- else\r
- ordering = PERMUTE;\r
-\r
-#if defined _LIBC && defined USE_NONOPTION_FLAGS\r
- if (posixly_correct == NULL\r
- && argc == __libc_argc && argv == __libc_argv)\r
- {\r
- if (nonoption_flags_max_len == 0)\r
- {\r
- if (__getopt_nonoption_flags == NULL\r
- || __getopt_nonoption_flags[0] == '\0')\r
- nonoption_flags_max_len = -1;\r
- else\r
- {\r
- const char *orig_str = __getopt_nonoption_flags;\r
- int len = nonoption_flags_max_len = strlen (orig_str);\r
- if (nonoption_flags_max_len < argc)\r
- nonoption_flags_max_len = argc;\r
- __getopt_nonoption_flags =\r
- (char *) malloc (nonoption_flags_max_len);\r
- if (__getopt_nonoption_flags == NULL)\r
- nonoption_flags_max_len = -1;\r
- else\r
- memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),\r
- '\0', nonoption_flags_max_len - len);\r
- }\r
- }\r
- nonoption_flags_len = nonoption_flags_max_len;\r
- }\r
- else\r
- nonoption_flags_len = 0;\r
-#endif\r
-\r
- return optstring;\r
-}\r
-\r
-/* Scan elements of ARGV (whose length is ARGC) for option characters\r
- given in OPTSTRING.\r
-\r
- If an element of ARGV starts with '-', and is not exactly "-" or "--",\r
- then it is an option element. The characters of this element\r
- (aside from the initial '-') are option characters. If `getopt'\r
- is called repeatedly, it returns successively each of the option characters\r
- from each of the option elements.\r
-\r
- If `getopt' finds another option character, it returns that character,\r
- updating `optind' and `nextchar' so that the next call to `getopt' can\r
- resume the scan with the following option character or ARGV-element.\r
-\r
- If there are no more option characters, `getopt' returns -1.\r
- Then `optind' is the index in ARGV of the first ARGV-element\r
- that is not an option. (The ARGV-elements have been permuted\r
- so that those that are not options now come last.)\r
-\r
- OPTSTRING is a string containing the legitimate option characters.\r
- If an option character is seen that is not listed in OPTSTRING,\r
- return '?' after printing an error message. If you set `opterr' to\r
- zero, the error message is suppressed but we still return '?'.\r
-\r
- If a char in OPTSTRING is followed by a colon, that means it wants an arg,\r
- so the following text in the same ARGV-element, or the text of the following\r
- ARGV-element, is returned in `optarg'. Two colons mean an option that\r
- wants an optional arg; if there is text in the current ARGV-element,\r
- it is returned in `optarg', otherwise `optarg' is set to zero.\r
-\r
- If OPTSTRING starts with `-' or `+', it requests different methods of\r
- handling the non-option ARGV-elements.\r
- See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.\r
-\r
- Long-named options begin with `--' instead of `-'.\r
- Their names may be abbreviated as long as the abbreviation is unique\r
- or is an exact match for some defined option. If they have an\r
- argument, it follows the option name in the same ARGV-element, separated\r
- from the option name by a `=', or else the in next ARGV-element.\r
- When `getopt' finds a long-named option, it returns 0 if that option's\r
- `flag' field is nonzero, the value of the option's `val' field\r
- if the `flag' field is zero.\r
-\r
- The elements of ARGV aren't really const, because we permute them.\r
- But we pretend they're const in the prototype to be compatible\r
- with other systems.\r
-\r
- LONGOPTS is a vector of `struct option' terminated by an\r
- element containing a name which is zero.\r
-\r
- LONGIND returns the index in LONGOPT of the long-named option found.\r
- It is only valid when a long-named option has been found by the most\r
- recent call.\r
-\r
- If LONG_ONLY is nonzero, '-' as well as '--' can introduce\r
- long-named options. */\r
-\r
-int\r
-_getopt_internal (argc, argv, optstring, longopts, longind, long_only)\r
- int argc;\r
- char *const *argv;\r
- const char *optstring;\r
- const struct option *longopts;\r
- int *longind;\r
- int long_only;\r
-{\r
- int print_errors = opterr;\r
- if (optstring[0] == ':')\r
- print_errors = 0;\r
-\r
- if (argc < 1)\r
- return -1;\r
-\r
- optarg = NULL;\r
-\r
- if (optind == 0 || !__getopt_initialized)\r
- {\r
- if (optind == 0)\r
- optind = 1; /* Don't scan ARGV[0], the program name. */\r
- optstring = _getopt_initialize (argc, argv, optstring);\r
- __getopt_initialized = 1;\r
- }\r
-\r
- /* Test whether ARGV[optind] points to a non-option argument.\r
- Either it does not have option syntax, or there is an environment flag\r
- from the shell indicating it is not an option. The later information\r
- is only used when the used in the GNU libc. */\r
-#if defined _LIBC && defined USE_NONOPTION_FLAGS\r
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \\r
- || (optind < nonoption_flags_len \\r
- && __getopt_nonoption_flags[optind] == '1'))\r
-#else\r
-# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0')\r
-#endif\r
-\r
- if (nextchar == NULL || *nextchar == '\0')\r
- {\r
- /* Advance to the next ARGV-element. */\r
-\r
- /* Give FIRST_NONOPT and LAST_NONOPT rational values if OPTIND has been\r
- moved back by the user (who may also have changed the arguments). */\r
- if (last_nonopt > optind)\r
- last_nonopt = optind;\r
- if (first_nonopt > optind)\r
- first_nonopt = optind;\r
-\r
- if (ordering == PERMUTE)\r
- {\r
- /* If we have just processed some options following some non-options,\r
- exchange them so that the options come first. */\r
-\r
- if (first_nonopt != last_nonopt && last_nonopt != optind)\r
- exchange ((char **) argv);\r
- else if (last_nonopt != optind)\r
- first_nonopt = optind;\r
-\r
- /* Skip any additional non-options\r
- and extend the range of non-options previously skipped. */\r
-\r
- while (optind < argc && NONOPTION_P)\r
- optind++;\r
- last_nonopt = optind;\r
- }\r
-\r
- /* The special ARGV-element `--' means premature end of options.\r
- Skip it like a null option,\r
- then exchange with previous non-options as if it were an option,\r
- then skip everything else like a non-option. */\r
-\r
- if (optind != argc && !strcmp (argv[optind], "--"))\r
- {\r
- optind++;\r
-\r
- if (first_nonopt != last_nonopt && last_nonopt != optind)\r
- exchange ((char **) argv);\r
- else if (first_nonopt == last_nonopt)\r
- first_nonopt = optind;\r
- last_nonopt = argc;\r
-\r
- optind = argc;\r
- }\r
-\r
- /* If we have done all the ARGV-elements, stop the scan\r
- and back over any non-options that we skipped and permuted. */\r
-\r
- if (optind == argc)\r
- {\r
- /* Set the next-arg-index to point at the non-options\r
- that we previously skipped, so the caller will digest them. */\r
- if (first_nonopt != last_nonopt)\r
- optind = first_nonopt;\r
- return -1;\r
- }\r
-\r
- /* If we have come to a non-option and did not permute it,\r
- either stop the scan or describe it to the caller and pass it by. */\r
-\r
- if (NONOPTION_P)\r
- {\r
- if (ordering == REQUIRE_ORDER)\r
- return -1;\r
- optarg = argv[optind++];\r
- return 1;\r
- }\r
-\r
- /* We have found another option-ARGV-element.\r
- Skip the initial punctuation. */\r
-\r
- nextchar = (argv[optind] + 1\r
- + (longopts != NULL && argv[optind][1] == '-'));\r
- }\r
-\r
- /* Decode the current option-ARGV-element. */\r
-\r
- /* Check whether the ARGV-element is a long option.\r
-\r
- If long_only and the ARGV-element has the form "-f", where f is\r
- a valid short option, don't consider it an abbreviated form of\r
- a long option that starts with f. Otherwise there would be no\r
- way to give the -f short option.\r
-\r
- On the other hand, if there's a long option "fubar" and\r
- the ARGV-element is "-fu", do consider that an abbreviation of\r
- the long option, just like "--fu", and not "-f" with arg "u".\r
-\r
- This distinction seems to be the most useful approach. */\r
-\r
- if (longopts != NULL\r
- && (argv[optind][1] == '-'\r
- || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1])))))\r
- {\r
- char *nameend;\r
- const struct option *p;\r
- const struct option *pfound = NULL;\r
- int exact = 0;\r
- int ambig = 0;\r
- int indfound = -1;\r
- int option_index;\r
-\r
- for (nameend = nextchar; *nameend && *nameend != '='; nameend++)\r
- /* Do nothing. */ ;\r
-\r
- /* Test all long options for either exact match\r
- or abbreviated matches. */\r
- for (p = longopts, option_index = 0; p->name; p++, option_index++)\r
- if (!strncmp (p->name, nextchar, nameend - nextchar))\r
- {\r
- if ((unsigned int) (nameend - nextchar)\r
- == (unsigned int) strlen (p->name))\r
- {\r
- /* Exact match found. */\r
- pfound = p;\r
- indfound = option_index;\r
- exact = 1;\r
- break;\r
- }\r
- else if (pfound == NULL)\r
- {\r
- /* First nonexact match found. */\r
- pfound = p;\r
- indfound = option_index;\r
- }\r
- else if (long_only\r
- || pfound->has_arg != p->has_arg\r
- || pfound->flag != p->flag\r
- || pfound->val != p->val)\r
- /* Second or later nonexact match found. */\r
- ambig = 1;\r
- }\r
-\r
- if (ambig && !exact)\r
- {\r
- if (print_errors)\r
- {\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-\r
- __asprintf (&buf, _("%s: option `%s' is ambiguous\n"),\r
- argv[0], argv[optind]);\r
-\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#else\r
- fprintf (stderr, _("%s: option `%s' is ambiguous\n"),\r
- argv[0], argv[optind]);\r
-#endif\r
- }\r
- nextchar += strlen (nextchar);\r
- optind++;\r
- optopt = 0;\r
- return '?';\r
- }\r
-\r
- if (pfound != NULL)\r
- {\r
- option_index = indfound;\r
- optind++;\r
- if (*nameend)\r
- {\r
- /* Don't test has_arg with >, because some C compilers don't\r
- allow it to be used on enums. */\r
- if (pfound->has_arg)\r
- optarg = nameend + 1;\r
- else\r
- {\r
- if (print_errors)\r
- {\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-#endif\r
-\r
- if (argv[optind - 1][1] == '-')\r
- {\r
- /* --option */\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- __asprintf (&buf, _("\\r
-%s: option `--%s' doesn't allow an argument\n"),\r
- argv[0], pfound->name);\r
-#else\r
- fprintf (stderr, _("\\r
-%s: option `--%s' doesn't allow an argument\n"),\r
- argv[0], pfound->name);\r
-#endif\r
- }\r
- else\r
- {\r
- /* +option or -option */\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- __asprintf (&buf, _("\\r
-%s: option `%c%s' doesn't allow an argument\n"),\r
- argv[0], argv[optind - 1][0],\r
- pfound->name);\r
-#else\r
- fprintf (stderr, _("\\r
-%s: option `%c%s' doesn't allow an argument\n"),\r
- argv[0], argv[optind - 1][0], pfound->name);\r
-#endif\r
- }\r
-\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#endif\r
- }\r
-\r
- nextchar += strlen (nextchar);\r
-\r
- optopt = pfound->val;\r
- return '?';\r
- }\r
- }\r
- else if (pfound->has_arg == 1)\r
- {\r
- if (optind < argc)\r
- optarg = argv[optind++];\r
- else\r
- {\r
- if (print_errors)\r
- {\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-\r
- __asprintf (&buf,\r
- _("%s: option `%s' requires an argument\n"),\r
- argv[0], argv[optind - 1]);\r
-\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#else\r
- fprintf (stderr,\r
- _("%s: option `%s' requires an argument\n"),\r
- argv[0], argv[optind - 1]);\r
-#endif\r
- }\r
- nextchar += strlen (nextchar);\r
- optopt = pfound->val;\r
- return optstring[0] == ':' ? ':' : '?';\r
- }\r
- }\r
- nextchar += strlen (nextchar);\r
- if (longind != NULL)\r
- *longind = option_index;\r
- if (pfound->flag)\r
- {\r
- *(pfound->flag) = pfound->val;\r
- return 0;\r
- }\r
- return pfound->val;\r
- }\r
-\r
- /* Can't find it as a long option. If this is not getopt_long_only,\r
- or the option starts with '--' or is not a valid short\r
- option, then it's an error.\r
- Otherwise interpret it as a short option. */\r
- if (!long_only || argv[optind][1] == '-'\r
- || my_index (optstring, *nextchar) == NULL)\r
- {\r
- if (print_errors)\r
- {\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-#endif\r
-\r
- if (argv[optind][1] == '-')\r
- {\r
- /* --option */\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- __asprintf (&buf, _("%s: unrecognized option `--%s'\n"),\r
- argv[0], nextchar);\r
-#else\r
- fprintf (stderr, _("%s: unrecognized option `--%s'\n"),\r
- argv[0], nextchar);\r
-#endif\r
- }\r
- else\r
- {\r
- /* +option or -option */\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"),\r
- argv[0], argv[optind][0], nextchar);\r
-#else\r
- fprintf (stderr, _("%s: unrecognized option `%c%s'\n"),\r
- argv[0], argv[optind][0], nextchar);\r
-#endif\r
- }\r
-\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#endif\r
- }\r
- nextchar = (char *) "";\r
- optind++;\r
- optopt = 0;\r
- return '?';\r
- }\r
- }\r
-\r
- /* Look at and handle the next short option-character. */\r
-\r
- {\r
- char c = *nextchar++;\r
- char *temp = my_index (optstring, c);\r
-\r
- /* Increment `optind' when we start to process its last character. */\r
- if (*nextchar == '\0')\r
- ++optind;\r
-\r
- if (temp == NULL || c == ':')\r
- {\r
- if (print_errors)\r
- {\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-#endif\r
-\r
- if (posixly_correct)\r
- {\r
- /* 1003.2 specifies the format of this message. */\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- __asprintf (&buf, _("%s: illegal option -- %c\n"),\r
- argv[0], c);\r
-#else\r
- fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c);\r
-#endif\r
- }\r
- else\r
- {\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- __asprintf (&buf, _("%s: invalid option -- %c\n"),\r
- argv[0], c);\r
-#else\r
- fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c);\r
-#endif\r
- }\r
-\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#endif\r
- }\r
- optopt = c;\r
- return '?';\r
- }\r
- /* Convenience. Treat POSIX -W foo same as long option --foo */\r
- if (temp[0] == 'W' && temp[1] == ';')\r
- {\r
- char *nameend;\r
- const struct option *p;\r
- const struct option *pfound = NULL;\r
- int exact = 0;\r
- int ambig = 0;\r
- int indfound = 0;\r
- int option_index;\r
-\r
- /* This is an option that requires an argument. */\r
- if (*nextchar != '\0')\r
- {\r
- optarg = nextchar;\r
- /* If we end this ARGV-element by taking the rest as an arg,\r
- we must advance to the next element now. */\r
- optind++;\r
- }\r
- else if (optind == argc)\r
- {\r
- if (print_errors)\r
- {\r
- /* 1003.2 specifies the format of this message. */\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-\r
- __asprintf (&buf, _("%s: option requires an argument -- %c\n"),\r
- argv[0], c);\r
-\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#else\r
- fprintf (stderr, _("%s: option requires an argument -- %c\n"),\r
- argv[0], c);\r
-#endif\r
- }\r
- optopt = c;\r
- if (optstring[0] == ':')\r
- c = ':';\r
- else\r
- c = '?';\r
- return c;\r
- }\r
- else\r
- /* We already incremented `optind' once;\r
- increment it again when taking next ARGV-elt as argument. */\r
- optarg = argv[optind++];\r
-\r
- /* optarg is now the argument, see if it's in the\r
- table of longopts. */\r
-\r
- for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++)\r
- /* Do nothing. */ ;\r
-\r
- /* Test all long options for either exact match\r
- or abbreviated matches. */\r
- for (p = longopts, option_index = 0; p->name; p++, option_index++)\r
- if (!strncmp (p->name, nextchar, nameend - nextchar))\r
- {\r
- if ((unsigned int) (nameend - nextchar) == strlen (p->name))\r
- {\r
- /* Exact match found. */\r
- pfound = p;\r
- indfound = option_index;\r
- exact = 1;\r
- break;\r
- }\r
- else if (pfound == NULL)\r
- {\r
- /* First nonexact match found. */\r
- pfound = p;\r
- indfound = option_index;\r
- }\r
- else\r
- /* Second or later nonexact match found. */\r
- ambig = 1;\r
- }\r
- if (ambig && !exact)\r
- {\r
- if (print_errors)\r
- {\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-\r
- __asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"),\r
- argv[0], argv[optind]);\r
-\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#else\r
- fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"),\r
- argv[0], argv[optind]);\r
-#endif\r
- }\r
- nextchar += strlen (nextchar);\r
- optind++;\r
- return '?';\r
- }\r
- if (pfound != NULL)\r
- {\r
- option_index = indfound;\r
- if (*nameend)\r
- {\r
- /* Don't test has_arg with >, because some C compilers don't\r
- allow it to be used on enums. */\r
- if (pfound->has_arg)\r
- optarg = nameend + 1;\r
- else\r
- {\r
- if (print_errors)\r
- {\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-\r
- __asprintf (&buf, _("\\r
-%s: option `-W %s' doesn't allow an argument\n"),\r
- argv[0], pfound->name);\r
-\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#else\r
- fprintf (stderr, _("\\r
-%s: option `-W %s' doesn't allow an argument\n"),\r
- argv[0], pfound->name);\r
-#endif\r
- }\r
-\r
- nextchar += strlen (nextchar);\r
- return '?';\r
- }\r
- }\r
- else if (pfound->has_arg == 1)\r
- {\r
- if (optind < argc)\r
- optarg = argv[optind++];\r
- else\r
- {\r
- if (print_errors)\r
- {\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-\r
- __asprintf (&buf, _("\\r
-%s: option `%s' requires an argument\n"),\r
- argv[0], argv[optind - 1]);\r
-\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#else\r
- fprintf (stderr,\r
- _("%s: option `%s' requires an argument\n"),\r
- argv[0], argv[optind - 1]);\r
-#endif\r
- }\r
- nextchar += strlen (nextchar);\r
- return optstring[0] == ':' ? ':' : '?';\r
- }\r
- }\r
- nextchar += strlen (nextchar);\r
- if (longind != NULL)\r
- *longind = option_index;\r
- if (pfound->flag)\r
- {\r
- *(pfound->flag) = pfound->val;\r
- return 0;\r
- }\r
- return pfound->val;\r
- }\r
- nextchar = NULL;\r
- return 'W'; /* Let the application handle it. */\r
- }\r
- if (temp[1] == ':')\r
- {\r
- if (temp[2] == ':')\r
- {\r
- /* This is an option that accepts an argument optionally. */\r
- if (*nextchar != '\0')\r
- {\r
- optarg = nextchar;\r
- optind++;\r
- }\r
- else\r
- optarg = NULL;\r
- nextchar = NULL;\r
- }\r
- else\r
- {\r
- /* This is an option that requires an argument. */\r
- if (*nextchar != '\0')\r
- {\r
- optarg = nextchar;\r
- /* If we end this ARGV-element by taking the rest as an arg,\r
- we must advance to the next element now. */\r
- optind++;\r
- }\r
- else if (optind == argc)\r
- {\r
- if (print_errors)\r
- {\r
- /* 1003.2 specifies the format of this message. */\r
-#if defined _LIBC && defined USE_IN_LIBIO\r
- char *buf;\r
-\r
- __asprintf (&buf,\r
- _("%s: option requires an argument -- %c\n"),\r
- argv[0], c);\r
-\r
- if (_IO_fwide (stderr, 0) > 0)\r
- __fwprintf (stderr, L"%s", buf);\r
- else\r
- fputs (buf, stderr);\r
-\r
- free (buf);\r
-#else\r
- fprintf (stderr,\r
- _("%s: option requires an argument -- %c\n"),\r
- argv[0], c);\r
-#endif\r
- }\r
- optopt = c;\r
- if (optstring[0] == ':')\r
- c = ':';\r
- else\r
- c = '?';\r
- }\r
- else\r
- /* We already incremented `optind' once;\r
- increment it again when taking next ARGV-elt as argument. */\r
- optarg = argv[optind++];\r
- nextchar = NULL;\r
- }\r
- }\r
- return c;\r
- }\r
-}\r
-\r
-int\r
-getopt (argc, argv, optstring)\r
- int argc;\r
- char *const *argv;\r
- const char *optstring;\r
-{\r
- return _getopt_internal (argc, argv, optstring,\r
- (const struct option *) 0,\r
- (int *) 0,\r
- 0);\r
-}\r
-\r
-#endif /* Not ELIDE_CODE. */\r
-\r
-\r
-/* Compile with -DTEST to make an executable for use in testing\r
- the above definition of `getopt'. */\r
-\r
-/* #define TEST */ /* Pete Wilson mod 7/28/02 */\r
-#ifdef TEST\r
-\r
-#ifndef exit /* Pete Wilson mod 7/28/02 */\r
- int exit(int); /* Pete Wilson mod 7/28/02 */\r
-#endif /* Pete Wilson mod 7/28/02 */\r
-\r
-int\r
-main (argc, argv)\r
- int argc;\r
- char **argv;\r
-{\r
- int c;\r
- int digit_optind = 0;\r
-\r
- while (1)\r
- {\r
- int this_option_optind = optind ? optind : 1;\r
-\r
- c = getopt (argc, argv, "abc:d:0123456789");\r
- if (c == -1)\r
- break;\r
-\r
- switch (c)\r
- {\r
- case '0':\r
- case '1':\r
- case '2':\r
- case '3':\r
- case '4':\r
- case '5':\r
- case '6':\r
- case '7':\r
- case '8':\r
- case '9':\r
- if (digit_optind != 0 && digit_optind != this_option_optind)\r
- printf ("digits occur in two different argv-elements.\n");\r
- digit_optind = this_option_optind;\r
- printf ("option %c\n", c);\r
- break;\r
-\r
- case 'a':\r
- printf ("option a\n");\r
- break;\r
-\r
- case 'b':\r
- printf ("option b\n");\r
- break;\r
-\r
- case 'c':\r
- printf ("option c with value `%s'\n", optarg);\r
- break;\r
-\r
- case '?':\r
- break;\r
-\r
- default:\r
- printf ("?? getopt returned character code 0%o ??\n", c);\r
- }\r
- }\r
-\r
- if (optind < argc)\r
- {\r
- printf ("non-option ARGV-elements: ");\r
- while (optind < argc)\r
- printf ("%s ", argv[optind++]);\r
- printf ("\n");\r
- }\r
-\r
- exit (0);\r
-}\r
-\r
-#endif /* TEST */\r
-\r
+++ /dev/null
-/* getopt.h */\r
-/* Declarations for getopt.\r
- Copyright (C) 1989-1994, 1996-1999, 2001 Free Software \r
- Foundation, Inc. This file is part of the GNU C Library.\r
-\r
- The GNU C Library is free software; you can redistribute \r
- it and/or modify it under the terms of the GNU Lesser \r
- General Public License as published by the Free Software \r
- Foundation; either version 2.1 of the License, or \r
- (at your option) any later version.\r
-\r
- The GNU C Library is distributed in the hope that it will \r
- be useful, but WITHOUT ANY WARRANTY; without even the \r
- implied warranty of MERCHANTABILITY or FITNESS FOR A \r
- PARTICULAR PURPOSE. See the GNU Lesser General Public \r
- License for more details.\r
-\r
- You should have received a copy of the GNU Lesser General \r
- Public License along with the GNU C Library; if not, write \r
- to the Free Software Foundation, Inc., 59 Temple Place,\r
- Suite 330, Boston, MA 02111-1307 USA. */\r
-\r
- \r
- \r
-\r
-#ifndef _GETOPT_H\r
-\r
-#ifndef __need_getopt\r
-# define _GETOPT_H 1\r
-#endif\r
-\r
-/* If __GNU_LIBRARY__ is not already defined, either we are being used\r
- standalone, or this is the first header included in the source file.\r
- If we are being used with glibc, we need to include <features.h>, but\r
- that does not exist if we are standalone. So: if __GNU_LIBRARY__ is\r
- not defined, include <ctype.h>, which will pull in <features.h> for us\r
- if it's from glibc. (Why ctype.h? It's guaranteed to exist and it\r
- doesn't flood the namespace with stuff the way some other headers do.) */\r
-#if !defined __GNU_LIBRARY__\r
-# include <ctype.h>\r
-#endif\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-/* For communication from `getopt' to the caller.\r
- When `getopt' finds an option that takes an argument,\r
- the argument value is returned here.\r
- Also, when `ordering' is RETURN_IN_ORDER,\r
- each non-option ARGV-element is returned here. */\r
-\r
-extern char *optarg;\r
-\r
-/* Index in ARGV of the next element to be scanned.\r
- This is used for communication to and from the caller\r
- and for communication between successive calls to `getopt'.\r
-\r
- On entry to `getopt', zero means this is the first call; initialize.\r
-\r
- When `getopt' returns -1, this is the index of the first of the\r
- non-option elements that the caller should itself scan.\r
-\r
- Otherwise, `optind' communicates from one call to the next\r
- how much of ARGV has been scanned so far. */\r
-\r
-extern int optind;\r
-\r
-/* Callers store zero here to inhibit the error message `getopt' prints\r
- for unrecognized options. */\r
-\r
-extern int opterr;\r
-\r
-/* Set to an option character which was unrecognized. */\r
-\r
-extern int optopt;\r
-\r
-#ifndef __need_getopt\r
-/* Describe the long-named options requested by the application.\r
- The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector\r
- of `struct option' terminated by an element containing a name which is\r
- zero.\r
-\r
- The field `has_arg' is:\r
- no_argument (or 0) if the option does not take an argument,\r
- required_argument (or 1) if the option requires an argument,\r
- optional_argument (or 2) if the option takes an optional argument.\r
-\r
- If the field `flag' is not NULL, it points to a variable that is set\r
- to the value given in the field `val' when the option is found, but\r
- left unchanged if the option is not found.\r
-\r
- To have a long-named option do something other than set an `int' to\r
- a compiled-in constant, such as set a value from `optarg', set the\r
- option's `flag' field to zero and its `val' field to a nonzero\r
- value (the equivalent single-letter option character, if there is\r
- one). For long options that have a zero `flag' field, `getopt'\r
- returns the contents of the `val' field. */\r
-\r
-struct option\r
-{\r
-# if (defined __STDC__ && __STDC__) || defined __cplusplus\r
- const char *name;\r
-# else\r
- char *name;\r
-# endif\r
- /* has_arg can't be an enum because some compilers complain about\r
- type mismatches in all the code that assumes it is an int. */\r
- int has_arg;\r
- int *flag;\r
- int val;\r
-};\r
-\r
-/* Names for the values of the `has_arg' field of `struct option'. */\r
-\r
-# define no_argument 0\r
-# define required_argument 1\r
-# define optional_argument 2\r
-#endif /* need getopt */\r
-\r
-\r
-/* Get definitions and prototypes for functions to process the\r
- arguments in ARGV (ARGC of them, minus the program name) for\r
- options given in OPTS.\r
-\r
- Return the option character from OPTS just read. Return -1 when\r
- there are no more options. For unrecognized options, or options\r
- missing arguments, `optopt' is set to the option letter, and '?' is\r
- returned.\r
-\r
- The OPTS string is a list of characters which are recognized option\r
- letters, optionally followed by colons, specifying that that letter\r
- takes an argument, to be placed in `optarg'.\r
-\r
- If a letter in OPTS is followed by two colons, its argument is\r
- optional. This behavior is specific to the GNU `getopt'.\r
-\r
- The argument `--' causes premature termination of argument\r
- scanning, explicitly telling `getopt' that there are no more\r
- options.\r
-\r
- If OPTS begins with `--', then non-option arguments are treated as\r
- arguments to the option '\0'. This behavior is specific to the GNU\r
- `getopt'. */\r
-\r
-#if (defined __STDC__ && __STDC__) || defined __cplusplus\r
-# ifdef __GNU_LIBRARY__\r
-/* Many other libraries have conflicting prototypes for getopt, with\r
- differences in the consts, in stdlib.h. To avoid compilation\r
- errors, only prototype getopt for the GNU C library. */\r
-extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);\r
-# else /* not __GNU_LIBRARY__ */\r
-extern int getopt ();\r
-# endif /* __GNU_LIBRARY__ */\r
-\r
-# ifndef __need_getopt\r
-extern int getopt_long (int ___argc, char *const *___argv,\r
- const char *__shortopts,\r
- const struct option *__longopts, int *__longind);\r
-extern int getopt_long_only (int ___argc, char *const *___argv,\r
- const char *__shortopts,\r
- const struct option *__longopts, int *__longind);\r
-\r
-/* Internal only. Users should not call this directly. */\r
-extern int _getopt_internal (int ___argc, char *const *___argv,\r
- const char *__shortopts,\r
- const struct option *__longopts, int *__longind,\r
- int __long_only);\r
-# endif\r
-#else /* not __STDC__ */\r
-extern int getopt ();\r
-# ifndef __need_getopt\r
-extern int getopt_long ();\r
-extern int getopt_long_only ();\r
-\r
-extern int _getopt_internal ();\r
-# endif\r
-#endif /* __STDC__ */\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-/* Make sure we later can get all the definitions and declarations. */\r
-#undef __need_getopt\r
-\r
-#endif /* getopt.h */\r
+++ /dev/null
-/* A portable stdint.h\r
- ****************************************************************************\r
- * BSD License:\r
- ****************************************************************************\r
- *\r
- * Copyright (c) 2005-2007 Paul Hsieh\r
- * All rights reserved.\r
- * \r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * \r
- * 1. Redistributions of source code must retain the above copyright\r
- * notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- * notice, this list of conditions and the following disclaimer in the\r
- * documentation and/or other materials provided with the distribution.\r
- * 3. The name of the author may not be used to endorse or promote products\r
- * derived from this software without specific prior written permission.\r
- * \r
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
- *\r
- ****************************************************************************\r
- *\r
- * Version 0.1.11\r
- *\r
- * The ANSI C standard committee, for the C99 standard, specified the\r
- * inclusion of a new standard include file called stdint.h. This is\r
- * a very useful and long desired include file which contains several\r
- * very precise definitions for integer scalar types that is\r
- * critically important for making portable several classes of\r
- * applications including cryptography, hashing, variable length\r
- * integer libraries and so on. But for most developers its likely\r
- * useful just for programming sanity.\r
- *\r
- * The problem is that most compiler vendors have decided not to\r
- * implement the C99 standard, and the next C++ language standard\r
- * (which has a lot more mindshare these days) will be a long time in\r
- * coming and its unknown whether or not it will include stdint.h or\r
- * how much adoption it will have. Either way, it will be a long time\r
- * before all compilers come with a stdint.h and it also does nothing\r
- * for the extremely large number of compilers available today which\r
- * do not include this file, or anything comparable to it.\r
- *\r
- * So that's what this file is all about. Its an attempt to build a\r
- * single universal include file that works on as many platforms as\r
- * possible to deliver what stdint.h is supposed to. A few things\r
- * that should be noted about this file:\r
- *\r
- * 1) It is not guaranteed to be portable and/or present an identical\r
- * interface on all platforms. The extreme variability of the\r
- * ANSI C standard makes this an impossibility right from the\r
- * very get go. Its really only meant to be useful for the vast\r
- * majority of platforms that possess the capability of\r
- * implementing usefully and precisely defined, standard sized\r
- * integer scalars. Systems which are not intrinsically 2s\r
- * complement may produce invalid constants.\r
- *\r
- * 2) There is an unavoidable use of non-reserved symbols.\r
- *\r
- * 3) Other standard include files are invoked.\r
- *\r
- * 4) This file may come in conflict with future platforms that do\r
- * include stdint.h. The hope is that one or the other can be\r
- * used with no real difference.\r
- *\r
- * 5) In the current verison, if your platform can't represent\r
- * int32_t, int16_t and int8_t, it just dumps out with a compiler\r
- * error.\r
- *\r
- * 6) 64 bit integers may or may not be defined. Test for their\r
- * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.\r
- * Note that this is different from the C99 specification which\r
- * requires the existence of 64 bit support in the compiler. If\r
- * this is not defined for your platform, yet it is capable of\r
- * dealing with 64 bits then it is because this file has not yet\r
- * been extended to cover all of your system's capabilities.\r
- *\r
- * 7) (u)intptr_t may or may not be defined. Test for its presence\r
- * with the test: #ifdef PTRDIFF_MAX. If this is not defined\r
- * for your platform, then it is because this file has not yet\r
- * been extended to cover all of your system's capabilities, not\r
- * because its optional.\r
- *\r
- * 8) The following might not been defined even if your platform is\r
- * capable of defining it:\r
- *\r
- * WCHAR_MIN\r
- * WCHAR_MAX\r
- * (u)int64_t\r
- * PTRDIFF_MIN\r
- * PTRDIFF_MAX\r
- * (u)intptr_t\r
- *\r
- * 9) The following have not been defined:\r
- *\r
- * WINT_MIN\r
- * WINT_MAX\r
- *\r
- * 10) The criteria for defining (u)int_least(*)_t isn't clear,\r
- * except for systems which don't have a type that precisely\r
- * defined 8, 16, or 32 bit types (which this include file does\r
- * not support anyways). Default definitions have been given.\r
- *\r
- * 11) The criteria for defining (u)int_fast(*)_t isn't something I\r
- * would trust to any particular compiler vendor or the ANSI C\r
- * committee. It is well known that "compatible systems" are\r
- * commonly created that have very different performance\r
- * characteristics from the systems they are compatible with,\r
- * especially those whose vendors make both the compiler and the\r
- * system. Default definitions have been given, but its strongly\r
- * recommended that users never use these definitions for any\r
- * reason (they do *NOT* deliver any serious guarantee of\r
- * improved performance -- not in this file, nor any vendor's\r
- * stdint.h).\r
- *\r
- * 12) The following macros:\r
- *\r
- * PRINTF_INTMAX_MODIFIER\r
- * PRINTF_INT64_MODIFIER\r
- * PRINTF_INT32_MODIFIER\r
- * PRINTF_INT16_MODIFIER\r
- * PRINTF_LEAST64_MODIFIER\r
- * PRINTF_LEAST32_MODIFIER\r
- * PRINTF_LEAST16_MODIFIER\r
- * PRINTF_INTPTR_MODIFIER\r
- *\r
- * are strings which have been defined as the modifiers required\r
- * for the "d", "u" and "x" printf formats to correctly output\r
- * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,\r
- * (u)least32_t, (u)least16_t and (u)intptr_t types respectively.\r
- * PRINTF_INTPTR_MODIFIER is not defined for some systems which\r
- * provide their own stdint.h. PRINTF_INT64_MODIFIER is not\r
- * defined if INT64_MAX is not defined. These are an extension\r
- * beyond what C99 specifies must be in stdint.h.\r
- *\r
- * In addition, the following macros are defined:\r
- *\r
- * PRINTF_INTMAX_HEX_WIDTH\r
- * PRINTF_INT64_HEX_WIDTH\r
- * PRINTF_INT32_HEX_WIDTH\r
- * PRINTF_INT16_HEX_WIDTH\r
- * PRINTF_INT8_HEX_WIDTH\r
- * PRINTF_INTMAX_DEC_WIDTH\r
- * PRINTF_INT64_DEC_WIDTH\r
- * PRINTF_INT32_DEC_WIDTH\r
- * PRINTF_INT16_DEC_WIDTH\r
- * PRINTF_INT8_DEC_WIDTH\r
- *\r
- * Which specifies the maximum number of characters required to\r
- * print the number of that type in either hexadecimal or decimal.\r
- * These are an extension beyond what C99 specifies must be in\r
- * stdint.h.\r
- *\r
- * Compilers tested (all with 0 warnings at their highest respective\r
- * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32\r
- * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio\r
- * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3\r
- *\r
- * This file should be considered a work in progress. Suggestions for\r
- * improvements, especially those which increase coverage are strongly\r
- * encouraged.\r
- *\r
- * Acknowledgements\r
- *\r
- * The following people have made significant contributions to the\r
- * development and testing of this file:\r
- *\r
- * Chris Howie\r
- * John Steele Scott\r
- * Dave Thorup\r
- *\r
- */\r
-\r
-#include <stddef.h>\r
-#include <limits.h>\r
-#include <signal.h>\r
-\r
-/*\r
- * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and\r
- * do nothing else. On the Mac OS X version of gcc this is _STDINT_H_.\r
- */\r
-\r
-#if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) )) && !defined (_PSTDINT_H_INCLUDED)\r
-#include <stdint.h>\r
-#define _PSTDINT_H_INCLUDED\r
-# ifndef PRINTF_INT64_MODIFIER\r
-# define PRINTF_INT64_MODIFIER "ll"\r
-# endif\r
-# ifndef PRINTF_INT32_MODIFIER\r
-# define PRINTF_INT32_MODIFIER "l"\r
-# endif\r
-# ifndef PRINTF_INT16_MODIFIER\r
-# define PRINTF_INT16_MODIFIER "h"\r
-# endif\r
-# ifndef PRINTF_INTMAX_MODIFIER\r
-# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER\r
-# endif\r
-# ifndef PRINTF_INT64_HEX_WIDTH\r
-# define PRINTF_INT64_HEX_WIDTH "16"\r
-# endif\r
-# ifndef PRINTF_INT32_HEX_WIDTH\r
-# define PRINTF_INT32_HEX_WIDTH "8"\r
-# endif\r
-# ifndef PRINTF_INT16_HEX_WIDTH\r
-# define PRINTF_INT16_HEX_WIDTH "4"\r
-# endif\r
-# ifndef PRINTF_INT8_HEX_WIDTH\r
-# define PRINTF_INT8_HEX_WIDTH "2"\r
-# endif\r
-# ifndef PRINTF_INT64_DEC_WIDTH\r
-# define PRINTF_INT64_DEC_WIDTH "20"\r
-# endif\r
-# ifndef PRINTF_INT32_DEC_WIDTH\r
-# define PRINTF_INT32_DEC_WIDTH "10"\r
-# endif\r
-# ifndef PRINTF_INT16_DEC_WIDTH\r
-# define PRINTF_INT16_DEC_WIDTH "5"\r
-# endif\r
-# ifndef PRINTF_INT8_DEC_WIDTH\r
-# define PRINTF_INT8_DEC_WIDTH "3"\r
-# endif\r
-# ifndef PRINTF_INTMAX_HEX_WIDTH\r
-# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH\r
-# endif\r
-# ifndef PRINTF_INTMAX_DEC_WIDTH\r
-# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH\r
-# endif\r
-\r
-/*\r
- * Something really weird is going on with Open Watcom. Just pull some of\r
- * these duplicated definitions from Open Watcom's stdint.h file for now.\r
- */\r
-\r
-# if defined (__WATCOMC__) && __WATCOMC__ >= 1250\r
-# if !defined (INT64_C)\r
-# define INT64_C(x) (x + (INT64_MAX - INT64_MAX))\r
-# endif\r
-# if !defined (UINT64_C)\r
-# define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX))\r
-# endif\r
-# if !defined (INT32_C)\r
-# define INT32_C(x) (x + (INT32_MAX - INT32_MAX))\r
-# endif\r
-# if !defined (UINT32_C)\r
-# define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX))\r
-# endif\r
-# if !defined (INT16_C)\r
-# define INT16_C(x) (x)\r
-# endif\r
-# if !defined (UINT16_C)\r
-# define UINT16_C(x) (x)\r
-# endif\r
-# if !defined (INT8_C)\r
-# define INT8_C(x) (x)\r
-# endif\r
-# if !defined (UINT8_C)\r
-# define UINT8_C(x) (x)\r
-# endif\r
-# if !defined (UINT64_MAX)\r
-# define UINT64_MAX 18446744073709551615ULL\r
-# endif\r
-# if !defined (INT64_MAX)\r
-# define INT64_MAX 9223372036854775807LL\r
-# endif\r
-# if !defined (UINT32_MAX)\r
-# define UINT32_MAX 4294967295UL\r
-# endif\r
-# if !defined (INT32_MAX)\r
-# define INT32_MAX 2147483647L\r
-# endif\r
-# if !defined (INTMAX_MAX)\r
-# define INTMAX_MAX INT64_MAX\r
-# endif\r
-# if !defined (INTMAX_MIN)\r
-# define INTMAX_MIN INT64_MIN\r
-# endif\r
-# endif\r
-#endif\r
-\r
-#ifndef _PSTDINT_H_INCLUDED\r
-#define _PSTDINT_H_INCLUDED\r
-\r
-#ifndef SIZE_MAX\r
-# define SIZE_MAX (~(size_t)0)\r
-#endif\r
-\r
-/*\r
- * Deduce the type assignments from limits.h under the assumption that\r
- * integer sizes in bits are powers of 2, and follow the ANSI\r
- * definitions.\r
- */\r
-\r
-#ifndef UINT8_MAX\r
-# define UINT8_MAX 0xff\r
-#endif\r
-#ifndef uint8_t\r
-# if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)\r
- typedef unsigned char uint8_t;\r
-# define UINT8_C(v) ((uint8_t) v)\r
-# else\r
-# error "Platform not supported"\r
-# endif\r
-#endif\r
-\r
-#ifndef INT8_MAX\r
-# define INT8_MAX 0x7f\r
-#endif\r
-#ifndef INT8_MIN\r
-# define INT8_MIN INT8_C(0x80)\r
-#endif\r
-#ifndef int8_t\r
-# if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)\r
- typedef signed char int8_t;\r
-# define INT8_C(v) ((int8_t) v)\r
-# else\r
-# error "Platform not supported"\r
-# endif\r
-#endif\r
-\r
-#ifndef UINT16_MAX\r
-# define UINT16_MAX 0xffff\r
-#endif\r
-#ifndef uint16_t\r
-#if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)\r
- typedef unsigned int uint16_t;\r
-# ifndef PRINTF_INT16_MODIFIER\r
-# define PRINTF_INT16_MODIFIER ""\r
-# endif\r
-# define UINT16_C(v) ((uint16_t) (v))\r
-#elif (USHRT_MAX == UINT16_MAX)\r
- typedef unsigned short uint16_t;\r
-# define UINT16_C(v) ((uint16_t) (v))\r
-# ifndef PRINTF_INT16_MODIFIER\r
-# define PRINTF_INT16_MODIFIER "h"\r
-# endif\r
-#else\r
-#error "Platform not supported"\r
-#endif\r
-#endif\r
-\r
-#ifndef INT16_MAX\r
-# define INT16_MAX 0x7fff\r
-#endif\r
-#ifndef INT16_MIN\r
-# define INT16_MIN INT16_C(0x8000)\r
-#endif\r
-#ifndef int16_t\r
-#if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)\r
- typedef signed int int16_t;\r
-# define INT16_C(v) ((int16_t) (v))\r
-# ifndef PRINTF_INT16_MODIFIER\r
-# define PRINTF_INT16_MODIFIER ""\r
-# endif\r
-#elif (SHRT_MAX == INT16_MAX)\r
- typedef signed short int16_t;\r
-# define INT16_C(v) ((int16_t) (v))\r
-# ifndef PRINTF_INT16_MODIFIER\r
-# define PRINTF_INT16_MODIFIER "h"\r
-# endif\r
-#else\r
-#error "Platform not supported"\r
-#endif\r
-#endif\r
-\r
-#ifndef UINT32_MAX\r
-# define UINT32_MAX (0xffffffffUL)\r
-#endif\r
-#ifndef uint32_t\r
-#if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)\r
- typedef unsigned long uint32_t;\r
-# define UINT32_C(v) v ## UL\r
-# ifndef PRINTF_INT32_MODIFIER\r
-# define PRINTF_INT32_MODIFIER "l"\r
-# endif\r
-#elif (UINT_MAX == UINT32_MAX)\r
- typedef unsigned int uint32_t;\r
-# ifndef PRINTF_INT32_MODIFIER\r
-# define PRINTF_INT32_MODIFIER ""\r
-# endif\r
-# define UINT32_C(v) v ## U\r
-#elif (USHRT_MAX == UINT32_MAX)\r
- typedef unsigned short uint32_t;\r
-# define UINT32_C(v) ((unsigned short) (v))\r
-# ifndef PRINTF_INT32_MODIFIER\r
-# define PRINTF_INT32_MODIFIER ""\r
-# endif\r
-#else\r
-#error "Platform not supported"\r
-#endif\r
-#endif\r
-\r
-#ifndef INT32_MAX\r
-# define INT32_MAX (0x7fffffffL)\r
-#endif\r
-#ifndef INT32_MIN\r
-# define INT32_MIN INT32_C(0x80000000)\r
-#endif\r
-#ifndef int32_t\r
-#if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)\r
- typedef signed long int32_t;\r
-# define INT32_C(v) v ## L\r
-# ifndef PRINTF_INT32_MODIFIER\r
-# define PRINTF_INT32_MODIFIER "l"\r
-# endif\r
-#elif (INT_MAX == INT32_MAX)\r
- typedef signed int int32_t;\r
-# define INT32_C(v) v\r
-# ifndef PRINTF_INT32_MODIFIER\r
-# define PRINTF_INT32_MODIFIER ""\r
-# endif\r
-#elif (SHRT_MAX == INT32_MAX)\r
- typedef signed short int32_t;\r
-# define INT32_C(v) ((short) (v))\r
-# ifndef PRINTF_INT32_MODIFIER\r
-# define PRINTF_INT32_MODIFIER ""\r
-# endif\r
-#else\r
-#error "Platform not supported"\r
-#endif\r
-#endif\r
-\r
-/*\r
- * The macro stdint_int64_defined is temporarily used to record\r
- * whether or not 64 integer support is available. It must be\r
- * defined for any 64 integer extensions for new platforms that are\r
- * added.\r
- */\r
-\r
-#undef stdint_int64_defined\r
-#if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)\r
-# if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)\r
-# define stdint_int64_defined\r
- typedef long long int64_t;\r
- typedef unsigned long long uint64_t;\r
-# define UINT64_C(v) v ## ULL\r
-# define INT64_C(v) v ## LL\r
-# ifndef PRINTF_INT64_MODIFIER\r
-# define PRINTF_INT64_MODIFIER "ll"\r
-# endif\r
-# endif\r
-#endif\r
-\r
-#if !defined (stdint_int64_defined)\r
-# if defined(__GNUC__)\r
-# define stdint_int64_defined\r
- __extension__ typedef long long int64_t;\r
- __extension__ typedef unsigned long long uint64_t;\r
-# define UINT64_C(v) v ## ULL\r
-# define INT64_C(v) v ## LL\r
-# ifndef PRINTF_INT64_MODIFIER\r
-# define PRINTF_INT64_MODIFIER "ll"\r
-# endif\r
-# elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)\r
-# define stdint_int64_defined\r
- typedef long long int64_t;\r
- typedef unsigned long long uint64_t;\r
-# define UINT64_C(v) v ## ULL\r
-# define INT64_C(v) v ## LL\r
-# ifndef PRINTF_INT64_MODIFIER\r
-# define PRINTF_INT64_MODIFIER "ll"\r
-# endif\r
-# elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)\r
-# define stdint_int64_defined\r
- typedef __int64 int64_t;\r
- typedef unsigned __int64 uint64_t;\r
-# define UINT64_C(v) v ## UI64\r
-# define INT64_C(v) v ## I64\r
-# ifndef PRINTF_INT64_MODIFIER\r
-# define PRINTF_INT64_MODIFIER "I64"\r
-# endif\r
-# endif\r
-#endif\r
-\r
-#if !defined (LONG_LONG_MAX) && defined (INT64_C)\r
-# define LONG_LONG_MAX INT64_C (9223372036854775807)\r
-#endif\r
-#ifndef ULONG_LONG_MAX\r
-# define ULONG_LONG_MAX UINT64_C (18446744073709551615)\r
-#endif\r
-\r
-#if !defined (INT64_MAX) && defined (INT64_C)\r
-# define INT64_MAX INT64_C (9223372036854775807)\r
-#endif\r
-#if !defined (INT64_MIN) && defined (INT64_C)\r
-# define INT64_MIN INT64_C (-9223372036854775808)\r
-#endif\r
-#if !defined (UINT64_MAX) && defined (INT64_C)\r
-# define UINT64_MAX UINT64_C (18446744073709551615)\r
-#endif\r
-\r
-/*\r
- * Width of hexadecimal for number field.\r
- */\r
-\r
-#ifndef PRINTF_INT64_HEX_WIDTH\r
-# define PRINTF_INT64_HEX_WIDTH "16"\r
-#endif\r
-#ifndef PRINTF_INT32_HEX_WIDTH\r
-# define PRINTF_INT32_HEX_WIDTH "8"\r
-#endif\r
-#ifndef PRINTF_INT16_HEX_WIDTH\r
-# define PRINTF_INT16_HEX_WIDTH "4"\r
-#endif\r
-#ifndef PRINTF_INT8_HEX_WIDTH\r
-# define PRINTF_INT8_HEX_WIDTH "2"\r
-#endif\r
-\r
-#ifndef PRINTF_INT64_DEC_WIDTH\r
-# define PRINTF_INT64_DEC_WIDTH "20"\r
-#endif\r
-#ifndef PRINTF_INT32_DEC_WIDTH\r
-# define PRINTF_INT32_DEC_WIDTH "10"\r
-#endif\r
-#ifndef PRINTF_INT16_DEC_WIDTH\r
-# define PRINTF_INT16_DEC_WIDTH "5"\r
-#endif\r
-#ifndef PRINTF_INT8_DEC_WIDTH\r
-# define PRINTF_INT8_DEC_WIDTH "3"\r
-#endif\r
-\r
-/*\r
- * Ok, lets not worry about 128 bit integers for now. Moore's law says\r
- * we don't need to worry about that until about 2040 at which point\r
- * we'll have bigger things to worry about.\r
- */\r
-\r
-#ifdef stdint_int64_defined\r
- typedef int64_t intmax_t;\r
- typedef uint64_t uintmax_t;\r
-# define INTMAX_MAX INT64_MAX\r
-# define INTMAX_MIN INT64_MIN\r
-# define UINTMAX_MAX UINT64_MAX\r
-# define UINTMAX_C(v) UINT64_C(v)\r
-# define INTMAX_C(v) INT64_C(v)\r
-# ifndef PRINTF_INTMAX_MODIFIER\r
-# define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER\r
-# endif\r
-# ifndef PRINTF_INTMAX_HEX_WIDTH\r
-# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH\r
-# endif\r
-# ifndef PRINTF_INTMAX_DEC_WIDTH\r
-# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH\r
-# endif\r
-#else\r
- typedef int32_t intmax_t;\r
- typedef uint32_t uintmax_t;\r
-# define INTMAX_MAX INT32_MAX\r
-# define UINTMAX_MAX UINT32_MAX\r
-# define UINTMAX_C(v) UINT32_C(v)\r
-# define INTMAX_C(v) INT32_C(v)\r
-# ifndef PRINTF_INTMAX_MODIFIER\r
-# define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER\r
-# endif\r
-# ifndef PRINTF_INTMAX_HEX_WIDTH\r
-# define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH\r
-# endif\r
-# ifndef PRINTF_INTMAX_DEC_WIDTH\r
-# define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH\r
-# endif\r
-#endif\r
-\r
-/*\r
- * Because this file currently only supports platforms which have\r
- * precise powers of 2 as bit sizes for the default integers, the\r
- * least definitions are all trivial. Its possible that a future\r
- * version of this file could have different definitions.\r
- */\r
-\r
-#ifndef stdint_least_defined\r
- typedef int8_t int_least8_t;\r
- typedef uint8_t uint_least8_t;\r
- typedef int16_t int_least16_t;\r
- typedef uint16_t uint_least16_t;\r
- typedef int32_t int_least32_t;\r
- typedef uint32_t uint_least32_t;\r
-# define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER\r
-# define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER\r
-# define UINT_LEAST8_MAX UINT8_MAX\r
-# define INT_LEAST8_MAX INT8_MAX\r
-# define UINT_LEAST16_MAX UINT16_MAX\r
-# define INT_LEAST16_MAX INT16_MAX\r
-# define UINT_LEAST32_MAX UINT32_MAX\r
-# define INT_LEAST32_MAX INT32_MAX\r
-# define INT_LEAST8_MIN INT8_MIN\r
-# define INT_LEAST16_MIN INT16_MIN\r
-# define INT_LEAST32_MIN INT32_MIN\r
-# ifdef stdint_int64_defined\r
- typedef int64_t int_least64_t;\r
- typedef uint64_t uint_least64_t;\r
-# define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER\r
-# define UINT_LEAST64_MAX UINT64_MAX\r
-# define INT_LEAST64_MAX INT64_MAX\r
-# define INT_LEAST64_MIN INT64_MIN\r
-# endif\r
-#endif\r
-#undef stdint_least_defined\r
-\r
-/*\r
- * The ANSI C committee pretending to know or specify anything about\r
- * performance is the epitome of misguided arrogance. The mandate of\r
- * this file is to *ONLY* ever support that absolute minimum\r
- * definition of the fast integer types, for compatibility purposes.\r
- * No extensions, and no attempt to suggest what may or may not be a\r
- * faster integer type will ever be made in this file. Developers are\r
- * warned to stay away from these types when using this or any other\r
- * stdint.h.\r
- */\r
-\r
-typedef int_least8_t int_fast8_t;\r
-typedef uint_least8_t uint_fast8_t;\r
-typedef int_least16_t int_fast16_t;\r
-typedef uint_least16_t uint_fast16_t;\r
-typedef int_least32_t int_fast32_t;\r
-typedef uint_least32_t uint_fast32_t;\r
-#define UINT_FAST8_MAX UINT_LEAST8_MAX\r
-#define INT_FAST8_MAX INT_LEAST8_MAX\r
-#define UINT_FAST16_MAX UINT_LEAST16_MAX\r
-#define INT_FAST16_MAX INT_LEAST16_MAX\r
-#define UINT_FAST32_MAX UINT_LEAST32_MAX\r
-#define INT_FAST32_MAX INT_LEAST32_MAX\r
-#define INT_FAST8_MIN INT_LEAST8_MIN\r
-#define INT_FAST16_MIN INT_LEAST16_MIN\r
-#define INT_FAST32_MIN INT_LEAST32_MIN\r
-#ifdef stdint_int64_defined\r
- typedef int_least64_t int_fast64_t;\r
- typedef uint_least64_t uint_fast64_t;\r
-# define UINT_FAST64_MAX UINT_LEAST64_MAX\r
-# define INT_FAST64_MAX INT_LEAST64_MAX\r
-# define INT_FAST64_MIN INT_LEAST64_MIN\r
-#endif\r
-\r
-#undef stdint_int64_defined\r
-\r
-/*\r
- * Whatever piecemeal, per compiler thing we can do about the wchar_t\r
- * type limits.\r
- */\r
-\r
-#if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)\r
-# include <wchar.h>\r
-# ifndef WCHAR_MIN\r
-# define WCHAR_MIN 0\r
-# endif\r
-# ifndef WCHAR_MAX\r
-# define WCHAR_MAX ((wchar_t)-1)\r
-# endif\r
-#endif\r
-\r
-/*\r
- * Whatever piecemeal, per compiler/platform thing we can do about the\r
- * (u)intptr_t types and limits.\r
- */\r
-\r
-#if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)\r
-# define STDINT_H_UINTPTR_T_DEFINED\r
-#endif\r
-\r
-#ifndef STDINT_H_UINTPTR_T_DEFINED\r
-# if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)\r
-# define stdint_intptr_bits 64\r
-# elif defined (__WATCOMC__) || defined (__TURBOC__)\r
-# if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)\r
-# define stdint_intptr_bits 16\r
-# else\r
-# define stdint_intptr_bits 32\r
-# endif\r
-# elif defined (__i386__) || defined (_WIN32) || defined (WIN32)\r
-# define stdint_intptr_bits 32\r
-# elif defined (__INTEL_COMPILER)\r
-/* TODO -- what will Intel do about x86-64? */\r
-# endif\r
-\r
-# ifdef stdint_intptr_bits\r
-# define stdint_intptr_glue3_i(a,b,c) a##b##c\r
-# define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c)\r
-# ifndef PRINTF_INTPTR_MODIFIER\r
-# define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)\r
-# endif\r
-# ifndef PTRDIFF_MAX\r
-# define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)\r
-# endif\r
-# ifndef PTRDIFF_MIN\r
-# define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)\r
-# endif\r
-# ifndef UINTPTR_MAX\r
-# define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)\r
-# endif\r
-# ifndef INTPTR_MAX\r
-# define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)\r
-# endif\r
-# ifndef INTPTR_MIN\r
-# define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)\r
-# endif\r
-# ifndef INTPTR_C\r
-# define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)\r
-# endif\r
-# ifndef UINTPTR_C\r
-# define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)\r
-# endif\r
- typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;\r
- typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t;\r
-# else\r
-/* TODO -- This following is likely wrong for some platforms, and does\r
- nothing for the definition of uintptr_t. */\r
- typedef ptrdiff_t intptr_t;\r
-# endif\r
-# define STDINT_H_UINTPTR_T_DEFINED\r
-#endif\r
-\r
-/*\r
- * Assumes sig_atomic_t is signed and we have a 2s complement machine.\r
- */\r
-\r
-#ifndef SIG_ATOMIC_MAX\r
-# define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)\r
-#endif\r
-\r
-#endif\r
-\r
-#if defined (__TEST_PSTDINT_FOR_CORRECTNESS)\r
-\r
-/* \r
- * Please compile with the maximum warning settings to make sure macros are not\r
- * defined more than once.\r
- */\r
- \r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <string.h>\r
- \r
-#define glue3_aux(x,y,z) x ## y ## z\r
-#define glue3(x,y,z) glue3_aux(x,y,z)\r
-\r
-#define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);\r
-#define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);\r
-\r
-#define DECL(us,bits) glue3(DECL,us,) (bits)\r
-\r
-#define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)\r
- \r
-int main () {\r
- DECL(I,8)\r
- DECL(U,8)\r
- DECL(I,16)\r
- DECL(U,16)\r
- DECL(I,32)\r
- DECL(U,32)\r
-#ifdef INT64_MAX\r
- DECL(I,64)\r
- DECL(U,64)\r
-#endif\r
- intmax_t imax = INTMAX_C(0);\r
- uintmax_t umax = UINTMAX_C(0);\r
- char str0[256], str1[256];\r
-\r
- sprintf (str0, "%d %x\n", 0, ~0);\r
- \r
- sprintf (str1, "%d %x\n", i8, ~0);\r
- if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);\r
- sprintf (str1, "%u %x\n", u8, ~0);\r
- if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);\r
- sprintf (str1, "%d %x\n", i16, ~0);\r
- if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);\r
- sprintf (str1, "%u %x\n", u16, ~0);\r
- if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1); \r
- sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0);\r
- if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);\r
- sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0);\r
- if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);\r
-#ifdef INT64_MAX \r
- sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0);\r
- if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);\r
-#endif\r
- sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0);\r
- if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);\r
- sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0);\r
- if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1); \r
- \r
- TESTUMAX(8);\r
- TESTUMAX(16);\r
- TESTUMAX(32);\r
-#ifdef INT64_MAX\r
- TESTUMAX(64);\r
-#endif\r
-\r
- return EXIT_SUCCESS;\r
-}\r
-\r
-#endif\r
+++ /dev/null
-#ifndef _UNISTD_H\r
-#define _UNISTD_H 1\r
-\r
-/* This file intended to serve as a drop-in replacement for \r
- * * unistd.h on Windows\r
- * * Please add functionality as neeeded \r
- * */\r
-\r
-#include <stdlib.h>\r
-#include <io.h>\r
-#include <getopt.h> /* getopt from: http://www.pwilson.net/sample.html. */\r
-\r
-#define srandom srand\r
-#define random rand\r
-\r
-/*\r
-const W_OK = 2;\r
-const R_OK = 4;\r
-*/\r
-\r
-#define access _access\r
-#define ftruncate _chsize\r
-\r
-#define ssize_t int\r
-\r
-#endif /* unistd.h */\r