home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trn / part02 / last.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-02  |  2.0 KB  |  80 lines

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