Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Living without zsh: command line parsing

    Hi all :)

    First of all, sorry for the length of the following message and
for being a bit off-topic, but I don't know anyone in the free
software world who knows more of shell scripting that you. So please
be patient with me O:)

    I have a problem with a free software project I'm making, where I
must process certain command line and store some values in a variable
depending on that command line. The problem is that I must do it so
it works with a Single Unix Specification V3 compliant shell, I want
to know how. If anyone has curiosity, all this is related with the
upcoming new version of MOBS, a building framework I use for my
projects, published in my homepage.

    What I want to do, and I *really* need your help for that, is the
following: I have a command line like, let's say

    $./0 --enable-feature1 --enable-feature2 --disable-feature1 ...

    I want to parse that command line and store some values in
variables for that. I cannot depend on 'getopt', so I parse the
command line using a case construct. When I parse the above command
line, what I do now is something like:

# Note that some code relating to checks is missing
        XDEFS="${XDEFS} -D_ENABLE_$argument -U_DISABLE_$argument" ;;

        XDEFS="${XDEFS} -D_DISABLE_$argument -U_ENABLE_$argument" ;;

    Well, this works, because when I use 'XDEFS' in the compilation I
have a series of -D and -U and only the lasts have effect, but what I
want is to have just one copy, that is, I want to have just one set
of '-D' and '-U' relating the $argument, the last one in fact. I have
the following limitations:

    - The syntax must be SUSv3 compatible, so no Zsh tricks :(
    - XDEFS is used for more options, so I cannot just throw away it.
    - I can have any number of --enable or --disable options with the
same $argument.
    - They can come in any order, interspersed with other options.

    I'm sure that there is a simple solution that I'm missing
completely that is far better than the duplication I'm currently
making :((

    Thanks a lot in advance :) If anyone wants to take a look at the
latest stable release of this project, which is no much different
than the development one, it is GPL'd and can be got in my homepage
(see the signature below). It's called MOBS (My Own Building System).

    Raúl Núñez de Arenas Coronado

Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/

Messages sorted by: Reverse Date, Date, Thread, Author