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.11 by maya, Mon May 14 14:07:14 2007 UTC revision 1.16 by maya, Wed Aug 8 15:56:35 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 165  static PProtoDlg PtDlg = NULL; Line 177  static PProtoDlg PtDlg = NULL;
177  BOOL OpenFTDlg(PFileVar fv)  BOOL OpenFTDlg(PFileVar fv)
178  {  {
179    PFileTransDlg FTDlg;    PFileTransDlg FTDlg;
180  #ifdef I18N  #ifndef NO_I18N
181    HWND HFTDlg;    HWND HFTDlg;
182  #endif  #endif
183    
# Line 173  BOOL OpenFTDlg(PFileVar fv) Line 185  BOOL OpenFTDlg(PFileVar fv)
185        
186    if (FTDlg!=NULL)    if (FTDlg!=NULL)
187    {    {
188  #ifdef I18N  #ifndef NO_I18N
189      FTDlg->Create(fv, &cv, &ts);      FTDlg->Create(fv, &cv, &ts);
190  #else  #else
191      FTDlg->Create(fv, &cv);      FTDlg->Create(fv, &cv);
# Line 188  BOOL OpenFTDlg(PFileVar fv) Line 200  BOOL OpenFTDlg(PFileVar fv)
200    else    else
201      SendDlg = FTDlg; /* File send */      SendDlg = FTDlg; /* File send */
202    
203  #ifdef I18N  #ifndef NO_I18N
204    HFTDlg=FTDlg->GetSafeHwnd();    HFTDlg=FTDlg->GetSafeHwnd();
205    
206    GetDlgItemText(HFTDlg, IDC_TRANS_FILENAME, ts.UIMsg, sizeof(ts.UIMsg));    GetDlgItemText(HFTDlg, IDC_TRANS_FILENAME, ts.UIMsg, sizeof(ts.UIMsg));
# Line 222  BOOL NewFileVar(PFileVar *fv) Line 234  BOOL NewFileVar(PFileVar *fv)
234      if ((*fv)!=NULL)      if ((*fv)!=NULL)
235      {      {
236        memset(*fv, 0, sizeof(TFileVar));        memset(*fv, 0, sizeof(TFileVar));
237        strcpy((*fv)->FullName,ts.FileDir);        strncpy_s((*fv)->FullName, sizeof((*fv)->FullName),ts.FileDir, _TRUNCATE);
238        AppendSlash((*fv)->FullName);        AppendSlash((*fv)->FullName,sizeof((*fv)->FullName));
239        (*fv)->DirLen = strlen((*fv)->FullName);        (*fv)->DirLen = strlen((*fv)->FullName);
240        (*fv)->FileOpen = FALSE;        (*fv)->FileOpen = FALSE;
241        (*fv)->OverWrite = ((ts.FTFlag & FT_RENAME) == 0);        (*fv)->OverWrite = ((ts.FTFlag & FT_RENAME) == 0);
# Line 252  void FreeFileVar(PFileVar *fv) Line 264  void FreeFileVar(PFileVar *fv)
264  }  }
265    
266  // &h をホスト名に置換 (2007.5.14)  // &h をホスト名に置換 (2007.5.14)
267  void ConvertLogname(char *c)  void ConvertLogname(char *c, int destlen)
268  {  {
269    char buf[MAXPATHLEN], buf2[MAXPATHLEN], *p = c;    char buf[MAXPATHLEN], buf2[MAXPATHLEN], *p = c;
270    
# Line 264  void ConvertLogname(char *c) Line 276  void ConvertLogname(char *c)
276          case 'h':          case 'h':
277            if (cv.Open) {            if (cv.Open) {
278              if (cv.PortType == IdTCPIP) {              if (cv.PortType == IdTCPIP) {
279                _snprintf(buf2, sizeof(buf2), "%s%s", buf, ts.HostName);                strncat_s(buf,sizeof(buf),ts.HostName,_TRUNCATE);
               strncpy(buf, buf2, sizeof(buf)-strlen(buf)-1);  
280              }              }
281              else if (cv.PortType == IdSerial) {              else if (cv.PortType == IdSerial) {
282                _snprintf(buf2, sizeof(buf2), "%sCOM%d", buf, ts.ComPort);                strncpy_s(buf2,sizeof(buf2),buf,_TRUNCATE);
283                strncpy(buf, buf2, sizeof(buf)-strlen(buf)-1);                _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%sCOM%d", buf2, ts.ComPort);
284              }              }
285            }            }
286            break;            break;
287          default:          default:
288            if (strlen(buf) < sizeof(buf)-3) {            strncpy_s(buf2,sizeof(buf2),p,2);
289              strncat(buf, p, 2);            strncat_s(buf,sizeof(buf),buf2,_TRUNCATE);
           }  
290        }        }
291        p++;        p++;
292      }      }
293      else {      else {
294            if (strlen(buf) < sizeof(buf)-2) {            strncpy_s(buf2,sizeof(buf2),p,1);
295              strncat(buf, p, 1);            strncat_s(buf,sizeof(buf),buf2,_TRUNCATE);
           }  
296      }      }
297      p++;      p++;
298    }    }
299    strcpy(c, buf);    strncpy_s(c, destlen, buf, _TRUNCATE);
300  }  }
301    
302  extern "C" {  extern "C" {
303  void LogStart()  void LogStart()
304  {  {
305          LONG Option;          LONG Option;
306            char *logdir;
307    
308          if ((FileLog) || (BinLog)) return;          if ((FileLog) || (BinLog)) return;
309    
# Line 305  void LogStart() Line 315  void LogStart()
315          }          }
316          LogVar->OpId = OpLog;          LogVar->OpId = OpLog;
317    
318            if (strlen(ts.LogDefaultPath) > 0) {
319                    logdir = ts.LogDefaultPath;
320            }
321            else if (strlen(ts.FileDir) > 0) {
322                    logdir = ts.FileDir;
323            }
324            else {
325                    logdir = ts.HomeDir;
326            }
327    
328          if (strlen(&(LogVar->FullName[LogVar->DirLen]))==0)          if (strlen(&(LogVar->FullName[LogVar->DirLen]))==0)
329          {          {
330                  // LOWORD                  // LOWORD
# Line 319  void LogStart() Line 339  void LogStart()
339                                                    (0x2000 * ts.LogTimestamp));                                                    (0x2000 * ts.LogTimestamp));
340    
341                  // ログのデフォルトファイル名を設定 (2006.8.28 maya)                  // ログのデフォルトファイル名を設定 (2006.8.28 maya)
342                  strncat(LogVar->FullName, ts.LogDefaultName, sizeof(LogVar->FullName));                  strncat_s(LogVar->FullName, sizeof(LogVar->FullName), ts.LogDefaultName, _TRUNCATE);
343                  ParseStrftimeFileName(LogVar->FullName);  
344                    ParseStrftimeFileName(LogVar->FullName, sizeof(LogVar->FullName));
345    
346                  // &h をホスト名に置換 (2007.5.14)                  // &h をホスト名に置換 (2007.5.14)
347                  ConvertLogname(LogVar->FullName);                  ConvertLogname(LogVar->FullName, sizeof(LogVar->FullName));
348    
349                  if (! (*GetTransFname)(LogVar, ts.FileDir, GTF_LOG, &Option))                  if (! (*GetTransFname)(LogVar, logdir, GTF_LOG, &Option))
350                  {                  {
351                          FreeFileVar(&LogVar);                          FreeFileVar(&LogVar);
352                          FreeTTFILE();                          FreeTTFILE();
# Line 351  void LogStart() Line 372  void LogStart()
372    
373          }          }
374          else {          else {
375                    // LogVar->DirLen = 0 だとここに来る
376                    // フルパス・相対パスともに LogVar->FullName に入れておく必要がある
377                    char FileName[MAX_PATH];
378    
379                    // フルパス化
380                    strncpy_s(FileName, sizeof(FileName), LogVar->FullName, _TRUNCATE);
381                    ConvFName(logdir,FileName,sizeof(FileName),"",LogVar->FullName,sizeof(LogVar->FullName));
382    
383                    ParseStrftimeFileName(LogVar->FullName, sizeof(LogVar->FullName));
384    
385                  // &h をホスト名に置換 (2007.5.14)                  // &h をホスト名に置換 (2007.5.14)
386                  ConvertLogname(LogVar->FullName);                  ConvertLogname(LogVar->FullName, sizeof(LogVar->FullName));
387                  (*SetFileVar)(LogVar);                  (*SetFileVar)(LogVar);
388          }          }
389    
# Line 379  void LogStart() Line 410  void LogStart()
410          cv.LCount = 0;          cv.LCount = 0;
411    
412          HelpId = HlpFileLog;          HelpId = HlpFileLog;
413            /* 2007.05.24 Gentaro */
414            eLineEnd = Line_LineHead;
415    
416          if (ts.Append > 0)          if (ts.Append > 0)
417          {          {
418                  LogVar->FileHandle = _lopen(LogVar->FullName,OF_WRITE);                  LogVar->FileHandle = _lopen(LogVar->FullName,OF_WRITE);
419                  if (LogVar->FileHandle>0)                  if (LogVar->FileHandle>0){
420                          _llseek(LogVar->FileHandle,0,2);                          _llseek(LogVar->FileHandle,0,2);
421                            /* 2007.05.24 Gentaro
422                                    If log file already exists,
423                                    a newline is inserted before the first timestamp.
424                            */
425                            eLineEnd = Line_FileHead;
426                    }
427                  else                  else
428                          LogVar->FileHandle = _lcreat(LogVar->FullName,0);                          LogVar->FileHandle = _lcreat(LogVar->FullName,0);
429          }          }
# Line 490  void CommentLogToFile(char *buf, int siz Line 530  void CommentLogToFile(char *buf, int siz
530          DWORD wrote;          DWORD wrote;
531    
532          if (LogVar == NULL || !LogVar->FileOpen) {          if (LogVar == NULL || !LogVar->FileOpen) {
533  #ifdef I18N  #ifndef NO_I18N
534                  char uimsg[MAX_UIMSG];                  char uimsg[MAX_UIMSG];
535                  strcpy(uimsg, "ERROR");                  strncpy_s(uimsg, sizeof(uimsg), "ERROR", _TRUNCATE);
536                  get_lang_msg("MSG_ERROR", uimsg, ts.UILanguageFile);                  get_lang_msg("MSG_ERROR", uimsg, ts.UILanguageFile);
537                  strcpy(ts.UIMsg, "It is not opened by the log file yet.");                  strncpy_s(ts.UIMsg, sizeof(ts.UIMsg), "It is not opened by the log file yet.", _TRUNCATE);
538                  get_lang_msg("MSG_COMMENT_LOG_OPEN_ERROR", ts.UIMsg, ts.UILanguageFile);                  get_lang_msg("MSG_COMMENT_LOG_OPEN_ERROR", ts.UIMsg, ts.UILanguageFile);
539                  ::MessageBox(NULL, ts.UIMsg, uimsg, MB_OK|MB_ICONEXCLAMATION);                  ::MessageBox(NULL, ts.UIMsg, uimsg, MB_OK|MB_ICONEXCLAMATION);
540  #else  #else
# Line 506  void CommentLogToFile(char *buf, int siz Line 546  void CommentLogToFile(char *buf, int siz
546          logfile_lock();          logfile_lock();
547          WriteFile((HANDLE)LogVar->FileHandle, buf, size, &wrote, NULL);          WriteFile((HANDLE)LogVar->FileHandle, buf, size, &wrote, NULL);
548          WriteFile((HANDLE)LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // 改行          WriteFile((HANDLE)LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // 改行
549            /* Set Line End Flag
550                    2007.05.24 Gentaro
551            */
552            eLineEnd = Line_LineHead;
553          logfile_unlock();          logfile_unlock();
554  }  }
555    
# Line 543  void LogToFile() Line 587  void LogToFile()
587                  {                  {
588                          // 時刻を書き出す(2006.7.23 maya)                          // 時刻を書き出す(2006.7.23 maya)
589                          // 日付フォーマットを日本ではなく世界標準に変更した (2006.7.23 yutaka)                          // 日付フォーマットを日本ではなく世界標準に変更した (2006.7.23 yutaka)
590                          if (ts.LogTimestamp &&                          /* 2007.05.24 Gentaro */
591                                  (Start == 1 || Buf[Start-2] == 0x0a)) {                          if ( ts.LogTimestamp && eLineEnd ) {
592  #if 0  #if 0
593                                  SYSTEMTIME      LocalTime;                                  SYSTEMTIME      LocalTime;
594                                  GetLocalTime(&LocalTime);                                  GetLocalTime(&LocalTime);
# Line 559  void LogToFile() Line 603  void LogToFile()
603                                          time_t tick = time(NULL);                                          time_t tick = time(NULL);
604                                          char *strtime = ctime(&tick);                                          char *strtime = ctime(&tick);
605  #endif  #endif
606                                    /* 2007.05.24 Gentaro */
607                                  // write to file                                  if( eLineEnd == Line_FileHead ){
608                                  if (Start == 1 && ts.Append) {                                          _lwrite(LogVar->FileHandle,"\r\n",2);
                                         _lwrite(LogVar->FileHandle,"\r\n",strlen("\r\n"));  
609                                  }                                  }
610                                  _lwrite(LogVar->FileHandle,"[",1);                                  _lwrite(LogVar->FileHandle,"[",1);
611                                  // 変換した文字列の終端に \n が含まれているので取り除く。                                  // 変換した文字列の終端に \n が含まれているので取り除く。
612                                  _lwrite(LogVar->FileHandle, strtime, strlen(strtime) - 1);                                  _lwrite(LogVar->FileHandle, strtime, strlen(strtime) - 1);
613                                  _lwrite(LogVar->FileHandle,"] ",2);                                  _lwrite(LogVar->FileHandle,"] ",2);
614                          }                          }
615                            
616                            /* 2007.05.24 Gentaro */
617                            if( b == 0x0a ){
618                                    eLineEnd = Line_LineHead; /* set endmark*/
619                            }
620                            else {
621                                    eLineEnd = Line_Other; /* clear endmark*/
622                            }
623    
624                          _lwrite(LogVar->FileHandle,(PCHAR)&b,1);                          _lwrite(LogVar->FileHandle,(PCHAR)&b,1);
625                          (LogVar->ByteCount)++;                          (LogVar->ByteCount)++;
# Line 845  BOOL OpenProtoDlg(PFileVar fv, int IdPro Line 896  BOOL OpenProtoDlg(PFileVar fv, int IdPro
896  {  {
897    int vsize;    int vsize;
898    PProtoDlg pd;    PProtoDlg pd;
899  #ifdef I18N  #ifndef NO_I18N
900    HWND Hpd;    HWND Hpd;
901  #endif  #endif
902    
# Line 899  BOOL OpenProtoDlg(PFileVar fv, int IdPro Line 950  BOOL OpenProtoDlg(PFileVar fv, int IdPro
950      ProtoVar = NULL;      ProtoVar = NULL;
951      return FALSE;      return FALSE;
952    }    }
953  #ifdef I18N  #ifndef NO_I18N
954    pd->Create(fv,&ts);    pd->Create(fv,&ts);
955  #else  #else
956    pd->Create(fv);    pd->Create(fv);
957  #endif  #endif
958    
959  #ifdef I18N  #ifndef NO_I18N
960    Hpd=pd->GetSafeHwnd();    Hpd=pd->GetSafeHwnd();
961    
962    GetDlgItemText(Hpd, IDC_PROT_FILENAME, ts.UIMsg, sizeof(ts.UIMsg));    GetDlgItemText(Hpd, IDC_PROT_FILENAME, ts.UIMsg, sizeof(ts.UIMsg));
# Line 1244  void QVStart(int mode) Line 1295  void QVStart(int mode)
1295    
1296  /*  /*
1297   * $Log$   * $Log$
1298     * Revision 1.16  2007/08/08 15:56:35  maya
1299     * 安全な関数を使用するように変更した。
1300     *
1301     * Revision 1.15  2007/06/06 14:02:53  maya
1302     * プリプロセッサにより構造体が変わってしまうので、INET6 と I18N の #define を逆転させた。
1303     *
1304     * Revision 1.14  2007/05/31 14:39:05  maya
1305     * 接続時に自動的にログ採取を開始できるようにした。
1306     *
1307     * Revision 1.13  2007/05/30 16:04:27  maya
1308     * 標準のログ保存先を指定できるようにした。
1309     *
1310     * Revision 1.12  2007/05/25 09:56:05  yutakapon
1311     * タイムスタンプ付きログで1KBごとに不要な改行が入るバグを修正。
1312     *
1313   * Revision 1.11  2007/05/14 14:07:14  maya   * Revision 1.11  2007/05/14 14:07:14  maya
1314   * バッファをクリアしていないので落ちる問題を修正した。   * バッファをクリアしていないので落ちる問題を修正した。
1315   *   *

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.16

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