Deutsch   English   Français   Italiano  
<vbqcat$35kjh$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups: comp.lang.c
Subject: Re: Command line globber/tokenizer library for C?
Date: Tue, 10 Sep 2024 23:05:32 +0200
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <vbqcat$35kjh$1@dont-email.me>
References: <lkbjchFebk9U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 10 Sep 2024 23:05:34 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="924a7b5cdcacf972d784a2302a9c8dba";
	logging-data="3330673"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX194MjJ7G1s2lbhGLIsUvgS8"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.8.0
Cancel-Lock: sha1:BM5rpoLbG/MOsgApGYCBGG/CZ8c=
In-Reply-To: <lkbjchFebk9U1@mid.individual.net>
X-Enigmail-Draft-Status: N1110
Bytes: 2616

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.
>