Logo Search packages:      
Sourcecode: jclassinfo version File versions  Download package

int string_list_add ( StringList list,
const char *  new_string,
int  flag 
)

string_list_add : The list to add the string. : The string to add. : The flag for the string.

If the string is already in the list it will not be added. If the string has other flags set, the given flag will also be set.

Returns: 1 if the string was added, 0 otherwise.

Definition at line 152 of file string_list.c.

References StringList::head.

{
      struct string_node* node;
      struct string_node* prev;
      struct string_node* next;
      
      if(new_string == NULL)
            return 0;
      
      next = list->head;
      prev = NULL;
      
      while(next != NULL && strcmp(next->string, new_string) < 0)
      {
            prev = next;
            next = next->next;
      }
            
      if((next == NULL) || strcmp(next->string, new_string))
      {
            node = (struct string_node*) malloc(sizeof(struct string_node));
            node->string = strdup(new_string);
            node->flag = flag;
            node->next = next;

            if(next == list->head)
                  list->head = node;
            else
                  prev->next = node;
      }
      else
      {
            /* if IS_LOCAL set remove IS_DEPENDENCY from flags */
            if(next->flag & IS_LOCAL)
                  flag &= ~IS_DEPENDENCY;
            
            flag &= ~(next->flag);

            if(!flag)
                  return 0;

            next->flag |= flag;
      }
      return 1;
}

Generated by  Doxygen 1.6.0   Back to index