Exemplo n.º 1
0
uint TY_(Win32MLangGetCPFromName)(TidyAllocator *allocator, ctmbstr encoding)
{
    uint i;
    tmbstr enc;

    /* ensure name is in lower case */
    enc = TY_(tmbstrdup)(allocator,encoding);
    enc = TY_(tmbstrtolower)(enc);

    for (i = 0; NameWinCPMap[i].name; ++i)
    {
        if (TY_(tmbstrcmp)(NameWinCPMap[i].name, enc) == 0)
        {
            IMLangConvertCharset * p = NULL;
            uint wincp = NameWinCPMap[i].wincp;
            HRESULT hr;

            TidyFree(allocator, enc);

            /* currently no support for unsafe encodings */
            if (!NameWinCPMap[i].safe)
                return 0;

            /* hack for config.c */
            CoInitialize(NULL);
            hr = CreateMLangObject(p);

            if (hr != S_OK || !p)
            {
                wincp = 0;
            }
            else
            {
                hr = IMLangConvertCharset_Initialize(p, wincp, 1200, 0);

                if (hr != S_OK)
                    wincp = 0;

                IMLangConvertCharset_Release(p);
                p = NULL;
            }

            CoUninitialize();

            return wincp;
        }
    }

    TidyFree(allocator, enc);
    return 0;
}
Exemplo n.º 2
0
/**
 *  Retrieves the POSIX name for a string. Result is a static char so please
 *  don't try to free it. If the name looks like a cc_ll identifier, we will
 *  return it if there's no other match.
 *  @note this routine uses default allocator, see tidySetMallocCall.
 */
tmbstr TY_(tidyNormalizedLocaleName)( ctmbstr locale )
{
    uint i;
    uint len;
    static char result[6] = "xx_yy";
    TidyAllocator * allocator = &TY_(g_default_allocator);

    tmbstr search = TY_(tmbstrdup)( allocator, locale );
    search = TY_(tmbstrtolower)(search);
    
    /* See if our string matches a Windows name. */
    for (i = 0; localeMappings[i].winName; ++i)
    {
        if ( strcmp( localeMappings[i].winName, search ) == 0 )
        {
            TidyFree( allocator, search );
            search = TY_(tmbstrdup)( allocator, localeMappings[i].POSIXName );
            break;
        }
    }
    
    /* We're going to be stupid about this and trust the user, and
     return just the first two characters if they exist and the
     4th and 5th if they exist. The worst that can happen is a
     junk language that doesn't exist and won't be set. */
    
    len = strlen( search );
    len = ( len <= 5 ? len : 5 );
    
    for ( i = 0; i < len; i++ )
    {
        if ( i == 2 )
        {
            /* Either terminate the string or ensure there's an underscore */
            if (len == 5) {
                result[i] = '_';
            }
            else {
                result[i] = '\0';
                break;      /* no need to copy after null */
            }
        }
        else
        {
            result[i] = tolower( search[i] );
        }
    }
    
    TidyFree( allocator, search );
    return result;
}
Exemplo n.º 3
0
int TY_(initFileSource)( TidyAllocator *allocator, TidyInputSource* inp, FILE* fp )
{
    MappedFileSource* fin;
    struct stat sbuf;
    int fd;

    fin = (MappedFileSource*) TidyAlloc( allocator, sizeof(MappedFileSource) );
    if ( !fin )
        return -1;

    fd = fileno(fp);
    if ( fstat(fd, &sbuf) == -1
         || sbuf.st_size == 0
         || (fin->base = mmap(0, fin->size = sbuf.st_size, PROT_READ,
                              MAP_SHARED, fd, 0)) == MAP_FAILED)
    {
        TidyFree( allocator, fin );
        /* Fallback on standard I/O */
        return TY_(initStdIOFileSource)( allocator, inp, fp );
    }

    fin->pos = 0;
    fin->allocator = allocator;
    fclose(fp);

    inp->getByte    = mapped_getByte;
    inp->eof        = mapped_eof;
    inp->ungetByte  = mapped_ungetByte;
    inp->sourceData = fin;

    return 0;
}
Exemplo n.º 4
0
void TY_(freeFileSource)( TidyInputSource* inp, Bool closeIt )
{
    if ( inp->getByte == mapped_getByte )
    {
        MappedFileSource* fin = (MappedFileSource*) inp->sourceData;
        munmap( (void*)fin->base, fin->size );
        TidyFree( fin->allocator, fin );
    }
    else
        TY_(freeStdIOFileSource)( inp, closeIt );
}
Exemplo n.º 5
0
void tidyGetLinks( TidyDoc tdoc, TidyBuffer* outbuf )
{
  TidyDocImpl* doc = tidyDocToImpl( tdoc );
  // uint outenc = cfg( doc, TidyOutCharEncoding );
  uint outenc = doc->config.value[ TidyOutCharEncoding ].v;
  // uint nl = cfg( doc, TidyNewline );
  uint nl = doc->config.value[ TidyNewline ].v;
  StreamOut* out = TY_(BufferOutput)( doc, outbuf, outenc, nl );
  doc->docOut = out;

  Node * html = TY_(FindHTML)( doc );
  if( html )
  {
    GetLinksRecusiv( doc, html );
  }

  doc->docOut = NULL;
  TidyFree( TALLOC, out );
}
Exemplo n.º 6
0
void TIDY_CALL tidyBufFree( TidyBuffer* buf )
{
    assert( buf != NULL );
    TidyFree(  buf->allocator, buf->bp );
    tidyBufInitWithAllocator( buf, buf->allocator );
}