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.8 by maya, Thu Jan 4 15:11:44 2007 UTC revision 1.13 by maya, Wed May 30 16:04:27 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  {  {
308          LONG Option;          LONG Option;
309            char *logdir;
310    
311          if ((FileLog) || (BinLog)) return;          if ((FileLog) || (BinLog)) return;
312    
# Line 266  void LogStart() Line 318  void LogStart()
318          }          }
319          LogVar->OpId = OpLog;          LogVar->OpId = OpLog;
320    
321            if (strlen(ts.LogDefaultPath) > 0) {
322                    logdir = ts.LogDefaultPath;
323            }
324            else if (strlen(ts.FileDir) > 0) {
325                    logdir = ts.FileDir;
326            }
327            else {
328                    logdir = ts.HomeDir;
329            }
330    
331          if (strlen(&(LogVar->FullName[LogVar->DirLen]))==0)          if (strlen(&(LogVar->FullName[LogVar->DirLen]))==0)
332          {          {
333                  // LOWORD                  // LOWORD
# Line 281  void LogStart() Line 343  void LogStart()
343    
344                  // ログのデフォルトファイル名を設定 (2006.8.28 maya)                  // ログのデフォルトファイル名を設定 (2006.8.28 maya)
345                  strncat(LogVar->FullName, ts.LogDefaultName, sizeof(LogVar->FullName));                  strncat(LogVar->FullName, ts.LogDefaultName, sizeof(LogVar->FullName));
346    
347                  ParseStrftimeFileName(LogVar->FullName);                  ParseStrftimeFileName(LogVar->FullName);
348    
349  #ifdef I18N                  // &h をホスト名に置換 (2007.5.14)
350                  if (! (*GetTransFname)(LogVar, ts.FileDir, GTF_LOG, &Option, &ts))                  ConvertLogname(LogVar->FullName);
351  #else  
352                  if (! (*GetTransFname)(LogVar, ts.FileDir, GTF_LOG, &Option))                  if (! (*GetTransFname)(LogVar, logdir, GTF_LOG, &Option))
 #endif  
353                  {                  {
354                          FreeFileVar(&LogVar);                          FreeFileVar(&LogVar);
355                          FreeTTFILE();                          FreeTTFILE();
# Line 312  void LogStart() Line 374  void LogStart()
374                  ts.Append &= 0x1; // 1bitにマスクする                  ts.Append &= 0x1; // 1bitにマスクする
375    
376          }          }
377          else          else {
378  #ifdef I18N                  // LogVar->DirLen = 0 だとここに来る
379                  (*SetFileVar)(FileVar, &ts);                  // フルパス・相対パスともに LogVar->FullName に入れておく必要がある
380  #else                  char FileName[MAX_PATH];
381    
382                    // フルパス化
383                    strncpy(FileName, LogVar->FullName, sizeof(FileName)-1);
384                    ConvFName(logdir,FileName,"",LogVar->FullName);
385    
386                    ParseStrftimeFileName(LogVar->FullName);
387    
388                    // &h をホスト名に置換 (2007.5.14)
389                    ConvertLogname(LogVar->FullName);
390                  (*SetFileVar)(LogVar);                  (*SetFileVar)(LogVar);
391  #endif          }
392    
393          if (ts.TransBin > 0)          if (ts.TransBin > 0)
394          {          {
# Line 342  void LogStart() Line 413  void LogStart()
413          cv.LCount = 0;          cv.LCount = 0;
414    
415          HelpId = HlpFileLog;          HelpId = HlpFileLog;
416            /* 2007.05.24 Gentaro */
417            eLineEnd = Line_LineHead;
418    
419          if (ts.Append > 0)          if (ts.Append > 0)
420          {          {
421                  LogVar->FileHandle = _lopen(LogVar->FullName,OF_WRITE);                  LogVar->FileHandle = _lopen(LogVar->FullName,OF_WRITE);
422                  if (LogVar->FileHandle>0)                  if (LogVar->FileHandle>0){
423                          _llseek(LogVar->FileHandle,0,2);                          _llseek(LogVar->FileHandle,0,2);
424                            /* 2007.05.24 Gentaro
425                                    If log file already exists,
426                                    a newline is inserted before the first timestamp.
427                            */
428                            eLineEnd = Line_FileHead;
429                    }
430                  else                  else
431                          LogVar->FileHandle = _lcreat(LogVar->FullName,0);                          LogVar->FileHandle = _lcreat(LogVar->FullName,0);
432          }          }
# Line 469  void CommentLogToFile(char *buf, int siz Line 549  void CommentLogToFile(char *buf, int siz
549          logfile_lock();          logfile_lock();
550          WriteFile((HANDLE)LogVar->FileHandle, buf, size, &wrote, NULL);          WriteFile((HANDLE)LogVar->FileHandle, buf, size, &wrote, NULL);
551          WriteFile((HANDLE)LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // 改行          WriteFile((HANDLE)LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // 改行
552            /* Set Line End Flag
553                    2007.05.24 Gentaro
554            */
555            eLineEnd = Line_LineHead;
556          logfile_unlock();          logfile_unlock();
557  }  }
558    
# Line 506  void LogToFile() Line 590  void LogToFile()
590                  {                  {
591                          // 時刻を書き出す(2006.7.23 maya)                          // 時刻を書き出す(2006.7.23 maya)
592                          // 日付フォーマットを日本ではなく世界標準に変更した (2006.7.23 yutaka)                          // 日付フォーマットを日本ではなく世界標準に変更した (2006.7.23 yutaka)
593                          if (ts.LogTimestamp &&                          /* 2007.05.24 Gentaro */
594                                  (Start == 1 || Buf[Start-2] == 0x0a)) {                          if ( ts.LogTimestamp && eLineEnd ) {
595  #if 0  #if 0
596                                  SYSTEMTIME      LocalTime;                                  SYSTEMTIME      LocalTime;
597                                  GetLocalTime(&LocalTime);                                  GetLocalTime(&LocalTime);
# Line 522  void LogToFile() Line 606  void LogToFile()
606                                          time_t tick = time(NULL);                                          time_t tick = time(NULL);
607                                          char *strtime = ctime(&tick);                                          char *strtime = ctime(&tick);
608  #endif  #endif
609                                    /* 2007.05.24 Gentaro */
610                                  // write to file                                  if( eLineEnd == Line_FileHead ){
611                                  if (Start == 1 && ts.Append) {                                          _lwrite(LogVar->FileHandle,"\r\n",2);
                                         _lwrite(LogVar->FileHandle,"\r\n",strlen("\r\n"));  
612                                  }                                  }
613                                  _lwrite(LogVar->FileHandle,"[",1);                                  _lwrite(LogVar->FileHandle,"[",1);
614                                  // 変換した文字列の終端に \n が含まれているので取り除く。                                  // 変換した文字列の終端に \n が含まれているので取り除く。
615                                  _lwrite(LogVar->FileHandle, strtime, strlen(strtime) - 1);                                  _lwrite(LogVar->FileHandle, strtime, strlen(strtime) - 1);
616                                  _lwrite(LogVar->FileHandle,"] ",2);                                  _lwrite(LogVar->FileHandle,"] ",2);
617                          }                          }
618                            
619                            /* 2007.05.24 Gentaro */
620                            if( b == 0x0a ){
621                                    eLineEnd = Line_LineHead; /* set endmark*/
622                            }
623                            else {
624                                    eLineEnd = Line_Other; /* clear endmark*/
625                            }
626    
627                          _lwrite(LogVar->FileHandle,(PCHAR)&b,1);                          _lwrite(LogVar->FileHandle,(PCHAR)&b,1);
628                          (LogVar->ByteCount)++;                          (LogVar->ByteCount)++;
# Line 634  void FileSendStart() Line 725  void FileSendStart()
725    {    {
726      Option = MAKELONG(ts.TransBin,0);      Option = MAKELONG(ts.TransBin,0);
727          SendVar->FullName[0] = 0;          SendVar->FullName[0] = 0;
 #ifdef I18N  
         if (! (*GetTransFname)(SendVar, ts.FileDir, GTF_SEND, &Option, &ts))  
 #else  
728      if (! (*GetTransFname)(SendVar, ts.FileDir, GTF_SEND, &Option))      if (! (*GetTransFname)(SendVar, ts.FileDir, GTF_SEND, &Option))
 #endif  
729          {          {
730        FileTransEnd(OpSendFile);        FileTransEnd(OpSendFile);
731        return;        return;
# Line 646  void FileSendStart() Line 733  void FileSendStart()
733      ts.TransBin = LOWORD(Option);      ts.TransBin = LOWORD(Option);
734    }    }
735    else    else
 #ifdef I18N  
     (*SetFileVar)(FileVar, &ts);  
 #else  
736      (*SetFileVar)(SendVar);      (*SetFileVar)(SendVar);
 #endif  
737    
738    SendVar->FileHandle = _lopen(SendVar->FullName,OF_READ);    SendVar->FileHandle = _lopen(SendVar->FullName,OF_READ);
739    SendVar->FileOpen = (SendVar->FileHandle>0);    SendVar->FileOpen = (SendVar->FileHandle>0);
# Line 975  int ProtoDlgParse() Line 1058  int ProtoDlgParse()
1058    P = ActiveWin;    P = ActiveWin;
1059    if (PtDlg==NULL) return P;    if (PtDlg==NULL) return P;
1060    
 #ifdef I18N  
   if ((*ProtoParse)(ProtoId,FileVar,ProtoVar,&cv,&ts))  
 #else  
1061    if ((*ProtoParse)(ProtoId,FileVar,ProtoVar,&cv))    if ((*ProtoParse)(ProtoId,FileVar,ProtoVar,&cv))
 #endif  
1062      P = 0; /* continue */      P = 0; /* continue */
1063    else {    else {
1064      CommSend(&cv);      CommSend(&cv);
# Line 1018  void KermitStart(int mode) Line 1097  void KermitStart(int mode)
1097        FileVar->OpId = OpKmtSend;        FileVar->OpId = OpKmtSend;
1098        if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)        if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)
1099        {        {
 #ifdef I18N  
         if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_KERMIT,&w,&ts) ||  
 #else  
1100          if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_KERMIT,&w) ||          if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_KERMIT,&w) ||
 #endif  
1101              (FileVar->NumFname==0))              (FileVar->NumFname==0))
1102          {          {
1103            ProtoEnd();            ProtoEnd();
# Line 1030  void KermitStart(int mode) Line 1105  void KermitStart(int mode)
1105          }          }
1106        }        }
1107        else        else
 #ifdef I18N  
     (*SetFileVar)(FileVar, &ts);  
 #else  
1108          (*SetFileVar)(FileVar);          (*SetFileVar)(FileVar);
 #endif  
1109            break;            break;
1110      case IdKmtReceive:      case IdKmtReceive:
1111        FileVar->OpId = OpKmtRcv;        FileVar->OpId = OpKmtRcv;
# Line 1051  void KermitStart(int mode) Line 1122  void KermitStart(int mode)
1122          }          }
1123        }        }
1124        else        else
 #ifdef I18N  
     (*SetFileVar)(FileVar, &ts);  
 #else  
