HELP: ===> wildcard ===> filename listing

Rick Schubert rns at tortuga.SanDiego.NCR.COM
Thu Feb 28 02:55:19 AEST 1991


In article <1991Feb26.144751.25144 at athena.mit.edu> jik at athena.mit.edu (Jonathan I. Kamens) writes:
>In article <1991Feb25.194140.15247 at SanDiego.NCR.COM>, rns at tortuga.SanDiego.NCR.COM (Rick Schubert) writes:
>|> Yes, it is possible to do pattern matching in C, but there is no reasonable%
>|> portable way of of doing filename expansion in C.  This is because there is
>|> no way in ANSI C to obtain a list of filenames to match against (there are
>|> ways on UNIX and other systems, but ANSI C has no such features).

>  That's true, but the code I mentioned said nothing at all about finding
>filenames against which to match; it was simply shell regular expression
>matching code, which is what was being asked for.  I'm sure the person who
>asked the original question is capable of figuring out how to use that code to
>match against filenames.

>  Most of the time, I agree with the people in comp.lang.c who say, "This
>question doesn't belong in this newsgroup!"  But the distinction Mr. Schubert

(you can call me Rick)

>appears to be attempting to draw here strikes me as absurd.  Sure, ANSI C
>doesn't have readdir().  So what.  You can talk about how to write shell
>regexp matchers without talking about how you're going to get the filenames to
>match against.

I was all ready to apologize for having misunderstood the original question,
but I decided to go back to read it first.  Here is what I found:

|> In article <1991Feb21.140918.1650 at cs.utk.edu> lape at cs.utk.edu (Bryon S. Lape) writes:
|> >
|> >	I need to know who to get all the filenames that meet a given
|> >wildcard in Unix from c.  For instance, say my programme my_foo will print
|> >the contents of any file given and I type:
|
|> >		my_foo *a*.c

|> >	What I would like to get is all files with an a in them and an
|> >extension of .c, and print them to stdout (not the same way pg or more
|> >does, by the way).  How do I get a list of files meeting the passed
|> >wildcard?  I have done this in Quick C but that was using none standard
|> >funcs.

My reading of this still is that he wants to start with a single wildcard
expression and from that generate a list of filenames matching that
expression.  If I am wrong then I apologize; if you still read it as not
requiring something like readdir(), then we just differ in interpretation
and I answered according to my interpretation and you answered according to
yours, and there's no point in arguing what was really meant -- we can just
agree to disagree, since it's not relevant to this newsgroup or anything
that matters very much.

Also (although I don't want to get into an extended debate on this), just
because something can be written in C doesn't mean that it is an appropriate
question for comp.lang.c, let alone comp.std.c.  C is a general-purpose
programming language, and many things can be written in C.  If the question
were: "Is there anything in ANSI C that will do most, if not all, of the
work necessary to do regular expression or wildcard pattern matching (e.g.
a library routine)," the answer would be "no, but thanks for asking."  If
the question were "Is it possible to do regular expression or wildcard
pattern matching in C," the answer would be "Yes, but you would have to code
the algorithm yourself.  This is not an algorithm newsgroup (although I'm not
sure there is one), so discussion of how do write such a program is not
appropriate here.  If you have questions about specific features of the C
language in terms of coding such an algorithm, go ahead and ask them in
comp.lang.c if they are general language issues or in comp.std.c if they are
standards issues.  If you want some source code, go ask in comp.sources.wanted."

I have to say that one cannot always know if a question is appropriate for
one of these newsgroups without knowing the answer, and this question may
fall into that category.  That's why my initial response was not a flame
but just an explanation that it was not possible to write portable C code
to do what I thought was being asked.

-- Rick Schubert (rns at tortuga.SanDiego.NCR.COM)



More information about the Comp.std.c mailing list