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 5564 by doda, Mon Mar 31 08:30:11 2014 UTC revision 5568 by doda, Mon Apr 14 04:26:52 2014 UTC
# Line 3888  void RequestStatusString(unsigned char * Line 3888  void RequestStatusString(unsigned char *
3888          }          }
3889  }  }
3890    
3891    int toHexStr(unsigned char *buff, int buffsize, unsigned char *str)
3892    {
3893            int len, i, copylen = 0;
3894            unsigned char c;
3895    
3896            len = strlen(str);
3897    
3898            if (buffsize < len*2) {
3899                    return -1;
3900            }
3901    
3902            for (i=0; i<len; i++) {
3903                    c = str[i] >> 4;
3904                    if (c <= 9) {
3905                            c += '0';
3906                    }
3907                    else {
3908                            c += 'a' - 10;
3909                    }
3910                    buff[copylen++] = c;
3911    
3912                    c = str[i] & 0xf;
3913                    if (c <= 9) {
3914                            c += '0';
3915                    }
3916                    else {
3917                            c += 'a' - 10;
3918                    }
3919                    buff[copylen++] = c;
3920            }
3921    
3922            return copylen;
3923    }
3924    
3925    int TermcapString(unsigned char *buff, int buffsize, unsigned char *capname)
3926    {
3927            int len = 0, l;
3928            unsigned char c;
3929            unsigned char *capval = NULL;
3930    
3931            if (strcmp(capname, "Co") == 0 || strcmp(capname, "colors") == 0) {
3932                    if ((ts.ColorFlag & CF_ANSICOLOR) == 0) {
3933                            return 0;
3934                    }
3935    
3936                    if (ts.ColorFlag & CF_XTERM256) {
3937                            capval = "256";
3938                    }
3939                    else if (ts.ColorFlag & CF_FULLCOLOR) {
3940                            capval = "16";
3941                    }
3942                    else {
3943                            capval = "8";
3944                    }
3945            }
3946    
3947            if (capval) {
3948                    if ((len = toHexStr(buff, buffsize, capname)) < 0) {
3949                            return 0;
3950                    }
3951    
3952                    if (buffsize <= len) {
3953                            return 0;
3954                    }
3955                    buff[len++] = '=';
3956    
3957                    if ((l = toHexStr(&buff[len], buffsize-len, capval)) < 0) {
3958                            return 0;
3959                    }
3960                    len += l;
3961            }
3962    
3963            return len;
3964    }
3965    
3966    void RequestTermcapString(unsigned char *StrBuff, int StrLen)   // xterm experimental
3967    {
3968            unsigned char RepStr[256];
3969            unsigned char CapName[16];
3970            int i, len, replen, caplen = 0;
3971    
3972            RepStr[0] = '1';
3973            RepStr[1] = '+';
3974            RepStr[2] = 'r';
3975            replen = 3;
3976    
3977            for (i=0; i<StrLen; i++) {
3978                    if (StrBuff[i] == ';') {
3979                            if (replen >= sizeof(RepStr)) {
3980                                    caplen = 0;
3981                                    break;
3982                            }
3983                            if (replen > 3) {
3984                                    RepStr[replen++] = ';';
3985                            }
3986                            if (caplen > 0 && caplen < sizeof(CapName)) {
3987                                    CapName[caplen] = 0;
3988                                    len = TermcapString(&RepStr[replen], sizeof(RepStr)-replen, CapName);
3989                                    replen += len;
3990                                    caplen = 0;
3991                                    if (len == 0) {
3992                                            break;
3993                                    }
3994                            }
3995                            else {
3996                                    caplen = 0;
3997                                    break;
3998                            }
3999                    }
4000                    else if (i+1 < StrLen && isxdigit(StrBuff[i]) && isxdigit(StrBuff[i+1])
4001                      && caplen < sizeof(CapName)-1) {
4002                            if (isdigit(StrBuff[i])) {
4003                                    CapName[caplen] = (StrBuff[i] - '0') * 16;
4004                            }
4005                            else {
4006                                    CapName[caplen] = ((StrBuff[i] | 0x20) - 'a' + 10) * 16;
4007                            }
4008                            i++;
4009                            if (isdigit(StrBuff[i])) {
4010                                    CapName[caplen] += (StrBuff[i] - '0');
4011                            }
4012                            else {
4013                                    CapName[caplen] += ((StrBuff[i] | 0x20) - 'a' + 10);
4014                            }
4015                            caplen++;
4016                    }
4017                    else {
4018                            caplen = 0;
4019                            break;
4020                    }
4021            }
4022    
4023            if (caplen && caplen < sizeof(CapName) && replen < sizeof(RepStr)) {
4024                    if (replen > 3) {
4025                            RepStr[replen++] = ';';
4026                    }
4027                    CapName[caplen] = 0;
4028                    len = TermcapString(&RepStr[replen], sizeof(RepStr)-replen, CapName);
4029                    replen += len;
4030            }
4031    
4032            if (replen == 3) {
4033                    RepStr[0] = '0';
4034            }
4035            SendDCSstr(RepStr, replen);
4036    }
4037    
4038  void ParseDCS(BYTE Cmd, unsigned char *StrBuff, int len) {  void ParseDCS(BYTE Cmd, unsigned char *StrBuff, int len) {
4039          switch (ICount) {          switch (ICount) {
4040          case 0:          case 0:
# Line 3914  void ParseDCS(BYTE Cmd, unsigned char *S Line 4061  void ParseDCS(BYTE Cmd, unsigned char *S
4061                                  RequestStatusString(StrBuff, len);                                  RequestStatusString(StrBuff, len);
4062                          }                          }
4063                          break;                          break;
4064                    case '+':
4065                            if (Cmd == 'q') { // Request termcap/terminfo string (xterm)
4066                                    RequestTermcapString(StrBuff, len);
4067                            }
4068                            break;
4069                  default:                  default:
4070                          break;                          break;
4071                  }                  }

Legend:
Removed from v.5564  
changed lines
  Added in v.5568

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