Skip to content

mwsis/shwild

 
 

Repository files navigation

shwild

SHell-compatible WILDcards is a small, standalone library, implemented in C++ with a C and a C++ API, that provides shell-compatible wildcard matching.

Table of Contents

  1. Introduction
  2. Installation
  3. Components
  4. Examples
  5. Project Information

Introduction

SHell-compatible WILDcards is a small, standalone library, implemented in C++ with a C and a C++ API, that provides shell-compatible wildcard matching.

Installation

The original (~2005) implementation used STLSoft, for discrimination of compilers are library support. However, if the preprocessor symbol SHWILD_NO_STLSOFT is specified, then all dependencies on STLSoft are removed and basic C++-11 features are used instead.

If STLSoft is to be used, then the makefiles require definition of the environment variable STLSOFT that should be set to the root directory of a clone of STLSoft (see Dependencies in this document).

NOTE: an upcoming version of shwild will provide CMake mechanisms for fully-automated installation.

Components

C API / core library

The shwild C API comprises the following functions:

  • shwild_init();
  • shwild_uninit();
  • shwild_match();
  • shwild_match_s();
  • shwild_compile_pattern();
  • shwild_compile_pattern_s();
  • shwild_destroy_pattern();
  • shwild_match_pattern();
  • shwild_match_pattern_s();

and used as in the following simple example:

#include <shwild/shwild.h>

. . .

int r = shwild_init();
if (r < 0) {
    . . . // report failure and exit
} else {
  shwild_handle_t hCompiledPattern;
  int r2 = shwild_compile_pattern("X[0-9]*", 0, &hCompiledPattern);
  if (r2 < 0) {
    . . . // report failure and exit
  } else {
    assert(0 == shwild_match_pattern(hCompiledPattern, "X0"));
    assert(0 == shwild_match_pattern(hCompiledPattern, "X8abc"));
    assert(0 != shwild_match_pattern(hCompiledPattern, "X"));
    assert(0 != shwild_match_pattern(hCompiledPattern, "Y0"));

    shwild_destroy_pattern(hCompiledPattern);
  }

  shwild_uninit();
}

C++ API

The shwild C++ API is a simple wrapper over the shwild C API, with the following components:

  • shwild::Pattern;
  • shwild::PatternException;

and used as in the following simple example:

#include <shwild/shwild.hpp>

. . .

shwild::Pattern pattern("X[0-9]*", 0);

assert( pattern.match("X0"));
assert( pattern.match("X8abc"));
assert(!pattern.match("X"));
assert(!pattern.match("Y0"));

Examples

Examples are provided in the examples directory, along with a markdown description for each.

Project Information

Where to get help

GitHub Page

Contribution guidelines

Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/shwild.

Dependencies

STLSoft (C++ API-only)

The C++ API depends on the STLSoft libraries, version 1.9.134 (or later). Version 1.10.1 beta19 (or later) is recommended.

Related projects

Projects in which shwild is used for testing include:

License

shwild is released under the 3-clause BSD license. See LICENSE for details.

About

SHell-compatible WILDcards

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 57.8%
  • C 31.9%
  • CMake 5.5%
  • Shell 4.8%