head     1.1;
branch   1.1.1;
access   ;
symbols  nastore3-beta-20000227:1.1.1.1 NAS:1.1.1;
locks    ; strict;
comment  @# @;


1.1
date     2000.02.28.02.18.14;  author wrstuden;  state Exp;
branches 1.1.1.1;
next     ;

1.1.1.1
date     2000.02.28.02.18.14;  author wrstuden;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <msscompat.h>
#include <dba.h>

int year;
DbA* filesdb, *bytesdb;
OFF_T filesize, files, bytes;
int month, day,  i, last_day = -1, last_month = -1;


void update_dbs()
{
  char key[24], valuestr[100];
  OFF_T value;
  int len;

  /* calculate the key */
  sprintf(key, "%04d%02d%02d", year, last_month, last_day);
  /* merge old values with new and save again for files and bytes */
  if((len = dba_fetch(filesdb, key, valuestr, 99)) > 0){
    valuestr[len] = '\0';
    value = atoll(valuestr);
    files += value;
  }
  sprintf(valuestr, "%lld", files);
  if(dba_store(filesdb, key, valuestr, strlen(valuestr)) != 0){
    fprintf(stderr, "error storing value\n");
    dba_close(bytesdb);
    dba_close(filesdb);
    exit(1);
  }

  if((len = dba_fetch(bytesdb, key, valuestr, 99)) > 0){
    valuestr[len] = '\0';
    value = atoll(valuestr);
    bytes += value;
  }
  sprintf(valuestr, "%lld", bytes);
  if(dba_store(bytesdb, key, valuestr, strlen(valuestr)) != 0){
    fprintf(stderr, "error storing value\n");
    dba_close(bytesdb);
    dba_close(filesdb);
    exit(1);
  }
}
  

/* caution, built for speed, not robustness. error checking is off */

main(int argc, char** argv)
{

  FILE* fp = stdin;
  char *p, linebuffer[1024], buffer[1024 * 64];



  /* parse args, check for stdin vs files on cmd line usage, 
     initialize arrays */
  if(argc  == 2){
    year = atoi(argv[1]);
    if(year < 70)
      year += 2000;
    else
      year += 1900;
  }
  else{
    fprintf(stderr, "usage: rashlogstat starting_year\n");
    exit(1);
  }

  if((filesdb = newDbAbstractor("FILES_ARCHIVED")) == NULL){
    fprintf(stderr, "couldn't open database FILES_ARCHIVED\n");
    exit(1);
  }

  if((bytesdb = newDbAbstractor("BYTES_ARCHIVED")) == NULL){
    fprintf(stderr, "couldn't open database FILES_ARCHIVED\n");
    exit(1);
  }

  setvbuf(fp, buffer, _IOFBF, 1024 * 64);

  /* read loop for each file */
  while(fgets(linebuffer, 1024, fp) != NULL){

    /* get line, parse fields */
    if((p = strtok(linebuffer, " /\t\n")) == NULL)
      continue;

    month = atoi(p);
    if((p = strtok(NULL, " /\t\n")) == NULL)
      continue;
    day = atoi(p);
    if((p = strtok(NULL, " /\t\n")) == NULL)
      continue;
    filesize = atoll(p);
    
    if( (month != last_month || day != last_day) &&
       (last_month != -1)){

      update_dbs();
      /* reset values */
      files = bytes = 0LL;
      /* check for year rollover */
      if(last_month = 12 && month == 1)
	++year;
    }
    bytes += filesize;
    files++;
    last_month == month;
    last_day == day;
  }

  /* write the partial record */
  update_dbs();

  dba_close(filesdb);
  dba_close(bytesdb);
}













@


1.1.1.1
log
@Import of snapshot of nastore3 code. Includes kernel code for dmfs, dmfs
user utilities, ms66 import and export, vvm, and volman. Also includes
makefile magic to automatically generate .tgz source files from the source.
Solaris support a bit of a question as zoularis is not working at the
moment.
@
text
@@
