Topic: Expanding wildcards from command-line


Author: Jimisola Laursen <dat97jla@ludat.lth.se>
Date: 1997/10/13
Raw View
Hello,

Are there any routines for handling file-wildcards in Standard ANSI C/C++.

I need information on which headerfile(s) to include also some examples
would do great.

Please send a copy of your reply to my email-address as well.

/Jimisola <dat97jla@ludat.lth.se>
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Pete Forman <gsez020@compo.bedford.waii.com>
Date: 1997/10/13
Raw View
>>>>> "Jimisola" == Jimisola Laursen <dat97jla@ludat.lth.se> writes:

    Jimisola> Are there any routines for handling file-wildcards in
    Jimisola> Standard ANSI C/C++.

    Jimisola> I need information on which headerfile(s) to include
    Jimisola> also some examples would do great.

In POSIX.2 there are four sets of functions to handle wildcards for
different purposes.  They are also in XPG4, Unix 95, Unix 98.

regex.h:
    regcomp(), regexec(), regerror(), regfree().
    Regular expression matching.
    Match a string against a pattern.
    Optionally split into substrings.
    Other options for basic/extended, ignore case, newline treatment.
    ed/sed/ex/vi uses BRE, grep uses BRE, egrep uses ERE.

fnmatch.h:
    fnmatch().
    Match filename or pathname.
    Special characters are *, ?, [].
    Options for treatment of period, slash, backslash.

glob.h:
    glob(), globfree().
    Generate pathnames matching a pattern.
    Special characters are *, ?, [].
    Options include treatment of directories, backslash, nosort.

wordexp.h:
    wordexp(), wordfree().
    Perform word expansions.
    Tilde expansion is performed first.
    Parameter expansion, command substitution, and arithmetic
    expansion are performed next, from beginning to end.
    Field splitting is then performed on fields generated by previous
    step, unless the IFS (input field separators) is full.
    Path-name expansion is performed, unless the set -f command is in
    effect.
    Quote removal is always performed last.


--
Pete Forman
Western Geophysical
pete.forman@bedford.waii.com
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/10/13
Raw View
Jimisola Laursen <dat97jla@ludat.lth.se> writes:

>Are there any routines for handling file-wildcards in Standard ANSI C/C++.

No, the ANSI/ISO C standard and the draft ANSI/ISO C++ standard do
not provide any such functions.

POSIX (P1003.1) provides the functions opendir(), readdir(), closedir(),
and rewinddir().  These functions provide a way to iterate through all the
files in a directory, but they don't provide any wildcard pattern-matching.

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: David R Tribble <david.tribble@central.beasys.com>
Date: 1997/10/14
Raw View
Jimisola Laursen <dat97jla@ludat.lth.se> asked:
> Are there any routines for handling file-wildcards in Standard ANSI C/C++.

fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) wrote:
> No, the ANSI/ISO C standard and the draft ANSI/ISO C++ standard do
> not provide any such functions.
>
> POSIX (P1003.1) provides the functions opendir(), readdir(), closedir(),
> and rewinddir().  These functions provide a way to iterate through all the
> files in a directory, but they don't provide any wildcard pattern-matching.

Pete Forman <gsez020@compo.bedford.waii.com> wrote:
> In POSIX.2 there are four sets of functions to handle wildcards for
> different purposes.  They are also in XPG4, Unix 95, Unix 98.

As they said above, there are no ANSI/ISO functions for filename wildcard
matching (a.k.a. filename pattern matching), and there probably never will
be because of the wide variance in filenaming styles in use by all the
operating systems around.  But there are POSIX functions for doing such
things.  Your best bet is probably the fnmatch() function mentioned by Pete.
There's also a gmatch() function in System V Release 4 (SVR4).  Other
operating systems have similar functions, too, but with different names of
course.  Win32 has 'Find first file' and 'Find next file' functions, but the
patterns they handle are limited to the '?' and '*' wildcard characters
(which are only marginally better than DOS wildcard patterns).

BTW, I have an article coming out in the December 1997 issue of the C/C++
User's Journal that gives source code for functions that do Unix-style
filename wildcard matching.  For those of you who can't wait, the code is
available at <http://www.flash.net/~dtribble/src/> in the 'fpattern.h' and
'fpattern.c' files.

--------------------.      BEA Systems, Inc. ,-.  +1-972-738-6125 Office
David R. Tribble     \   ,------------------'   \ +1-972-738-6111 Fax
http://www.beasys.com `-'  Dallas, TX 75248      `-----------------------
david.tribble@noSPAM.beasys.com            http://www.flash.net/~dtribble
Support the anti-Spam amendment, join at http://www.cauce.org/
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1997/10/14
Raw View
Jimisola Laursen <dat97jla@ludat.lth.se> writes:

|>  Are there any routines for handling file-wildcards in Standard ANSI C/C++.

There aren't even any standard conventions as to what handling
file-wildcards means, much less standard functions to implement the
conventions.  There are platform specific standards: Posix (Unix)
defines a number of functions (already described by other posters), the
old MS-DOS API (and thus, I suppose, Windows) processes wildcards in its
findfirst/findnext routines, etc., etc.

So the answer is that you cannot do it portably.  (For a platform
specific answer, of course, you should post to the appropriate newsgroup
for the platform.)

--
James Kanze    +33 (0)1 39 23 84 71    mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
        I'm looking for a job -- Je recherche du travail
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]