bool Uri::Private::parseIPvFuture() { if (!expectChar('v') && !expectChar('V')) { return false; } m_parserAux.clear(); Char curr = m_uri[m_parserPos]; size_t currValue = curr.value(); if (currValue > 127 || !isHexdig[currValue]) { return false; } ++m_parserPos; if (!expectChar('.')) { return false; } curr = m_uri[m_parserPos]; currValue = curr.value(); if (currValue < 128 && isUnreserved[currValue]) { ++m_parserPos; return true; } if (currValue < 128 && isSubdelim[currValue]) { ++m_parserPos; return true; } if (curr == ':') { ++m_parserPos; return true; } return false; }
bool Uri::Private::parseIPv4Address() { m_parserAux.clear(); if (!parseDecOctet()) { return false; } if (!expectChar('.')) { return false; } m_parserAux += '.'; if (!parseDecOctet()) { return false; } if (!expectChar('.')) { return false; } m_parserAux += '.'; if (!parseDecOctet()) { return false; } if (!expectChar('.')) { return false; } m_parserAux += '.'; if (!parseDecOctet()) { return false; } return true; }
bool Uri::Private::parseRelativePart() { if (expectChar('/')) { if (expectChar('/')) { parseAuthority(); parsePathAbempty(); return true; } else { --m_parserPos; } } const size_t parserOldPos = m_parserPos; if (parsePathAbsolute()) { return true; } m_parserPos = parserOldPos; if (parsePathNoScheme()) { return true; } m_parserPos = parserOldPos; if (parsePathEmpty()) { return true; } return false; }
bool Uri::Private::parseRelativeRef() { if (!parseRelativePart()) { return false; } if (expectChar('?')) { parseQuery(); } if (expectChar('#')) { parseFragment(); } return true; }
void Uri::Private::parseAuthority() { m_parserAux.clear(); const size_t parserOldPos = m_parserPos; parseUserinfo(); if (!expectChar('@')) { m_parserPos = parserOldPos; } parseHost(); if (expectChar(':')) { parsePort(); } }
Integer ParseString::parse(StringParser *sp) { ParseName parseName; if(expectStatement(sp,&parseName)) { parseName.getString(m_string,256); return 1; } char quote = sp->getCurrentChar(); if(!expectChars(sp,"\'\"")) return 0; ParseStringChar stringChar(quote); Integer i=0; while(stringChar(sp)) { m_string[i]=stringChar.getChar(); m_string[i+1]=0; i++; } if(!expectChar(sp,quote)) return 0; m_string[i]=0; return 1; }
bool Uri::Private::parsePctEncoded() { if (expectChar('%')) { Char curr = m_uri[m_parserPos]; size_t currValue = curr.value(); if (!currValue || currValue > 127 || !isHexdig[currValue]) { return false; } m_parserAux += curr; ++m_parserPos; curr = m_uri[m_parserPos]; currValue = curr.value(); if (!currValue || currValue > 127 || !isHexdig[currValue]) { return false; } m_parserAux += curr; ++m_parserPos; } else { const Char curr = m_uri[m_parserPos]; const iuint32 currValue = curr.value(); if (curr.octetsRequired() > 1) { m_parserAux += curr; ++m_parserPos; } else if (currValue && currValue < 128 && (!isUnreserved[currValue] && !isGendelim[currValue] && !isSubdelim[currValue] && curr != ':' && curr != '@')) { m_parserTrick = true; m_parserAux += getHex(curr); ++m_parserPos; } else { return false; } } return true; }
bool Uri::Private::parseAbsoluteURI() { if (!parseScheme()) { return false; } if (!expectChar(':')) { return false; } if (!parseHierPart()) { return false; } if (expectChar('?')) { parseQuery(); } return true; }
bool Uri::Private::parseIPLiteral() { if (!expectChar('[')) { return false; } const size_t parserOldPos = m_parserPos; if (parseIPv6Address()) { if (!expectChar(']')) { return false; } return true; } m_parserPos = parserOldPos; if (parseIPvFuture()) { if (!expectChar(']')) { return false; } return true; } return false; }
bool Uri::Private::parsePathAbsolute() { if (!expectChar('/')) { return false; } m_pathStack.clear(); m_pathStack.push(String('/')); if (parseSegmentNz()) { constructPath(); while (expectChar('/')) { m_pathStack.push(String('/')); parseSegment(); constructPath(); } } constructPath(); m_path.clear(); const size_t stackSize = m_pathStack.size(); for (size_t i = 0; i < stackSize; ++i) { m_path.prepend(m_pathStack.pop()); } return true; }
void Uri::Private::parsePathAbempty() { m_parserAux.clear(); m_pathStack.clear(); while (expectChar('/')) { m_pathStack.push(String('/')); parseSegment(); constructPath(); } constructPath(); m_path.clear(); const size_t stackSize = m_pathStack.size(); for (size_t i = 0; i < stackSize; ++i) { m_path.prepend(m_pathStack.pop()); } }
/* * Send a COM_PORT_OPTION subcommand to the server */ static asynStatus sbComPortOption(interposePvt *pinterposePvt, asynUser *pasynUser, const char *xBuf, int xLen, char *rBuf) { char cbuf[20]; asynStatus status; int c; size_t nbytes; cbuf[0] = C_IAC; cbuf[1] = C_SB; cbuf[2] = SB_COM_PORT_OPTION; memcpy(cbuf+3, xBuf, xLen); cbuf[3+xLen+0] = C_IAC; cbuf[3+xLen+1] = C_SE; status = pinterposePvt->pasynOctetDrv->write(pinterposePvt->drvPvt, pasynUser, cbuf, 5+xLen, &nbytes); if (status != asynSuccess) return status; for (;;) { while ((c = nextChar(pinterposePvt, pasynUser)) != C_IAC) { if (c == EOF) return asynError; } if (!expectChar(pinterposePvt, pasynUser, C_SB) || !expectChar(pinterposePvt, pasynUser, SB_COM_PORT_OPTION)) return asynError; c = nextChar(pinterposePvt, pasynUser); if ((c == CPO_SERVER_NOTIFY_LINESTATE ) || (c == CPO_SERVER_NOTIFY_MODEMSTATE)) { if ((nextChar(pinterposePvt, pasynUser) == EOF) || !expectChar(pinterposePvt, pasynUser, C_IAC) || !expectChar(pinterposePvt, pasynUser, C_SE)) return asynError; } else if (c == (*xBuf + 100)) { while (--xLen > 0) { if ((c = nextChar(pinterposePvt, pasynUser)) == EOF) return asynError; *rBuf++ = c; } if (!expectChar(pinterposePvt, pasynUser, C_IAC) || !expectChar(pinterposePvt, pasynUser, C_SE)) return asynError; return asynSuccess; } else { epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize, "Sent COM-PORT-OPTION %d but got reply %d", *xBuf, c); return asynError; } } return asynSuccess; }
bool Uri::Private::parseLs32() { const size_t parserOldPos = m_parserPos; if (parseH16()) { if (!expectChar(':')) { return false; } if (parseH16()) { return true; } return false; } m_parserPos = parserOldPos; if (parseIPv4Address()) { return true; } return false; }
void ArtDTrack::processAsciiData(void) { Vrui::VRDeviceState::TrackerState ts; ts.linearVelocity=Vrui::VRDeviceState::TrackerState::LinearVelocity::zero; ts.angularVelocity=Vrui::VRDeviceState::TrackerState::AngularVelocity::zero; while(true) { /* Wait for the next data message from the DTrack daemon: */ char messageBuffer[4096]; size_t messageSize=dataSocket.receiveMessage(messageBuffer,sizeof(messageBuffer)-1); /* Newline-terminate the message as a sentinel: */ messageBuffer[messageSize]='\n'; /* Parse the received message: */ const char* mPtr=messageBuffer; const char* mEnd=messageBuffer+(messageSize+1); while(mPtr!=mEnd) { /* Skip whitespace, but not the line terminator: */ while(*mPtr!='\n'&&isspace(*mPtr)) ++mPtr; /* Get the line's device report format: */ DeviceReportFormat drf=parseDeviceReportFormat(mPtr,0,&mPtr); /* Process the line: */ if(drf!=DRF_NUMFORMATS) { if(drf==DRF_6DF2) { /* Skip the number of defined flysticks: */ readInt(mPtr); } /* Read the number of bodies in this report: */ int numBodies=readInt(mPtr); /* Parse all body reports: */ for(int body=0;body<numBodies;++body) { /* Check for opening bracket: */ if(!expectChar('[',mPtr)) break; /* Read the body's ID and find the corresponding device structure: */ int id=readInt(mPtr); int deviceIndex=deviceIdToIndex[drf][id]; Device* device=deviceIndex>=0?&devices[deviceIndex]:0; /* Read the quality value: */ float quality=float(readFloat(mPtr)); /* Read button/valuator or finger data depending on report format: */ int numButtons=0; int numValuators=0; int numFingers=0; if(drf==DRF_6DF) { /* Read the button bit mask: */ unsigned int buttonBits=readUint(mPtr); if(device!=0) { /* Set the device's button states: */ for(int i=0;i<32&&i<device->numButtons;++i,buttonBits>>=1) setButtonState(device->firstButtonIndex+i,(buttonBits&0x1)!=0x0); } } if(drf==DRF_6DF2||drf==DRF_6DMT) { /* Read the number of buttons: */ numButtons=readInt(mPtr); if(drf==DRF_6DF2) { /* Read the number of valuators: */ numValuators=readInt(mPtr); } } if(drf==DRF_GL) { /* Skip the glove's handedness: */ readInt(mPtr); /* Read the number of fingers: */ numFingers=readInt(mPtr); } /* Check for closing bracket followed by opening bracket: */ if(!expectChar(']',mPtr)||!expectChar('[',mPtr)) break; Vector pos; Rotation orient=Rotation::identity; /* Read the body's 3D position: */ for(int i=0;i<3;++i) pos[i]=VScalar(readFloat(mPtr)); if(drf!=DRF_3D) { /* Read the body's 3D orientation: */ if(drf==DRF_6D||drf==DRF_6DF) { /* Read the body's orientation angles: */ VScalar angles[3]; for(int i=0;i<3;++i) angles[i]=VScalar(readFloat(mPtr)); /* Convert the orientation angles to a 3D rotation: */ orient*=Rotation::rotateX(Math::rad(angles[0])); orient*=Rotation::rotateY(Math::rad(angles[1])); orient*=Rotation::rotateZ(Math::rad(angles[2])); } /* Check for closing bracket followed by opening bracket: */ if(!expectChar(']',mPtr)||!expectChar('[',mPtr)) break; if(drf==DRF_6DF2||drf==DRF_6DMT||drf==DRF_GL) { /* Read the body's orientation matrix (yuck!): */ Geometry::Matrix<VScalar,3,3> matrix; for(int j=0;j<3;++j) for(int i=0;i<3;++i) matrix(i,j)=VScalar(readFloat(mPtr)); if(quality>0.0f) { /* Calculate the body's orientation quaternion (YUCK!): */ orient=Rotation::fromMatrix(matrix); } } else { /* Skip the body's orientation matrix: */ for(int i=0;i<9;++i) readFloat(mPtr); } } /* Check for closing bracket: */ if(!expectChar(']',mPtr)) break; if(drf==DRF_6DF2) { /* Check for opening bracket: */ if(!expectChar('[',mPtr)) break; /* Read button states: */ for(int bitIndex=0;bitIndex<numButtons;bitIndex+=32) { /* Read the next button bit mask: */ unsigned int buttonBits=readUint(mPtr); if(device!=0) { /* Set the device's button states: */ for(int i=0;i<32&&bitIndex+i<device->numButtons;++i,buttonBits>>=1) setButtonState(device->firstButtonIndex+bitIndex+i,(buttonBits&0x1)!=0x0); } } /* Read valuator states: */ for(int i=0;i<numValuators;++i) { /* Read the next valuator value: */ float value=float(readFloat(mPtr)); /* Set the valuator value if the valuator is valid: */ if(device!=0&&i<device->numValuators) setValuatorState(device->firstValuatorIndex+i,value); } /* Check for closing bracket: */ if(!expectChar(']',mPtr)) break; } if(drf==DRF_GL) { /* Skip all finger data for now: */ bool error=false; for(int finger=0;finger<numFingers;++finger) { /* Check for opening bracket: */ if(!expectChar('[',mPtr)) { error=true; break; } /* Skip finger position: */ for(int i=0;i<3;++i) readFloat(mPtr); /* Check for closing followed by opening bracket: */ if(!expectChar(']',mPtr)||!expectChar('[',mPtr)) { error=true; break; } /* Skip finger orientation: */ for(int i=0;i<9;++i) readFloat(mPtr); /* Check for closing followed by opening bracket: */ if(!expectChar(']',mPtr)||!expectChar('[',mPtr)) { error=true; break; } /* Skip finger bending parameters: */ for(int i=0;i<6;++i) readFloat(mPtr); /* Check for closing bracket: */ if(!expectChar(']',mPtr)) { error=true; break; } } /* Stop parsing the packet on syntax error: */ if(error) break; } /* Check if this body has a valid position/orientation and has been configured as a device: */ if(quality>0.0f&&device!=0) { /* Set the device's tracker state: */ ts.positionOrientation=PositionOrientation(pos,orient); setTrackerState(deviceIndex,ts); } } } /* Skip the rest of the line: */ while(*mPtr!='\n') ++mPtr; /* Go to the next line: */ ++mPtr; } /* Tell the VR device manager that the current state has updated completely: */ updateState(); }
bool Uri::Private::parseIPv6Address() { m_parserAux.clear(); const size_t parserOldPos = m_parserPos; { // 6( h16 ":" ) ls32 bool parse = true; for (size_t i = 0; i < 6; ++i) { if (!parseH16()) { parse = false; break; } if (!expectChar(':')) { parse = false; break; } else { m_parserAux += ':'; } } if (parse) { if (parseLs32()) { return true; } } } m_parserPos = parserOldPos; m_parserAux.clear(); { // "::" 5( h16 ":" ) ls32 if (expectChar(':') && expectChar(':')) { m_parserAux += ':'; m_parserAux += ':'; bool parse = true; for (size_t i = 0; i < 5; ++i) { if (!parseH16()) { parse = false; break; } if (!expectChar(':')) { parse = false; break; } else { m_parserAux += ':'; } } if (parse) { if (parseLs32()) { return true; } } } } m_parserPos = parserOldPos; m_parserAux.clear(); { // [ h16 ] "::" 4( h16 ":" ) ls32 const bool hasColon = expectChar(':'); bool parse = true; if (!hasColon) { parse = parseH16(); } if (parse && expectChar(':') && (hasColon || expectChar(':'))) { m_parserAux += ':'; m_parserAux += ':'; bool parse = true; for (size_t i = 0; i < 4; ++i) { if (!parseH16()) { parse = false; break; } if (!expectChar(':')) { parse = false; break; } else { m_parserAux += ':'; } } if (parse) { if (parseLs32()) { return true; } } } } m_parserPos = parserOldPos; m_parserAux.clear(); { // [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 const bool hasColon = expectChar(':'); bool parse = true; if (!hasColon) { parse = parseH16(); if (parse && expectChar(':')) { m_parserAux += ':'; parse = parseH16(); } } if (parse && expectChar(':') && (hasColon || expectChar(':'))) { m_parserAux += ':'; m_parserAux += ':'; bool parse = true; for (size_t i = 0; i < 3; ++i) { if (!parseH16()) { parse = false; break; } if (!expectChar(':')) { parse = false; break; } else { m_parserAux += ':'; } } if (parse) { if (parseLs32()) { return true; } } } } m_parserPos = parserOldPos; m_parserAux.clear(); { // [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 const bool hasColon = expectChar(':'); bool parse = true; if (!hasColon) { for (size_t i = 0; i < 2; ++i) { if (!parseH16()) { parse = false; break; } if (!expectChar(':')) { parse = false; break; } else { m_parserAux += ':'; } } if (parse) { parse = parseH16(); } } if (parse && expectChar(':') && (hasColon || expectChar(':'))) { m_parserAux += ':'; m_parserAux += ':'; bool parse = true; for (size_t i = 0; i < 2; ++i) { if (!parseH16()) { parse = false; break; } if (!expectChar(':')) { parse = false; break; } else { m_parserAux += ':'; } } if (parse) { if (parseLs32()) { return true; } } } } m_parserPos = parserOldPos; m_parserAux.clear(); { // [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 bool hasColon = false; if (parseH16()) { for (size_t i = 0; i < 3; ++i) { if (!expectChar(':')) { break; } m_parserAux += ':'; if (!parseH16()) { hasColon = true; break; } } } if (expectChar(':') && (hasColon || expectChar(':'))) { m_parserAux += ':'; if (!hasColon) { m_parserAux += ':'; } if (parseH16() && expectChar(':')) { m_parserAux += ':'; if (parseLs32()) { return true; } } } } m_parserPos = parserOldPos; m_parserAux.clear(); { // [ *4( h16 ":" ) h16 ] "::" ls32 bool hasColon = false; if (parseH16()) { for (size_t i = 0; i < 4; ++i) { if (!expectChar(':')) { break; } m_parserAux += ':'; if (!parseH16()) { hasColon = true; break; } } } if (expectChar(':') && (hasColon || expectChar(':'))) { m_parserAux += ':'; if (!hasColon) { m_parserAux += ':'; } if (parseLs32()) { return true; } } } m_parserPos = parserOldPos; m_parserAux.clear(); { // [ *5( h16 ":" ) h16 ] "::" h16 bool hasColon = false; if (parseH16()) { for (size_t i = 0; i < 5; ++i) { if (!expectChar(':')) { break; } m_parserAux += ':'; if (!parseH16()) { hasColon = true; break; } } } if (expectChar(':') && (hasColon || expectChar(':'))) { m_parserAux += ':'; if (!hasColon) { m_parserAux += ':'; } if (parseH16()) { return true; } } } m_parserPos = parserOldPos; m_parserAux.clear(); { // [ *6( h16 ":" ) h16 ] "::" bool hasColon = false; if (parseH16()) { for (size_t i = 0; i < 6; ++i) { if (!expectChar(':')) { break; } m_parserAux += ':'; if (!parseH16()) { hasColon = true; break; } } } if (expectChar(':') && (hasColon || expectChar(':'))) { m_parserAux += ':'; if (!hasColon) { m_parserAux += ':'; } return true; } } return false; }