From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7037 invoked from network); 18 Jan 2021 21:40:26 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 18 Jan 2021 21:40:26 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1611006026; b=YQ4GD0sDvOdEtJg3CXM47yf0tAyUz1sNnDp4eLQk+wJwy4pUJJ60JIfKsnQOC/aM6sZb6u17QT xoyaDGmQxrsnYK+3StVL++lVWU5gCDSBxs0+69QpqyqhDCIPUGHvOdiQPLMJQ777zxerxZslDV /9sspuKOnqUEtFKwzS2SLLD8rjaWs/8KjQJpkPC2Lb23m2rt3Q1CfHAV15Qf8Hm7Ys7Uouw7GB PQ+shqEG2/aSueexcNDq9NC6JOLI9m6mF+45WD8nSsyhtQ5Ow5CHdF394zIB/MP/LyZy1g2amT 9fZdKLHIihTHShd1o2WBNuh5XulWJlnObUxJcnyjSeLVCA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f171.google.com) smtp.remote-ip=209.85.167.171; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1611006026; bh=3l4UjmcfKWLNrJyV7SrckZcnYpCfzT2BHsEFHrexrIM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=jyaqb1cHPol9YuicWolwU6sOCGa+aFjEcFn4Odc5wwu7/+irDOrzGHvKiDdUKTmIQf/IptIIzO DJkrhTwfpUTZWzi1CLbRytMnJOodGhLxQYZ3F7CPa8td8LnY27J6e6U1B0Minr7Zlgx2TSS4QB EhncVel/EpC9EIU0RRwQCobg31EwMjcEqtrZricXX3zI5u9J8Z/NzbIW09aPG+kjeFEEMH+D/a 3HShuwX/rymhva1d9BL2OL++dXEiuETtU8ySWxtml7nVtMgt+JrjTxCeXVevpRVAIoT37s1Ff7 UjCjQudNhJXjZRvW9LlJAV+StzN0tXVG9hwbDZAzTaPryQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=+0RZZfdEIQ/7M0m3W/YlCf8Id7aKytUrWWz7ds4ye9s=; b=lT+sGjw968KsIiaQoVjCkWOPYv mPcokp2682uFPdM/z8leXMCPfdMPcDPwhty2evzEpU+btDLb5NUnctdccpoQ4dWbZzNhL+oU2SIfU P5DRWkTEsDbbH02CEimeFXj8ccq8syKUn5Kd+rJK1BM6Bb+SbWTWjrz5GUPCuxWs2Xe33LfBQB0ux aJbUb47axRh63MRuwo+QwZICNm2GQ9LVE9rEN6fVOBlBw+36VmufHeXbF/H+hFqvEynm9OHQr0SmH 5BEIwUZAdYFbjBTSa+IQYd9bXkWlmtyqQY+m7MmhOGqHeF/xLUxILuPNcErkyDcG1Lr8ftNNhmBOD w1cpHN6Q==; Received: from authenticated user by zero.zsh.org with local id 1l1cG9-000M16-D3; Mon, 18 Jan 2021 21:40:25 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f171.google.com) smtp.remote-ip=209.85.167.171; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-oi1-f171.google.com ([209.85.167.171]:34586) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1l1cFY-000LbO-MY; Mon, 18 Jan 2021 21:39:50 +0000 Received: by mail-oi1-f171.google.com with SMTP id h192so1461188oib.1 for ; Mon, 18 Jan 2021 13:39:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=+0RZZfdEIQ/7M0m3W/YlCf8Id7aKytUrWWz7ds4ye9s=; b=do+7+j+BdNL7fR/1DGCzqixJWEKM2zTEvCCDw1DoLfx/zJ3sixLEZEQufhfGABdg1C a5LTJ59QiA5b68NRox/Ql3tzVKTgBrS2VePrXPfeJy9EnRiEKuDW2+blesGEdus8BDrz HVSwXRHKR9aBUwgOLNZQa8Alh2CNAcG1y5knTzskiy9DuMJQjPXo7FHmHOspibTYvR+y BWUz+vl52COmtTJ/uW+yadR6JTqpjmFIz94d1o40EK1WMlYjRhcbFYBS4+R/KappjuET 1qnMAoNCiO69VDqHTvgb3197mxUEv3b1d7ZuhIiv1+iaA5tMZYB8zUeh8kM04hdLU6eQ 0C3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=+0RZZfdEIQ/7M0m3W/YlCf8Id7aKytUrWWz7ds4ye9s=; b=aER97vuLkgJqpGxe1ADe30cdkugGs18lkicnt9WFV2OYzcyo+6clJyc+qra67yB7he WjhtF3fDP3ORvmcuCbke4JvoQhdOp4jsrYbHv/zIsNnP/UgmpmBNCTtBkCapoI3QRCc+ Q/PPRjpePTxXTORdmjiWCCZcBjz95eiUjxzHr1K72GpjXHqmgNC6fx1563U1tg0qdnUK pTy7v7sQgcEIp9JsUGJm+XJ076Pz3WBwSPP+Yv1pv/vABFWEsVxM3C7u/JqML6jYD9/P 83ZEqbrCr+Qy8VDozUdvibOZKh/rBPpSG37LU18sRZl1ann/QwpRfX3+rBMfwn0MqNig /TzQ== X-Gm-Message-State: AOAM532yD4tR92YIKnNz/RqJK1SCyqKeucnoYcWZaZY5VZx87ODi2ICv mhKzvCgPVUWnMFB3LyzzYfHnhuZRCA9B/4IRiNzWGf0iZvbT89hE X-Google-Smtp-Source: ABdhPJwVCD8BhlIhu9ixK0zXQmaqB7mT3BCE9tSnWLlzJvLX9Ug75ZEMKIJrMdFQAq6NVL4fZbicUJi1RTScnjh9CPY= X-Received: by 2002:aca:de41:: with SMTP id v62mr805649oig.132.1611005987046; Mon, 18 Jan 2021 13:39:47 -0800 (PST) MIME-Version: 1.0 References: <20210118015252.GA3550.ref@node1.localdomain> <20210118015252.GA3550@node1.localdomain> In-Reply-To: <20210118015252.GA3550@node1.localdomain> From: Bart Schaefer Date: Mon, 18 Jan 2021 13:39:36 -0800 Message-ID: Subject: Re: (question) C struct-like template to read positional arguments? To: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26391 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On Sun, Jan 17, 2021 at 5:53 PM William Park wrote: > > 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. I'm having a hard time figuring out what you're talking about here. How is this structure initialized? If you're casting a char* to a pointer to this struct type, I suppose that gets you a bunch of pointers into the array (unless the compiler does pointer alignment on word boundaries, in which case dd following that cc[7] is going to be problematic), but those aren't usable as strings because you don't have the terminating NUL bytes. So what do you mean? And IMO in any event, that's a horrible programming style. > Can zsh do something similar? > [...] > 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. Why do you have 200 positional parameters that have to be split up into subsets this way? Seems like it'd be at least as easy to make a mistake when creating the argument list for the call as when doing the subsetting. However ... > template=( > aa 32 > bb 32 > skip 128 > cc 7 > dd 32 > ... > ) I think what you're asking for might be for var len in $template do set -A $var "${@[1,len]}" shift len done