u32int FSNode::getLengthSC() { u64int* a = (u64int*)Mem::mkXchgSpace(sizeof(u64int)); *a = getLength(); return (u32int)a; }
QString PathResult::getResult() const { return QString("pads = %1, length = %2").arg(size()).arg(getLength()); }
bool LLChatEntry::useLabel() const { return !getLength() && !mLabel.empty(); }
short BigNum::add(Attributes * left, Attributes * right, char * op_data[]) { // Extract signs. char leftSign = BIGN_GET_SIGN(op_data[1], getLength()); char rightSign = BIGN_GET_SIGN(op_data[2], getLength()); // Clear sign bits BIGN_CLR_SIGN(op_data[1], getLength()); BIGN_CLR_SIGN(op_data[2], getLength()); Int32 code; if ((!isUnsigned()) && ((leftSign) || (rightSign))) { // Signed addition. Either left or right is signed. if ((leftSign == 0) && (rightSign)) { code = BigNumHelper::SubHelper(getLength(), op_data[1], op_data[2], op_data[0]); } else if ((leftSign) && (rightSign == 0)) { code = BigNumHelper::SubHelper(getLength(), op_data[2], op_data[1], op_data[0]); } else { // Both left and right are negative numbers BigNumHelper::AddHelper(getLength(), op_data[1], op_data[2], op_data[0]); code = 1; } } else { // Both are positive numbers BigNumHelper::AddHelper(getLength(), op_data[1], op_data[2], op_data[0]); code = 0; } // Reset sign bits if (leftSign) BIGN_SET_SIGN(op_data[1], getLength()); if (rightSign) BIGN_SET_SIGN(op_data[2], getLength()); if (code) { BIGN_SET_SIGN(op_data[0], getLength()); } else { BIGN_CLR_SIGN(op_data[0], getLength()); } return 0; };
short BigNum::div(Attributes * left, Attributes * right, char * op_data[], NAMemory *heap, ComDiagsArea** diagsArea) { // Extract signs. // Extract signs. char leftSign = BIGN_GET_SIGN(op_data[1], ((BigNum*) left)->getLength()); char rightSign = BIGN_GET_SIGN(op_data[2], ((BigNum*) right)->getLength()); // Clear sign bits BIGN_CLR_SIGN(op_data[1], ((BigNum*) left)->getLength()); BIGN_CLR_SIGN(op_data[2], ((BigNum*) right)->getLength()); // Ignore trailing zeros in right. unsigned short * rightDataInShorts = (unsigned short *) op_data[2]; Lng32 rightLengthInShorts = (((BigNum *) right)->getLength())/2; while ((rightDataInShorts[rightLengthInShorts - 1] == 0) && (rightLengthInShorts > 0)) rightLengthInShorts--; if (rightLengthInShorts == 0) { if (heap) ExRaiseSqlError(heap, diagsArea, EXE_DIVISION_BY_ZERO); // Reset sign bits if (leftSign) BIGN_SET_SIGN(op_data[1], ((BigNum*) left)->getLength()); if (rightSign) BIGN_SET_SIGN(op_data[2], ((BigNum*) right)->getLength()); return -1; } if (rightLengthInShorts == 1) { BigNumHelper::SimpleDivHelper(((BigNum *) left)->getLength(), 2, op_data[1], op_data[2], op_data[0]); } else { BigNumHelper::DivHelper(((BigNum *) left)->getLength(), 2*rightLengthInShorts, op_data[1], op_data[2], op_data[0], (char *) tempSpacePtr_); } if (leftSign) BIGN_SET_SIGN(op_data[1], ((BigNum*) left)->getLength()); if (rightSign) BIGN_SET_SIGN(op_data[2], ((BigNum*) right)->getLength()); if (leftSign == rightSign) { BIGN_CLR_SIGN(op_data[0], getLength()); } else { BIGN_SET_SIGN(op_data[0], getLength()); } return 0; }
float Marker::getLengthf() { if (getLength()>0) return getNew(getLength()-1)-getNew(0); else return NULL; }
String substring (int start) const { return substring(start, getLength()); }
//--------------------------------------------------------------------------- long File::seek (long pos, long from) { switch (from) { case SEEK_SET: if (pos > (long)getLength()) { return READ_PAST_EOF_ERR; } break; case SEEK_END: if ((abs(pos) > (long)getLength()) || (pos > 0)) { return READ_PAST_EOF_ERR; } break; case SEEK_CUR: if (pos+logicalPosition > getLength()) { return READ_PAST_EOF_ERR; } break; } if (inRAM && fileImage) { if (parent) { switch (from) { case SEEK_SET: newPosition = pos; break; case SEEK_END: newPosition = getLength()+parentOffset; newPosition += pos; break; case SEEK_CUR: newPosition += pos; break; } } else { switch (from) { case SEEK_SET: newPosition = pos; break; case SEEK_END: newPosition = getLength() + pos; break; case SEEK_CUR: newPosition += pos; break; } } if (newPosition == -1) { return (INVALID_SEEK_ERR); } logicalPosition = newPosition; } else if (fastFile) { newPosition = fastFile->seekFast(fastFileHandle,pos,from); logicalPosition = newPosition; } else { if (parent) { switch (from) { case SEEK_SET: _lseek(handle,pos+parentOffset,SEEK_SET); newPosition = pos; break; case SEEK_END: _lseek(handle,getLength()+parentOffset,SEEK_SET); _lseek(handle,pos,SEEK_CUR); newPosition = getLength() + pos; break; case SEEK_CUR: _lseek(handle,pos,SEEK_CUR); newPosition = logicalPosition + pos; break; } } else { newPosition = _lseek(handle,pos,from); } if (newPosition == -1) { return (INVALID_SEEK_ERR); } logicalPosition = newPosition; } return (NO_ERR); }
bool StyleContext::evalStyle(FunctionID _id, StyleParamKey _key, StyleParam::Value& _val) { _val = none_type{}; JSScope jsScope(*m_jsContext); auto jsValue = jsScope.getFunctionResult(_id); if (!jsValue) { return false; } if (jsValue.isString()) { std::string value = jsValue.toString(); switch (_key) { case StyleParamKey::outline_style: case StyleParamKey::repeat_group: case StyleParamKey::sprite: case StyleParamKey::sprite_default: case StyleParamKey::style: case StyleParamKey::text_align: case StyleParamKey::text_repeat_group: case StyleParamKey::text_source: case StyleParamKey::text_source_left: case StyleParamKey::text_source_right: case StyleParamKey::text_transform: case StyleParamKey::texture: _val = value; break; case StyleParamKey::color: case StyleParamKey::outline_color: case StyleParamKey::text_font_fill: case StyleParamKey::text_font_stroke_color: { Color result; if (StyleParam::parseColor(value, result)) { _val = result.abgr; } else { LOGW("Invalid color value: %s", value.c_str()); } break; } default: _val = StyleParam::parseString(_key, value); break; } } else if (jsValue.isBoolean()) { bool value = jsValue.toBool(); switch (_key) { case StyleParamKey::interactive: case StyleParamKey::text_interactive: case StyleParamKey::visible: _val = value; break; case StyleParamKey::extrude: _val = value ? glm::vec2(NAN, NAN) : glm::vec2(0.0f, 0.0f); break; default: break; } } else if (jsValue.isArray()) { auto len = jsValue.getLength(); switch (_key) { case StyleParamKey::extrude: { if (len != 2) { LOGW("Wrong array size for extrusion: '%d'.", len); break; } double v1 = jsValue.getValueAtIndex(0).toDouble(); double v2 = jsValue.getValueAtIndex(1).toDouble(); _val = glm::vec2(v1, v2); break; } case StyleParamKey::color: case StyleParamKey::outline_color: case StyleParamKey::text_font_fill: case StyleParamKey::text_font_stroke_color: { if (len < 3 || len > 4) { LOGW("Wrong array size for color: '%d'.", len); break; } double r = jsValue.getValueAtIndex(0).toDouble(); double g = jsValue.getValueAtIndex(1).toDouble(); double b = jsValue.getValueAtIndex(2).toDouble(); double a = 1.0; if (len == 4) { a = jsValue.getValueAtIndex(3).toDouble(); } _val = ColorF(r, g, b, a).toColor().abgr; break; } default: break; } } else if (jsValue.isNumber()) { double number = jsValue.toDouble(); if (std::isnan(number)) { LOGD("duk evaluates JS method to NAN.\n"); } switch (_key) { case StyleParamKey::text_source: case StyleParamKey::text_source_left: case StyleParamKey::text_source_right: _val = doubleToString(number); break; case StyleParamKey::extrude: _val = glm::vec2(0.f, number); break; case StyleParamKey::placement_spacing: { _val = StyleParam::Width{static_cast<float>(number), Unit::pixel}; break; } case StyleParamKey::width: case StyleParamKey::outline_width: { // TODO more efficient way to return pixels. // atm this only works by return value as string _val = StyleParam::Width{static_cast<float>(number)}; break; } case StyleParamKey::angle: case StyleParamKey::priority: case StyleParamKey::text_priority: case StyleParamKey::text_font_stroke_width: case StyleParamKey::placement_min_length_ratio: { _val = static_cast<float>(number); break; } case StyleParamKey::size: { StyleParam::SizeValue vec; vec.x.value = static_cast<float>(number); _val = vec; break; } case StyleParamKey::order: case StyleParamKey::outline_order: case StyleParamKey::color: case StyleParamKey::outline_color: case StyleParamKey::text_font_fill: case StyleParamKey::text_font_stroke_color: { _val = static_cast<uint32_t>(number); break; } default: break; } } else if (jsValue.isUndefined()) { // Explicitly set value as 'undefined'. This is important for some styling rules. _val = Undefined(); } else { LOGW("Unhandled return type from Javascript style function for %d.", _key); } return !_val.is<none_type>(); }
//--------------------------------------------------------------------------- bool File::eof (void) { return (logicalPosition >= getLength()); }
//--------------------------------------------------------------------------- long File::open (const char* fName, FileMode _mode, long numChild) { gosASSERT( !isOpen() ); //------------------------------------------------------------- long fNameLength = strlen(fName); fileName = (char *)systemHeap->Malloc(fNameLength+1); gosASSERT(fileName != NULL); strncpy(fileName,fName,fNameLength+1); fileMode = _mode; _fmode = _O_BINARY; _strlwr(fileName); if (fileMode == CREATE) { handle = _creat(fileName,_S_IWRITE); if (handle == INVALID_HANDLE_VALUE) { lastError = errno; return lastError; } } else { //---------------------------------------------------------------- //-- First, see if file is in normal place. Useful for patches!! handle = _open(fileName,_O_RDONLY); //------------------------------------------ //-- Next, see if file is in fastFile. if (handle == INVALID_HANDLE_VALUE) { lastError = errno; fastFile = FastFileFind(fileName,fastFileHandle); if (!fastFile) { //Not in main installed directory and not in fastfile. Look on CD. char actualPath[2048]; strcpy(actualPath,CDInstallPath); strcat(actualPath,fileName); handle = _open(actualPath,_O_RDONLY); if (handle == INVALID_HANDLE_VALUE) { bool openFailed = false; bool alreadyFullScreen = (Environment.fullScreen != 0); while (handle == INVALID_HANDLE_VALUE) { openFailed = true; //OK, check to see if the CD is actually present. // Do this by checking for tgl.fst on the CD Path. // If its there, the CD is present BUT the file is missing. // MANY files in MechCommander 2 are LEGALLY missing! // Tell it to the art staff. char testCDPath[2048]; strcpy(testCDPath,CDInstallPath); strcat(testCDPath,"tgl.fst"); DWORD findCD = fileExists(testCDPath); if (findCD == 1) //File exists. CD is in drive. Return 2 to indicate file not found. return 2; EnterWindowMode(); char data[2048]; sprintf(data,FileMissingString,fileName,CDMissingString); DWORD result1 = MessageBox(NULL,data,MissingTitleString,MB_OKCANCEL | MB_ICONWARNING); if (result1 == IDCANCEL) { ExitGameOS(); return (2); //File not found. Never returns though! } handle = _open(actualPath,_O_RDONLY); } if (openFailed && (Environment.fullScreen == 0) && alreadyFullScreen) EnterFullScreenMode(); } else { if (logFileTraffic && (handle != INVALID_HANDLE_VALUE)) { if (!fileTrafficLog) { createTrafficLog(); } char msg[300]; sprintf(msg,"CFHandle Length: %010d File: %s",fileSize(),fileName); fileTrafficLog->writeLine(msg); } setup(); //------------------------------------------------------------ // NEW FUNCTIONALITY!!! // // Each file may have a number of files open as children which // use the parent's handle for reads and writes. This would // allow us to open a packet file and read a packet as a fitIni // or allow us to write a packet as a fit ini and so forth. // // It also allows us to use the packet file extensions as tree // files to avoid the ten thousand file syndrome. // // There is now an open which takes a FilePtr and a size. maxChildren = numChild; childList = (FilePtr *)systemHeap->Malloc(sizeof(FilePtr) * maxChildren); if (!childList) { return(NO_RAM_FOR_CHILD_LIST); } numChildren = 0; for (long i=0;i<(long)maxChildren;i++) { childList[i] = NULL; } return (NO_ERR); } } if (logFileTraffic) { if (!fileTrafficLog) { createTrafficLog(); } char msg[300]; sprintf(msg,"FASTF Length: %010d File: %s",fileSize(),fileName); fileTrafficLog->writeLine(msg); } //--------------------------------------------------------------------- //-- FastFiles are all compressed. Must read in entire chunk into RAM //-- Then close fastfile!!!!! inRAM = TRUE; fileImage = (unsigned char *)malloc(fileSize()); if (fileImage) { fastFile->readFast(fastFileHandle,fileImage,fileSize()); physicalLength = getLength(); //------------------------------------ //-- Image is in RAM. Shut the file. //fastFile->closeFast(fastFileHandle); //fastFile = NULL; //fastFileHandle = -1; logicalPosition = 0; } return NO_ERR; } else { if (logFileTraffic && (handle != INVALID_HANDLE_VALUE)) { if (!fileTrafficLog) { createTrafficLog(); } char msg[300]; sprintf(msg,"CFHandle Length: %010d File: %s",fileSize(),fileName); fileTrafficLog->writeLine(msg); } setup(); //------------------------------------------------------------ // NEW FUNCTIONALITY!!! // // Each file may have a number of files open as children which // use the parent's handle for reads and writes. This would // allow us to open a packet file and read a packet as a fitIni // or allow us to write a packet as a fit ini and so forth. // // It also allows us to use the packet file extensions as tree // files to avoid the ten thousand file syndrome. // // There is now an open which takes a FilePtr and a size. maxChildren = numChild; childList = (FilePtr *)systemHeap->Malloc(sizeof(FilePtr) * maxChildren); if (!childList) { return(NO_RAM_FOR_CHILD_LIST); } numChildren = 0; for (long i=0;i<(long)maxChildren;i++) { childList[i] = NULL; } return (NO_ERR); } } return(NO_ERR); }
//--------------------------------------------------------------------------- unsigned long File::fileSize (void) { return getLength(); }
void ram (void) { uint8_t key = BTN_RIGHT, button; lcdClear(); while (1) { switch (key) { case BTN_ENTER: // exit return; case BTN_RIGHT: if (direction != DIRECTION_LEFT) direction = DIRECTION_RIGHT; break; case BTN_UP: if (direction != DIRECTION_DOWN) direction = DIRECTION_UP; break; case BTN_LEFT: if (direction != DIRECTION_RIGHT) direction = DIRECTION_LEFT; break; case BTN_DOWN: if (direction != DIRECTION_UP) direction = DIRECTION_DOWN; break; //Default: No keystroke received. Assuming last keystroke. } point newendpoint = snake.endpoint; shiftPoint (&newendpoint, direction); bool resetBacon = false; if (newendpoint.x == bacon.x && newendpoint.y == bacon.y) { growBuf (&snake, direction); resetBacon = true; } else { setGamePixel(snake.startpoint.x, snake.startpoint.y, 0); shiftBuf (&snake, direction); } if (getGamePixel(snake.endpoint.x, snake.endpoint.y)) break; setGamePixel(snake.endpoint.x, snake.endpoint.y, 1); while (resetBacon) { bacon.x = getRandom() % GAME_WIDTH; bacon.y = getRandom() % GAME_HEIGHT; if (!getGamePixel(bacon.x, bacon.y)) resetBacon = false; } drawFood (bacon.x, bacon.y); lcdRefresh(); key = BTN_NONE; for (i=0; i < ( TIME_PER_MOVE / 50 ); ++i) { delayms(50); if ((button = getInputRaw()) != BTN_NONE) key = button; } } // Game ended, show results lcdClear(); lcdNl(); lcdPrintln("Game Over"); lcdPrintln("Your score:"); lcdPrintInt(getLength(&snake) - INITIAL_LENGTH + 1); lcdNl(); lcdPrintln("Press any key"); lcdPrintln("to continue."); lcdRefresh(); delayms(500); while(getInputRaw() == BTN_NONE) delayms(25); }
MathVector MathVector::getNormalized() { double length = getLength(); return MathVector(x / length, y / length, z / length); }
int Marker::getAreaNew(float n) { // TODO n=getNew(i) for (int i=0; i<getLength(); ++i) if (n<getNew(i)) return i-1; return getLength()-1; }
String toString() const { long len = getLength(); return String( (const char*) getAmount(0, len), len ); }
int Marker::getAreaOld(float o) { // TODO n=getNew(i) for (int i=0; i<getLength(); ++i) if (o<getOld(i)) return i-1; return getLength()-1; }
void fillAmountWith(long startPos, long amount, char fillChar) { ASSERT(0 <= startPos && startPos + amount <= getLength()); memset(getAmount(startPos, amount), fillChar, amount); }
char getChar (int idx) const { FW_ASSERT(idx < getLength()); return m_chars[idx]; }
char* appendAndFillAmountWith(long amount, char fillChar) { long pos = getLength(); char* rslt = appendAmount(amount); fillAmountWith(pos, amount, fillChar); return rslt; }
short BigNum::comp (OperatorTypeEnum compOp, Attributes * other, char * op_data[]) { // Recast char strings as arrays of unsigned shorts unsigned short * thisDataInShorts = (unsigned short *) op_data[1]; unsigned short * otherDataInShorts = (unsigned short *) op_data[2]; // Extract signs. char thisSign = BIGN_GET_SIGN(op_data[1], getLength()); char otherSign = BIGN_GET_SIGN(op_data[2], getLength()); // Clear sign bits BIGN_CLR_SIGN(op_data[1], getLength()); BIGN_CLR_SIGN(op_data[2], getLength()); short returnValue = 0; short compCode = 0; // if the signs are different but 'this' and 'other' values are zeroes, // then they are equal. NABoolean allZeroes = FALSE; if (thisSign != otherSign) { allZeroes = TRUE; // check if the values are zeroes. for (Lng32 i = 0; i < getLength()/2; i++) { // if a nonzero is found, break out. if ((thisDataInShorts[i] != 0) || (otherDataInShorts[i] != 0)) { allZeroes = FALSE; break; } } // for } // if if (allZeroes) compCode = 0; else { // We calculate compCode as follows: if this > other, then compCode = 1 // if this < other, then compCode = -1 // if this = other, then compCode = 0 if ((thisSign == 0) && (otherSign)) // this +ve, other -ve compCode = 1; else if ((thisSign) && (otherSign == 0)) // this -ve, other +ve compCode = -1; else { // both same sign, so check // if magnitude of this is // larger than other for (Lng32 i = 0; i < getLength()/2; i++) { if (otherDataInShorts[i] > thisDataInShorts[i]) compCode = -1; else if (otherDataInShorts[i] < thisDataInShorts[i]) compCode = 1; } if (thisSign) // both -ve, so if magnitudes // are different, switch // compCode #pragma nowarn(1506) // warning elimination compCode = (compCode ? -compCode : 0); #pragma warn(1506) // warning elimination } } switch (compOp) { case ITM_EQUAL: returnValue = ((compCode == 0) ? 1 : 0); break; case ITM_NOT_EQUAL: returnValue = ((compCode != 0) ? 1 : 0); break; case ITM_LESS: returnValue = ((compCode < 0) ? 1 : 0); break; case ITM_LESS_EQ: returnValue = ((compCode <= 0) ? 1 : 0); break; case ITM_GREATER: returnValue = ((compCode > 0) ? 1 : 0); break; case ITM_GREATER_EQ: returnValue = ((compCode >= 0) ? 1 : 0); break; } // Reset sign bits if (thisSign) BIGN_SET_SIGN(op_data[1], getLength()); if (otherSign) BIGN_SET_SIGN(op_data[2], getLength()); return returnValue; }
void shavs_test1(void){ /* KAT tests */ uint32_t length=0; int32_t expect_input=0; if(!shavs_algo){ fputs_P(PSTR("\r\nERROR: select algorithm first!"), shavs_out_file); return; } char c; uint8_t diggest[pgm_read_word(&(shavs_algo->hashsize_b))/8]; shavs_ctx.buffersize_B=pgm_read_word(&(shavs_algo->blocksize_b))/8; uint8_t buffer[shavs_ctx.buffersize_B+5]; shavs_ctx.buffer = buffer; fprintf_P(shavs_out_file, PSTR("\nbuffer_size = 0x%04"PRIx16" bytes"), shavs_ctx.buffersize_B); for(;;){ shavs_ctx.blocks = 0; memset(buffer, 0, shavs_ctx.buffersize_B); length = getLength(); if(length<0){ return; } #if DEBUG fprintf_P(shavs_out_file, PSTR("\nLen == %"PRIu32), length) #endif if(length==0){ expect_input=2; }else{ expect_input=((length + 7) >> 2) & (~1L); } #if DEBUG fprintf_P(shavs_out_file, PSTR("\r\nexpected_input == %"PRId32), expected_input); #endif shavs_ctx.buffer_idx = 0; shavs_ctx.in_byte = 0; shavs_ctx.blocks = 0; uint8_t ret; #if DEBUG fprintf_P(shavs_out_file, PSTR("\n HFAL init\n (2) expected_input == "), expected_input); #endif ret = hfal_hash_init(shavs_algo, &(shavs_ctx.ctx)); if(ret){ fprintf_P(shavs_out_file, PSTR("\r\n HFAL init returned with: %"PRIx8), ret); return; } #if DEBUG fprintf_P(shavs_out_file, PSTR("\r\n (3) expected_input == %"PRId32"\n"), expected_input) #endif while((c=cli_getc_cecho())!='M' && c!='m'){ if(!isblank(c)){ fprintf_P(shavs_out_file, PSTR("\nERROR: wrong input (1) [0x%"PRIx8"]!\n"), c); hfal_hash_free(&(shavs_ctx.ctx)); return; } } if((c=cli_getc_cecho())!='s' && c!='S'){ fputs_P(PSTR("\nERROR: wrong input (2)!\n"), shavs_out_file); hfal_hash_free(&(shavs_ctx.ctx)); return; } if((c=cli_getc_cecho())!='g' && c!='G'){ fputs_P(PSTR("\nERROR: wrong input (3)!\n"), shavs_out_file); hfal_hash_free(&(shavs_ctx.ctx)); return; } while((c=cli_getc_cecho())!='='){ if(!isblank(c)){ fputs_P(PSTR("\nERROR: wrong input (4)!\n"), shavs_out_file); hfal_hash_free(&(shavs_ctx.ctx)); return; } } #if DEBUG fputs_P(PSTR("\r\nparsing started"), shavs_out_file); #endif shavs_ctx.buffer_idx = 0; shavs_ctx.in_byte = 0; shavs_ctx.blocks = 0; while(expect_input>0){ c=cli_getc_cecho(); #if DEBUG fprintf_P(shavs_out_file, PSTR("\n\t(%"PRId32") "), expected_input); _delay_ms(500); #endif if(buffer_add(c)==0){ --expect_input; }else{ if(!isblank((uint16_t)c)){ fprintf_P(shavs_out_file, PSTR("\nERROR: wrong input (5) (%c)!\n"), c); hfal_hash_free(&(shavs_ctx.ctx)); return; } } } #if DEBUG cli_putstr_P(PSTR("\r\nBuffer-A:")); cli_hexdump_block(buffer, shavs_ctx.buffersize_B, 5, 8); cli_putstr_P(PSTR("\r\n starting finalisation")); cli_putstr_P(PSTR("\r\n\tblocks == ")); cli_hexdump_rev(&(shavs_ctx.blocks),4); cli_putstr_P(PSTR("\r\n\tbuffer_idx == ")); cli_hexdump_rev(&(shavs_ctx.buffer_idx),2); cli_putstr_P(PSTR("\r\n\tin_byte == ")); cli_hexdump_rev(&(shavs_ctx.in_byte),1); _delay_ms(500); cli_putstr_P(PSTR("\r\n starting last block")); cli_putstr_P(PSTR("\r\n\tlength == ")); cli_hexdump_rev(&length,4); cli_putstr_P(PSTR("\r\n\tbuffersize_B == ")); cli_hexdump_rev(&(shavs_ctx.buffersize_B),2); uint16_t temp=length-(shavs_ctx.blocks)*((shavs_ctx.buffersize_B)*8); cli_putstr_P(PSTR("\r\n\t (temp) == ")); cli_hexdump_rev(&temp,2); _delay_ms(500); temp=length-(shavs_ctx.blocks)*((shavs_ctx.buffersize_B)*8); #else uint16_t temp=length-(shavs_ctx.blocks)*((shavs_ctx.buffersize_B)*8); #endif hfal_hash_lastBlock( &(shavs_ctx.ctx), buffer, /* be aware of freaking compilers!!! */ temp ); #if DEBUG cli_putstr_P(PSTR("\r\n starting ctx2hash")); _delay_ms(500); #endif hfal_hash_ctx2hash(diggest, &(shavs_ctx.ctx)); #if DEBUG cli_putstr_P(PSTR("\r\n starting hash free")); #endif hfal_hash_free(&(shavs_ctx.ctx)); cli_putstr_P(PSTR("\r\n MD = ")); cli_hexdump(diggest, pgm_read_word(&(shavs_algo->hashsize_b))/8); } }
short BigNum::sub(Attributes * left, Attributes * right, char * op_data[]) { // Extract signs. char leftSign = BIGN_GET_SIGN(op_data[1], getLength()); char rightSign = BIGN_GET_SIGN(op_data[2], getLength()); // Clear sign bits BIGN_CLR_SIGN(op_data[1], getLength()); BIGN_CLR_SIGN(op_data[2], getLength()); Int32 code; if ((!isUnsigned()) && ((leftSign) || (rightSign))) { if (leftSign == 0) { // left - (-right) => left + right BigNumHelper::AddHelper(getLength(), op_data[1], op_data[2], op_data[0]); code = 0; } else if (rightSign == 0) { // -left - right => -(left + right) BigNumHelper::AddHelper(getLength(), op_data[1], op_data[2], op_data[0]); code = 1; } else { // -left - (-right) => right - left code = BigNumHelper::SubHelper(getLength(), op_data[2], op_data[1], op_data[0]); } } else { code = BigNumHelper::SubHelper(getLength(), op_data[1], op_data[2], op_data[0]); } // Reset sign bits if (leftSign) BIGN_SET_SIGN(op_data[1], getLength()); if (rightSign) BIGN_SET_SIGN(op_data[2], getLength()); if (code) { BIGN_SET_SIGN(op_data[0], getLength()); } else { BIGN_CLR_SIGN(op_data[0], getLength()); } return 0; }
void TaxiPath::SendMoveForTime(Player *riding, Player *to, uint32 time) { if (!time) return; float traveled_len = (time/(getLength() * TAXI_TRAVEL_SPEED))*getLength();; uint32 len = 0, count = 0; float x = 0,y = 0,z = 0; if (!m_pathNodes.size()) return; std::map<uint32, TaxiPathNode*>::iterator itr; itr = m_pathNodes.begin(); float nx = itr->second->x; float ny = itr->second->y; float nz = itr->second->z; itr++; while (itr != m_pathNodes.end()) { len = (uint32)sqrt((itr->second->x - nx)*(itr->second->x - nx) + (itr->second->y - ny)*(itr->second->y - ny) + (itr->second->z - nz)*(itr->second->z - nz)); if (len > traveled_len) { x = (itr->second->x - nx)*(traveled_len/len) + nx; y = (itr->second->y - ny)*(traveled_len/len) + ny; z = (itr->second->z - nz)*(traveled_len/len) + nz; break; } else { traveled_len -= len; } nx = itr->second->x; ny = itr->second->y; nz = itr->second->z; itr++; count++; } if (itr == m_pathNodes.end()) return; WorldPacket * data = new WorldPacket(SMSG_MONSTER_MOVE, 2000); *data << riding->GetNewGUID(); *data << riding->GetPositionX( ) << riding->GetPositionY( ) << riding->GetPositionZ( ); *data << getMSTime(); *data << uint8( 0 ); *data << uint32( 0x00000300 ); *data << uint32( uint32((getLength() * TAXI_TRAVEL_SPEED) - time)); *data << uint32( GetNodeCount() - count ); *data << nx << ny << nz; while (itr != m_pathNodes.end()) { TaxiPathNode *pn = itr->second; *data << pn->x << pn->y << pn->z; itr++; } //to->GetSession()->SendPacket(&data); to->delayedPackets.add(data); }
short BigNum::castFrom (Attributes * source, char * op_data[], NAMemory *heap, ComDiagsArea** diagsArea) { SimpleType * source1 = (SimpleType *) source; short sourceType = source1->getDatatype(); unsigned short * thisDataInShorts = (unsigned short *) op_data[0]; if ((sourceType >= REC_MIN_INTERVAL) && (sourceType <= REC_MAX_INTERVAL)) { // LCOV_EXCL_START switch (source1->getLength()) { case SQL_SMALL_SIZE: sourceType = REC_BIN16_SIGNED; break; case SQL_INT_SIZE: sourceType = REC_BIN32_SIGNED; break; case SQL_LARGE_SIZE: sourceType = REC_BIN64_SIGNED; // LCOV_EXCL_STOP break; } } // Initialize magnitude of Big Num to zeros. for (Int32 k = 0; k < getLength(); k++) op_data[0][k] = 0; switch (sourceType) { case REC_BIN16_SIGNED: { // LCOV_EXCL_START if ( *((short *) op_data[1]) < 0) { #pragma nowarn(1506) // warning elimination thisDataInShorts[0] = -*((short *) op_data[1]); #pragma warn(1506) // warning elimination BIGN_SET_SIGN(op_data[0], getLength()); } else { thisDataInShorts[0] = *((short *) op_data[1]); } // LCOV_EXCL_STOP } break; case REC_BPINT_UNSIGNED: case REC_BIN16_UNSIGNED: { // LCOV_EXCL_START thisDataInShorts[0] = *((unsigned short *) op_data[1]); } break; case REC_BIN32_SIGNED: { if ( *((Lng32 *) op_data[1]) < 0) { *((ULng32 *) op_data[0]) = -*((Lng32 *) op_data[1]); BIGN_SET_SIGN(op_data[0], getLength()); } else { *((ULng32 *) op_data[0]) = *((Lng32 *) op_data[1]); // LCOV_EXCL_STOP } #ifdef NA_LITTLE_ENDIAN // Do nothing, target is already in right format. #else // Reverse the shorts in the target. unsigned short temp = thisDataInShorts[0]; thisDataInShorts[0] = thisDataInShorts[1]; thisDataInShorts[1] = temp; #endif } break; case REC_BIN32_UNSIGNED: { *((ULng32 *) op_data[0]) = *((ULng32 *) op_data[1]); #ifdef NA_LITTLE_ENDIAN // Do nothing, target is already in right format. #else // Reverse the shorts in the target. unsigned short temp = thisDataInShorts[0]; thisDataInShorts[0] = thisDataInShorts[1]; thisDataInShorts[1] = temp; #endif } break; case REC_BIN64_SIGNED: { // Since this case is a little more complex, we call a helper method. BigNumHelper::ConvInt64ToBigNumWithSignHelper(getLength(), *((Int64 *) op_data[1]), op_data[0] ); } break; case REC_DECIMAL_LSE: { // Remember first char of source in temp // LCOV_EXCL_START char temp = op_data[1][0]; // Temporarily suppress sign bit in source #pragma nowarn(1506) // warning elimination op_data[1][0] = op_data[1][0] & 0177; #pragma warn(1506) // warning elimination // Convert source from ASCII to Big Num without sign and store in this. BigNumHelper::ConvAsciiToBigNumHelper(source1->getLength(), getLength(), op_data[1], op_data[0]); // Set sign in this (must be done after conversion to prevent overwrite) if (temp & 0200) BIGN_SET_SIGN(op_data[0], getLength()); // Restore first char in source op_data[1][0] = temp; } break; case REC_DECIMAL_UNSIGNED: { // Convert source from ASCII to Big Num without sign and store in this. BigNumHelper::ConvAsciiToBigNumHelper(source1->getLength(), getLength(), op_data[1], op_data[0]); } break; case REC_FLOAT32: { // The code below is modeled on the corresponding code in large decimals. char tempTarget[SQL_REAL_DISPLAY_SIZE + 1]; // Map of tempTarget: -d.dddddddE+dddn // 0123456789012345 // 1 // where '-' is '-' or ' '; '+' is '+' or '-'; n is null character; // and 'd' is a digit in ascii. if (convDoIt(op_data[1], 4, REC_FLOAT32, 0, 0, tempTarget, SQL_REAL_DISPLAY_SIZE, REC_BYTE_F_ASCII, 0, 0, NULL, 0, heap, diagsArea, CONV_UNKNOWN_LEFTPAD) != ex_expr::EXPR_OK) return -1; Lng32 i; // Compute the 8-digit mantissa by skipping the decimal point. ULng32 mantissa = 0; for (i = 1; i <= 9; i++) { if (i != 2) mantissa = mantissa * 10 + (tempTarget[i] - '0'); } // Get the exponent - absolute value only Lng32 exponent = 0; Lng32 multiplier = 100; for (i = 12; i < 15; i++) { exponent += (tempTarget[i] - '0') * multiplier; multiplier /= 10; } // If we're dealing with a positive exponent, then we have at least // "exponent" number of digits before a decimal point followed by "scale" // digits. Make sure that the number of digits to the left of the // decimal point (i.e. precision - scale) is >= "exponent" number of // digits. Special care is taken when the float is less than 1 - in this // case, the 0 digit before the decimal point should not count towards // the precision, since it will be ignored. if (tempTarget[11] != '-') { Int32 includeFirstDigit = (tempTarget[1] == '0') ? 0 : 1; if ((exponent + includeFirstDigit) > (getPrecision() - getScale())) return -1; } if (tempTarget[11] == '-') exponent = -exponent; // Subtract 7 from the exponent. This will set the exponent exactly // where the decimal point should be in the mantissa. exponent -= 7; // Shift down the mantissa so as to leave "scale" digits to the right of // the decimal point. Lng32 scaleBy = getScale() + exponent; if (scaleBy < 0) { for (i = 0; i < -scaleBy; i++) mantissa /= 10; scaleBy = 0; } // At this stage, our source is effectively = mantissa * 10^exponent. // We need to create the target Big Num by multiplying the mantissa // with 10^(scale + exponent). // Create a Big Num (without sign) for 10^(scale + exponent); // This can be stored in the temporary area pointed to by tempSpacePtr_. char * tempPowersOfTen = (char *) tempSpacePtr_; Lng32 tempPowersOfTenLength; BigNumHelper::ConvPowersOfTenToBigNumHelper(scaleBy, tempSpaceLength_, &tempPowersOfTenLength, tempPowersOfTen); // Convert the mantissa into a Big Num representation (without sign). unsigned short * mantissaDataInShorts = (unsigned short *) &mantissa; #ifdef NA_LITTLE_ENDIAN // Do nothing, mantissaData is already in the correct format. #else // Swap the two shorts in mantissaData. unsigned short temp = mantissaDataInShorts[0]; mantissaDataInShorts[0] = mantissaDataInShorts[1]; mantissaDataInShorts[1] = temp; #endif // Multiply mantissaData with tempPowersOfTen and store in this. BigNumHelper::MulHelper(getLength(), 4, tempPowersOfTenLength, (char *) &mantissa, tempPowersOfTen, op_data[0]); // Set sign of this. if ( tempTarget[0] == '-') BIGN_SET_SIGN(op_data[0], getLength()); } break; // LCOV_EXCL_STOP case REC_FLOAT64: { // The code below is modeled on the corresponding code in large decimals. char tempTarget[SQL_FLOAT_DISPLAY_SIZE + 1]; // Map of tempTarget: -d.dddddddddddddddddE+dddn // 01234567890123456789012345 // 1 2 // where '-' is '-' or ' '; '+' is '+' or '-'; n is null character; // and 'd' is a digit in ascii. if (convDoIt(op_data[1], 8, REC_FLOAT64, 0, 0, tempTarget, SQL_FLOAT_DISPLAY_SIZE, REC_BYTE_F_ASCII, 0, 0, NULL, 0, heap, diagsArea, CONV_UNKNOWN_LEFTPAD) != ex_expr::EXPR_OK) return -1; Lng32 i; // Compute the 18-digit mantissa by skipping the decimal point. Int64 mantissa = 0; for (i = 1; i <= 19; i++) { if (i != 2) mantissa = mantissa * 10 + (tempTarget[i] - '0'); } // Get the exponent - absolute value only Lng32 exponent = 0; Lng32 multiplier = 100; for (i = 22; i < 25; i++) { exponent += (tempTarget[i] - '0') * multiplier; multiplier /= 10; } // If we're dealing with a positive exponent, then we have at least // "exponent" number of digits before a decimal point followed by "scale" // digits. Make sure that the number of digits to the left of the // decimal point (i.e. precision - scale) is >= "exponent" number of // digits. Special care is taken when the float is less than 1 - in this // case, the 0 digit before the decimal point should not count towards // the precision, since it will be ignored. if (tempTarget[21] != '-') { Int32 includeFirstDigit = (tempTarget[1] == '0') ? 0 : 1; if ((exponent + includeFirstDigit) > (getPrecision() - getScale())) return -1; } if (tempTarget[21] == '-') exponent = -exponent; // Subtract 17 from the exponent. This will set the exponent exactly // where the decimal point should be in the mantissa. exponent -= 17; // Shift down the mantissa so as to leave "scale" digits to the right of // the decimal point. Lng32 scaleBy = getScale() + exponent; if (scaleBy < 0) { for (i = 0; i < -scaleBy; i++) mantissa /= 10; scaleBy = 0; } // At this stage, our source is effectively = mantissa * 10^exponent. // We need to create the target Big Num by multiplying the mantissa // with 10^(scale + exponent). // Create a Big Num (without sign) for 10^(scale + exponent); // This can be stored in the temporary area pointed to by tempSpacePtr_. char * tempPowersOfTen = (char *) tempSpacePtr_; if (tempSpacePtr_ == 0) { tempPowersOfTen = new(heap) char[tempSpaceLength_]; } Lng32 tempPowersOfTenLength; BigNumHelper::ConvPowersOfTenToBigNumHelper(scaleBy, tempSpaceLength_, &tempPowersOfTenLength, tempPowersOfTen); // Convert the mantissa into a Big Num representation (without sign). unsigned short * mantissaDataInShorts = (unsigned short *) &mantissa; #ifdef NA_LITTLE_ENDIAN // Do nothing, mantissaData is already in the correct format. #else // Reverse the four shorts in mantissaData. unsigned short temp = mantissaDataInShorts[0]; mantissaDataInShorts[0] = mantissaDataInShorts[3]; mantissaDataInShorts[3] = temp; temp = mantissaDataInShorts[1]; mantissaDataInShorts[1] = mantissaDataInShorts[2]; mantissaDataInShorts[2] = temp; #endif // Multiply mantissaData with tempPowersOfTen and store in this. BigNumHelper::MulHelper(getLength(), 8, tempPowersOfTenLength, (char *) &mantissa, tempPowersOfTen, op_data[0]); // Set sign of this. if ( tempTarget[0] == '-') // This originally set sign to 0! //*thisSign = 0; BIGN_SET_SIGN(op_data[0], getLength()); if ((Long)tempPowersOfTen != tempSpacePtr_) NADELETEBASIC(tempPowersOfTen, heap); } break; default: { // Inform the caller that the conversion is not supported. return -1; } break; } return 0; };
float Marker::new2nnew(float n) { return (n-getNew(0))/(getNew(getLength()-1)-getNew(0)); }
bool AlcEnabler::grabCodecs() { if (!that) { SYSLOG("alc @ you should call grabCodecs right before AppleHDA loading"); return false; } for (size_t lookup = 0; lookup < codecLookupSize; lookup++) { that->tmpLayout = -1; // Not using recursive lookup due to multiple possible entries auto sect = IOUtil::findEntryByPrefix("/AppleACPIPlatformExpert", "PCI", gIOServicePlane); size_t i {0}; while (sect && i < codecLookup[lookup].treeSize) { sect = IOUtil::findEntryByPrefix(sect, codecLookup[lookup].tree[i], gIOServicePlane, i+1 == codecLookup[lookup].treeSize ? [](IORegistryEntry *e) { if (that->tmpLayout < 0) { SYSLOG("alc @ invalid layout-id was previously found %d", that->tmpLayout); return; } auto ven = e->getProperty("IOHDACodecVendorID"); auto rev = e->getProperty("IOHDACodecRevisionID"); if (!ven || !rev) { SYSLOG("alc @ codec entry misses properties, skipping"); return; } auto venNum = OSDynamicCast(OSNumber, ven); auto revNum = OSDynamicCast(OSNumber, rev); if (!venNum || !revNum) { SYSLOG("alc @ codec entry contains invalid properties, skipping"); return; } auto ci = AlcEnabler::CodecInfo::create(venNum->unsigned64BitValue(), revNum->unsigned32BitValue(), that->tmpLayout); if (ci) { if (!that->codecs.push_back(ci)) { SYSLOG("alc @ failed to store codec info for %X %X", ci->vendor, ci->codec); AlcEnabler::CodecInfo::deleter(ci); } } else { SYSLOG("alc @ failed to create codec info for %X %X", ci->vendor, ci->codec); } } : nullptr); if (i == codecLookup[lookup].layoutNum) { if (sect) { auto lid = sect->getProperty("layout-id"); if (lid) { auto lidNum = OSDynamicCast(OSData, lid); if (lidNum && lidNum->getLength() > 0) { tmpLayout = static_cast<const uint8_t *>(lidNum->getBytesNoCopy())[0]; DBGLOG("alc @ found layout-id %d in %s", tmpLayout, codecLookup[lookup].tree[i]); i++; continue; } else { SYSLOG("alc @ %s contains invalid layout-id", codecLookup[lookup].tree[i]); } } } SYSLOG("alc @ no layout found in %s, aborting", codecLookup[lookup].tree[i]); break; } i++; } } return validateCodecs(); }
float Marker::nnew2new(float nn) { return nn*(getNew(getLength()-1)-getNew(0))+getNew(0); }
BOOL LLViewerTextEditor::handleMouseDown(S32 x, S32 y, MASK mask) { BOOL handled = FALSE; // Let scrollbar have first dibs handled = LLView::childrenHandleMouseDown(x, y, mask) != NULL; // enable I Agree checkbox if the user scrolled through entire text BOOL was_scrolled_to_bottom = (mScrollbar->getDocPos() == mScrollbar->getDocPosMax()); if (mOnScrollEndCallback && was_scrolled_to_bottom) { mOnScrollEndCallback(mOnScrollEndData); } if( !handled && mTakesNonScrollClicks) { if (!(mask & MASK_SHIFT)) { deselect(); } BOOL start_select = TRUE; if( allowsEmbeddedItems() ) { setCursorAtLocalPos( x, y, FALSE ); llwchar wc = 0; if (mCursorPos < getLength()) { wc = getWChar(mCursorPos); } LLInventoryItem* item_at_pos = LLEmbeddedItems::getEmbeddedItem(wc); if (item_at_pos) { mDragItem = item_at_pos; mDragItemChar = wc; mDragItemSaved = LLEmbeddedItems::getEmbeddedItemSaved(wc); gFocusMgr.setMouseCapture( this ); mMouseDownX = x; mMouseDownY = y; S32 screen_x; S32 screen_y; localPointToScreen(x, y, &screen_x, &screen_y ); LLToolDragAndDrop::getInstance()->setDragStart( screen_x, screen_y ); start_select = FALSE; } else { mDragItem = NULL; } } if( start_select ) { // If we're not scrolling (handled by child), then we're selecting if (mask & MASK_SHIFT) { S32 old_cursor_pos = mCursorPos; setCursorAtLocalPos( x, y, TRUE ); if (hasSelection()) { /* Mac-like behavior - extend selection towards the cursor if (mCursorPos < mSelectionStart && mCursorPos < mSelectionEnd) { // ...left of selection mSelectionStart = llmax(mSelectionStart, mSelectionEnd); mSelectionEnd = mCursorPos; } else if (mCursorPos > mSelectionStart && mCursorPos > mSelectionEnd) { // ...right of selection mSelectionStart = llmin(mSelectionStart, mSelectionEnd); mSelectionEnd = mCursorPos; } else { mSelectionEnd = mCursorPos; } */ // Windows behavior mSelectionEnd = mCursorPos; } else { mSelectionStart = old_cursor_pos; mSelectionEnd = mCursorPos; } // assume we're starting a drag select mIsSelecting = TRUE; } else { setCursorAtLocalPos( x, y, TRUE ); startSelection(); } gFocusMgr.setMouseCapture( this ); } handled = TRUE; } if (hasTabStop()) { setFocus(TRUE); handled = TRUE; } // Delay cursor flashing resetKeystrokeTimer(); return handled; }
std::vector<lo_message> DSPNode::getState() const { // inherit state from base class std::vector<lo_message> ret = GroupNode::getState(); lo_message msg; msg = lo_message_new(); lo_message_add(msg, "si", "setActive",(int) this->active); ret.push_back(msg); msg = lo_message_new(); lo_message_add(msg, "ss", "setPlugin", plugin.c_str()); ret.push_back(msg); /* if (connectTO.size()) { msg = lo_message_new(); lo_message_add_string(msg, "connectedTo"); for (int i=0; i<connectTO.size(); i++) lo_message_add_string(msg, (char*)connectTO[i]->sink->id->s_name); ret.push_back(msg); } */ for (int i=0; i<connectTO.size(); i++) { msg = lo_message_new(); lo_message_add(msg, "ss", "connect", (char*)connectTO[i]->sink->id->s_name); ret.push_back(msg); } msg = lo_message_new(); lo_message_add(msg, "ss", "setRolloff", _rolloff.c_str()); ret.push_back(msg); msg = lo_message_new(); lo_message_add(msg, "sf", "setSpread", getSpread()); ret.push_back(msg); msg = lo_message_new(); lo_message_add(msg, "sf", "setLength", getLength()); ret.push_back(msg); msg = lo_message_new(); lo_message_add(msg, "sf", "setRadius", getRadius()); ret.push_back(msg); msg = lo_message_new(); lo_message_add(msg, "sf", "setDirectivityFlag", directivityFlag); ret.push_back(msg); msg = lo_message_new(); lo_message_add(msg, "sffff", "setDirectivityColor", directivityColor.x(), directivityColor.y(), directivityColor.z(), directivityColor.w()); ret.push_back(msg); msg = lo_message_new(); lo_message_add(msg, "sf", "setLaserFlag", laserFlag); ret.push_back(msg); msg = lo_message_new(); lo_message_add(msg, "sf", "setVUmeterFlag", VUmeterFlag); ret.push_back(msg); // not doing this anymore (not supposed to be saved or refreshed) /* msg = lo_message_new(); lo_message_add(msg, "sf", "setIntensity", currentSoundIntensity); ret.push_back(msg); */ // have to re-send setContext AFTER setPlugin, so that loaded plugins will // have the up-to-date parameter msg = lo_message_new(); lo_message_add(msg, "ss", "setContext", getContext()); ret.push_back(msg); return ret; }