Quizzer
view release on metacpan or search on metacpan
exercises/compile-tcsh/tcsh-6.10.00/tc.sched.c view on Meta::CPAN
}
tp = (struct sched_event *) xcalloc(1, sizeof *tp);
#ifdef _SX
tp->t_when = cur_time - ltp->tm_sec + dif_hour * 3600 + dif_min * 60;
#else /* _SX */
tp->t_when = cur_time - ltp->tm_sec + dif_hour * 3600L + dif_min * 60L;
#endif /* _SX */
/* use of tm_sec: get to beginning of minute. */
if (!sched_ptr || tp->t_when < sched_ptr->t_when) {
tp->t_next = sched_ptr;
sched_ptr = tp;
}
else {
tp1 = sched_ptr->t_next;
tp2 = sched_ptr;
while (tp1 && tp->t_when >= tp1->t_when) {
tp2 = tp1;
tp1 = tp1->t_next;
}
tp->t_next = tp1;
tp2->t_next = tp;
}
tp->t_lex = saveblk(v);
}
/*
* Execute scheduled events
*/
/*ARGSUSED*/
void
sched_run(n)
int n;
{
time_t cur_time;
register struct sched_event *tp, *tp1;
struct wordent cmd, *nextword, *lastword;
struct command *t;
Char **v, *cp;
extern Char GettingInput;
#ifdef BSDSIGS
sigmask_t omask;
omask = sigblock(sigmask(SIGINT)) & ~sigmask(SIGINT);
#else
(void) sighold(SIGINT);
#endif
USE(n);
(void) time(&cur_time);
tp = sched_ptr;
/* bugfix by: Justin Bur at Universite de Montreal */
/*
* this test wouldn't be necessary if this routine were not called before
* each prompt (in sh.c). But it is, to catch missed alarms. Someone
* ought to fix it all up. -jbb
*/
if (!(tp && tp->t_when < cur_time)) {
#ifdef BSDSIGS
(void) sigsetmask(omask);
#else
(void) sigrelse(SIGINT);
#endif
return;
}
if (GettingInput)
(void) Cookedmode();
while (tp && tp->t_when < cur_time) {
if (seterr) {
xfree((ptr_t) seterr);
seterr = NULL;
}
cmd.word = STRNULL;
lastword = &cmd;
v = tp->t_lex;
for (cp = *v; cp; cp = *++v) {
nextword = (struct wordent *) xcalloc(1, sizeof cmd);
nextword->word = Strsave(cp);
lastword->next = nextword;
nextword->prev = lastword;
lastword = nextword;
}
lastword->next = &cmd;
cmd.prev = lastword;
tp1 = tp;
sched_ptr = tp = tp1->t_next; /* looping termination cond: */
blkfree(tp1->t_lex); /* straighten out in case of */
xfree((ptr_t) tp1); /* command blow-up. */
/* expand aliases like process() does. */
alias(&cmd);
/* build a syntax tree for the command. */
t = syntax(cmd.next, &cmd, 0);
if (seterr)
stderror(ERR_OLD);
/* execute the parse tree. */
execute(t, -1, NULL, NULL);
/* done. free the lex list and parse tree. */
freelex(&cmd), freesyn(t);
}
if (GettingInput && !just_signaled) { /* PWP */
(void) Rawmode();
ClearLines(); /* do a real refresh since something may */
ClearDisp(); /* have printed to the screen */
Refresh();
}
just_signaled = 0;
#ifdef BSDSIGS
(void) sigsetmask(omask);
#else
(void) sigrelse(SIGINT);
#endif
}
( run in 0.822 second using v1.01-cache-2.11-cpan-364913b4093 )