Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/teraterm/teraterm/filesys_log.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8908 by zmatsuo, Tue Aug 18 15:31:51 2020 UTC revision 8909 by zmatsuo, Tue Aug 18 15:31:59 2020 UTC
# Line 781  static BOOL LogStart(const wchar_t *fnam Line 781  static BOOL LogStart(const wchar_t *fnam
781   */   */
782  void FLogOutputAllBuffer(void)  void FLogOutputAllBuffer(void)
783  {  {
784          DWORD ofs, written_size;          DWORD ofs;
785          int size;          int size;
786          wchar_t buf[512];          wchar_t buf[512];
787          for (ofs = 0 ;  ; ofs++ ) {          for (ofs = 0 ;  ; ofs++ ) {
# Line 920  static void LogRotate(void) Line 920  static void LogRotate(void)
920          logfile_unlock();          logfile_unlock();
921  }  }
922    
923    static char *TimeStampStr()
924    {
925            char *strtime = NULL;
926            switch (ts.LogTimestampType) {
927            case TIMESTAMP_LOCAL:
928            default:
929                    strtime = mctimelocal(ts.LogTimestampFormat, FALSE);
930                    break;
931            case TIMESTAMP_UTC:
932                    strtime = mctimelocal(ts.LogTimestampFormat, TRUE);
933                    break;
934            case TIMESTAMP_ELAPSED_LOGSTART:
935                    strtime = strelapsed(LogVar->StartTime);
936                    break;
937            case TIMESTAMP_ELAPSED_CONNECTED:
938                    strtime = strelapsed(cv.ConnectedTime);
939                    break;
940            }
941    
942            char tmp[128];
943            tmp[0] = 0;
944            strncat_s(tmp, sizeof(tmp), "[", _TRUNCATE);
945            strncat_s(tmp, sizeof(tmp), strtime, _TRUNCATE);
946            strncat_s(tmp, sizeof(tmp), "] ", _TRUNCATE);
947    
948            return strdup(tmp);
949    //      return ToWcharA(tmp);
950    }
951    
952  /**  /**
953   * バッファ内のログをファイルへ書き込む   * バッファ内のログをファイルへ書き込む
954   */   */
# Line 928  static void LogToFile(void) Line 957  static void LogToFile(void)
957          PCHAR Buf;          PCHAR Buf;
958          int Start, Count;          int Start, Count;
959          BYTE b;          BYTE b;
         PCHAR WriteBuf;  
         DWORD WriteBufMax, WriteBufLen;  
         CHAR tmp[128];  
         DWORD wrote;  
960          PFileVar fv = LogVar;          PFileVar fv = LogVar;
961    
962          if (FileLog)          if (FileLog)
# Line 955  static void LogToFile(void) Line 980  static void LogToFile(void)
980          // ロックを取る(2004.8.6 yutaka)          // ロックを取る(2004.8.6 yutaka)
981          logfile_lock();          logfile_lock();
982    
983          if (ts.DeferredLogWriteMode) {          // 書き込みデータを作成する
984                  WriteBufMax = 8192;          DWORD WriteBufMax = 8192;
985                  WriteBufLen = 0;          DWORD WriteBufLen = 0;
986                  WriteBuf = (PCHAR)malloc(WriteBufMax);          PCHAR WriteBuf = (PCHAR)malloc(WriteBufMax);
987                  while (Get1(Buf,&Start,&Count,&b)) {          while (Get1(Buf,&Start,&Count,&b)) {
988                          if (!FLogIsPause() && (! cv.ProtoFlag))                  if (FLogIsPause() || (cv.ProtoFlag)) {
989                          {                          continue;
                                 tmp[0] = 0;  
                                 if ( ts.LogTimestamp && fv->eLineEnd ) {  
                                         char *strtime = NULL;  
   
                                         switch (ts.LogTimestampType) {  
                                         case TIMESTAMP_LOCAL:  
                                                 strtime = mctimelocal(ts.LogTimestampFormat, FALSE);  
                                                 break;  
                                         case TIMESTAMP_UTC:  
                                                 strtime = mctimelocal(ts.LogTimestampFormat, TRUE);  
                                                 break;  
                                         case TIMESTAMP_ELAPSED_LOGSTART:  
                                                 strtime = strelapsed(LogVar->StartTime);  
                                                 break;  
                                         case TIMESTAMP_ELAPSED_CONNECTED:  
                                                 strtime = strelapsed(cv.ConnectedTime);  
                                                 break;  
                                         }  
   
                                         /* 2007.05.24 Gentaro */  
                                         if(fv->eLineEnd == Line_FileHead ){  
                                                 strncat_s(tmp, sizeof(tmp), "\r\n", _TRUNCATE);  
                                         }  
                                         strncat_s(tmp, sizeof(tmp), "[", _TRUNCATE);  
                                         strncat_s(tmp, sizeof(tmp), strtime, _TRUNCATE);  
                                         strncat_s(tmp, sizeof(tmp), "] ", _TRUNCATE);  
                                 }  
   
                                 /* 2007.05.24 Gentaro */  
                                 if( b == 0x0a ){  
                                         fv->eLineEnd = Line_LineHead; /* set endmark*/  
                                 }  
                                 else {  
                                         fv->eLineEnd = Line_Other; /* clear endmark*/  
                                 }  
   
                                 if (WriteBufLen >= (WriteBufMax*4/5)) {  
                                         WriteBufMax *= 2;  
                                         WriteBuf = (PCHAR)realloc(WriteBuf, WriteBufMax);  
                                 }  
                                 memcpy(&WriteBuf[WriteBufLen], tmp, strlen(tmp));  
                                 WriteBufLen += strlen(tmp);  
                                 WriteBuf[WriteBufLen++] = b;  
   
                                 (LogVar->ByteCount)++;  
                         }  
990                  }                  }
991    
992                  PostThreadMessage(LogVar->LogThreadId, WM_DPC_LOGTHREAD_SEND, (WPARAM)WriteBuf, WriteBufLen);                  if (WriteBufLen >= (WriteBufMax*4/5)) {
993                            WriteBufMax *= 2;
994                            WriteBuf = (PCHAR)realloc(WriteBuf, WriteBufMax);
995                    }
996    
997          } else {                  // add time stamp string
998                    if ( ts.LogTimestamp && fv->eLineEnd ) {
999                            char *strtime = TimeStampStr();
1000                            size_t len = strlen(strtime);
1001                            memcpy(&WriteBuf[WriteBufLen], strtime, len);
1002                            free(strtime);
1003                            WriteBufLen += len;
1004                    }
1005    
1006                  while (Get1(Buf,&Start,&Count,&b))                  /* 2007.05.24 Gentaro */
1007                  {                  if( b == 0x0a ){
1008                          if (!FLogIsPause() && (! cv.ProtoFlag))                          fv->eLineEnd = Line_LineHead; /* set endmark*/
                         {  
                                 if ( ts.LogTimestamp && fv->eLineEnd ) {  
                                         char *strtime = NULL;  
   
                                         switch (ts.LogTimestampType) {  
                                         case TIMESTAMP_LOCAL:  
                                                 strtime = mctimelocal(ts.LogTimestampFormat, FALSE);  
                                                 break;  
                                         case TIMESTAMP_UTC:  
                                                 strtime = mctimelocal(ts.LogTimestampFormat, TRUE);  
                                                 break;  
                                         case TIMESTAMP_ELAPSED_LOGSTART:  
                                                 strtime = strelapsed(LogVar->StartTime);  
                                                 break;  
                                         case TIMESTAMP_ELAPSED_CONNECTED:  
                                                 strtime = strelapsed(cv.ConnectedTime);  
                                                 break;  
                                         }  
                                         WriteFile(LogVar->FileHandle, "[", 1, &wrote, NULL);  
                                         WriteFile(LogVar->FileHandle, strtime, strlen(strtime), &wrote, NULL);  
                                         WriteFile(LogVar->FileHandle, "] ", 2, &wrote, NULL);  
                                 }  
   
                                 /* 2007.05.24 Gentaro */  
                                 if( b == 0x0a ){  
                                         fv->eLineEnd = Line_LineHead; /* set endmark*/  
                                 }  
                                 else {  
                                         fv->eLineEnd = Line_Other; /* clear endmark*/  
                                 }  
   
                                 WriteFile(LogVar->FileHandle, (PCHAR)&b, 1, &wrote, NULL);  
                                 (LogVar->ByteCount)++;  
                         }  
1009                  }                  }
1010                    else {
1011                            fv->eLineEnd = Line_Other; /* clear endmark*/
1012                    }
1013    
1014                    WriteBuf[WriteBufLen++] = b;
1015    
1016                    (LogVar->ByteCount)++;
1017            }
1018    
1019            // 書き込み
1020            if (WriteBufLen > 0) {
1021                    if (ts.DeferredLogWriteMode) {
1022                            PostThreadMessage(LogVar->LogThreadId, WM_DPC_LOGTHREAD_SEND, (WPARAM)WriteBuf, WriteBufLen);
1023                    }
1024                    else {
1025                            DWORD wrote;
1026                            WriteFile(LogVar->FileHandle, WriteBuf, WriteBufLen, &wrote, NULL);
1027                            free(WriteBuf);
1028                    }
1029          }          }
1030    
1031          logfile_unlock();          logfile_unlock();

Legend:
Removed from v.8908  
changed lines
  Added in v.8909

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26