1125          (*SetFileVar)(FileVar);          (*SetFileVar)(FileVar);
 #endif  
1126            break;            break;
1127      case IdKmtFinish:      case IdKmtFinish:
1128        FileVar->OpId = OpKmtFin;        FileVar->OpId = OpKmtFin;
# Line 1089  void XMODEMStart(int mode) Line 1156  void XMODEMStart(int mode)
1156    if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)    if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)
1157    {    {
1158      Option = MAKELONG(ts.XmodemBin,ts.XmodemOpt);      Option = MAKELONG(ts.XmodemBin,ts.XmodemOpt);
 #ifdef I18N  
     if (! (*GetXFname)(FileVar->HMainWin,  
       mode==IdXReceive,&Option,FileVar,ts.FileDir,&ts))  
 #else  
1159      if (! (*GetXFname)(FileVar->HMainWin,      if (! (*GetXFname)(FileVar->HMainWin,
1160        mode==IdXReceive,&Option,FileVar,ts.FileDir))        mode==IdXReceive,&Option,FileVar,ts.FileDir))
 #endif  
1161      {      {
1162        ProtoEnd();        ProtoEnd();
1163        return;        return;
# Line 1104  void XMODEMStart(int mode) Line 1166  void XMODEMStart(int mode)
1166      ts.XmodemBin = LOWORD(Option);      ts.XmodemBin = LOWORD(Option);
1167    }    }
1168    else    else
 #ifdef I18N  
     (*SetFileVar)(FileVar, &ts);  
 #else  
1169      (*SetFileVar)(FileVar);      (*SetFileVar)(FileVar);
 #endif  
1170    
1171    if (mode==IdXReceive)    if (mode==IdXReceive)
1172      FileVar->FileHandle = _lcreat(FileVar->FullName,0);      FileVar->FileHandle = _lcreat(FileVar->FullName,0);
# Line 1145  void ZMODEMStart(int mode) Line 1203  void ZMODEMStart(int mode)
1203      FileVar->OpId = OpZSend;      FileVar->OpId = OpZSend;
1204      if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)      if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)
1205      {      {
 #ifdef I18N  
       if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_Z,&Opt,&ts) ||  
 #else  
1206        if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_Z,&Opt) ||        if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_Z,&Opt) ||
 #endif  
