00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008 #include <assert.h>
00009 #include <string.h>
00010 #include <getopt.h>
00011
00012 #ifndef __USE_XOPEN
00013 #define __USE_XOPEN
00014 #endif
00015 #include <time.h>
00016
00017 #include "spinDbAPI.h"
00018
00019
00020
00021
00022 int verboseMode = false;
00023 int quietMode = false;
00024
00025
00026
00027
00028
00029 time_t
00030 getTimeStamp(const char *timeformat[] , const char *timestr)
00031 {
00032 time_t ts=0;
00033 struct tm tm;
00034
00035 ts = time(NULL);
00036 localtime(&ts);
00037
00038 if(strncmp(timestr,"now",3)) {
00039 memset(&tm,0x0,sizeof(struct tm));
00040 for(int i=0; timeformat[i]!=NULL ; i++ ) {
00041
00042 if(strptime(timestr,timeformat[i], &tm)!=NULL) {
00043
00044 break;
00045 }
00046 }
00047 ts = mktime(&tm);
00048 }
00049 if(ts<0) {
00050 fprintf(stderr,"time stamp %s not understood\n",timestr);
00051 fprintf(stderr,"\tvalid formats are:\n");
00052 for(int i=0; timeformat[i]!=NULL ; i++ )
00053 fprintf(stderr,"\t%s\n",timeformat[i]);
00054 return(-1);
00055 }
00056
00057
00058 char *tstr=NULL,*nline=NULL;
00059
00060 dprintf("TIME STAMP: ");
00061 tstr=asctime(localtime(&ts));
00062 nline=strrchr(tstr,'\n');
00063 if(nline!=NULL) *nline=0x00;
00064 dprintf("%s (%s)\t",tstr,tzname[daylight]);
00065
00066 tstr=asctime(gmtime(&ts));
00067 nline=strrchr(tstr,'\n');
00068 if(nline!=NULL) *nline=0x00;
00069 dprintf("%s (GMT)\n",tstr);
00070 return ts;
00071 }
00072
00073
00074
00075
00076
00077 static void
00078 timeStringConv1(const char *a, char *b) {
00079 memcpy(b+0,a+0,4);
00080 b[4]='-';
00081 memcpy(b+5,a+4,2);
00082 b[7]='-';
00083 memcpy(b+8,a+6,2);
00084 b[10]=' ';
00085 memcpy(b+11,a+8,2);
00086 b[13]=':';
00087 memcpy(b+14,a+10,2);
00088 b[16]=':';
00089 memcpy(b+17,a+12,2);
00090 b[19]=0;
00091
00092 }
00093
00094
00095 char *
00096 fmtSqlTime(const char* sqltime) {
00097 static char stringTime[1024];
00098 timeStringConv1(sqltime,stringTime);
00099 return stringTime;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108 static inline char*
00109 fmt(const char *s, const int len) {
00110 static char fmtstr[SpinDbMaxDbPathLen];
00111 sprintf(fmtstr,"%s %%%d[A-z0-9 \\t]\n",s,len-1);
00112 return fmtstr;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121