Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
-M option for sched
- X-seq: zsh-workers 727
- From: Zefram <A.Main@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Z Shell workers mailing list)
- Subject: -M option for sched
- Date: Wed, 10 Jan 1996 06:50:32 +0000 (GMT)
-----BEGIN PGP SIGNED MESSAGE-----
The option below adds the -M option to sched. I note that using the
relative time form it is possible to get commands scheduled for some
time that is not an exact minute, which is not possible when specifying
an absolute time. Nevertheless, the -M output form always uses
absolute time. I intend to correct this disparity at some point, as
well as fixing a couple of other shortcomings in the command.
-zefram
*** 1.10 1996/01/10 05:41:18
--- Src/builtin.c 1996/01/10 06:37:58
***************
*** 5011,5028 ****
bin_sched(char *nam, char **argv, char *ops, int func)
{
char *s = *argv++;
! time_t t;
long h, m;
struct tm *tm;
struct schedcmd *sch, *sch2, *schl;
int sn;
! /* If the argument begins with a -, remove the specified item from the
! schedule. */
if (s && *s == '-') {
! sn = atoi(s + 1);
!
! if (!sn) {
zwarnnam("sched", "usage for delete: sched -<item#>.", NULL, 0);
return 1;
}
--- 5011,5031 ----
bin_sched(char *nam, char **argv, char *ops, int func)
{
char *s = *argv++;
! time_t t, T = time(NULL);
long h, m;
struct tm *tm;
struct schedcmd *sch, *sch2, *schl;
int sn;
! /* If the argument begins with a -, remove the specified *
! * items from the schedule. */
if (s && *s == '-') {
! if(*argv) {
! zwarnnam("sched", "too many arguments", NULL, 0);
! return 1;
! }
! sn = zstrtol(s + 1, &s, 10);
! if (!sn || *s) {
zwarnnam("sched", "usage for delete: sched -<item#>.", NULL, 0);
return 1;
}
***************
*** 5046,5069 ****
for (sn = 1, sch = schedcmds; sch; sch = sch->next, sn++) {
t = sch->time;
tm = localtime(&t);
! ztrftime(tbuf, 20, "%a %b %e %k:%M:%S", tm);
! printf("%3d %s %s\n", sn, tbuf, sch->cmd);
}
return 0;
} else if (!*argv) {
/* other than the two cases above, sched *
! *requires at least two arguments */
zwarnnam("sched", "not enough arguments", NULL, 0);
return 1;
}
! /* The first argument specifies the time to schedule the command for. The
! remaining arguments form the command. */
if (*s == '+') {
! /* + introduces a relative time. The rest of the argument is an
! hour:minute offset from the current time. Once the hour and minute
! numbers have been extracted, and the format verified, the resulting
! offset is simply added to the current time. */
h = zstrtol(s + 1, &s, 10);
if (*s != ':') {
zwarnnam("sched", "bad time specifier", NULL, 0);
--- 5049,5085 ----
for (sn = 1, sch = schedcmds; sch; sch = sch->next, sn++) {
t = sch->time;
tm = localtime(&t);
! if(ops['M']) {
! int h = tm->tm_hour, m = tm->tm_min;
! if((t - T) >= 24 * 3600)
! h += 24 * ((t - T) / (24 * 3600));
! if(t < T)
! printf("# ");
! printf("sched %02d:%02d ", h, m);
! printquoted(sch->cmd);
! } else {
! ztrftime(tbuf, 20, "%a %b %e %k:%M:%S", tm);
! printf("%3d %s ", sn, tbuf);
! nicefputs(sch->cmd, stdout);
! }
! putchar('\n');
}
return 0;
} else if (!*argv) {
/* other than the two cases above, sched *
! * requires at least two arguments */
zwarnnam("sched", "not enough arguments", NULL, 0);
return 1;
}
! /* The first argument specifies the time to schedule the command *
! * for. The remaining arguments form the command. */
if (*s == '+') {
! /* + introduces a relative time. The rest of the argument is *
! * an hour:minute offset from the current time. Once the *
! * hour and minute numbers have been extracted, and the *
! * format verified, the resulting offset is simply added to *
! * the current time. */
h = zstrtol(s + 1, &s, 10);
if (*s != ':') {
zwarnnam("sched", "bad time specifier", NULL, 0);
***************
*** 5074,5080 ****
zwarnnam("sched", "bad time specifier", NULL, 0);
return 1;
}
! t = time(NULL) + h * 3600 + m * 60;
} else {
/* If there is no +, an absolute time of day must have been given.
This is in hour:minute format, optionally followed by a string starting
--- 5090,5096 ----
zwarnnam("sched", "bad time specifier", NULL, 0);
return 1;
}
! t = T + h * 3600 + m * 60;
} else {
/* If there is no +, an absolute time of day must have been given.
This is in hour:minute format, optionally followed by a string starting
***************
*** 5090,5108 ****
zwarnnam("sched", "bad time specifier", NULL, 0);
return 1;
}
! t = time(NULL);
! tm = localtime(&t);
! t -= tm->tm_sec + tm->tm_min * 60 + tm->tm_hour * 3600;
if (*s == 'p' || *s == 'P')
h += 12;
t += h * 3600 + m * 60;
! /* If the specified time is before the current time, it must refer to
! tomorrow. */
! if (t < time(NULL))
t += 3600 * 24;
}
! /* The time has been calculated; now add the new entry to the linked list
! of scheduled commands. */
sch = (struct schedcmd *) zcalloc(sizeof *sch);
sch->time = t;
sch->cmd = ztrdup(join(argv, ' '));
--- 5106,5123 ----
zwarnnam("sched", "bad time specifier", NULL, 0);
return 1;
}
! tm = localtime(&T);
! t = T - tm->tm_sec - tm->tm_min * 60 - tm->tm_hour * 3600;
if (*s == 'p' || *s == 'P')
h += 12;
t += h * 3600 + m * 60;
! /* If the specified time is before the current time, *
! * it must refer to tomorrow. */
! if (t < T)
t += 3600 * 24;
}
! /* The time has been calculated; now add the new entry to *
! * the linked list of scheduled commands. */
sch = (struct schedcmd *) zcalloc(sizeof *sch);
sch->time = t;
sch->cmd = ztrdup(join(argv, ' '));
*** 1.7 1996/01/10 05:41:18
--- Src/hashtable.h 1996/01/10 06:23:49
***************
*** 297,303 ****
{NULL, "readonly", BINF_TYPEOPTS | BINF_MAGICEQUALS, bin_typeset, 0, -1, 0, "LRZfiltux", "r"},
{NULL, "rehash", 0, bin_hash, 0, 0, 0, "df", "r"},
{NULL, "return", 0, bin_break, 0, 1, BIN_RETURN, NULL, NULL},
! {NULL, "sched", 0, bin_sched, 0, -1, 0, NULL, NULL},
{NULL, "set", BINF_SETOPTS | BINF_PLUSOPTS, bin_set, 0, -1, 0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZaefghjklmnopsuvwxy", NULL},
{NULL, "setopt", BINF_PLUSOPTS, bin_setopt, 0, -1, BIN_SETOPT, "0123456789BCDEFGHIJKLMNOPQRSTUVWXYZaefghjklmnopsuvwxy", NULL},
{NULL, "shift", 0, bin_shift, 0, -1, 0, NULL, NULL},
--- 297,303 ----
{NULL, "readonly", BINF_TYPEOPTS | BINF_MAGICEQUALS, bin_typeset, 0, -1, 0, "LRZfiltux", "r"},
{NULL, "rehash", 0, bin_hash, 0, 0, 0, "df", "r"},
{NULL, "return", 0, bin_break, 0, 1, BIN_RETURN, NULL, NULL},
! {NULL, "sched", 0, bin_sched, 0, -1, 0, "M", NULL},
{NULL, "set", BINF_SETOPTS | BINF_PLUSOPTS, bin_set, 0, -1, 0, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZaefghjklmnopsuvwxy", NULL},
{NULL, "setopt", BINF_PLUSOPTS, bin_setopt, 0, -1, BIN_SETOPT, "0123456789BCDEFGHIJKLMNOPQRSTUVWXYZaefghjklmnopsuvwxy", NULL},
{NULL, "shift", 0, bin_shift, 0, -1, 0, NULL, NULL},
*** 1.7 1996/01/10 05:41:18
--- Doc/zshbuiltins.man 1996/01/10 06:41:23
***************
*** 778,788 ****
.PD 0
\fBsched\fP [+]\fIhh\fP:\fImm\fP \fIcommand\fP ...
.TP
! \fBsched\fP [ \-\fIitem\fP ]
.PD
Make an entry in the scheduled list of commands to execute.
The time may be specified in either absolute or relative time.
With no arguments, prints the list of scheduled commands.
With the argument \-\fIitem\fP, removes the given item
from the list.
.TP
--- 778,791 ----
.PD 0
\fBsched\fP [+]\fIhh\fP:\fImm\fP \fIcommand\fP ...
.TP
! \fBsched\fP [ \-\fBM\fP ] [ \-\fIitem\fP ]
.PD
Make an entry in the scheduled list of commands to execute.
The time may be specified in either absolute or relative time.
With no arguments, prints the list of scheduled commands.
+ The option \-\fBM\fP causes this list to be in the form of
+ .I sched
+ commands.
With the argument \-\fIitem\fP, removes the given item
from the list.
.TP
-----BEGIN PGP SIGNATURE-----
Version: 2.6.i
iQCVAgUBMPNhqHD/+HJTpU/hAQElXQP/eT4i9eb2+5KUFSOZK3Wd5vyNdFJBKFA1
KcMI/UPxuZ7CbY3FTItoX8u4Wl9BhZSkApCLOg4mUrxFfIDFehkHEGBzz5Q08Gl+
J4xCHOAMFWFUNixUdKFMknxBcKIgUvDhrU0xqi51yks4dyF7GhljmFQekIknttNk
xA/yNU5/SEk=
=UXsT
-----END PGP SIGNATURE-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author