/+junk/c_sdl_joypad

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad
21 by Gustav Hatvigsson
* added Modeline to (almost) all files.
1
/* c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil
2
 * vi: set shiftwidth=2 tabstop=2 expandtab:
3
 * :indentSize=2:tabSize=2:noTabs=true:
4
 */
5
6
#incluede "LinkedList.h"
7
8
9
LinkedList * linked_list_new (void (* free_func)(void *)) {
10
  LinkedList * self = malloc (sizeof (LinkedList));
11
  self->len = 0;
12
  self->free_func = free_func;
13
  self->dead = self->tail = self->current = null;
14
  return self;
15
}
16
17
18
void linked_list_free (LinkedList * self, bool free_data) {
19
  
20
}
21
22
23
void linked_list_add (LinkedList * self, void * data) {
24
  if (self->len  == 0) { // special case when the list is empty.
25
    self->head = self->tail = self->current = malloc (sizeof (LinkedListNode));
26
    self->tail->prev = NULL;
27
    self->head->next = NULL
28
    self->current->data = data;
29
  } else { // general case.
30
    self->tail->next = malloc (sizeof (LinkedListNode));
31
    self->tail->next->next = NULL;
32
  }
33
}
34
35
void linked_list_next (LinkedList * self) {
36
  if (this->current->next) {
37
    this->current = this->current->next;
38
  } else {
39
    fprintf (stderr, "Reached end of list %lld\n", (long long int) self);
40
    assert (this->current == this->tail);
41
  }
42
}
43
44
45
void linked_list_pev (LinkedList * self) {
46
  if (self->current->prev) {
47
    this->current = this->current->prev;
48
  } else {
49
    fprintf (stderr, "Reached begining of list %lld\n", (long long int) self);
50
    assert (this->current == this->head);
51
  }
52
}
53
54
55
void * linked_list_get_current (LinkedList * self) {
56
  return self->current->data;
57
}
58
59
60
void * linked_list_get_next (LinkedList * self) {
61
  if (self->current->next) {
62
    return self->current->next;
63
  } else {
64
    fprintf (stderr, "No \"next\" item exists in list %lld\n", (long long int)
65
                                                                self);
66
    assert (self->current == self->tail);
67
    return NULL;
68
  }
69
}
70
71
72
void * linked_list_get_prev (LinkedList * self) {
73
    if (self->current->prev) {
74
    return self->current->next;
75
  } else {
76
    fprintf (stderr, "No \"previous\" item exists in list %lld\n",
77
            (long long int) self);
78
    assert (self->current == self->head);
79
    return NULL;
80
  }
81
}
82
83
84
void linked_list_head (LinkedList * self) {
85
  self->current = self->head;
86
}
87
88
89
void linked_list_tail (LinkedList * self) {
90
  self->current = self->tail;
91
}
92
93
94
size_t linked_list_len (LinkedList * self)  {
95
  return self->len;
96
}
97
98
void linked_list_remove_current (LinkedList * self) {
99
  // TODO
100
}
101
102