|
@@ -117,35 +117,61 @@ int message_file::put_line(uint64_t time,char*buf,int buflen)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+int line_type(const char*s)
|
|
|
+{
|
|
|
+ if(s[0]==0 || s[0]=='\n')
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ if(strncmp("2019-",s,5)==0)
|
|
|
+ return 1;
|
|
|
+
|
|
|
+ return 2;
|
|
|
+}
|
|
|
+
|
|
|
int message_file::get_line(uint64_t*time,char*buf,int buflen)
|
|
|
{
|
|
|
- const char*p;
|
|
|
- while(m_last_line[0]!='[')
|
|
|
- {
|
|
|
+ return get_line(time,buf,buflen,0);
|
|
|
+}
|
|
|
+
|
|
|
+int message_file::get_line(uint64_t*time,char*buf,int buflen,char*m)
|
|
|
+{
|
|
|
+ int type=0;
|
|
|
+
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
if(fgets(m_last_line,sizeof(m_last_line),m_file)==nullptr)
|
|
|
return 0;
|
|
|
- }
|
|
|
|
|
|
- {
|
|
|
- struct tm tm;
|
|
|
- memset(&tm, 0, sizeof(struct tm));
|
|
|
- const char*ms=strptime(&m_last_line[1], "%Y-%m-%d %H:%M:%S", &tm);
|
|
|
+ type=line_type(m_last_line);
|
|
|
|
|
|
- *time=1000*mktime(&tm)+atoi(ms+1);
|
|
|
+ if(type==0)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if(type==1)
|
|
|
+ {
|
|
|
+ struct tm tm;
|
|
|
+ memset(&tm, 0, sizeof(struct tm));
|
|
|
+ const char*ms=strptime(&m_last_line[0], "%Y-%m-%d %H:%M:%S", &tm);
|
|
|
+ *time=1000LL*mktime(&tm)+atoi(ms+1);
|
|
|
+
|
|
|
+ if(m) strcpy(m,m_last_line);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
char*o=buf;
|
|
|
- for(;;)
|
|
|
+ while(1)
|
|
|
{
|
|
|
- if(nullptr==(p=fgets(m_last_line,sizeof(m_last_line),m_file)))
|
|
|
- return 0;
|
|
|
-
|
|
|
- if(*p=='[')
|
|
|
+ if(line_type(m_last_line)<=1)
|
|
|
break;
|
|
|
|
|
|
- o+=convert(p,o);
|
|
|
- }
|
|
|
+ o+=convert(m_last_line,o);
|
|
|
|
|
|
+ if(fgets(m_last_line,sizeof(m_last_line),m_file)==nullptr)
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
return o-buf;
|
|
|
}
|
|
|
|