git: 9front

Download patch

ref: 858da33d9b7393f0eeebb355dc7db6aa53e91c98
parent: e8102befdeb48abbce97b6ea308456976843615e
parent: 6851d816f0dd4ae19e6d5759bc35c61aaaf81641
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Sat Jun 4 17:36:15 EDT 2011

merge

--- a/sys/include/ape/time.h
+++ b/sys/include/ape/time.h
@@ -66,6 +66,8 @@
 
 #ifdef _POSIX_SOURCE
 extern char *tzname[2];
+extern long timezone;
+extern int daylight;
 #endif
 
 #endif /* __TIME_H */
--- a/sys/man/1/awk
+++ b/sys/man/1/awk
@@ -243,6 +243,13 @@
 .SM UTF
 string
 .TP
+.BI substr( s , " m")
+the maximum length substring of
+.I s
+that begins at position
+.IR m
+counted from 1.
+.TP
 .BI substr( s , " m" , " n\fL)
 the
 .IR n -character
@@ -303,6 +310,10 @@
 is not given,
 .B $0
 is used.
+.B &
+in
+.I t
+is replaced by the match.
 .TP
 .B gsub
 same as
--- a/sys/man/1/sed
+++ b/sys/man/1/sed
@@ -255,6 +255,30 @@
 if a replacement
 was made.
 .RE
+.IP
+An ampersand 
+.L &
+appearing in the replacement
+is replaced by the string matching the regular expression.
+The characters
+.BI \e n\f1,
+where
+.I n
+is a digit,
+are replaced by the text matched by the
+.IR n -th
+regular subexpression
+enclosed between
+.L (
+and
+.LR ) .
+When
+nested parenthesized subexpressions
+are present,
+.I n
+is determined by counting occurrences of
+.L (
+starting from the left.
 .TP
 .BI t " label"
 Test.
--- a/sys/src/ape/lib/ap/gen/mktime.c
+++ b/sys/src/ape/lib/ap/gen/mktime.c
@@ -110,8 +110,8 @@
 	d = ptm->tm_hour;
 	ptm = localtime(&a);
 	d -= ptm->tm_hour;
-	if(d < 0)
-		d += 24;
+//	if(d < 0)
+//		d += 24;
 	if(t->tm_isdst == 0 && ptm->tm_isdst)
 		d--;
 	if(t->tm_isdst > 0 && !ptm->tm_isdst)
--- a/sys/src/ape/lib/ap/posix/tzset.c
+++ b/sys/src/ape/lib/ap/posix/tzset.c
@@ -6,136 +6,54 @@
 #include <string.h>
 #include <unistd.h>
 
-#define TZFILE	"/etc/TZ"
-
-static char TZ[128];
 static char std[32] = "GMT0";
 static char dst[32];
 char *tzname[2] = {
 	std, dst
 };
-time_t tzoffset, tzdstoffset;
-int tzdst = 0;
+long timezone;
+int daylight;
 
-static int
-offset(char *env, time_t *off)
-{
-	int n, sign;
-	size_t len, retlen;
-
-	retlen = 0;
-	sign = 1;
-	/*
-	 * strictly, no sign is allowed in the 'time' part of the
-	 * dst start/stop rules, but who cares?
-	 */
-	if (*env == '-' || *env == '+') {
-		if (*env++ == '-')
-			sign = -1;
-		retlen++;
-	}
-	if ((len = strspn(env, ":0123456789")) == 0)
-		return 0;
-	retlen += len;
-	for (*off = 0; len && isdigit(*env); len--)		/* hours */
-		*off = *off*10 + (*env++ - '0')*60*60;
-	if (len) {
-		if (*env++ != ':')
-			return 0;
-		len--;
-	}
-	for (n = 0; len && isdigit(*env); len--)		/* minutes */
-		n = n*10 + (*env++ - '0')*60;
-	*off += n;
-	if (len) {
-		if (*env++ != ':')
-			return 0;
-		len--;
-	}
-	for (n = 0; len && isdigit(*env); len--)		/* seconds */
-		n = n*10 + (*env++ - '0');
-	*off = (*off + n)*sign;
-	return retlen;
-}
-
-/*
- * TZ=stdoffset[dst[offset][,start[/time],end[/time]]]
- */
 void
 tzset(void)
 {
-	char *env, *p, envbuf[128];
-	int fd, i;
-	size_t len, retlen;
-	time_t off;
-
-	/*
-	 * get the TZ environment variable and check for validity.
-	 * the implementation-defined manner for dealing with the
-	 * leading ':' format is to reject it.
-	 * if it's ok, stash a copy away for quick comparison next time.
-	 */
-	if ((env = getenv("TZ")) == 0) {
-		if ((fd = open(TZFILE, O_RDONLY)) == -1)
-			return;
-		if (read(fd, envbuf, sizeof(envbuf)-1) == -1) {
-			close(fd);
-			return;
-		}
-		close(fd);
-		for (i = 0; i < sizeof(envbuf); i++) {
-			if (envbuf[i] != '\n')
-				continue;
-			envbuf[i] = '\0';
-			break;
-		}
-		env = envbuf;
-	}
-	if (strcmp(env, TZ) == 0)
-		return;
-	if (*env == 0 || *env == ':')
-		return;
-	strncpy(TZ, env, sizeof(TZ)-1);
-	TZ[sizeof(TZ)-1] = 0;
-	/*
-	 * get the 'std' string.
-	 * before committing, check there is a valid offset.
-	 */
-	if ((len = strcspn(env, ":0123456789,-+")) == 0)
-		return;
-	if ((retlen = offset(env+len, &off)) == 0)
-		return;
-	for (p = std, i = len+retlen; i; i--)
-		*p++ = *env++;
+	char *env, *p, *q;
+	
+	if((p = getenv("timezone")) == 0)
+		goto error;
+	if((env = malloc(strlen(p) + 1)) == 0)
+		goto error;
+	strcpy(env, p);
+	if((p = strchr(env, ' ')) == 0)
+		goto error;
 	*p = 0;
-	tzoffset = -off;
-	/*
-	 * get the 'dst' string (if any).
-	 */
-	if (*env == 0 || (len = strcspn(env, ":0123456789,-+")) == 0)
-		return;
-	for (p = dst; len; len--)
-		*p++ = *env++;
+	strncpy(std, env, sizeof std);
+	q = p + 1;
+	if((p = strchr(q, ' ')) == 0)
+		goto error;
+	timezone = - atoi(q);
+	q = p + 1;
+	if((p = strchr(q, ' ')) == 0)
+		goto nodst;
 	*p = 0;
-	/*
-	 * optional dst offset.
-	 * default is one hour.
-	 */
-	tzdst = 1;
-	if (retlen = offset(env+len, &off)) {
-		tzdstoffset = -off;
-		env += retlen;
-	}
-	else
-		tzdstoffset = tzoffset + 60*60;
-	/*
-	 * optional rule(s) for start/end of dst.
-	 */
-	if (*env == 0 || *env != ',' || *(env+1) == 0)
-		return;
-	env++;
-	/*
-	 * we could go on...
-	 * but why bother?
-	 */
+	strncpy(dst, q, sizeof dst);
+	q = p + 1;
+	daylight = 1;
+	free(env);
+	return;
+
+error:
+	strcpy(std, "GMT0");
+	dst[0] = '\0';
+	timezone = 0;
+	daylight = 0;
+	if(env != 0)
+		free(env);
+	return;
+
+nodst:
+	dst[0] = '\0';
+	daylight = 0;
+	free(env);
+	return;
 }
--- a/sys/src/cmd/python/Modules/timemodule.c
+++ b/sys/src/cmd/python/Modules/timemodule.c
@@ -678,8 +678,7 @@
 	PyModule_AddIntConstant(m, "timezone", _timezone);
 #else /* !PYOS_OS2 */
 #ifdef PLAN9APE
-	//PyModule_AddIntConstant(m, "timezone", timezone);
-	PyModule_AddIntConstant(m, "timezone", 0);
+	PyModule_AddIntConstant(m, "timezone", timezone);
 #endif
 #endif /* PYOS_OS2 */
 #ifdef HAVE_ALTZONE
@@ -689,14 +688,12 @@
 	PyModule_AddIntConstant(m, "altzone", _timezone-3600);
 #else /* !PYOS_OS2 */
 #ifdef PLAN9APE
-	//PyModule_AddIntConstant(m, "altzone", timezone-3600);
-	PyModule_AddIntConstant(m, "altzone", 3600);
+	PyModule_AddIntConstant(m, "altzone", timezone-3600);
 #endif
 #endif /* PYOS_OS2 */
 #endif
 #ifdef PLAN9APE
-	//PyModule_AddIntConstant(m, "daylight", daylight);
-	PyModule_AddIntConstant(m, "daylight", 0);
+	PyModule_AddIntConstant(m, "daylight", daylight);
 	PyModule_AddObject(m, "tzname",
 			   Py_BuildValue("(zz)", tzname[0], tzname[1]));
 #endif
--- a/sys/src/cmd/python/pyconfig.h
+++ b/sys/src/cmd/python/pyconfig.h
@@ -45,7 +45,6 @@
 typedef unsigned long u_long;
 
 #define EISCONN	63
-#define EWOULDBLOCK 64
 
 #define FD_SETSIZE 96	/* see /sys/include/ape/sys/select.h */
 
--