Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
78 user(s) are online (71 user(s) are browsing Forums)

Members: 1
Guests: 77

emeck, more...

Support us!

Headlines

 
  Register To Post  

Anyway to get *un*parsed shell arguments for a portable C program?
Home away from home
Home away from home


See User information
This is a not an Amiga-specific question, but one aimed at a C program which would compile with GCC equally well on Windows or Amiga or whatever:

If I use main(int argc, char *argv[]) to get the Shell parameters supplied to a program, then they come pre-parsed... WHICH I DO NOT WANT. Is there a portable-C way of getting the original unparsed parameters?

Author of the PortablE programming language.
Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Just popping in
Just popping in


See User information
This is the result of the startup code programs get compiled with

If you bypass startup code and offer your own replacement...

This may be the only way to dictate exactly what environment your program has at launch

Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Just can't stay away
Just can't stay away


See User information
@ChrisH

Use dos.library/GetArgStr(). This function exists in AmigaOS >= 2.0.

Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Not too shy to talk
Not too shy to talk


See User information
If things are not changed recently, name expansion
on unix are made by the shell that are calling
the program so there is no way to have what you
are asking

Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Home away from home
Home away from home


See User information
@Salass00 Quote:
Use dos.library/GetArgStr(). This function exists in AmigaOS >= 2.0.

Unfortunately it doesn't exist on Windows, Linux, nor any other non AmigaOS :(

After more searching I decided that what I was asking was impossible, which seems ridiculous. It doesn't even appear to be possible using POSIX functionality either, so not only will I need an Amiga-specific implementation, I'll also need a Windows-specific one, and for any other OSes I want to support.

Author of the PortablE programming language.
Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Not too shy to talk
Not too shy to talk


See User information

What don't you want argc/argv? This is C standard and exists in every OS.

Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Home away from home
Home away from home


See User information
@Thomas
The short story is that I need to know when arguments have been quoted, but the C library auto-strips quotes so I can't tell.

The long story is that my portable ReadArgs clone (it works on Windows just as well) needs to know when things have been quoted, so it knows if something should be treated as a keyword or not. When a parameter contains spaces you can guess it was quoted, but that is not a fool-proof method (and recently it become a show-stopper for me).

(And as to why I don't use ReadArgs on the Amiga: My implementation has some nice improvements. It's also simpler (and safer) to use the same implementation on all platforms.)

Author of the PortablE programming language.
Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Just can't stay away
Just can't stay away


See User information
@ChrisH

If you want an argument parser that works on all systems then why don't why don't you just use getopt_long() from getopt system? It's portable and exists on pretty much all systems since it just uses argc/argv.

Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Home away from home
Home away from home


See User information
@salass0
Because I happen to think ReadArg-style argument parsing is far superior to the rather basic Unix-style that has become the defacto-standard on other systems.

Author of the PortablE programming language.
Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Not too shy to talk
Not too shy to talk


See User information

I made a simple ReadArgs replacement for OS 1.3 which uses argc/argv as input and it works rather good IMO. Yes, you can surround keywords by quotation marks and they are still recognised as keywords. But I can live with that.


Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Just popping in
Just popping in


See User information
Doing:

prog *.c

You will always get the globed arguments in your main function. Your program knows not wether the user typed in each argument or globed with the wild card. It should infact never have to care. This is a good part of unix design and sets it apart from the IMO crapper way amigaos leaves this to the program being run. Likewise quoting is a function of the shell under unix.

prog "foo bar"

Will cause your main to see one argument without the quotes.

Hope this helps. I'm not sure what you are really wanting to do...

Lawrence

Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Amigans Defender
Amigans Defender


See User information
@Aslak3

Quote:
Doing:

prog *.c

You will always get the globed arguments in your main function. Your program knows not wether the user typed in each argument or globed with the wild card. It should infact never have to care. This is a good part of unix design and sets it apart from the IMO crapper way amigaos leaves this to the program being run.


What if the program being run *does* care? What if I have a command-line crossword solver that supports AmigaDOS-style pattern-matching (bear with me)?

crossolve a?i?a

Could show all words in its dictionary matching that AmigaDOS pattern.

UNIX-style the program would presumably just get a list of filenames matching that pattern, unless the user bothered to escape each wildcard?

Having said that, I can see this being very useful. It's something that could be added to ReadArgs, with /P specifying that the program wants a parsed array of files, rather than the argument verbatim. That would take the pattern parsing and directory-scanning nonsense out of the application and into the OS, where it should be. It would also finally get rid of having to use spat all the time because nobody can be bothered to implement pattern-matching.

Anybody able to raise that as an OS4 feature request?

Go to top
Re: Anyway to get *un*parsed shell arguments for a portable C program?
Home away from home
Home away from home


See User information
No need to continue the discussion (unless any *does* have a portable equivalent to GetArgStr()), as I'm now using GetArgStr() anyway (except on Windows of course).

Author of the PortablE programming language.
Go to top

  Register To Post

 




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




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project