static BOOL ParseVertexUVs(char **data, Mesh3D *mesh) { FLOAT scale_u = SPFlt(16); FLOAT scale_v = SPFlt(16); UVCoord *uv; WORD n; if (!(ReadShort(data, &n) && EndOfLine(data))) return FALSE; Log("[3D] Mesh has %ld uv coordinates\n", (LONG)n); mesh->uv = MemAlloc(sizeof(Point2D) * n, MEMF_PUBLIC); uv = mesh->uv ; while (NextLine(data) && !MatchString(data, "@end")) { FLOAT u, v; if (!(ReadFloat(data, &u) && ReadFloat(data, &v) && EndOfLine(data))) return FALSE; uv->u = SPFix(SPMul(u, scale_u)); uv->v = SPFix(SPMul(v, scale_v)); uv++; n--; } return n == 0; }
static BOOL ParseFaceUVs(char **data, Mesh3D *mesh) { IndexListT **faceUVs; WORD *index; WORD n, m; if (!(ReadShort(data, &n) && ReadShort(data, &m) && EndOfLine(data))) return FALSE; mesh->faceUV = MemAlloc(sizeof(IndexListT *) * (n + 1) + sizeof(WORD) * (m + n), MEMF_PUBLIC|MEMF_CLEAR); faceUVs = mesh->faceUV; index = (WORD *)&mesh->faceUV[n + 1]; while (NextLine(data) && !MatchString(data, "@end")) { IndexListT *faceUV = (IndexListT *)index++; while (!EndOfLine(data)) { if (!ReadShort(data, index++)) return FALSE; faceUV->count++, m--; } *faceUVs++ = faceUV, n--; } return (n == 0) && (m == 0); }
static BOOL ParseVertices(char **data, Mesh3D *mesh) { FLOAT scale = SPMul(mesh->scale, SPFlt(16)); Point3D *vertex; WORD n; if (!(ReadShort(data, &n) && EndOfLine(data))) return FALSE; Log("[3D] Mesh has %ld points\n", (LONG)n); mesh->vertices = n; mesh->vertex = MemAlloc(sizeof(Point3D) * n, MEMF_PUBLIC); vertex = mesh->vertex; while (NextLine(data) && !MatchString(data, "@end") && n > 0) { FLOAT x, y, z; if (!(ReadFloat(data, &x) && ReadFloat(data, &y) && ReadFloat(data, &z) && EndOfLine(data))) return FALSE; vertex->x = SPFix(SPMul(x, scale)); vertex->y = SPFix(SPMul(y, scale)); vertex->z = SPFix(SPMul(z, scale)); vertex++; n--; } return n == 0; }
static BOOL ParseSurface(char **data, Mesh3D *mesh) { MeshSurfaceT *surface; WORD n; if (!(ReadShort(data, &n) && EndOfLine(data))) return FALSE; surface = &mesh->surface[n]; while (NextLine(data) && !MatchString(data, "@end")) { if (MatchString(data, "color")) { if (!(ReadByte(data, &surface->r) && ReadByte(data, &surface->g) && ReadByte(data, &surface->b) && EndOfLine(data))) return FALSE; } else if (MatchString(data, "side")) { if (!(ReadByte(data, &surface->sideness) && EndOfLine(data))) return FALSE; } else if (MatchString(data, "texture")) { if (!(ReadShort(data, &surface->texture) && EndOfLine(data))) return FALSE; } else { SkipLine(data); } } return TRUE; }
boolean TextManip::HandleKey (Event& e) { World* world = GetViewer()->GetWorld(); char c = e.keystring[0]; boolean manipulating = true; switch (c) { case '\007': world->RingBell(1); break; case '\001': BeginningOfLine(); break; case '\005': EndOfLine(); break; case '\006': ForwardCharacter(1); break; case '\002': BackwardCharacter(1); break; case '\016': ForwardLine(1); break; case '\020': BackwardLine(1); break; case '\013': DeleteLine(); break; case '\004': DeleteCharacter(1); break; case '\010': DeleteCharacter(-1); break; case '\177': DeleteCharacter(-1); break; case '\011': InsertCharacter('\t'); break; case '\015': if (_multiline) InsertCharacter('\n'); break; case '\033': manipulating = false; break; default: if (!iscntrl(c & 0x7f)) { InsertCharacter(c); } break; } return manipulating; }
/*** AG Link finder, to work with TAB key ***/ void FindNextLink( struct scrpos *inf, char dir ) { AGNode src = (AGNode) inf->node; /* If there was a previous active link, reset styles */ if( src->ActiveLink ) src->ActiveLink->bgpen = DEF_BGPEN, src->ActiveLink->style = DEF_LINKSTYLE; /* If there is no previous selected link, or it is now outside ** ** the visible area, choose a new one, starting from topline. */ if( src->ActiveLink == NULL || src->ActiveLine < src->line || src->ActiveLine >= src->line+inf->height-1 ) { short nb; src->ActiveLink = WordsPara( src->StartLine = src->Shown ); src->ActiveLine = src->line; /* Start at bottom of screen, if backward scan */ if( dir == -1 ) { for(nb=inf->height-2; nb && NEXT(src->StartLine); nb--,src->StartLine=NEXT(src->StartLine),src->ActiveLine++); src->ActiveLink = EndOfLine( src->StartLine ); } } else { /* Unhilight previous visible link */ tabs = src->StartLine->ts; set_cursor_pos(src->ActiveLine - src->line + 1, 0); RenderLine(src->StartLine, src->column, inf->width, OVERWRITE); NextLink( src, dir ); } /* Search for the next available link following current position */ while( src->StartLine ) { AGWord wrd = src->ActiveLink; if(wrd && wrd->data != NULL && wrd->link) break; NextLink( src, dir ); /* If `cursor' go outside visible area, resets it */ if( src->ActiveLine >= src->line + inf->height - 1 || src->ActiveLine < src->line ) { src->ActiveLink = NULL; break; } } /* Hilite the new one */ if( src->ActiveLink ) { src->ActiveLink->bgpen = DEF_ACTIVELINK; src->ActiveLink->style = DEF_LINKSTYLE | FSF_INVERSID; tabs = src->StartLine->ts; set_cursor_pos(src->ActiveLine - src->line + 1, 0); RenderLine(src->StartLine, src->column, inf->width, OVERWRITE); } set_cursor_pos(inf->height,6); fflush(stdout); }
int TextBuffer::Width () const { int width = 0; int i = 0; while (i != length) { width = Math::max(width, EndOfLine(i) - i); i = BeginningOfNextLine(i); } return width; }
static BOOL ParseSurfaceCount(char **data, Mesh3D *mesh) { WORD n; if (!(ReadShort(data, &n) && EndOfLine(data))) return FALSE; Log("[3D] Mesh has %ld surfaces\n", (LONG)n); mesh->surfaces = n; mesh->surface = MemAlloc(sizeof(MeshSurfaceT) * n, MEMF_PUBLIC|MEMF_CLEAR); return TRUE; }
/*** Go through the next word ***/ void NextLink( AGNode src, char dir ) { if( dir == 1) if( src->ActiveLink ) src->ActiveLink = NEXT(src->ActiveLink); else src->ActiveLine++, src->ActiveLink = WordsPara( src->StartLine = NEXT(src->StartLine) ); else if( src->ActiveLink ) src->ActiveLink = PREV(src->ActiveLink); else src->ActiveLine--, src->ActiveLink = EndOfLine( src->StartLine = PREV(src->StartLine) ); }
void CEditView::GetSelectedText(CString& strResult) const { ASSERT_VALID(this); int nStartChar, nEndChar; GetEditCtrl().GetSel(nStartChar, nEndChar); ASSERT((UINT)nEndChar <= GetBufferLength()); LPCTSTR lpszText = ((CEditView*)this)->LockBuffer(); UINT nLen = EndOfLine(lpszText, nEndChar, nStartChar) - nStartChar; memcpy(strResult.GetBuffer(nLen), lpszText + nStartChar, nLen * sizeof(TCHAR)); strResult.ReleaseBuffer(nLen); UnlockBuffer(); ASSERT_VALID(this); }
static BOOL ParseFaces(char **data, Mesh3D *mesh) { IndexListT **faces; UBYTE *faceSurface; WORD *index; WORD n, m; if (!(ReadShort(data, &n) && ReadShort(data, &m) && EndOfLine(data))) return FALSE; Log("[3D] Mesh has %ld polygons\n", (LONG)n); mesh->faces = n; mesh->face = MemAlloc(sizeof(IndexListT *) * (n + 1) + sizeof(WORD) * (m + n), MEMF_PUBLIC|MEMF_CLEAR); mesh->faceSurface = MemAlloc(n, MEMF_PUBLIC); faces = mesh->face; faceSurface = mesh->faceSurface; index = (WORD *)&mesh->face[n + 1]; while (NextLine(data) && !MatchString(data, "@end") && n > 0) { IndexListT *face = (IndexListT *)index++; if (!ReadByte(data, faceSurface++)) return FALSE; while (!EndOfLine(data)) { if (!ReadShort(data, index++)) return FALSE; face->count++, m--; } *faces++ = face, n--; } return (n == 0) && (m == 0); }
UINT CEditView::PrintInsideRect(CDC* pDC, RECT& rectLayout, UINT nIndexStart, UINT nIndexStop) // worker function for laying out text in a rectangle. { ASSERT_VALID(this); ASSERT_VALID(pDC); BOOL bWordWrap = (GetStyle() & ES_AUTOHSCROLL) == 0; // get buffer and real starting and ending postions UINT nLen = GetBufferLength(); if (nIndexStart >= nLen) return nLen; LPCTSTR lpszText = LockBuffer(); if (nIndexStop > nLen) nIndexStop = nLen; ASSERT(nIndexStart < nLen); // calculate text & tab metrics TEXTMETRIC tm; pDC->GetTextMetrics(&tm); int cyChar = tm.tmHeight + tm.tmExternalLeading; #ifndef _MAC int nTabStop = m_nTabStops * pDC->GetTabbedTextExtent(_T("\t"), 1, 0, NULL).cx / 8 / 4; #else int nTabStop = pDC->GetTextExtent(_T("\t"), 1).cx; #endif int aCharWidths[256]; pDC->GetCharWidth(0, 255, aCharWidths); int y = rectLayout.top; UINT cx = rectLayout.right - rectLayout.left; UINT nIndex = nIndexStart; VERIFY(pDC->SaveDC() != 0); BOOL bLayoutOnly = pDC->IntersectClipRect(&rectLayout) == NULLREGION; do { UINT nIndexEnd = EndOfLine(lpszText, nIndexStop, nIndex); if (nIndex == nIndexEnd) { y += cyChar; } else if (bWordWrap) { // word-wrap printing do { UINT nIndexWrap = ClipLine(pDC, aCharWidths, cx, nTabStop, lpszText, nIndex, nIndexEnd); UINT nIndexWord = nIndexWrap; if (nIndexWord != nIndexEnd) { while (nIndexWord > nIndex && !isspace(lpszText[nIndexWord])) { nIndexWord--; } if (nIndexWord == nIndex) nIndexWord = nIndexWrap; } CRect rect(rectLayout.left, y, rectLayout.right, y+cyChar); if (!bLayoutOnly && pDC->RectVisible(rect)) { #ifndef _MAC pDC->TabbedTextOut(rect.left, y, (LPCTSTR)(lpszText+nIndex), nIndexWord-nIndex, 1, &nTabStop, rect.left); #else pDC->TextOut(rect.left, y, (LPCTSTR)(lpszText+nIndex), nIndexWord-nIndex); #endif } y += cyChar; nIndex = nIndexWord; while (nIndex < nIndexEnd && isspace(lpszText[nIndex])) nIndex++; } while (nIndex < nIndexEnd && y+cyChar <= rectLayout.bottom); nIndexEnd = nIndex; } else { // non-word wrap printing (much easier and faster) CRect rect(rectLayout.left, y, rectLayout.right, y+cyChar); if (!bLayoutOnly && pDC->RectVisible(rect)) { UINT nIndexClip = ClipLine(pDC, aCharWidths, cx, nTabStop, lpszText, nIndex, nIndexEnd); if (nIndexClip < nIndexEnd) { if (_istlead(*(lpszText+nIndexClip))) nIndexClip++; nIndexClip++; } #ifndef _MAC pDC->TabbedTextOut(rect.left, y, (LPCTSTR)(lpszText+nIndex), nIndexClip-nIndex, 1, &nTabStop, rect.left); #else pDC->TextOut(rect.left, y, (LPCTSTR)(lpszText+nIndex), nIndexClip-nIndex); #endif } y += cyChar; } nIndex = NextLine(lpszText, nIndexStop, nIndexEnd); } while (nIndex < nIndexStop && y+cyChar <= rectLayout.bottom); pDC->RestoreDC(-1); UnlockBuffer(); ASSERT_VALID(this); rectLayout.bottom = y; return nIndex; }
// --------------------------------------------------------- // TCodParser::AttrLineL() // --------------------------------------------------------- // TBool TCodParser::AttrLineL(CMediaObjectData *& aMediaObject) { SkipWhiteSpace(); // Skip lines which contain only WS and LF at the end. while ( IsEndOfLine() ) { NextLine(); SkipWhiteSpace(); } TBool ok( ETrue ); if ( iCurP < iEndP ) { // Still has something to read. switch( AttrName() ) { case ECodName: { if ( Colon() ) { ok = aMediaObject->SetNameL( AttrValue() ); EndOfLine(); } break; } case ECodVendor: { if ( Colon() ) { ok = iData->SetVendorL( AttrValue() ); EndOfLine(); } break; } case ECodDescription: { if ( Colon() ) { ok = aMediaObject->SetDescriptionL( AttrValue() ); EndOfLine(); } break; } case ECodSize: { if ( Colon() ) { // Parse as TUint - negative not allowed. TUint size; TLex lex( AttrValue() ); if ( !lex.Val( size ) ) { aMediaObject->SetSize( size ); } else { ok = EFalse; } EndOfLine(); } break; } case ECodInstallNotify: { if ( Colon() ) { ok = aMediaObject->SetInstallNotifyL( AttrValue() ); EndOfLine(); } break; } case ECodNextUrl: { if ( Colon() ) { ok = iData->SetNextUrlL( AttrValue() ); EndOfLine(); } break; } case ECodNextUrlAtError: { if ( Colon() ) { ok = iData->SetNextUrlAtErrorL( AttrValue() ); EndOfLine(); } break; } case ECodInfoUrl: { if ( Colon() ) { ok = aMediaObject->SetInfoUrlL( AttrValue() ); EndOfLine(); } break; } case ECodPrice: { if ( Colon() ) { ok = aMediaObject->SetPriceL( AttrValue() ); EndOfLine(); } break; } case ECodIcon: { if ( Colon() ) { ok = aMediaObject->SetIconL( AttrValue() ); EndOfLine(); } break; } case ECodType: { if ( Colon() ) { ok = aMediaObject->SetTypeL( AttrValue() ); EndOfLine(); } break; } case ECodUrl: { if ( Colon() ) { ok = aMediaObject->SetUrlL( AttrValue() ); EndOfLine(); } break; } case ECodUnknownAttr: { // Name unknown; check colon anyway (syntax check). ok = Colon(); // Rest of the line goes unchecked. break; } default: { // Unexpected value. CodPanic( ECodInternal ); } } if ( !ok ) { Error( KErrCodInvalidDescriptor ); } NextLine(); // Step past LF. return ETrue; // More lines to go. } else { // EOF reached; done. // Note: not expecting EOF in any other place than here (well-formed // COD has complete attrlines. If EOF is found some other place, it // is a syntax error. return EFalse; } }
CSVLine::CSVLine(const char *line): data(line), end(EndOfLine(line)) {}
STATUSCODE ParseFile( PPARSERDATA pParserData, PWSTR pFilename ) /*++ Routine Description: Parse a PCL-XL printer description file Arguments: pParserData - Points to parser data structure pFilename - Specifies the name of the file to be parsed Return Value: ERR_NONE if successful, error code otherwise --*/ { STATUSCODE status; PFILEOBJ pFile; INT syntaxErrors; // // Map the file into memory for read-only access // Verbose(("File %ws\n", pFilename)); if (! (pFile = CreateFileObj(pFilename))) return ERR_FILE; pParserData->pFile = pFile; // // Compute the 16-bit CRC checksum of the file content // pParserData->checksum = ComputeCrc16Checksum(pFile->pStartPtr, pFile->fileSize, pParserData->checksum); // // Process entries in the file // while ((status = ParseEntry(pParserData)) != ERR_EOF) { if (status != ERR_NONE && status != ERR_SYNTAX) { DeleteFileObj(pFile); return status; } } if (EndOfFile(pFile) && !EndOfLine(pFile)) { Warning(("Incomplete last line ignored.\n")); } // // Unmap the file and return to the caller // syntaxErrors = pFile->syntaxErrors; DeleteFileObj(pFile); if (syntaxErrors > 0) { Error(("%d syntax error(s) found in %ws\n", syntaxErrors, pFilename)); return ERR_SYNTAX; } return ERR_NONE; }