Sujet : Re: Command line globber/tokenizer library for C?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 10. Sep 2024, 22:05:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbqcat$35kjh$1@dont-email.me>
References : 1
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 10.09.2024 21:01, Ted Nolan <tednolan> wrote:
I have the case where my C program is handed a string which is basically
a command line.
IIUC you don't want the shell to do the expansion but, sort of,
re-invent the wheel in your application (a'la DOS). - Okay.
Is there a common open source C library for tokenizing and globbing
this into an argc/argv as a shell would do? I've googled, but I get
too much C++ & other language stuff.
I also suppose that by "tokenizing" you don't mean something like
strtok (3) - extract tokens from strings
but a field separation as the Unix shell does using 'IFS'.
I don't know of a C library but if I'd want to implement a function
that all POSIX shells do then I'd look into the shell packages...
For Kornshell (e.g. version 93u+m) I see these files in the package
src/lib/libast/include/glob.h
src/lib/libast/misc/glob.c
that obviously care about the globbing function. (I suspect you'll
need some more supporting files from the ksh package.)
HTH
Janis
Note that I'm not asking for getopt(), that comes afterwards, and
I'm not asking for any variable interpolation, but just that a string
like, say
hello -world "This is foo.*" foo.*
becomes something like
my_argv[0] "hello"
my_argv[1] "-world"
my_argv[2] "This is foo.*"
my_argv[3] foo.h
my_argv[4] foo.c
my_argv[5] foo.txt
my_argc = 6
I could live without the globbing if that's a bridge too far.