int _RkReadHeader(int fd, struct HD *hd, off_t off_from_top) { unsigned char *src; unsigned long len, off; int i, tmpres; long hdrsize; #ifdef WIN DWORD readsize; #endif for (i = 0; i < HD_MAXTAG; i++) { hd->data[i].var = 0; hd->flag[i] = 0; } /* ¼¡¤Î off_from_top ¤Î·×»»¤¬¤¦¤µ¤ó¤¯¤µ¤¤¤¾ */ tmpres = lseek(fd, off_from_top, 0); if (tmpres < 0) { RkSetErrno(RK_ERRNO_EACCES); goto read_err; } hdrsize = read(fd, (char *)localbuffer, RK_MAX_HDRSIZ); if (hdrsize <= ((long) 0)) { RkSetErrno(RK_ERRNO_EACCES); goto read_err; } for (src = localbuffer; src < (localbuffer + hdrsize);) { if (isEndTag(src)) break; for (i = 0; i < HD_MAXTAG; i++) { if (!strncmp((char *)src, Hdrtag[i], HD_TAGSIZ)) break; } if (i == HD_MAXTAG) goto read_err; src += HD_TAGSIZ; len = bst4_to_l(src); src += HD_TAGSIZ; off = bst4_to_l(src); src += HD_TAGSIZ; if (hd->flag[i] != 0) goto read_err; if (len == 0) { hd->flag[i] = -1; hd->data[i].var = off; } else { hd->flag[i] = len; if (!(hd->data[i].ptr = (unsigned char *)malloc((size_t) (len + 1)))) { RkSetErrno(RK_ERRNO_NOMEM); goto read_err; } if (off < (unsigned long)hdrsize) { memcpy(hd->data[i].ptr, localbuffer + off, (size_t) len); } else { tmpres = lseek(fd, off_from_top + off, 0); if (tmpres < 0) { RkSetErrno(RK_ERRNO_EACCES); goto read_err; } tmpres = read(fd, (char *)hd->data[i].ptr, (unsigned)len); if (tmpres != (int)len) { RkSetErrno(RK_ERRNO_EACCES); goto read_err; } } hd->data[i].ptr[len] = 0; } } if (hd->data[HD_MAG].var != (long)bst4_to_l("CDIC")) { goto read_err; } return 0; read_err: for (i = 0; i < HD_MAXTAG; i++) { if (hd->flag[i] > 0) free(hd->data[i].ptr); hd->flag[i] = 0; hd->data[i].var = 0; } return -1; }
void SvgParser::parseElement() { bool hasAttributes = true; int nameLength = 0; while (!atEnd()) { // check is element name ends with end tag // namely do not have child elements and attributes EndTagType endType = isEndTag(false); if (endType != NotEnd) { hasAttributes = false; m_name = QString(str-nameLength, nameLength); if (endType == EndType1) str++; else if (endType == EndType2) { str += 2; m_isPrevElemEnded = true; } break; } // if char is space than node name is ended if (StringWalker::isSpace(str->unicode())) { m_name = QString(str-nameLength, nameLength); // check is element has end char after spaces // and not attributes skipSpaces(); endType = isEndTag(); if (endType != NotEnd) { if (endType == EndType2) m_isPrevElemEnded = true; hasAttributes = false; } break; } nameLength++; str++; } if (!hasAttributes) return; // parse attributes // reserve memory for attributes // 6 - is average attributes count m_attrHash.reserve(6); QChar quote; QString attrName; while (!atEnd()) { nameLength = 0; skipSpaces(); // data between ' ' and '=' is attribute name while (!atEnd() && *str != QL1C('=')) { nameLength++; ++str; } // ignore spaces in attribute name attrName.clear(); uint attrId = hash(str-nameLength, nameLength); if (!isDefaultAttribute(attrId)) attrName = QString(str-nameLength, nameLength); // skip '=' str++; skipSpaces(); if (!atEnd() && (*str == QL1C('\"') || *str == QL1C('\''))) { quote = *str; str++; } // data between quotes is attribute value nameLength = 0; while (!atEnd() && *str != quote) { nameLength++; str++; } // ignore empty attributes if (nameLength > 0) { if ( attrId == AttrId::transform || attrId == AttrId::gradientTransform || attrId == AttrId::patternTransform) { Transform ts(str-nameLength, nameLength); if (ts.isValid()) m_attrHash.insert(AttrId::transform, SvgAttribute(ts)); } else { QString attrValue = QString(str-nameLength, nameLength); if (attrName.isEmpty()) { if (attrId == AttrId::d) m_attrHash.insert(AttrId::d, SvgAttribute(PathSegmentList(), attrValue)); else m_attrHash.insert(attrId, SvgAttribute(attrId, attrValue)); } else { m_attrHash.insert(attrId, SvgAttribute(attrName, attrValue)); } } } // skip quote char str++; skipSpaces(); EndTagType endType = isEndTag(); if (endType != NotEnd) { if (endType == EndType2) m_isPrevElemEnded = true; break; } } }