English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 05 January 2021, 09:46   #1
alancfrancis
Registered User
 
alancfrancis's Avatar
 
Join Date: Jun 2020
Location: Scotland
Posts: 146
ReadArgs and wildcard expansion

Hi,

Just getting back into Amiga Programming and C on my A1200/3.1.4 after almost 30 years. I have a question for more experienced hands though.

I'm working on a super minimal native git implementation, just enough to be able to add some files, commit and push/pull to GitHub for now, to make it easier to work across my Mac and Amiga with VBCC.

As I go through the many rounds of Yak shaving just figuring out *how* things work, I've hit what seemed a weird one.

Code:
git_add #?.c
. with a template of
Code:
FILES/M/A
. comes through to
Code:
ReadArgs
as a single item -
Code:
#?.c
. I can't see any obvious system function to expand wildcards relative to the
Code:
GetCurrentDir
so I figured maybe this just wasn't a thing.

I noticed that, e.g.
Code:
type #?.txt
does the right thing though.

So... either someone has to write all that code to walk the directory and PatternMatch the strings in every single tool, again and again, or there's some trick I'm missing either in the CLI or in the code to make this work the way I expect.

Any help or suggestions (or the source code for the TYPE command :-) welcomed.

Alan
alancfrancis is offline  
Old 05 January 2021, 10:59   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by alancfrancis View Post
So... either someone has to write all that code to walk the directory and PatternMatch the strings in every single tool
This. Allocate an AnchorPath object. Then MatchFirst() and MatchNext() are your friends.
Only a Unix shell automatically expands such patterns, before passing them to the application.
phx is offline  
Old 05 January 2021, 11:18   #3
alancfrancis
Registered User
 
alancfrancis's Avatar
 
Join Date: Jun 2020
Location: Scotland
Posts: 146
@phx. Damn. I was afraid of that. :-) Thanks.

I might try and make the code into a little reusable library cause I'll need it for some other git commands. I was spoiled by Ruby's Dir.glob
alancfrancis is offline  
Old 05 January 2021, 12:34   #4
alancfrancis
Registered User
 
alancfrancis's Avatar
 
Join Date: Jun 2020
Location: Scotland
Posts: 146
Aha, I just reread and I didn't know about AnchorPath/MatchXXX so that's actually much easier than I was thinking with Examine and recursing and pattern matching each string myself. :lightbulb: Thanks again @phx.
alancfrancis is offline  
Old 06 January 2021, 15:55   #5
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by alancfrancis View Post
Aha, I just reread and I didn't know about AnchorPath/MatchXXX so that's actually much easier than I was thinking with Examine and recursing and pattern matching each string myself. :lightbulb: Thanks again @phx.

you might also consider

Code:
int scandir(const char *dirname,struct dirent ***namelist,
    int (*select)(const struct dirent *),
    int (*dcomp)(const struct dirent **, const struct dirent **))
https://man7.org/linux/man-pages/man3/scandir.3.html

which is provided by libnix

PS: I hope it's working^^

Last edited by bebbo; 06 January 2021 at 16:27. Reason: PS
bebbo is offline  
Old 06 February 2021, 16:49   #6
alancfrancis
Registered User
 
alancfrancis's Avatar
 
Join Date: Jun 2020
Location: Scotland
Posts: 146
Thanks @bebbo, I am trying as best I can to not rely on anything other than standard amiga APIs because I am a masochist. :-)
alancfrancis is offline  
Old 12 March 2021, 17:46   #7
nyteshade
Registered User
 
Join Date: Mar 2020
Location: Boulder Creek / USA
Posts: 43
Not completely related to your post, but I have a small personal wiki usually used for my own purposes but did a RDArgs post you might find interesting. It’s just a way of using it that doesn’t rely on setting #defines for variable storage index markers.

Would be curious what you think. Or any pointers you might have.

https://nyteshade.com:3443/amiga-rdargs


Sent from my iPhone using Tapatalk
nyteshade is offline  
Old 12 March 2021, 18:45   #8
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Quote:
Originally Posted by nyteshade View Post
Would be curious what you think. Or any pointers you might have.
Two comments about your "Working Example":

You do not need to allocate a RDArgs structure if you want to read args from the command line, you can supply a NULL pointer to ReadArgs. A pre-allocated RDArgs is only needed if you want to parse a string in memory.

It does not make much sense to create a memory pool if you allocate only one chunk of memory. And of course the arguments array can be held on the stack, you do not need to allocate it.
thomas is offline  
Old 12 March 2021, 19:05   #9
nyteshade
Registered User
 
Join Date: Mar 2020
Location: Boulder Creek / USA
Posts: 43
Thanks for the feedback. I was going to do an extra piece on the extra help portion as well to indicate how you can print out additional usage info if you supply a second ? to template string prompt in the shell.

You’re right that the pool of memory is wasteful here; it’s a habit of mine to play with pools of late.


Sent from my iPhone using Tapatalk
nyteshade is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
ReadARgs() bug in Roadshow AddNetInterface Bruce Abbott Coders. System 11 21 September 2023 04:06
ReadArgs implementation for kickstart 1.3 jotd Coders. Asm / Hardware 19 06 February 2023 12:45
Query about "all" wildcard in Shell Foebane support.Apps 6 05 January 2020 14:08
Help please strugglng to get multiple options out of ReadArgs chocsplease Coders. C/C++ 28 23 July 2017 19:07
Using ReadArgs() from asm oRBIT Coders. General 4 11 May 2010 16:11

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:49.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07596 seconds with 15 queries