RecklessDarph

Untitled

Dec 15th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. void alias_list_delete(struct alias_list *list)
  2. {
  3. struct alias *current = list->first;
  4.  
  5. while (current != NULL)
  6. {
  7. struct alias *previous = current;
  8. current = current->next;
  9. alias_delete(previous);
  10. }
  11.  
  12. free(list);
  13. }
  14.  
  15. // Append the given (key, value) pair to the given list
  16. //
  17. // Python: list.append((key, value))
  18. void alias_list_append(struct alias_list *list, char *key, char *value)
  19. {
  20. if (list->first==NULL){
  21. struct *alias = alias_create(key, value);
  22. list->first = alias;
  23. }
  24. else{
  25. struct alias *current = list->first;
  26. while (current->next != NULL){
  27. current = current->next;
  28. }
  29. struct *alias = alias_create(key, value);
  30. current->next = alias;
  31. }
  32. }
  33.  
  34. // Return the value of the element with the given key. If the given key was not
  35. // found, the value NULL is returned.
  36. char *alias_list_lookup(struct alias_list *list, char *key)
  37. {
  38. if(list->first!=NULL){
  39. struct *current=list->first;
  40. if(strcmp(current->key,key)==0){
  41. return current->value;
  42. }
  43. while(current->next!=NULL){
  44. current = current->next;
  45. if(strcmp(current->key,key)==0){
  46. return current->value;
  47. }
  48. }
  49. }
  50. return NULL;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment