# HTUtils functions

HTUtils is a subset of the libwww modules that is used by CSLUtils. That is, the CSLUtils modules, CSParse and CSLabel, use certain functionality from libwww. The functions containing these modules have been sequestered into a seperated directory called HTUtils. When CSLApp is being used in an application not based on libwww, it is expected that the developer will either:

1. import the modules
2. emulate their functionality elsewhere in the app
3. define macros to map HT functions to those already in the application

A combination of 1 and 2 can be see in the LablPars example.

## function list

### tracing

- HTTrace - provides a simple error tracing facility. The calling convention is identical to that of printf so

      #define HTTrace printf

  is a perfectly logical implementation.

  ### List functions from HTList.c

- HTList_new
- HTList_delete
- HTList_appendObject
- HTList_removeObject
- HTList_removeLastObject
- HTList_count

  ### Chunk functions from HTChunk.c

- HTChunk_new
- HTChunk_delete
- HTChunk_clear
- HTChunk_putb
- HTChunk_putc

  ### string functions from HTString.c

- strcasecomp
- strcasecomp
- HTSACopy

  ### memory allocation functions from HTMemory.c

- HTMemory_malloc
- HTMemory_calloc
- HTMemory_realloc
- HTMemory_free
- HTMemory_outofmem

## importing HT modules

The simplest way to provide the HT functionality to the application is to add the required modules to the application. Because all libwww functions and macros start with HT, there should be no name collisions. However, this may result in redundant code. If your application already has List, Chunk, string, or memory functions, it may be advisable to use one of the following solutions:

## emulating HT functions in the application

Any of the HT functions may be resolved elsewhere in the application. The LablPars example uses this technique to provide the HTMemory_ functions. It includes simple version of the HTMemory_ functions in LabePars.c, eg:

    void * HTMemory_malloc (size_t size)
    {
        return malloc(size);
    }

    void HTMemory_free (void * ptr)
    {
        free(ptr);
    }

## mapping HT functions to application functions

The parser modules all include HTUtils.h. This module maps macros to the HT functions listed above. The developer may with to replace HTUtils.h with one that maps the macros to funtions already present in the application. Some of the functions, HTTrace, and the HTMemory_ functions, correlate to stdlib functions and may be mapped directly to them, eg:

    #define HT_MALLOC malloc
    #define HT_CALLOC calloc
    #define HT_REALLOC realloc
    #define HT_FREE free

## LablPars

The LablParse.c program is an example of a simple application using the CSLUtils interface to libpics. It includes the libwww modules

- HTList.c
- HTChunk.c
- HTString.c

The functionality of HTMemory.c is provided by the HTMemory_ functions in the bottom of LablPars.c. HTMemory.c's implementation of the HTMemory_ functions provides callbacks for out of memory conditions and was more complicated than the LablPars example merrited.