source: list.c @ 5550eb0

debianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 5550eb0 was f34dd65, checked in by Nelson Elhage <nelhage@mit.edu>, 15 years ago
Kill a whole bunch of unused code. I generated a list of dead functions by building with -ffunction-sections and linking with -Wl,--gc-sections -Wl,--print-gc-sections I kept a number of functions that seemed to be logical parts of an existing API, as well as stuff in varstubs.c, since that file is autogenerated.
  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include "owl.h"
2#include <stdlib.h>
3
4static const char fileIdent[] = "$Id$";
5
6#define INITSIZE 10
7#define GROWBY 1.5
8
9int owl_list_create(owl_list *l)
10{
11  l->size=0;
12  l->list=(void **)owl_malloc(INITSIZE*sizeof(void *));
13  l->avail=INITSIZE;
14  if (l->list==NULL) return(-1);
15  return(0);
16}
17
18int owl_list_get_size(owl_list *l)
19{
20  return(l->size);
21}
22
23
24void owl_list_grow(owl_list *l, int n) /*noproto*/
25{
26  void *ptr;
27
28  if ((l->size+n) > l->avail) {
29    ptr=owl_realloc(l->list, l->avail*GROWBY*sizeof(void *));
30    if (ptr==NULL) abort();
31    l->list=ptr;
32    l->avail=l->avail*GROWBY;
33  }
34
35}
36
37void *owl_list_get_element(owl_list *l, int n)
38{
39  if (n>l->size-1) return(NULL);
40  return(l->list[n]);
41}
42
43int owl_list_insert_element(owl_list *l, int at, void *element)
44{
45  int i;
46  if(at < 0 || at > l->size) return -1;
47  owl_list_grow(l, 1);
48
49  for (i=l->size; i>at; i--) {
50    l->list[i]=l->list[i-1];
51  }
52
53  l->list[at] = element;
54  l->size++;
55  return(0);
56}
57
58int owl_list_append_element(owl_list *l, void *element)
59{
60  return owl_list_insert_element(l, l->size, element);
61}
62
63int owl_list_prepend_element(owl_list *l, void *element)
64{
65  return owl_list_insert_element(l, 0, element);
66}
67
68int owl_list_remove_element(owl_list *l, int n)
69{
70  int i;
71
72  if (n>l->size-1) return(-1);
73  for (i=n; i<l->size-1; i++) {
74    l->list[i]=l->list[i+1];
75  }
76  l->size--;
77  return(0);
78}
79
80void owl_list_free_all(owl_list *l, void (*elefree)(void *))
81{
82  int i;
83
84  for (i=0; i<l->size; i++) {
85    (elefree)(l->list[i]);
86  }
87  owl_free(l->list);
88}
89
90void owl_list_free_simple(owl_list *l)
91{
92  if (l->list) owl_free(l->list);
93}
Note: See TracBrowser for help on using the repository browser.