src/lib/apacheLog.c 1.5
1.5 2009/09/10 01:50:01 kent
Checking end coordinate for off-chromosome.
Index: src/lib/apacheLog.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/apacheLog.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -b -B -U 4 -r1.4 -r1.5
--- src/lib/apacheLog.c 28 Aug 2009 00:56:01 -0000 1.4
+++ src/lib/apacheLog.c 10 Sep 2009 01:50:01 -0000 1.5
@@ -56,8 +56,21 @@
badFormat(pLl, line, fileName, lineIx,
"bad time stamp");
}
+time_t apacheAccessLogTimeToTick(char *timeStamp)
+/* Convert something like 27/Aug/2009:09:25:32 to Unix timestamp (seconds since 1970).
+ * On error returns zero. */
+
+{
+struct tm tm;
+ZeroVar(&tm);
+if (strptime(timeStamp, "%d/%b/%Y:%T", &tm) != NULL)
+ return mktime(&tm);
+else
+ return 0;
+}
+
struct apacheAccessLog *apacheAccessLogParse(char *line,
char *fileName, int lineIx)
/* Return a apacheAccessLog from line. Return NULL if there's a parsing
* problem, but don't abort. */
@@ -98,11 +111,10 @@
}
ll->timeZone = nextWord(&s);
/* Convert time stamp to Unix tick. */
-struct tm tm;
-if (strptime(ll->timeStamp, "%d/%b/%Y:%T", &tm) != NULL)
- ll->tick = mktime(&tm);
+ll->tick = apacheAccessLogTimeToTick(ll->timeStamp);
+
buf = e+2;
if (buf[0] != '"')
{
@@ -181,4 +193,17 @@
return ll;
}
+int apacheAccessLogCmpTick(const void *va, const void *vb)
+/* Compare items to sort by tick (which tracks timestamp) */
+{
+const struct apacheAccessLog *a = *((struct apacheAccessLog **)va);
+const struct apacheAccessLog *b = *((struct apacheAccessLog **)vb);
+if (a->tick < b->tick)
+ return -1;
+else if (a->tick == b->tick)
+ return 0;
+else
+ return 1;
+}
+