1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

[v1.0] posix: don't zero-pad 2nds (re: 5c677a4c, 70fc1da7, b1a41311)

The POSIX mode now disables left-hand zero-padding of seconds in
'time'/'times' output. The standard specifies the output format quite
exactly and zero-padding is not in it.
This commit is contained in:
Martijn Dekker 2022-06-12 16:16:11 +01:00
parent cfc7307be2
commit 9b893992a3
7 changed files with 31 additions and 12 deletions

4
NEWS
View file

@ -3,6 +3,10 @@ For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
Any uppercase BUG_* names are modernish shell bug IDs.
2022-06-12:
- The POSIX mode now disables zero-padding of seconds in 'time'/'times' output.
2022-06-09:
- The POSIX mode has been amended to use a UNIX pipe(2) instead of a

View file

@ -519,7 +519,7 @@ static void print_times(struct timeval utime, struct timeval stime)
int st_min = stime.tv_sec / 60;
int st_sec = stime.tv_sec % 60;
int st_ms = stime.tv_usec / 1000;
sfprintf(sfstdout, "%dm%02d%c%03ds %dm%02d%c%03ds\n",
sfprintf(sfstdout, sh_isoption(SH_POSIX) ? "%dm%d%c%03ds %dm%d%c%03ds\n" : "%dm%02d%c%03ds %dm%02d%c%03ds\n",
ut_min, ut_sec, sh.radixpoint, ut_ms, st_min, st_sec, sh.radixpoint, st_ms);
}
#if _lib_getrusage

View file

@ -23,7 +23,7 @@
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
#define SH_RELEASE_SVER "1.0.0-beta.2" /* semantic version number: https://semver.org */
#define SH_RELEASE_DATE "2022-06-09" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_DATE "2022-06-12" /* must be in this format for $((.sh.version)) */
#define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

View file

@ -2296,6 +2296,9 @@ hours if greater than zero,
minutes, and seconds of the form \fIHH\fPh\fIMM\fPm\fISS\fP.\fIFF\fPs.
The value of \fIp\fP determines whether or not the fraction is
included.
Seconds are zero-padded unless the
.B posix
shell option is on.
.IP
All other characters are output without change and a trailing
newline is added.
@ -7747,6 +7750,12 @@ enables the recognition of a leading zero as introducing an octal number in
all arithmetic evaluation contexts, except in the \fBlet\fR built-in while
\fBletoctal\fR is off;
.IP \[bu]
disables zero-padding of seconds in the output of the
.B time
and
.B times
built-ins;
.IP \[bu]
stops the \fB.\fR command (but not \fBsource\fR) from looking up functions
defined with the \fBfunction\fR syntax;
.IP \[bu]
@ -7987,6 +7996,9 @@ or
Displays the accumulated user and system CPU times, one line with the times
used by the shell and another with those used by all of the shell's child
processes. No options are supported.
Seconds are zero-padded unless the
.B posix
shell option is on.
.TP
\(dg \f3trap\fP \*(OK \f3\-p\fP \*(CK \*(OK \f2action\^\fP \*(CK \*(OK \f2sig\^\fP \*(CK .\|.\|.
The

View file

@ -239,9 +239,9 @@ static void l_time(Sfio_t *outfile,register clock_t t,int precision)
if(hr)
sfprintf(outfile,"%dh",hr);
if(precision)
sfprintf(outfile,"%dm%02d%c%0*ds",min,sec,sh.radixpoint,precision,frac);
sfprintf(outfile, sh_isoption(SH_POSIX) ? "%dm%d%c%0*ds" : "%dm%02d%c%0*ds", min, sec, sh.radixpoint, precision, frac);
else
sfprintf(outfile,"%dm%02ds",min,sec);
sfprintf(outfile, sh_isoption(SH_POSIX) ? "%dm%ds" : "%dm%02ds", min, sec);
}
#define TM_REAL_IDX 0
@ -2401,11 +2401,9 @@ int sh_exec(register const Shnode_t *t, int flags)
if(t->par.partre)
{
Namval_t *np = nv_open("TIMEFORMAT",sh.var_tree,NV_NOADD);
if(np)
Namval_t *np;
if(np = nv_open("TIMEFORMAT",sh.var_tree,NV_NOADD))
format = nv_getval(np);
if(!format)
format = e_timeformat;
}
else
format = strchr(format+1,'\n')+1;

View file

@ -746,11 +746,11 @@ then
fi
# ======
# 'times' builtin
# 'time' keyword and 'times' builtin
expect=$'0m00.0[0-9][0-9]s 0m00.0[0-9][0-9]s\n0m00.000s 0m00.000s'
actual=$("$SHELL" -c times)
[[ $actual == $expect ]] || err_exit "times output: expected $(printf %q "$expect"), got $(printf %q "$actual")"
exp=$'^user\t0m00.[0-9]{2}s\nsys\t0m00.[0-9]{2}s\n0m00.[0-9]{3}s 0m00.[0-9]{3}s\n0m00.000s 0m00.000s$'
got=$("$SHELL" -c '{ time; } 2>&1; times')
[[ $got =~ $exp ]] || err_exit "times output: expected match of $(printf %q "$exp"), got $(printf %q "$got")"
expect=$'*: times: too many operands'
actual=$(set +x; eval 'times Extra Args' 2>&1)

View file

@ -197,6 +197,11 @@ let "017 == 15" || err_exit "leading octal zero not recognised in 'let' in --pos
(set --noposix --letoctal; let "017 == 15") || err_exit "leading octal zero not recognised in --noposix --letoctal (1)"
(set --noposix; set --letoctal; let "017 == 15") || err_exit "leading octal zero not recognised in --noposix --letoctal (2)"
# disables zero-padding of seconds in the output of the time and times built-ins;
exp=$'^user\t0m0.[0-9]{2}s\nsys\t0m0.[0-9]{2}s\n0m0.[0-9]{3}s 0m0.[0-9]{3}s\n0m0.000s 0m0.000s$'
got=$("$SHELL" --posix -c '{ time; } 2>&1; times')
[[ $got =~ $exp ]] || err_exit "POSIX time/times output: expected match of $(printf %q "$exp"), got $(printf %q "$got")"
# stops the . command (but not source) from looking up functions defined with the function syntax;
echo 'echo SCRIPT' >scrunction
function scrunction { echo FUNCTION; }