[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Re: globbing source for C

Joel C. Salomon

5/12/2011 1:39:00 PM

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
4 Answers

Seebs

5/12/2011 3:58:00 PM

0

On 2011-05-12, Joel C. Salomon <joelcsalomon@gmail.com> 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 / usenet-nospam@seebs.net
http://www.seeb... <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/...(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

John Doe

5/13/2011 8:36:00 AM

0

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.

Seebs

5/13/2011 8:43:00 AM

0

On 2011-05-13, Nobody <nobody@nowhere.com> 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 / usenet-nospam@seebs.net
http://www.seeb... <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/...(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Ben Bacarisse

5/14/2011 2:19:00 AM

0

Seebs <usenet-nospam@seebs.net> 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 <nobody@nowhere.com> 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.