static Lexem ParseNumericConstant( const std::string& file_data, std::string::const_iterator& it ) { Lexem result; result.file_position= it - file_data.begin(); // Hex if( *it == '0' && (it+1) < file_data.end() && *(it+1) == 'x' ) { if( it+2 == file_data.end() || !IsHexDigit(*it) ) throw LexicalError( it - file_data.begin() ); result.text+= "0x"; it+= 2; while( it != file_data.end() && IsHexDigit(*it) ) { result.text+= *it; it++; } } else while( it != file_data.end() && isdigit(*it) ) { result.text+= *it; it++; } if( it != file_data.end() && isalpha(*it) ) throw LexicalError( it - file_data.begin() ); result.type= Lexem::Type::NumericConstant; return result; }
bool LogicalExpression::GetNumber(const wchar_t **p, long long *n) { if (!IsDigit(**p)) return false; *n=0; if (**p == L'0' && ((*(*p+1))|0x20) == L'x') { (*p)+=2; if (!IsHexDigit(**p)) return false; while (IsHexDigit(**p)) { *n=*n*16ll + GetHex(**p); (*p)++; } } else if (!GetIPv4(p,n)) { *n=0; while (IsDigit(**p)) { *n=*n*10ll+**p-L'0'; (*p)++; } } return true; }
// Returns true if the string represents a number: // Valid styles: // 1) 0xAB, 0XAB (hex) // 2) ABh, ABH (hex) // 3) 171 (decimal assumed) bool IsNumber(char *string) { int len; int i; // Get string length for(len = 0; string[len] != '\0'; len++); if(string[1] == 'x' || string[1] == 'X') { // Case 1) First digits "0x" or "0X", all others should be hex digits if(string[0] != '0') return false; for(i = 2; i < len; i++) if(!IsHexDigit(string[i])) return false; return true; } else if(string[len-1] == 'h' || string[len-1] == 'H') { // Case 2) All but last byte (the h or H) should be hex digits len--; for(i = 0; i < len; i++) if(!IsHexDigit(string[i])) return false; return true; } else { // Case 3) Must be all numbers for(i = 0; i < len; i++) if(!IsDigit(string[i])) return false; return true; } return false; }
// parses a hex number bool opScanner::Hexadecimals(const inputtype& Input, int& current) { if (current + 2 < Input.Size()) { int one = current; int two = current + 1; int three = current + 2; if (Input[one] == '0' && (Input[two] == 'x' || Input[two] == 'X') && IsHexDigit(Input[three])) { int end = Input.Size(); opToken newToken(T_HEXADECIMAL, opString("0x") + Input[three], CurrentLine); current += 3; one = current; while (one != end) { if (!IsHexDigit(Input[one])) break; newToken.Value += Input[one]; ++current; one = current; } Tokens.PushBack(newToken); return true; } } return false; }
CByteArray::CByteArray(const std::string & csData, bool bIsHex) { if (!bIsHex) { const unsigned char *data = reinterpret_cast<const unsigned char *>(csData.c_str()); MakeArray(data, static_cast<unsigned int>(csData.length())); } else { const char *csHexData = csData.c_str(); unsigned long ulHexLen = (int) csData.size(); m_ulCapacity = ulHexLen / 2; MakeArray(NULL, 0, m_ulCapacity); if (!m_bMallocError) { unsigned char uc = 0; bool bSecondHexDigit = true; for (unsigned long i = 0; i < ulHexLen; i++) { if (IsHexDigit(csHexData[i])) { uc = 16 * uc + Hex2Byte(csHexData[i]); bSecondHexDigit = !bSecondHexDigit; if (bSecondHexDigit) m_pucData[m_ulSize++] = uc; } } } } }
bool CDirstatApp::ScanAuxiliaryFileName(LPCTSTR prefix, LPCTSTR suffix, LPCTSTR name, LANGID& langid) { ASSERT(lstrlen(prefix) == 4); // "wdsr" or "wdsh" ASSERT(lstrlen(suffix) == 4); // ".dll" or ".chm" CString s= name; // "wdsr0a01.dll" s.MakeLower(); if (s.Left(4) != prefix) return false; s= s.Mid(4); // "0a01.dll" if (s.GetLength() != 8) return false; if (s.Mid(4) != suffix) return false; s= s.Left(4); // "0a01" for (int i=0; i < 4; i++) if (!IsHexDigit(s[i])) return false; int id; VERIFY(1 == _stscanf(s, _T("%04x"), &id)); langid= (LANGID)id; return true; }
long long LogicalExpression::GetHex(int c) { if (IsDigit(c)) return (c-L'0'); if (IsHexDigit(c)) return (10ll + (c|0x20) - L'a'); return 0ll; }
int HexStrToInt64(const char *string, uint64_t *dest){ while(*string!='\0'){ if(!IsHexDigit(*string)) return -1; dest[0]<<=4; dest[0]+=HexDigitValue(*string); string++; } return 1; }
/* Parse hex number from the string pucStr. */ bool GetHexValueFromString(char *szStr, u32 *pu4bVal, u32 *pu4bMove) { char *szScan = szStr; /* Check input parameter. */ if (!szStr || !pu4bVal || !pu4bMove) { DBG_871X("GetHexValueFromString(): Invalid input arguments! szStr: %p, pu4bVal: %p, pu4bMove: %p\n", szStr, pu4bVal, pu4bMove); return false; } /* Initialize output. */ *pu4bMove = 0; *pu4bVal = 0; /* Skip leading space. */ while (*szScan != '\0' && (*szScan == ' ' || *szScan == '\t')) { szScan++; (*pu4bMove)++; } /* Skip leading '0x' or '0X'. */ if (*szScan == '0' && (*(szScan+1) == 'x' || *(szScan+1) == 'X')) { szScan += 2; (*pu4bMove) += 2; } /* Check if szScan is now pointer to a character for hex digit, */ /* if not, it means this is not a valid hex number. */ if (!IsHexDigit(*szScan)) return false; /* Parse each digit. */ do { (*pu4bVal) <<= 4; *pu4bVal += MapCharToHexDigit(*szScan); szScan++; (*pu4bMove)++; } while (IsHexDigit(*szScan)); return true; }
// Returns true if the string is of the correct form for an address. // Valid styles: // Valid styles: // 1) seg:off (hex only for segment and offset) // 2) 0xAB, 0XAB (hex) // 3) ABh, ABH (hex) // 3) 171 (decimal assumed) bool IsAddress(char *string) { int colonIndex; int len; int i; for(len = 0, colonIndex = 0; string[len] != '\0'; len++) { if(string[len] == ':') colonIndex = len; } if(colonIndex) { // Case 1) Has colon in middle or end. All digits before and after must be hex digits for(i = 0; i < colonIndex; i++) if(!IsHexDigit(string[i])) return false; for(i++; i < len; i++) if(!IsHexDigit(string[i])) return false; return true; } // Must be a physical address in the form of a number (hex or dec) return IsNumber(string); }
/**************************************************************************** ** *F CharHexDigit( <ch> ) . . . . . . . . . turn a single hex digit into Char ** */ static inline Char CharHexDigit( Char c ) { c = GET_NEXT_CHAR(); if (!IsHexDigit(c)) { SyntaxError("Expecting hexadecimal digit"); } if (c >= 'a') { return (c - 'a' + 10); } else if (c >= 'A') { return (c - 'A' + 10); } else { return (c - '0'); } }
static int ScanNumericLiteral() { int base = 10; if('.' == *CURSOR) { return ScanFloatLiteral(); } if('0' == *CURSOR && (CURSOR[1] == 'x'|| CURSOR[1] == 'X')) { base = 16; CURSOR += 2; while(IsHexDigit(*CURSOR)) { CURSOR++; } } else if('0' == *CURSOR) { base = 8; CURSOR++; while(IsOctDigit(*CURSOR)) { CURSOR++; } } else { CURSOR++; while(IsDigit(*CURSOR)) { CURSOR++; } } if(base == 16 || (*CURSOR == '.' && *CURSOR == 'e' && *CURSOR == 'E')) { while('u' == *CURSOR || 'U' == *CURSOR || 'l' == *CURSOR || 'L' == *CURSOR) { CURSOR++; } return TK_INTCONST; } else { return ScanFloatLiteral(); } }
BOOLEAN ParseMAC (MACADDR dest, const char *src) { int c; int mac_index = 0; BOOLEAN high_digit = FALSE; int delim_action = 1; MYASSERT (src); MYASSERT (dest); CLEAR_MAC (dest); while (c = *src++) { if (IsMacDelimiter (c)) { mac_index += delim_action; high_digit = FALSE; delim_action = 1; } else if (IsHexDigit (c)) { const int digit = HexStringToDecimalInt (c); if (mac_index < sizeof (MACADDR)) { if (!high_digit) { dest[mac_index] = (char)(digit); high_digit = TRUE; delim_action = 1; } else { dest[mac_index] = (char)(dest[mac_index] * 16 + digit); ++mac_index; high_digit = FALSE; delim_action = 0; } } else return FALSE; } else return FALSE; } return (mac_index + delim_action) >= sizeof (MACADDR); }
/* 扫描常数序列 */ static int ScanNumericLiteral (void) { unsigned char *start = CURRENT; /* 表示数值是多少进制 */ unsigned char base = 10; if ('.' == *CURRENT) { return ScanFloatLiteral (start); } /* 扫描前半部分(小数点的左边) */ if ('0' == *CURRENT && ('x' == CURRENT[1] || 'X' == CURRENT[1])) { base = 16; start = (CURRENT += 2); if (!IsHexDigit (*CURRENT)) { Error (&TokenCoord, "Expect hex digit"); TokenValue.i[0] = 0; return TK_INTCONST; } while (IsHexDigit (*CURRENT)) CURRENT++; } else if ('0' == *CURRENT) { base = 8; while (IsOctDigit (*++CURRENT)); } else { while (IsDigit (*++CURRENT)); } /* 如果符合下边条件,按整形处理 */ if (16 == base || ('.' != *CURRENT && 'e' != *CURRENT && 'E' != *CURRENT)) return ScanIntLiteral (start, (int)(CURRENT - start), base); else return ScanFloatLiteral (start); }
VOID GenerateRandomMac( __in MACADDR mac, __in const unsigned char *adapter_name ) { unsigned const char *cp = adapter_name; unsigned char c; unsigned int i = 2; unsigned int byte = 0; int brace = 0; int state = 0; CLEAR_MAC (mac); mac[0] = 0x00; mac[1] = 0xFF; while (c = *cp++) { if (i >= sizeof (MACADDR)) break; if (c == '{') brace = 1; if (IsHexDigit (c) && brace) { const unsigned int digit = HexStringToDecimalInt (c); if (state) { byte <<= 4; byte |= digit; mac[i++] = (unsigned char) byte; state = 0; } else { byte = digit; state = 1; } } } }
TokenType ReadHexNumber(istream& is, string& str, Coordinates& xy) { State st; char c; while (!is.eof()) { st = GetState(is.peek()); if (IsSyntaxError(st)) throw Error("syntax error", pos.first, pos.second); if (IsHexDigit(is.peek())) str = str + GetSymb(is,xy); else { c = GetSymb(is,xy); if (!IsSep(c) && c != '\n' && c != EOF) throw Error("wrong hex number", pos.first, pos.second); return int_const_hex; } } return int_const_hex; }
static inline size_t EscapeC(unsigned char c, TNextChar next, TBufferChar r[ESCAPE_C_BUFFER_SIZE]) { // (1) Printable characters go as-is, except backslash and double quote. // (2) Characters \r, \n, \t and \0 ... \7 replaced by their simple escape characters (if possible). // (3) Otherwise, character is encoded using hexadecimal escape sequence (if possible), or octal. if (c == '\"') { r[0] = '\\'; r[1] = '\"'; return 2; } else if (c == '\\') { r[0] = '\\'; r[1] = '\\'; return 2; } else if (IsPrintable(c)) { r[0] = c; return 1; } else if (c == '\r') { r[0] = '\\'; r[1] = 'r'; return 2; } else if (c == '\n') { r[0] = '\\'; r[1] = 'n'; return 2; } else if (c == '\t') { r[0] = '\\'; r[1] = 't'; return 2; } else if (c < 8 && !IsOctDigit(next)) { r[0] = '\\'; r[1] = OctDigit(c); return 2; } else if (!IsHexDigit(next)) { r[0] = '\\'; r[1] = 'x'; r[2] = HexDigit((c & 0xF0) >> 4); r[3] = HexDigit((c & 0x0F) >> 0); return 4; } else {
bool ReadAnnotatedAssembly(const char *filename) { File::IOFile f(filename, "r"); if (!f) { ERROR_LOG(DSPLLE, "Bah! ReadAnnotatedAssembly couldn't find the file %s", filename); return false; } char line[512]; int last_addr = 0; lines.reserve(3000); // Symbol generation int brace_count = 0; bool symbol_in_progress = false; int symbol_count = 0; Symbol current_symbol; while (fgets(line, 512, f.GetHandle())) { // Scan string for the first 4-digit hex string. size_t len = strlen(line); int first_hex = -1; bool hex_found = false; for (unsigned int i = 0; i < strlen(line); i++) { const char c = line[i]; if (IsHexDigit(c)) { if (first_hex == -1) { first_hex = i; } else { // Remove hex notation if ((int)i == first_hex + 3 && (first_hex == 0 || line[first_hex - 1] != 'x') && (i >= len - 1 || line[i + 1] == ' ')) { hex_found = true; break; } } } else { if (i - first_hex < 3) { first_hex = -1; } if (IsAlpha(c)) break; } } // Scan for function starts if (!memcmp(line, "void", 4)) { char temp[256]; for (size_t i = 6; i < len; i++) { if (line[i] == '(') { // Yep, got one. memcpy(temp, line + 5, i - 5); temp[i - 5] = 0; // Mark symbol so the next hex sets the address current_symbol.name = temp; current_symbol.address = 0xFFFF; current_symbol.index = symbol_count++; symbol_in_progress = true; // Reset brace count. brace_count = 0; } } } // Scan for braces for (size_t i = 0; i < len; i++) { if (line[i] == '{') brace_count++; if (line[i] == '}') { brace_count--; if (brace_count == 0 && symbol_in_progress) { // Commit this symbol. current_symbol.size = last_addr - current_symbol.address + 1; g_dsp_symbol_db.AddCompleteSymbol(current_symbol); current_symbol.address = 0xFFFF; symbol_in_progress = false; } } } if (hex_found) { int hex = 0; sscanf(line + first_hex, "%04x", &hex); // Sanity check if (hex > last_addr + 3 || hex < last_addr - 3) { static int errors = 0; INFO_LOG(DSPLLE, "Got Insane Hex Digit %04x (%04x) from %s", hex, last_addr, line); errors++; if (errors > 10) { return false; } } else { // if (line_counter >= 200 && line_counter <= 220) // NOTICE_LOG(DSPLLE, "Got Hex Digit %04x from %s, line %i", hex, line, line_counter); if (symbol_in_progress && current_symbol.address == 0xFFFF) current_symbol.address = hex; line_to_addr[line_counter] = hex; addr_to_line[hex] = line_counter; last_addr = hex; } } lines.push_back(TabsToSpaces(4, line)); line_counter++; } return true; }
// 从socket中把接收的数据转换到本地内存 David 2010.6.11 Add // 缓冲区指针为空返回0 // 不是来自设备端的数据包返回-1 // 与客户端的IP不同返回-2 // 转换分段数据错误-3 // 用户名和密码错误返回-4 // 成功返回1 int CUpgraderDoc::GetDataFromSocket(char* buffer, //[in] 接收socket数据的缓冲的指针 CString& strServIP) { int nRes = 1; ASSERT(NULL != buffer); if (NULL == buffer) return 0; // 清空原内存 m_RecieveData.ClearData(); int npBufferIndex = 0; // 接收成功 ULONG uClientOper; HexToULONG(buffer, 2, npBufferIndex, &uClientOper); // 如果不是来自设备端的数据包返回 if (uClientOper != UAP_CLIENT_OPTION) return -1; // 正常接收设备端的数据包 memset(m_szLocalHostIP, NULL, sizeof(m_szLocalHostIP)); GetLocalIPs(m_szLocalHostIP, sizeof(m_szLocalHostIP)); int len = strlen(m_szLocalHostIP); if (!IsHexDigit(m_szLocalHostIP[len-1])) m_szLocalHostIP[len-1] = 0; char szIPEnd[2]= {13, 0}; len = strcspn(m_szLocalHostIP, szIPEnd); m_szLocalHostIP[len] = 0; // 客户端IP char szIP[20]; HexToChar(buffer, 4 , npBufferIndex , szIP); Ip2String(szIP, szIP); if (strcmp(m_szLocalHostIP, szIP) != 0) return -1; // UDP 端口号 ULONG uPort; HexToULONG(buffer, 2 , npBufferIndex , &uPort); // 服务(设备)端类型 ULONG Distype; HexToULONG(buffer, 2 , npBufferIndex , &Distype); // 服务(设备)端MAC地址 int iMACAddrTemp[6]; for (int j=0; j<6; j++) { HexToint(buffer, 1 , npBufferIndex , &iMACAddrTemp[j]); } char chrMacAddrTemp[18]; memset(chrMacAddrTemp, 0 , sizeof(chrMacAddrTemp)); _stprintf(chrMacAddrTemp,"%02X:%02X:%02X:%02X:%02X:%02X", iMACAddrTemp[0], iMACAddrTemp[1], iMACAddrTemp[2], iMACAddrTemp[3], iMACAddrTemp[4], iMACAddrTemp[5]); CString strMACAddress = chrMacAddrTemp; for (int j=0; j<6; j++) m_RecieveData.m_arrMacAddr[j] = iMACAddrTemp[j]; // 序列号 ULONG uFlagRequest; HexToULONG(buffer, 2 , npBufferIndex , &uFlagRequest); // 设备类型 ULONG uIPConfig; HexToULONG(buffer, 2 , npBufferIndex , &uIPConfig); // Flag ULONG uType; HexToULONG(buffer, 1 , npBufferIndex , &uType); // 设备类别 ULONG uUCPClass; HexToULONG(buffer, 4 , npBufferIndex , &uUCPClass); m_RecieveData.m_strServIP = strServIP; // method ULONG uMethod; HexToULONG(buffer, 2 , npBufferIndex , &uMethod); m_RecieveData.m_SendData.m_uMethod = uMethod; switch(uMethod) { case UCP_METHOD_DISCOVER: { // 读取设备的名称,类型和固件版本 for (int n = 0; n < 4; n++) { // 读取长度 ULONG Flag; HexToULONG(buffer, 1 , npBufferIndex , &Flag); // 读取长度 int StrLen = (int)buffer[npBufferIndex++]; char szDeviceTemp[100] = {'\0'}; switch(Flag) { case UCP_CODE_DEVICE_NAME: HexToChar(buffer, StrLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_DiscoverData.m_strDeviceName = szDeviceTemp; break; case UCP_CODE_DEVICE_TYPE: HexToChar(buffer, StrLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_DiscoverData.m_strDeviceType = szDeviceTemp; break; case UCP_CODE_SOFTWARE_VER: HexToChar(buffer, StrLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_DiscoverData.m_strFirmware = szDeviceTemp; break; case UCP_CODE_HTTP_TYPE: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_DiscoverData.m_nHttpType); break; } } // 根据MAC地址查找是否该设备已经存在 int i=0; for(; i<m_arrDevice.size(); i++) { LCT_DEVICE* pDevice = m_arrDevice[i]; if (strcmp((LPCTSTR)pDevice->m_strMACAddr, chrMacAddrTemp) == 0) break; } // 不存在则说明探测到新设备 if (i == m_arrDevice.size()) { // 添加到内存 LCT_DEVICE* pDevice = new LCT_DEVICE; ASSERT(NULL != pDevice); m_arrDevice.push_back(pDevice); pDevice->m_strName = m_RecieveData.m_SendData.m_DiscoverData.m_strDeviceName; pDevice->m_strType = m_RecieveData.m_SendData.m_DiscoverData.m_strDeviceType; pDevice->m_strFirmwareVer = m_RecieveData.m_SendData.m_DiscoverData.m_strFirmware; pDevice->m_nHTTPSEnable = m_RecieveData.m_SendData.m_DiscoverData.m_nHttpType; pDevice->m_strMACAddr = chrMacAddrTemp; pDevice->m_strIPAddr = m_RecieveData.m_strServIP; for (int j=0; j<6; ++j) pDevice->m_arrMac[j] = iMACAddrTemp[j]; } break; } case UCP_METHOD_GET_INFO: case UCP_METHOD_GET_IP: { // 读取标志 char Flag; for( HexToChar(buffer, 1 , npBufferIndex , &Flag); Flag != (char)UCP_CODE_END; HexToChar(buffer, 1 , npBufferIndex , &Flag) ) { // 读取长度 char GetLen; HexToChar(buffer, 1 , npBufferIndex , &GetLen); // 根据长度读取内容 char szDeviceTemp[100] = {'\0'}; // 读取字符的缓冲区 BOOL ErrorBreak = FALSE; // 错误标志 switch (Flag) { case UCP_CODE_BRIDGE: HexToint(buffer, GetLen , npBufferIndex , &m_RecieveData.bridge); break; case UCP_CODE_DEVICE_NAME: HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_DiscoverData.m_strDeviceName = szDeviceTemp; m_RecieveData.m_SendData.m_GetinfoData.m_strDeviceName = szDeviceTemp; break; case UCP_CODE_DEVICE_TYPE: HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_DiscoverData.m_strDeviceType = szDeviceTemp; break; case UCP_CODE_SOFTWARE_VER: HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_DiscoverData.m_strFirmware = szDeviceTemp; m_RecieveData.m_SendData.m_GetinfoData.m_strFirmware = szDeviceTemp; break; case UCP_CODE_USE_DHCP: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_nDHCP); break; case UCP_CODE_GATEWAY_ADDR: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrGateway[0]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrGateway[1]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrGateway[2]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrGateway[3]); break; case UCP_CODE_SUBNET_MASK: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrSubmask[0]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrSubmask[1]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrSubmask[2]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrSubmask[3]); break; case UCP_CODE_IP_ADDR: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrIPAddr[0]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrIPAddr[1]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrIPAddr[2]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_arrIPAddr[3]); break; case UCP_CODE_SSID: HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_GetinfoData.m_strSSID = szDeviceTemp; break; case UCP_CODE_CHANNEL: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_nChannel); break; case UCP_CODE_OPMODE: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_nOper); break; case UCP_CODE_WIRELESS_MODE: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_nWirelessMode); break; case UCP_CODE_SEC_METHOD: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_nSecurity); break; case UCP_CODE_WLAN_MACADDR: HexToChar(buffer, GetLen , npBufferIndex , m_RecieveData.m_SendData.m_GetinfoData.m_szcharWlanMACAddress); break; case UCP_CODE_ENCRYPT_ONOFF: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_nEncryptionOnOff); break; case UCP_CODE_SUPER_G: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_nSuperG); break; case UCP_CODE_ASSOCIATED: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_associated); break; case UCP_CODE_BSSID: HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_GetinfoData.m_Bssid = szDeviceTemp; break; case UCP_CODE_RSSI: HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_GetinfoData.m_Rssi = szDeviceTemp; break; case UCP_CODE_5GWIRELESS_MODE: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_n5GWirelessMode); break; case UCP_CODE_5GWLAN_MACADDR: HexToChar(buffer, GetLen , npBufferIndex , m_RecieveData.m_SendData.m_GetinfoData.m_szchar5GWlanMACAddress); break; case UCP_CODE_5GSSID: HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_GetinfoData.m_str5GSSID = szDeviceTemp; break; case UCP_CODE_5GRSSI: HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_GetinfoData.m_5GRssi = szDeviceTemp; break; case UCP_CODE_5GBSSID: HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_GetinfoData.m_5GBssid = szDeviceTemp; break; case UCP_CODE_5GASSOCIATED: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_5Gassociated); break; case UCP_CODE_5GCHANNEL: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_n5GChannel); break; case UCP_CODE_5GSEC_METHOD: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_n5GSecurity); break; case UCP_CODE_5GENCRYPT_ONOFF: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_n5GEncryptionOnOff); break; case UCP_CODE_2GRADIO_ONOFF: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_nRadioOnOff); break; case UCP_CODE_5GRADIO_ONOFF: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_n5GRadioOnOff); break; case UCP_CODE_WLAN_OPMODE: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_nWlanOpmode); break; case UCP_CODE_5GWLAN_OPMODE: HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_GetinfoData.m_n5GWlanOpmode); break; default: // 其他的跳过 HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); //ErrorBreak = TRUE; break; } // 读取到位置类型的标志发生错误则推出循环 if (ErrorBreak) { nRes = -3; break; } } break; } case UCP_METHOD_GET_HOST:{ char Flag; for( HexToChar(buffer, 1 , npBufferIndex , &Flag); Flag != (char)UCP_CODE_END; HexToChar(buffer, 1 , npBufferIndex , &Flag) ) { // 读取长度 char GetLen; HexToChar(buffer, 1 , npBufferIndex , &GetLen); // 根据长度读取内容 char szDeviceTemp[100] = {'\0'}; // 读取字符的缓冲区 int szIPTemp[4] = {'\0'}; switch(Flag) { case UCP_CODE_HOST_NAME:{ HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_HostData.m_hostName = szDeviceTemp; break; } case UCP_CODE_IP_ADDR:{ HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_HostData.m_IPAddr[0]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_HostData.m_IPAddr[1]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_HostData.m_IPAddr[2]); HexToint(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_HostData.m_IPAddr[3]); break; } case UCP_CODE_DOMAIN_NAME:{ HexToChar(buffer, GetLen , npBufferIndex , szDeviceTemp); m_RecieveData.m_SendData.m_HostData.m_domainName = szDeviceTemp; break; } default:{ break; } } } break; } case UCP_METHOD_SET_HOST:{ ULONG ip_set_result; HexToULONG(buffer, 1 , npBufferIndex , &ip_set_result); m_RecieveData.m_SendData.ip_set_result = ip_set_result; break; } case UCP_METHOD_SET_IP:{ ULONG ip_set_result; HexToULONG(buffer, 1 , npBufferIndex , &ip_set_result); m_RecieveData.m_SendData.ip_set_result = ip_set_result; break; } case UCP_METHOD_AUTH: HexToULONG(buffer, 1 , npBufferIndex , &m_RecieveData.m_SendData.m_AuthData.m_uAuto); if (m_RecieveData.m_SendData.m_AuthData.m_uAuto == 1) { //AfxMessageBox( "User Name or Password Fail!" ); nRes = -4; } else { HexToULONG(buffer, 2 , npBufferIndex , &m_RecieveData.m_SendData.m_AuthData.m_uRequestMethod); } break; default: //ASSERT(FALSE); break; } // 更新设备信息 UpdateDeviceInfoFromRcv(); return nRes; }
void nsCSSScanner::ParseAndAppendEscape(nsresult& aErrorCode, nsString& aOutput) { PRInt32 ch = Peek(aErrorCode); if (ch < 0) { aOutput.Append(CSS_ESCAPE); return; } if (IsHexDigit(ch)) { PRInt32 rv = 0; int i; for (i = 0; i < 6; i++) { // up to six digits ch = Read(aErrorCode); if (ch < 0) { // Whoops: error or premature eof break; } if (!IsHexDigit(ch) && !IsWhitespace(ch)) { Pushback(ch); break; } else if (IsHexDigit(ch)) { if (IsDigit(ch)) { rv = rv * 16 + (ch - '0'); } else { // Note: c&7 just keeps the low three bits which causes // upper and lower case alphabetics to both yield their // "relative to 10" value for computing the hex value. rv = rv * 16 + ((ch & 0x7) + 9); } } else { NS_ASSERTION(IsWhitespace(ch), "bad control flow"); // single space ends escape break; } } if (6 == i) { // look for trailing whitespace and eat it ch = Peek(aErrorCode); if (IsWhitespace(ch)) { (void) Read(aErrorCode); } } NS_ASSERTION(rv >= 0, "How did rv become negative?"); // "[at most six hexadecimal digits following a backslash] stand // for the ISO 10646 character with that number, which must not be // zero. (It is undefined in CSS 2.1 what happens if a style sheet // does contain a character with Unicode codepoint zero.)" // -- CSS2.1 section 4.1.3 // // Silently deleting \0 opens a content-filtration loophole (see // bug 228856), so what we do instead is pretend the "cancels the // meaning of special characters" rule applied. if (rv > 0) { AppendUCS4ToUTF16(ENSURE_VALID_CHAR(rv), aOutput); } else { while (i--) aOutput.Append('0'); if (IsWhitespace(ch)) Pushback(ch); } return; } else { // "Any character except a hexidecimal digit can be escaped to // remove its special meaning by putting a backslash in front" // -- CSS1 spec section 7.1 if (!EatNewline(aErrorCode)) { // skip escaped newline (void) Read(aErrorCode); if (ch > 0) { aOutput.Append(ch); } } return; } }
PRBool nsCSSScanner::ParseURange(PRInt32 aChar, nsCSSToken& aResult) { PRInt32 intro2 = Read(); PRInt32 ch = Peek(); // We should only ever be called if these things are true. NS_ASSERTION(aChar == 'u' || aChar == 'U', "unicode-range called with improper introducer (U)"); NS_ASSERTION(intro2 == '+', "unicode-range called with improper introducer (+)"); // If the character immediately after the '+' is not a hex digit or // '?', this is not really a unicode-range token; push everything // back and scan the U as an ident. if (!IsHexDigit(ch) && ch != '?') { Pushback(intro2); Pushback(aChar); return ParseIdent(aChar, aResult); } aResult.mIdent.Truncate(); aResult.mIdent.Append(aChar); aResult.mIdent.Append(intro2); PRBool valid = PR_TRUE; PRBool haveQues = PR_FALSE; PRUint32 low = 0; PRUint32 high = 0; int i = 0; for (;;) { ch = Read(); i++; if (i == 7 || !(IsHexDigit(ch) || ch == '?')) { break; } aResult.mIdent.Append(ch); if (IsHexDigit(ch)) { if (haveQues) { valid = PR_FALSE; // all question marks should be at the end } low = low*16 + HexDigitValue(ch); high = high*16 + HexDigitValue(ch); } else { haveQues = PR_TRUE; low = low*16 + 0x0; high = high*16 + 0xF; } } if (ch == '-' && IsHexDigit(Peek())) { if (haveQues) { valid = PR_FALSE; } aResult.mIdent.Append(ch); high = 0; i = 0; for (;;) { ch = Read(); i++; if (i == 7 || !IsHexDigit(ch)) { break; } aResult.mIdent.Append(ch); high = high*16 + HexDigitValue(ch); } } Pushback(ch); aResult.mInteger = low; aResult.mInteger2 = high; aResult.mIntegerValid = valid; aResult.mType = eCSSToken_URange; return PR_TRUE; }
void nsCSSScanner::ParseAndAppendEscape(nsString& aOutput) { PRInt32 ch = Peek(); if (ch < 0) { aOutput.Append(CSS_ESCAPE); return; } if (IsHexDigit(ch)) { PRInt32 rv = 0; int i; for (i = 0; i < 6; i++) { // up to six digits ch = Read(); if (ch < 0) { // Whoops: error or premature eof break; } if (!IsHexDigit(ch) && !IsWhitespace(ch)) { Pushback(ch); break; } else if (IsHexDigit(ch)) { rv = rv * 16 + HexDigitValue(ch); } else { NS_ASSERTION(IsWhitespace(ch), "bad control flow"); // single space ends escape break; } } if (6 == i) { // look for trailing whitespace and eat it ch = Peek(); if (IsWhitespace(ch)) { (void) Read(); } } NS_ASSERTION(rv >= 0, "How did rv become negative?"); // "[at most six hexadecimal digits following a backslash] stand // for the ISO 10646 character with that number, which must not be // zero. (It is undefined in CSS 2.1 what happens if a style sheet // does contain a character with Unicode codepoint zero.)" // -- CSS2.1 section 4.1.3 // // Silently deleting \0 opens a content-filtration loophole (see // bug 228856), so what we do instead is pretend the "cancels the // meaning of special characters" rule applied. if (rv > 0) { AppendUCS4ToUTF16(ENSURE_VALID_CHAR(rv), aOutput); } else { while (i--) aOutput.Append('0'); if (IsWhitespace(ch)) Pushback(ch); } return; } // "Any character except a hexidecimal digit can be escaped to // remove its special meaning by putting a backslash in front" // -- CSS1 spec section 7.1 ch = Read(); // Consume the escaped character if ((ch > 0) && (ch != '\n')) { aOutput.Append(ch); } }
/** * Scan a unicode-range token. These match the regular expression * * u\+[0-9a-f?]{1,6}(-[0-9a-f]{1,6})? * * However, some such tokens are "invalid". There are three valid forms: * * u+[0-9a-f]{x} 1 <= x <= 6 * u+[0-9a-f]{x}\?{y} 1 <= x+y <= 6 * u+[0-9a-f]{x}-[0-9a-f]{y} 1 <= x <= 6, 1 <= y <= 6 * * All unicode-range tokens have their text recorded in mIdent; valid ones * are also decoded into mInteger and mInteger2, and mIntegerValid is set. * Note that this does not validate the numeric range, only the syntactic * form. */ bool nsCSSScanner::ScanURange(nsCSSToken& aResult) { int32_t intro1 = Peek(); int32_t intro2 = Peek(1); int32_t ch = Peek(2); MOZ_ASSERT((intro1 == 'u' || intro1 == 'U') && intro2 == '+' && (IsHexDigit(ch) || ch == '?'), "should not have been called"); aResult.mIdent.Append(intro1); aResult.mIdent.Append(intro2); Advance(2); bool valid = true; bool haveQues = false; uint32_t low = 0; uint32_t high = 0; int i = 0; do { aResult.mIdent.Append(ch); if (IsHexDigit(ch)) { if (haveQues) { valid = false; // All question marks should be at the end. } low = low*16 + HexDigitValue(ch); high = high*16 + HexDigitValue(ch); } else { haveQues = true; low = low*16 + 0x0; high = high*16 + 0xF; } i++; Advance(); ch = Peek(); } while (i < 6 && (IsHexDigit(ch) || ch == '?')); if (ch == '-' && IsHexDigit(Peek(1))) { if (haveQues) { valid = false; } aResult.mIdent.Append(ch); Advance(); ch = Peek(); high = 0; i = 0; do { aResult.mIdent.Append(ch); high = high*16 + HexDigitValue(ch); i++; Advance(); ch = Peek(); } while (i < 6 && IsHexDigit(ch)); } aResult.mInteger = low; aResult.mInteger2 = high; aResult.mIntegerValid = valid; aResult.mType = eCSSToken_URange; return true; }
// Decode a parameter value using the encoding defined in RFC 5987 // // charset "'" [ language ] "'" value-chars NS_IMETHODIMP nsMIMEHeaderParamImpl::DecodeRFC5987Param(const nsACString& aParamVal, nsACString& aLang, nsAString& aResult) { nsCAutoString charset; nsCAutoString language; nsCAutoString value; PRUint32 delimiters = 0; const char *encoded = PromiseFlatCString(aParamVal).get(); const char *c = encoded; while (*c) { char tc = *c++; if (tc == '\'') { // single quote delimiters++; } else if (tc >= 128) { // fail early, not ASCII NS_WARNING("non-US-ASCII character in RFC5987-encoded param"); return NS_ERROR_INVALID_ARG; } else { if (delimiters == 0) { // valid characters are checked later implicitly charset.Append(tc); } else if (delimiters == 1) { // no value checking for now language.Append(tc); } else if (delimiters == 2) { if (IsRFC5987AttrChar(tc)) { value.Append(tc); } else if (tc == '%') { if (!IsHexDigit(c[0]) || !IsHexDigit(c[1])) { // we expect two more characters NS_WARNING("broken %-escape in RFC5987-encoded param"); return NS_ERROR_INVALID_ARG; } value.Append(tc); // we consume two more value.Append(*c++); value.Append(*c++); } else { // character not allowed here NS_WARNING("invalid character in RFC5987-encoded param"); return NS_ERROR_INVALID_ARG; } } } } if (delimiters != 2) { NS_WARNING("missing delimiters in RFC5987-encoded param"); return NS_ERROR_INVALID_ARG; } // abort early for unsupported encodings if (!charset.LowerCaseEqualsLiteral("utf-8")) { NS_WARNING("unsupported charset in RFC5987-encoded param"); return NS_ERROR_INVALID_ARG; } // percent-decode if (!PercentDecode(value)) { return NS_ERROR_OUT_OF_MEMORY; } // return the encoding aLang.Assign(language); // finally convert octet sequence to UTF-8 and be done nsresult rv = NS_OK; nsCOMPtr<nsIUTF8ConverterService> cvtUTF8 = do_GetService(NS_UTF8CONVERTERSERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString utf8; rv = cvtUTF8->ConvertStringToUTF8(value, charset.get(), true, false, 1, utf8); NS_ENSURE_SUCCESS(rv, rv); CopyUTF8toUTF16(utf8, aResult); return NS_OK; }
EFI_STATUS GetNumericInput ( IN UI_MENU_SELECTION *Selection, IN UI_MENU_OPTION *MenuOption ) /*++ Routine Description: This routine reads a numeric value from the user input. Arguments: Selection - Pointer to current selection. MenuOption - Pointer to the current input menu. Returns: EFI_SUCCESS - If numerical input is read successfully EFI_DEVICE_ERROR - If operation fails --*/ { EFI_STATUS Status; UINTN Column; UINTN Row; CHAR16 InputText[23]; CHAR16 FormattedNumber[22]; UINT64 PreviousNumber[20]; UINTN Count; UINTN Loop; BOOLEAN ManualInput; BOOLEAN HexInput; BOOLEAN DateOrTime; UINTN InputWidth; UINT64 EditValue; UINT64 Step; UINT64 Minimum; UINT64 Maximum; UINTN EraseLen; UINT8 Digital; EFI_INPUT_KEY Key; EFI_HII_VALUE *QuestionValue; FORM_BROWSER_FORM *Form; FORM_BROWSER_FORMSET *FormSet; FORM_BROWSER_STATEMENT *Question; Column = MenuOption->OptCol; Row = MenuOption->Row; PreviousNumber[0] = 0; Count = 0; InputWidth = 0; Digital = 0; FormSet = Selection->FormSet; Form = Selection->Form; Question = MenuOption->ThisTag; QuestionValue = &Question->HiiValue; Step = Question->Step; Minimum = Question->Minimum; Maximum = Question->Maximum; if ((Question->Operand == EFI_IFR_DATE_OP) || (Question->Operand == EFI_IFR_TIME_OP)) { DateOrTime = TRUE; } else { DateOrTime = FALSE; } // // Prepare Value to be edit // EraseLen = 0; EditValue = 0; if (Question->Operand == EFI_IFR_DATE_OP) { Step = 1; Minimum = 1; switch (MenuOption->Sequence) { case 0: Maximum = 12; EraseLen = 4; EditValue = QuestionValue->Value.date.Month; break; case 1: Maximum = 31; EraseLen = 3; EditValue = QuestionValue->Value.date.Day; break; case 2: Maximum = 0xffff; EraseLen = 5; EditValue = QuestionValue->Value.date.Year; break; default: break; } } else if (Question->Operand == EFI_IFR_TIME_OP) { Step = 1; Minimum = 0; switch (MenuOption->Sequence) { case 0: Maximum = 23; EraseLen = 4; EditValue = QuestionValue->Value.time.Hour; break; case 1: Maximum = 59; EraseLen = 3; EditValue = QuestionValue->Value.time.Minute; break; case 2: Maximum = 59; EraseLen = 3; EditValue = QuestionValue->Value.time.Second; break; default: break; } } else { // // Numeric // EraseLen = gOptionBlockWidth; EditValue = QuestionValue->Value.u64; if (Maximum == 0) { Maximum = (UINT64) -1; } } if (Step == 0) { ManualInput = TRUE; } else { ManualInput = FALSE; } if ((Question->Operand == EFI_IFR_NUMERIC_OP) && ((Question->Flags & EFI_IFR_DISPLAY) == EFI_IFR_DISPLAY_UINT_HEX)) { HexInput = TRUE; } else { HexInput = FALSE; } if (ManualInput) { if (HexInput) { InputWidth = Question->StorageWidth * 2; } else { switch (Question->StorageWidth) { case 1: InputWidth = 3; break; case 2: InputWidth = 5; break; case 4: InputWidth = 10; break; case 8: InputWidth = 20; break; default: InputWidth = 0; break; } } InputText[0] = LEFT_NUMERIC_DELIMITER; SetUnicodeMem (InputText + 1, InputWidth, L' '); InputText[InputWidth + 1] = RIGHT_NUMERIC_DELIMITER; InputText[InputWidth + 2] = L'\0'; PrintAt (Column, Row, InputText); Column++; } // // First time we enter this handler, we need to check to see if // we were passed an increment or decrement directive // do { Key.UnicodeChar = CHAR_NULL; if (gDirection != 0) { Key.ScanCode = gDirection; gDirection = 0; goto TheKey2; } Status = WaitForKeyStroke (&Key); TheKey2: switch (Key.UnicodeChar) { case '+': case '-': if (Key.UnicodeChar == '+') { Key.ScanCode = SCAN_RIGHT; } else { Key.ScanCode = SCAN_LEFT; } Key.UnicodeChar = CHAR_NULL; goto TheKey2; case CHAR_NULL: switch (Key.ScanCode) { case SCAN_LEFT: case SCAN_RIGHT: if (DateOrTime) { // // By setting this value, we will return back to the caller. // We need to do this since an auto-refresh will destroy the adjustment // based on what the real-time-clock is showing. So we always commit // upon changing the value. // gDirection = SCAN_DOWN; } if (!ManualInput) { if (Key.ScanCode == SCAN_LEFT) { if (EditValue > Step) { EditValue = EditValue - Step; } else { EditValue = Minimum; } } else if (Key.ScanCode == SCAN_RIGHT) { EditValue = EditValue + Step; if (EditValue > Maximum) { EditValue = Maximum; } } EfiZeroMem (FormattedNumber, 21 * sizeof (CHAR16)); if (Question->Operand == EFI_IFR_DATE_OP) { if (MenuOption->Sequence == 2) { // // Year // SPrint (FormattedNumber, 21 * sizeof (CHAR16), L"%04d", (UINTN) EditValue); } else { // // Month/Day // SPrint (FormattedNumber, 21 * sizeof (CHAR16), L"%02d", (UINTN) EditValue); } if (MenuOption->Sequence == 0) { FormattedNumber[EraseLen - 2] = DATE_SEPARATOR; } else if (MenuOption->Sequence == 1) { FormattedNumber[EraseLen - 1] = DATE_SEPARATOR; } } else if (Question->Operand == EFI_IFR_TIME_OP) { SPrint (FormattedNumber, 21 * sizeof (CHAR16), L"%02d", (UINTN) EditValue); if (MenuOption->Sequence == 0) { FormattedNumber[EraseLen - 2] = TIME_SEPARATOR; } else if (MenuOption->Sequence == 1) { FormattedNumber[EraseLen - 1] = TIME_SEPARATOR; } } else { QuestionValue->Value.u64 = EditValue; PrintFormattedNumber (Question, FormattedNumber, 21 * sizeof (CHAR16)); } gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND); for (Loop = 0; Loop < EraseLen; Loop++) { PrintAt (MenuOption->OptCol + Loop, MenuOption->Row, L" "); } gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT); if (MenuOption->Sequence == 0) { PrintCharAt (MenuOption->OptCol, Row, LEFT_NUMERIC_DELIMITER); Column = MenuOption->OptCol + 1; } PrintStringAt (Column, Row, FormattedNumber); if (!DateOrTime || MenuOption->Sequence == 2) { PrintChar (RIGHT_NUMERIC_DELIMITER); } goto EnterCarriageReturn; } break; case SCAN_UP: case SCAN_DOWN: goto EnterCarriageReturn; case SCAN_ESC: return EFI_DEVICE_ERROR; default: break; } break; EnterCarriageReturn: case CHAR_CARRIAGE_RETURN: // // Store Edit value back to Question // if (Question->Operand == EFI_IFR_DATE_OP) { switch (MenuOption->Sequence) { case 0: QuestionValue->Value.date.Month = (UINT8) EditValue; break; case 1: QuestionValue->Value.date.Day = (UINT8) EditValue; break; case 2: QuestionValue->Value.date.Year = (UINT16) EditValue; break; default: break; } } else if (Question->Operand == EFI_IFR_TIME_OP) { switch (MenuOption->Sequence) { case 0: QuestionValue->Value.time.Hour = (UINT8) EditValue; break; case 1: QuestionValue->Value.time.Minute = (UINT8) EditValue; break; case 2: QuestionValue->Value.time.Second = (UINT8) EditValue; break; default: break; } } else { // // Numeric // QuestionValue->Value.u64 = EditValue; } // // Check to see if the Value is something reasonable against consistency limitations. // If not, let's kick the error specified. // Status = ValidateQuestion (FormSet, Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF); if (EFI_ERROR (Status)) { // // Input value is not valid, restore Question Value // GetQuestionValue (FormSet, Form, Question, TRUE); } else { SetQuestionValue (FormSet, Form, Question, TRUE); if (!DateOrTime || (Question->Storage != NULL)) { // // NV flag is unnecessary for RTC type of Date/Time // UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE); } } return Status; break; case CHAR_BACKSPACE: if (ManualInput) { if (Count == 0) { break; } // // Remove a character // EditValue = PreviousNumber[Count - 1]; UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, FALSE); Count--; Column--; PrintAt (Column, Row, L" "); } break; default: if (ManualInput) { if (HexInput) { if (!IsHexDigit (&Digital, Key.UnicodeChar)) { UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, TRUE); break; } } else { if (Key.UnicodeChar > L'9' || Key.UnicodeChar < L'0') { UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, TRUE); break; } } // // If Count exceed input width, there is no way more is valid // if (Count >= InputWidth) { break; } // // Someone typed something valid! // if (Count != 0) { if (HexInput) { EditValue = LShiftU64 (EditValue, 4) + Digital; } else { // // EditValue = EditValue * 10 + (Key.UnicodeChar - L'0'); // EditValue = LShiftU64 (EditValue, 3) + LShiftU64 (EditValue, 1) + (Key.UnicodeChar - L'0'); } } else { if (HexInput) { EditValue = Digital; } else { EditValue = Key.UnicodeChar - L'0'; } } if (EditValue > Maximum) { UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, TRUE); EditValue = PreviousNumber[Count]; break; } else { UpdateStatusBar (INPUT_ERROR, Question->QuestionFlags, FALSE); } Count++; PreviousNumber[Count] = EditValue; PrintCharAt (Column, Row, Key.UnicodeChar); Column++; } break; } } while (TRUE); return EFI_SUCCESS; }
WCHAR CLexer::ScanUnicodeEscape (PCWSTR &p, __out PWCH pchSurrogate, BOOL fPeek) { ASSERT(pchSurrogate); *pchSurrogate = 0; PCWSTR pszStart = p - 1; // Back-up to the '\' ASSERT(*pszStart == '\\'); WCHAR ch = *p++; if (ch == 'U') { unsigned int uChar = 0; if (!IsHexDigit (*p)) { if (!fPeek) ErrorAtPosition (m_iCurLine, (long)(pszStart - m_pszCurLine), (long)(p - pszStart), ERR_IllegalEscape); } else { for (int i=0; i<8; i++) { if (!IsHexDigit (*p)) { if (!fPeek) ErrorAtPosition (m_iCurLine, (long)(pszStart - m_pszCurLine), (long)(p - pszStart), ERR_IllegalEscape); break; } uChar = (uChar << 4) + HexValue (*p++); } if (uChar < 0x00010000) { ch = (WCHAR)uChar; *pchSurrogate = L'\0'; } else if (uChar > 0x0010FFFF) { if (!fPeek) ErrorAtPosition (m_iCurLine, (long)(pszStart - m_pszCurLine), (long)(p - pszStart), ERR_IllegalEscape); } else { ASSERT(uChar > 0x0000FFFF && uChar <= 0x0010FFFF); ch = (WCHAR)((uChar - 0x00010000) / 0x0400 + 0xD800); *pchSurrogate = (WCHAR)((uChar - 0x00010000) % 0x0400 + 0xDC00); } } } else { ASSERT(ch == L'u' || ch == L'x'); int iChar = 0; if (!IsHexDigit (*p)) { if (!fPeek) ErrorAtPosition (m_iCurLine, (long)(pszStart - m_pszCurLine), (long)(p - pszStart), ERR_IllegalEscape); } else { for (int i=0; i<4; i++) { if (!IsHexDigit (*p)) { if (ch == 'u' && !fPeek) ErrorAtPosition (m_iCurLine, (long)(pszStart - m_pszCurLine), (long)(p - pszStart), ERR_IllegalEscape); break; } iChar = (iChar << 4) + HexValue (*p++); } ch = (WCHAR)iChar; } } return ch; }
/* 处理转移字符 */ static int ScanEscapeChar (int wide) { int i, v, overflow; /* 跳过转移字符的 \ */ CURRENT++; switch (*CURRENT++) { /* 返回转义后的ASCII 值 */ case 'a': return '\a'; case 'b': return '\b'; case 'f': return '\f'; case 'n': return '\n'; case 'r': return '\r'; case 't': return '\t'; case 'v': return '\v'; /* 返回源字符的ASCII 值即可 */ case '\'': case '"': case '\\': case '\?': return *(CURRENT-1); case 'x': /* x之后若不是十六进制的数字则错误 */ if (!IsHexDigit (*CURRENT)) { Error (&TokenCoord, "Expect hex digit"); return 'x'; } /* 如果非宽字符 * 且从0开始可处理3个字符, * 非0开始可处理2个字符 * 如果宽字符 * 且从0开始可处理9个字符, * 非0开始可处理8个字符 */ i = ('0' == *CURRENT ? 0 : 1) + (wide ? 0 : 6); for (v = 0; i < 9 && IsHexDigit (*CURRENT); CURRENT++, i++) { v = (v << 4) + (IsDigit (*CURRENT) ? (*CURRENT-'0') : (ToUpper (*CURRENT) - 'A' + 10)); } /* 如果i不到9则字符中间有非法字符 */ if (9 != i) Warning (&TokenCoord, "Hexademical espace sequence overflo"); return v; /* 处理八进制 */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': /* 如果非宽字符 * 且从0开始可处理三个字符, * 非0开始可处理两个字符 * 若是宽字符可处理三个字符 */ v = *(CURRENT - 1) - '0'; //i = wide ? for (i = v ? 1 : 0; i < 2 && IsOctDigit (*CURRENT); i++) v = (v << 3) + *CURRENT++ - '0'; return v; default: Warning (&TokenCoord, "Unrecognized escape sequence: \\%c", *CURRENT); return *CURRENT; } }
/** * If there is a valid escape sequence starting at the current read * position, consume it, decode it, append the result to |aOutput|, * and return true. Otherwise, consume nothing, leave |aOutput| * unmodified, and return false. If |aInString| is true, accept the * additional form of escape sequence allowed within string-like tokens. */ bool nsCSSScanner::GatherEscape(nsString& aOutput, bool aInString) { MOZ_ASSERT(Peek() == '\\', "should not have been called"); int32_t ch = Peek(1); if (ch < 0) { // If we are in a string (or a url() containing a string), we want to drop // the backslash on the floor. Otherwise, we want to treat it as a U+FFFD // character. Advance(); if (aInString) { SetEOFCharacters(eEOFCharacters_DropBackslash); } else { aOutput.Append(UCS2_REPLACEMENT_CHAR); SetEOFCharacters(eEOFCharacters_ReplacementChar); } return true; } if (IsVertSpace(ch)) { if (aInString) { // In strings (and in url() containing a string), escaped // newlines are completely removed, to allow splitting over // multiple lines. Advance(); AdvanceLine(); return true; } // Outside of strings, backslash followed by a newline is not an escape. return false; } if (!IsHexDigit(ch)) { // "Any character (except a hexadecimal digit, linefeed, carriage // return, or form feed) can be escaped with a backslash to remove // its special meaning." -- CSS2.1 section 4.1.3 Advance(2); if (ch == 0) { aOutput.Append(UCS2_REPLACEMENT_CHAR); } else { aOutput.Append(ch); } return true; } // "[at most six hexadecimal digits following a backslash] stand // for the ISO 10646 character with that number, which must not be // zero. (It is undefined in CSS 2.1 what happens if a style sheet // does contain a character with Unicode codepoint zero.)" // -- CSS2.1 section 4.1.3 // At this point we know we have \ followed by at least one // hexadecimal digit, therefore the escape sequence is valid and we // can go ahead and consume the backslash. Advance(); uint32_t val = 0; int i = 0; do { val = val * 16 + HexDigitValue(ch); i++; Advance(); ch = Peek(); } while (i < 6 && IsHexDigit(ch)); // "Interpret the hex digits as a hexadecimal number. If this number is zero, // or is greater than the maximum allowed codepoint, return U+FFFD // REPLACEMENT CHARACTER" -- CSS Syntax Level 3 if (MOZ_UNLIKELY(val == 0)) { aOutput.Append(UCS2_REPLACEMENT_CHAR); } else { AppendUCS4ToUTF16(ENSURE_VALID_CHAR(val), aOutput); } // Consume exactly one whitespace character after a // hexadecimal escape sequence. if (IsVertSpace(ch)) { AdvanceLine(); } else if (IsHorzSpace(ch)) { Advance(); } return true; }