pax_global_header00006660000000000000000000000064131107474620014517gustar00rootroot0000000000000052 comment=749ea650b4eb2a903b0d48fc9d101287315f3425 sv-1.0/000077500000000000000000000000001311074746200120075ustar00rootroot00000000000000sv-1.0/.gitignore000066400000000000000000000050341311074746200140010ustar00rootroot00000000000000# Created by .ignore support plugin (hsz.mobi) ### Autotools template # http://www.gnu.org/software/automake Makefile.in /ar-lib /mdate-sh /py-compile /test-driver /ylwrap .deps/ .libs/ .dirstamp stamp-vti # http://www.gnu.org/software/autoconf /autom4te.cache /autoscan.log /autoscan-*.log /aclocal.m4 /compile /config.guess /config.h.in /config.sub /configure /configure.scan /depcomp /install-sh /missing /stamp-h1 stamp-h1 config.cache autotools/ # https://www.gnu.org/software/libtool/ /ltmain.sh # http://www.gnu.org/software/texinfo /texinfo.tex *.info* version.texi m4/libtool.m4 m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 scripts/ar-lib scripts/compile scripts/config.guess scripts/config.sub scripts/depcomp scripts/install-sh scripts/libsv.pc scripts/ltmain.sh scripts/missing scripts/test-driver config.log config.status libtool test-suite.log test/comp test/match test/range test/utils test/usage test/version test/*.log test/*.trs travis.log ### CMake template CMakeCache.txt CMakeFiles CMakeScripts Testing Makefile cmake_install.cmake install_manifest.txt compile_commands.json CTestTestfile.cmake ### C template # Prerequisites *.d # Object files *.o *.ko *.obj *.elf # Linker output *.ilk *.map *.exp # Precompiled Headers *.gch *.pch # Libraries *.lib *.a *.la *.lo # Shared objects (inc. Windows DLLs) *.dll *.so *.so.* *.dylib # Executables *.exe *.out *.app *.i*86 *.x86_64 *.hex # Debug files *.dSYM/ *.su *.idb *.pdb # Kernel Module Compile Results *.mod* *.cmd modules.order Module.symvers Mkfile.old dkms.conf ### JetBrains template # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff: .idea/**/workspace.xml .idea/**/tasks.xml .idea/dictionaries # Sensitive or high-churn files: .idea/**/dataSources/ .idea/**/dataSources.ids .idea/**/dataSources.xml .idea/**/dataSources.local.xml .idea/**/sqlDataSources.xml .idea/**/dynamic.xml .idea/**/uiDesigner.xml # Gradle: .idea/**/gradle.xml .idea/**/libraries # Mongo Explorer plugin: .idea/**/mongoSettings.xml ## File-based project format: *.iws ## Plugin-specific files: # IntelliJ /out/ # mpeltonen/sbt-idea plugin .idea_modules/ # JIRA plugin atlassian-ide-plugin.xml # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties # Clion .idea/ cmake-build-debug/ # xmake .xmake/ build/ # Stuff *~ =* ,,* sv-1.0/.travis.yml000066400000000000000000000105641311074746200141260ustar00rootroot00000000000000sudo: false language: c cache: ccache: true apt: true directories: - $HOME/.xmake before_install: - bash <(curl -s https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.sh) install: - xmake - cd build - cmake .. - make all script: - ctest --verbose - cd .. && xmake check matrix: include: # coverage build - os: linux dist: trusty compiler: gcc-5 addons: apt: sources: - george-edison55-precise-backports - ubuntu-toolchain-r-test packages: - cmake - cmake-data - gcc-5 install: - mkdir build && cd build - cmake -DCOVERAGE=ON -DCMAKE_BUILD_TYPE=Debug .. - make script: - ctest --verbose after_success: - cd .. && bash <(curl -s https://codecov.io/bash) -xgcov-5 - os: linux addons: apt: sources: - george-edison55-precise-backports packages: - cmake - cmake-data - os: linux compiler: gcc-4.9 addons: apt: sources: - ubuntu-toolchain-r-test - george-edison55-precise-backports packages: - gcc-4.9 - cmake - cmake-data - os: linux compiler: gcc-5 addons: apt: sources: - ubuntu-toolchain-r-test - george-edison55-precise-backports packages: - gcc-5 - cmake - cmake-data - os: linux compiler: gcc-6 addons: apt: sources: - ubuntu-toolchain-r-test - george-edison55-precise-backports packages: - gcc-6 - cmake - cmake-data - os: linux compiler: clang-3.5 addons: apt: sources: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.5 - george-edison55-precise-backports packages: - clang-3.5 - cmake - cmake-data - os: linux compiler: clang-3.6 addons: apt: sources: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.6 - george-edison55-precise-backports packages: - clang-3.6 - cmake - cmake-data - os: linux compiler: clang-3.7 addons: apt: sources: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.7 - george-edison55-precise-backports packages: - clang-3.7 - cmake - cmake-data - os: linux compiler: clang-3.8 addons: apt: sources: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.8 - george-edison55-precise-backports packages: - clang-3.8 - cmake - cmake-data - os: linux compiler: clang-3.9 addons: apt: sources: - ubuntu-toolchain-r-test - llvm-toolchain-precise-3.9 - george-edison55-precise-backports packages: - clang-3.9 - cmake - cmake-data - os: linux dist: trusty compiler: clang-4.0 addons: apt: sources: - ubuntu-toolchain-r-test - llvm-toolchain-trusty-4.0 packages: - clang-4.0 - os: linux dist: trusty before_install: ./autogen.sh install: - mkdir build && cd build - ../configure --enable-maintainer-mode - make script: make check - os: osx osx_image: xcode6.4 compiler: clang install: - brew install ccache - PATH=$PATH:/usr/local/opt/ccache/libexec - xmake - cd build - cmake .. - make all - os: osx osx_image: xcode7.3 compiler: clang install: - brew install ccache - PATH=$PATH:/usr/local/opt/ccache/libexec - xmake - cd build - cmake .. - make all - os: osx osx_image: xcode8.3 compiler: clang install: - brew install ccache - PATH=$PATH:/usr/local/opt/ccache/libexec - xmake - cd build - cmake .. - make all sv-1.0/CMakeLists.txt000066400000000000000000000056721311074746200145610ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) project(sv) option(SHARED "Build as shared library" OFF) option(COVERAGE "Turn on COVERAGE support" ON) if (COVERAGE) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} --coverage") endif() if(CMAKE_VERSION VERSION_LESS "3.1") if(CMAKE_C_COMPILER_ID STREQUAL "GNU") set(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}") endif() else() set(CMAKE_C_STANDARD 99) endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") if(MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W2") else() if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g3 -DDEBUG") else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Werror -fomit-frame-pointer") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-function") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-variable -Wno-unused-value -Wno-unused-result") endif() set(sv_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include) set(sv_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src) set(sv_TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/test) file(GLOB sv_HEADERS ${sv_HEADERS} ${sv_INCLUDE_DIR}/*.h) file(GLOB sv_SOURCES ${sv_SOURCES} ${sv_SOURCE_DIR}/*.c) include_directories(${sv_INCLUDE_DIR}) if(SHARED) if(MSVC) set(CMAKE_FLAGS CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE ) foreach(CMAKE_FLAG ${CMAKE_FLAGS}) string(REPLACE "/MD" "/MT" ${CMAKE_FLAG} "${${CMAKE_FLAG}}") string(REPLACE "/MDd" "/MTd" ${CMAKE_FLAG} "${${CMAKE_FLAG}}") endforeach() endif() add_library(${PROJECT_NAME} SHARED ${sv_SOURCES} ${sv_HEADERS}) target_compile_definitions(${PROJECT_NAME} PUBLIC BUILD_DYNAMIC_LINK=1) else() add_library(${PROJECT_NAME} STATIC ${sv_SOURCES} ${sv_HEADERS}) endif() target_compile_definitions(${PROJECT_NAME} PUBLIC SEMVER_COMPILE=1) enable_testing() add_subdirectory(${sv_TEST_DIR}) if(WIN32) set(CPACK_GENERATOR "WIX") set(CPACK_SOURCE_GENERATOR "ZIP") elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(CPACK_GENERATOR "PackageMake") else() set(CPACK_GENERATOR "DEB;RPM") set(CPACK_SOURCE_GENERATOR "TGZ") endif() set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Lucas Abel") set(CPACK_PACKAGE_VERSION "1.0.0") set(CPACK_PACKAGE_VERSION_MAJOR "1") set(CPACK_PACKAGE_VERSION_MINOR "0") set(CPACK_PACKAGE_VERSION_PATCH "0") set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README.md") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/UNLICENSE") set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md") set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/README.md") set(CPACK_SOURCE_IGNORE_FILES "${CMAKE_SOURCE_DIR}/build/;${CMAKE_SOURCE_DIR}/.git/") set(CPACK_SYSTEM_NAME "") include(CPack) sv-1.0/INSTALL000066400000000000000000000363311311074746200130460ustar00rootroot00000000000000Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without warranty of any kind. Basic Installation ================== Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. Some packages provide this `INSTALL' file but do not implement all of the features documented below. The lack of an optional feature in a given package is not necessarily a bug. More recommendations for GNU packages can be found in *note Makefile Conventions: (standards)Makefile Conventions. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. Caching is disabled by default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. Running `configure' might take a while. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package, generally using the just-built uninstalled binaries. 4. Type `make install' to install the programs and any data files and documentation. When installing into a prefix owned by root, it is recommended that the package be configured and built as a regular user, and only the `make install' phase executed with root privileges. 5. Optionally, type `make installcheck' to repeat any self-tests, but this time using the binaries in their final installed location. This target does not install anything. Running this target as a regular user, particularly if the prior `make install' required root privileges, verifies that the installation completed correctly. 6. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. 7. Often, you can also type `make uninstall' to remove the installed files again. In practice, not all packages have tested that uninstallation works correctly, even though it is required by the GNU Coding Standards. 8. Some packages, particularly those that use Automake, provide `make distcheck', which can by used by developers to test that all other targets like `make install' and `make uninstall' work correctly. This target is generally not run by end users. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. This is known as a "VPATH" build. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. On MacOS X 10.5 and later systems, you can create libraries and executables that work on multiple system types--known as "fat" or "universal" binaries--by specifying multiple `-arch' options to the compiler but only a single `-arch' option to the preprocessor. Like this: ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ CPP="gcc -E" CXXCPP="g++ -E" This is not guaranteed to produce working output in all cases, you may have to build one architecture at a time and combine the results using the `lipo' tool if you have problems. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX', where PREFIX must be an absolute file name. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. In general, the default for these options is expressed in terms of `${prefix}', so that specifying just `--prefix' will affect all of the other directory specifications that were not explicitly provided. The most portable way to affect installation locations is to pass the correct locations to `configure'; however, many packages provide one or both of the following shortcuts of passing variable assignments to the `make install' command line to change installation locations without having to reconfigure or recompile. The first method involves providing an override variable for each affected directory. For example, `make install prefix=/alternate/directory' will choose an alternate location for all directory configuration variables that were expressed in terms of `${prefix}'. Any directories that were specified during `configure', but not in terms of `${prefix}', must each be overridden at install time for the entire installation to be relocated. The approach of makefile variable overrides for each directory variable is required by the GNU Coding Standards, and ideally causes no recompilation. However, some platforms have known limitations with the semantics of shared libraries that end up requiring recompilation when using this method, particularly noticeable in packages that use GNU Libtool. The second method involves providing the `DESTDIR' variable. For example, `make install DESTDIR=/alternate/directory' will prepend `/alternate/directory' before all installation names. The approach of `DESTDIR' overrides is not required by the GNU Coding Standards, and does not work on platforms that have drive letters. On the other hand, it does better at avoiding recompilation issues, and works well even when some directory options were not specified in terms of `${prefix}' at `configure' time. Optional Features ================= If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Some packages offer the ability to configure how verbose the execution of `make' will be. For these packages, running `./configure --enable-silent-rules' sets the default to minimal output, which can be overridden with `make V=1'; while running `./configure --disable-silent-rules' sets the default to verbose, which can be overridden with `make V=0'. Particular systems ================== On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC is not installed, it is recommended to use the following options in order to use an ANSI C compiler: ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" and if that doesn't work, install pre-built binaries of GCC for HP-UX. On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot parse its `' header file. The option `-nodtk' can be used as a workaround. If GNU CC is not installed, it is therefore recommended to try ./configure CC="cc" and if that doesn't work, try ./configure CC="cc -nodtk" On Solaris, don't put `/usr/ucb' early in your `PATH'. This directory contains several dysfunctional programs; working variants of these programs are available in `/usr/bin'. So, if you need `/usr/ucb' in your `PATH', put it _after_ `/usr/bin'. On Haiku, software installed for all users goes in `/boot/common', not `/usr/local'. It is recommended to use the following options: ./configure --prefix=/boot/common Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Unfortunately, this technique does not work for `CONFIG_SHELL' due to an Autoconf bug. Until the bug is fixed you can use this workaround: CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of all of the options to `configure', and exit. `--help=short' `--help=recursive' Print a summary of the options unique to this package's `configure', and exit. The `short' variant lists options used only in the top level, while the `recursive' variant lists options also present in any nested packages. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `--prefix=DIR' Use DIR as the installation prefix. *note Installation Names:: for more details, including other options available for fine-tuning the installation locations. `--no-create' `-n' Run the configure checks, but stop before creating any output files. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. sv-1.0/Makefile.am000066400000000000000000000047371311074746200140560ustar00rootroot00000000000000## Process this file with automake to produce Makefile.in ACLOCAL_AMFLAGS = -I m4 AUTOMAKE_OPTIONS = foreign dist_doc_DATA = UNLICENSE README.md AM_CFLAGS = -I$(srcdir)/src -I$(srcdir)/include -Wall $(AX_CFLAGS) ## -------------------------------------------------------------------- EXTRA_DIST = scripts/libsv.pc.in pkgconfigdir = $(libdir)/pkgconfig nodist_pkgconfig_DATA = scripts/libsv.pc ## -------------------------------------------------------------------- # Commented out because at present there is no Texinfo documentation # included. It will come later. (Marco Maggi; May 17, 2017) # # AM_MAKEINFOFLAGS = --no-split # info_TEXINFOS = doc/semver.texi # doc_semver_TEXINFOS = doc/macros.texi #page #### libraries libsv_CURRENT = @libsv_VERSION_INTERFACE_CURRENT@ libsv_REVISION = @libsv_VERSION_INTERFACE_REVISION@ libsv_AGE = @libsv_VERSION_INTERFACE_AGE@ include_HEADERS = include/semver.h lib_LTLIBRARIES = libsv.la libsv_la_LDFLAGS = -version-info $(libsv_CURRENT):$(libsv_REVISION):$(libsv_AGE) libsv_la_SOURCES = \ src/comp.c \ src/id.c \ src/num.c \ src/range.c \ src/version.c \ src/utils.c #page #### test check_PROGRAMS = \ test/version \ test/comp \ test/match \ test/range \ test/utils \ test/usage TESTS = $(check_PROGRAMS) libsv_test_cppflags = -I$(srcdir)/src -I$(srcdir)/include libsv_test_ldadd = libsv.la test_version_CPPFLAGS = $(libsv_test_cppflags) test_version_LDADD = $(libsv_test_ldadd) test_comp_CPPFLAGS = $(libsv_test_cppflags) test_comp_LDADD = $(libsv_test_ldadd) test_match_CPPFLAGS = $(libsv_test_cppflags) test_match_LDADD = $(libsv_test_ldadd) test_range_CPPFLAGS = $(libsv_test_cppflags) test_range_LDADD = $(libsv_test_ldadd) test_utils_CPPFLAGS = $(libsv_test_cppflags) test_utils_LDADD = $(libsv_test_ldadd) test_usage_CPPFLAGS = $(libsv_test_cppflags) test_usage_LDADD = $(libsv_test_ldadd) installcheck-local: $(TEST) @for f in $(TEST); do $(builddir)/$$f; done #page #### Static analysis with Clang's Static Analyzer # # See the documentation for the command line tool at: # # # # To run the tool we must do: # # $ make clean # $ make clang-static-analysis # # The program "scan-build" works by overriding the CC and CXX # environment variables. # .PHONY: clang-static-analysis clang-static-analysis: scan-build make ### end of file sv-1.0/README.md000066400000000000000000000264561311074746200133030ustar00rootroot00000000000000# libsv libsv - Public domain semantic versioning in c [![Build Status](https://travis-ci.org/uael/sv.svg?branch=master)](https://travis-ci.org/uael/sv) [![Build status](https://ci.appveyor.com/api/projects/status/7li44f9agk0u4dxc?svg=true)](https://ci.appveyor.com/project/uael/sv) [![codecov](https://codecov.io/gh/uael/sv/branch/master/graph/badge.svg)](https://codecov.io/gh/uael/sv) # Topics - [Introduction](#introduction) - [License](#license) - [Install](#install) - [xmake](#xmake) - [cmake](#cmake) - [autotools](#autotools) - [Usage](#usage) - [Credits](#credits) - [Bugs, vulnerabilities and contributions](#bugs-vulnerabilities-and-contributions) - [Resources](#resources) - [Badges and static analysis](#badges-and-static-analysis) - [Travis CI](#travis-ci) - [Clang's Static Analyzer](#clangs-static-analyzer) ## Introduction This is free and unencumbered software released into the public domain. This package installs a C language library implementing semantic versioning for the C language. ## License See the [UNLICENSE](https://github.com/uael/sv/blob/master/UNLICENSE) file. ## Install ### xmake [Install xmake build system (A make-like build utility based on Lua)](http://xmake.io) ```bash $ xmake $ xmake check $ xmake install ``` ### cmake ```bash $ mkdir build && cd build $ cmake .. $ make $ make test $ make install ``` ### autotools To install from a proper release tarball, do this: ```bash $ cd libsv-3.1 $ mkdir build $ cd build $ ../configure $ make $ make check $ make install ``` to inspect the available configuration options: ```bash $ ../configure --help ``` The Makefile is designed to allow parallel builds, so we can do: ```bash $ make -j4 all && make -j4 check ``` which, on a 4-core CPU, should speed up building and checking significantly. The Makefile supports the DESTDIR environment variable to install files in a temporary location, example: to see what will happen: ```bash $ make -n install DESTDIR=/tmp/libsv ``` to really do it: ```bash $ make install DESTDIR=/tmp/libsv ``` After the installation it is possible to verify the installed library against the test suite with: ```bash $ make installcheck ``` From a repository checkout or snapshot (the ones from the Github site): we must install the GNU Autotools (GNU Automake, GNU Autoconf, GNU Libtool), then we must first run the script "autogen.sh" from the top source directory, to generate the needed files: ```bash $ cd libsv $ sh autogen.sh ``` notice that "autogen.sh" will run the programs "autoreconf" and "libtoolize"; the latter is selected through the environment variable "LIBTOOLIZE", whose value can be customised; for example to run "glibtoolize" rather than "libtoolize" we do: ```bash $ LIBTOOLIZE=glibtoolize sh autogen.sh ``` After this the procedure is the same as the one for building from a proper release tarball, but we have to enable maintainer mode: ```bash $ ../configure --enable-maintainer-mode [options] $ make $ make check $ make install ``` ## Usage ```c ... semver_t semver = {0}; semver(&semver, "v1.2.3-alpha.1"); assert(1 == semver.major); assert(2 == semver.minor); assert(3 == semver.patch); assert(0 == memcmp("alpha", semver.prerelease.raw, sizeof("alpha")-1)); assert(0 == memcmp("1", semver.prerelease.next->raw, sizeof("1")-1)); assert(true == semver_rmatch(semver, "1.2.1 || >=1.2.3-alpha <1.2.5")); semver_dtor(&semver); ... ``` ### Versions A "version" is described by the `v2.0.0` specification found at . A leading `"v"` character is stripped off and ignored. ### Ranges A `version range` is a set of `comparators` which specify versions that satisfy the range. A `comparator` is composed of an `operator` and a `version`. The set of primitive `operators` is: * `<` Less than * `<=` Less than or equal to * `>` Greater than * `>=` Greater than or equal to * `=` Equal. If no operator is specified, then equality is assumed, so this operator is optional, but MAY be included. For example, the comparator `>=1.2.7` would match the versions `1.2.7`, `1.2.8`, `2.5.3`, and `1.3.9`, but not the versions `1.2.6` or `1.1.0`. Comparators can be joined by whitespace to form a `comparator set`, which is satisfied by the **intersection** of all of the comparators it includes. A range is composed of one or more comparator sets, joined by `||`. A version matches a range if and only if every comparator in at least one of the `||`-separated comparator sets is satisfied by the version. For example, the range `>=1.2.7 <1.3.0` would match the versions `1.2.7`, `1.2.8`, and `1.2.99`, but not the versions `1.2.6`, `1.3.0`, or `1.1.0`. The range `1.2.7 || >=1.2.9 <2.0.0` would match the versions `1.2.7`, `1.2.9`, and `1.4.6`, but not the versions `1.2.8` or `2.0.0`. #### Prerelease Tags If a version has a prerelease tag (for example, `1.2.3-alpha.3`) then it will only be allowed to satisfy comparator sets if at least one comparator with the same `[major, minor, patch]` tuple also has a prerelease tag. For example, the range `>1.2.3-alpha.3` would be allowed to match the version `1.2.3-alpha.7`, but it would *not* be satisfied by `3.4.5-alpha.9`, even though `3.4.5-alpha.9` is technically "greater than" `1.2.3-alpha.3` according to the SemVer sort rules. The version range only accepts prerelease tags on the `1.2.3` version. The version `3.4.5` *would* satisfy the range, because it does not have a prerelease flag, and `3.4.5` is greater than `1.2.3-alpha.7`. The purpose for this behavior is twofold. First, prerelease versions frequently are updated very quickly, and contain many breaking changes that are (by the author's design) not yet fit for public consumption. Therefore, by default, they are excluded from range matching semantics. Second, a user who has opted into using a prerelease version has clearly indicated the intent to use *that specific* set of alpha/beta/rc versions. By including a prerelease tag in the range, the user is indicating that they are aware of the risk. However, it is still not appropriate to assume that they have opted into taking a similar risk on the *next* set of prerelease versions. #### Advanced Range Syntax Advanced range syntax desugars to primitive comparators in deterministic ways. Advanced ranges may be combined in the same way as primitive comparators using white space or `||`. ##### Hyphen Ranges `X.Y.Z - A.B.C` Specifies an inclusive set. * `1.2.3 - 2.3.4` := `>=1.2.3 <=2.3.4` If a partial version is provided as the first version in the inclusive range, then the missing pieces are replaced with zeroes. * `1.2 - 2.3.4` := `>=1.2.0 <=2.3.4` If a partial version is provided as the second version in the inclusive range, then all versions that start with the supplied parts of the tuple are accepted, but nothing that would be greater than the provided tuple parts. * `1.2.3 - 2.3` := `>=1.2.3 <2.4.0` * `1.2.3 - 2` := `>=1.2.3 <3.0.0` ##### X-Ranges `1.2.x` `1.X` `1.2.*` `*` Any of `X`, `x`, or `*` may be used to "stand in" for one of the numeric values in the `[major, minor, patch]` tuple. * `*` := `>=0.0.0` (Any version satisfies) * `1.x` := `>=1.0.0 <2.0.0` (Matching major version) * `1.2.x` := `>=1.2.0 <1.3.0` (Matching major and minor versions) A partial version range is treated as an X-Range, so the special character is in fact optional. * `""` (empty string) := `*` := `>=0.0.0` * `1` := `1.x.x` := `>=1.0.0 <2.0.0` * `1.2` := `1.2.x` := `>=1.2.0 <1.3.0` ##### Tilde Ranges `~1.2.3` `~1.2` `~1` Allows patch-level changes if a minor version is specified on the comparator. Allows minor-level changes if not. * `~1.2.3` := `>=1.2.3 <1.(2+1).0` := `>=1.2.3 <1.3.0` * `~1.2` := `>=1.2.0 <1.(2+1).0` := `>=1.2.0 <1.3.0` (Same as `1.2.x`) * `~1` := `>=1.0.0 <(1+1).0.0` := `>=1.0.0 <2.0.0` (Same as `1.x`) * `~0.2.3` := `>=0.2.3 <0.(2+1).0` := `>=0.2.3 <0.3.0` * `~0.2` := `>=0.2.0 <0.(2+1).0` := `>=0.2.0 <0.3.0` (Same as `0.2.x`) * `~0` := `>=0.0.0 <(0+1).0.0` := `>=0.0.0 <1.0.0` (Same as `0.x`) * `~1.2.3-beta.2` := `>=1.2.3-beta.2 <1.3.0` Note that prereleases in the `1.2.3` version will be allowed, if they are greater than or equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but `1.2.4-beta.2` would not, because it is a prerelease of a different `[major, minor, patch]` tuple. #### Caret Ranges `^1.2.3` `^0.2.5` `^0.0.4` Allows changes that do not modify the left-most non-zero digit in the `[major, minor, patch]` tuple. In other words, this allows patch and minor updates for versions `1.0.0` and above, patch updates for versions `0.X >=0.1.0`, and *no* updates for versions `0.0.X`. Many authors treat a `0.x` version as if the `x` were the major "breaking-change" indicator. Caret ranges are ideal when an author may make breaking changes between `0.2.4` and `0.3.0` releases, which is a common practice. However, it presumes that there will *not* be breaking changes between `0.2.4` and `0.2.5`. It allows for changes that are presumed to be additive (but non-breaking), according to commonly observed practices. * `^1.2.3` := `>=1.2.3 <2.0.0` * `^0.2.3` := `>=0.2.3 <0.3.0` * `^0.0.3` := `>=0.0.3 <0.0.4` * `^1.2.3-beta.2` := `>=1.2.3-beta.2 <2.0.0` Note that prereleases in the `1.2.3` version will be allowed, if they are greater than or equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but `1.2.4-beta.2` would not, because it is a prerelease of a different `[major, minor, patch]` tuple. * `^0.0.3-beta` := `>=0.0.3-beta <0.0.4` Note that prereleases in the `0.0.3` version *only* will be allowed, if they are greater than or equal to `beta`. So, `0.0.3-pr.2` would be allowed. When parsing caret ranges, a missing `patch` value desugars to the number `0`, but will allow flexibility within that value, even if the major and minor versions are both `0`. * `^1.2.x` := `>=1.2.0 <2.0.0` * `^0.0.x` := `>=0.0.0 <0.1.0` * `^0.0` := `>=0.0.0 <0.1.0` A missing `minor` and `patch` values will desugar to zero, but also allow flexibility within those values, even if the major version is zero. * `^1.x` := `>=1.0.0 <2.0.0` * `^0.x` := `>=0.0.0 <1.0.0` ## Credits The stuff was written by Lucas Abel and contributors - Marco Maggi ## Bugs, vulnerabilities and contributions Bug and vulnerability reports are appreciated, all the vulnerability reports are public; register them using the Issue Tracker at the project's Github site. For contributions and patches please use the Pull Requests feature at the project's Github site. Reports about the original code must be registered at: ## Resources Development of the original projects takes place at: the GNU Project software can be found here: ## Badges and static analysis ### Travis CI Travis CI is a hosted, distributed continuous integration service used to build and test software projects hosted at GitHub. We can find this project's dashboards at: Usage of this service is configured through the file ".travis.yml". ### Clang's Static Analyzer The Clang Static Analyzer is a source code analysis tool that finds bugs in C, C++, and Objective-C programs. It is distributed along with Clang and we can find it at: Usage of this service is implemented with make rules; see the relevant section in the file "Makefile.am". sv-1.0/UNLICENSE000066400000000000000000000022721311074746200132620ustar00rootroot00000000000000This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to sv-1.0/appveyor.yml000066400000000000000000000012711311074746200144000ustar00rootroot00000000000000version: "1.0.{build}" platform: - Win32 - x64 image: - Visual Studio 2013 - Visual Studio 2015 - Visual Studio 2017 configuration: - Debug - Release init: - ps: Invoke-Expression (Invoke-Webrequest 'https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.ps1' -UseBasicParsing).Content - cmd: xmake --version - cmd: msbuild /version branches: only: - master - dev install: - git submodule update --init --recursive before_build: - cmd: if %platform%==x64 xmake f -a x64 - cmd: if %configuration%==Debug xmake f -m debug - cmd: if %configuration%==Release xmake f -m release build_script: - cmd: xmake -v test_script: - cmd: xmake check sv-1.0/autogen.sh000077500000000000000000000004261311074746200140120ustar00rootroot00000000000000#!/bin/sh # autogen.sh -- # # Run this in the top source directory to rebuild the infrastructure. LIBTOOLIZE=${LIBTOOLIZE:=libtoolize} set -xe test -d m4 || mkdir -p m4 test -f m4/libtool.m4 || "$LIBTOOLIZE" autoreconf --warnings=all --install --verbose "$@" ### end of file sv-1.0/codecov.yml000066400000000000000000000000761311074746200141570ustar00rootroot00000000000000ignore: - "test" # ignore test folder and all its contents sv-1.0/configure.ac000066400000000000000000000042121311074746200142740ustar00rootroot00000000000000dnl @configure_input@ dnl AC_PREREQ([2.69]) AC_INIT([libsv],[0.0.1],,[libsv],[http://github.com/uael/sv]) AC_COPYRIGHT([This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to ]) AC_CONFIG_SRCDIR([src]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR([scripts]) AC_CANONICAL_BUILD AC_CANONICAL_HOST AC_CANONICAL_TARGET AM_INIT_AUTOMAKE([foreign dist-xz no-dist-gzip subdir-objects]) AM_MAINTAINER_MODE AM_PROG_AR AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MAKE_SET AC_PROG_MKDIR_P LT_PREREQ([2.4]) LT_INIT dnl This is the version stored in the pkg-config data file. AC_SUBST([LIBSV_PKG_CONFIG_VERSION],[0.0.1]) dnl page #### libraries interface version MM_LIBTOOL_LIBRARY_VERSIONS([libsv],1,0,0) dnl page #### basic system inspection AC_LANG([C]) AM_PROG_AS AC_PROG_CC_C99 AM_PROG_CC_C_O AC_HEADER_STDC AC_CACHE_SAVE dnl page #### finish AC_CONFIG_FILES([Makefile] [scripts/libsv.pc]) AC_OUTPUT ### end of file # Local Variables: # mode: autoconf # page-delimiter: "^dnl page" # End: sv-1.0/include/000077500000000000000000000000001311074746200134325ustar00rootroot00000000000000sv-1.0/include/semver.h000066400000000000000000000122601311074746200151050ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #ifndef SV_H__ # define SV_H__ #include #include #include #ifndef SV_COMPILE # define SV_COMPILE (0) #endif #ifndef SV_BUILD_DYNAMIC_LINK # define SV_BUILD_DYNAMIC_LINK (0) #endif #if SV_BUILD_DYNAMIC_LINK && defined(_MSC_VER) # define SV_EXPORT_LINK __declspec(dllexport) # define SV_IMPORT_LINK __declspec(dllimport) #else # define SV_EXPORT_LINK # define SV_IMPORT_LINK #endif #if SV_COMPILE # ifdef __cplusplus # define SV_API extern "C" SV_EXPORT_LINK # else # define SV_API extern SV_EXPORT_LINK # endif #else # ifdef __cplusplus # define SV_API extern "C" SV_IMPORT_LINK # else # define SV_API extern SV_IMPORT_LINK # endif #endif #if !defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER < 1900 # define bool unsigned char # define true 1 # define false 0 # define __bool_true_false_are_defined 1 #else # ifdef __cplusplus # include # else # include # endif #endif #ifndef sv_malloc # define sv_malloc malloc #endif #ifndef sv_free # define sv_free free #endif #define SEMVER_NUM_X (-1) #define semver(self, str) semvern(self, str, strlen(str)) #define semver_write(self, buffer, len) semver_pwrite(&(self), buffer, len) #define semver_cmp(self, other) semver_pcmp(&(self), &(other)) #define semver_comp(self, str) semver_compn(self, str, strlen(str)) #define semver_comp_write(self, buffer, len) semver_comp_pwrite(&(self), buffer, len) #define semver_comp_match(self, comp) semver_comp_pmatch(&(self), &(comp)) #define semver_match(self, comp_str) semver_comp_matchn(&(self), comp_str, strlen(comp_str)) #define semver_range(self, str) semver_rangen(self, str, strlen(str)) #define semver_range_write(self, buffer, len) semver_range_pwrite(&(self), buffer, len) #define semver_range_match(self, range) semver_range_pmatch(&(self), &(range)) #define semver_rmatch(self, range_str) semver_range_matchn(&(self), range_str, strlen(range_str)) typedef struct semver semver_t; typedef struct semver_id semver_id_t; typedef struct semver_comp semver_comp_t; typedef struct semver_range semver_range_t; enum semver_op { SEMVER_OP_EQ = 0, SEMVER_OP_LT, SEMVER_OP_LE, SEMVER_OP_GT, SEMVER_OP_GE, }; struct semver_id { bool numeric; int num; size_t len; const char *raw; struct semver_id *next; }; struct semver { int major, minor, patch; semver_id_t prerelease, build; size_t len; const char *raw; }; SV_API char semvern(semver_t *self, const char *str, size_t len); SV_API void semver_dtor(semver_t *self); SV_API int semver_pwrite(const semver_t *self, char *buffer, size_t len); SV_API size_t semver_fwrite (const semver_t *self, FILE * stream); SV_API char semver_pcmp(const semver_t *self, const semver_t *other); SV_API bool semver_comp_pmatch(const semver_t *self, const semver_comp_t *comp); SV_API bool semver_comp_matchn(const semver_t *self, const char *comp_str, size_t comp_len); SV_API bool semver_range_pmatch(const semver_t *self, const semver_range_t *range); SV_API bool semver_range_matchn(const semver_t *self, const char *range_str, size_t range_len); struct semver_comp { struct semver_comp *next; enum semver_op op; semver_t version; }; SV_API char semver_compn(semver_comp_t *self, const char *str, size_t len); SV_API void semver_comp_dtor(semver_comp_t *self); SV_API int semver_comp_pwrite(const semver_comp_t *self, char *buffer, size_t len); SV_API size_t semver_comp_fwrite (const semver_comp_t *self, FILE *stream); SV_API char semver_and(semver_comp_t *left, const char *str, size_t len); struct semver_range { struct semver_range *next; semver_comp_t comp; }; SV_API char semver_rangen(semver_range_t *self, const char *str, size_t len); SV_API void semver_range_dtor(semver_range_t *self); SV_API int semver_range_pwrite(const semver_range_t *self, char *buffer, size_t len); SV_API size_t semver_range_fwrite (const semver_range_t *rangep, FILE *stream); SV_API char semver_or(semver_range_t *left, const char *str, size_t len); #endif /* SV_H__ */ sv-1.0/m4/000077500000000000000000000000001311074746200123275ustar00rootroot00000000000000sv-1.0/m4/mm-libtool-library-versions.m4000066400000000000000000000022311311074746200201520ustar00rootroot00000000000000dnl mm-libtool-library-versions.m4 dnl Set version numbers for libraries built with GNU Libtool. dnl dnl MM_LIBTOOL_LIBRARY_VERSIONS(stem,current,revision,age) dnl AC_DEFUN([MM_LIBTOOL_LIBRARY_VERSIONS], [$1_VERSION_INTERFACE_CURRENT=$2 $1_VERSION_INTERFACE_REVISION=$3 $1_VERSION_INTERFACE_AGE=$4 AC_DEFINE_UNQUOTED([$1_VERSION_INTERFACE], [$$1_VERSION_INTERFACE_CURRENT.$$1_VERSION_INTERFACE_REVISION.$$1_VERSION_INTERFACE_AGE], [current interface number]) AC_DEFINE_UNQUOTED([$1_VERSION_INTERFACE_CURRENT], [$$1_VERSION_INTERFACE_CURRENT], [current interface number]) AC_DEFINE_UNQUOTED([$1_VERSION_INTERFACE_REVISION], [$$1_VERSION_INTERFACE_REVISION], [current interface implementation number]) AC_DEFINE_UNQUOTED([$1_VERSION_INTERFACE_AGE], [$$1_VERSION_INTERFACE_AGE], [current interface age number]) AC_DEFINE_UNQUOTED([$1_VERSION_INTERFACE_STRING], ["$$1_VERSION_INTERFACE_CURRENT.$$1_VERSION_INTERFACE_REVISION"], [library interface version]) AC_SUBST([$1_VERSION_INTERFACE_CURRENT]) AC_SUBST([$1_VERSION_INTERFACE_REVISION]) AC_SUBST([$1_VERSION_INTERFACE_AGE])]) dnl end of file sv-1.0/scripts/000077500000000000000000000000001311074746200134765ustar00rootroot00000000000000sv-1.0/scripts/libsv.pc.in000066400000000000000000000011601311074746200155440ustar00rootroot00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ bindir=@bindir@ datarootdir=@datarootdir@ datadir=@datadir@ docdir=${prefix}/doc includedir=@includedir@ infodir=@infodir@ htmldir=${docdir} libdir=@libdir@ libexecdir=@libexecdir@ localstatedir=@localstatedir@ mandir=@mandir@ sbindir=@sbindir@ sharedstatedir=@sharedstatedir@ sysconfdir=@sysconfdir@ ## ------------------------------------------------------------ Name: @PACKAGE_NAME@ Description: semantic versioning for the C language Version: @LIBSV_PKG_CONFIG_VERSION@ Libs: -L${libdir} -lsv Cflags: -I${includedir} ### end of file # Local Variables: # mode: script # End: sv-1.0/src/000077500000000000000000000000001311074746200125765ustar00rootroot00000000000000sv-1.0/src/comp.c000066400000000000000000000244441311074746200137100ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include #include "comp.h" #include "num.h" #include "id.h" #include "utils.h" static void semver_xrevert(semver_t *semver) { if (semver->major == SEMVER_NUM_X) { semver->major = semver->minor = semver->patch = 0; } else if (semver->minor == SEMVER_NUM_X) { semver->minor = semver->patch = 0; } else if (semver->patch == SEMVER_NUM_X) { semver->patch = 0; } } static semver_comp_t *semver_xconvert(semver_comp_t *self) { if (self->version.major == SEMVER_NUM_X) { self->op = SEMVER_OP_GE; semver_xrevert(&self->version); return self; } if (self->version.minor == SEMVER_NUM_X) { semver_xrevert(&self->version); self->op = SEMVER_OP_GE; self->next = (semver_comp_t *) sv_malloc(sizeof(semver_comp_t)); if (self->next == NULL) { return NULL; } semver_comp_ctor(self->next); self->next->op = SEMVER_OP_LT; self->next->version = self->version; ++self->next->version.major; return self->next; } if (self->version.patch == SEMVER_NUM_X) { semver_xrevert(&self->version); self->op = SEMVER_OP_GE; self->next = (semver_comp_t *) sv_malloc(sizeof(semver_comp_t)); if (self->next == NULL) { return NULL; } semver_comp_ctor(self->next); self->next->op = SEMVER_OP_LT; self->next->version = self->version; ++self->next->version.minor; return self->next; } self->op = SEMVER_OP_EQ; return self; } static char parse_partial(semver_t *self, const char *str, size_t len, size_t *offset) { semver_ctor(self); self->major = self->minor = self->patch = SEMVER_NUM_X; if (*offset < len) { self->raw = str + *offset; if (semver_num_read(&self->major, str, len, offset)) { return 0; } if (*offset >= len || str[*offset] != '.') { return 0; } ++*offset; if (semver_num_read(&self->minor, str, len, offset)) { return 1; } if (*offset >= len || str[*offset] != '.') { return 0; } ++*offset; if (semver_num_read(&self->patch, str, len, offset)) { return 1; } if ((str[*offset] == '-' && semver_id_read(&self->prerelease, str, len, (++*offset, offset))) || (str[*offset] == '+' && semver_id_read(&self->build, str, len, (++*offset, offset)))) { return 1; } self->len = str + *offset - self->raw; return 0; } return 0; } static char parse_hiphen(semver_comp_t *self, const char *str, size_t len, size_t *offset) { semver_t partial; if (parse_partial(&partial, str, len, offset)) { return 1; } self->op = SEMVER_OP_GE; semver_xrevert(&self->version); self->next = (semver_comp_t *) sv_malloc(sizeof(semver_comp_t)); if (self->next == NULL) { return 1; } semver_comp_ctor(self->next); self->next->op = SEMVER_OP_LT; if (partial.minor == SEMVER_NUM_X) { self->next->version.major = partial.major + 1; } else if (partial.patch == SEMVER_NUM_X) { self->next->version.major = partial.major; self->next->version.minor = partial.minor + 1; } else { self->next->op = SEMVER_OP_LE; self->next->version = partial; } return 0; } static char parse_tidle(semver_comp_t *self, const char *str, size_t len, size_t *offset) { semver_t partial; if (parse_partial(&self->version, str, len, offset)) { return 1; } semver_xrevert(&self->version); self->op = SEMVER_OP_GE; partial = self->version; if (partial.major != 0) { ++partial.major; partial.minor = partial.patch = 0; } else if (partial.minor != 0) { ++partial.minor; partial.patch = 0; } else { ++partial.patch; } self->next = (semver_comp_t *) sv_malloc(sizeof(semver_comp_t)); if (self->next == NULL) { return 1; } semver_comp_ctor(self->next); self->next->op = SEMVER_OP_LT; self->next->version = partial; return 0; } static char parse_caret(semver_comp_t *self, const char *str, size_t len, size_t *offset) { semver_t partial; if (parse_partial(&self->version, str, len, offset)) { return 1; } semver_xrevert(&self->version); self->op = SEMVER_OP_GE; partial = self->version; if (partial.minor || partial.patch) { ++partial.minor; partial.patch = 0; } else { ++partial.major; partial.minor = partial.patch = 0; } self->next = (semver_comp_t *) sv_malloc(sizeof(semver_comp_t)); if (self->next == NULL) { return 1; } semver_comp_ctor(self->next); self->next->op = SEMVER_OP_LT; self->next->version = partial; return 0; } void semver_comp_ctor(semver_comp_t *self) { #ifndef _MSC_VER *self = (semver_comp_t) {0}; #else self->next = NULL; self->op = SEMVER_OP_EQ; semver_ctor(&self->version); #endif } void semver_comp_dtor(semver_comp_t *self) { if (self && self->next) { semver_comp_dtor(self->next); free(self->next); self->next = NULL; } } char semver_compn(semver_comp_t *self, const char *str, size_t len) { size_t offset = 0; if (len > SV_COMP_MAX_LEN) { return 1; } if (semver_comp_read(self, str, len, &offset) || offset < len) { semver_comp_dtor(self); return 1; } return 0; } char semver_comp_read(semver_comp_t *self, const char *str, size_t len, size_t *offset) { semver_comp_ctor(self); while (*offset < len) { switch (str[*offset]) { case '^': ++*offset; if (parse_tidle(self, str, len, offset)) { return 1; } self = self->next; goto next; case '~': ++*offset; if (parse_caret(self, str, len, offset)) { return 1; } self = self->next; goto next; case '>': ++*offset; if (*offset < len && str[*offset] == '=') { ++*offset; self->op = SEMVER_OP_GE; } else { self->op = SEMVER_OP_GT; } if (parse_partial(&self->version, str, len, offset)) { return 1; } semver_xrevert(&self->version); goto next; case '<': ++*offset; if (*offset < len && str[*offset] == '=') { ++*offset; self->op = SEMVER_OP_LE; } else { self->op = SEMVER_OP_LT; } if (parse_partial(&self->version, str, len, offset)) { return 1; } semver_xrevert(&self->version); goto next; case '=': ++*offset; self->op = SEMVER_OP_EQ; if (parse_partial(&self->version, str, len, offset)) { return 1; } semver_xrevert(&self->version); goto next; default: goto range; } } range: if (parse_partial(&self->version, str, len, offset)) { return 1; } if (*offset < len && str[*offset] == ' ' && *offset + 1 < len && str[*offset + 1] == '-' && *offset + 2 < len && str[*offset + 2] == ' ') { *offset += 3; if (parse_hiphen(self, str, len, offset)) { return 1; } self = self->next; } else { self = semver_xconvert(self); if (self == NULL) { return 1; } } next: if (*offset < len && str[*offset] == ' ' && *offset < len + 1 && str[*offset + 1] != ' ' && str[*offset + 1] != '|') { ++*offset; if (*offset < len) { self->next = (semver_comp_t *) sv_malloc(sizeof(semver_comp_t)); if (self->next == NULL) { return 1; } return semver_comp_read(self->next, str, len, offset); } return 1; } return 0; } char semver_and(semver_comp_t *left, const char *str, size_t len) { semver_comp_t *comp, *tail; if (len > 0) { comp = (semver_comp_t *) sv_malloc(sizeof(semver_comp_t)); if (NULL == comp) { return 1; } if (semver_compn(comp, str, len)) { sv_free(comp); return 1; } if (NULL == left->next) { left->next = comp; } else { tail = left->next; while (tail->next) tail = tail->next; tail->next = comp; } return 0; } return 1; } bool semver_comp_pmatch(const semver_t *self, const semver_comp_t *comp) { char result = semver_pcmp(self, &comp->version); if (result < 0 && comp->op != SEMVER_OP_LT && comp->op != SEMVER_OP_LE) { return false; } if (result > 0 && comp->op != SEMVER_OP_GT && comp->op != SEMVER_OP_GE) { return false; } if (result == 0 && comp->op != SEMVER_OP_EQ && comp->op != SEMVER_OP_LE && comp->op != SEMVER_OP_GE) { return false; } if (comp->next) { return semver_comp_pmatch(self, comp->next); } return true; } bool semver_comp_matchn(const semver_t *self, const char *comp_str, size_t comp_len) { semver_comp_t comp; bool result; if (semver_compn(&comp, comp_str, comp_len)) { return false; } result = semver_comp_pmatch(self, &comp); semver_comp_dtor(&comp); return result; } int semver_comp_pwrite(const semver_comp_t *self, char *buffer, size_t len) { char semver[SV_COMP_MAX_LEN], next[SV_COMP_MAX_LEN]; semver_write(self->version, semver, SV_COMP_MAX_LEN); if (self->next) { return snprintf(buffer, len, "%s%s %.*s", semver_op_string(self->op), semver, semver_comp_pwrite(self->next, next, SV_COMP_MAX_LEN), next ); } return snprintf(buffer, len, "%s%s", semver_op_string(self->op), semver); } sv-1.0/src/comp.h000066400000000000000000000030041311074746200137020ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #ifndef SV_COMP_H__ # define SV_COMP_H__ #include "version.h" #define SV_COMP_MAX_LEN (512) void semver_comp_ctor(semver_comp_t *self); char semver_comp_read(semver_comp_t *self, const char *str, size_t len, size_t *offset); #endif /* SV_COMP_H__ */ sv-1.0/src/id.c000066400000000000000000000072111311074746200133370ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include #include #include "id.h" void semver_id_ctor(semver_id_t *self) { #ifndef _MSC_VER *self = (semver_id_t) {true}; #else self->next = NULL; self->len = 0; self->raw = NULL; self->num = 0; self->numeric = true; #endif } void semver_id_dtor(semver_id_t *self) { if (self && self->next) { semver_id_dtor(self->next); sv_free(self->next); self->next = NULL; } } char semver_id_read(semver_id_t *self, const char *str, size_t len, size_t *offset) { size_t i = 0; char is_zero = 0; semver_id_ctor(self); while (*offset < len) { if (isalnum(str[*offset]) || str[*offset] == '-') { if (!isdigit(str[*offset])) { is_zero = 0; self->numeric = false; } else { if (i == 0) { is_zero = str[*offset] == '0'; } else if (is_zero) { return 1; } } ++i, ++*offset; continue; } break; } if (!i) { return 1; } self->raw = str + *offset - i; self->len = i; if (!is_zero && self->numeric) { self->num = (int) strtol(self->raw, NULL, 0); } if (str[*offset] == '.') { self->next = (semver_id_t *) sv_malloc(sizeof(semver_id_t)); if (self->next == NULL) { return 1; } ++*offset; return semver_id_read(self->next, str, len, offset); } return 0; } char semver_id_pcmp(const semver_id_t *self, const semver_id_t *other) { char s; if (self->len && !other->len) { return -1; } if (!self->len && other->len) { return 1; } if (!self->len) { return 0; } if (self->numeric && other->numeric) { if (self->num > other->num) { return 1; } if (self->num < other->num) { return -1; } } else if ((s = (char) memcmp(self->raw, other->raw, self->len > other->len ? self->len : other->len)) != 0) { return s; } if (!self->next && other->next) { return -1; } if (self->next && !other->next) { return 1; } if (!self->next) { return 0; } return semver_id_pcmp(self->next, other->next); } int semver_id_pwrite(const semver_id_t *self, char *buffer, size_t len) { char next[SV_MAX_LEN]; if (self->next) { return snprintf(buffer, len, "%.*s.%.*s", (int) self->len, self->raw, semver_id_pwrite(self->next, next, SV_MAX_LEN), next ); } return snprintf(buffer, len, "%.*s", (int) self->len, self->raw); } sv-1.0/src/id.h000066400000000000000000000034521311074746200133470ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #ifndef SV_ID_H__ # define SV_ID_H__ #include "version.h" void semver_id_ctor(semver_id_t *self); void semver_id_dtor(semver_id_t *self); char semver_id_read(semver_id_t *self, const char *str, size_t len, size_t *offset); int semver_id_pwrite(const semver_id_t *self, char *buffer, size_t len); char semver_id_pcmp(const semver_id_t *self, const semver_id_t *other); #define semver_id_write(self, buffer, len) semver_id_pwrite(&(self), buffer, len) #define semver_id_comp(self, other) semver_id_pcmp(&(self), &(other)) #endif /* SV_ID_H__ */ sv-1.0/src/num.c000066400000000000000000000041331311074746200135420ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include #include "num.h" char semver_num_read(int *self, const char *str, size_t len, size_t *offset) { char *endptr; *self = 0; if (*offset >= len) { return 1; } switch (str[*offset]) { case 'x': case 'X': case '*': *self = SEMVER_NUM_X; ++*offset; break; case '0': ++*offset; if (*offset < len && isdigit(str[*offset])) { return 1; } *self = 0; break; default: if (isdigit(str[*offset])) { *self = (int) strtol(str + *offset, &endptr, 0); *offset += endptr - str - *offset; } else { return 1; } break; } return 0; } char semver_num_cmp(int self, int other) { if (self > other) { return 1; } if (self < other) { return -1; } return 0; } sv-1.0/src/num.h000066400000000000000000000027251311074746200135540ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #ifndef SV_NUM_H__ # define SV_NUM_H__ #include "version.h" char semver_num_read(int *self, const char *str, size_t len, size_t *offset); char semver_num_cmp(int self, int other); #endif /* SV_NUM_H__ */ sv-1.0/src/range.c000066400000000000000000000077751311074746200140560ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include #include "range.h" #include "comp.h" void semver_range_ctor(semver_range_t *self) { #ifndef _MSC_VER *self = (semver_range_t) {0}; #else self->next = NULL; semver_comp_ctor(&self->comp); #endif } void semver_range_dtor(semver_range_t *self) { if (self && self->next) { semver_range_dtor(self->next); sv_free(self->next); self->next = NULL; } } char semver_rangen(semver_range_t *self, const char *str, size_t len) { size_t offset = 0; if (len > SV_RANGE_MAX_LEN) { return 1; } if (semver_range_read(self, str, len, &offset) || offset < len) { semver_range_dtor(self); return 1; } return 0; } char semver_range_read(semver_range_t *self, const char *str, size_t len, size_t *offset) { semver_range_ctor(self); if (semver_comp_read(&self->comp, str, len, offset)) { return 1; } while (*offset < len && str[*offset] == ' ') ++*offset; if (*offset < len && str[*offset] == '|' && *offset + 1 < len && str[*offset + 1] == '|') { *offset += 2; while (*offset < len && str[*offset] == ' ') ++*offset; self->next = (semver_range_t *) sv_malloc(sizeof(semver_range_t)); if (self->next == NULL) { return 1; } return semver_range_read(self->next, str, len, offset); } return 0; } char semver_or(semver_range_t *left, const char *str, size_t len) { semver_range_t *range, *tail; if (len > 0) { range = (semver_range_t *) sv_malloc(sizeof(semver_range_t)); if (NULL == range) { return 1; } if (semver_rangen(range, str, len)) { sv_free(range); return 1; } if (NULL == left->next) { left->next = range; } else { tail = left->next; while (tail->next) tail = tail->next; tail->next = range; } return 0; } return 1; } bool semver_range_pmatch(const semver_t *self, const semver_range_t *range) { return semver_comp_pmatch(self, &range->comp) ? true : range->next ? semver_range_pmatch(self, range->next) : false; } bool semver_range_matchn(const semver_t *self, const char *range_str, size_t range_len) { semver_range_t range; bool result; if (semver_rangen(&range, range_str, range_len)) { return false; } result = semver_range_pmatch(self, &range); semver_range_dtor(&range); return result; } int semver_range_pwrite(const semver_range_t *self, char *buffer, size_t len) { char comp[SV_RANGE_MAX_LEN], next[SV_RANGE_MAX_LEN]; if (self->next) { return snprintf(buffer, len, "%.*s || %.*s", semver_comp_write(self->comp, comp, SV_RANGE_MAX_LEN), comp, semver_range_pwrite(self->next, next, SV_RANGE_MAX_LEN), next ); } return snprintf(buffer, len, "%.*s", semver_comp_write(self->comp, comp, SV_RANGE_MAX_LEN), comp); } sv-1.0/src/range.h000066400000000000000000000030141311074746200140410ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #ifndef SV_RANGE_H__ # define SV_RANGE_H__ #include "version.h" #define SV_RANGE_MAX_LEN (512) void semver_range_ctor(semver_range_t *self); char semver_range_read(semver_range_t *self, const char *str, size_t len, size_t *offset); #endif /* SV_RANGE_H__ */ sv-1.0/src/utils.c000066400000000000000000000060011311074746200140770ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include #include "utils.h" #include "comp.h" #include "range.h" /*!\brief Serialise the version to the STREAM. When successful: return the * number of bytes written and set "errno" to zero. When unsuccessful: * set "errno" to an error code. */ size_t semver_fwrite(const semver_t *self, FILE *stream) { char buffer[SV_MAX_LEN]; int cs; if ((cs = semver_pwrite(self, buffer, SV_MAX_LEN)) == 0) { return 0; } errno = 0; return fwrite(buffer, sizeof(char), (size_t) cs, stream); } /*!\brief Serialise the comparator to the STREAM. When successful: return the * number of bytes written and set "errno" to zero. When unsuccessful: * set "errno" to an error code. */ size_t semver_comp_fwrite(const semver_comp_t *self, FILE *stream) { char buffer[SV_COMP_MAX_LEN]; int cs; if ((cs = semver_comp_pwrite(self, buffer, SV_COMP_MAX_LEN)) == 0) { return 0; } errno = 0; return fwrite(buffer, sizeof(char), (size_t) cs, stream); } /*!\brief Serialise the range to the STREAM. When successful: return the * number of bytes written and set "errno" to zero. When unsuccessful: * set "errno" to an error code. */ size_t semver_range_fwrite(const semver_range_t *self, FILE *stream) { char buffer[SV_RANGE_MAX_LEN]; int cs; if ((cs = semver_range_pwrite(self, buffer, SV_RANGE_MAX_LEN)) == 0) { return 0; } errno = 0; return fwrite(buffer, sizeof(char), (size_t) cs, stream); } const char *semver_op_string(enum semver_op op) { switch (op) { case SEMVER_OP_EQ: return ""; case SEMVER_OP_LT: return "<"; case SEMVER_OP_LE: return "<="; case SEMVER_OP_GT: return ">"; case SEMVER_OP_GE: return ">="; default: return NULL; } } sv-1.0/src/utils.h000066400000000000000000000026241311074746200141130ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #ifndef SV_UTILS_H__ # define SV_UTILS_H__ #include "version.h" const char *semver_op_string(enum semver_op op); #endif /* SV_UTILS_H__ */ sv-1.0/src/version.c000066400000000000000000000102231311074746200144250ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include "version.h" #include "num.h" #include "id.h" void semver_ctor(semver_t *self) { #ifndef _MSC_VER *self = (semver_t) {0}; #else self->len = 0; self->raw = NULL; self->major = 0; self->minor = 0; self->patch = 0; semver_id_ctor(&self->prerelease); semver_id_ctor(&self->build); #endif } void semver_dtor(semver_t *self) { semver_id_dtor(&self->prerelease); semver_id_dtor(&self->build); } char semvern(semver_t *self, const char *str, size_t len) { size_t offset = 0; if (len > SV_MAX_LEN) { return 1; } if (semver_read(self, str, len, &offset) || offset < len) { semver_dtor(self); return 1; } return 0; } char semver_read(semver_t *self, const char *str, size_t len, size_t *offset) { if (*offset < len) { semver_ctor(self); self->raw = str + *offset; if (str[*offset] == 'v') { ++*offset; } if (semver_num_read(&self->major, str, len, offset) || self->major == SEMVER_NUM_X || *offset >= len || str[*offset] != '.' || semver_num_read(&self->minor, str, len, (++*offset, offset)) || self->minor == SEMVER_NUM_X || *offset >= len || str[*offset] != '.' || semver_num_read(&self->patch, str, len, (++*offset, offset)) || self->patch == SEMVER_NUM_X || (str[*offset] == '-' && semver_id_read(&self->prerelease, str, len, (++*offset, offset))) || (str[*offset] == '+' && semver_id_read(&self->build, str, len, (++*offset, offset)))) { self->len = str + *offset - self->raw; return 1; } self->len = str + *offset - self->raw; return 0; } return 1; } char semver_pcmp(const semver_t *self, const semver_t *other) { char result; if ((result = semver_num_cmp(self->major, other->major)) != 0) { return result; } if ((result = semver_num_cmp(self->minor, other->minor)) != 0) { return result; } if ((result = semver_num_cmp(self->patch, other->patch)) != 0) { return result; } return semver_id_comp(self->prerelease, other->prerelease); } int semver_pwrite(const semver_t *self, char *buffer, size_t len) { char prerelease[SV_MAX_LEN], build[SV_MAX_LEN]; if (self->prerelease.len && self->build.len) { return snprintf(buffer, len, "%d.%d.%d-%.*s+%.*s", self->major, self->minor, self->patch, semver_id_write(self->prerelease, prerelease, SV_MAX_LEN), prerelease, semver_id_write(self->build, build, SV_MAX_LEN), build ); } if (self->prerelease.len) { return snprintf(buffer, len, "%d.%d.%d-%.*s", self->major, self->minor, self->patch, semver_id_write(self->prerelease, prerelease, SV_MAX_LEN), prerelease ); } if (self->build.len) { return snprintf(buffer, len, "%d.%d.%d+%.*s", self->major, self->minor, self->patch, semver_id_write(self->build, build, SV_MAX_LEN), build ); } return snprintf(buffer, len, "%d.%d.%d", self->major, self->minor, self->patch); } sv-1.0/src/version.h000066400000000000000000000031461311074746200144400ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #ifndef SV_VERSION_H__ # define SV_VERSION_H__ #include "semver.h" #ifdef _MSC_VER # define snprintf(s, maxlen, fmt, ...) _snprintf_s(s, _TRUNCATE, maxlen, fmt, __VA_ARGS__) #endif #define SV_MAX_LEN (256) void semver_ctor(semver_t *self); char semver_read(semver_t *self, const char *str, size_t len, size_t *offset); #endif /* SV_VERSION_H__ */ sv-1.0/test/000077500000000000000000000000001311074746200127665ustar00rootroot00000000000000sv-1.0/test/CMakeLists.txt000066400000000000000000000011201311074746200155200ustar00rootroot00000000000000add_executable(version version.c) target_link_libraries(version ${PROJECT_NAME}) add_test(version version) add_executable(comp comp.c) target_link_libraries(comp ${PROJECT_NAME}) add_test(comp comp) add_executable(range range.c) target_link_libraries(range ${PROJECT_NAME}) add_test(range range) add_executable(match match.c) target_link_libraries(match ${PROJECT_NAME}) add_test(match match) add_executable(utils utils.c) target_link_libraries(utils ${PROJECT_NAME}) add_test(utils utils) add_executable(usage usage.c) target_link_libraries(usage ${PROJECT_NAME}) add_test(usage usage) sv-1.0/test/comp.c000066400000000000000000000231421311074746200140720ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include #include "semver.h" #define STRNSIZE(s) (s), sizeof(s)-1 int test_read(const char *expected, const char *str, size_t len) { unsigned slen; char buffer[1024]; semver_comp_t comp = {0}; printf("test: `%.*s`", (int) len, str); if (semver_compn(&comp, str, len)) { puts(" \tcouldn't parse"); return 1; } slen = (unsigned) semver_comp_write(comp, buffer, 1024); printf(" \t=> \t`%.*s`", slen, buffer); if (memcmp(expected, buffer, (size_t) slen > len ? slen : len) != 0) { printf(" != `%s`\n", expected); semver_comp_dtor(&comp); return 1; } printf(" == `%s`\n", expected); semver_comp_dtor(&comp); return 0; } int test_and(const char *expected, const char *base_str, size_t base_len, const char *str, size_t len) { unsigned slen; char buffer[1024]; semver_comp_t comp = {0}; printf("test and: `%.*s`", (int) base_len, base_str); if (semver_compn(&comp, base_str, base_len)) { puts(" \tcouldn't parse"); return 1; } if (semver_and(&comp, str, len)) { puts(" \tand failed"); return 1; } slen = (unsigned) semver_comp_write(comp, buffer, 1024); printf(" \t=> \t`%.*s`", slen, buffer); if (memcmp(expected, buffer, (size_t) slen > base_len + len + 1 ? slen : base_len + len + 1) != 0) { printf(" != `%s`\n", expected); semver_comp_dtor(&comp); return 1; } printf(" == `%s`\n", expected); semver_comp_dtor(&comp); return 0; } int main(void) { puts("failure:"); if (test_read("", STRNSIZE("* ")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("* ")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("* |")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("* || *")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("abc")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE(">")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("<=")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("~")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("^")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("=")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE(">a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("<1.a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("~1.a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("^1.a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("=1.a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.3 ")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.3 -")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.3 - ")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.3 -a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.3 - a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.3 - 1.2.a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("a.2.3")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.a.3")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.3-")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.3-alpha+")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("1.2.3+")) == 0) { return EXIT_FAILURE; } if (test_read("1.2.3", STRNSIZE("1.2.3"))) { return EXIT_FAILURE; } puts("\nsome prerelease and build:"); if (test_read(">=0.0.0 1.2.3-alpha", STRNSIZE("* 1.2.3-alpha"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0 1.2.3-alpha.2", STRNSIZE("* 1.2.3-alpha.2"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0 1.2.3+77", STRNSIZE("* 1.2.3+77"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0 1.2.3+77.2", STRNSIZE("* 1.2.3+77.2"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0 1.2.3-alpha.2+77", STRNSIZE("* 1.2.3-alpha.2+77"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0 1.2.3-alpha.2+77.2", STRNSIZE("* 1.2.3-alpha.2+77.2"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0 1.2.3-al-pha.2+77", STRNSIZE("* 1.2.3-al-pha.2+77"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0 1.2.3-al-pha.2+77.2", STRNSIZE("* 1.2.3-al-pha.2+77.2"))) { return EXIT_FAILURE; } puts("\nx-range:"); if (test_read(">=0.0.0", STRNSIZE("*"))) { return EXIT_FAILURE; } if (test_read(">=1.0.0 <2.0.0", STRNSIZE("1.x"))) { return EXIT_FAILURE; } if (test_read(">=1.2.0 <1.3.0", STRNSIZE("1.2.x"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0", STRNSIZE(""))) { return EXIT_FAILURE; } if (test_read(">=1.0.0 <2.0.0", STRNSIZE("1"))) { return EXIT_FAILURE; } if (test_read(">=1.2.0 <1.3.0", STRNSIZE("1.2"))) { return EXIT_FAILURE; } puts("\nhyphen:"); if (test_read(">=1.2.3 <=2.3.4", STRNSIZE("1.2.3 - 2.3.4"))) { return EXIT_FAILURE; } if (test_read(">=1.2.0 <=2.3.4", STRNSIZE("1.2 - 2.3.4"))) { return EXIT_FAILURE; } if (test_read(">=1.2.3 <2.4.0", STRNSIZE("1.2.3 - 2.3"))) { return EXIT_FAILURE; } if (test_read(">=1.2.3 <3.0.0", STRNSIZE("1.2.3 - 2"))) { return EXIT_FAILURE; } puts("\ntidle:"); if (test_read(">=1.2.3 <1.3.0", STRNSIZE("~1.2.3"))) { return EXIT_FAILURE; } if (test_read(">=1.2.0 <1.3.0", STRNSIZE("~1.2"))) { return EXIT_FAILURE; } if (test_read(">=1.0.0 <2.0.0", STRNSIZE("~1"))) { return EXIT_FAILURE; } if (test_read(">=0.2.3 <0.3.0", STRNSIZE("~0.2.3"))) { return EXIT_FAILURE; } if (test_read(">=0.2.0 <0.3.0", STRNSIZE("~0.2"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0 <1.0.0", STRNSIZE("~0"))) { return EXIT_FAILURE; } puts("\ncaret:"); if (test_read(">=1.2.3 <2.0.0", STRNSIZE("^1.2.3"))) { return EXIT_FAILURE; } if (test_read(">=0.2.3 <0.3.0", STRNSIZE("^0.2.3"))) { return EXIT_FAILURE; } if (test_read(">=0.0.3 <0.0.4", STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } puts("\nprimitive:"); if (test_read(">=1.2.3 <2.0.0", STRNSIZE(">=1.2.3 <2.0"))) { return EXIT_FAILURE; } if (test_read(">=0.2.3 <0.3.0", STRNSIZE(">=0.2.3 <0.3"))) { return EXIT_FAILURE; } if (test_read(">=0.5.0 <0.0.4", STRNSIZE(">=0.5 <0.0.4"))) { return EXIT_FAILURE; } if (test_read(">0.0.3", STRNSIZE(">0.0.3"))) { return EXIT_FAILURE; } if (test_read("0.0.3", STRNSIZE("=0.0.3"))) { return EXIT_FAILURE; } if (test_read("9.0.0", STRNSIZE("=9"))) { return EXIT_FAILURE; } puts("\nand:"); if (test_and(">=0.0.0 >=0.0.3 <0.0.4", STRNSIZE("*"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_and(">=1.0.0 <2.0.0 >=0.0.3 <0.0.4", STRNSIZE("1.x"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_and(">=1.2.0 <1.3.0 >=0.0.3 <0.0.4", STRNSIZE("1.2.x"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_and(">=1.2.0 <1.3.0 >=1.2.0 <1.3.0 >=0.0.3 <0.0.4", STRNSIZE("1.2 1.2.x"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_and(">=1.0.0 <2.0.0 >=0.0.3 <0.0.4", STRNSIZE("1"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_and(">=1.2.0 <1.3.0 >=0.0.3 <0.0.4", STRNSIZE("1.2"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_and("", STRNSIZE("1.2"), STRNSIZE("")) == 0) { return EXIT_FAILURE; } if (test_and("", STRNSIZE("1.2"), STRNSIZE("a")) == 0) { return EXIT_FAILURE; } if (test_and("", STRNSIZE("1.2"), STRNSIZE("1.2.x abc")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget " "dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascet" "ur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, s")) == 0) { return EXIT_FAILURE; } return EXIT_SUCCESS; } sv-1.0/test/match.c000066400000000000000000000307771311074746200142440ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include "semver.h" #define STRNSIZE(s) (s), sizeof(s)-1 int test_matchn(bool expected, const char *semver_str, size_t semver_len, const char *comp_str, size_t comp_len) { bool result; semver_t semver = {0}; printf("test: `%.*s` ^ `%.*s`", (int) semver_len, semver_str, (int) comp_len, comp_str); if (semvern(&semver, semver_str, semver_len)) { puts(" \tcouldn't parse semver"); return 1; } result = semver_comp_matchn(&semver, comp_str, comp_len); printf(" \t=> %d\t", result); if (result != expected) { printf(" != `%d`\n", expected); semver_dtor(&semver); return 1; } printf(" == `%d`\n", expected); semver_dtor(&semver); return 0; } int test_rmatchn(bool expected, const char *semver_str, size_t semver_len, const char *range_str, size_t range_len) { bool result; semver_t semver = {0}; printf("test: `%.*s` ^ `%.*s`", (int) semver_len, semver_str, (int) range_len, range_str); if (semvern(&semver, semver_str, semver_len)) { puts(" \tcouldn't parse semver"); return 1; } result = semver_range_matchn(&semver, range_str, range_len); printf(" \t=> %d\t", result); if (result != expected) { printf(" != `%d`\n", expected); semver_dtor(&semver); return 1; } printf(" == `%d`\n", expected); semver_dtor(&semver); return 0; } int main(void) { if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1.2.3"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1.2.x"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1.x.x"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1.x"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("*"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE(">1"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE(">2"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE(">=2"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE("<1"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE("<=1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE(">=1.2.3"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE(">1.2.3"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE("<1.2.3"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("v1.2.3"), STRNSIZE("<=1.2.3"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("v1.2.3"), STRNSIZE("2.x"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("<0.0.1-99"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("<=0.0.1-99"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("<=0.0.1-98"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("=0.0.1-98"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE(">=0.0.1-98"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE(">=0.0.1-97"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE(">0.0.1-97"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha"), STRNSIZE("0.0.1-alpha"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("<0.0.1-99"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<0.0.1-alpha.99"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<=0.0.1-alpha.99"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<=0.0.1-alpha.98"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("=0.0.1-alpha.98"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">=0.0.1-alpha.98"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">=0.0.1-alpha.97"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">0.0.1-alpha.97"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<0.0.1-alpha.99.1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<=0.0.1-alpha.99.1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("<=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">=0.0.1-alpha.97.1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE(">0.0.1-alpha.97.1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("<0.0.1-alpha.99.1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("<=0.0.1-alpha.99.1"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("<=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_matchn(false, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE(">=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE(">=0.0.1-alpha.97.1"))) { return EXIT_FAILURE; } if (test_matchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE(">0.0.1-alpha.97.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1.2.3"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1.2.x"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1.x.x"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1.x"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || *"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >1"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >2"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >=2"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || <1"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || <=1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >=1.2.3"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || >1.2.3"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || <1.2.3"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("v1.2.3"), STRNSIZE("9.x || <=1.2.3"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("v1.2.3"), STRNSIZE("9.x || 2.x"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || <0.0.1-99"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || <=0.0.1-99"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || <=0.0.1-98"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || =0.0.1-98"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || >=0.0.1-98"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || >=0.0.1-97"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || >0.0.1-97"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha"), STRNSIZE("9.x || 0.0.1-alpha"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-98"), STRNSIZE("9.x || <0.0.1-99"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <0.0.1-alpha.99"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <=0.0.1-alpha.99"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <=0.0.1-alpha.98"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || =0.0.1-alpha.98"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >=0.0.1-alpha.98"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >=0.0.1-alpha.97"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >0.0.1-alpha.97"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <0.0.1-alpha.99.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <=0.0.1-alpha.99.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || <=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || =0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >=0.0.1-alpha.97.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98"), STRNSIZE("9.x || >0.0.1-alpha.97.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || <0.0.1-alpha.99.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || <=0.0.1-alpha.99.1"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || <=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_rmatchn(false, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || =0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || >=0.0.1-alpha.98.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || >=0.0.1-alpha.97.1"))) { return EXIT_FAILURE; } if (test_rmatchn(true, STRNSIZE("0.0.1-alpha.98.1.3"), STRNSIZE("9.x || >0.0.1-alpha.97.1"))) { return EXIT_FAILURE; } return EXIT_SUCCESS; } sv-1.0/test/range.c000066400000000000000000000147571311074746200142440ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include #include "semver.h" #define STRNSIZE(s) (s), sizeof(s)-1 int test_read(const char *expected, const char *str, size_t len) { unsigned slen; char buffer[1024]; semver_range_t range = {0}; printf("test: `%.*s`", (int) len, str); if (semver_rangen(&range, str, len)) { puts(" \tcouldn't parse"); return 1; } slen = (unsigned) semver_range_write(range, buffer, 1024); printf(" \t=> \t`%.*s`", slen, buffer); if (memcmp(expected, buffer, (size_t) slen > len ? slen : len) != 0) { printf(" != `%s`\n", expected); semver_range_dtor(&range); return 1; } printf(" == `%s`\n", expected); semver_range_dtor(&range); return 0; } int test_or(const char *expected, const char *base_str, size_t base_len, const char *str, size_t len) { unsigned slen; char buffer[1024]; semver_range_t range = {0}; printf("test and: `%.*s`", (int) base_len, base_str); if (semver_rangen(&range, base_str, base_len)) { puts(" \tcouldn't parse base"); return 1; } if (semver_or(&range, str, len)) { puts(" \tand failed"); return 1; } slen = (unsigned) semver_range_write(range, buffer, 1024); printf(" \t=> \t`%.*s`", slen, buffer); if (memcmp(expected, buffer, (size_t) slen > base_len + len + 1 ? slen : base_len + len + 1) != 0) { printf(" != `%s`\n", expected); semver_range_dtor(&range); return 1; } printf(" == `%s`\n", expected); semver_range_dtor(&range); return 0; } int main(void) { puts("failure:"); if (test_read("", STRNSIZE("* |")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("* ||a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("* || a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("* || 1.a")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget " "dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascet" "ur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, s")) == 0) { return EXIT_FAILURE; } puts("\nx-range:"); if (test_read(">=0.0.0 || 1.2.3", STRNSIZE("* || 1.2.3"))) { return EXIT_FAILURE; } if (test_read(">=1.0.0 <2.0.0 || >=2.0.0 <3.0.0", STRNSIZE("1.x || 2.x"))) { return EXIT_FAILURE; } if (test_read(">=1.2.0 <1.3.0 || 3.0.0", STRNSIZE("1.2.x || 3.0.0"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0", STRNSIZE(""))) { return EXIT_FAILURE; } if (test_read(">=1.0.0 <2.0.0 || >=2.0.0 <3.0.0 || >=3.0.0 <4.0.0", STRNSIZE("1 || 2 || 3"))) { return EXIT_FAILURE; } if (test_read(">=1.2.0 <1.3.0 || >=5.0.0", STRNSIZE("1.2 || >=5"))) { return EXIT_FAILURE; } puts("\nhyphen:"); if (test_read(">=1.2.3 <=2.3.4 || >=5.0.0", STRNSIZE("1.2.3 - 2.3.4 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=1.2.0 <=2.3.4 || >=5.0.0", STRNSIZE("1.2 - 2.3.4 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=1.2.3 <2.4.0 || >=5.0.0", STRNSIZE("1.2.3 - 2.3 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=1.2.3 <3.0.0 || >=5.0.0", STRNSIZE("1.2.3 - 2 || >=5"))) { return EXIT_FAILURE; } puts("\ntidle:"); if (test_read(">=1.2.3 <1.3.0 || >=5.0.0", STRNSIZE("~1.2.3 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=1.2.0 <1.3.0 || >=5.0.0", STRNSIZE("~1.2 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=1.0.0 <2.0.0 || >=5.0.0", STRNSIZE("~1 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=0.2.3 <0.3.0 || >=5.0.0", STRNSIZE("~0.2.3 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=0.2.0 <0.3.0 || >=5.0.0", STRNSIZE("~0.2 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=0.0.0 <1.0.0 || >=5.0.0", STRNSIZE("~0 || >=5"))) { return EXIT_FAILURE; } puts("\ncaret:"); if (test_read(">=1.2.3 <2.0.0 || >=5.0.0", STRNSIZE("^1.2.3 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=0.2.3 <0.3.0 || >=5.0.0", STRNSIZE("^0.2.3 || >=5"))) { return EXIT_FAILURE; } if (test_read(">=0.0.3 <0.0.4 || >=5.0.0", STRNSIZE("^0.0.3 || >=5"))) { return EXIT_FAILURE; } puts("\nand:"); if (test_or(">=0.0.0 || >=0.0.3 <0.0.4", STRNSIZE("*"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_or(">=1.0.0 <2.0.0 || >=0.0.3 <0.0.4", STRNSIZE("1.x"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_or(">=1.2.0 <1.3.0 || >=0.0.3 <0.0.4", STRNSIZE("1.2.x"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_or(">=1.2.0 <1.3.0 || >=1.2.0 <1.3.0 || >=0.0.3 <0.0.4", STRNSIZE("1.2 || 1.2.x"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_or(">=1.0.0 <2.0.0 || >=0.0.3 <0.0.4", STRNSIZE("1"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_or(">=1.2.0 <1.3.0 || >=0.0.3 <0.0.4", STRNSIZE("1.2"), STRNSIZE("^0.0.3"))) { return EXIT_FAILURE; } if (test_or("", STRNSIZE("1.2"), STRNSIZE("")) == 0) { return EXIT_FAILURE; } if (test_or("", STRNSIZE("1.2"), STRNSIZE("a")) == 0) { return EXIT_FAILURE; } if (test_or("", STRNSIZE("1.2"), STRNSIZE("1.2.x || abc")) == 0) { return EXIT_FAILURE; } return EXIT_SUCCESS; } sv-1.0/test/usage.c000066400000000000000000000033431311074746200142410ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include "semver.h" int main(void) { semver_t semver = {0}; semver(&semver, "v1.2.3-alpha.1"); assert(1 == semver.major); assert(2 == semver.minor); assert(3 == semver.patch); assert(0 == memcmp("alpha", semver.prerelease.raw, sizeof("alpha")-1)); assert(0 == memcmp("1", semver.prerelease.next->raw, sizeof("1")-1)); assert(true == semver_rmatch(semver, "1.2.1 || >=1.2.3-alpha <1.2.5")); semver_dtor(&semver); } sv-1.0/test/utils.c000066400000000000000000000051511311074746200142740ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include #include "semver.h" int test_version_fwrite(void) { static const char input_str[] = "1.2.3-alpha.1+x86-64"; semver_t version; int rv; rv = semver(&version, input_str); if (0 == rv) { printf("test_version_fwrite: "); semver_fwrite(&version, stdout); if (0 == errno) { printf("\n"); rv = 0; } } semver_dtor(&version); return rv; } int test_comparator_fwrite(void) { static const char input_str[] = "<=1.2.3"; semver_comp_t comp; int rv; rv = semver_comp(&comp, input_str); if (0 == rv) { printf("test_comparator_fwrite: "); semver_comp_fwrite(&comp, stdout); if (0 == errno) { printf("\n"); rv = 0; } } semver_comp_dtor(&comp); return rv; } int test_range_fwrite(void) { static const char input_str[] = ">=1.2.3 <4.0.0"; semver_range_t range; int rv; rv = semver_range(&range, input_str); if (0 == rv) { printf("test_range_fwrite: "); semver_range_fwrite(&range, stdout); if (0 == errno) { printf("\n"); rv = 0; } } semver_range_dtor(&range); return rv; } int main(void) { if (test_version_fwrite()) { return EXIT_FAILURE; } if (test_comparator_fwrite()) { return EXIT_FAILURE; } if (test_range_fwrite()) { return EXIT_FAILURE; } return EXIT_SUCCESS; } sv-1.0/test/version.c000066400000000000000000000077001311074746200146230ustar00rootroot00000000000000/* * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to */ #include #include #include #include "semver.h" #define STRNSIZE(s) (s), sizeof(s)-1 int test_read(const char *expected, const char *str, size_t len) { unsigned slen; char buffer[1024]; semver_t semver = {0}; printf("test: `%.*s`", (int) len, str); if (semvern(&semver, str, len)) { puts(" \tcouldn't parse"); return 1; } slen = (unsigned) semver_write(semver, buffer, 1024); printf(" \t=> \t`%.*s`", slen, buffer); if (memcmp(expected, buffer, (size_t) slen > len ? slen : len) != 0) { printf(" != `%s`\n", expected); semver_dtor(&semver); return 1; } printf(" == `%s`\n", expected); semver_dtor(&semver); return 0; } int main(void) { if (test_read("0.2.3", STRNSIZE("0.2.3"))) { return EXIT_FAILURE; } if (test_read("1.2.3", STRNSIZE("1.2.3"))) { return EXIT_FAILURE; } if (test_read("1.2.3-alpha", STRNSIZE("v1.2.3-alpha"))) { return EXIT_FAILURE; } if (test_read("1.2.3-alpha.2", STRNSIZE("1.2.3-alpha.2"))) { return EXIT_FAILURE; } if (test_read("1.2.3+77", STRNSIZE("v1.2.3+77"))) { return EXIT_FAILURE; } if (test_read("1.2.3+0", STRNSIZE("v1.2.3+0"))) { return EXIT_FAILURE; } if (test_read("1.2.3+77.2", STRNSIZE("1.2.3+77.2"))) { return EXIT_FAILURE; } if (test_read("1.2.3-alpha.2+77", STRNSIZE("v1.2.3-alpha.2+77"))) { return EXIT_FAILURE; } if (test_read("1.2.3-alpha.2+77.2", STRNSIZE("1.2.3-alpha.2+77.2"))) { return EXIT_FAILURE; } if (test_read("1.2.3-al-pha.2+77", STRNSIZE("v1.2.3-al-pha.2+77"))) { return EXIT_FAILURE; } if (test_read("1.2.3-al-pha.2+77.2", STRNSIZE("1.2.3-al-pha.2+77.2"))) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("vv1.2.3")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("v1.2")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("v1.2.x")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("v1.2.3-")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("v1.2.3+")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("v1.2.3+01")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("v0.01.3")) == 0) { return EXIT_FAILURE; } if (test_read("", STRNSIZE("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget " "dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascet" "ur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, s")) == 0) { return EXIT_FAILURE; } return EXIT_SUCCESS; } sv-1.0/test/xmake.lua000066400000000000000000000016251311074746200146020ustar00rootroot00000000000000set_default(false) set_languages("c99") set_kind("binary") add_deps("sv") add_links("sv") add_includedirs("../include") add_linkdirs("$(buildir)") target("version_test") add_files("version.c") target("comp_test") add_files("comp.c") target("range_test") add_files("range.c") target("match_test") add_files("match.c") target("utils_test") add_files("utils.c") target("usage_test") add_files("usage.c") task("check") on_run(function () import("core.project.task") task.run("run", {target = "version_test"}) task.run("run", {target = "comp_test"}) task.run("run", {target = "range_test"}) task.run("run", {target = "match_test"}) task.run("run", {target = "utils_test"}) task.run("run", {target = "usage_test"}) end) set_menu { usage = "xmake check" , description = "Run tests !" , options = {} } sv-1.0/xmake.lua000066400000000000000000000012131311074746200136140ustar00rootroot00000000000000set_project("libsv") set_version("0.0.1") set_warnings("all", "error") if is_os("macosx") or is_os("ios") then add_cflags("-Wno-nullability-completeness") add_cxxflags("-Wno-nullability-completeness") end if is_mode("release") then set_symbols("hidden") set_optimize("fastest") set_strip("all") end if is_mode("debug") then set_symbols("debug") set_optimize("none") end target("sv") set_default(true) set_languages("c99") set_kind("$(kind)") set_headerdir("$(buildir)/include") add_headers("include/(*.h)") add_includedirs("$(buildir)", "include") add_files("src/*.c") add_subdirs("test")