Re: globbing source for C

Discussion in 'C Programming' started by Joel C. Salomon, May 12, 2011.

  1. On Thursday, May 12, 2011 9:07:44 AM UTC-4, Datesfat Chicks wrote:
    > Here are other suggestions and thoughts that come to mind:

    <snip>
    > c)It is my understanding that the treatment of command-line arguments
    > has always been different in Windows (i.e. it predates Windows 7 by
    > far). *nix globs for you, Windows does not.


    Exactly; the OP was asking for pointers on how to implement (in C, so it's on-topic) functionality like that provided by *nix, on a platform where it is not provided.

    Turns out the most useful answers are Windows-specific, but a link to some portable library (or to *sh source code!) would have been appropriate, too.

    --Joel
    Joel C. Salomon, May 12, 2011
    #1
    1. Advertising

  2. Joel C. Salomon

    Seebs Guest

    On 2011-05-12, Joel C. Salomon <> wrote:
    > Exactly; the OP was asking for pointers on how to implement (in
    >C, so it's on-topic)


    The only on-topic answer is "you can't". The C language lacks the
    necessary file manipulation primitives.

    (Well, maybe. You could in theory do it by iterating over the entire possible
    namespace of files using "fopen" and recording which ones you find?)

    > Turns out the most useful answers are Windows-specific, but a
    >link to some portable library (or to *sh source code!) would have
    >been appropriate, too.


    No, it wouldn't, because there is no way to write a portable library for that,
    and the *sh source code would be useless as it just waves you back at "and
    then you use the operating system's mechanism for traversing a directory".

    -s
    --
    Copyright 2011, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, May 12, 2011
    #2
    1. Advertising

  3. Joel C. Salomon

    Nobody Guest

    On Thu, 12 May 2011 15:57:53 +0000, Seebs wrote:

    >> Exactly; the OP was asking for pointers on how to implement (in
    >>C, so it's on-topic)

    >
    > The only on-topic answer is "you can't".


    Not for any sane definition of "on-topic".

    > The C language lacks the necessary file manipulation primitives.


    The C language lacks a lot of things, but that doesn't mean that you
    can't write them yourself or obtain them from elsewhere.

    On any platform where the concept of globbing is even meaningful, it's
    safe to assume that you can enumerate filenames in some
    (implementation-defined) manner.

    In fact, globbing doesn't absolutely /have/ to be related to filenames;
    the concept can be applied to any set of strings.
    Nobody, May 13, 2011
    #3
  4. Joel C. Salomon

    Seebs Guest

    On 2011-05-13, Nobody <> wrote:
    > Not for any sane definition of "on-topic".


    Uh.

    For the ONLY sane definition: "Stuff about the C programming language".

    The language is the thing that all the implementations have in common.

    If something is held in common between perl on Linux and C on Linux, but
    not between C on Linux and C on Windows, it is a Linux thing, not a C thing.

    > The C language lacks a lot of things, but that doesn't mean that you
    > can't write them yourself or obtain them from elsewhere.


    But it does mean that there is no way you can write such a thing "in C" --
    that is to say, one which arbitrary C compilers can do something with.

    > On any platform where the concept of globbing is even meaningful, it's
    > safe to assume that you can enumerate filenames in some
    > (implementation-defined) manner.


    Probably!

    > In fact, globbing doesn't absolutely /have/ to be related to filenames;
    > the concept can be applied to any set of strings.


    This would be correct except that "globbing" is specifically the term
    for expanding a pattern to the list of files matching that pattern. The
    term is in fact specific to file names. Pattern matching is not globbing.

    Pattern matching can be done in C. Once you've got pattern matching, it
    is trivial to show how you would build globbing from it if you had an
    enumeration of file names...

    -s
    --
    Copyright 2011, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, May 13, 2011
    #4
  5. Seebs <> writes:
    <snip>
    > If something is held in common between perl on Linux and C on Linux, but
    > not between C on Linux and C on Windows, it is a Linux thing, not a C thing.

    <snip>
    > On 2011-05-13, Nobody <> wrote:
    >> In fact, globbing doesn't absolutely /have/ to be related to filenames;
    >> the concept can be applied to any set of strings.

    >
    > This would be correct except that "globbing" is specifically the term
    > for expanding a pattern to the list of files matching that pattern. The
    > term is in fact specific to file names. Pattern matching is not globbing.
    >
    > Pattern matching can be done in C. Once you've got pattern matching, it
    > is trivial to show how you would build globbing from it if you had an
    > enumeration of file names...


    You need a little more or your assertion that filename globbing is
    off-topic would be false. Filenames can be enumerated in standard C --
    the problem is that the enumeration is very inefficient and that it does
    not terminate. You need at least a terminating enumeration of file
    names and, if possible, and efficient one.

    --
    Ben.
    Ben Bacarisse, May 14, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Philips

    Case-insensitive globbing

    Thomas Philips, Jun 3, 2004, in forum: Python
    Replies:
    4
    Views:
    580
    Derek Chen-Becker
    Jun 3, 2004
  2. Replies:
    5
    Views:
    410
  3. Replies:
    3
    Views:
    288
  4. Daz
    Replies:
    3
    Views:
    334
  5. Owner

    globbing source for C

    Owner, May 12, 2011, in forum: C Programming
    Replies:
    7
    Views:
    307
    Roberto Waltman
    May 16, 2011
Loading...

Share This Page