|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T a
Length: 4044 (0xfcc) Types: TextFile Names: »add.c«
└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit └─⟦653021b30⟧ »EurOpenD3/utils/downtime.tar.Z« └─⟦946c717da⟧ └─⟦this⟧ »add.c«
/* * Copyright (c) 1988 Michael A. Cooper, University of Southern California. * This program may be used, copied, modified, and redistributed freely * for noncommercial purposes, so long as this notice remains intact. */ #ifndef lint static char *RCSid = "$Header: add.c,v 4.2 88/07/05 15:58:01 mcooper Exp $"; #endif /* *------------------------------------------------------------------ * * $Source: /usr/skat3/src/common/usc/etc/downtime/RCS/add.c,v $ * $Revision: 4.2 $ * $Date: 88/07/05 15:58:01 $ * $State: Exp $ * *------------------------------------------------------------------ * * Michael A. Cooper * Research and Development Group * University Computing Services * University of Southern California * (mcooper@oberon.USC.EDU) * *------------------------------------------------------------------ * * $Log: add.c,v $ * Revision 4.2 88/07/05 15:58:01 mcooper * Added copyright notice. * * Revision 4.1 88/06/10 13:09:59 mcooper * If adding motd, mark it as done to * avoid dup's. * * Revision 4.0 88/04/20 15:40:42 mcooper * Version 4. * * Revision 3.3 88/04/19 18:27:14 mcooper * Use stmsg() to print status of what * we are doing. * * Revision 3.2 88/04/11 19:47:03 mcooper * Converted all dt_flags to use flag * bits. * * Revision 3.1 88/03/15 14:42:10 mcooper * Malloc dt_shutter and dt_reason. * * Revision 3.0 87/07/24 14:11:14 mcooper * Version 3. * *------------------------------------------------------------------ */ #include "defs.h" /* * add - Add a downtime entry to the downtime database. */ add(d, flags) struct downtime *d; int flags; { struct downtime *n; char *ddate, *p; FILE *fd; long delta; int domotd = FALSE; if (!d->dt_reason || !d->dt_reason[0]) { d->dt_reason = (char *) xmalloc(strlen(EMPTY)+1); (void) strcpy(d->dt_reason, EMPTY); } if ((ddate = ttod(d->dt_down)) == NULL) { return(-1); } /* * check to see if there is already an entry for * this time */ if (n = (struct downtime *) getdtdate(ddate)) { fprintf(stderr, "There is already an entry for %s:\n\n", mkdate(n->dt_down, D_VERBOSE)); prinfo(n); fprintf(stderr, "\n"); return(-1); } delta = getdelta(d->dt_orderdown, d->dt_down); if (delta < 0) { fprintf(stderr, "You must specify a down time in the future:\n"); fprintf(stderr, "\n\tDown: %s\n", mkdate(d->dt_down, D_DATE)); fprintf(stderr, "\t Now: %s\n\n", mkdate(d->dt_orderdown, D_DATE)); return(-1); } if (getdelta(d->dt_down, d->dt_up) < 1) { fprintf(stderr, "The up time must occur after the down time:\n"); fprintf(stderr, "\n\tDown: %s\n", mkdate(d->dt_down, D_DATE)); fprintf(stderr, "\t Up: %s\n\n", mkdate(d->dt_up, D_DATE)); return(-1); } if ((flags & FORCE) == 0) { printf("\n"); prinfo(d); printf("\n"); if (!yes("Add")) return(-1); } if ((flags & QUIET) == 0) { printf("\n Adding [%s] ... ", mkdate(d->dt_down, D_DATE)); fflush(stdout); } if ((d->dt_flags & F_MOTD) && ((delta < motdtime) && (delta >= 0))) { domotd = TRUE; d->dt_flags |= F_DONEMOTD; } d->dt_islocked = FALSE; if ((p = (char *) mkdtline(d)) == NULL) { fprintf(stderr, "downtime: add: mkdtline failed.\n"); return(-1); } dtclose(); stmsg("\n Lock data file ..."); if (dtfilelock() < 0) { return(-1); } if ((fd = fopen(datafile, "a")) == NULL) { perror(datafile); return(-1); } stmsg("\n Add entry ..."); (void) fputs(p, fd); (void) fclose(fd); stmsg("\n Unlock data file ..."); if (dtfileunlock() < 0) { return(-1); } /* * actually add the msg to the motd. */ if (domotd) { stmsg("\n Add motd message ..."); addmotd(d); } if (!quiet) { printf("done.\n\n"); } dtlog("ADD: %s%s%s.", mkdate(d->dt_down, D_LOGFILE), (strcmp(d->dt_reason, EMPTY)) ? " for " : "", (strcmp(d->dt_reason, EMPTY)) ? d->dt_reason : ""); warnusers(d, flags); return(0); }