dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] trivial add ;& ;;& case break types
@ 2021-02-03 21:29 Vladimir N. Oleynik
  2021-02-03 21:44 ` Vladimir N. Oleynik
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir N. Oleynik @ 2021-02-03 21:29 UTC (permalink / raw)
  To: dash

[-- Attachment #1: Type: text/plain, Size: 395 bytes --]

Hello.

The trivial patch for add ';&' and ';;&' case break types in attach

test code:

foo() {
  case "$1" in
  a)   echo "case (a)" ;&
  a*)  echo "case (a*)" ;;&
  ab*) echo "case (ab*)" ;;
  *)   echo "default"
  esac
}

$ foo
default

$ foo b
default

$ foo a
case (a)
case (a*)
default

$ foo ab
case (a*)
case (ab*)

$ foo ad
case (a*)
default

$ foo abc
case (a*)
case (ab*)


--w
vodz

[-- Attachment #2: case-brk_type.diff.txt --]
[-- Type: text/plain, Size: 2631 bytes --]

--- eval.c.orig 2021-02-04 00:38:55.261769233 +0400
+++ eval.c      2021-02-04 00:45:51.555756211 +0400
@@ -440,6 +440,7 @@
	union node *patp;
	struct arglist arglist;
	int status = 0;
+       int skipmatch = 0;

	errlinno = lineno = n->ncase.linno;
	if (funcline)
@@ -449,7 +450,7 @@
	expandarg(n->ncase.expr, &arglist, EXP_TILDE);
	for (cp = n->ncase.cases ; cp && evalskip == 0 ; cp = cp->nclist.next) {
		for (patp = cp->nclist.pattern ; patp ; patp = patp->narg.next) {
-                       if (casematch(patp, arglist.list->text)) {
+                       if (skipmatch || casematch(patp, arglist.list->text)) {
				/* Ensure body is non-empty as otherwise
				 * EV_EXIT may prevent us from setting the
				 * exit status.
@@ -458,7 +459,15 @@
					status = evaltree(cp->nclist.body,
							  flags);
				}
-                               goto out;
+                               switch (cp->nclist.brk_type) {
+                               case 0:
+                                       goto out;
+                               case 1:
+                                       skipmatch = 1;
+                                       break;
+                               default:
+                                       skipmatch = 0;
+                               }
			}
		}
	}
--- mktokens.orig       2021-02-04 00:26:31.252792506 +0400
+++ mktokens    2021-02-04 00:29:26.483787025 +0400
@@ -50,6 +50,8 @@
 TLP    0       "("
 TRP    1       ")"
 TENDCASE 1     ";;"
+TENDCSCONT 1   ";&"
+TENDCSNPAT 1   ";;&"
 TENDBQUOTE 1   "`"
 TREDIR 0       redirection
 TWORD  0       word
--- parser.c.orig       2021-02-04 00:31:56.372782336 +0400
+++ parser.c    2021-02-04 00:51:34.876964135 +0400
@@ -449,10 +449,14 @@

			checkkwd = CHKNL | CHKKWD;
			if ((t = readtoken()) != TESAC) {
-                               if (t != TENDCASE)
+                               if (t != TENDCASE &&
+                                   t != TENDCSCONT &&
+                                   t != TENDCSNPAT) {
					synexpect(TENDCASE);
-                               else
+                               } else {
+                                       cp->nclist.brk_type = t - TENDCASE;
					goto next_case;
+                               }
			}
		}
		*cpp = NULL;
--- nodetypes.orig	2021-02-04 00:29:46.284786405 +0400
+++ nodetypes	2021-02-04 00:31:25.715783295 +0400
@@ -102,6 +102,7 @@
 
 NCLIST nclist			# a case
 	type	  int
+	brk_type  int			# 0 - ;;  1 - ;&  2 - ;;&
 	next	  nodeptr		# the next case in list
 	pattern	  nodeptr		# list of patterns for this case
 	body	  nodeptr		# code to execute for this case

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] trivial add ;& ;;& case break types
  2021-02-03 21:29 [PATCH] trivial add ;& ;;& case break types Vladimir N. Oleynik
@ 2021-02-03 21:44 ` Vladimir N. Oleynik
  0 siblings, 0 replies; 2+ messages in thread
From: Vladimir N. Oleynik @ 2021-02-03 21:44 UTC (permalink / raw)
  To: dash

Vladimir N. Oleynik wrote:

> The trivial patch for add ';&' and ';;&' case break types in attach


OOPS, I forgot this lines of patch to parser.c:

@@ -818,8 +822,16 @@
                         pungetc();
                         RETURN(TPIPE);
                 case ';':
-                       if (pgetc_eatbnl() == ';')
+                       c = pgetc_eatbnl();
+                       if (c == '&')
+                               RETURN(TENDCSCONT);
+                       if (c == ';') {
+                               c = pgetc_eatbnl();
+                               if (c == '&')
+                                       RETURN(TENDCSNPAT);
+                               pungetc();
                                 RETURN(TENDCASE);
+                       }
                         pungetc();
                         RETURN(TSEMI);

--w
vodz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-03 21:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-03 21:29 [PATCH] trivial add ;& ;;& case break types Vladimir N. Oleynik
2021-02-03 21:44 ` Vladimir N. Oleynik

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).