这个c ++ html整洁程序有什么问题

时间:2011-02-18 20:50:25

标签: c++ htmltidy

我编译了一个c tidy程序我收到错误,这是他们给出的示例程序

#include "tidy/tidy.h"
#include <stdio.h>
#include <errno.h>


int main(int argc, char **argv )
{
  const char* input = "<title>Foo</title><p>Foo!";
  TidyBuffer output = {0};
  TidyBuffer errbuf = {0};
  int rc = -1;
  Bool ok;

  TidyDoc tdoc = tidyCreate();                     // Initialize "document"
  printf( "Tidying:\t%s\n", input );

  ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
  if ( ok )
    rc = tidySetErrorBuffer( tdoc, &errbuf );      // Capture diagnostics
  if ( rc >= 0 )
    rc = tidyParseString( tdoc, input );           // Parse the input
  if ( rc >= 0 )
    rc = tidyCleanAndRepair( tdoc );               // Tidy it up!
  if ( rc >= 0 )
    rc = tidyRunDiagnostics( tdoc );               // Kvetch
  if ( rc > 1 )                                    // If error, force output.
    rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
  if ( rc >= 0 )
    rc = tidySaveBuffer( tdoc, &output );          // Pretty Print

  if ( rc >= 0 )
  {
    if ( rc > 0 )
      printf( "\nDiagnostics:\n\n%s", errbuf.bp );
    printf( "\nAnd here is the result:\n\n%s", output.bp );
  }
  else
    printf( "A severe error (%d) occurred.\n", rc );

  tidyBufFree( &output );
  tidyBufFree( &errbuf );
  tidyRelease( tdoc );
  return rc;
}

错误

项目cr **的配置构建

全部

Building file: ../src/a.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/a.d" -MT"src/a.d" -o"src/a.o" "../src/a.cpp"
../src/a.cpp: In function ‘int main(int, char**)’:
../src/a.cpp:9: error: variable ‘TidyBuffer output’ has initializer but incomplete type
../src/a.cpp:10: error: variable ‘TidyBuffer errbuf’ has initializer but incomplete type
../src/a.cpp:40: error: ‘tidyBufFree’ was not declared in this scope
make: *** [src/a.o] Error 1

1 个答案:

答案 0 :(得分:5)

TidyBuffer结构在Tidy库头buffio.h中声明,所以如果你包含它也应该有效。

顶部的包含应该如下所示:

#include <tidy.h>
#include <buffio.h>
#include <errno.h>