cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/08/21:01:16

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How to get file-globbed names?
Date: Wed, 08 Apr 1998 20:25:20 -0400
Organization: Two pounds of chaos and a pinch of salt.
Lines: 63
Message-ID: <352C1570.4E7A@cs.com>
References: <koehlerEr4BDM DOT Csw AT netcom DOT com>
NNTP-Posting-Host: ppp228.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Koehler wrote:
> 
> Could some kind person please provide me with a djgpp code example where the
> names of multiple ("globbed") files are sequentially processed..... Or
> could someone point me to a (simple!!!!) dos version of grep.

Well, there's always DOS 'find'; it's a really dumb text search tool. 
But I suppose you want something more complex.  BTW, what's so difficult
about using 'grep'?  Basic syntax:

   grep "word" files...

For example:

   grep "hello" *.c

If you find this syntax difficult to understand, please tell us and
we'll try to help.  :-)

Okay, reading globbed filenames.  You may or may not be aware that in C,
the command line arguments to a program are passed in via the arguments
to main(), in the following form:

   int main( int argv, char *argc[] )

argv contains the count of arguments, argc is an array of strings
containing the arguments themselves.  When the command line is
processed, all globbed filenames are inserted into the argument list
just as if you'd typed them all out on the command line.  argv[0] is the
name of the program itself; argv[1] thru argv[argc-1] are the remainder
of the arguments.  Example:

/* args.c */
#include <stdio.h>
int main( int argc, char *argv[0] )
{
    int i;
    for ( i = 0; i < argc; i++ )
        printf( "argv[%d] = %s", i, argv[i] );
    return 0;
}

C:\CPROGS> gcc -o args.exe args.c
C:\CPROGS> ls
foo1.c	foo2.c	foo3.c	args.c	args.exe

C:\CPROGS> args foo*
argv[0] = c:/cprogs/args.exe
argv[1] = foo1.c
argv[2] = foo2.c
argv[3] = foo3.c

If that's not simple enough...

hth!

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "A 'critic' is a man who creates     |
|       aka Fighteer I       | nothing and thereby feels qualified  |
|   mailto:fighteer AT cs DOT com   | to judge the work of creative men."  |
| http://www.cs.com/fighteer |               - Lazarus Long         |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019