Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/teraterm/teraterm/vtterm.c

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

revision 8897 by zmatsuo, Tue Aug 18 15:27:54 2020 UTC revision 8904 by zmatsuo, Tue Aug 18 15:31:14 2020 UTC
# Line 58  Line 58 
58  #include "codeconv.h"  #include "codeconv.h"
59  #include "unicode.h"  #include "unicode.h"
60  #include "ttdde.h"  #include "ttdde.h"
61    #include "checkeol.h"
62    
63  #include "vtterm.h"  #include "vtterm.h"
64    
# Line 215  static DWORD BeepOverUsedCount = 0; Line 216  static DWORD BeepOverUsedCount = 0;
216  static _locale_t CLocale = NULL;  static _locale_t CLocale = NULL;
217    
218  typedef struct {  typedef struct {
219          BOOL log_cr_hold;          CheckEOLData_t *eol;
         int log_code;  
220          int log_cr_type;          int log_cr_type;
221  } vtterm_work_t;  } vtterm_work_t;
222    
# Line 362  void ResetTerminal() /*reset variables b Line 362  void ResetTerminal() /*reset variables b
362    
363          {          {
364                  vtterm_work_t *vtterm = &vtterm_work;                  vtterm_work_t *vtterm = &vtterm_work;
365                  vtterm->log_cr_hold = FALSE;                  vtterm->eol = CheckEOLCreate();
                 vtterm->log_code = 0;  
366                  vtterm->log_cr_type = 0;                  vtterm->log_cr_type = 0;
367          }          }
368  }  }
# Line 452  void MoveToMainScreen() Line 451  void MoveToMainScreen()
451          MoveCursor(MainX, MainY); // move to main screen          MoveCursor(MainX, MainY); // move to main screen
452  }  }
453    
 /*  
  *      ログに1キャラクタ(BYTE)出力  
  */  
 static void Log1Char(vtterm_work_t *vtterm, char c)  
 {  
         switch (vtterm->log_code) {  
         case 0:  
         default:  
                 // UTF-8  
                 LogPut1(c);  
                 break;  
         case 1:  
                 // UTF-16LE  
                 LogPut1(c);  
                 LogPut1(0);  
                 break;  
         case 2:  
                 // UTF-16LE  
                 LogPut1(0);  
                 LogPut1(c);  
                 break;  
         }  
 }  
   
