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=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 29592 invoked from network); 29 Nov 2021 00:37:45 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 29 Nov 2021 00:37:45 -0000 Received: from mail.9lab.org ([168.119.8.41]) by 4ess; Sun Nov 28 19:30:12 -0500 2021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9lab.org; s=20210803; t=1638145791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=+0EHc50Yd4Y4BGMy7ibmYILSd2AF37025a7ZwF/TvFs=; b=AHTuw+oBajd6eDp8DlSpnNQ15cmdzsHPnxfWp9SYgMyzu/w31TYFBp3Z1k9Fv3tKiU3HDr RKEd2nrGDafuqGCSEBTMnxvmua8Fo6vZ21+lGS8uOYSX6f5r35eJS7I5j9l4GFh8KMhQQA 6pMPkh/CG2FzZUtc5/vtiyfH+ARZSq8= Received: from pjw (host-185-64-155-70.ecsnet.at [185.64.155.70]) by mail.9lab.org (OpenSMTPD) with ESMTPSA id 5e633dd2 (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO); Mon, 29 Nov 2021 01:29:51 +0100 (CET) Message-ID: <78471EBB208850B6682BAF4168D2911A@9lab.org> To: 9front@9front.org CC: cinap_lenrek@felloff.net Date: Mon, 29 Nov 2021 01:29:50 +0100 From: igor@9lab.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-uiyfxrgvzqrrtiexjbalksllfh" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: asynchronous polling generator Subject: Re: [9front] [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window Reply-To: 9front@9front.org Precedence: bulk This is a multi-part message in MIME format. --upas-uiyfxrgvzqrrtiexjbalksllfh Content-Disposition: inline Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Quoth cinap_lenrek@felloff.net: […] > probably is better to parse everything using gettokens(). > as your patch doesnt handle quoting the quotes. […] Done. Using gettokens(…) instead of the previous hack. > the whole window command also will probably have issues with > this kind of stuff... the quoting is definitely messed up in > there. > > tho it is possible to quote from rc, like: > > fn q {a=$1 whatis a | sed 's!^a=!!;q'} […] Done. Thanks for the tip with quoting from rc. > or even get rid of wctl all together... it is a bit silly given > you can just fork and mount $wsys yourself... then there are not > two different code paths for creating a window. […] The attached patch fixes the use case with spaces in paths for the -cd option for wctl and window command. Agree that two *different* code paths in /rc/bin/window for creating a window is a bit silly. Will work on unifying that in the next revision of the patch… Thanks. Cheers, Igor --upas-uiyfxrgvzqrrtiexjbalksllfh Content-Disposition: attachment; filename=rio-working-directory-with-spaces-v2.patch Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit From: Igor Böhm Date: Mon, 29 Nov 2021 00:06:45 +0000 Subject: [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window The initial working directory of the new window may be set by a `-cd directory` option. However, the `-cd directory` option is not capable of handling paths with spaces. To enable paths with spaces the function /sys/src/cmd/rio/wctl.c:/^parsewctl is extended to handle quoted directory paths. Before applying the patch the following will fail to open a new window by writing to /dev/wctl: % rio -i window % mkdir '/tmp/path with space' % echo new -cd '''/tmp/path with space''' window -x rc >> /dev/wctl % pwd /tmp/path with space The following invocation fails as well: % window -cd '/tmp/path with space' % pwd /tmp/path with space After applying the patch the above sequences work as expected, opening a window running rc and the working directory set to '/tmp/path with space'. --- diff 78c7ad88ffbfbd2b7a7269d863e5f4be7535b566 06623a45c7101085ce651a92ff8b952fe239eaac --- a/rc/bin/window Fri Nov 26 22:47:15 2021 +++ b/rc/bin/window Mon Nov 29 01:06:45 2021 @@ -100,6 +100,6 @@ } if(! ~ $#wdir 0) - spec=($spec -cd $wdir) + spec=($spec -cd `{a=$wdir whatis a|sed 's!^a=!!;q'}) echo new $spec $argv0 -x $cmd >>$wctl } --- a/sys/src/cmd/rio/wctl.c Fri Nov 26 22:47:15 2021 +++ b/sys/src/cmd/rio/wctl.c Mon Nov 29 01:06:45 2021 @@ -203,7 +203,7 @@ parsewctl(char **argp, Rectangle r, Rectangle *rp, int *pidp, int *idp, int *hiddenp, int *scrollingp, char **cdp, char *s, char *err) { int cmd, param, xy, sign; - char *t; + char *f[2], *t; *pidp = 0; *hiddenp = 0; @@ -252,10 +252,13 @@ s++; if(param == Cd){ *cdp = s; - while(*s && !isspace(*s)) - s++; - if(*s != '\0') - *s++ = '\0'; + gettokens(*cdp, f, nelem(f), " \t\r\n\v\f"); + s += strlen(*cdp); + if((*cdp)[0] == '\'' && s[-1] == '\''){ + /* drop quotes */ + *cdp += 1; + s[-1] = '\0'; + } continue; } sign = 0; --upas-uiyfxrgvzqrrtiexjbalksllfh--