Re: Why Case Sensitive?
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Sun, 22 Jul 2007 22:51:37 +0100
"Flash Gordon" <spam@xxxxxxxxxxxxxxxxxx> wrote in message news:26pcn4xmui.ln2@xxxxxxxxxxxxxxxxxxxxxxxxxx
Malcolm McLean wrote, On 22/07/07 19:44:Let's take a real example.
That shows how little you know about programming in the real world. > In the real world you only write the bits of the "any program" routines you need now, but you design and implement them to allow for the inevitable future changes in requirements. Or why do you think the revision of the X library (to take a favourite of yours) is so high? Even the standard C library itself has changed.
I've got code that has to compile under pure ANSI C, and I want to pass in a couple of optional parameters and three filenames.
Now I could write a custom routine that would parse the options and extract the filenames.
typedef struct
{
int window;
int keep;
char *protein;
char *ramaangleset;
char *chiangleset;
} ARGS;
int fillargc(int argc, char **argv)
Or I could say - "most of this code can be any program". Parsing commandline options is hardly an unusual requirement.
getopt is the obvious choice, but it isn't in the standard library. I could have downloaded some code from the web. But actually I don't really like the interface and I think I can do better. Rightly or wrongly, options.c is born.
So the heart of it is a routine.
int opt_get(OPTIONS *opt, char *name, char *fmt, ...);
example usage
int window;
opt_get(opt, "-window -win", "%d", &window);
Now I've added more functionality than I strictly require. You can have several parameters of integer, real or string types per option. It also returns a value for parameterless flag options. The option name is passed in and you can have aliases.
That's because it is an "any program" routine. So it will handle a wide range of options. Not everything possible, of course, but everything that can be reasonably foreseen and doesn't require excessive coding effort.
Now if the command line options change, which they are quite likely to do, all I've got to do is add a call to opt_get(). If I want to write another program, I've got options.c, and I don't have to write it again.
If someone really insists on -f123 (flag and parameter run together) format it will need a rewrite, because that was a foreseeable demand that would have required "excessive coding" to support. It wouldn't be the end of the project, but it would mean that the plan had broken down. However normally I would expect to control the options format myself.
That's "any program" status should also mean "don't change me". The options.c module shouldn't change. If it needs changing then that's a failure on my part. The calls to it will change as options are added or removed, but normally that change will be only one or two lines of source. Obviously you can't expect to change the behaviour of the program with not changes at all to its source.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
.
- Follow-Ups:
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- References:
- Why Case Sensitive?
- From: Bart
- Re: Why Case Sensitive?
- From: Malcolm McLean
- Re: Why Case Sensitive?
- From: August Karlstrom
- Re: Why Case Sensitive?
- From: Malcolm McLean
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- From: Malcolm McLean
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- From: Ian Collins
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- From: Ian Collins
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- From: Ian Collins
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- From: Ian Collins
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- From: Ian Collins
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- From: Ian Collins
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- From: Charlton Wilbur
- Re: Why Case Sensitive?
- From: Flash Gordon
- Re: Why Case Sensitive?
- From: Malcolm McLean
- Re: Why Case Sensitive?
- From: Flash Gordon
- Why Case Sensitive?
- Prev by Date: Re: About c programing
- Next by Date: Re: I want unsigned char * string literals
- Previous by thread: Re: Why Case Sensitive?
- Next by thread: Re: Why Case Sensitive?
- Index(es):
Relevant Pages
|
|