3

I just got to know both functions. Have been searching internet to learn their usage. Found one thing which is very important to parse the command line option input, but not discussed.

Is such a case, if duplicated options are typed in, both functions can not do anything to handle it. I was wondering if there is any lib function to use for this.

If I have to handle it myself. The way in my mind is to collection short option into an array and find identical ones in the array.

Any better way to do it?

dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
tao
  • 251
  • 3
  • 13

1 Answers1

2

If you want to do something special with duplicate options, you can manage state in the option handling code.

Something like -v|--verbose can be repeated for additional verboseness, and the vebosity handling code is

// initialize
int verbose_level=0

// in the getopt case for -v
  verbose_level++;

(for options that can be repeated with arguments which should all be used, load up a list or some such).

If you don't want repeats to do anything special just set the value every time

  // in the case
  verbose_level = 1;

and if you want to detect repeats

  // in the case
  if (verbose_level) {
   // handle this case as an error...
}
dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
  • 1
    What I meant is if typing in command like this :> Appexec.exe --same-option --same-option. So in this case option handling should show error information to th user and quit. I guess there is no such a lib API to handle the case. It has to be done by self. – tao Nov 30 '10 at 08:34