Thread: regex

  1. #1
    Registered User
    Join Date
    Sep 2007


    I wrote a primitive shell program that reads in commands from standard input. What's the best way to handle "globbing", i.e. "ls *.c" (list all files with ".c" extension). I'm sure I don't have to do it all myself, can I get the system to do it? Isn't there already a function designed to do that for me? If anyone can let me know what my options are that would be great. Cause without it, it tries to associate *.c to a file name which obviously doesn't exist. Thanks

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    Why not just write a simple routine to handle it? You could, for example, have the only supported wild card be the * symbol (then add more as you need them). If time is money though, there is always the glob library.

  3. #3
    Registered User
    Join Date
    Sep 2007
    I've been trolling the net for something like the glob library. Haven't come across anything though. Any links to it? No idea how to implement any of the functions otherwise.

  4. #4
    Join Date
    Dec 2007

  5. #5
    Registered User
    Join Date
    Sep 2007
    All I could really dig up was the following. For handling let's say the command "ls -l *.c". But I have no idea what "globbuf" is. Any of you guys ever tried doing something like this before. I got all my shell code written out, i'm just trying to figure out how to incorporate something like the above command I gave into the shell.
    	  globbuf.gl_offs = count; (count = # of args after command)
              glob( expr, GLOB_DOOFFS, NULL, &globbuf );
              for( i=0; i < count; i++ ) //copy array of parsed arguments after command to this array
                  globbuf.gl_pathv[i] = args_in[i];
    	   execvp( cmd, &globbuf.gl_pathv[0] ); //execute

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with Boost Regex in Eclipse CDT
    By Hunter0000 in forum C++ Programming
    Replies: 4
    Last Post: 01-13-2010, 12:22 PM
  2. regex help
    By Jaqui in forum Tech Board
    Replies: 8
    Last Post: 10-14-2006, 03:53 PM
  3. My own regex...............class?
    By misplaced in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2005, 09:18 AM
  4. <regex.h> regex syntax in C
    By battersausage in forum C Programming
    Replies: 7
    Last Post: 03-24-2004, 01:35 PM
  5. How is regex used?
    By Strider in forum C++ Programming
    Replies: 0
    Last Post: 12-14-2001, 08:15 AM