1207            (FileVar->NumFname==0))            (FileVar->NumFname==0))
1208        {        {
1209          ProtoEnd();          ProtoEnd();
# Line 1158  void ZMODEMStart(int mode) Line 1212  void ZMODEMStart(int mode)
1212        ts.XmodemBin = Opt;        ts.XmodemBin = Opt;
1213      }      }
1214      else      else
 #ifdef I18N  
       (*SetFileVar)(FileVar, &ts);  
 #else  
1215        (*SetFileVar)(FileVar);        (*SetFileVar)(FileVar);
 #endif  
1216    }    }
1217    else /* IdZReceive or IdZAuto */    else /* IdZReceive or IdZAuto */
1218      FileVar->OpId = OpZRcv;      FileVar->OpId = OpZRcv;
# Line 1189  void BPStart(int mode) Line 1239  void BPStart(int mode)
1239      if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)      if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)
1240      {      {
1241            FileVar->FullName[0] = 0;            FileVar->FullName[0] = 0;
 #ifdef I18N  
       if (! (*GetTransFname)(FileVar, ts.FileDir, GTF_BP, &Option, &ts))  
 #else  
1242        if (! (*GetTransFname)(FileVar, ts.FileDir, GTF_BP, &Option))        if (! (*GetTransFname)(FileVar, ts.FileDir, GTF_BP, &Option))
 #endif  
1243            {            {
1244          ProtoEnd();          ProtoEnd();
1245          return;          return;
1246        }        }
1247      }      }
1248      else      else
 #ifdef I18N  
       (*SetFileVar)(FileVar, &ts);  
 #else  
