#define HALFDAY (12*HOUR)
#define THISDAY "/usr/spool/at"
int utime
; /* requested time in grains */
int now
; /* when is it */
int uday
; /* day of year to be done */
int today
; /* day of year today */
/* argv[1] is the user's time: e.g., 3AM */
/* argv[2] is a month name or day of week */
/* argv[3] is day of month or 'week' */
/* another argument might be an input file */
fprintf(stderr
, "at: arg count\n");
larg
= makeuday(argc
,argv
)+1;
if (uday
==today
&& larg
<=2 && utime
<=now
)
c
= uyear
%4==0? 366: 365;
filename(THISDAY
, uyear
, uday
, utime
);
ifile
= fopen(argv
[larg
], "r");
fprintf(stderr
, "at: cannot open input: %s\n", argv
[larg
]);
if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
file
= fopen(fname
, "a");
fprintf(stderr
, "at: cannot open memo file\n");
if ((pwfil
= popen("pwd", "r")) == NULL
) {
fprintf(stderr
, "at: can't execute pwd\n");
fgets(pwbuf
, 100, pwfil
);
fprintf(file
, "cd %s", pwbuf
);
fprintf(file
, "%s\n", *ep
++);
while((c
= getc(ifile
)) != EOF
) {
/* p points to a user time */
val
= val
*10+(*p
++ -'0');
val
+=(10* *p
+ p
[1] - 11*'0');
fprintf(stderr
, "at: bad time format:\n");
val
= DAY
+1; /* illegal */
if (val
>= HALFDAY
&& val
<(HALFDAY
+HOUR
))
val
= DAY
+1; /* illegal */
fprintf(stderr
, "at: bad time format\n");
if (val
< 0 || val
>= DAY
) {
fprintf(stderr
, "at: time out of range\n");
fprintf(stderr
, "at: illegal minute field\n");
/* the presumption is that argv[2], argv[3] are either
month day OR weekday [week]. Returns either 2 or 3 as last
/* first of all, what's today */
struct tm
*detail
, *localtime();
uday
= today
= detail
->tm_yday
;
now
= detail
->tm_hour
*100+detail
->tm_min
;
/* is the next argument a month name ? */
for (pt
=months
; pt
->mname
; pt
++) {
if (prefix(argv
[2], pt
->mname
)) {
fprintf(stderr
, "at: ambiguous month\n");
uday
= atoi(argv
[3]) - 1;
fprintf(stderr
, "at: illegal day\n");
uday
+= months
[found
].mlen
;
if (detail
->tm_year
%4==0 && uday
>59)
/* not a month, try day of week */
for (ps
=days
; ps
<days
+7; ps
++) {
if (prefix(argv
[2], *ps
)) {
fprintf(stderr
, "at: ambiguous day of week\n");
/* find next day of this sort */
uday
= found
- detail
->tm_wday
;
if (argc
>3 && strcmp("week", argv
[3])==0) {
sprintf(fname
, "%s/%02d.%03d.%04d.%02d", dir
, y
, d
, t
,
if (access(fname
, 0) == -1)