diff --git a/components/codetools/avl_tree.pas b/components/codetools/avl_tree.pas index c9dbd74b0e..6d516281cb 100644 --- a/components/codetools/avl_tree.pas +++ b/components/codetools/avl_tree.pas @@ -31,7 +31,11 @@ unit AVL_Tree; interface -uses Classes, SysUtils; +{off $DEFINE MEM_CHECK} + +uses + {$IFDEF MEM_CHECK}MemCheck,{$ENDIF} + Classes, SysUtils; type TAVLTreeNode = class diff --git a/components/codetools/codetools.inc b/components/codetools/codetools.inc index dabea19416..9e766e1f13 100644 --- a/components/codetools/codetools.inc +++ b/components/codetools/codetools.inc @@ -25,8 +25,8 @@ } -{ $DEFINE MEM_CHECK} +{off $DEFINE MEM_CHECK} -{ $DEFINE CTDEBUG} +{off $DEFINE CTDEBUG} // end. diff --git a/components/codetools/laz_xmlcfg.pas b/components/codetools/laz_xmlcfg.pas index 14f24705fa..ef7881c9d8 100644 --- a/components/codetools/laz_xmlcfg.pas +++ b/components/codetools/laz_xmlcfg.pas @@ -32,7 +32,11 @@ unit Laz_XMLCfg; interface -uses Classes, Laz_DOM, Laz_XMLRead, Laz_XMLWrite; +{off $DEFINE MEM_CHECK} + +uses + {$IFDEF MEM_CHECK}MemCheck,{$ENDIF} + Classes, Laz_DOM, Laz_XMLRead, Laz_XMLWrite; type @@ -74,6 +78,7 @@ uses SysUtils; constructor TXMLConfig.Create(const AFilename: String); begin + //writeln('TXMLConfig.Create ',AFilename); inherited Create(nil); SetFilename(AFilename); end; @@ -207,6 +212,8 @@ var f: File; cfg: TDOMElement; begin + {$IFDEF MEM_CHECK}CheckHeapWrtMemCnt('TXMLConfig.SetFilename A '+AFilename);{$ENDIF} + if FFilename = AFilename then exit; FFilename := AFilename; if csLoading in ComponentState then @@ -224,7 +231,9 @@ begin {$I+} if IOResult = 0 then try + {$IFDEF MEM_CHECK}CheckHeapWrtMemCnt('TXMLConfig.SetFilename B');{$ENDIF} ReadXMLFile(doc, f); + {$IFDEF MEM_CHECK}CheckHeapWrtMemCnt('TXMLConfig.SetFilename C');{$ENDIF} finally CloseFile(f); end; @@ -237,12 +246,16 @@ begin cfg := doc.CreateElement('CONFIG'); doc.AppendChild(cfg); end; + {$IFDEF MEM_CHECK}CheckHeapWrtMemCnt('TXMLConfig.SetFilename END');{$ENDIF} end; end. { $Log$ + Revision 1.3 2002/09/13 16:58:27 lazarus + MG: removed the 1x1 bitmap from TBitBtn + Revision 1.2 2002/07/30 14:36:28 lazarus MG: accelerated xmlread and xmlwrite diff --git a/components/codetools/laz_xmlread.pas b/components/codetools/laz_xmlread.pas index 18166f834d..059eab305d 100644 --- a/components/codetools/laz_xmlread.pas +++ b/components/codetools/laz_xmlread.pas @@ -20,14 +20,18 @@ **********************************************************************} +unit Laz_XMLRead; + {$MODE objfpc} {$H+} -unit Laz_XMLRead; - interface -uses SysUtils, Classes, Laz_DOM; +{off $DEFINE MEM_CHECK} + +uses + {$IFDEF MEM_CHECK}MemCheck,{$ENDIF} + SysUtils, Classes, Laz_DOM; type @@ -62,8 +66,63 @@ const NmToken: set of Char = Letter + Digit + ['.', '-', '_', ':']; -type +function CompareIPChar(p1, p2: PChar): boolean; +begin + if p1<>p2 then begin + if (p1<>nil) and (p2<>nil) then begin + while true do begin + if (p1^=p2^) then begin + if p1^<>#0 then begin + inc(p1); + inc(p2); + end else begin + Result:=true; + exit; + end; + end else begin + Result:=false; + exit; + end; + end; + Result:=true; + end else begin + Result:=false; + end; + end else begin + Result:=true; + end; +end; +function CompareLIPChar(p1, p2: PChar; Max: integer): boolean; +begin + if p1<>p2 then begin + if (p1<>nil) and (p2<>nil) then begin + while Max>0 do begin + if (p1^=p2^) then begin + if (p1^<>#0) then begin + inc(p1); + inc(p2); + dec(Max); + end else begin + Result:=true; + exit; + end; + end else begin + Result:=false; + exit; + end; + end; + Result:=true; + end else begin + Result:=false; + end; + end else begin + Result:=true; + end; +end; + + +type TXMLReaderDocument = class(TXMLDocument) public procedure SetDocType(ADocType: TDOMDocumentType); @@ -83,19 +142,22 @@ type buf, BufStart: PChar; Filename: String; - procedure RaiseExc(descr: String); + procedure RaiseExc(const descr: String); function SkipWhitespace: Boolean; procedure ExpectWhitespace; - procedure ExpectString(s: String); + procedure ExpectString(const s: String); function CheckFor(s: PChar): Boolean; - procedure SkipString(ValidChars: TSetOfChar); - function GetString(ValidChars: TSetOfChar): String; + procedure SkipString(const ValidChars: TSetOfChar); + function GetString(const ValidChars: TSetOfChar): String; function GetString(BufPos: PChar; Len: integer): String; + function CheckName: Boolean; function GetName(var s: String): Boolean; function ExpectName: String; // [5] + procedure SkipName; procedure ExpectAttValue(attr: TDOMAttr); // [10] function ExpectPubidLiteral: String; // [12] + procedure SkipPubidLiteral; function ParseComment(AOwner: TDOMNode): Boolean; // [15] function ParsePI: Boolean; // [16] procedure ExpectProlog; // [22] @@ -111,15 +173,16 @@ type function ParseExternalID: Boolean; // [75] procedure ExpectExternalID; function ParseEncodingDecl: String; // [80] + procedure SkipEncodingDecl; procedure ResolveEntities(RootNode: TDOMNode); public doc: TXMLReaderDocument; - procedure ProcessXML(ABuf: PChar; AFilename: String); // [1] - procedure ProcessDTD(ABuf: PChar; AFilename: String); // ([29]) + procedure ProcessXML(ABuf: PChar; const AFilename: String); // [1] + procedure ProcessDTD(ABuf: PChar; const AFilename: String); // ([29]) end; - +{ TXMLReaderDocument } procedure TXMLReaderDocument.SetDocType(ADocType: TDOMDocumentType); begin @@ -134,7 +197,7 @@ end; -procedure TXMLReader.RaiseExc(descr: String); +procedure TXMLReader.RaiseExc(const descr: String); var apos: PChar; x, y: Integer; @@ -172,19 +235,26 @@ begin RaiseExc('Expected whitespace'); end; -procedure TXMLReader.ExpectString(s: String); +procedure TXMLReader.ExpectString(const s: String); + + procedure RaiseStringNotFound; + var + s2: PChar; + s3: String; + begin + GetMem(s2, Length(s) + 1); + StrLCopy(s2, buf, Length(s)); + s3 := StrPas(s2); + FreeMem(s2, Length(s) + 1); + RaiseExc('Expected "' + s + '", found "' + s3 + '"'); + end; + var i: Integer; - s2: PChar; - s3: String; begin for i := 1 to Length(s) do if buf[i - 1] <> s[i] then begin - GetMem(s2, Length(s) + 1); - StrLCopy(s2, buf, Length(s)); - s3 := StrPas(s2); - FreeMem(s2, Length(s) + 1); - RaiseExc('Expected "' + s + '", found "' + s3 + '"'); + RaiseStringNotFound; end; Inc(buf, Length(s)); end; @@ -202,14 +272,14 @@ begin Result := False; end; -procedure TXMLReader.SkipString(ValidChars: TSetOfChar); +procedure TXMLReader.SkipString(const ValidChars: TSetOfChar); begin while buf[0] in ValidChars do begin Inc(buf); end; end; -function TXMLReader.GetString(ValidChars: TSetOfChar): String; +function TXMLReader.GetString(const ValidChars: TSetOfChar): String; var OldBuf: PChar; i, len: integer; @@ -236,7 +306,7 @@ begin end; end; -procedure TXMLReader.ProcessXML(ABuf: PChar; AFilename: String); // [1] +procedure TXMLReader.ProcessXML(ABuf: PChar; const AFilename: String); // [1] //var // LastNodeBeforeDoc: TDOMNode; begin @@ -246,8 +316,10 @@ begin doc := TXMLReaderDocument.Create; ExpectProlog; + {$IFDEF MEM_CHECK}CheckHeapWrtMemCnt('TXMLReader.ProcessXML A');{$ENDIF} //LastNodeBeforeDoc := doc.LastChild; ExpectElement(doc); + {$IFDEF MEM_CHECK}CheckHeapWrtMemCnt('TXMLReader.ProcessXML B');{$ENDIF} ParseMisc(doc); if buf[0] <> #0 then @@ -262,6 +334,20 @@ begin } end; +function TXMLReader.CheckName: Boolean; +var OldBuf: PChar; +begin + if not (buf[0] in (Letter + ['_', ':'])) then begin + Result := False; + exit; + end; + + OldBuf := buf; + Inc(buf); + SkipString(Letter + ['0'..'9', '.', '-', '_', ':']); + buf := OldBuf; + Result := True; +end; function TXMLReader.GetName(var s: String): Boolean; // [5] var OldBuf: PChar; @@ -280,10 +366,16 @@ begin end; function TXMLReader.ExpectName: String; // [5] + + procedure RaiseNameNotFound; + begin + RaiseExc('Expected letter, "_" or ":" for name, found "' + buf[0] + '"'); + end; + var OldBuf: PChar; begin if not (buf[0] in (Letter + ['_', ':'])) then - RaiseExc('Expected letter, "_" or ":" for name, found "' + buf[0] + '"'); + RaiseNameNotFound; OldBuf := buf; Inc(buf); @@ -291,19 +383,32 @@ begin Result:=GetString(OldBuf,buf-OldBuf); end; +procedure TXMLReader.SkipName; + + procedure RaiseSkipNameNotFound; + begin + RaiseExc('Expected letter, "_" or ":" for name, found "' + buf[0] + '"'); + end; + +begin + if not (buf[0] in (Letter + ['_', ':'])) then + RaiseSkipNameNotFound; + + Inc(buf); + SkipString(Letter + ['0'..'9', '.', '-', '_', ':']); +end; + procedure TXMLReader.ExpectAttValue(attr: TDOMAttr); // [10] var - s: String; OldBuf: PChar; procedure FlushStringBuffer; + var + s: String; begin if OldBuf<>buf then begin - s := s + GetString(OldBuf,buf-OldBuf); + s := GetString(OldBuf,buf-OldBuf); OldBuf := buf; - end; - if Length(s) > 0 then - begin attr.AppendChild(doc.CreateTextNode(s)); SetLength(s, 0); end; @@ -317,12 +422,11 @@ begin StrDel[0] := buf[0]; StrDel[1] := #0; Inc(buf); - SetLength(s, 0); OldBuf := buf; while not CheckFor(StrDel) do if buf[0] = '&' then begin - FlushStringBuffer; + if OldBuf<>buf then FlushStringBuffer; ParseReference(attr); OldBuf := buf; end else @@ -330,7 +434,7 @@ begin Inc(buf); end; dec(buf); - FlushStringBuffer; + if OldBuf<>buf then FlushStringBuffer; inc(buf); ResolveEntities(Attr); end; @@ -348,13 +452,24 @@ begin RaiseExc('Expected quotation marks'); end; +procedure TXMLReader.SkipPubidLiteral; +begin + if CheckFor('''') then begin + SkipString(PubidChars - ['''']); + ExpectString(''''); + end else if CheckFor('"') then begin + SkipString(PubidChars - ['"']); + ExpectString('"'); + end else + RaiseExc('Expected quotation marks'); +end; + function TXMLReader.ParseComment(AOwner: TDOMNode): Boolean; // [15] var comment: String; OldBuf: PChar; begin if CheckFor('