Back to index

tetex-bin  3.0
Defines | Functions
add_tries.c File Reference
#include <curses.priv.h>

Go to the source code of this file.

Defines

#define SET_TRY(dst, src)   if ((dst->ch = *src++) == 128) dst->ch = '\0'
#define CMP_TRY(a, b)   ((a)? (a == b) : (b == 128))

Functions

 _nc_add_to_try (struct tries **tree, const char *str, unsigned short code)

Define Documentation

#define CMP_TRY (   a,
  b 
)    ((a)? (a == b) : (b == 128))

Definition at line 45 of file add_tries.c.

#define SET_TRY (   dst,
  src 
)    if ((dst->ch = *src++) == 128) dst->ch = '\0'

Definition at line 44 of file add_tries.c.


Function Documentation

_nc_add_to_try ( struct tries **  tree,
const char *  str,
unsigned short  code 
)

Definition at line 48 of file add_tries.c.

{
    static bool out_of_memory = FALSE;
    struct tries *ptr, *savedptr;
    unsigned const char *txt = (unsigned const char *) str;

    if (txt == 0 || *txt == '\0' || out_of_memory || code == 0)
       return;

    if ((*tree) != 0) {
       ptr = savedptr = (*tree);

       for (;;) {
           unsigned char cmp = *txt;

           while (!CMP_TRY(ptr->ch, cmp)
                 && ptr->sibling != 0)
              ptr = ptr->sibling;

           if (CMP_TRY(ptr->ch, cmp)) {
              if (*(++txt) == '\0') {
                  ptr->value = code;
                  return;
              }
              if (ptr->child != 0)
                  ptr = ptr->child;
              else
                  break;
           } else {
              if ((ptr->sibling = typeCalloc(struct tries, 1)) == 0) {
                  out_of_memory = TRUE;
                  return;
              }

              savedptr = ptr = ptr->sibling;
              SET_TRY(ptr, txt);
              ptr->value = 0;

              break;
           }
       }                    /* end for (;;) */
    } else {                /* (*tree) == 0 :: First sequence to be added */
       savedptr = ptr = (*tree) = typeCalloc(struct tries, 1);

       if (ptr == 0) {
           out_of_memory = TRUE;
           return;
       }

       SET_TRY(ptr, txt);
       ptr->value = 0;
    }

    /* at this point, we are adding to the try.  ptr->child == 0 */

    while (*txt) {
       ptr->child = typeCalloc(struct tries, 1);

       ptr = ptr->child;

       if (ptr == 0) {
           out_of_memory = TRUE;

           while ((ptr = savedptr) != 0) {
              savedptr = ptr->child;
              free(ptr);
           }

           return;
       }

       SET_TRY(ptr, txt);
       ptr->value = 0;
    }

    ptr->value = code;
    return;
}

Here is the call graph for this function:

Here is the caller graph for this function: