zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <raul@pleyades.net>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Living without zsh: command line parsing
Date: Tue, 4 May 2004 19:38:33 +0200	[thread overview]
Message-ID: <20040504173833.GB4794@DervishD> (raw)

    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
    --enable*)
        argument="${option#--enable}"
        argument="${argument#-}"
        XDEFS="${XDEFS} -D_ENABLE_$argument -U_DISABLE_$argument" ;;

    --disable*)
        argument="${option#--disable}"
        argument="${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/


             reply	other threads:[~2004-05-04 17:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-04 17:38 DervishD [this message]
2004-05-05 10:29 ` DervishD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040504173833.GB4794@DervishD \
    --to=raul@pleyades.net \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).