[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Feature Request: C struct-like template
From: |
William Park |
Subject: |
Feature Request: C struct-like template |
Date: |
Thu, 14 Jan 2021 04:44:16 -0500 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
Here is another feature request.
In C struct, eg.
struct {
char date[7], dev[16], ver[32], rev[10], ...
}
you just access variables, and compiler will do the offsetting. I would
like something like that, where I don't have to do the bookkeeping.
Right now, I am doing
set -- ...break into arguments...
and access $1, $2, ..., ${@:20:32}, ... Or,
read -a tokens
and acess tokens[0], tokens[1], ...
This is fine for few arguments, but when it goes to few hundreds, it's
very easy to make mistakes and very difficult to catch it.
So, how about C-like struct template to put your arguments into?
You can build the template like
template=(
date 7
dev 16
ver 32
rev 10
...
)
and it will put the first 7 arguments into array "date", next 16
arguments into array "dev", next 32 arguments into array "ver", next 10
arguments into array "rev", ...
Then, I just use variable "rev" and that would be equivalent to
${@:55:10}.
Where it would useful?
- parsing real-life CSV files
- parsing UDP packets, for prototyping.
- parsing anything that has fixed width format.
- ...
--
William Park <opengeometry@yahoo.ca>
- Feature Request: C struct-like template,
William Park <=