//////////////////////////////////////////////////////////////////////////////// // Lexer::Type::substitution // / <unquoted-string> / <unquoted-string> / [g] <EOS> | <isWhitespace> bool Lexer::isSubstitution (std::string& token, Lexer::Type& type) { std::size_t marker = _cursor; std::string word; if (readWord (_text, "/", _cursor, word)) { --_cursor; // Step backwards over the '/'. if (readWord (_text, "/", _cursor, word)) { if (_text[_cursor] == 'g') ++_cursor; // Lookahread: <EOS> | <isWhitespace> if (_text[_cursor] == '\0' || isWhitespace (_text[_cursor])) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::substitution; return true; } } } _cursor = marker; return false; }
void getUsrName(int procUID, char usr[], int size){ char etcUser[MAX_LEN] ; char etcPass[MAX_LEN] ; char etcUserId[MAX_LEN] ; char filename[] = "/etc/passwd"; int fd, i; if((fd = open(filename, O_RDONLY)) < 0){ printf(1, "login.c:getUsrName: Error cannot open file '%s'\n", filename); exit(); } // compare the username and password given against each user and password in the file for(i = 0; i < NUM_OF_USERS ; i++){ // zero out buffers zeroOutBuffer(etcUser, sizeof(etcUser)); zeroOutBuffer(etcPass, sizeof(etcPass)); zeroOutBuffer(etcUserId, sizeof(etcUserId)); // read one user info from file readWord(fd, etcUser, sizeof(etcUser)); readWord(fd, etcPass, sizeof(etcPass)); readWord(fd, etcUserId, sizeof(etcUserId)); if(procUID == atoi(etcUserId)){ strcpy(usr, etcUser); } } close(fd); }
//////////////////////////////////////////////////////////////////////////////// // / <from> / <to> / [<flags>] bool Lexer::decomposeSubstitution ( const std::string& text, std::string& from, std::string& to, std::string& flags) { std::string parsed_from; std::string::size_type cursor = 0; if (readWord (text, "/", cursor, parsed_from) && parsed_from.length ()) { --cursor; std::string parsed_to; if (readWord (text, "/", cursor, parsed_to)) { std::string parsed_flags = text.substr (cursor); if (parsed_flags.find ("/") == std::string::npos) { dequote (parsed_from, "/"); dequote (parsed_to, "/"); from = parsed_from; to = parsed_to; flags = parsed_flags; return true; } } } return false; }
void farLoad() { if (!useMemory) runtimeError("This instruction needs a memory address"); savedIP = readWord(address); savedCS = readWord(address + 2); }
//////////////////////////////////////////////////////////////////////////////// // Lexer::Type::pair // <identifier> <separator> [ <string> | <word> ] // separator '::' | ':=' | ':' | '=' bool Lexer::isPair (std::string& token, Lexer::Type& type) { std::size_t marker = _cursor; std::string ignoredToken; Lexer::Type ignoredType; if (isIdentifier (ignoredToken, ignoredType)) { // Look for a valid separator. std::string separator = _text.substr (_cursor, 2); if (separator == "::" || separator == ":=") _cursor += 2; else if (separator[0] == ':' || separator[0] == '=') _cursor++; else { _cursor = marker; return false; } // String, word or nothing are all valid. if (readWord (_text, "'\"", _cursor, ignoredToken) || readWord (_text, _cursor, ignoredToken) || isEOS () || isWhitespace (_text[_cursor])) { token = _text.substr (marker, _cursor - marker); type = Lexer::Type::pair; return true; } } _cursor = marker; return false; }
MessageIn Network::getNextMessage() { while (!messageReady()) { if (mState == NET_ERROR) break; } SDL_mutexP(mMutex); int msgId = readWord(0); int len; if (msgId == SMSG_SERVER_VERSION_RESPONSE) len = 10; else if (msgId == SMSG_UPDATE_HOST2) len = -1; else len = packet_lengths[msgId]; if (len == -1) len = readWord(2); #ifdef ENABLEDEBUGLOG // logger->dlog(strprintf("Received packet 0x%x of length %d\n", // msgId, len)); #endif MessageIn msg(mInBuffer, len); SDL_mutexV(mMutex); return msg; }
bool Network::messageReady() { int len = -1; SDL_mutexP(mMutexIn); if (mInSize >= 2) { const int msgId = readWord(0); if (msgId == SMSG_SERVER_VERSION_RESPONSE) { len = 10; } else { if (msgId >= 0 && static_cast<unsigned int>(msgId) < packet_lengths_size) { len = packet_lengths[msgId]; } } if (len == -1 && mInSize > 4) len = readWord(2); } const bool ret = (mInSize >= static_cast<unsigned int>(len)); SDL_mutexV(mMutexIn); return ret; }
MessageIn Network::getNextMessage() { while (!messageReady()) { if (mState == NET_ERROR) break; } MutexLocker lock(&mMutex); uint16_t msgId = readWord(0); uint16_t len = 0; if (msgId == SMSG_SERVER_VERSION_RESPONSE) len = 10; else if (msgId < 0x220) len = packet_lengths[msgId]; if (len == VAR) len = readWord(2); #ifdef DEBUG logger->log("Received packet 0x%x of length %d", msgId, len); #endif return MessageIn(mInBuffer, len); }
unsigned int getWavFileLength(char *fileName) { // TBD: This function MUST be fixed - it currently returns an incorrect value, becuase - vals dont always mean it's done. unsigned int fileLength = 0; short int fileHandle = openFile(fileName); if (fileHandle == -1) { printf("Error occurred, unable to open file in 'getFileLength' with name: %s", fileName); } readPastWavHeader(fileHandle); // to get wav file length, dont bypass header i think.. short int wordRead = readWord(fileHandle); //unsigned char firstByte = 0x0000FFFF | wordRead; //unsigned char secondByte = 0x0000FFFF | (wordRead >> 8); while ((short int)wordRead >= 0) { //printf("%c", (unsigned char)byteRead); fileLength += 2; wordRead = readWord(fileHandle); } if ((short int)wordRead <= -1) { printf("Error reading bytes from %s\n", fileName); } closeFile(fileHandle); return fileLength; }
void SX1509::writePin(byte pin, byte highLow) { unsigned int tempRegDir = readWord(REG_DIR_B); if ((0xFFFF^tempRegDir)&(1<<pin)) // If the pin is an output, write high/low { unsigned int tempRegData = readWord(REG_DATA_B); if (highLow) tempRegData |= (1<<pin); else tempRegData &= ~(1<<pin); writeWord(REG_DATA_B, tempRegData); } else // Otherwise the pin is an input, pull-up/down { unsigned int tempPullUp = readWord(REG_PULL_UP_B); unsigned int tempPullDown = readWord(REG_PULL_DOWN_B); if (highLow) // if HIGH, do pull-up, disable pull-down { tempPullUp |= (1<<pin); tempPullDown &= ~(1<<pin); writeWord(REG_PULL_UP_B, tempPullUp); writeWord(REG_PULL_DOWN_B, tempPullDown); } else // If LOW do pull-down, disable pull-up { tempPullDown |= (1<<pin); tempPullUp &= ~(1<<pin); writeWord(REG_PULL_UP_B, tempPullUp); writeWord(REG_PULL_DOWN_B, tempPullDown); } } }
struct GPatch * gusload(char * filename) { struct GPatch * gp = (struct GPatch *)malloc(sizeof(struct GPatch)); rb->memset(gp, 0, sizeof(struct GPatch)); int file = rb->open(filename, O_RDONLY); if(file < 0) { char message[50]; rb->snprintf(message, 50, "Error opening %s", filename); rb->splash(HZ*2, message); return NULL; } gp->header=readData(file, 12); gp->gravisid=readData(file, 10); gp->desc=readData(file, 60); gp->inst=readChar(file); gp->voc=readChar(file); gp->chan=readChar(file); gp->numWaveforms=readWord(file); gp->vol=readWord(file); gp->datSize=readDWord(file); gp->res=readData(file, 36); gp->instrID=readWord(file); gp->instrName=readData(file,16); gp->instrSize=readDWord(file); gp->layers=readChar(file); gp->instrRes=readData(file,40); gp->layerDup=readChar(file); gp->layerID=readChar(file); gp->layerSize=readDWord(file); gp->numWaves=readChar(file); gp->layerRes=readData(file,40); /* printf("\nFILE: %s", filename); */ /* printf("\nlayerSamples=%d", gp->numWaves); */ int a=0; for(a=0; a<gp->numWaves; a++) gp->waveforms[a] = loadWaveform(file); /* printf("\nPrecomputing note table"); */ for(a=0; a<128; a++) { gp->noteTable[a] = selectWaveform(gp, a); } rb->close(file); return gp; }
//purpose: parse a BMP file and package in a BMP structure void parseBmp (char *fileName, BMP *bmp) { int i, j, k; char b, g, r; int pixels, rowOffset, offset; short int fh; fh = openFile(fileName); bmp->header.type = readWord(fh); bmp->header.size = readDWord(fh); bmp->header.reserved1 = readWord(fh); bmp->header.reserved2 = readWord(fh); bmp->header.offset = readDWord(fh); bmp->infoheader.size = readDWord(fh); bmp->infoheader.width = readDWord(fh); bmp->infoheader.height = readDWord(fh); bmp->infoheader.planes = readWord(fh); bmp->infoheader.bits = readWord(fh); bmp->infoheader.compression = readDWord(fh); bmp->infoheader.imagesize = readDWord(fh); bmp->infoheader.xresolution = readDWord(fh); bmp->infoheader.yresolution = readDWord(fh); bmp->infoheader.ncolors = readDWord(fh); bmp->infoheader.importantcolors = readDWord(fh); pixels = bmp->infoheader.width * bmp->infoheader.height; bmp->color = malloc(BYTES_PER_PIXEL * pixels); for(i = 0; i < bmp->infoheader.height; i++) { rowOffset = i*bmp->infoheader.width; for(j = 0; j < bmp->infoheader.width; j++ ){ offset = pixels - rowOffset - j - 1; b = (readByte(fh) & 0xF1) >> 3; g = (readByte(fh) & 0xFC) >> 2; r = (readByte(fh) & 0xF1) >> 3; //Filter out the pink pixels if(b == 0x1E && g == 0 && r == 0x1E) { bmp->color[offset] = 0x0; } else { bmp->color[offset] = (r << 11) | (g << 5) | b; } } if((BYTES_PER_PIXEL*bmp->infoheader.width) % 4 != 0) { for (k = 0; k < (4 - ((BYTES_PER_PIXEL*bmp->infoheader.width) % 4)); k++) { readByte(fh); } } } closeFile(fh); }
void readReplica(Uint32 &index, Uint32 *buf) { Uint32 i; Uint32 procNode = readWord(index, buf); Uint32 initialGci = readWord(index, buf); Uint32 numCrashedReplicas = readWord(index, buf); Uint32 nextLcp = readWord(index, buf); ndbout << "Replica node is: " << procNode; ndbout << " initialGci: " << initialGci; ndbout << " numCrashedReplicas = " << numCrashedReplicas; ndbout << " nextLcpNo = " << nextLcp << endl; for (i = 0; i < 3; i++) { Uint32 maxGciCompleted = readWord(index, buf); Uint32 maxGciStarted = readWord(index, buf); Uint32 lcpId = readWord(index, buf); Uint32 lcpStatus = readWord(index, buf); if (i == 2) continue; ndbout << "LcpNo[" << i << "]: "; ndbout << "maxGciCompleted: " << maxGciCompleted; ndbout << " maxGciStarted: " << maxGciStarted; ndbout << " lcpId: " << lcpId; ndbout << " lcpStatus: "; if (lcpStatus == 1) { ndbout << "valid"; } else if (lcpStatus == 2) { ndbout << "invalid"; } else { ndbout << "error: set to " << lcpStatus; } ndbout << endl; } for (i = 0; i < 8; i++) { Uint32 createGci = readWord(index, buf); Uint32 replicaLastGci = readWord(index, buf); if (i < numCrashedReplicas) { ndbout << "Crashed_replica[" << i << "]: "; ndbout << "CreateGci: " << createGci; ndbout << " replicaLastGci:" << replicaLastGci << endl; } } }
bool internalizeOneObjectFile(objectFileListType *objectFile) { FILE *objectFildes; int magic; int mode; addressType startAddress; addressType endAddress; currentFileName = objectFile->name; if ((objectFildes = fopen(objectFile->name, "r")) == NULL) { error(CANT_OPEN_OBJECT_FILE_ERROR, objectFile->name); perror("Unix says"); return(FALSE); } if (verbose) printf("internalizing %s:\n", objectFile->name); if ((magic = readWord(objectFildes, objectFile->name)) != 0xFFFF) { error(BAD_OBJECT_FILE_ERROR, objectFile->name); return(FALSE); } mode = MODE_ABSOLUTE; for (;;) { startAddress = readWord(objectFildes, objectFile->name); if (startAddress == 0xFFFF) { if (mode == MODE_ABSOLUTE) { mode = MODE_RELOCATABLE; continue; } else { break; } } endAddress = readWord(objectFildes, objectFile->name); readCode(startAddress, endAddress, mode, objectFile, objectFildes); } readReservations(objectFile, objectFildes); readReferences(objectFile, objectFildes); readSymbols(objectFile, objectFildes); readExpressions(objectFile, objectFildes); readFunctions(objectFile, objectFildes); instantiateExpressionAndSymbolPointers(objectFile); if (readExpressionEntryPoint) { pc = entryPointExpression; putSymbolPointersIntoExpression(); readExpressionEntryPoint = FALSE; haveExpressionEntryPoint = TRUE; } qsort(objectFile->symbolTable, objectFile->symbolCount, sizeof(symbolType *), compareSymbolValues); fclose(objectFildes); return(TRUE); }
byte SX1509::readPin(byte pin) { unsigned int tempRegDir = readWord(REG_DIR_B); if (tempRegDir & (1<<pin)) // If the pin is an input { unsigned int tempRegData = readWord(REG_DATA_B); if (tempRegData & (1<<pin)) return 1; } return 0; }
/*------------------------------------------------------------------ * Create a BinaryGraphLoader reading from a binary istream. * NOTE: the input stream must be open with the * ios::binary | ios::in mode. -----------------------------------------------------------------*/ BinaryGraphLoader::BinaryGraphLoader(istream &in) { unsigned n, ne, dest; unsigned i,j; n = readWord(in); for(i=0; i<n; i++) InsertNode(NULL); for(i=0; i<n; i++) { ne = readWord(in); for(j=0; j<ne; j++) { dest=readWord(in); InsertEdge(i, dest, NULL); } } }
void SATParser::read(istream *s) { string name; m_stream = s; m_header.version = readInt(); m_header.n_data_records = readInt(); m_header.n_entities = readInt(); m_header.has_history = readBool(); finishLine(); m_header.product_id = readString(); m_header.acis_version = readString(); m_header.date = readString(); finishLine(); m_header.unit = readDouble(); m_header.resabs = readDouble(); m_header.resnor = readDouble(); MSG_DEBUG("SATParser::read", "resnor = " << m_header.resnor); finishLine(); // cout << readString() << endl; name = readWord(); while (!m_stream->eof() && name != END_OF_DATA_STR) { SATEntity *e; if (SATEntity_Factory::exists(name)) { e = SATEntity_Factory::byName(name).instantiate(); } else { MSG_DEBUG("SATParser::read", "Unknown entity: '" << name << "'"); e = new SATUnknown(); } e->read(this); m_entities.push_back(e); finishLine(); name = readWord(); } fixPointers(); }
void Network::dispatchMessages() { while (messageReady()) { SDL_mutexP(mMutexIn); const unsigned int msgId = readWord(0); int len = -1; if (msgId == SMSG_SERVER_VERSION_RESPONSE) { len = 10; } else if (msgId == SMSG_UPDATE_HOST2) { len = -1; } else { if (msgId < packet_lengths_size) len = packet_lengths[msgId]; } if (len == -1) len = readWord(2); MessageIn msg(mInBuffer, len); msg.postInit(); SDL_mutexV(mMutexIn); if (len == 0) { // need copy data for safty std::string str = strprintf("Wrong packet %u ""received. Exiting.", msgId); logger->safeError(str); } if (msgId < messagesSize) { MessageHandler *const handler = mMessageHandlers[msgId]; if (handler) handler->handleMessage(msg); else logger->log("Unhandled packet: %x", msgId); } skip(len); } }
Array readCommand(){ int wordCounter=0; int stopCommand=0; int maxCommandSize=8; String word=(String){NULL,0}; Array command=(Array){NULL,0}; command.c = calloc(maxCommandSize,sizeof(String)); while ( word.str==NULL || !stopCommand ){ word = readWord(); if (word.str[word.length-1]=='\n'){ stopCommand=2; } word.str[word.length-1] = '\0'; if ( strcmp(word.str,";")==0 || strcmp(word.str,"&&")==0 || strcmp(word.str,"||")==0 ){ stopCommand=1; } if (wordCounter==maxCommandSize){ maxCommandSize*=2; command.c=realloc(command.c,maxCommandSize*sizeof(String)); } command.c[wordCounter++]=word; } command.length=wordCounter; return command; }
boolean patchValid(byte i) { cli(); uint16_t addr = PATCH_BASE_ADDR + (i * PATCH_SIZE); unsigned int valid = readWord(addr); sei(); return (valid == PATCH_VALID_MARK); }
main (int argc, char **argv) { uint32_t a = 0; bool last; bool withAddress = false; bool bigEnd = false; argv ++; while (argc > 1) { if (strcmp (argv[0], "-a") == 0) { withAddress = true; } else if (strcmp (argv[0], "-b") == 0) { bigEnd = true; } argv ++; argc --; } do { uint32_t word; last = readWord (stdin, bigEnd, &word); if (withAddress) printf ("%08X %08X\n", a, word); else printf ("%08X\n", word); a += 4; } while (not last); }
bool UtlXMLStream::readEndOfAssociation(std::string& sOwnerClass, std::string& sName) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } iChar=readChar( getInputStream() ); if (iChar != '/') { return false; } // Read a string, search '_' and split the string in two std::string sCompletWord,sDebut,sFin; if (!readWord( getInputStream(), sCompletWord )) return false; if (!splitString( sCompletWord, '_', sOwnerClass, sName)) return false; iChar=readChar( getInputStream() ); if (iChar != '>') { return false; } return true; }
/** Read a single bit from a 16-bit device register. * @param devAddr I2C slave device address * @param regAddr Register regAddr to read from * @param bitNum Bit position to read (0-15) * @param data Container for single bit value * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) * @return Status of read operation (true = success) **/ int8_t I2Cdev::readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout) { uint16_t b; uint8_t count = readWord(devAddr, regAddr, &b, timeout); *data = b & (1 << bitNum); return count; }
bool UtlXMLStream::readEndTag(std::string& sTag) { int iChar; skipBlanks( getInputStream() ); iChar=readChar( getInputStream() ); if (iChar != '<') { return false; } iChar=readChar( getInputStream() ); if (iChar != '/') { return false; } if (!readWord( getInputStream(), sTag )) return false; iChar=readChar( getInputStream() ); if (iChar != '>') { return false; } return true; }
byte SX1509::init(void) { // Begin I2C Wire.begin(); // If the reset pin is connected if (pinReset != 255) reset(1); else reset(0); // Communication test. We'll read from two registers with different // default values to verify communication. unsigned int testRegisters = 0; testRegisters = readWord(REG_INTERRUPT_MASK_A); // This should return 0xFF00 // Then read a byte that should be 0x00 if (testRegisters == 0xFF00) { // Set the clock to a default of 2MHz using internal clock(INTERNAL_CLOCK_2MHZ); return 1; } return 0; }
void SX1509::pinDir(byte pin, byte inOut) { // The SX1509 RegDir registers: REG_DIR_B, REG_DIR_A // 0: IO is configured as an output // 1: IO is configured as an input byte modeBit; if ((inOut == OUTPUT) || (inOut == ANALOG_OUTPUT)) modeBit = 0; else modeBit = 1; unsigned int tempRegDir = readWord(REG_DIR_B); if (modeBit) tempRegDir |= (1<<pin); else tempRegDir &= ~(1<<pin); writeWord(REG_DIR_B, tempRegDir); // If INPUT_PULLUP was called, set up the pullup too: if (inOut == INPUT_PULLUP) writePin(pin, HIGH); if (inOut == ANALOG_OUTPUT) { ledDriverInit(pin); } }
static void skipList(bfFile bf) { int len,i; unsigned char type; bfread(bf,&type,1); len=readDword(bf); switch (type) { default: break; case 1: //byte bfseek(bf,len,SEEK_CUR); break; case 2: //short bfseek(bf,len*2,SEEK_CUR); break; case 3: //int bfseek(bf,len*4,SEEK_CUR); break; case 4: //long bfseek(bf,len*8,SEEK_CUR); break; case 5: //float bfseek(bf,len*4,SEEK_CUR); break; case 6: //double bfseek(bf,len*8,SEEK_CUR); break; case 7: //byte array for (i=0;i<len;i++) { int slen=readDword(bf); bfseek(bf,slen,SEEK_CUR); } break; case 8: //string for (i=0;i<len;i++) { int slen=readWord(bf); bfseek(bf,slen,SEEK_CUR); } break; case 9: //list for (i=0;i<len;i++) skipList(bf); break; case 10: //compound for (i=0;i<len;i++) skipCompound(bf); break; case 11: //int array for (i=0;i<len;i++) { int slen=readDword(bf); bfseek(bf,slen*4,SEEK_CUR); } break; } }
list<string> getOutgroup(string fn){ list<string> result; FILE * o = fopen(fn.c_str(),"rt"); if (o==NULL) cout<<"Impossible to open outgroup file"<<endl; int ino=readInt(o,"Error in the outgroup file, the file should begin with an integer (the number of outgroups)"); for (int i=0;i<ino;i++) result.push_back(readWord(o,fn)); return result; }
const Reader &BasicReader::readFloat (float& val ) { Glib::ustring buf = readWord(); double ival; if (getDouble(buf, &ival)) val = (float)ival; return *this; }
const Reader &BasicReader::readDouble (double& val ) { Glib::ustring buf = readWord(); double ival; if (getDouble(buf, &ival)) val = ival; return *this; }