Develop and Download Open Source Software

Browse CVS Repository

Diff of /ttssh2/teraterm/source/teraterm/filesys.cpp

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

revision 1.9 by maya, Sun Jan 21 16:18:35 2007 UTC revision 1.12 by yutakapon, Fri May 25 09:56:05 2007 UTC
# Line 64  PProtoCancel ProtoCancel; Line 64  PProtoCancel ProtoCancel;
64  #define IdProtoTimeOutProc 9  #define IdProtoTimeOutProc 9
65  #define IdProtoCancel    10  #define IdProtoCancel    10
66    
67    /*
68       Line Head flag for timestamping
69       2007.05.24 Gentaro
70    */
71    enum enumLineEnd {
72            Line_Other = 0,
73            Line_LineHead = 1,
74            Line_FileHead = 2,
75    };
76    
77    enum enumLineEnd eLineEnd = Line_LineHead;
78    
79  BOOL LoadTTFILE()  BOOL LoadTTFILE()
80  {  {
81    BOOL Err;    BOOL Err;
# Line 251  void FreeFileVar(PFileVar *fv) Line 263  void FreeFileVar(PFileVar *fv)
263    }    }
264  }  }
265    
266    // &h をホスト名に置換 (2007.5.14)
267    void ConvertLogname(char *c)
268    {
269      char buf[MAXPATHLEN], buf2[MAXPATHLEN], *p = c;
270    
271      memset(buf, 0, sizeof(buf));
272    
273      while(*p != '\0') {
274        if (*p == '&' && *(p+1) != '\0') {
275          switch (*(p+1)) {
276            case 'h':
277              if (cv.Open) {
278                if (cv.PortType == IdTCPIP) {
279                  _snprintf(buf2, sizeof(buf2), "%s%s", buf, ts.HostName);
280                  strncpy(buf, buf2, sizeof(buf)-strlen(buf)-1);
281                }
282                else if (cv.PortType == IdSerial) {
283                  _snprintf(buf2, sizeof(buf2), "%sCOM%d", buf, ts.ComPort);
284                  strncpy(buf, buf2, sizeof(buf)-strlen(buf)-1);
285                }
286              }
287              break;
288            default:
289              if (strlen(buf) < sizeof(buf)-3) {
290                strncat(buf, p, 2);
291              }
292          }
293          p++;
294        }
295        else {
296              if (strlen(buf) < sizeof(buf)-2) {
297                strncat(buf, p, 1);
298              }
299        }
300        p++;
301      }
302      strcpy(c, buf);
303    }
304    
305  extern "C" {  extern "C" {
306  void LogStart()  void LogStart()
307  {  {
# Line 283  void LogStart() Line 334  void LogStart()
334                  strncat(LogVar->FullName, ts.LogDefaultName, sizeof(LogVar->FullName));                  strncat(LogVar->FullName, ts.LogDefaultName, sizeof(LogVar->FullName));
335                  ParseStrftimeFileName(LogVar->FullName);                  ParseStrftimeFileName(LogVar->FullName);
336    
337                    // &h をホスト名に置換 (2007.5.14)
338                    ConvertLogname(LogVar->FullName);
339    
340                  if (! (*GetTransFname)(LogVar, ts.FileDir, GTF_LOG, &Option))                  if (! (*GetTransFname)(LogVar, ts.FileDir, GTF_LOG, &Option))
341                  {                  {
342                          FreeFileVar(&LogVar);                          FreeFileVar(&LogVar);
# Line 308  void LogStart() Line 362  void LogStart()
362                  ts.Append &= 0x1; // 1bitにマスクする                  ts.Append &= 0x1; // 1bitにマスクする
363    
364          }          }
365          else          else {
366                    // &h をホスト名に置換 (2007.5.14)
367                    ConvertLogname(LogVar->FullName);
368                  (*SetFileVar)(LogVar);                  (*SetFileVar)(LogVar);
369            }
370    
371          if (ts.TransBin > 0)          if (ts.TransBin > 0)
372          {          {
# Line 334  void LogStart() Line 391  void LogStart()
391          cv.LCount = 0;          cv.LCount = 0;
392    
393          HelpId = HlpFileLog;          HelpId = HlpFileLog;
394            /* 2007.05.24 Gentaro */
395            eLineEnd = Line_LineHead;
396    
397          if (ts.Append > 0)          if (ts.Append > 0)
398          {          {
399                  LogVar->FileHandle = _lopen(LogVar->FullName,OF_WRITE);                  LogVar->FileHandle = _lopen(LogVar->FullName,OF_WRITE);
400                  if (LogVar->FileHandle>0)                  if (LogVar->FileHandle>0){
401                          _llseek(LogVar->FileHandle,0,2);                          _llseek(LogVar->FileHandle,0,2);
402                            /* 2007.05.24 Gentaro
403                                    If log file already exists,
404                                    a newline is inserted before the first timestamp.
405                            */
406                            eLineEnd = Line_FileHead;
407                    }
408                  else                  else
409                          LogVar->FileHandle = _lcreat(LogVar->FullName,0);                          LogVar->FileHandle = _lcreat(LogVar->FullName,0);
410          }          }
# Line 461  void CommentLogToFile(char *buf, int siz Line 527  void CommentLogToFile(char *buf, int siz
527          logfile_lock();          logfile_lock();
528          WriteFile((HANDLE)LogVar->FileHandle, buf, size, &wrote, NULL);          WriteFile((HANDLE)LogVar->FileHandle, buf, size, &wrote, NULL);
529          WriteFile((HANDLE)LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // 改行          WriteFile((HANDLE)LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // 改行
530            /* Set Line End Flag
531                    2007.05.24 Gentaro
532            */
533            eLineEnd = Line_LineHead;
534          logfile_unlock();          logfile_unlock();
535  }  }
536    
# Line 498  void LogToFile() Line 568  void LogToFile()
568                  {                  {
569                          // 時刻を書き出す(2006.7.23 maya)                          // 時刻を書き出す(2006.7.23 maya)
570                          // 日付フォーマットを日本ではなく世界標準に変更した (2006.7.23 yutaka)                          // 日付フォーマットを日本ではなく世界標準に変更した (2006.7.23 yutaka)
571                          if (ts.LogTimestamp &&                          /* 2007.05.24 Gentaro */
572                                  (Start == 1 || Buf[Start-2] == 0x0a)) {                          if ( ts.LogTimestamp && eLineEnd ) {
573  #if 0  #if 0
574                                  SYSTEMTIME      LocalTime;                                  SYSTEMTIME      LocalTime;
575                                  GetLocalTime(&LocalTime);                                  GetLocalTime(&LocalTime);
# Line 514  void LogToFile() Line 584  void LogToFile()
584                                          time_t tick = time(NULL);                                          time_t tick = time(NULL);
585                                          char *strtime = ctime(&tick);                                          char *strtime = ctime(&tick);
586  #endif  #endif
587                                    /* 2007.05.24 Gentaro */
588                                  // write to file                                  if( eLineEnd == Line_FileHead ){
589                                  if (Start == 1 && ts.Append) {                                          _lwrite(LogVar->FileHandle,"\r\n",2);
                                         _lwrite(LogVar->FileHandle,"\r\n",strlen("\r\n"));  
590                                  }                                  }
591                                  _lwrite(LogVar->FileHandle,"[",1);                                  _lwrite(LogVar->FileHandle,"[",1);
592                                  // 変換した文字列の終端に \n が含まれているので取り除く。                                  // 変換した文字列の終端に \n が含まれているので取り除く。
593                                  _lwrite(LogVar->FileHandle, strtime, strlen(strtime) - 1);                                  _lwrite(LogVar->FileHandle, strtime, strlen(strtime) - 1);
594                                  _lwrite(LogVar->FileHandle,"] ",2);                                  _lwrite(LogVar->FileHandle,"] ",2);
595                          }                          }
596                            
597                            /* 2007.05.24 Gentaro */
598                            if( b == 0x0a ){
599                                    eLineEnd = Line_LineHead; /* set endmark*/
600                            }
601                            else {
602                                    eLineEnd = Line_Other; /* clear endmark*/
603                            }
604    
605                          _lwrite(LogVar->FileHandle,(PCHAR)&b,1);                          _lwrite(LogVar->FileHandle,(PCHAR)&b,1);
606                          (LogVar->ByteCount)++;                          (LogVar->ByteCount)++;
# Line 1199  void QVStart(int mode) Line 1276  void QVStart(int mode)
1276    
1277  /*  /*
1278   * $Log$   * $Log$
1279     * Revision 1.12  2007/05/25 09:56:05  yutakapon
1280     * タイムスタンプ付きログで1KBごとに不要な改行が入るバグを修正。
1281     *
1282     * Revision 1.11  2007/05/14 14:07:14  maya
1283     * バッファをクリアしていないので落ちる問題を修正した。
1284     *
1285     * Revision 1.10  2007/05/14 13:29:58  maya
1286     * ログファイル名中の &h を、接続中のホスト名に変換する機能を追加した。
1287     *
1288   * Revision 1.9  2007/01/21 16:18:35  maya   * Revision 1.9  2007/01/21 16:18:35  maya
1289   * 表示メッセージの読み込み対応   * 表示メッセージの読み込み対応
1290   *   *

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.12

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