Xref: utzoo alt.sources:3017 unix-pc.sources:614 Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!tut.cis.ohio-state.edu!n8emr!uncle!donlash From: donlash@uncle.uucp (Donald Lashomb) Newsgroups: alt.sources,unix-pc.sources Subject: repost: cron(1m) facility incl at(1) batch(1) crontab(1) part 4 of 4 Keywords: cron at batch crontab Message-ID: <1991Jan15.200125.3972@uncle.uucp> Date: 15 Jan 91 20:01:25 GMT Reply-To: donlash@uncle.UUCP (Donald Lashomb) Organization: U.N.C.L.E. Lines: 1057 It seems that part 4 of 4 of my cron program somehow was lost in space. I have recieved email from 3 widely separated sites who are missing it, so here is a repost. Sorry about the bandwith to those who got it the first time. ---- Don ---- Cut Here and unpack ---- #!/bin/sh # This is part 04 of a multipart archive if touch 2>&1 | fgrep '[-amc]' > /dev/null then TOUCH=touch else TOUCH=true fi # ============= parsesched.c ============== if test X"$1" != X"-c" -a -f 'parsesched.c'; then echo "File already exists: skipping 'parsesched.c'" else echo "x - extracting parsesched.c (Text)" sed 's/^X//' << 'SHAR_EOF' > parsesched.c && X/* parse: cronjob X * X * =
X * X * = X * X * = X * X *
= X * X * = X * | X * X * = X * | X * X * = X * |, X * X * = X * |- X * X */ X X#include X#include X#include X#include X#include X#include "cron.h" X#include "job.h" X X X/* =============== hooks to the caller of parsesched() ================ */ X X/* parsesched() returns pointer to static SCHED struct or NULL if bad */ X/* sets caller's char *str --> rest of the line in static area */ X Xextern int optind; Xstatic SCHED sched; X X/* ==================================================================== */ X X Xextern void longjmp(); Xstatic jmp_buf parsebad; X#define badsched() longjmp(parsebad,-1) X Xstatic char line[LINESIZ]; Xstatic char *lin; X Xstatic void markstring(); Xstatic void list(); Xstatic int nocvt(); Xstatic int mocvt(); Xstatic int wkcvt(); Xstatic int compare(); Xstatic void eatword(); X/* ==================================================================== */ X XSCHED *parsesched(argc,argv,strp) X int argc; X char **argv; X char **strp; X { X char *mm,*hh,*DD,*MM,*ww; X X if(setjmp(parsebad)) return((SCHED *)NULL); X X /* put command line back together, always put " " at end */ X *line = '\0'; X while(optind < argc) { X strncat(line,argv[optind], X LINESIZ-1-strlen(line)-strlen(argv[optind])); X strncat(line," ", X LINESIZ-1-strlen(line)-strlen(argv[optind])); X ++optind; X } X lin = line; X X /* now break command line into 5 strings */ X markstring(&mm); X markstring(&hh); X markstring(&DD); X markstring(&MM); X markstring(&ww); X while(isspace(*lin)) ++lin; X *strp = lin; /* pass back pointer to rest of line */ X X list(mm,sched.min,0,60,0,nocvt); X list(hh,sched.hour,0,24,0,nocvt); X list(DD,sched.mday,1,32,0,nocvt); X list(MM,sched.mon,0,12,1,mocvt); X list(ww,sched.wday,0,7,0,wkcvt); X X/* if specify '*' for only one "days" field X * then only the other one counts X */ X if((*DD == '*') && (*ww != '*')) X memset(sched.mday,'\0',32); X if((*ww == '*') && (*DD != '*')) X memset(sched.wday,'\0',7); X X/* note: things like Feb 31st are not checked for X * the resched() routine takes care of these X */ X return(&sched); X } X X X/* mark separate strings -------------------------------------- */ X Xstatic void markstring(str) X char **str; X { X while(isspace(*lin)) ++lin; X if(*lin == '\0') badsched(); X *str = lin; X while(!isspace(*lin)) ++lin; X *lin++ = '\0'; X } X X/* set arrays from ascii "lists" ------------------------------ */ X Xstatic void list(asc,ary,beg,end,off,cvt) X char *asc; X char ary[]; X int beg; X int end; X int off; X int (*cvt)(); X { X register int i,b,e; X X if(strcmp(asc,"*") == 0) { X memset(ary,'\001',end); X return; X } X memset(ary,'\0',end); X while(1) { X if(isdigit(*asc)) { X b = atoi(asc)-off; X while(isdigit(*asc)) ++asc; X } X else X b = (*cvt)(&asc); X X if(*asc == '-') { X ++asc; X if(isdigit(*asc)) { X e = atoi(asc)-off; X while(isdigit(*asc)) ++asc; X } X else X e = (*cvt)(&asc); X } X else X e = b; X X for(i=b;i<=e;++i) { X if((i < beg) || (i > end)) X badsched(); X ary[i] = '\001'; X } X switch(*asc) { X case '\0': X return; X case ',': X ++asc; X continue; X } X badsched(); X } X } X Xstatic int nocvt(ascp) X char **ascp; X { X badsched(); X /*NOTREACHED*/ X } X X Xstatic char *months[] = { X "January","February","March","April", X "May","June","July","August", X "September","October","November","December" X }; Xstatic int mocvt(ascp) X register char **ascp; X { X register int i; X register char *p; X X /* check month names */ X for(i=0;i<12;++i) { X p = months[i]; X if(compare(*ascp,p,3) == 0) { X eatword(ascp,p); X break; X } X } X if(i > 11) badsched(); X return(i); X } X X Xstatic char *wdays[] = { X "Sunday","Monday","Tuesday","Wednesday", X "Thursday","Friday","Saturday" X }; Xstatic int wkcvt(ascp) X register char **ascp; X { X register int i; X register char *p; X X /* check weekday names */ X for(i=0;i<7;++i) { X p = wdays[i]; X if(compare(*ascp,p,3) == 0) { X eatword(ascp,p); X break; X } X } X if(i > 6) badsched(); X return(i); X } X Xstatic int compare(p,q,n) X register char *p,*q; X register int n; X { X while(n--) X if(tolower(*p++) != tolower(*q++)) return(-1); X return(0); X } X Xstatic void eatword(ascp,p) X register char **ascp; X register char *p; X { X while(tolower(**ascp) == tolower(*p)) { ++(*ascp); ++p; } X } SHAR_EOF $TOUCH -am 1007171790 parsesched.c && chmod 0644 parsesched.c || echo "restore of parsesched.c failed" set `wc -c parsesched.c`;Wc_c=$1 if test "$Wc_c" != "4523"; then echo original size 4523, current size $Wc_c fi fi # ============= parsetime.c ============== if test X"$1" != X"-c" -a -f 'parsetime.c'; then echo "File already exists: skipping 'parsetime.c'" else echo "x - extracting parsetime.c (Text)" sed 's/^X//' << 'SHAR_EOF' > parsetime.c && X/* parse: at