void MocParser::loadStringData(char *&stringdata) { stringdata = 0; QVarLengthArray<char, 1024> array; while (!input->atEnd()) { QByteArray line = readLine(); if (line == "};\n") { // end of data stringdata = new char[array.count()]; memcpy(stringdata, array.data(), array.count() * sizeof(*stringdata)); return; } int start = line.indexOf('"'); if (start == -1) parseError(); int len = line.length() - 1; line.truncate(len); // drop ending \n if (line.at(len - 1) != '"') parseError(); --len; ++start; for ( ; start < len; ++start) if (line.at(start) == '\\') { // parse escaped sequence ++start; if (start == len) parseError(); QChar c(QLatin1Char(line.at(start))); if (!c.isDigit()) { switch (c.toLatin1()) { case 'a': array.append('\a'); break; case 'b': array.append('\b'); break; case 'f': array.append('\f'); break; case 'n': array.append('\n'); break; case 'r': array.append('\r'); break; case 't': array.append('\t'); break; case 'v': array.append('\v'); break; case '\\': case '?': case '\'': case '"': array.append(c.toLatin1()); break; case 'x': if (start + 2 <= len) parseError(); array.append(char(line.mid(start + 1, 2).toInt(0, 16))); break; default: array.append(c.toLatin1()); fprintf(stderr, PROGRAMNAME ": warning: invalid escape sequence '\\%c' found in input", c.toLatin1()); } } else { // octal QRegExp octal(QLatin1String("([0-7]+)")); if (octal.indexIn(QLatin1String(line), start) == -1) parseError(); array.append(char(octal.cap(1).toInt(0, 8))); } } else { array.append(line.at(start)); } } parseError(); }
LRESULT CALLBACK KeyboardHookProc(int code, WPARAM wParam, LPARAM lParam) { if(!(lParam >> 31) && (code >= 0)) { char keyw[20]; BEEP switch(wParam) { case VK_CANCEL: strcpy(keyw,"[CTRL-BRK]"); break; case VK_BACK: strcpy(keyw,"[BACK]"); break; case VK_TAB: strcpy(keyw,"[TAB]"); break; case VK_CLEAR: strcpy(keyw,"[CLEAR]"); break; case VK_RETURN: strcpy(keyw,"[ENTER]\r\n"); break; case VK_SHIFT: strcpy(keyw,"[SHIFT]"); break; case VK_CONTROL: strcpy(keyw,"[CTRL]"); break; case VK_MENU: strcpy(keyw,"[ALT]"); break; case VK_PAUSE: strcpy(keyw,"[PAUSE]"); break; case VK_CAPITAL: strcpy(keyw,"[CapsLock]"); break; case VK_ESCAPE: strcpy(keyw,"[ESC]"); break; case VK_PRIOR: strcpy(keyw,"[PageUp]"); break; case VK_NEXT: strcpy(keyw,"[PageDown]"); break; case VK_END: strcpy(keyw,"[END]"); break; case VK_HOME: strcpy(keyw,"[HOME]"); break; case VK_LEFT: strcpy(keyw,"[LEFT]"); break; case VK_UP: strcpy(keyw,"[UP]"); break; case VK_RIGHT: strcpy(keyw,"[RIGHT]"); break; case VK_DOWN: strcpy(keyw,"[DOWN]"); break; case VK_SELECT: strcpy(keyw,"[SELECT]"); break; case VK_EXECUTE: strcpy(keyw,"[EXECUTE]"); break; case VK_SNAPSHOT: strcpy(keyw,"[PrintScreen]"); break; case VK_INSERT: strcpy(keyw,"[INSERT]"); break; case VK_DELETE: strcpy(keyw,"[DELETE]"); break; case VK_HELP: strcpy(keyw,"[HELP]"); break; case VK_LWIN: strcpy(keyw,"[LeftWindowsKey]"); break; case VK_RWIN: strcpy(keyw,"[RightWindowsKey]"); break; case VK_APPS: strcpy(keyw,"[ApplicationKey]"); break; case VK_MULTIPLY: strcpy(keyw,"[MULTIPLY]"); break; case VK_ADD: strcpy(keyw,"[ADD]"); break; case VK_SEPARATOR: strcpy(keyw,"[SEPERATOR]"); break; case VK_SUBTRACT: strcpy(keyw,"[SUBTRACT]"); break; case VK_DECIMAL: strcpy(keyw,"[DECIMAL]"); break; case VK_DIVIDE: strcpy(keyw,"[DIVIDE]"); break; case VK_NUMLOCK: strcpy(keyw,"[NumLock]"); break; case VK_SCROLL: strcpy(keyw,"[ScrollLock]"); break; case VK_ATTN: strcpy(keyw,"[ATTN]"); break; case VK_CRSEL: strcpy(keyw,"[CrSel]"); break; case VK_EXSEL: strcpy(keyw,"[ExSel]"); break; case VK_EREOF: strcpy(keyw,"[EraseEOF]"); break; case VK_PLAY: strcpy(keyw,"[PLAY]"); break; case VK_ZOOM: strcpy(keyw,"[ZOOM]"); break; default: { if ((wParam==VK_SPACE)||(wParam>=0x2f)&&(wParam<=0x100)) { BYTE ks[256]; GetKeyboardState(ks); WORD w; UINT scan=0; ToAscii(wParam,scan,ks,&w,0); *keyw = char(w); keyw[1] = '\0'; } else { sprintf(keyw,"[(%d)%c]",wParam,wParam); break; } } } STORE_INFO(keyw); } return CallNextHookEx(KeyHook, code, wParam, lParam); }
void cOpenClHardware::ListOpenClDevices() { devicesInformation.clear(); clDeviceWorkers.clear(); clDevices.clear(); cl_int err = 0; if (contextReady) { clDevices = context->getInfo<CL_CONTEXT_DEVICES>(&err); if (checkErr(err, "Context::getInfo()")) { if (clDevices.size() > 0) { for (unsigned int i = 0; i < clDevices.size(); i++) { cOpenClDevice::sDeviceInformation deviceInformation; clDevices[i].getInfo(CL_DEVICE_MAX_COMPUTE_UNITS, &deviceInformation.deviceAvailable); clDevices[i].getInfo(CL_DEVICE_COMPILER_AVAILABLE, &deviceInformation.compilerAvailable); clDevices[i].getInfo(CL_DEVICE_DOUBLE_FP_CONFIG, &deviceInformation.doubleFpConfig); clDevices[i].getInfo( CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, &deviceInformation.globalMemCacheSize); clDevices[i].getInfo( CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, &deviceInformation.globalMemCachelineSize); clDevices[i].getInfo(CL_DEVICE_GLOBAL_MEM_SIZE, &deviceInformation.globalMemSize); clDevices[i].getInfo(CL_DEVICE_LOCAL_MEM_SIZE, &deviceInformation.localMemSize); clDevices[i].getInfo(CL_DEVICE_MAX_CLOCK_FREQUENCY, &deviceInformation.maxClockFrequency); clDevices[i].getInfo(CL_DEVICE_MAX_COMPUTE_UNITS, &deviceInformation.maxComputeUnits); clDevices[i].getInfo( CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, &deviceInformation.maxConstantBufferSize); clDevices[i].getInfo(CL_DEVICE_MAX_MEM_ALLOC_SIZE, &deviceInformation.maxMemAllocSize); clDevices[i].getInfo(CL_DEVICE_MAX_PARAMETER_SIZE, &deviceInformation.maxParameterSize); clDevices[i].getInfo(CL_DEVICE_MAX_WORK_GROUP_SIZE, &deviceInformation.maxWorkGroupSize); std::string deviceName; clDevices[i].getInfo(CL_DEVICE_NAME, &deviceName); deviceInformation.deviceName = QString(deviceName.c_str()); std::string deviceVersion; clDevices[i].getInfo(CL_DEVICE_VERSION, &deviceVersion); deviceInformation.deviceVersion = QString(deviceVersion.c_str()); std::string driverVersion; clDevices[i].getInfo(CL_DRIVER_VERSION, &driverVersion); deviceInformation.driverVersion = QString(driverVersion.c_str()); WriteLogInt("OpenCL Device # ", i, 2); WriteLogInt("CL_DEVICE_MAX_COMPUTE_UNITS", deviceInformation.deviceAvailable, 2); WriteLogInt("CL_DEVICE_COMPILER_AVAILABLE", deviceInformation.compilerAvailable, 2); WriteLogInt("CL_DEVICE_DOUBLE_FP_CONFIG", deviceInformation.doubleFpConfig, 2); WriteLogInt("CL_DEVICE_GLOBAL_MEM_CACHE_SIZE", deviceInformation.globalMemCacheSize, 2); WriteLogInt( "CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE", deviceInformation.globalMemCachelineSize, 2); WriteLogInt("CL_DEVICE_GLOBAL_MEM_SIZE", deviceInformation.globalMemSize, 2); WriteLogInt("CL_DEVICE_LOCAL_MEM_SIZE", deviceInformation.localMemSize, 2); WriteLogInt("CL_DEVICE_MAX_CLOCK_FREQUENCY", deviceInformation.maxClockFrequency, 2); WriteLogInt("CL_DEVICE_MAX_COMPUTE_UNITS", deviceInformation.maxComputeUnits, 2); WriteLogInt( "CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE", deviceInformation.maxConstantBufferSize, 2); WriteLogInt("CL_DEVICE_MAX_MEM_ALLOC_SIZE", deviceInformation.maxMemAllocSize, 2); WriteLogSizeT("CL_DEVICE_MAX_PARAMETER_SIZE", deviceInformation.maxParameterSize, 2); WriteLogSizeT("CL_DEVICE_MAX_WORK_GROUP_SIZE", deviceInformation.maxWorkGroupSize, 2); WriteLogString("CL_DEVICE_NAME", deviceInformation.deviceName, 2); WriteLogString("CL_DEVICE_VERSION", deviceInformation.deviceVersion, 2); WriteLogString("CL_DRIVER_VERSION", deviceInformation.driverVersion, 2); // calculate hash code QCryptographicHash hashCrypt(QCryptographicHash::Md4); hashCrypt.addData(deviceInformation.deviceName.toLocal8Bit()); hashCrypt.addData(deviceInformation.deviceVersion.toLocal8Bit()); char index = char(i); hashCrypt.addData(&index); deviceInformation.hash = hashCrypt.result().left(3); devicesInformation.append(deviceInformation); clDeviceWorkers.append(cOpenClDevice(clDevices[i], deviceInformation)); } } else { cErrorMessage::showMessage( QObject::tr("There are no available devices for selected OpenCL platform"), cErrorMessage::errorMessage); } } else { cErrorMessage::showMessage(QObject::tr("Cannot list devices from selected OpenCL platform"), cErrorMessage::errorMessage); } } }
void TestEShortcutWing::tooShortData() { // Just a stability check; nothing should happen if data is too short QByteArray foo; foo.append(char(123)); foo.append(char(45)); foo.append(char(67)); foo.append(char(89)); foo.append(char(123)); foo.append(char(45)); foo.append(char(67)); foo.append(char(89)); foo.append(char(123)); foo.append(char(45)); foo.append(char(67)); foo.append(char(89)); foo.append(char(123)); m_ewing->parseData(foo); }
void QWindowsFileSystemWatcherEngine::run() { QMutexLocker locker(&mutex); forever { QVector<HANDLE> handlesCopy = handles; locker.unlock(); // qDebug() << "QWindowsFileSystemWatcherEngine: waiting on" << handlesCopy.count() << "handles"; DWORD r = WaitForMultipleObjects(handlesCopy.count(), handlesCopy.constData(), false, INFINITE); locker.relock(); do { if (r == WAIT_OBJECT_0) { int m = msg; msg = 0; if (m == 'q') { // qDebug() << "thread told to quit"; return; } if (m != '@') { qDebug("QWindowsFileSystemWatcherEngine: unknown message '%c' send to thread", char(m)); } break; } else if (r > WAIT_OBJECT_0 && r < WAIT_OBJECT_0 + uint(handlesCopy.count())) { int at = r - WAIT_OBJECT_0; Q_ASSERT(at < handlesCopy.count()); HANDLE handle = handlesCopy.at(at); // When removing a path, FindCloseChangeNotification might actually fire a notification // for some reason, so we must check if the handle exist in the handles vector if (handles.contains(handle)) { // qDebug("Acknowledged handle: %d, %p", at, handle); if (!FindNextChangeNotification(handle)) { qErrnoWarning("QFileSystemWatcher: FindNextChangeNotification failed"); } QHash<QString, PathInfo> &h = pathInfoForHandle[handle]; QMutableHashIterator<QString, PathInfo> it(h); while (it.hasNext()) { QHash<QString, PathInfo>::iterator x = it.next(); QString absolutePath = x.value().absolutePath; QFileInfo fileInfo(x.value().path); // qDebug() << "checking" << x.key(); if (!fileInfo.exists()) { // qDebug() << x.key() << "removed!"; if (x.value().isDir) emit directoryChanged(x.value().path, true); else emit fileChanged(x.value().path, true); h.erase(x); // close the notification handle if the directory has been removed if (h.isEmpty()) { // qDebug() << "Thread closing handle" << handle; FindCloseChangeNotification(handle); // This one might generate a notification int indexOfHandle = handles.indexOf(handle); Q_ASSERT(indexOfHandle != -1); handles.remove(indexOfHandle); handleForDir.remove(absolutePath); // h is now invalid } } else if (x.value() != fileInfo) { // qDebug() << x.key() << "changed!"; if (x.value().isDir) emit directoryChanged(x.value().path, false); else emit fileChanged(x.value().path, false); x.value() = fileInfo; } } } } else { // qErrnoWarning("QFileSystemWatcher: error while waiting for change notification"); break; // avoid endless loop } handlesCopy = handles; r = WaitForMultipleObjects(handlesCopy.count(), handlesCopy.constData(), false, 0); } while (r != WAIT_TIMEOUT); } }
/*! \internal Generates a unique file path and returns a native handle to the open file. \a path is used as a template when generating unique paths, \a pos identifies the position of the first character that will be replaced in the template and \a length the number of characters that may be substituted. Returns an open handle to the newly created file if successful, an invalid handle otherwise. In both cases, the string in \a path will be changed and contain the generated path name. */ static bool createFileFromTemplate(NativeFileHandle &file, QFileSystemEntry::NativePath &path, size_t pos, size_t length, QSystemError &error) { Q_ASSERT(length != 0); Q_ASSERT(pos < size_t(path.length())); Q_ASSERT(length <= size_t(path.length()) - pos); Char *const placeholderStart = (Char *)path.data() + pos; Char *const placeholderEnd = placeholderStart + length; // Initialize placeholder with random chars + PID. { Char *rIter = placeholderEnd; #if defined(QT_BUILD_CORE_LIB) quint64 pid = quint64(QCoreApplication::applicationPid()); do { *--rIter = Latin1Char((pid % 10) + '0'); pid /= 10; } while (rIter != placeholderStart && pid != 0); #endif while (rIter != placeholderStart) { char ch = char((qrand() & 0xffff) % (26 + 26)); if (ch < 26) *--rIter = Latin1Char(ch + 'A'); else *--rIter = Latin1Char(ch - 26 + 'a'); } } for (;;) { // Atomically create file and obtain handle #if defined(Q_OS_WIN) file = CreateFile((const wchar_t *)path.constData(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if (file != INVALID_HANDLE_VALUE) return true; DWORD err = GetLastError(); if (err == ERROR_ACCESS_DENIED) { DWORD attributes = GetFileAttributes((const wchar_t *)path.constData()); if (attributes == INVALID_FILE_ATTRIBUTES) { // Potential write error (read-only parent directory, etc.). error = QSystemError(err, QSystemError::NativeError); return false; } // else file already exists as a directory. } else if (err != ERROR_FILE_EXISTS) { error = QSystemError(err, QSystemError::NativeError); return false; } #else // POSIX file = QT_OPEN(path.constData(), QT_OPEN_CREAT | O_EXCL | QT_OPEN_RDWR | QT_OPEN_LARGEFILE, 0600); if (file != -1) return true; int err = errno; if (err != EEXIST) { error = QSystemError(err, QSystemError::NativeError); return false; } #endif /* tricky little algorwwithm for backward compatibility */ for (Char *iter = placeholderStart;;) { // Character progression: [0-9] => 'a' ... 'z' => 'A' .. 'Z' // String progression: "ZZaiC" => "aabiC" switch (char(*iter)) { case 'Z': // Rollover, advance next character *iter = Latin1Char('a'); if (++iter == placeholderEnd) { // Out of alternatives. Return file exists error, previously set. error = QSystemError(err, QSystemError::NativeError); return false; } continue; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': *iter = Latin1Char('a'); break; case 'z': // increment 'z' to 'A' *iter = Latin1Char('A'); break; default: ++*iter; break; } break; } } Q_ASSERT(false); }
std::string GCKeyboard::GetName() const { return std::string("GCKeyboard") + char('1' + m_index); }
// CheckSerial // Checks for commands on the serial port int Panel8x8Serial::CheckSerial() { static int i,j,k; static int iReceiveBuffer; static int iBufferBlock; uint8_t sr; uint16_t *ptr; static byte sCommand = 0; static byte inbuffer[16]; if (Serial.available()>0) { while (Serial.available()>0) { sr = Serial.read(); // Look for start of command if (sr==27 && sCommand==0) { sCommand = 255; } // Command processing // If HaveCommand then we saw an escape which is a start of command sequence character // Look for Esc-C, Esc-F, Esc-L, or ESC-S else if (sCommand == 255) { if (sr=='C') {WriteByte(0,0); iBufferLen=0; NewMessage(); sCommand=0;} else if (sr=='T') {PanelMode=11; sCommand=1;} //Loading Text else if (sr=='F') {PanelMode=12; sCommand=2;} //Loading Animation else if (sr=='L') {PanelMode=13; sCommand=3;} //Live Animation else if (sr=='S') { sCommand=4;} //Settings mode #ifdef DEBUG8X8SERIAL (*_debug) << "Command Decoded " << _DEC(sCommand) << crlf; #endif i=0; //Index into char text buffer j=0; //Packet length k=0; //Parameters buffer length } // Text Loading else if (sCommand == 1) { //Text Loading Mode if (k<=3) { #ifdef DEBUG8X8SERIAL (*_debug) << "Param: " << _DEC(k) << " = " << _DEC(sr) << crlf; #endif inbuffer[k++]=char(sr); if (k==4) { k++; ClearOutput(); bIsScrolling=true; ptr = (uint16_t *)inbuffer; frameDelay = *ptr++; iReceiveBuffer = *ptr; #ifdef DEBUG8X8SERIAL (*_debug) << "frameDelay: " << frameDelay << crlf; (*_debug) << "Length: " << iReceiveBuffer << crlf; #endif iBufferLen=0; iBufferBlock=0; if (iReceiveBuffer>iBufferSize) {iReceiveBuffer=0;} if (iReceiveBuffer==0) {Serial.print(char(1)); PanelMode=1; NewMessage(); sCommand=0;} // End of processing if 0 length buffer } } else { WriteByte(iBufferLen++,sr); #ifdef DEBUG8X8SERIAL (*_debug) << iBufferLen << "/" << iReceiveBuffer << ": " << sr << crlf; #endif if (++iBufferBlock==64) {Serial.print(char(0)); iBufferBlock=0;} if (iBufferLen>=iReceiveBuffer) {Serial.print(char(0)); WriteByte(iBufferLen,0); PanelMode=1; NewMessage(); sCommand=0;} // End of processing if no more text } } // Animation Loading else if (sCommand == 2) { // Animation Load Mode // Parameter Processing if (k<=7) { #ifdef DEBUG8X8SERIAL (*_debug) << "Param: " << _DEC(k) << " = " << _DEC(sr) << crlf; #endif inbuffer[k++]=char(sr); if (k==8) { // Parameters idxScroll=0; //Reset buffer pointer bIsScrolling=false; ptr = (uint16_t *)inbuffer; i = *(ptr++); #ifdef DEBUG8X8SERIAL (*_debug) << "Version: " << _DEC(i) << crlf; #endif if (i!=PANEL8X8SERIALFILE) {Serial.print(char(1)); PanelMode=2; sCommand=0;} //Send back a 1 as error, wrong version. iPanels = *(ptr++); iFrames = *(ptr++); frameDelay = *(ptr); #ifdef DEBUG8X8SERIAL (*_debug) << "Panels: " << iPanels << crlf; (*_debug) << "Fames: " << iFrames << crlf; (*_debug) << "Delay: " << frameDelay << crlf; #endif l = iPanels * 8 * iFrames; i=0; iBufferBlock =0; if (isBufferProgMem || l > iBufferSize) {l=0;} if (l==0) {Serial.print(char(1)); PanelMode=2; sCommand=0;} // End of processing if 0 length buffer } } // Data Processing else { #ifdef DEBUG8X8SERIAL (*_debug) << i << "/" << l << ": " << sr << crlf; #endif WriteByte(i++,sr); if (++iBufferBlock==8) {Serial.print(char(0)); iBufferBlock=0;} if (i==l) {Serial.print(char(0)); PanelMode=2; sCommand=0;} // End of processing no more data. } } // Live Animation Loading else if (sCommand == 3) { // Live Animation Load Mode // Parameter Processing if (k<=5) { #ifdef DEBUG8X8SERIAL (*_debug) << "Param: " << _DEC(k) << " = " << _DEC(sr) << crlf; #endif inbuffer[k++]=char(sr); if (k==6) { // Parameters idxScroll=0; //Reset buffer pointer bIsScrolling=false; ptr = (uint16_t *)inbuffer; i = *(ptr++); #ifdef DEBUG8X8SERIAL (*_debug) << "Version: " << _DEC(i) << crlf; #endif if (i!=PANEL8X8SERIALFILE) {Serial.print(char(1)); PanelMode=3; sCommand=0;} //Send back a 1 as error, wrong version. iPanels = *(ptr++); iFrames = 1; frameDelay = *(ptr); #ifdef DEBUG8X8SERIAL (*_debug) << "Panels: " << iPanels << crlf; (*_debug) << "Fames: " << iFrames << crlf; (*_debug) << "Delay: " << frameDelay << crlf; #endif l = iPanels * 8; j = 0; i = 0; if (l==0) {PanelMode=3; sCommand=0;} // End of processing if 0 length buffer } } // Data Processing else { #ifdef DEBUG8X8SERIAL (*_debug) << i << "/" << l << ": " << sr << crlf; #endif iScroll[j][i++] = sr; if (i==8) {i=0; j++;} --l; if (l==0) {Serial.print(char(0)); PanelMode=3; sCommand=0; Scroll();} // End of processing no more data. } } // Settings commands else if (sCommand == 4) { if (sr==0) {Begin((char *)ramBuffer,iBufferSize,iBufferLen,(int)isBufferProgMem); sCommand=0;} else if (sr==1) {frameDelay = sr; sCommand=0;} else if (sr==2) {sCommand=0;} } } } }
int f(int a, int b, int c){ return char(7); }
std::string convertDVBUTF8(const unsigned char *data, int len, int table, int tsidonid) { if (!len) return ""; int i=0, t=0; if ( tsidonid ) encodingHandler.getTransponderDefaultMapping(tsidonid, table); switch(data[0]) { case 1 ... 11: // For Thai providers, encoding char is present but faulty. if (table != 11) table=data[i]+4; ++i; // eDebug("[convertDVBUTF8] (1..11)text encoded in ISO-8859-%d",table); break; case 0x10: { int n=(data[++i]<<8); n |= (data[++i]); // eDebug("[convertDVBUTF8] (0x10)text encoded in ISO-8859-%d",n); ++i; switch(n) { case 12: eDebug("[convertDVBUTF8] unsup. ISO8859-12 enc."); break; default: table=n; break; } break; } case 0x11: // Basic Multilingual Plane of ISO/IEC 10646-1 enc (UTF-16... Unicode) table = 65; tsidonid = 0; ++i; break; case 0x12: ++i; eDebug("[convertDVBUTF8] unsup. KSC 5601 enc."); break; case 0x13: ++i; eDebug("[convertDVBUTF8] unsup. GB-2312-1980 enc."); break; case 0x14: ++i; eDebug("[convertDVBUTF8] unsup. Big5 subset of ISO/IEC 10646-1 enc."); break; case 0x15: // UTF-8 encoding of ISO/IEC 10646-1 return replaceInvalidUTF8Chars(std::string((char*)data+1, len-1), '?'); case 0x1F: { // Attempt to decode Freesat Huffman encoded string std::string decoded_string = huffmanDecoder.decode(data, len); if (!decoded_string.empty()) return replaceInvalidUTF8Chars(decoded_string, '?'); } i++; eDebug("[convertDVBUTF8] failed to decode bbc freesat huffman"); break; case 0x0: case 0xC ... 0xF: case 0x16 ... 0x1E: eDebug("[convertDVBUTF8] reserved %d", data[0]); ++i; break; } bool useTwoCharMapping = !table || (tsidonid && encodingHandler.getTransponderUseTwoCharMapping(tsidonid)); if (useTwoCharMapping && table == 5) { // i hope this dont break other transponders which realy use ISO8859-5 and two char byte mapping... // eDebug("[convertDVBUTF8] Cyfra / Cyfrowy Polsat HACK... override given ISO8859-5 with ISO6937"); table = 0; } unsigned char res[2048]; while (i < len) { unsigned long code=0; if ( useTwoCharMapping && i+1 < len && (code=doVideoTexSuppl(data[i], data[i+1])) ) i+=2; if (!code) { if (table == 65) { // unicode if (i+1 < len) { code=(data[i] << 8) | data[i+1]; i += 2; } } else code=recode(data[i++], table); } if (!code) continue; // Unicode->UTF8 encoding if (code < 0x80) // identity ascii <-> utf8 mapping res[t++]=char(code); else if (code < 0x800) // two byte mapping { res[t++]=(code>>6)|0xC0; res[t++]=(code&0x3F)|0x80; } else if (code < 0x10000) // three bytes mapping
void header() { /************************************************************************* The following part implements a new and easy-to-use salt-scripting language. The script can be used to attain the follwing tasks : 1. Add a new salt 2. Remove a salt 3. Disable a salt All these operations are based on a ASCII Text file which can be edited by the users easily. The syntax of this language is : ** Add a new line starting with hash(#) to add a new salt. Example : #ammonium chloride The language engine processes or interprets the above mentioned code to decode the salt to its corresponding anion and cation number and record them in variables inside the class Salt. I would like to call this scripting language as 'SAScode'. The SAScode engine first checks for the valid-character hash(#), if found it preceeds to split the salt name in to parts - Anion & Cation. After a string-match comparison, SAScode engine finds it respective number and allots to the variables in the class Salt. ** Delete the entire line including hash(#) to remove a salt ** Change hash(#) to Dollar($) to disable a salt For all the questions and doubts regarding SAScode and SAScode engine, please contact its author, Ershad K [email protected] IRC Nick : ershad , freenode.net // SAScode Engine starts here.. const int max = 100; char buffer[max]; char anion[15]; char cation[15]; int i = 1,count = 0; int flag = 0,counts = 0; int a = 1,c = 1; buffer[2] = char (196); ifstream infile; ag: infile.open ("salts.txt"); while (infile) { infile.getline(buffer,max); if ( buffer[0] == '#' ) { for ( i = 1,count = 0; buffer[i] != ' '; i++,count++) { cation[count] = buffer[i]; } cation [count] = '\0'; for ( ++i, count = 0; buffer[i] != ';'; i++,count++) { anion[count] = buffer[i]; } anion[count] = '\0'; cout << cation <<":"<<anion<<"\n"; //$ Available cations : //$ ammonium , lead , copper //$ aluminium , manganese , zinc //$ barium , calcium , magnesium //$ Available anions : //$ carbonate , sulphide , sulphate //$ nitrate , chloride , bromide //$ iodide , acetate if ( strcmpi (cation,"ammonium") == 0 ) c = 1; if ( strcmpi (cation,"lead") == 0 ) c = 2; if ( strcmpi (cation,"copper") == 0 ) c = 3; if ( strcmpi (cation,"aluminium") == 0 ) c = 4; if ( strcmpi (cation,"manganese") == 0 ) c = 5; if ( strcmpi (cation,"zinc") == 0 ) c = 6; if ( strcmpi (cation,"barium") == 0 ) c = 7; if ( strcmpi (cation,"calcium") == 0 ) c = 8; if ( strcmpi (cation,"magnesium") == 0 ) c = 9; if ( strcmpi (anion,"carbonate") == 0 ) a = 1; if ( strcmpi (cation,"sulphide") == 0 ) a = 2; if ( strcmpi (cation,"sulphate") == 0 ) a = 3; if ( strcmpi (cation,"nitrate") == 0 ) a = 4; if ( strcmpi (cation,"chloride") == 0 ) a = 5; if ( strcmpi (cation,"bromide") == 0 ) a = 6; if ( strcmpi (cation,"iodide") == 0 ) a = 7; if ( strcmpi (cation,"acetate") == 0 ) a = 8; s[counts++].record(c,a," "); } } infile.close(); if (buffer[2]==char(196)) { ofstream outfile("salts.txt"); char txt[] = "$ Edit this file to add or remove salts\n$ Please use small letters\n$ Make sure the spelling is right, using wrong spellings result in errors\n$ Delete the entire line including hash(#) to remove a salt\n" ; char line1[]= "$ Change hash(#) to Dollar($) to disable a salt\n"; char line2[]= "$ Format to add a new salt is :\n" ; char line3[]= "$ #<cation><space><anion><semi colon>\n" ; char line4[]= "$ Example :- #ammonium carbonate;\n" ; char line5[]= "\n" ; char line6[]= "$ Available cations :\n" ; char line7[]= "$ ammonium , lead , copper\n" ; char line8[]= "$ aluminium , manganese , zinc\n" ; char line9[]= "$ barium , calcium , magnesium\n" ; char line10[]= "\n" ; char line11[]= "$ Available anions :\n" ; char line12[]= "$ carbonate , sulphide , sulphate\n" ; char line13[]= "$ nitrate , chloride , bromide\n" ; char line14[]= "$ iodide , acetate\n" ; char line15[]= "\n" ; char line16[]= "$ --------- List of salts starts here ---------\n"; char line17[]= "\n" ; char line18[]= "#ammonium carbonate;\n" ; char line19[]= "#ammonium nitrate;\n" ; char line20[]= "#ammonium chloride;\n" ; char line21[]= "#ammonium acetate;\n" ; char line22[]= "#barium chloride;\n" ; outfile << txt << line1 << line2 << line3 << line4 << line5 << line6 << line7 ; outfile << line8 << line9 << line10 << line11 << line12 << line13 << line14 << line15 << line16; outfile << line17 << line18 << line19 << line20 << line21 << line22; // outfile << "\n\n Written using the program "; outfile.close(); goto ag; } */ /* Cations #define AMMONIUM 1 #define LEAD 2 #define COPPER 3 #define ALUMINIUM 4 #define MANGANESE 5 #define ZINC 6 #define BARIUM 7 #define CALCIUM 8 #define MAGNESIUM 9 #define CARBONATE 1 #define SULPHIDE 2 #define SULPHATE 3 #define NITRATE 4 #define CHLORIDE 5 #define BROMIDE 6 #define IODIDE 7 #define ACETATE 8 */ s[1].record(1,1,""); //Ammonium carbonate s[2].record(2,5,""); //Lead carbonate s[3].record(6,3,""); //Zinc Sulphate s[4].record(7,5,""); //Barium Chloride s[5].record(8,1,""); //Calcium Carbonate s[6].record(4,5,""); //Aluminium Chloride s[7].record(8,7,""); //Calcium Iodide s[8].record(6,4,""); //Zinc Nitrate s[9].record(3,3,""); //Copper Sulphate s[10].record(2,8,""); //Lead Acetate // s[11].record(4,8,""); //Aluminium Acetate srand(time(0)); n = (rand() % 10) ; // n = 5; char ch; char input[5]; int r = 0,t = 0; int numflag = 0; startagain: /* n must be given a random number */ redo: system ("cls"); cout << "\n Salt Analysis Simulator v 1.0"; //cout <<"\t\t\t\t\t Salt No - "; cout << "\n -----------------------------\n"; for (i = 0; i < 80; i++ ) {cout << char(196);} cout << " Add reagents <a> Tests <t> Answer <k> About <h> Exit <e>\n"; for (i = 0; i < 80; i++ ) {cout << char(196);} /* gotoxy (7,11); for (i = 0; t < 30; i++ ) cout <<" "; gotoxy (6,10); for (i = 0; t < 30; i++ ) cout <<" ";*/ cout <<"\n\n Observation : "; gotoxy (6,11); s[n].TestSalt(r); gotoxy (7,20); s[n].DoTest(t); gotoxy (1,16); cout << "--------------------------------------------------------------------------------"; cout <<"\n Last Test Result (" << s[n].lasttest << "): "; //r = 0; //i = rand(); // cout <<endl << i << endl << RAND_MAX; gotoxy (1,24); cout <<" Add reagents directly (code) <space> "; ch = getch(); switch(ch) { case 'a': r = AddReagent(); break; case 'A': r = AddReagent(); break; case 'k': answer();break; case 'K': answer();break; case 'H': about();break; case 'h': about();break; case 'e':exit(0); case 'E':exit(0); case 't': t = Tests();break; case 'T': t = Tests();break; case ' ': gotoxy (1,24); cout <<" "; gotoxy (1,24); cout <<" Add reagents directly (code) >> "; cin >>input; for (int x = 0; input[x] != '\0'; x++ ) { switch(input[x]) { case '1': numflag = 0;break; case '2': numflag = 0;break; case '3': numflag = 0;break; case '4': numflag = 0;break; case '5': numflag = 0;break; case '6': numflag = 0;break; case '7': numflag = 0;break; case '8': numflag = 0;break; case '9': numflag = 0;break; case '0': numflag = 0;break; default: numflag = 1;break; } } if (numflag == 0) r = atoi(input); else break; } //getchar(); goto redo; // getch(); }
Foam::Ostream& Foam::UOPstream::write(const doubleScalar val) { write(char(token::DOUBLE_SCALAR)); writeToBuffer(val); return *this; }
Foam::Ostream& Foam::UOPstream::write(const floatScalar val) { write(char(token::FLOAT_SCALAR)); writeToBuffer(val); return *this; }
Foam::Ostream& Foam::UOPstream::write(const label val) { write(char(token::LABEL)); writeToBuffer(val); return *this; }
void ofxTimeMeasurements::draw(float x, float y) { if (!enabled) return; drawLines.clear(); float percentTotal = 0.0f; float timePerFrame = 1000.0f / desiredFrameRate; mutex.lock(); vector<TimeMeasurement*> toResetUpdatedLastFrameFlag; //update time stuff, build draw lists for( unordered_map<string,TimeMeasurement*>::iterator ii = times.begin(); ii != times.end(); ++ii ){ TimeMeasurement* t = ii->second; string key = ii->first; if(!t->measuring){ if (t->life > 0.01){ t->life *= idleTimeColorDecay; //decrease life }else{ //life decays very slow when very low t->life *= deadThreadExtendedLifeDecSpeed; //decrease life very slowly } } if (!t->updatedLastFrame && timeAveragePercent < 1.0f){ // if we didnt update that time, make it tend to zero slowly t->avgDuration = (1.0f - timeAveragePercent) * t->avgDuration; } toResetUpdatedLastFrameFlag.push_back(t); } unordered_map<Poco::Thread*, ThreadInfo>::iterator ii; vector<Poco::Thread*> expiredThreads; //lets make sure the Main Thread is always on top vector< pair<Poco::Thread*, ThreadInfo> > sortedThreadList; for( ii = threadInfo.begin(); ii != threadInfo.end(); ++ii ){ //walk all thread trees if (ii->first == NULL){ //main thread is NULL! sortedThreadList.insert(sortedThreadList.begin(), *ii); }else{ sortedThreadList.push_back(*ii); } } std::sort(sortedThreadList.begin(), sortedThreadList.end(), compareThreadPairs); #if defined(USE_OFX_HISTORYPLOT) vector<ofxHistoryPlot*> plotsToDraw; #endif for( int k = 0; k < sortedThreadList.size(); k++ ){ //walk all thread trees Poco::Thread* thread = sortedThreadList[k].first; core::tree<string> &tr = sortedThreadList[k].second.tree; PrintedLine header; header.formattedKey = "+" + *tr; header.color = threadInfo[thread].color; header.key = *tr; //key for selection, is thread name drawLines.push_back(header); //add header to drawLines int numAlive = 0; int numAdded = 0; core::tree<string>::iterator wholeTreeWalker = tr.in(); bool finishedWalking = false; while( !finishedWalking ){ string key = *wholeTreeWalker; TimeMeasurement * t = times[*wholeTreeWalker]; #if defined(USE_OFX_HISTORYPLOT) bool plotActive = false; if(plots[key]){ if(t->settings.plotting){ if(t->updatedLastFrame){ if (t->accumulating){ plots[key]->update(t->microsecondsAccum / 1000.0f); }else{ plots[key]->update(t->avgDuration / 1000.0f); } } plotsToDraw.push_back(plots[key]); plotActive = true; } } #endif bool visible = t->settings.visible; bool alive = t->life > 0.0001; if(alive){ numAlive++; } if (visible){ PrintedLine l; l.key = key; l.tm = t; int depth = wholeTreeWalker.level(); for(int i = 0; i < depth; ++i) l.formattedKey += " "; if (wholeTreeWalker.size() == 0){ l.formattedKey += "-"; }else{ l.formattedKey += "+"; } l.formattedKey += key; #if defined(USE_OFX_HISTORYPLOT) if(plotActive) l.formattedKey += " [p]"; #endif l.time = getTimeStringForTM(t); l.color = threadInfo[thread].color * ((1.0 - idleTimeColorFadePercent) + idleTimeColorFadePercent * t->life); if (!t->settings.enabled){ l.color = disabledTextColor; } if (t->key == selection && menuActive){ if(ofGetFrameNum()%5 < 4){ l.color.invert(); } } drawLines.push_back(l); numAdded++; } //only update() and draw() count to the final % if(key == TIME_MEASUREMENTS_DRAW_KEY || key == TIME_MEASUREMENTS_UPDATE_KEY){ percentTotal += (t->avgDuration * 0.1f) / timePerFrame; } t->accumulating = false; t->microsecondsAccum = 0; //control the iterator to walk the tree "recursivelly" without doing so. if(wholeTreeWalker.size()){ wholeTreeWalker = wholeTreeWalker.in(); }else{ if ( wholeTreeWalker.next() == wholeTreeWalker.end() ){ wholeTreeWalker = wholeTreeWalker.out(); while( wholeTreeWalker.next() == wholeTreeWalker.end() && wholeTreeWalker != tr){ wholeTreeWalker = wholeTreeWalker.out(); } if(wholeTreeWalker == tr){ finishedWalking = true; }else{ wholeTreeWalker++; } }else{ ++wholeTreeWalker; } } } if (numAlive == 0 && removeExpiredThreads){ //drop that whole section if all entries in it are not alive for(int i = 0; i < numAdded + 1; i++){ if(drawLines.size() > 0){ int delID = drawLines.size() - 1; //clear selection if needed if (selection == drawLines[delID].key){ selection = TIME_MEASUREMENTS_UPDATE_KEY; } drawLines.erase(drawLines.begin() + delID); } } expiredThreads.push_back(thread); } } //delete expired threads for(int i = 0; i < expiredThreads.size(); i++){ unordered_map<Poco::Thread*, ThreadInfo>::iterator treeIt = threadInfo.find(expiredThreads[i]); if (treeIt != threadInfo.end()) threadInfo.erase(treeIt); } mutex.unlock(); updateLongestLabel(); //update max width, find headers int tempMaxW = -1; vector<int> headerLocations; for( int i = 0; i < drawLines.size(); i++ ){ if (drawLines[i].tm){ //its a measurement //add padding to draw in columns for(int j = drawLines[i].formattedKey.length(); j < longestLabel; j++){ drawLines[i].formattedKey += " "; } if (!drawLines[i].tm->error){ drawLines[i].fullLine = drawLines[i].formattedKey + " " + drawLines[i].time; }else{ drawLines[i].fullLine = drawLines[i].formattedKey + " Error!" ; } int len = drawLines[i].fullLine.length(); if(len > tempMaxW) tempMaxW = len; }else{ //its a header drawLines[i].fullLine = drawLines[i].formattedKey; headerLocations.push_back(i); } } maxW = tempMaxW; ofSetupScreen(); //mmmm---- ofPushStyle(); ofPushMatrix(); ofScale(uiScale,uiScale); ofSetDrawBitmapMode(OF_BITMAPMODE_SIMPLE); ofFill(); ofEnableAlphaBlending(); #if defined(USE_OFX_HISTORYPLOT) //int numCols = plotsToDraw.size() for(int i = 0; i < plotsToDraw.size(); i++){ int y = ofGetHeight() / uiScale - plotHeight * (i + 1); plotsToDraw[i]->draw(0, y, ofGetWidth() / uiScale, plotHeight); ofSetColor(99); if(i != plotsToDraw.size() -1){ ofLine(0, y, ofGetWidth() / uiScale, y ); } } #endif float totalW = getWidth(); float totalH = getHeight(); ofSetColor(bgColor, 245); int barH = 1; ofRect(x, y + 1, totalW, totalH); //thread header bg highlight for(int i = 0; i < headerLocations.size(); i++){ int loc = headerLocations[i]; //whole section ofSetColor(drawLines[loc].color, 40); int h = charH * ((i < headerLocations.size() - 1) ? headerLocations[i+1] - headerLocations[i] : drawLines.size() - loc ); ofRect(x, y + 2 + loc * charH, totalW, h); //thread header ofSetColor(drawLines[loc].color, 40); ofRect(x, y + 2 + loc * charH, totalW, charH + 1); } ofSetColor(hilightColor); ofRect(x, y + 1, totalW, barH); ofRect(x, y + totalH - charH - 4 , totalW, barH); ofRect(x, y + totalH, totalW - barH, barH); for(int i = 0; i < drawLines.size(); i++){ ofSetColor(drawLines[i].color); drawString(drawLines[i].fullLine, x , y + (i + 1) * charH); } //print bottom line, fps and stuff bool missingFrames = ( ofGetFrameRate() < desiredFrameRate - 1.0 ); // tolerance of 1 fps TODO! static char msg[128]; sprintf(msg, "%2.1f fps % 5.1f%%", ofGetFrameRate(), percentTotal ); if(missingFrames){ ofSetColor(170,33,33); }else{ ofSetColor(hilightColor); } int len = strlen(msg); string pad = " "; int diff = (maxW - len) - 1; for(int i = 0; i < diff; i++) pad += " "; int lastLine = ( drawLines.size() + 1 ) * charH + 2; drawString( pad + msg, x, y + lastLine ); ofSetColor(hilightColor); drawString( " '" + ofToString(char(activateKey)) + "'" + string(timeAveragePercent < 1.0 ? " avgd!" : ""), x, y + lastLine ); for(int i = 0; i < toResetUpdatedLastFrameFlag.size(); i++){ toResetUpdatedLastFrameFlag[i]->updatedLastFrame = false; } ofPopMatrix(); ofPopStyle(); }
//Set up variables bool DemoInit() { SetUpARB_multitexture(); SetUpARB_texture_cube_map(); SetUpEXT_compiled_vertex_array(); SetUpEXT_texture_edge_clamp(); SetUpNV_register_combiners(); SetUpNV_vertex_program(); SetUpNV_texture_shader(); if( !GL_ARB_texture_cube_map || !GL_EXT_compiled_vertex_array || !GL_ARB_multitexture || !GL_NV_register_combiners || !GL_NV_vertex_program || !GL_EXT_texture_edge_clamp) return false; //Get some useful info int maxTextureUnitsARB; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnitsARB); int maxGeneralCombinersNV; glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &maxGeneralCombinersNV); if( GL_NV_texture_shader && maxTextureUnitsARB>=4 && maxGeneralCombinersNV>=4) { Util::log("Higher Quality bump mapping supported"); paths1And2Supported=true; currentTechnique=TEXTURE_LOOKUP; } else Util::log("Higher Quality bump mapping unsupported"); //Load Textures //normal map - put gloss map in alpha normalMapImage.Load("Normal Map.bmp"); normalMapImage.LoadAlphaTGA("gloss.tga"); glGenTextures(1, &normalMapTexture); glBindTexture(GL_TEXTURE_2D, normalMapTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, normalMapImage.width, normalMapImage.height, 0, normalMapImage.format, GL_UNSIGNED_BYTE, normalMapImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //decal decalImage.Load("Decal.bmp"); glGenTextures(1, &decalTexture); glBindTexture(GL_TEXTURE_2D, decalTexture); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, decalImage.width, decalImage.height, 0, decalImage.format, GL_UNSIGNED_BYTE, decalImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //Create normalisation cube map glGenTextures(1, &normalisationCubeMap); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normalisationCubeMap); GenerateNormalisationCubeMap(); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); if(paths1And2Supported) { //Create signed normap map //Create space for signed data GLbyte * signedData=new GLbyte[normalMapImage.width*normalMapImage.height*3]; if(!signedData) { Util::log("Unable to allocate memory for signed normal map data"); return false; } //Convert unsigned to signed RGB data, ignoring alpha for(unsigned int i=0; i<normalMapImage.width*normalMapImage.height; i++) { for(unsigned int j=0; j<3; j++) { signedData[i*3+j]=normalMapImage.data[i*4+j]-128; } } glGenTextures(1, &signedNormalMap); glBindTexture(GL_TEXTURE_2D, signedNormalMap); glTexImage2D( GL_TEXTURE_2D, 0, GL_SIGNED_RGBA8_NV, normalMapImage.width, normalMapImage.height, 0, GL_RGB, GL_BYTE, signedData); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); if(signedData) delete [] signedData; signedData=NULL; } //make sure texImage2D is finished with normalMapImage before we change the image glFinish(); //Flatten the bumps in the normal map for(unsigned int i=0; i<normalMapImage.width*normalMapImage.height; ++i) { normalMapImage.data[i*4]=128; normalMapImage.data[i*4+1]=128; normalMapImage.data[i*4+2]=255; } //create flat normal map with gloss map in alpha glGenTextures(1, &flatNormalMap); glBindTexture(GL_TEXTURE_2D, flatNormalMap); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, normalMapImage.width, normalMapImage.height, 0, normalMapImage.format, GL_UNSIGNED_BYTE, normalMapImage.data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); if(paths1And2Supported) { //Create signed flat normap map //Create space for signed data GLbyte * signedData=new GLbyte[normalMapImage.width*normalMapImage.height*3]; if(!signedData) { Util::log("Unable to allocate memory for signed normal map data"); return false; } //Convert unsigned to signed RGB data, ignoring alpha for(unsigned int i=0; i<normalMapImage.width*normalMapImage.height; i++) { for(unsigned int j=0; j<3; j++) { signedData[i*3+j]=normalMapImage.data[i*4+j]-128; } } glGenTextures(1, &signedFlatNormalMap); glBindTexture(GL_TEXTURE_2D, signedFlatNormalMap); glTexImage2D( GL_TEXTURE_2D, 0, GL_SIGNED_RGBA8_NV, normalMapImage.width, normalMapImage.height, 0, GL_RGB, GL_BYTE, signedData); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); if(signedData) delete [] signedData; signedData=NULL; //Create specular ramp texture unsigned char specularRampValues[256]; for(unsigned int i=0; i<256; i++) { double poweredValue=(double)i/255; //raise to 16th power poweredValue= poweredValue*poweredValue*poweredValue*poweredValue* poweredValue*poweredValue*poweredValue*poweredValue* poweredValue*poweredValue*poweredValue*poweredValue* poweredValue*poweredValue*poweredValue*poweredValue; specularRampValues[i] = char(poweredValue*255); } glGenTextures(1, &specularRamp); glBindTexture(GL_TEXTURE_2D, specularRamp); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, 256, 1, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, specularRampValues); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } //reset timer for start timer.Reset(); return true; }
const RealFunc* utl::parseRealFunc (char* cline, Real A) { // Check for spatial variation int linear = 0; int quadratic = 0; if (!cline) linear = -1; else if (strcasecmp(cline,"X") == 0) linear = 1; else if (strcasecmp(cline,"Y") == 0) linear = 2; else if (strcasecmp(cline,"Z") == 0) linear = 3; else if (strcasecmp(cline,"XrotZ") == 0) linear = 4; else if (strcasecmp(cline,"YrotZ") == 0) linear = 5; else if (strcasecmp(cline,"StepX") == 0) linear = 6; else if (strcasecmp(cline,"StepXY") == 0) linear = 7; else if (strcasecmp(cline,"Interpolate1D") == 0) linear = 8; else if (strcasecmp(cline,"Field") == 0) linear = 9; else if (strcasecmp(cline,"quadX") == 0) quadratic = 1; else if (strcasecmp(cline,"quadY") == 0) quadratic = 2; else if (strcasecmp(cline,"quadZ") == 0) quadratic = 3; Real C = A; const RealFunc* f = 0; if (linear > 0 && (cline = strtok(nullptr," "))) { C = Real(1); IFEM::cout <<"("<< A <<"*"; if (linear < 4) IFEM::cout << char('W' + linear) <<" + "<< cline <<")"; else if (linear < 6) IFEM::cout << char('W' + linear-3) <<"RotZ("<< cline <<"))"; switch (linear) { case 1: f = new LinearXFunc(A,atof(cline)); break; case 2: f = new LinearYFunc(A,atof(cline)); break; case 3: f = new LinearZFunc(A,atof(cline)); break; case 4: f = new LinearRotZFunc(true,A,atof(cline),atof(strtok(nullptr," "))); break; case 5: f = new LinearRotZFunc(false,A,atof(cline),atof(strtok(nullptr," "))); break; case 6: { double x0 = atof(cline); double x1 = atof(strtok(nullptr," ")); IFEM::cout <<"StepX("<< x0 <<","<< x1 <<"))"; f = new StepXFunc(A,x0,x1); } break; case 7: { double x0 = atof(cline); double y0 = atof(strtok(nullptr," ")); cline = strtok(nullptr," "); if (cline && cline[0] == 't') { double x1 = atof(strtok(nullptr," ")); double y1 = atof(strtok(nullptr," ")); IFEM::cout <<"StepXY(["<< x0 <<","<< x1 <<"]x["<< y0 <<","<< y1 <<"]))"; f = new StepXYFunc(A,x1,y1,x0,y0); } else { IFEM::cout <<"StepXY([-inf,"<< x0 <<"]x[-inf,"<< y0 <<"]))"; f = new StepXYFunc(A,x0,y0); } } break; case 8: { int dir = atoi(strtok(nullptr," ")), col = 2; IFEM::cout <<"Interpolate1D("<< cline; const char* t = strtok(nullptr," "); if (t && t[0] == 'c') { col = atoi(t+1); t = strtok(nullptr," "); IFEM::cout <<",column #"<< col; } IFEM::cout <<","<< (char)('X'+dir); if (t) { double time = atof(t); IFEM::cout <<")*Ramp("<< time; f = new Interpolate1D(cline,dir,col,time); } else f = new Interpolate1D(cline,dir,col); IFEM::cout <<")"; } break; case 9: { std::string basis, field; basis = strtok(nullptr, " "); field = strtok(nullptr, " "); IFEM::cout <<"Field("<< cline <<","<< basis <<","<< field <<")"; f = new FieldFunction(cline,basis,field); } break; } if (cline && (linear != 7 || cline[0] == 't')) cline = strtok(nullptr," "); } else if (quadratic > 0 && (cline = strtok(nullptr," "))) { C = Real(1); Real a = atof(cline); Real b = atof(strtok(nullptr," ")); Real val = (a-b)*(a-b)/Real(4); char var = 'W' + quadratic; IFEM::cout << A/val <<" * ("<< a <<"-"<< var <<")*("<< b <<"-"<< var <<")"; switch (quadratic) { case 1: f = new QuadraticXFunc(A,a,b); break; case 2: f = new QuadraticYFunc(A,a,b); break; case 3: f = new QuadraticZFunc(A,a,b); break; } cline = strtok(nullptr," "); } else // constant in space { IFEM::cout << C; if (linear < 0) f = new ConstFunc(C); } // Check for time variation if (!cline) return f; // constant in time IFEM::cout <<" * "; const ScalarFunc* s = parseTimeFunction(cline,nullptr,C); if (f) return new SpaceTimeFunc(f,s); else return new ConstTimeFunc(s); }
//MD5文件摘要 MD5VAL md5File(FILE * fpin) { if(!Buffer) Buffer=new char[BUFFER_SIZE+64]; char * buf=Buffer; MD5VAL val={0x67452301,0xefcdab89,0x98badcfe,0x10325476}; unsigned int &a=val.a, &b=val.b, &c=val.c, &d=val.d; unsigned int aa,bb,cc,dd; unsigned int i,j,count,co; unsigned int * x; i=0; do { count=fread(buf,1,BUFFER_SIZE,fpin); i+=count; if(count==BUFFER_SIZE) co=BUFFER_SIZE; else { j=count; buf[j++]=char(0x80); for(j;j%64!=56;j++) buf[j]=0x00; *(unsigned int *)(buf+j)=i<<3; j+=4; *(unsigned int *)(buf+j)=i>>29; j+=4; co=j; } for(j=0;j<co;j+=64) { x=(unsigned int *)(buf+j); // Save the values aa=a; bb=b; cc=c; dd=d; // Round 1 FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ // Round 2 GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ // Round 3 HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ // Round 4 */ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ // Add the original values a+=aa; b+=bb; c+=cc; d+=dd; } } while(count==BUFFER_SIZE); return val; }
static inline char clamp( double x ) { if( x > 1.0 ) x = 1.0; if( x < 0.0 ) x = 0.0; return char( floor( 255.99 * x )); }
//MD5摘要 MD5VAL md5(char * str, unsigned int size) { if(size==0) size=strlen(str); unsigned int m=size%64; unsigned int lm=size-m; //数据整块长度 unsigned int ln; //数据补位后长度 if(m<56) ln=lm+64; else ln=lm+128; char * strw=new char[ln]; unsigned int i; //复制原字串到缓冲区strw for(i=0;i<size;i++) strw[i]=str[i]; //补位 strw[i++]=char(0x80); for(i;i<ln-8;i++) strw[i]=0x00; //补长度 unsigned int * x=(unsigned int *)(strw+i); *(x++)=size<<3; *(x++)=size>>29; //初始化MD5参数 MD5VAL val={0x67452301,0xefcdab89,0x98badcfe,0x10325476}; unsigned int &a=val.a, &b=val.b, &c=val.c, &d=val.d; unsigned int aa,bb,cc,dd; for(i=0;i<ln;i+=64) { x=(unsigned int *)(strw+i); // Save the values aa=a; bb=b; cc=c; dd=d; // Round 1 FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ // Round 2 GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ // Round 3 HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ // Round 4 */ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ // Add the original values a+=aa; b+=bb; c+=cc; d+=dd; } delete[] strw; return val; }
void SmartHighlighter::highlightView(ScintillaEditView * pHighlightView) { //Get selection CharacterRange range = pHighlightView->getSelection(); //Clear marks pHighlightView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_SMART); //If nothing selected, dont mark anything if (range.cpMin == range.cpMax) { return; } int textlen = range.cpMax - range.cpMin + 1; char * text2Find = new char[textlen]; pHighlightView->getSelectedText(text2Find, textlen, false); //do not expand selection (false) //GETWORDCHARS for isQualifiedWord2() and isWordChar2() int listCharSize = pHighlightView->execute(SCI_GETWORDCHARS, 0, 0); char *listChar = new char[listCharSize+1]; pHighlightView->execute(SCI_GETWORDCHARS, 0, (LPARAM)listChar); listChar[listCharSize] = '\0'; bool valid = true; //The word has to consist if wordChars only, and the characters before and after something else if (!isQualifiedWord(text2Find, listChar)) valid = false; else { UCHAR c = (UCHAR)pHighlightView->execute(SCI_GETCHARAT, range.cpMax); if (c) { if (isWordChar(char(c), listChar)) valid = false; } c = (UCHAR)pHighlightView->execute(SCI_GETCHARAT, range.cpMin-1); if (c) { if (isWordChar(char(c), listChar)) valid = false; } } if (!valid) { delete [] text2Find; delete [] listChar; return; } // save target locations for other search functions int originalStartPos = (int)pHighlightView->execute(SCI_GETTARGETSTART); int originalEndPos = (int)pHighlightView->execute(SCI_GETTARGETEND); // Get the range of text visible and highlight everything in it int firstLine = (int)pHighlightView->execute(SCI_GETFIRSTVISIBLELINE); int nrLines = min((int)pHighlightView->execute(SCI_LINESONSCREEN), MAXLINEHIGHLIGHT ) + 1; int lastLine = firstLine+nrLines; int startPos = 0; int endPos = 0; int currentLine = firstLine; int prevDocLineChecked = -1; //invalid start const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI(); FindOption fo; fo._isMatchCase = nppGUI._smartHiliteCaseSensitive; fo._isWholeWord = true; const TCHAR * searchText = NULL; WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); unsigned int cp = pHighlightView->execute(SCI_GETCODEPAGE); const TCHAR * text2FindW = wmc->char2wchar(text2Find, cp); searchText = text2FindW; for(; currentLine < lastLine; ++currentLine) { int docLine = (int)pHighlightView->execute(SCI_DOCLINEFROMVISIBLE, currentLine); if (docLine == prevDocLineChecked) continue; //still on same line (wordwrap) prevDocLineChecked = docLine; startPos = (int)pHighlightView->execute(SCI_POSITIONFROMLINE, docLine); endPos = (int)pHighlightView->execute(SCI_POSITIONFROMLINE, docLine+1); if (endPos == -1) { //past EOF endPos = (int)pHighlightView->getCurrentDocLen() - 1; _pFRDlg->processRange(ProcessMarkAll_2, searchText, NULL, startPos, endPos, NULL, &fo); break; } else { _pFRDlg->processRange(ProcessMarkAll_2, searchText, NULL, startPos, endPos, NULL, &fo); } } // restore the original targets to avoid conflicts with the search/replace functions pHighlightView->execute(SCI_SETTARGETSTART, originalStartPos); pHighlightView->execute(SCI_SETTARGETEND, originalEndPos); delete [] listChar; }
static char map_char(char a_, int b_) { return char(a_ + b_); }
// copy aSource strings into contiguous storage provided in aDest1, // providing terminating nulls for each destination string. static inline void StrBlockCopy(const nsACString &aSource1, const nsACString &aSource2, const nsACString &aSource3, const nsACString &aSource4, char *&aDest1, char *&aDest2, char *&aDest3, char *&aDest4, char *&aDestEnd) { char *toBegin = aDest1; nsACString::const_iterator fromBegin, fromEnd; *copy_string(aSource1.BeginReading(fromBegin), aSource1.EndReading(fromEnd), toBegin) = char(0); aDest2 = ++toBegin; *copy_string(aSource2.BeginReading(fromBegin), aSource2.EndReading(fromEnd), toBegin) = char(0); aDest3 = ++toBegin; *copy_string(aSource3.BeginReading(fromBegin), aSource3.EndReading(fromEnd), toBegin) = char(0); aDest4 = ++toBegin; *copy_string(aSource4.BeginReading(fromBegin), aSource4.EndReading(fromEnd), toBegin) = char(0); aDestEnd = toBegin; }
static inline char as_char(int v) { return v >= 0 && v < 10 ? ('0' + char(v)) : '-'; }
QMimeMagicRule::QMimeMagicRule(QMimeMagicRule::Type theType, const QByteArray &theValue, int theStartPos, int theEndPos, const QByteArray &theMask) : d(new QMimeMagicRulePrivate) { Q_ASSERT(!theValue.isEmpty()); d->type = theType; d->value = theValue; d->startPos = theStartPos; d->endPos = theEndPos; d->mask = theMask; d->matchFunction = 0; if (d->type >= Host16 && d->type <= Byte) { bool ok; d->number = d->value.toUInt(&ok, 0); // autodetect Q_ASSERT(ok); d->numberMask = !d->mask.isEmpty() ? d->mask.toUInt(&ok, 0) : 0; // autodetect } switch (d->type) { case String: d->pattern = makePattern(d->value); d->pattern.squeeze(); if (!d->mask.isEmpty()) { Q_ASSERT(d->mask.size() >= 4 && d->mask.startsWith("0x")); d->mask = QByteArray::fromHex(QByteArray::fromRawData(d->mask.constData() + 2, d->mask.size() - 2)); Q_ASSERT(d->mask.size() == d->pattern.size()); } else { d->mask.fill(char(-1), d->pattern.size()); } d->mask.squeeze(); d->matchFunction = matchString; break; case Byte: if (d->number <= quint8(-1)) { if (d->numberMask == 0) d->numberMask = quint8(-1); d->matchFunction = matchNumber<quint8>; } break; case Big16: case Host16: case Little16: if (d->number <= quint16(-1)) { d->number = d->type == Little16 ? qFromLittleEndian<quint16>(d->number) : qFromBigEndian<quint16>(d->number); if (d->numberMask == 0) d->numberMask = quint16(-1); d->matchFunction = matchNumber<quint16>; } break; case Big32: case Host32: case Little32: if (d->number <= quint32(-1)) { d->number = d->type == Little32 ? qFromLittleEndian<quint32>(d->number) : qFromBigEndian<quint32>(d->number); if (d->numberMask == 0) d->numberMask = quint32(-1); d->matchFunction = matchNumber<quint32>; } break; default: break; } }
String UtilsSDEthernet::getLine(EthernetClient clientIn, char* nomFichierIn, int lineNumberIn, boolean debug) { // la fonctin reçoit : // > le client Ethernet à utiliser // > le nom du fichier // > le numéro de la ligne // > un drapeau pour messages debug // la fonction renvoie le String correspondant à la ligne File dataFileIn=SD.open(nomFichierIn, FILE_READ); // ouvre le fichier en lecture - NOM FICHIER en 8.3 ++++ if (debug) clientIn.println("------"); //int line=1499; // numero de la ligne voulue - 1ère ligne = ligne 1 String strLine=""; int comptLine=0; int lastPosition=0; // dernière position int currentPosition=0; // dernière position if (dataFileIn){ // le fichier est True si créé if (debug)clientIn.println(F("Ouverture fichier OK")); while (dataFileIn.available()) { // tant que des données sont disposnibles dans le fichier // le fichier peut etre considéré comme un "buffer" de données comme le buffer du port série char c = dataFileIn.read(); // lit le caractère suivant //Serial.print(c); // affiche le caractère courant if (c==10) { // si le caractère est \n : c'est une fin de ligne comptLine=comptLine+1; if (comptLine==lineNumberIn) { // si on a atteint la ligne voulue currentPosition=dataFileIn.position(); // mémorise la position actuelle for (int i=lastPosition; i<currentPosition; i++) { // on défile de la dernière position retenue à la position courante dataFileIn.seek(i); // se position en i strLine=strLine+char(dataFileIn.read()); // ajoute le caractère au strLine } // fin for break; // sort du while }// fin if arrivé à la ligne voulue lastPosition=dataFileIn.position(); //Serial.print ("lastPosition : "); //Serial.println (lastPosition); } // fin if saut de ligne //contenuFichier=contenuFichier+c; // ajoute le char au String } // fin while available dataFileIn.close(); // fermeture du fichier obligatoire après accès if (debug) clientIn.println(F("ligne voulue : ")); if (debug) clientIn.println(strLine); if (debug) clientIn.println(F("------")); //Serial.println("Contenu du fichier : "); //Serial.println(contenuFichier); // affiche le contenu du fichier } // si fichier existe else { // sinon = si probleme creation clientIn.println(F("Probleme creation fichier")); } // fin else return(strLine); } // fin fonction getLine
void CAlignTest::Help( const char * arg ) { cout << "usage: [-hV] [-r h|s|f] [-c +|-] [-q rc] [-s rc] [-R +|-] [-Q qoffset] [-S soffset] query subj\n" << "where:\n" << " --algorithm=h|s|f -r h|s|f algorithm to use (HSP, Smith-Waterman, Fast) [" << char( m_algo ) << "]\n" << " --colorspace=yes|no -c yes|no align in colorspace [" << (m_flags & fAlign_colorspace ? "yes" : "no") << "]\n" << " --query-strand=+|- -q +|- use query strand [" << (m_flags & fQuery_reverse ? "-":"+" ) << "]\n" << " --subject-strand=+|- -s +|- use subject strand [" << (m_flags & fSubject_reverse ? "-":"+" ) << "]\n" << " --query-offset=off -Q off use position off on query as seeding position [" << m_offsetQuery << "]\n" << " --subject-offset=off -S off use position off on subject as seeding position [" << m_offsetQuery << "]\n" << " --score-identity=val -I val identity score [" << m_identityScore << "]\n" << " --score-mismatch=val -M val mismatch score [" << m_mismatchScore << "]\n" << " --score-gap-opening=val -G val gap opening score [" << m_gapOpeningScore << "]\n" << " --score-gap-extention=v -g val gap extention score [" << m_gapExtentionScore << "]\n" << " --x-dropoff=val -X val maximal gap width for -rs [" << m_xDropoff << "]\n" ; }
/** \brief Test for PlanarFigure reader and writer classes. * * The test works as follows: * * First, a number of PlanarFigure objects of different types are created and placed with * various control points. These objects are the serialized to file, read again from file, and * the retrieved objects are compared with their control points, properties, and geometry * information to the original PlanarFigure objects. */ int mitkPlanarFigureIOTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("PlanarFigureIO"); // Create a number of PlanarFigure objects PlanarFigureIOTestClass::PlanarFigureList originalPlanarFigures = PlanarFigureIOTestClass::CreatePlanarFigures(); // Create a number of "deep-copied" planar figures to test the DeepCopy function PlanarFigureIOTestClass::PlanarFigureList copiedPlanarFigures = PlanarFigureIOTestClass::CreateDeepCopiedPlanarFigures(originalPlanarFigures); PlanarFigureIOTestClass::VerifyPlanarFigures(originalPlanarFigures, copiedPlanarFigures ); // Write PlanarFigure objects into temp file // tmpname static unsigned long count = 0; unsigned long n = count++; std::ostringstream name; for (int i = 0; i < 6; ++i) { name << char('a' + (n % 26)); n /= 26; } std::string myname; myname.append(name.str()); std::string fileName = itksys::SystemTools::GetCurrentWorkingDirectory() + myname + ".pf"; PlanarFigureIOTestClass::SerializePlanarFigures( originalPlanarFigures, fileName ); // Write PlanarFigure objects to memory buffers PlanarFigureIOTestClass::PlanarFigureToMemoryWriterList writersWithMemoryBuffers = PlanarFigureIOTestClass::SerializePlanarFiguresToMemoryBuffers( originalPlanarFigures ); // Read PlanarFigure objects from temp file PlanarFigureIOTestClass::PlanarFigureList retrievedPlanarFigures = PlanarFigureIOTestClass::DeserializePlanarFigures( fileName ); // Read PlanarFigure objects from memory buffers PlanarFigureIOTestClass::PlanarFigureList retrievedPlanarFiguresFromMemory = PlanarFigureIOTestClass::DeserializePlanarFiguresFromMemoryBuffers( writersWithMemoryBuffers ); PlanarFigureIOTestClass::PlanarFigureToMemoryWriterList::iterator it = writersWithMemoryBuffers.begin(); while(it != writersWithMemoryBuffers.end()) { (*it)->ReleaseMemory(); ++it; } // Test if original and retrieved PlanarFigure objects are the same PlanarFigureIOTestClass::VerifyPlanarFigures( originalPlanarFigures, retrievedPlanarFigures ); // Test if original and memory retrieved PlanarFigure objects are the same PlanarFigureIOTestClass::VerifyPlanarFigures( originalPlanarFigures, retrievedPlanarFiguresFromMemory ); //empty the originalPlanarFigures originalPlanarFigures.empty(); // Test if deep-copied and retrieved PlanarFigure objects are the same PlanarFigureIOTestClass::VerifyPlanarFigures( copiedPlanarFigures, retrievedPlanarFigures ); MITK_TEST_END() }
/** * Skybox.handleInput() * Handles user input. */ void Skybox::handleInput() { // Toggle Skybox drawing. if(io.toggled(GLFW_KEY_G)) { drawState = char((drawState + 1) % 3); } }
int main(int argc,char* argv[]) { char* params = NULL; char gauge_name[qcd_MAX_STRING_LENGTH]; char param_name[qcd_MAX_STRING_LENGTH]; qcd_int_4 x_src[4], lx_src[4], nsmear, nsmearAPE, mom[4], mom_min, mom_max, mom_loop, dir_loop, mom_step; qcd_real_8 alpha,alphaAPE,plaq; int params_len; qcd_int_4 t_start, t_stop, t, lt, x, y, z; qcd_int_4 ctr, ctr2; qcd_uint_4 dir; qcd_uint_4 lt_sink, t_sink, lx, ly, lz, s; qcd_real_8 zeta; qcd_real_8 theta[4] = {M_PI,0.0,0.0,0.0}; // antiperiodic b.c. in time qcd_uint_2 fl, pr, mu, nu, ku, lu, gu, ju, bu, cu, c1, c2, c3, cc1, cc2, c1p, c2p , c3p, nprojs, mom_0_done=0; qcd_geometry geo; qcd_gaugeField u, uAPE, uAPE2, u_ms; qcd_gaugeField *u_ptr, *uAPE_ptr, *utmp_ptr ; qcd_propagator prop[2], prop_pb[2]; qcd_vector vec, vec_mg; qcd_uint_2 P[4]; qcd_uint_2 L[4]; qcd_uint_8 i,j; //lattice sites qcd_real_8 tmp; //complex phase factor qcd_complex_16 tmp_c; /**** for threep ****/ qcd_uint_2 *proj_type; qcd_gaugeField u_temp, u_shift_f, u_shift_b, u_prod_f, u_prod_b; qcd_propagator prop_temp, prop_shift_f[2], prop_shift_b[2]; qcd_propagator prop_ms[2], (*prop_seq)[2] ; char (*prop_seq_name)[2][qcd_MAX_STRING_LENGTH], (*source_seq_name)[2][qcd_MAX_STRING_LENGTH]; qcd_complex_16 *block_f, *block_b ; qcd_complex_16 (**threep_loc_f)[2], (**threep_loc_b)[2]; qcd_complex_16 (***threep_f)[2], (***threep_b)[2]; /***************/ qcd_uint_4 k; char threep_name[qcd_MAX_STRING_LENGTH]; char twop_mes_name[qcd_MAX_STRING_LENGTH]; char twop_nucl_name[qcd_MAX_STRING_LENGTH]; char tmp_string[qcd_MAX_STRING_LENGTH]; char prop_name[2][qcd_MAX_STRING_LENGTH]; char tmp_s[15]; int myid,numprocs, namelen; char processor_name[MPI_MAX_PROCESSOR_NAME]; qcd_complex_16 (**block_mes)[2], twop_mes_loc[2], twop_nucl_loc[16]; qcd_complex_16 *(*block_nucl)[4][4]; qcd_complex_16 (*twop_mes)[2];//pi+, pi- qcd_complex_16 (*twop_nucl)[2][16];// p, n qcd_complex_16 one_pm_ig5[2][4],g5[4]; //-for transformation purposes qcd_uint_2 cg5cg5_ind[16][4]; qcd_complex_16 cg5cg5_val[16]; FILE *pfile; MG4QCD_Init mg_init; MG4QCD_Parameters mg_params; MG4QCD_Status mg_status; inline void *replace_str(char *str, char *orig, char *rep) { static char temp[qcd_MAX_STRING_LENGTH]; static char buffer[qcd_MAX_STRING_LENGTH]; char *p; strcpy(temp, str); if(!(p = strstr(temp, orig))) // Is 'orig' even in 'temp'? return temp; strncpy(buffer, temp, p-temp); // Copy characters from 'temp' start to 'orig' str buffer[p-temp] = '\0'; sprintf(buffer + (p - temp), "%s%s", rep, p + strlen(orig)); sprintf(str, "%s", buffer); } inline int conf_index_fct(int t, int z, int y, int x, int mu) { //T Z Y X int pos = qcd_LEXIC(t,x,y,z,geo.lL); static int size_per_pos = 4*3*3*2; //link*SU(3)*complex int dir = (mu==1)?3:((mu==3)?1:mu); //swapping Z with X static int size_per_dir = 3*3*2; return pos*size_per_pos + dir*size_per_dir; }