ExpressionTreeElement* ExpressionParser::BuildValueElement(const wchar_t* input) { if (!input || wcslen(input) == 0) return NULL; ExpressionTreeElement* tmp = new ExpressionTreeElement(); // integer type if (IsNumeric(input)) { tmp->valueType = VT_INTEGER; tmp->value.asLong = ToInt(input); return tmp; } // floating type wchar_t *left = NULL, *right = NULL; left = LeftSide(input, L'.'); right = RightSide(input, L'.'); if (left && right && IsNumeric(left) && IsNumeric(right)) { tmp->valueType = VT_FLOAT; tmp->value.asDouble = atof(ToMultiByteString(input)); return tmp; } // if it doesn't fit our defined integer or float pattern, let's call it string tmp->valueType = VT_STRING; tmp->value.asString = (wchar_t*)input; return tmp; }
JBoolean JVariableList::HaveSameValues ( const JIndex index1, const JIndex index2 ) const { if (IsNumeric(index1) && IsNumeric(index2)) { return kJTrue; } else if (IsDiscrete(index1) && IsDiscrete(index2)) { const JSize valueCount = GetDiscreteValueCount(index1); if (valueCount != GetDiscreteValueCount(index2)) { return kJFalse; } for (JIndex i=1; i<=valueCount; i++) { const JString& value1 = GetDiscreteValueName(index1, i); const JString& value2 = GetDiscreteValueName(index2, i); if (value1 != value2) { return kJFalse; } } return kJTrue; } else { return kJFalse; } }
static void write_insert_line_two(FILE *file, char *field_name, FIELD_TYPE field_type, int field_num) { /* * Adds to the values string for the insert statement. */ static char is_first_line = TRUE; fprintf(file, " if (data->bitfields[%d] == ABP_SET) {\n", field_num); if (is_first_line) { if (IsString(field_type)) fprintf(file, " arb_dbfcmd(dbcon, \"'%%s'\", data->%s);\n", field_name); else if (IsDate(field_type)) fprintf(file, " arb_dbfcmd(dbcon, \"%%t\", &data->%s);\n", field_name); else if (IsNumeric(field_type)) fprintf(file, " arb_dbfcmd(dbcon, \"%%n\", &data->%s);\n", field_name); else fprintf(file, " arb_dbfcmd(dbcon, \"%%d\", data->%s);\n", field_name); } else { if (IsString(field_type)) fprintf(file, " arb_dbfcmd(dbcon, \"%%s'%%s'\", separator, data->%s);\n", field_name); else if (IsDate(field_type)) fprintf(file, " arb_dbfcmd(dbcon, \"%%s%%t\", separator, &data->%s);\n", field_name); else if (IsNumeric(field_type)) fprintf(file, " arb_dbfcmd(dbcon, \"%%s%%n\", separator, &data->%s);\n", field_name); else fprintf(file, " arb_dbfcmd(dbcon, \"%%s%%d\", separator, data->%s);\n", field_name); } fputs(" separator = &comma[0];\n }\n", file); fprintf(file, " else if (IS_NULL(data->bitfields[%d])) {\n", field_num); if (is_first_line) { fprintf(file, " arb_dbcmd(dbcon, \"NULL\");\n"); is_first_line = FALSE; } else fprintf(file, " arb_dbfcmd(dbcon, \"%%sNULL\", separator);\n"); fputs(" separator = &comma[0];\n }\n", file); /* * "Defaulted" fields -- if not set, use current date. */ if (take_field_from_list(field_name, &defaults)) { fputs(" else {\n", file); fputs(" arb_dbfcmd(dbcon, \"%s%s\", separator, arb_server_getdate());\n", file); fputs(" separator = &comma[0];\n }\n", file); } }
bool isGoodDecomp(wchar32 rune, wchar32 decomp){ if ( (NUnicode::NPrivate::CharInfo(rune) == NUnicode::NPrivate::CharInfo(decomp)) || (IsAlpha(rune) && IsAlpha(decomp)) || (IsNumeric(rune) && IsNumeric(decomp)) || (IsQuotation(rune) && IsQuotation(decomp)) ) { return true; } return false; }
void write_dbbind_line(FILE *file, char *field_name, FIELD_TYPE field_type) { char bindstring[64]; switch (field_type) { case CHAR: case BYTE: strcpy(bindstring, "ARB_TYPE_INT8"); break; case BIT: /* ??? */ strcpy(bindstring, "ARB_TYPE_BIT"); break; case SHORT: strcpy(bindstring, "ARB_TYPE_INT16"); break; case INT: strcpy(bindstring, "ARB_TYPE_INT32"); break; case LONG: strcpy(bindstring, "ARB_TYPE_INT32"); /* ?? */ break; case STRING: case LSTRING: case MSTRING: strcpy(bindstring, "ARB_TYPE_STRING"); break; case SMALL_DATETIME: case DATETIME: strcpy(bindstring, "ARB_TYPE_DATELONG"); /* ?????? */ break; case NUMERIC: strcpy(bindstring, "ARB_TYPE_NUMERIC"); break; default: printf("Error: Unknown field type %d. (%d)\n", field_type, __LINE__); break; } if (IsString(field_type)) /* Length: sizeof() or sizeof() - 1? */ fprintf(file, " ++fieldnum;\n arb_dbbind_with_ind(dbcon, fieldnum, %s, sizeof(%s_buf->%s), %s_buf->%s, &(nbbuf[fieldnum - 1]));\n\n", bindstring, /* type */ lc_table_name, field_name, lc_table_name, field_name); else if (IsDate(field_type) || IsNumeric(field_type)) fprintf(file, " ++fieldnum;\n arb_dbbind_with_ind(dbcon, fieldnum, %s, sizeof(%s_buf->%s), &(%s_buf->%s), &(nbbuf[fieldnum - 1]));\n\n", bindstring, /* type */ lc_table_name, field_name, lc_table_name, field_name); else /* Length: 0 or length_of[type] ? Irrelevant. */ fprintf(file, " ++fieldnum;\n arb_dbbind_with_ind(dbcon, fieldnum, %s, 0, &(%s_buf->%s), &(nbbuf[fieldnum - 1]));\n\n", bindstring, lc_table_name, field_name); }
BOOL CEnumerateSerial::QueryRegistryPortName(HKEY hDeviceKey, int& nPort) { //What will be the return value from the method (assume the worst) BOOL bAdded = FALSE; //Read in the name of the port LPTSTR pszPortName = NULL; if (RegQueryValueString(hDeviceKey, _T("PortName"), pszPortName)) { //If it looks like "COMX" then //add it to the array which will be returned size_t nLen = _tcslen(pszPortName); if (nLen > 3) { if ((_tcsnicmp(pszPortName, _T("COM"), 3) == 0) && IsNumeric((pszPortName + 3), FALSE)) { //Work out the port number nPort = _ttoi(pszPortName + 3); bAdded = TRUE; } } LocalFree(pszPortName); } return bAdded; }
bool ScannerA::IsAlphanumeric() { if (IsNumeric() || IsAlphabetic()) { return true; } return false; }
char CEventVariable::GetChar() { if (IsNumeric() == false) return 0; if (!m_pData) return 0; return *((char *)m_pData); }
bool CEventVariable::GetBool() { if (IsNumeric() == false) return 0; if (!m_pData) return 0; return *((bool *)m_pData); }
float CEventVariable::GetFloat() { if (IsNumeric() == false) return 0; if (!m_pData) return 0; return *((float *)m_pData); }
int CEventVariable::GetInteger() { if (IsNumeric() == false) return 0; if (!m_pData) return 0; return *((int *)m_pData); }
pid_t ProcessInfo::GetPIDbyName(const char* cchrptr_ProcessName) const { char chrarry_CommandLinePath[260] ; char chrarry_NameOfProcess[300] ; char* chrptr_StringToCompare = NULL ; pid_t pid_ProcessIdentifier = (pid_t) - 1 ; struct dirent* de_DirEntity = NULL ; DIR* dir_proc = NULL ; dir_proc = opendir("/proc/") ; if (dir_proc == NULL) { perror("Couldn't open the /proc/ directory") ; return (pid_t) - 2 ; } // Loop while not NULL while ((de_DirEntity = readdir(dir_proc))) { #ifndef __HAIKU__ if (de_DirEntity->d_type == DT_DIR) { if (IsNumeric(de_DirEntity->d_name)) { strcpy(chrarry_CommandLinePath, "/proc/") ; strcat(chrarry_CommandLinePath, de_DirEntity->d_name) ; strcat(chrarry_CommandLinePath, "/cmdline") ; FILE* fd_CmdLineFile = fopen(chrarry_CommandLinePath, "rt") ; // open the file for reading text if (fd_CmdLineFile) { int r = fscanf(fd_CmdLineFile, "%20s", chrarry_NameOfProcess) ; // read from /proc/<NR>/cmdline fclose(fd_CmdLineFile); // close the file prior to exiting the routine if (r < 1) { continue; } if (strrchr(chrarry_NameOfProcess, '/')) { chrptr_StringToCompare = strrchr(chrarry_NameOfProcess, '/') + 1 ; } else { chrptr_StringToCompare = chrarry_NameOfProcess ; } //printf("Process name: %s\n", chrarry_NameOfProcess); //printf("Pure Process name: %s\n", chrptr_StringToCompare ); if (!strcmp(chrptr_StringToCompare, cchrptr_ProcessName)) { pid_ProcessIdentifier = (pid_t) atoi(de_DirEntity->d_name) ; closedir(dir_proc) ; return pid_ProcessIdentifier ; } } } } #endif } closedir(dir_proc) ; return pid_ProcessIdentifier ; }
bool wxSimpleHtmlParser::ReadNumber(wxString& str, bool eatIt) { int pos = m_pos; if (!IsNumeric(GetChar(pos))) return FALSE; str += (wxChar) GetChar(pos) ; pos ++; while (!Eof(pos) && IsNumeric(GetChar(pos))) { str += (wxChar) GetChar(pos); pos ++; } if (eatIt) m_pos = pos; return TRUE; }
/** * 通过进程名称获取pid */ pid_t GetPIDbyName_implements(const char *cchrptr_ProcessName, int intCaseSensitiveness, int intExactMatch) { char chrarry_CommandLinePath[100]; char chrarry_NameOfProcess[300]; char *chrptr_StringToCompare = NULL; pid_t pid_ProcessIdentifier = (pid_t) - 1; struct dirent *de_DirEntity = NULL; DIR *dir_proc = NULL; int (*CompareFunction)(const char *, const char *, int); if (intExactMatch) CompareFunction = &strcmp_Wrapper; else CompareFunction = &strstr_Wrapper; dir_proc = opendir(PROC_DIRECTORY); if (dir_proc == NULL) { perror("Couldn't open the " PROC_DIRECTORY " directory"); return (pid_t) - 2; } while ((de_DirEntity = readdir(dir_proc))) { if (de_DirEntity->d_type == DT_DIR) { if (IsNumeric(de_DirEntity->d_name)) { strcpy(chrarry_CommandLinePath, PROC_DIRECTORY); strcat(chrarry_CommandLinePath, de_DirEntity->d_name); strcat(chrarry_CommandLinePath, "/cmdline"); FILE *fd_CmdLineFile = fopen(chrarry_CommandLinePath, "rt"); //open the file for reading text if (fd_CmdLineFile) { LOGI("chrarry_NameOfProcess %s", chrarry_NameOfProcess); fscanf(fd_CmdLineFile, "%s", chrarry_NameOfProcess); //read from /proc/<NR>/cmdline fclose(fd_CmdLineFile); //close the file prior to exiting the routine chrptr_StringToCompare = chrarry_NameOfProcess; if (CompareFunction(chrptr_StringToCompare, cchrptr_ProcessName, intCaseSensitiveness)) { pid_ProcessIdentifier = (pid_t) atoi( de_DirEntity->d_name); LOGI("processName=%d, pid=%d", cchrptr_ProcessName, pid_ProcessIdentifier); closedir(dir_proc); return pid_ProcessIdentifier; } } } } } LOGI("processName=%d, pid=%d", cchrptr_ProcessName, pid_ProcessIdentifier); closedir(dir_proc); return pid_ProcessIdentifier; }
BOOL CEnumerateSerial::UsingEnumPorts(CSimpleArray<UINT>& ports) #endif { //Make sure we clear out any elements which may already be in the array #if defined CENUMERATESERIAL_USE_STL ports.clear(); #else ports.RemoveAll(); #endif //Call the first time to determine the size of the buffer to allocate DWORD cbNeeded = 0; DWORD dwPorts = 0; EnumPorts(NULL, 1, NULL, 0, &cbNeeded, &dwPorts); //What will be the return value BOOL bSuccess = FALSE; //Allocate the buffer and recall CAutoHeapAlloc portsBuffer; if (portsBuffer.Allocate(cbNeeded)) { BYTE* pPorts = static_cast<BYTE*>(portsBuffer.m_pData); bSuccess = EnumPorts(NULL, 1, pPorts, cbNeeded, &cbNeeded, &dwPorts); if (bSuccess) { PORT_INFO_1* pPortInfo = reinterpret_cast<PORT_INFO_1*>(pPorts); for (DWORD i=0; i<dwPorts; i++) { //If it looks like "COMX" then //add it to the array which will be returned size_t nLen = _tcslen(pPortInfo->pName); if (nLen > 3) { if ((_tcsnicmp(pPortInfo->pName, _T("COM"), 3) == 0) && IsNumeric(&(pPortInfo->pName[3]), TRUE)) { //Work out the port number int nPort = _ttoi(&(pPortInfo->pName[3])); #if defined CENUMERATESERIAL_USE_STL ports.push_back(nPort); #else ports.Add(nPort); #endif } } pPortInfo++; } } } else SetLastError(ERROR_OUTOFMEMORY); return bSuccess; }
inline MOptionValue GetOptionValue(wxConfigBase *config, const MOption opt) { MOptionValue value; const char *name = GetOptionName(opt); if ( IsNumeric(opt) ) value.Set(config->Read(name, GetNumericDefault(opt))); else value.Set(config->Read(name, GetStringDefault(opt))); return value; }
void ProcessParameter::GetNumericRange( double& minValue, double& maxValue ) const { if ( !IsNumeric() ) { minValue = maxValue = 0; return; } if ( (*API->Process->GetParameterRange)( m_data->handle, &minValue, &maxValue ) == api_false ) throw APIFunctionError( "GetParameterRange" ); }
CompareResult SemanticVersion::Compare(const SemanticVersion& version) const { if (major != version.major) return major < version.major ? kLessThan : kGreaterThan; if (minor != version.minor) return minor < version.minor ? kLessThan : kGreaterThan; if (patch != version.patch) return patch < version.patch ? kLessThan : kGreaterThan; if (prerelease_identifiers != version.prerelease_identifiers) { if (prerelease_identifiers.empty() && !version.prerelease_identifiers.empty()) return kGreaterThan; if (!prerelease_identifiers.empty() && version.prerelease_identifiers.empty()) return kLessThan; std::vector<string_t> identifiers_, identifiers; Split(prerelease_identifiers, L".", identifiers_); Split(version.prerelease_identifiers, L".", identifiers); size_t min_size = min(identifiers_.size(), identifiers.size()); for (size_t i = 0; i < min_size; ++i) { if (IsNumeric(identifiers_.at(i)) && IsNumeric(identifiers.at(i))) { int lhs = ToInt(identifiers_.at(i)); int rhs = ToInt(identifiers.at(i)); if (lhs != rhs) return lhs < rhs ? kLessThan : kGreaterThan; } else { int result = CompareStrings(identifiers_.at(i), identifiers.at(i)); if (result != 0) return result < 0 ? kLessThan : kGreaterThan; } } if (identifiers_.size() != identifiers.size()) return identifiers_.size() < identifiers.size() ? kLessThan : kGreaterThan; } return kEqualTo; }
Double GetRealScalar(pMatrix ppm, int element) { rMatrix pm = ppm[element]; if ((GetM(pm) == 1) && (GetN(pm) == 1) && (IsNumeric(pm)) && (!IsComplex(pm)) ) { return(mxGetScalar(pm)); } else { ErrMsgTxt("Expecting a scalar argument."); } return(0.0); }
void write_setter(FILE *file, char *name, FIELD_TYPE type) { /* * Writing to file, define a slot setter for the datatype defined. */ fprintf(file, "void set_%s_%s(%s *data, %s%svalue)\n{\n", lc_table_name, name, struct_name, c_type[type], (IsString(type) || IsDate(type) || IsNumeric(type)) ? "" : " "); #ifdef _GENERATE_COMMENTS fprintf(file, "\n /* Set value of %s in data */\n", name); #endif if (IsString(type)) fprintf(file, " arb_safe_strncpy(data->%s, value, sizeof(data->%s));\n", name, name); else if (IsDate(type)) fprintf(file, " memcpy(&data->%s, value, sizeof(Arb_date));\n", name); else if (IsNumeric(type)) fprintf(file, " memcpy(&data->%s, value, sizeof(Arb_numeric));\n", name); else fprintf(file, " data->%s = value;\n", name); fprintf(file," *(%s_%s_bits(data)) = ABP_SET;\n}\n\n", lc_table_name, name); }
static vsString ExtractNumberToken( vsString &string ) { vsAssert(IsNumeric(string[0]), "Tried to extract a number from something that isn't a number!"); // okay. We need to find vsString numberString; size_t len = string.length(); size_t index = 0; for ( index = 0; index < len; index++ ) { if ( !IsNumeric(string[index]) ) // this character isn't alphabetic, so isn't part of the label { index--; // back up one character break; // exit the loop } } numberString = string.substr(0, index+1); string.erase(0,index+1); return numberString; }
//-------------------------------------------------------------------------- // main program int _tmain(int argc, _TCHAR* argv[]) { if (argc<2) { PrintUsage(); return 0; } // get the full path of ropguarddll.dll char dllpath[1000]; char *filename; if (!GetModuleFileName(NULL, dllpath, 980)) { printf("Error: could not obtain current executable path\n"); return 0; } filename = strrchr(dllpath,'\\'); if(!filename) { printf("Error: could not obtain current executable path\n"); return 0; } filename++; strcpy(filename, "ropsettings.txt"); ropSettings = new ROPSettings(); ReadROPSettings(dllpath); strcpy(filename, "ropguarddll.dll"); //if the first argument is a number it's considered to be a PID if (IsNumeric(argv[1])) { //protect existing process GuardExistingProcess(atol(argv[1]), dllpath); } else { // create new protected process if (GetROPSettings()->waitEntryPoint) { CreateProcessWithDll(argv[1], dllpath, true); } else { CreateProcessWithDll(argv[1], dllpath, false); } } return 0; }
wxString Letter(const wxString & text) { size_t count = text.Len(); for (size_t i = 0; i < count; i++) { wxChar ch = text[i]; if (IsAlpha(ch)) { wxString res = Upper(ch); if (res == wxChar(0x401)) res = wxChar(0x415); return res; } else if (IsNumeric(ch)) { return wxT('#'); } } return wxT('#'); }
void write_acc_declarations(FILE *file, char *name, FIELD_TYPE type) { /* * Writing to file, declare the accessor and bitfield accessor functions * for a field. */ if (IsString(type) || IsDate(type) || IsNumeric(type)) fprintf(file, "extern void set_%s_%s(%s *data, %svalue);\n", lc_table_name, name, struct_name, c_type[type]); else /* no *, so extra space... */ fprintf(file, "extern void set_%s_%s(%s *data, %s value);\n", lc_table_name, name, struct_name, c_type[type]); fprintf(file, "extern char *%s_%s_bits(%s *data);\n", lc_table_name, name, struct_name); }
void execute() { std::vector<std::string> command(split(input ':')); int countCommand = command.size(); for (int i = 0; i < countCommand; i++) { if (IsNumeric(command[i])) { // command for servo int angle = std::stoi(command[i]); if (angle >= -9 && angle <= 9) executeServo(angle); } } else if (std::all_of(command[i].cbegin(), command[i].cend(), [&s](char ch) {
bool nwxString::IsInteger(const wxString &s, bool bAllowSign) { const wxChar *p = s.wc_str(); bool bFoundDigit = false; if(bAllowSign && IsSign(*p)) { p++; } while(IsNumeric(*p)) { p++; bFoundDigit = true; } bool bRtn = bFoundDigit && (!(*p)); return bRtn; }
bool Size::Parse(const char* s, size_t len, Size& v) { // 1.23px // 1.23ep // 1.23pt // 1.23% // 0 char digits[100]; if (len > 30) { ParseFail("Parse failed, size too big (>30 characters)\n"); return false; } Size x = Size::Pixels(0); size_t nondig = 0; for (; nondig < len; nondig++) { digits[nondig] = s[nondig]; if (!IsNumeric(s[nondig])) break; } digits[nondig] = 0; x.Val = (float) atof(digits); if (nondig == len) { if (len == 1 && s[0] == '0') { // ok } else { ParseFail("Parse failed, invalid size: %.*s\n", (int) len, s); return false; } } else { if (s[nondig] == '%') { x.Type = Size::PERCENT; } else if (s[nondig] == 'p' && len - nondig >= 2) { if (s[nondig + 1] == 'x') x.Type = Size::PX; else if (s[nondig + 1] == 't') x.Type = Size::PT; else { ParseFail("Parse failed, invalid size: %.*s\n", (int) len, s); return false; } } else if (s[nondig] == 'e' && len - nondig >= 2 && s[nondig + 1] == 'p') { x.Type = Size::EP; } } v = x; return true; }
bool Loader::ReadDouble(double *d) { char token[LOADER_INPUT_LENGTH]; int OldPos = ftell(f); ReadToken(token); if (!IsNumeric(token)) { MoveTo(OldPos); return false; } else { *d = atof(token); return true; } }
bool wxSimpleHtmlParser::ParseAttributes(wxSimpleHtmlTag* tag) { // Parse attributes of a tag header until we reach > while (!IsTagEndBracket(GetChar(m_pos)) && !Eof()) { EatWhitespace(); wxString attrName, attrValue; if (IsString()) { ReadString(attrName, TRUE); tag->AppendAttribute(attrName, wxEmptyString); } else if (IsNumeric(GetChar(m_pos))) { ReadNumber(attrName, TRUE); tag->AppendAttribute(attrName, wxEmptyString); } else { // Try to read an attribute name/value pair, or at least a name // without the value ReadLiteral(attrName, TRUE); EatWhitespace(); if (GetChar(m_pos) == wxT('=')) { m_pos ++; EatWhitespace(); if (IsString()) ReadString(attrValue, TRUE); else if (!Eof() && !IsTagEndBracket(GetChar(m_pos))) ReadLiteral(attrValue, TRUE); } if (!attrName.IsEmpty()) tag->AppendAttribute(attrName, attrValue); } } return TRUE; }
float utility::string_utility::ToFloat(const std::string& str) { WARNING_LOG_UTILITY("This function has not been tested yet."); auto result = 0.0f; auto inString = Trim(str); if (!FromString<float>(result, inString, std::dec)) { ERROR_LOG_UTILITY("Failed to convert \"", inString, "\" to floating-point number. Default 0.0f will be returned."); return 0.0f; } // TODO: This for loop could definitely be improved. const auto decimalMark = '.'; auto decimalMarkFound = false; const auto isNegative = inString[0] == '-'; for (unsigned int j = 0; j < inString.length(); ++j) { if (!IsNumeric(inString[j])) { if (j == 0 && isNegative) { continue; } if (inString[j] == decimalMark) { if (decimalMarkFound) { ERROR_LOG_UTILITY("More than one decimal mark \"", decimalMark, "\" found in the string \"", inString, "\". The surplus decimal marks will be ignored."); continue; } decimalMarkFound = true; } else { ERROR_LOG_UTILITY("Failed to convert \"", inString, "\" to integer. The character \"", inString[j], "\" %c is not numeric. Default 0.0f will be returned."); return 0.0f; } } } return result; }