1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
/* $Id: last.c,v 3.0 1992/02/01 03:09:32 davison Trn $
*/
/* This software is Copyright 1991 by Stan Barber.
*
* Permission is hereby granted to copy, reproduce, redistribute or otherwise
* use this software as long as: there is no monetary profit gained
* specifically from the use or reproduction of this software, it is not
* sold, rented, traded or otherwise marketed, and this copyright notice is
* included prominently in any copy made.
*
* The authors make no claims as to the fitness or correctness of this software
* for any use whatsoever, and it is provided as is. Any use of this software
* is at the user's own risk.
*/
#include "EXTERN.h"
#include "common.h"
#include "trn.h"
#include "util.h"
#include "intrp.h"
#include "INTERN.h"
#include "last.h"
char *lastname = Nullch; /* path name of .rnlast file */
void
last_init(tcbuf)
char *tcbuf;
{
lastname = savestr(filexp(LASTNAME));
if ((tmpfp = fopen(lastname,"r")) != Nullfp &&
fgets(tcbuf,1024,tmpfp) != Nullch) {
tcbuf[strlen(tcbuf)-1] = '\0';
lastngname = savestr(tcbuf);
fgets(tcbuf,1024,tmpfp);
lasttime = atol(tcbuf);
fgets(tcbuf,1024,tmpfp);
lastactsiz = atol(tcbuf);
if (fgets(tcbuf,1024,tmpfp) != Nullch)
lastnewtime = atol(tcbuf);
else
lastnewtime = lasttime;
#if 1
/* If the time is in the future, rewind by thirty days */
if (lastnewtime > time(Null(time_t*)))
lastnewtime = time(Null(time_t*)) - 30L*24*60*60;
#endif
/* If the time wasn't set, just give them 2 days worth of groups */
if (!lastnewtime)
lastnewtime = time(Null(time_t*)) - 2L*24*60*60;
if (fgets(tcbuf,1024,tmpfp) != Nullch)
lastnewsize = atol(tcbuf);
else
lastnewsize = 0;
fclose(tmpfp);
}
else {
lastngname = nullstr;
lasttime = 0;
lastactsiz = 0;
lastnewsize = 0;
/* Use two days ago as an initial value for finding new groups. */
lastnewtime = time(Null(time_t*)) - 2L*24*60*60;
}
}
/* put out certain values for next run of rn */
void
writelast()
{
if ((tmpfp = fopen(lastname,"w")) != Nullfp) {
fprintf(tmpfp,"%s\n%ld\n%ld\n%ld\n%ld\n",
(ngname==Nullch?nullstr:ngname),(long)lasttime,(long)lastactsiz,
(long)lastnewtime,(long)lastnewsize);
fclose(tmpfp);
}
else
printf(cantcreate,lastname) FLUSH;
}
|