aboutsummaryrefslogtreecommitdiffstats
path: root/meta-initramfs/recipes-devtools/klibc/klibc-1.5.26+2.0/dash_readopt.patch
blob: 3be1be04fbb2b5942b7b5966fc381f03e634eb2f (plain)
1
2
3
4

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other
Patch was imported from the OpenEmbedded git server
(git://git.openembedded.org/openembedded)
as of commit id ad67a97e8fbfb03a68088a6ca6ad87b086c88094
Signed-off-by: Thomas Kunze <thommycheck@gmx.de>
Minor adjustments tracking upstream changes
Signed-off-by: Andrea Adami <andrea.adami@gmail.com>

diff -uNr klibc-1.5.22.orig//usr/dash/miscbltin.c klibc-1.5.22/usr/dash/miscbltin.c
--- klibc-1.5.22.orig//usr/dash/miscbltin.c	2011-06-11 02:08:49.000000000 +0200
+++ klibc-1.5.22/usr/dash/miscbltin.c	2011-06-11 13:55:32.000000000 +0200
@@ -46,6 +46,7 @@
 #include <ctype.h>
 #include <inttypes.h>
 #include <time.h>		/* strtotimeval() */
+#include <termios.h>
 
 #include "shell.h"
 #include "options.h"
@@ -149,6 +150,11 @@
 	int timeout;
 	int i;
 	fd_set set;
+	int n_flag = 0;
+	unsigned int nchars = 0;
+	int silent = 0;
+	struct termios tty, old_tty;
+
 	struct timeval ts, t0, t1, to;
 
 	ts.tv_sec = ts.tv_usec = 0;
@@ -156,11 +162,18 @@
 	rflag = 0;
 	timeout = 0;
 	prompt = NULL;
-	while ((i = nextopt("p:rt:")) != '\0') {
+	while ((i = nextopt("p:rt:n:s")) != '\0') {
 		switch(i) {
 		case 'p':
 			prompt = optionarg;
 			break;
+		case 'n':
+			nchars = strtoul(optionarg, NULL, 10);
+			n_flag = nchars; /* just a flag "nchars is nonzero" */
+			break;
+		case 's':
+			silent = 1;
+			break;
 		case 't':
 			p = strtotimeval(optionarg, &ts);
 			if (*p || (!ts.tv_sec && !ts.tv_usec))
@@ -182,6 +197,24 @@
 	}
 	if (*(ap = argptr) == NULL)
 		sh_error("arg count");
+	if (n_flag || silent) {
+		if (tcgetattr(0, &tty) != 0) {
+			/* Not a tty */
+			n_flag = 0;
+			silent = 0;
+		} else {
+			old_tty = tty;
+			if (n_flag) {
+				tty.c_lflag &= ~ICANON;
+				tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
+			}
+			if (silent) {
+				tty.c_lflag &= ~(ECHO | ECHOK | ECHONL);
+			}
+			tcsetattr(0, TCSANOW, &tty);
+		}
+	}
+
 
 	status = 0;
 	if (timeout) {
@@ -200,12 +231,14 @@
	goto start;
 
-	for (;;) {
+	do {
 		if (timeout) {
 			gettimeofday(&t1, NULL);
 			if (t1.tv_sec > ts.tv_sec ||
 			    (t1.tv_sec == ts.tv_sec &&
 			     t1.tv_usec >= ts.tv_usec)) {
 				status = 1;
+				if (n_flag)
+					tcsetattr(0, TCSANOW, &old_tty);
 				break;	/* Timeout! */
 			}
 
@@ -222,6 +255,8 @@
 			FD_SET(0, &set);
 			if (select(1, &set, NULL, NULL, &to) != 1) {
 				status = 1;
+				if (n_flag)
+					tcsetattr(0, TCSANOW, &old_tty);
 				break; /* Timeout! */
 			}
 		}
@@ -263,6 +298,9 @@
 			newloc = startloc - 1;
 		}
-	}
+	} while (!n_flag || --nchars);
+	if (n_flag || silent)
+		tcsetattr(0, TCSANOW, &old_tty);
+
 out:
 	recordregion(startloc, p - (char *)stackblock(), 0);
 	STACKSTRNUL(p);