File: string_list.c

package info (click to toggle)
cpufreqd 1.2.3-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,648 kB
  • ctags: 210
  • sloc: sh: 8,665; ansic: 1,648; makefile: 120
file content (68 lines) | stat: -rw-r--r-- 2,056 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 *  Copyright (C) 2002,2003,2004  Mattia Dongili<dongili@supereva.it>
 *                                George Staikos <staikos@0wned.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include "string_list.h"


int string_list_free_sublist(struct string_list *list, struct string_node *start) {
  int ret = 0;
  struct string_node *prev = 0L;
  
  /* return if !start */
  if (!start)
    return 0;
  
  /* terminate the list just before the subtree to remove */
  if (start->prev) {  /* unless the starting node is the first */
    list->last = start->prev;
    list->last->next = 0L;
  }

  /* free subtree */
  while(start) {
    prev = start;
    start = start->next;
    free(prev);
    ret++;
  }
  return ret;
}

struct string_list *string_list_new(void) {
  struct string_list *ret = 0L;
  ret = (struct string_list *) malloc(sizeof(struct string_list));
  memset(ret, 0, sizeof(struct string_list));
  return ret;
}

struct string_node *string_node_new(void) {
  struct string_node *ret = 0L;
  ret = (struct string_node *) malloc(sizeof(struct string_node));
  memset(ret, 0, sizeof(struct string_node));
  return ret;
}

void string_list_append(struct string_list *list, struct string_node *node) {
  if (!list->first) {
    list->first = list->last = node;
  } else {
    list->last->next = node;
    node->prev = list->last;
    list->last = node;
  }
}