char KBD_read(void){ // set the pull ups in row on KEYPAD_PORT =0x0f; uint8_t keyCount=0; uint8_t keyCode =0xff; // loop columns for (uint8_t col=0; col <3; col++){ KEYPAD_DDR &=~(0x7F); KEYPAD_DDR |=(0x40 >>col); for(uint8_t row=0; row <4; row++){ if((KEYPAD_PIN &(0x08 >>row))==0){ keyCount ++; keyCode =(row*3+col); // (00)(01)(02) } } } // decode code if(keyCount == 1){ return decodeKey(keyCode); } return NULL; }
bool deserializeIDBKeyData(const uint8_t* data, size_t size, IDBKeyData& result) { if (!data || !size) return false; #if USE(CF) if (data[0] == LegacySerializedKeyVersion) { auto decoder = KeyedDecoder::decoder(data, size); return IDBKeyData::decode(*decoder, result); } // Verify this is a SerializedIDBKey version we understand. const uint8_t* current = data; const uint8_t* end = data + size; if (current++[0] != SIDBKeyVersion) return false; if (decodeKey(current, end, result)) { // Even if we successfully decoded a key, the deserialize is only successful // if we actually consumed all input data. return current == end; } return false; #else auto decoder = KeyedDecoder::decoder(data, size); return IDBKeyData::decode(*decoder, result); #endif }
int main() { char *line = NULL; size_t size; initSegIndex(); initSegCounter(); while(getline(&line, &size, stdin) != -1) { char *key = NULL; char *val = NULL; parseEntry(line, size, &key, &val); if(key==NULL) continue; decodeKey(key); decodeVal(val); // hash_set(index, key, val); } // readline - mallocs space free(line); // fprintf(stderr, "Hash values: %d\n", hash_size(index)); // hash_each(index, { // printf("%s: %s\n", key, (char *) val); // // release key/val - parseEntry strdup key/val on heap // free((char *)key); // free((char *)val); // }); // hash_free(index); printSegCounter(); clearSegCounter(); clearSegIndex(); return 0; }
void KConfigINIBackEnd::parseSingleConfigFile(QFile &rFile, KEntryMap *pWriteBackMap, bool bGlobal, bool bDefault) { const char *s; // May get clobbered by sigsetjump, but we don't use them afterwards. const char *eof; // May get clobbered by sigsetjump, but we don't use them afterwards. QByteArray data; if(!rFile.isOpen()) // come back, if you have real work for us ;-> return; // using kdDebug() here leads to an infinite loop // remove this for the release, aleXXX // qWarning("Parsing %s, global = %s default = %s", // rFile.name().latin1(), bGlobal ? "true" : "false", bDefault ? "true" : "false"); QCString aCurrentGroup("<default>"); unsigned int ll = localeString.length(); #ifdef HAVE_MMAP static volatile const char *map; map = (const char *)mmap(0, rFile.size(), PROT_READ, MAP_PRIVATE, rFile.handle(), 0); if(map != MAP_FAILED) { s = (const char *)map; eof = s + rFile.size(); #ifdef SIGBUS struct sigaction act; act.sa_handler = mmap_sigbus_handler; sigemptyset(&act.sa_mask); #ifdef SA_ONESHOT act.sa_flags = SA_ONESHOT; #else act.sa_flags = SA_RESETHAND; #endif sigaction(SIGBUS, &act, &mmap_old_sigact); if(sigsetjmp(mmap_jmpbuf, 1)) { qWarning("SIGBUS while reading %s", rFile.name().latin1()); munmap((char *)map, rFile.size()); sigaction(SIGBUS, &mmap_old_sigact, 0); return; } #endif } else #endif { rFile.at(0); data = rFile.readAll(); s = data.data(); eof = s + data.size(); } bool fileOptionImmutable = false; bool groupOptionImmutable = false; bool groupSkip = false; int line = 0; for(; s < eof; s++) { line++; while((s < eof) && isspace(*s) && (*s != '\n')) s++; // skip leading whitespace, shouldn't happen too often // skip empty lines, lines starting with # if((s < eof) && ((*s == '\n') || (*s == '#'))) { sktoeol: // skip till end-of-line while((s < eof) && (*s != '\n')) s++; continue; // Empty or comment or no keyword } const char *startLine = s; if(*s == '[') // group { // In a group [[ and ]] have a special meaning while((s < eof) && (*s != '\n')) { if(*s == ']') { if((s + 1 < eof) && (*(s + 1) == ']')) s++; // Skip "]]" else break; } s++; // Search till end of group } const char *e = s; while((s < eof) && (*s != '\n')) s++; // Search till end of line / end of file if((e >= eof) || (*e != ']')) { fprintf(stderr, "Invalid group header at %s:%d\n", rFile.name().latin1(), line); continue; } // group found; get the group name by taking everything in // between the brackets if((e - startLine == 3) && (startLine[1] == '$') && (startLine[2] == 'i')) { if(!kde_kiosk_exception) fileOptionImmutable = true; continue; } aCurrentGroup = decodeGroup(startLine + 1, e - startLine); // cout<<"found group ["<<aCurrentGroup<<"]"<<endl; // Backwards compatibility if(aCurrentGroup == "KDE Desktop Entry") aCurrentGroup = "Desktop Entry"; groupOptionImmutable = fileOptionImmutable; e++; if((e + 2 < eof) && (*e++ == '[') && (*e++ == '$')) // Option follows { if((*e == 'i') && !kde_kiosk_exception) { groupOptionImmutable = true; } } KEntryKey groupKey(aCurrentGroup, 0); KEntry entry = pConfig->lookupData(groupKey); groupSkip = entry.bImmutable; if(groupSkip && !bDefault) continue; entry.bImmutable |= groupOptionImmutable; pConfig->putData(groupKey, entry, false); if(pWriteBackMap) { // add the special group key indicator (*pWriteBackMap)[groupKey] = entry; } continue; } if(groupSkip && !bDefault) goto sktoeol; // Skip entry bool optionImmutable = groupOptionImmutable; bool optionDeleted = false; bool optionExpand = false; const char *endOfKey = 0, *locale = 0, *elocale = 0; for(; (s < eof) && (*s != '\n'); s++) { if(*s == '=') // find the equal sign { if(!endOfKey) endOfKey = s; goto haveeq; } if(*s == '[') // find the locale or options. { const char *option; const char *eoption; endOfKey = s; option = ++s; for(;; s++) { if((s >= eof) || (*s == '\n') || (*s == '=')) { fprintf(stderr, "Invalid entry (missing ']') at %s:%d\n", rFile.name().latin1(), line); goto sktoeol; } if(*s == ']') break; } eoption = s; if(*option != '$') { // Locale if(locale) { fprintf(stderr, "Invalid entry (second locale!?) at %s:%d\n", rFile.name().latin1(), line); goto sktoeol; } locale = option; elocale = eoption; } else { // Option while(option < eoption) { option++; if((*option == 'i') && !kde_kiosk_exception) optionImmutable = true; else if(*option == 'e') optionExpand = true; else if(*option == 'd') { optionDeleted = true; goto haveeq; } else if(*option == ']') break; } } } } fprintf(stderr, "Invalid entry (missing '=') at %s:%d\n", rFile.name().latin1(), line); continue; haveeq: for(endOfKey--;; endOfKey--) { if(endOfKey < startLine) { fprintf(stderr, "Invalid entry (empty key) at %s:%d\n", rFile.name().latin1(), line); goto sktoeol; } if(!isspace(*endOfKey)) break; } const char *st = ++s; while((s < eof) && (*s != '\n')) s++; // Search till end of line / end of file if(locale) { unsigned int cl = static_cast< unsigned int >(elocale - locale); if((ll != cl) || memcmp(locale, localeString.data(), ll)) { // backward compatibility. C == en_US if(cl != 1 || ll != 5 || *locale != 'C' || memcmp(localeString.data(), "en_US", 5)) { // cout<<"mismatched locale '"<<QCString(locale, elocale-locale +1)<<"'"<<endl; // We can ignore this one if(!pWriteBackMap) continue; // We just ignore it // We just store it as is to be able to write it back later. endOfKey = elocale; locale = 0; } } } // insert the key/value line QCString key(startLine, endOfKey - startLine + 2); QCString val = printableToString(st, s - st); // qDebug("found key '%s' with value '%s'", key.data(), val.data()); KEntryKey aEntryKey(aCurrentGroup, decodeKey(key)); aEntryKey.bLocal = (locale != 0); aEntryKey.bDefault = bDefault; KEntry aEntry; aEntry.mValue = val; aEntry.bGlobal = bGlobal; aEntry.bImmutable = optionImmutable; aEntry.bDeleted = optionDeleted; aEntry.bExpand = optionExpand; aEntry.bNLS = (locale != 0); if(pWriteBackMap) { // don't insert into the config object but into the temporary // scratchpad map pWriteBackMap->insert(aEntryKey, aEntry); } else { // directly insert value into config object // no need to specify localization; if the key we just // retrieved was localized already, no need to localize it again. pConfig->putData(aEntryKey, aEntry, false); } } if(fileOptionImmutable) bFileImmutable = true; #ifdef HAVE_MMAP if(map) { munmap((char *)map, rFile.size()); #ifdef SIGBUS sigaction(SIGBUS, &mmap_old_sigact, 0); #endif } #endif }
int main(int argc, char **argv) { //! # Algorithm structure //! ## Initialization ros::init(argc, argv, "rollo_control"); ros::start(); //! - Initialize nodehandle for publisher ros::NodeHandle RolloControlNode; //! - Publisher initialization with topic, message format and queue size definition ros::Publisher RolloTwist = RolloControlNode.advertise<geometry_msgs::Twist>(TopicCmdVel, 1024); //! - Node arguments using command line int rate_frequency; //! - Initialize node parameters from launch file or command line. //! Use a private node handle so that multiple instances of the node can be run simultaneously //! while using different parameters. ros::NodeHandle private_node_handle_("~"); private_node_handle_.param("rate", rate_frequency, int(100)); //! - Publishing rate [Hz] ros::Rate frequency(rate_frequency); //! - Publisher variables for conventional messages geometry_msgs::Twist PubRolloCmd; //! - Initialize variables for computing linear and angular velocity of the robot double Speed = 0; double Turn = 0; double LastTurn = 0; //! - Initialize character holder char c = 0; //! ## Main loop while (ros::ok()) { //! - Check if a key is pressed: //! - Read character //! - Decode key pressed if (kbhit()) { // Read character c = getchar(); // Decode key pressed decodeKey(c, Speed, Turn, LastTurn); } //! - Prepare message to publish linear and angular velocities PubRolloCmd.linear.x = Speed; PubRolloCmd.angular.z = Turn; //! - Print message with velocities ROS_INFO("[Rollo][%s][Pub] Linear speed [%f] Angular speed [%f]", NodeName, PubRolloCmd.linear.x, PubRolloCmd.angular.z); //! - Publish message in Twist format RolloTwist.publish(PubRolloCmd); //! - ROS spinOnce ros::spinOnce(); //! - Sleep to conform node frequency rate frequency.sleep(); } //! ## Main loop end return 0; }
static bool decodeKey(const uint8_t*& data, const uint8_t* end, IDBKeyData& result) { if (!data || data >= end) return false; SIDBKeyType type = static_cast<SIDBKeyType>(data++[0]); switch (type) { case SIDBKeyType::Min: result = IDBKeyData::minimum(); return true; case SIDBKeyType::Max: result = IDBKeyData::maximum(); return true; case SIDBKeyType::Number: { double d; if (!readDouble(data, end, d)) return false; result.setNumberValue(d); return true; } case SIDBKeyType::Date: { double d; if (!readDouble(data, end, d)) return false; result.setDateValue(d); return true; } case SIDBKeyType::String: { uint32_t length; if (!readLittleEndian(data, end, length)) return false; if (static_cast<uint64_t>(end - data) < length * 2) return false; Vector<UChar> buffer; buffer.reserveInitialCapacity(length); for (size_t i = 0; i < length; i++) { uint16_t ch; if (!readLittleEndian(data, end, ch)) return false; buffer.uncheckedAppend(ch); } result.setStringValue(String::adopt(WTFMove(buffer))); return true; } case SIDBKeyType::Binary: { uint64_t size64; if (!readLittleEndian(data, end, size64)) return false; if (static_cast<uint64_t>(end - data) < size64) return false; if (size64 > std::numeric_limits<size_t>::max()) return false; size_t size = static_cast<size_t>(size64); Vector<uint8_t> dataVector; dataVector.append(data, size); data += size; result.setBinaryValue(ThreadSafeDataBuffer::adoptVector(dataVector)); return true; } case SIDBKeyType::Array: { uint64_t size64; if (!readLittleEndian(data, end, size64)) return false; if (size64 > std::numeric_limits<size_t>::max()) return false; size_t size = static_cast<size_t>(size64); Vector<IDBKeyData> array; array.reserveInitialCapacity(size); for (size_t i = 0; i < size; ++i) { IDBKeyData keyData; if (!decodeKey(data, end, keyData)) return false; ASSERT(keyData.isValid()); array.uncheckedAppend(WTFMove(keyData)); } result.setArrayValue(array); return true; } default: LOG_ERROR("decodeKey encountered unexpected type: %i", (int)type); return false; } }