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
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.
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.
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 ); //execute