]> code.citadel.org Git - citadel.git/blobdiff - citadel/readlog.c
fix all the <time.h> vs. <sys/time.h> issues, hopefully
[citadel.git] / citadel / readlog.c
index 91e196f04686dde4e3baaac081feba8051d140fb..b11dbf46c902f0b3f3bfe38509b5e01b9bb4fb0e 100644 (file)
@@ -1,99 +1,89 @@
 /* 
- * readlog.c
- * v1.4
+ * $Id$
+ *
+ * A simple program to parse citadel.log
  */
 
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdio.h>
-#include <time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <string.h>
+#include <errno.h>
 #include "citadel.h"
 
-void get_config();
+void get_config (void);
 struct config config;
 
-void last20(file,pos)
-int file;
-long pos;
-       {
-       int a,count;
-       long aa;
-       struct calllog calllog;
-       struct calllog listing[20];
-       struct tm *tm;
-       char *tstring;
-       
-       count=0;
-       for (a=0; a<20; ++a) {
-               listing[a].CLfullname[0]=0;
-               listing[a].CLtime=0L;
-               listing[a].CLflags=0;
-               }
-       aa=pos-1;
-       while(count<20) {
-               if (aa<0L) aa=CALLLOG;
-               lseek(file,(aa*sizeof(struct calllog)),0);
-               a=read(file,(char *)&calllog,sizeof(struct calllog));
-               if (calllog.CLflags==CL_LOGIN) {
-                       strcpy(listing[count].CLfullname,calllog.CLfullname);
-                       listing[count].CLtime=calllog.CLtime;
-                       listing[count].CLflags=calllog.CLflags;
-                       ++count;
-                       }
-               if (aa==pos) break;
-               aa=aa-1;
-               }
-       for (a=19; a>=0; --a) {
-               tm=(struct tm *)localtime(&listing[a].CLtime);
-               tstring=(char *)asctime(tm);
-               printf("%30s %s",listing[a].CLfullname,tstring);
-               }
-       }
+int 
+main (int argc, char **argv)
+{
+  time_t LogTime;
+  unsigned int LogType;
+  char LogName[SIZ];
 
-void main(argc,argv)
-int argc;
-char *argv[]; {
-       struct calllog calllog;
-       int file,pos,a,b;
-       char aaa[100];
-       struct tm *tm;
-       char *tstring;
+  char buf[SIZ];
+  char aaa[100];
+  struct tm *tm;
+  char *tstring;
+  FILE *logfp;
+
+  get_config ();
+
+  logfp = fopen ("citadel.log", "r");
+  if (logfp == NULL)
+    {
+      perror ("Could not open citadel.log");
+      exit (errno);
+    }
+  else
+    {
+      while (fgets (buf, sizeof buf, logfp) != NULL)
+       {
+         buf[strlen (buf) - 1] = 0;
+         strcat(buf, " ");
 
-       get_config();
-       file=open("calllog.pos",O_RDONLY);
-       a=read(file,(char *)&pos,sizeof(int));
-       close(file);
+         LogTime = atol (strtok(buf, "|"));
+          LogType = atol (strtok(NULL, "|"));
+          strcpy(LogName, strtok(NULL, "|"));
 
-       file=open("calllog",O_RDONLY);
-       if (argc>=2) {
-               if (!strcmp(argv[1],"-t")) last20(file,(long)pos);
-               else fprintf(stderr,"%s: usage: %s [-t]\n",argv[0],argv[0]);
-               close(file);
-               exit(0);
-               }
-else {
-       lseek(file,(long)(pos*sizeof(struct calllog)),0);
-       for (a=0; a<CALLLOG; ++a) {
-               if ((a+pos)==CALLLOG) lseek(file,0L,0);
-               b=read(file,(char *)&calllog,sizeof(struct calllog));
-       if (calllog.CLflags!=0) {
-               strcpy(aaa,"");
-               if (calllog.CLflags&CL_CONNECT) strcpy(aaa,"Connect");
-               if (calllog.CLflags&CL_LOGIN)   strcpy(aaa,"Login");
-               if (calllog.CLflags&CL_NEWUSER) strcpy(aaa,"New User");
-               if (calllog.CLflags&CL_BADPW)   strcpy(aaa,"Bad PW Attempt");
-               if (calllog.CLflags&CL_TERMINATE) strcpy(aaa,"Terminate");
-               if (calllog.CLflags&CL_DROPCARR) strcpy(aaa,"Dropped Carrier");
-               if (calllog.CLflags&CL_SLEEPING) strcpy(aaa,"Sleeping");
-               if (calllog.CLflags&CL_PWCHANGE) strcpy(aaa,"Changed Passwd");
-               tm=(struct tm *)localtime(&calllog.CLtime);
-               tstring=(char *)asctime(tm);
-               printf("%30s %20s %s",calllog.CLfullname,aaa,tstring);
-               }
-               }
+         if (LogType != 0)
+           {
+             strcpy (aaa, "");
+             if (LogType & CL_CONNECT)
+               strcpy (aaa, "Connect");
+             if (LogType & CL_LOGIN)
+               strcpy (aaa, "Login");
+             if (LogType & CL_NEWUSER)
+               strcpy (aaa, "New User");
+             if (LogType & CL_BADPW)
+               strcpy (aaa, "Bad PW Attempt");
+             if (LogType & CL_TERMINATE)
+               strcpy (aaa, "Terminate");
+             if (LogType & CL_DROPCARR)
+               strcpy (aaa, "Dropped Carrier");
+             if (LogType & CL_SLEEPING)
+               strcpy (aaa, "Sleeping");
+             if (LogType & CL_PWCHANGE)
+               strcpy (aaa, "Changed Passwd");
+             tm = (struct tm *) localtime (&LogTime);
+             tstring = (char *) asctime (tm);
+             printf ("%30s %20s %s", LogName, aaa, tstring);
+           }
        }
-       close(file);
-       exit(0);
+    }
+  fclose(logfp);
+  exit (0);
 }
-