int CCSClones::partition(int left, int right, int pivot) { while (left <= right) { while (getNumericValue(left) < pivot) ++left; while (getNumericValue(right) >= pivot) --right; if (left < right) { swapEntry(left, right); ++left; --right; } } return left; }
/** * Returns the "offset:" value of a PluralFormat argument, or 0 if none is specified. * @param pluralStart the index of the first PluralFormat argument style part. (0..countParts()-1) * @return the "offset:" value. * @draft ICU 4.8 */ double MessagePattern::getPluralOffset(int32_t pluralStart) const { const Part &part=getPart(pluralStart); if(Part::hasNumericValue(part.type)) { return getNumericValue(part); } else { return 0; } }
bool CCSClones::findPivot(int left, int right, int& pivot) { pivot = -1; // left value int a = getNumericValue(left); // middle value int b = getNumericValue(left + (right - left) / 2); // right value int c = getNumericValue(right); // order these 3 values orderNumbers(a, b, c); if (a < b) { pivot = b; return true; } if (b < c) { pivot = c; return true; } int pValue = -1, leftValue = -1; int p = left + 1; while (p <= right) { pValue = getNumericValue(p); leftValue = getNumericValue(left); if (pValue != leftValue) { if (pValue < leftValue) pivot = leftValue; else pivot = pValue; return true; } ++p; } return false; }
int GetValueW(MCONTACT hContact, const char *module, const char *setting, WCHAR *value, int length) { DBVARIANT dbv = { 0 }; if (!module || !setting || !value) return 0; if (length >= 10 && !db_get_s(hContact, module, setting, &dbv, 0)) { switch (dbv.type) { case DBVT_ASCIIZ: mir_wstrncpy(value, ptrW(mir_a2u(dbv.pszVal)), length); break; case DBVT_DWORD: case DBVT_WORD: case DBVT_BYTE: _ultow(getNumericValue(&dbv), value, 10); break; case DBVT_WCHAR: mir_wstrncpy(value, dbv.pwszVal, length); break; case DBVT_UTF8: mir_wstrncpy(value, ptrW(mir_utf8decodeW(dbv.pszVal)), length); break; case DBVT_DELETED: value[0] = 0; return 0; } int type = dbv.type; db_free(&dbv); return type; } value[0] = 0; return 0; }
void __cdecl FindSettings(LPVOID param) { FindInfo* fi = (FindInfo*)param; HWND hwndParent = GetParent(fi->hwnd); ModuleSettingLL ModuleList, SettingList; ModSetLinkLinkItem *module, *setting; MCONTACT hContact; DBVARIANT dbv = { 0 }; int foundCount = 0, replaceCount = 0, deleteCount = 0; DWORD numsearch = 0, numreplace = 0; int NULLContactDone = 0; if (!fi->search || !EnumModules(&ModuleList)) { fi_free(fi); return; } _T2A search(fi->search); _T2A replace(fi->replace); // skip modules and setting names on unicode search or replace if (IsRealUnicode(fi->search) || IsRealUnicode(fi->replace)) { fi->options &= ~(F_SETNAME | F_MODNAME); fi->options |= F_UNICODE; } if (!(fi->options & F_UNICODE) && (fi->options & F_SETVAL)) { char val[16]; numsearch = strtoul(search, NULL, 10); _ultoa(numsearch, val, 10); if (!mir_strcmp(search, val)) { fi->options |= F_NUMSRCH; // replace numeric values only entirely if (replace && (fi->options & F_ENTIRE)) { numreplace = strtoul(replace, NULL, 10); _ultoa(numreplace, val, 10); if (!replace[0] || !mir_strcmp(replace, val)) fi->options |= F_NUMREPL; } } } SendDlgItemMessage(hwndParent, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)TranslateT("Searching...")); hContact = 0; while (GetWindowLongPtr(GetDlgItem(hwndParent, IDC_SEARCH), GWLP_USERDATA)) { if (!hContact) { if (NULLContactDone) break; else { NULLContactDone = 1; hContact = db_find_first(); } } else hContact = db_find_next(hContact); for (module = ModuleList.first; module; module = module->next) { if (IsModuleEmpty(hContact, module->name)) continue; if (fi->options & (F_SETVAL | F_SETNAME)) { if (!EnumSettings(hContact, module->name, &SettingList)) { fi_free(fi); FreeModuleSettingLL(&ModuleList); return; } for (setting = SettingList.first; setting; setting = setting->next) { dbv.type = 0; if (db_get_s(hContact, module->name, setting->name, &dbv, 0)) continue; // check in settings value if (fi->options & F_SETVAL) { TCHAR *value = NULL; switch(dbv.type) { case DBVT_BYTE: case DBVT_WORD: case DBVT_DWORD: if ((fi->options & F_NUMSRCH) && numsearch == getNumericValue(&dbv)) { TCHAR *val = fi->search; int flag = F_SETVAL; if (fi->options & F_NUMREPL) { if (replace[0]) { db_unset(hContact, module->name, setting->name); flag |= F_DELETED; deleteCount++; } else if (setNumericValue(hContact, module->name, setting->name, numreplace, dbv.type)) { val = fi->replace; flag |= F_REPLACED; replaceCount++; } } ItemFound(fi->hwnd, hContact, module->name, setting->name, val, flag); } break; case DBVT_WCHAR: if (!value) value = mir_u2t(dbv.pwszVal); case DBVT_UTF8: if (!value) value = mir_utf8decodeT(dbv.pszVal); case DBVT_ASCIIZ: if (!value) value = mir_a2t(dbv.pszVal); if (FindMatchT(value, fi->search, fi->options)) { foundCount++; ptrT ptr; TCHAR *newValue = value; int flag = F_SETVAL; if (fi->replace) { newValue = (fi->options & F_ENTIRE) ? fi->replace : ptr = multiReplaceT(value, fi->search, fi->replace, fi->options & F_CASE); // !!!! delete or make empty ? if (!newValue[0]) { db_unset(hContact, module->name, setting->name); flag |= F_DELETED; newValue = value; deleteCount++; } else { #ifdef _UNICODE // save as unicode if needed if (dbv.type != DBVT_ASCIIZ || IsRealUnicode(newValue)) db_set_ws(hContact, module->name, setting->name, newValue); else #endif db_set_s(hContact, module->name, setting->name, _T2A(newValue)); flag |= F_REPLACED; replaceCount++; } } ItemFound(fi->hwnd, hContact, module->name, setting->name, newValue, flag); } mir_free(value); break; } // switch } // check in setting name if ((fi->options & F_SETNAME) && FindMatchA(setting->name, search, fi->options)) { foundCount++; ptrA ptr; char *newSetting = setting->name; int flag = F_SETNAME; if (replace) { newSetting = (fi->options & F_ENTIRE) ? replace : ptr = multiReplaceA(setting->name, search, replace, fi->options & F_CASE); if (!newSetting[0]) { db_unset(hContact, module->name, setting->name); flag |= F_DELETED; newSetting = setting->name; deleteCount++; } else { DBVARIANT dbv2; // skip if exist if (!db_get_s(hContact, module->name, newSetting, &dbv2, 0)) db_free(&dbv2); else if (!db_set(hContact, module->name, newSetting, &dbv)) { db_unset(hContact, module->name, setting->name); flag |= F_REPLACED; replaceCount++; } } } ItemFound(fi->hwnd, hContact, module->name, newSetting, NULL, flag); } db_free(&dbv); } // for(setting) FreeModuleSettingLL(&SettingList); } // check in module name if ((fi->options & F_MODNAME) && FindMatchA(module->name, search, fi->options)) { foundCount++; char *newModule = module->name; int flag = F_MODNAME; ptrA ptr; if (replace) { newModule = (fi->options & F_ENTIRE) ? replace : ptr = multiReplaceA(module->name, search, replace, fi->options & F_CASE); if (!newModule[0]) { deleteModule(hContact, module->name, 0); replaceTreeItem(hContact, module->name, NULL); flag |= F_DELETED; newModule = module->name; deleteCount++; } else if (renameModule(hContact, module->name, newModule)) { replaceTreeItem(hContact, module->name, NULL); flag |= F_REPLACED; replaceCount++; } } ItemFound(fi->hwnd, hContact, newModule, 0, 0, flag); } } // for(module) } TCHAR msg[MSG_SIZE]; mir_sntprintf(msg, TranslateT("Finished. Items found: %d / replaced: %d / deleted: %d"), foundCount, replaceCount, deleteCount); SendDlgItemMessage(hwndParent, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)msg); if (fi->replace) { EnableWindow(GetDlgItem(hwndParent, IDC_SEARCH), 1); SetDlgItemText(hwndParent, IDOK, TranslateT("&Replace")); } else { SetDlgItemText(hwndParent, IDC_SEARCH, TranslateT("&Search")); EnableWindow(GetDlgItem(hwndParent, IDOK), 1); } fi_free(fi); FreeModuleSettingLL(&ModuleList); SetWindowLongPtr(GetDlgItem(hwndParent, IDC_SEARCH), GWLP_USERDATA, 0); EnableWindow(GetDlgItem(hwndParent, IDCANCEL), 1); }
int cmd_writemsg( void ) { int rv = 0; int i; static canmsg_t canMsg; char *p = (gbuffer+1); // 'ws' if ( (*p & ~0x20) == 'S' ) { // Standard p++; canMsg.flags = 0; } // 'we' else if ( (*p & ~0x20) == 'E' ) { // Extended Frame p++; canMsg.flags = MSG_EXT; } // 'wr' else if ( (*p & ~0x20) == 'R' ) { // Remote Frame p++; canMsg.flags = MSG_RTR; } // 'w' 'ws' 'we' 'wr'? if ( 0 == *p ) { // Send 'last message' if ( !sja1000_writeMsgToBuf( &canMsg ) ) { rv = -1; // error; } } else { uart0BlockingPutch( '<' ); // NULL length is default canMsg.length = 0; // if there is a number at the current buffer pos // we have an id otherwise there is an error if ( ( *p >= '0' ) && ( *p <= '9' ) ) { uart0BlockingPutch( '-' ); if ( 0xffff == ( canMsg.id = getNumericValue( p ) ) ) { // Error uart0BlockingPutch( '>' ); return -1; } } else { // Syntax error uart0BlockingPutch( ':' ); rv = -1; } uart0BlockingPutch( '?' ); while ( *p && ( *p != ',') && ( *p != ' ') ) { p++; } if ( *p ) { uart0BlockingPutch( '=' ); p++; // move past ',' or space // We have data for ( i=0; i<8; i++ ) { if ( ( *p >= '0' ) && ( *p <= '9' ) ) { canMsg.data[ i ] = getNumericValue( p ); while ( *p && ( *p != ',') && ( *p != ' ') ) { p++; } if ( 0 == *p ) break; p++; } else { // Syntax error break;; } } } // Send message if ( !sja1000_writeMsgToBuf( &canMsg ) ) { rv = -1; // error; } } return rv; }
void doCommand( void ) { int rv = 0; switch( ( *gbuffer & ~0x20 ) ) { // AT<CR> case 0x00: // OK break; // Autobaud detection case 'A': rv = cmd_autobaud(); break; // Set Baudrate case 'B': rv = cmd_baudrate(); break; case 'C': // { char buf[20]; int rr; *buf = 0; rr = getNumericValue( ( gbuffer + 1 ) ); itoa( rr, buf, 10 ); uart0BlockingPutch( ' ' ); uart0BlockingPuts( buf ); } break; case 'D': // Dial - Go online rv = cmd_online(); break; case 'E': // Turn on/off echo rv = cmd_echo(); break; case 'F': // Set Filter/Mask rv = cmd_filter(); break; case 'G': // Send Burst n - number of messages. sz - delay between frames rv = cmd_sendBurst(); break; case 'H': // Hook - Go online rv = cmd_online(); break; case 'I': // Information rv = cmd_info(); break; case 'J': rv = -1; // Not implemented break; case 'K': { canmsg_t msg; msg.id = 0x334; msg.length = 2; msg.data[ 0 ] = 1; msg.data[ 1 ] = 2; msg.flags |= MSG_EXT; //if ( !sja1000_sendMsg( &msg ) ) { //doResponse( FALSE, 0 ); //} if ( !sja1000_writeMsgToBuf( &msg ) ) { rv = -1; // Not implemented; } rv = 0; } break; case 'L': // Go online in Listen only mode rv = cmd_listen(); break; case 'M': rv = -1; // Not implemented break; case 'N': rv = -1; // Not implemented break; case 'O': rv = -1; // Not implemented break; case 'P': rv = -1; // Not implemented break; case 'Q': // Quite rv = cmd_quite(); break; case 'R': // Read message rv = cmd_readmsg(); break; case 'S': // Set/read registers rv = cmd_register(); break; case 'T': rv = -1; // Not implemented break; case 'U': rv = -1; // Not implemented break; case 'V': // Verbal rv = cmd_verbal(); break; case 'W': // Write message rv = cmd_writemsg(); break; case 'X': rv = -1; // Not implemented break; case 'Y': rv = -1; // Not implemented break; case 'Z': // Reset device rv = cmd_reset(); break; case '?': // Get statistics rv = -1; // Not implemented break; default: // Uknown command rv = -1; // Not implemented break; } // Print out response if ( 0 == rv ) { doResponse( TRUE, rv ); } else { doResponse( FALSE, rv ); } }