1249        (*SetFileVar)(FileVar);        (*SetFileVar)(FileVar);
 #endif  
1250    }    }
1251    else /* IdBPReceive or IdBPAuto */    else /* IdBPReceive or IdBPAuto */
1252      FileVar->OpId = OpBPRcv;      FileVar->OpId = OpBPRcv;
# Line 1231  void QVStart(int mode) Line 1273  void QVStart(int mode)
1273      FileVar->OpId = OpQVSend;      FileVar->OpId = OpQVSend;
1274      if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)      if (strlen(&(FileVar->FullName[FileVar->DirLen]))==0)
1275      {      {
 #ifdef I18N  
       if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_QV, &W, &ts) ||  
 #else  
1276        if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_QV, &W) ||        if (! (*GetMultiFname)(FileVar,ts.FileDir,GMF_QV, &W) ||
 #endif  
1277            (FileVar->NumFname==0))            (FileVar->NumFname==0))
1278        {        {
1279          ProtoEnd();          ProtoEnd();
# Line 1243  void QVStart(int mode) Line 1281  void QVStart(int mode)
1281        }        }
1282      }      }
1283      else      else
 #ifdef I18N  
       (*SetFileVar)(FileVar, &ts);  
 #else  
1284        (*SetFileVar)(FileVar);        (*SetFileVar)(FileVar);
 #endif  
1285    }    }
1286    else    else
1287      FileVar->OpId = OpQVRcv;      FileVar->OpId = OpQVRcv;
# Line 1264  void QVStart(int mode) Line 1298  void QVStart(int mode)
1298    
1299  /*  /*
1300   * $Log$   * $Log$
1301     * Revision 1.13  2007/05/30 16:04:27  maya
1302     * 標準のログ保存先を指定できるようにした。
1303     *
1304     * Revision 1.12  2007/05/25 09:56:05  yutakapon
1305     * タイムスタンプ付きログで1KBごとに不要な改行が入るバグを修正。
1306     *
1307     * Revision 1.11  2007/05/14 14:07:14  maya
1308     * バッファをクリアしていないので落ちる問題を修正した。
1309     *
1310     * Revision 1.10  2007/05/14 13:29:58  maya
1311     * ログファイル名中の &h を、接続中のホスト名に変換する機能を追加した。
1312     *
1313     * Revision 1.9  2007/01/21 16:18:35  maya
1314     * 表示メッセージの読み込み対応
1315     *
1316   * Revision 1.8  2007/01/04 15:11:44  maya   * Revision 1.8  2007/01/04 15:11:44  maya
1317   * 表示メッセージの読み込み対応   * 表示メッセージの読み込み対応
1318   *   *

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.13

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