- Timestamp:
- May 2, 2014, 8:06:58 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UKConfig.pas
r9 r10 42 42 43 43 TMenuNode = class 44 Index: Integer;45 44 ID: string; 46 45 Name: string; 47 Condition: string;48 46 Depends: TStringList; 49 47 Selects: TStringList; … … 51 49 Items: TObjectList; // TList<TMenuNode> 52 50 Parent: TMenuNode; 53 NewParent: TMenuNode;51 //NewParent: TMenuNode; 54 52 DefaultValue: string; 55 53 ValueType: TValueType; … … 59 57 constructor Create; virtual; 60 58 destructor Destroy; override; 61 function HaveUpperNode(Node: TMenuNode): Boolean; 59 procedure ChangeParent(NewParent: TMenuNode); 60 procedure AddLastToList(List: TObjectList); 62 61 function GetName: string; virtual; 63 62 function GetAbsoluteName: string; virtual; … … 67 66 procedure Search(Text: string; List: TObjectList); virtual; 68 67 procedure SaveToList(List: TStrings); virtual; 69 procedure PrepareMoveList(Lookup: TStringList; var List: TObjectMoves); virtual;68 function PrepareMoveList(Lookup: TStringList; var List: TObjectMoves): Boolean; virtual; 70 69 function GetCount: Integer; virtual; 71 70 function GetTopNode: TMenuNode; virtual; … … 83 82 Arch: string; 84 83 FOnLog: TOnLogEvent; 85 IndexCounter: Integer;86 84 function GetTopCondition: string; 87 85 procedure Log(Text: string); … … 143 141 end; 144 142 145 function TMenuNode.HaveUpperNode(Node: TMenuNode): Boolean; 146 begin 147 Result := False; 148 if NewParent = Node then Result := True 149 else if Assigned(NewParent) then Result := NewParent.HaveUpperNode(Node); 143 procedure TMenuNode.ChangeParent(NewParent: TMenuNode); 144 var 145 LastOwnState: Boolean; 146 begin 147 try 148 LastOwnState := Parent.Items.OwnsObjects; 149 Parent.Items.OwnsObjects := False; 150 Parent.Items.Remove(Self); 151 finally 152 Parent.Items.OwnsObjects := LastOwnState; 153 end; 154 Parent := NewParent; 155 NewParent.Items.Add(Self); 156 end; 157 158 procedure TMenuNode.AddLastToList(List: TObjectList); 159 begin 160 List.Add(Self); 161 if Items.Count > 0 then begin 162 TMenuNode(Items.Last).AddLastToList(List); 163 end; 150 164 end; 151 165 … … 181 195 with List do begin 182 196 Clear; 183 Add('Index: ' + IntToStr(Index));184 197 Add('ID: ' + ID); 185 198 Add('Name: ' + Name); … … 187 200 Add('Selects: ' + Selects.Text); 188 201 Add('Description: ' + Description.Text); 189 Add('Condition: ' + Condition);190 202 Add('Value type: ' + IntToStr(Integer(ValueType))); 191 203 Add('Default value: ' + DefaultValue); 204 Add('Path: ' + GetAbsoluteName); 192 205 end; 193 206 end; … … 224 237 end; 225 238 226 procedure TMenuNode.PrepareMoveList(Lookup: TStringList; var List: TObjectMoves);227 var 228 I: Integer; 229 Node: TMenuNode;239 function TMenuNode.PrepareMoveList(Lookup: TStringList; var List: TObjectMoves): Boolean; 240 var 241 I: Integer; 242 J: Integer; 230 243 NewMove: TObjectMove; 231 244 Index: Integer; 232 P: TMenuNode;233 245 LatestNode: TMenuNode; 234 begin 235 if ID = 'PARAVIRT_DEBUG' then 236 Name := Name + '$'; 237 NewParent := Parent; 238 P := Parent; 239 { if Condition <> '' then begin 240 Index := Lookup.IndexOf(Condition); 241 if Index <> -1 then Node := TMenuNode(Lookup.Objects[Index]) 242 else Node := nil; 243 if Assigned(Node) and (NewParent <> Node) and Node.MenuConfig then begin 244 NewParent := Node; 246 CheckList: TObjectList; 247 begin 248 Result := False; 249 try 250 CheckList := TObjectList.Create; 251 CheckList.OwnsObjects := False; 252 if Assigned(Parent) then begin 253 Index := Parent.Items.IndexOf(Self); 254 if Index = -1 then raise Exception.Create('Node not found in parent'); 255 if Index >= 1 then TMenuNode(Parent.Items[Index - 1]).AddLastToList(CheckList); 256 for I := CheckList.Count - 1 downto 0 do begin 257 for J := 0 to Depends.Count - 1 do 258 if Trim(Depends[J]) <> '' then begin 259 if (Depends[J] = TMenuNode(CheckList[I]).ID) and (TMenuNode(CheckList[I]).ValueType <> vtChoice) then begin 260 ChangeParent(TMenuNode(CheckList[I])); 261 Result := True; 262 Break; 263 end; 264 end; 265 if Result then Break; 245 266 end; 246 end;}247 I := 0;248 LatestNode := NewParent;249 while I < Depends.Count do begin250 Index := Lookup.IndexOf(Depends[I]);251 if Index <> -1 then Node := TMenuNode(Lookup.Objects[Index])252 else Node := nil;253 if Assigned(Node) and (NewParent <> Node) and (Node.HaveUpperNode(NewParent)) and254 (Node.Index > LatestNode.Index) then begin255 LatestNode := Node;256 267 end; 257 Inc(I); 258 end; 259 NewParent := LatestNode; 260 261 if NewParent <> Parent then begin 262 NewMove.Source := Self; 263 NewMove.NewParent := NewParent; 264 SetLength(List, Length(List) + 1); 265 List[Length(List) - 1] := NewMove; 268 finally 269 CheckList.Free; 266 270 end; 267 271 … … 269 273 while I < Items.Count do 270 274 with TMenuNode(Items[I]) do begin 271 PrepareMoveList(Lookup, List); 272 Inc(I); 275 if not PrepareMoveList(Lookup, List) then Inc(I); 273 276 end; 274 277 end; … … 323 326 function TConfigMenu.IsWhiteSpace(Character: Char): Boolean; 324 327 begin 325 Result := (Character = ' ') or (Character = #9);328 Result := (Character >= #0) and (Character <= ' '); 326 329 end; 327 330 … … 362 365 Content: TStringList; 363 366 I: Integer; 367 J: Integer; 364 368 Command: string; 365 369 Parameter: string; 366 370 Line: string; 367 State: (stNormal, stConfig, stHelp );371 State: (stNormal, stConfig, stHelp, stHelpStart); 368 372 NewItem: TMenuNode; 369 373 NewMenu: TMenuNode; … … 376 380 Result := FileName + ':' + IntToStr(I + 1) + ' ' + Content[I]; 377 381 end; 382 383 const 384 TabSize = 8; 378 385 379 386 begin … … 389 396 Line := MergedLines + Content[I]; 390 397 MergedLines := ''; 391 LineIndent := 1; 392 while (LineIndent <= Length(Line)) and IsWhiteSpace(Line[LineIndent]) do Inc(LineIndent); 393 if (State = stHelp) and (Trim(Line) <> '') and (LineIndent = 1) then 398 LineIndent := 0; 399 J := 1; 400 while (J <= Length(Line)) and IsWhiteSpace(Line[J]) do begin 401 if Line[J] = #9 then LineIndent := (Trunc(LineIndent / TabSize) + 1) * TabSize 402 else Inc(LineIndent); 403 Inc(J); 404 end; 405 if (State = stHelp) and (Trim(Line) <> '') then begin 406 State := stHelpStart; 407 if LineIndent = 0 then State := stNormal; 408 HelpIndent := LineIndent; 409 if (State = stHelpStart) and (HelpIndent = 0) then 410 raise Exception.Create('Error during help parsing'); 411 end; 412 if (State = stHelpStart) and (Trim(Line) <> '') and (LineIndent < HelpIndent) then 394 413 State := stNormal; 395 414 … … 411 430 end; 412 431 Command := GetNextToken(Line); 413 if State = stHelpthen begin432 if (State = stHelp) or (State = stHelpStart) then begin 414 433 NewItem.Description.Add(Trim(Content[I])); 415 434 end else … … 496 515 Command := GetNextToken(Line); 497 516 if Command = 'help' then begin 498 Parameter := GetNextToken(Line);499 517 State := stHelp; 500 518 HelpIndent := LineIndent; … … 502 520 end else 503 521 if (Command = 'help') or (Command = '---help---') then begin 504 Parameter := GetNextToken(Line);505 522 State := stHelp; 506 523 HelpIndent := LineIndent; … … 515 532 NewItem.Parent := CurrentMenu; 516 533 NewItem.ID := Parameter; 517 NewItem.Condition := GetTopCondition; 518 NewItem.Index := IndexCounter; 519 Inc(IndexCounter); 534 NewItem.Depends.AddStrings(ConditionStack); 520 535 CurrentMenu.Items.Add(NewItem); 521 536 if Command = 'menuconfig' then NewItem.MenuConfig := True; … … 526 541 NewItem.Parent := CurrentMenu; 527 542 NewItem.Name := Parameter; 528 NewItem.Condition := GetTopCondition; 529 NewItem.Index := IndexCounter; 530 Inc(IndexCounter); 543 NewItem.Depends.AddStrings(ConditionStack); 531 544 NewItem.ValueType := vtComment; 532 545 CurrentMenu.Items.Add(NewItem); … … 547 560 NewMenu.Name := Parameter; 548 561 NewMenu.Parent := CurrentMenu; 549 NewMenu.Condition := GetTopCondition; 550 NewMenu.Index := IndexCounter; 551 Inc(IndexCounter); 562 NewMenu.Depends.AddStrings(ConditionStack); 552 563 ConditionStack.AddObject('', nil); 553 564 NewItem := NewMenu; … … 573 584 NewMenu.Name := Parameter; 574 585 NewMenu.Parent := CurrentMenu; 575 NewMenu. Condition := GetTopCondition;586 NewMenu.Depends.AddStrings(ConditionStack); 576 587 ConditionStack.AddObject('', nil); 577 588 NewItem := NewMenu; … … 588 599 if Command = 'if' then begin 589 600 ConditionStack.AddObject(GetNextToken(Line), NewItem); 590 if Assigned(NewItem) and NewItem.MenuConfig then begin591 CurrentMenu := NewItem;592 end;593 601 end else 594 602 if Command = 'visible' then begin … … 596 604 end else 597 605 if Command = 'endif' then begin 598 if Assigned(ConditionStack.Objects[ConditionStack.Count - 1]) then599 if TMenuNode(ConditionStack.Objects[ConditionStack.Count - 1]).MenuConfig then600 CurrentMenu := CurrentMenu.Parent;601 606 ConditionStack.Delete(ConditionStack.Count - 1); 602 607 end else … … 615 620 TopNode.Name := 'Root'; 616 621 CurrentMenu := TopNode; 617 IndexCounter := 1;618 622 ParseFile(BaseDir + DirectorySeparator + 'Kconfig'); 619 623 end; … … 664 668 Node := TopNode.FindNode(List[I]); 665 669 if Assigned(Node) then 666 List[I] := Node.GetAbsoluteName + ' (' + List[I] + ')';670 List[I] := '"' + Node.GetAbsoluteName + '";' + List[I]; 667 671 end; 668 672 end;
Note:
See TracChangeset
for help on using the changeset viewer.