mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
So far we've been handling AST release build and git commit flags
and ksh SHOPT_* compile time options in the generic package build
script. That was a hack that was necessary before I had sufficient
understanding of the build system. Some of it did not work very
well, e.g. the correct git commit did not show up in ${.sh.version}
when compiling from a git repo.
As of this commit, this is properly included in the mamake
dependency tree by handling it from the libast and ksh93 Mamfiles,
guaranteeing they are properly up to date.
For a release build, the _AST_ksh_release macro is renamed to
_AST_release, because some aspects of libast also use this.
This commit also adds my first attempt at documenting the (very
simple, six-command) mamake language as it is currently implemented
-- which is significantly different from Glenn Fowler's original
paper. This is mostly based on reading the mamake.c source code.
src/cmd/INIT/README-mamake.md:
- Added.
bin/package, src/cmd/INIT/package.sh:
- Delete the hack.
**/Mamfile:
- Remove KSH_RELFLAGS and KSH_SHOPTFLAGS, which supported the hack.
- Delete 'meta' commands. They were no-ops; mamake.c ignores them.
They also did not add any informative value.
src/lib/libast/Mamfile:
- Add a 'virtual' target that obtains the current git commit,
examines the git branch, and decides whether to auto-set an
_AST_git_commit and/or or _AST_release #define to a new
releaseflags.h header file. This is overwritten on each run.
- Add code to the install target that copies limit.h to
include/ast, but only if it doesn't exist or the content of the
original changed. This allows '#include <releaseflags.h>' from
any program using libast while avoiding needless recompiles.
- When there are uncommitted changes, add /MOD (modified) to the
commit hash instead of not defining it at all.
src/cmd/ksh93/**:
- Mamfile: Add a shopt.h target that reads SHOPT.sh and converts it
into a new shopt.h header file in the object code directory. The
shopt.h header only contains SHOPT_* directives that have a value
in SHOPT.sh (not the empty/probe ones). They also do not redefine
the macros if they already exist, so overriding with something
like CCFLAGS+=' -DSHOPT_FOO=1' remains possible.
- **.c: Every c file now #includes "shopt.h" first. So SHOPT_*
macros are no longer passed via environment/MAM variables.
* SHOPT.sh: The AUDITFILE and CMDLIB_DIR macros no longer need an
extra backslash-escape for the double quotes in their values.
(The old way required this because mamake inserts MAM variables
directly into shell scripts as literals without quoting. :-/ )
src/cmd/INIT/mamake.c:
- Import the two minor changes between from 93u+ and 93v-: bind()
is renamed to bindfile() and there is a tweak to detecting an
"improper done statement".
- Allow arbitrary whitespace (isspace()) everywhere, instead of
spaces only. This obsoletes my earlier indentation workaround
from 6cc2f6a0
; turns out mamake always supported indentation, but
with spaces only.
- Do not skip line numbers at the beginning of each line. This
undocumented feature is not and (AFAICT) never has been used.
- Throw an error on unknown command or rule attribute. Quite an
important feature for manual maintenance: catches typos, etc.
156 lines
4 KiB
C
156 lines
4 KiB
C
/***********************************************************************
|
|
* *
|
|
* This software is part of the ast package *
|
|
* Copyright (c) 1982-2012 AT&T Intellectual Property *
|
|
* Copyright (c) 2020-2022 Contributors to ksh 93u+m *
|
|
* and is licensed under the *
|
|
* Eclipse Public License, Version 1.0 *
|
|
* by AT&T Intellectual Property *
|
|
* *
|
|
* A copy of the License is available at *
|
|
* http://www.eclipse.org/org/documents/epl-v10.html *
|
|
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
|
|
* *
|
|
* Information and Software Systems Research *
|
|
* AT&T Research *
|
|
* Florham Park NJ *
|
|
* *
|
|
* David Korn <dgk@research.att.com> *
|
|
* *
|
|
***********************************************************************/
|
|
/*
|
|
* sleep [-s] duration
|
|
*
|
|
* David Korn
|
|
* AT&T Labs
|
|
*
|
|
*/
|
|
|
|
#include "shopt.h"
|
|
#include "defs.h"
|
|
#include <error.h>
|
|
#include <errno.h>
|
|
#include <tmx.h>
|
|
#include "builtins.h"
|
|
#include "FEATURE/time"
|
|
#include "FEATURE/poll"
|
|
|
|
int b_sleep(register int argc,char *argv[],Shbltin_t *context)
|
|
{
|
|
register char *cp;
|
|
register double d=0;
|
|
int sflag=0;
|
|
time_t tloc = 0;
|
|
char *last;
|
|
NOT_USED(context);
|
|
if(!(sh.sigflag[SIGALRM]&(SH_SIGFAULT|SH_SIGOFF)))
|
|
sh_sigtrap(SIGALRM);
|
|
while((argc = optget(argv,sh_optsleep))) switch(argc)
|
|
{
|
|
case 's':
|
|
sflag=1;
|
|
break;
|
|
case ':':
|
|
errormsg(SH_DICT,2, "%s", opt_info.arg);
|
|
break;
|
|
case '?':
|
|
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
|
UNREACHABLE();
|
|
}
|
|
if(error_info.errors)
|
|
{
|
|
errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
|
|
UNREACHABLE();
|
|
}
|
|
argv += opt_info.index;
|
|
if(cp = *argv)
|
|
{
|
|
d = strtod(cp, &last);
|
|
if(*last)
|
|
{
|
|
Time_t now,ns;
|
|
char* pp;
|
|
now = TMX_NOW;
|
|
ns = 0;
|
|
if(*cp == 'P' || *cp == 'p')
|
|
ns = tmxdate(cp, &last, now);
|
|
else if(*last=='.' && sh.radixpoint!='.' && d==(unsigned long)d)
|
|
{
|
|
*(pp=last) = sh.radixpoint;
|
|
if(!strchr(cp,'.'))
|
|
d = strtod(cp,&last);
|
|
*pp = '.';
|
|
if(*last==0)
|
|
goto skip;
|
|
}
|
|
else if(*last!='.' && *last!=sh.radixpoint)
|
|
{
|
|
if(pp = sfprints("exact %s", cp))
|
|
ns = tmxdate(pp, &last, now);
|
|
if(*last && (pp = sfprints("p%s", cp)))
|
|
ns = tmxdate(pp, &last, now);
|
|
}
|
|
if(*last)
|
|
{
|
|
errormsg(SH_DICT,ERROR_exit(1),e_number,*argv);
|
|
UNREACHABLE();
|
|
}
|
|
d = ns - now;
|
|
d /= TMX_RESOLUTION;
|
|
}
|
|
skip:
|
|
if(argv[1])
|
|
{
|
|
errormsg(SH_DICT,ERROR_exit(1),e_oneoperand);
|
|
UNREACHABLE();
|
|
}
|
|
}
|
|
else if(!sflag)
|
|
{
|
|
errormsg(SH_DICT,ERROR_exit(1),e_oneoperand);
|
|
UNREACHABLE();
|
|
}
|
|
if(d > .10)
|
|
{
|
|
time(&tloc);
|
|
tloc += (time_t)(d+.5);
|
|
}
|
|
if(sflag && d==0)
|
|
pause(); /* 'sleep -s' waits until a signal is sent */
|
|
else while(1)
|
|
{
|
|
time_t now;
|
|
errno = 0;
|
|
sh.lastsig=0;
|
|
sh_delay(d,sflag);
|
|
if(sflag || tloc==0 || errno!=EINTR || sh.lastsig)
|
|
break;
|
|
sh_sigcheck();
|
|
if(tloc < (now=time(NIL(time_t*))))
|
|
break;
|
|
d = (double)(tloc-now);
|
|
if(sh.sigflag[SIGALRM]&SH_SIGTRAP)
|
|
sh_timetraps();
|
|
}
|
|
return(0);
|
|
}
|
|
|
|
/*
|
|
* Delay execution for time <t>.
|
|
* If sflag==1, stop sleeping when any signal is received
|
|
* (such as SIGWINCH in an interactive shell).
|
|
*/
|
|
void sh_delay(double t, int sflag)
|
|
{
|
|
int n = (int)t;
|
|
Tv_t ts, tx;
|
|
|
|
ts.tv_sec = n;
|
|
ts.tv_nsec = 1000000000 * (t - (double)n);
|
|
while(tvsleep(&ts, &tx) < 0)
|
|
{
|
|
if ((sh.trapnote & (SH_SIGSET | SH_SIGTRAP)) || sflag)
|
|
return;
|
|
ts = tx;
|
|
}
|
|
}
|