program optdemo;

{ Simple demo of how to iterate through tidy's option settings. }

{$H+}
uses tidy_h;


procedure ShowOption(doc:pTidyDoc; opt:pTidyOption; id:TidyOptionId; MaxLen:LongInt);
var
  name:string;
begin
  if ( id in [TidyUnknownOption, N_TIDY_OPTIONS] ) then EXIT;
  name:=tidyOptGetName(opt);
  name:=name+StringOfChar(' ', MaxLen-length(name));
  Write(' ', name);
  if tidyOptIsReadOnly(opt) then Write(' RO') else Write(' RW');
  case tidyOptGetType(opt) of
    TidyString:  WriteLn(' String  = ', tidyOptGetValue(doc, id));
    TidyInteger: WriteLn(' Integer = ', tidyOptGetInt(doc, id));
    TidyBoolean: WriteLn(' Boolean = ', tidyOptGetBool(doc, id));
  end;
end;


var
  doc:pTidyDoc;
  iter:pTidyIterator;
  opt:pTidyOption;
  id:TidyOptionId;
  cat:TidyConfigCategory;
  MaxLen, L:LongInt;
  USE_ITERATOR:Boolean;

begin

  USE_ITERATOR:=True;

  doc:=tidyCreate;
  MaxLen:=0;

  for id :=low(TidyOptionId) to high(TidyOptionId) do begin
    L:=length(string(tidyOptGetName(tidyGetOption(doc, id))));
    if ( L > MaxLen ) then MaxLen:=L;
  end;


  for cat:=low(TidyConfigCategory) to high(TidyConfigCategory) do begin

    case cat of
      TidyMarkup:        WriteLn('Markup Options:');
      TidyDiagnostics:   WriteLn('Diagnostics Options:');
      TidyPrettyPrint:   WriteLn('Pretty Print Options:');
      TidyEncoding:      WriteLn('Encoding Options:');
      TidyMiscellaneous: WriteLn('Miscellaneous Options:');
    end;

    if USE_ITERATOR then begin
      iter:=tidyGetOptionList(doc);
      repeat
        opt:=tidyGetNextOption(doc, @iter);
        if ( opt = nil ) then BREAK;
        if ( tidyOptGetCategory(opt) = cat ) then ShowOption(doc, opt, tidyOptGetID(opt), MaxLen);
      until FALSE;
    end else begin
      for id :=low(TidyOptionId) to high(TidyOptionId) do begin
        opt:=tidyGetOption(doc, id);
        if ( tidyOptGetCategory(opt) = cat ) then ShowOption(doc, opt, id, MaxLen);
      end;
    end;

    WriteLn;
  end;

end.




Get CurlPas and TidyPas at SourceForge.net. Fast, secure and Free Open Source software downloads