From: William Park <opengeometry@yahoo.ca>
To: Zsh Users <zsh-users@zsh.org>
Subject: (question) C struct-like template to read positional arguments?
Date: Sun, 17 Jan 2021 20:52:52 -0500 [thread overview]
Message-ID: <20210118015252.GA3550@node1.localdomain> (raw)
In-Reply-To: <20210118015252.GA3550.ref@node1.localdomain>
Hi all,
I have question...
In C struct like,
struct {
char aa[32], bb[32], skip[128], cc[7], dd[32], ...;
}
you just access variables, and compiler will do the offsetting.
Can zsh do something similar?
That is, you could probably build the template like
template=(
aa 32
bb 32
skip 128
cc 7
dd 32
...
)
and read into them, then just use variables, without worrying about
offsets. So, ${cc[@]} would be equivalent to ${@:193:7}, and ${cc[1]}
would be same as ${194}.
I know I can do
aa=( "${@:1:32}" )
bb=( "${@:33:32}" )
cc=( "${@:193:7}" )
...
But, it's so easy to make mistake and very difficult to catch it.
--
William Park <opengeometry@yahoo.ca>
next parent reply other threads:[~2021-01-18 1:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210118015252.GA3550.ref@node1.localdomain>
2021-01-18 1:52 ` William Park [this message]
2021-01-18 21:39 ` Bart Schaefer
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=20210118015252.GA3550@node1.localdomain \
--to=opengeometry@yahoo.ca \
--cc=zsh-users@zsh.org \
/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).