454  /**  /**
455   *      1キャラクタ(unsigned int, char32_t)をログ(or/and macro送信バッファ)へ出力   *      1キャラクタ(unsigned int, char32_t)をmacroへ出力
  *      New Line 以外  
456   */   */
457  static void OutputLogUTF32WONL(vtterm_work_t *vtterm, unsigned int u32)  static void DDEPut1U32(unsigned int u32)
458  {  {
459          size_t i;          if (DDELog) {
460          BOOL log_available = (cv.HLogBuf != 0);                  // UTF-8 で出力する
   
         if (!DDELog && !log_available) {  
                 // ログにも macro にも出力不要  
                 return;  
         }  
   
         // UTF-8 で出力する Log or/and macro  
         if (DDELog || (log_available && vtterm->log_code == 0)) {  
461                  char u8_buf[4];                  char u8_buf[4];
462                  size_t u8_len = UTF32ToUTF8(u32, u8_buf, _countof(u8_buf));                  size_t u8_len = UTF32ToUTF8(u32, u8_buf, _countof(u8_buf));
463                    size_t i;
464                  for (i = 0; i < u8_len; i++) {                  for (i = 0; i < u8_len; i++) {
465                          BYTE b = u8_buf[i];                          BYTE b = u8_buf[i];
466                          if (DDELog)                          DDEPut1(b);
                                 DDEPut1(b);  
                         if (log_available && vtterm->log_code == 0)  
                                 LogPut1(b);  
467                  }                  }
468          }          }
   
         if (!log_available) {  
                 // ログには出力しない(macro出力だけだった)  
                 return;  
         }  
   
         switch(vtterm->log_code) {  
         case 0: {  
                 // UTF-8, 出力済み  
                 break;  
         }  
         case 1:  
         case 2: {  
                 // UTF-16  
                 wchar_t u16[2];  
                 size_t u16_len = UTF32ToUTF16(u32, u16, _countof(u16));  
                 size_t i;  
                 for (i = 0; i < u16_len; i++) {  
                         if (vtterm->log_code == 1) {  
                                 // UTF-16LE  
                                 LogPut1(u16[i] & 0xff);  
                                 LogPut1((u16[i] >> 8) & 0xff);  
                         }  
                         else {  
                                 // UTF-16BE  
                                 LogPut1(u16[i] & 0xff);  
                                 LogPut1((u16[i] >> 8) & 0xff);  
                         }  
                 }  
         }  
         }  
469  }  }
470    
471  /**  /**
472   *      改行をログ(or/and macro送信バッファ)へ出力   *      ログへ設定された改行コードを出力
  *      ログには設定された改行コードを出力  
  *      macro用には CR+LF を出力  
473   */   */
474  static void OutputLogNewLine(vtterm_work_t *vtterm)  static void OutputLogNewLine(vtterm_work_t *vtterm)
475  {  {
476          // ログ出力          switch(vtterm->log_cr_type) {
477          if (cv.HLogBuf != 0) {          case 0:
478                  // ログは取っている                  // CR + LF
479                  switch(vtterm->log_cr_type) {                  FLogPutUTF32(CR);
480                  case 0:                  FLogPutUTF32(LF);
481                          // CR + LF                  break;
482                          Log1Char(vtterm, CR);          case 1:
483                          Log1Char(vtterm, LF);                  // CR
484                          break;                  FLogPutUTF32(CR);
485                  case 1:                  break;
486                          // CR          case 2:
487                          Log1Char(vtterm, CR);                  // LF
488                          break;                  FLogPutUTF32(LF);
489                  case 2:                  break;
                         // LF  
                         Log1Char(vtterm, LF);  
                         break;  
                 }  
490          }          }
   
         // マクロ出力  
         DDEPut1(CR);  
         DDEPut1(LF);  
491  }  }
492    
493  /**  /**
# Line 572  static void OutputLogNewLine(vtterm_work Line 495  static void OutputLogNewLine(vtterm_work
495   */   */
496  static void OutputLogUTF32(unsigned int u32)  static void OutputLogUTF32(unsigned int u32)
497  {  {
498            if (!FLogIsOpend() && !DDELog) {
499                    return;
500            }
501          vtterm_work_t *vtterm = &vtterm_work;          vtterm_work_t *vtterm = &vtterm_work;
502    
503          // 入力が改行(CR or LF)の場合、          CheckEOLRet r = CheckEOLCheck(vtterm->eol, u32);
504          // 改行の種類(CR or LF or CR+LF)を自動で判定して          if ((r & CheckEOLOutputEOL) != 0) {
505          // OutputLogNewLine() で改行を出力する                  // ログ、改行を出力
506          //              入力    CR hold     改行出力    CR hold 変更                  if (FLogIsOpend()) {
         //              +-------+-----------+-----------+------------  
         //              CR      なし        しない              セットする  
         //              LF      なし        する                変化なし  
         //              その他  なし        しない              変化なし  
         //              CR      あり        する                変化なし(ホールドしたまま)  
         //              LF      あり        する                クリアする  
         //              その他  あり        する                クリアする  
         if (vtterm->log_cr_hold == FALSE) {  
                 if (u32 == CR) {  
                         vtterm->log_cr_hold = TRUE;  
                         return;  
                 }  
                 else if (u32 == LF) {  
507                          OutputLogNewLine(vtterm);                          OutputLogNewLine(vtterm);
                         return;  
508                  }                  }
509                  else {  
510                          // 改行特になし                  // マクロ、改行を出力
511                    if (DDELog) {
512                            DDEPut1(CR);
513                            DDEPut1(LF);
514                  }                  }
515          }          }
516          else {          if ((r & CheckEOLOutputChar) != 0) {
517                  if (u32 == CR) {                  // ログ、u32を出力
518                          OutputLogNewLine(vtterm);                  if (FLogIsOpend()) {
519                          return;                          FLogPutUTF32(u32);
520                  }                  }
521                  else if (u32 == LF) {  
522                          vtterm->log_cr_hold = FALSE;                  // マクロ、u32を出力
523                          OutputLogNewLine(vtterm);                  if (DDELog) {
524                          return;                          DDEPut1U32(u32);
                 }  
                 else {  
                         vtterm->log_cr_hold = FALSE;  
                         OutputLogNewLine(vtterm);  
525                  }                  }
526          }          }
   
         // 改行以外を出力  
         OutputLogUTF32WONL(vtterm, u32);  
527  }  }
528    
529  /**  /**
# Line 634  static BOOL NeedsOutputBufs(void) Line 542  static BOOL NeedsOutputBufs(void)
542          return cv.HLogBuf != 0 || DDELog;          return cv.HLogBuf != 0 || DDELog;
543  }  }
544    
 void TermLogSetCode(int code)  
 {  
         vtterm_work_t *vtterm = &vtterm_work;  
         vtterm->log_code = code;  
 }  
   
 void TermLogOutputBOM(void)  
 {  
         vtterm_work_t *vtterm = &vtterm_work;  
         BOOL needs_unlock = FALSE;  
   
         if ((cv.HLogBuf!=NULL) && (cv.LogBuf==NULL)) {  
                 cv.LogBuf = (PCHAR)GlobalLock(cv.HLogBuf);  
                 needs_unlock = TRUE;  
         }  
   
         switch (vtterm->log_code) {  
         case 0:  
                 // UTF-8  
                 LogPut1(0xef);  
                 LogPut1(0xbb);  
                 LogPut1(0xbf);  
                 break;  
         case 1:  
                 // UTF-16LE  
                 LogPut1(0xfe);  
                 LogPut1(0xff);  
                 break;  
         case 2:  
                 // UTF-16BE  
                 LogPut1(0xff);  
                 LogPut1(0xfe);  
                 break;  
         default:  
                 break;  
         }  
   
         if (needs_unlock) {  
                 GlobalUnlock(cv.HLogBuf);  
                 cv.LogBuf = NULL;  
         }  
 }  
   
545  void MoveToStatusLine()  void MoveToStatusLine()
546  {  {
547          MainX = CursorX;          MainX = CursorX;

Legend:
Removed from v.8897  
changed lines
  Added in v.8904

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