From 13ae620a451fc0941810b7617e6efaeceb8473c6 Mon Sep 17 00:00:00 2001 From: aiju Date: Sat, 4 Jun 2011 08:56:37 +0000 Subject: [PATCH 1/4] removed EWOULDBLOCK definition from python --- sys/src/cmd/python/pyconfig.h | 1 - 1 file changed, 1 deletion(-) diff --git a/sys/src/cmd/python/pyconfig.h b/sys/src/cmd/python/pyconfig.h index aee1449a1..ff951cc24 100644 --- a/sys/src/cmd/python/pyconfig.h +++ b/sys/src/cmd/python/pyconfig.h @@ -45,7 +45,6 @@ typedef unsigned short u_short; typedef unsigned long u_long; #define EISCONN 63 -#define EWOULDBLOCK 64 #define FD_SETSIZE 96 /* see /sys/include/ape/sys/select.h */ From 67daf453a755bb6fc15a69e49784f1bdd66eaa61 Mon Sep 17 00:00:00 2001 From: aiju Date: Sat, 4 Jun 2011 12:02:42 +0200 Subject: [PATCH 2/4] fixed tzset(), hopefully hg timezone bug should be fixed now --- sys/include/ape/time.h | 2 + sys/src/ape/lib/ap/posix/tzset.c | 162 ++++++------------------ sys/src/cmd/python/Modules/timemodule.c | 9 +- 3 files changed, 45 insertions(+), 128 deletions(-) diff --git a/sys/include/ape/time.h b/sys/include/ape/time.h index 73dfc797d..f5ed975a9 100644 --- a/sys/include/ape/time.h +++ b/sys/include/ape/time.h @@ -66,6 +66,8 @@ extern int nanosleep(const struct timespec *req, struct timespec *rem); #ifdef _POSIX_SOURCE extern char *tzname[2]; +extern long timezone; +extern int daylight; #endif #endif /* __TIME_H */ diff --git a/sys/src/ape/lib/ap/posix/tzset.c b/sys/src/ape/lib/ap/posix/tzset.c index 8502c6d66..bcbe59dc7 100644 --- a/sys/src/ape/lib/ap/posix/tzset.c +++ b/sys/src/ape/lib/ap/posix/tzset.c @@ -6,136 +6,54 @@ #include #include -#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; + 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; + 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; + strncpy(dst, q, sizeof dst); + q = p + 1; + daylight = 1; + free(env); + return; - /* - * 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++; - *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++; - *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? - */ +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; } diff --git a/sys/src/cmd/python/Modules/timemodule.c b/sys/src/cmd/python/Modules/timemodule.c index 7a1e44605..bded1af27 100644 --- a/sys/src/cmd/python/Modules/timemodule.c +++ b/sys/src/cmd/python/Modules/timemodule.c @@ -678,8 +678,7 @@ void inittimezone(PyObject *m) { 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 @@ void inittimezone(PyObject *m) { 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 From 7a4e46d7abb4d1cd95bbe2143e0b42c76568e505 Mon Sep 17 00:00:00 2001 From: aiju Date: Fri, 3 Jun 2011 13:06:28 +0200 Subject: [PATCH 3/4] fixed mktime bug --- sys/src/ape/lib/ap/gen/mktime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/src/ape/lib/ap/gen/mktime.c b/sys/src/ape/lib/ap/gen/mktime.c index 2c8fa79fa..4f171f7c1 100644 --- a/sys/src/ape/lib/ap/gen/mktime.c +++ b/sys/src/ape/lib/ap/gen/mktime.c @@ -110,8 +110,8 @@ mktime(struct tm *t) 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) From eadeb86f5132ca1cd5595179fe5a503ec69dca4a Mon Sep 17 00:00:00 2001 From: aiju Date: Fri, 3 Jun 2011 13:27:04 +0200 Subject: [PATCH 4/4] fixed issue #29 --- sys/man/1/awk | 11 +++++++++++ sys/man/1/sed | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/sys/man/1/awk b/sys/man/1/awk index d79b963c4..02c27b206 100644 --- a/sys/man/1/awk +++ b/sys/man/1/awk @@ -243,6 +243,13 @@ converts its numerical argument, a character number, to a .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 @@ If is not given, .B $0 is used. +.B & +in +.I t +is replaced by the match. .TP .B gsub same as diff --git a/sys/man/1/sed b/sys/man/1/sed index 6bb2e6123..e057b7192 100644 --- a/sys/man/1/sed +++ b/sys/man/1/sed @@ -255,6 +255,30 @@ Append the pattern space to 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.