Welcome, Guest. Please login or register.

Author Topic: Coding: CLI args parsing and resident purity  (Read 1981 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Coding: CLI args parsing and resident purity
« on: January 11, 2012, 12:54:22 AM »
Quote from: nyteschayde;675265

Also, where can I find information on how to make the command resident safe?

It's easy. Your program must be reentrant:
https://en.wikipedia.org/wiki/Reentrancy_%28computing%29

Basically this means: No global or static variables of any kind.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Coding: CLI args parsing and resident purity
« Reply #1 on: January 11, 2012, 02:07:32 AM »
Quote from: Leffmann;675285
You can use global data in your resident programs with a bit of care. F.ex you can use a mutex to enter a critical section where you can retrieve the global data
That's entirely possible, although if you need to go to such lengths I'd say it would be better to go "ROMable" right away.

Quote
or initialize it if it's the first run of the program
This however will lead to resource leak and there's no "cleanup" called when the resident command is removed.

I say nuke the site from orbit, err, go for ROMable from the beginning...
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: Coding: CLI args parsing and resident purity
« Reply #2 on: January 11, 2012, 08:44:53 PM »
Quote from: nyteschayde;675397
So I tried to compile something that uses ReadArgs. I can successfully get it to prompt me using the template string I pass in but I don't fully understand the second parameter (the LONG* array). I am also not 100% clear on how to check the parsed args afterwards.

Do you guys have any example usages anywhere. Google failed me on this account.
Here's a simple program that requests a number:
http://www.amiga.org/forums/showthread.php?t=3348
It has a mistake in it that I correct in my reply.

Here's a an example of a more complex argument parsing:
http://www.sinz.org/Michael.Sinz/Enforcer/MMU.c.html
(Just skip the irrelevant parts and look for the ReadArgs usage)

MMU.c already shows how you can read arguments from an arbitrary input buffer instead of stdin. Here's another example of that:
http://www.control.auc.dk/~ksst01/readargs.c

NOTE: Normally you just use NULL as the 3rd argument to read from stdin.
« Last Edit: January 11, 2012, 08:49:47 PM by Piru »