~ubuntu-branches/ubuntu/breezy/tiemu/breezy

« back to all changes in this revision

Viewing changes to src/core/intlist.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2005-06-02 16:50:15 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050602165015-59ab24414tl2wzol
Tags: 1.99+svn1460-1
* New snapshot.
* debian/control:
  + Updated build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  gtktiemu - a TI89/92/92+ emulator
2
 
 *  (c) Copyright 2000-2001, Romain Lievin and Thomas Corvazier
3
 
 *
4
 
 *  This program is free software; you can redistribute it and/or modify
5
 
 *  it under the terms of the GNU General Public License as published by
6
 
 *  the Free Software Foundation; either version 2 of the License, or
7
 
 *  (at your option) any later version.
8
 
 *
9
 
 *  This program is distributed in the hope that it will be useful,
10
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 *  GNU General Public License for more details.
13
 
 *
14
 
 *  You should have received a copy of the GNU General Public License
15
 
 *  along with this program; if not, write to the Free Software
16
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 
 */
18
 
 
19
 
/*
20
 
  Specific linked lists: should be replaced with glib
21
 
*/
22
 
 
23
 
#include <stdlib.h>
24
 
 
25
 
#include "intlist.h"
26
 
 
27
 
int getSize(struct intlist* list) 
28
 
{
29
 
  if (!list) 
30
 
    return 0;
31
 
  else 
32
 
    return (getSize(list->next)+1);
33
 
}
34
 
 
35
 
void addEnd(struct intlist** list,int val) 
36
 
{
37
 
  struct intlist *l;
38
 
 
39
 
  if (!(*list)) 
40
 
    addAt(list,0,val);
41
 
  else 
42
 
    {
43
 
      if ((*list)->next) addEnd(&(*list)->next,val);
44
 
      else 
45
 
        {
46
 
          l=(struct intlist*)malloc(sizeof(struct intlist));
47
 
          (*list)->next = l;
48
 
          l->next = 0;
49
 
          l->val = val;
50
 
        }
51
 
    }
52
 
}
53
 
 
54
 
void add2End(struct intlist** list,int val,int val2) 
55
 
{
56
 
  struct intlist *l;
57
 
 
58
 
  if (!(*list)) 
59
 
    addAt(list,0,val);
60
 
  else 
61
 
    {
62
 
      if ((*list)->next) add2End(&(*list)->next,val,val2);
63
 
      else 
64
 
        {
65
 
          l=(struct intlist*)malloc(sizeof(struct intlist));
66
 
          (*list)->next = l;
67
 
          l->next = 0;
68
 
          l->val = val;
69
 
          l->val2 = val2;
70
 
        }
71
 
    }
72
 
}
73
 
 
74
 
void addAt(struct intlist** list,int i,int val) 
75
 
{
76
 
  struct intlist* l;
77
 
  if (!*list) 
78
 
    {
79
 
      *list=(struct intlist*)malloc(sizeof(struct intlist));
80
 
      (*list)->next=0;
81
 
      (*list)->val=val;
82
 
      return;
83
 
    }
84
 
  if (i>0) 
85
 
    addAt(&(*list)->next,i-1,val);
86
 
  else 
87
 
    {
88
 
      l=(struct intlist*)malloc(sizeof(struct intlist));
89
 
      l->val = val;
90
 
      l->next = *list;
91
 
      *list = l;
92
 
    }
93
 
}
94
 
 
95
 
void add2At(struct intlist** list,int i,int val,int val2) 
96
 
{
97
 
  struct intlist* l;
98
 
  if (!*list) 
99
 
    {
100
 
      *list=(struct intlist*)malloc(sizeof(struct intlist));
101
 
      (*list)->next=0;
102
 
      (*list)->val=val;
103
 
      (*list)->val2=val2;
104
 
      return;
105
 
    }
106
 
  if (i>0) 
107
 
    add2At(&(*list)->next,i-1,val,val2);
108
 
  else 
109
 
    {
110
 
      l=(struct intlist*)malloc(sizeof(struct intlist));
111
 
      l->val = val;
112
 
      l->val2 = val2;
113
 
      l->next = *list;
114
 
      *list = l;
115
 
    }
116
 
}
117
 
 
118
 
void delList(struct intlist** list) 
119
 
{
120
 
  if (!list) return;
121
 
  delList(&(*list)->next);
122
 
  free(list);
123
 
  *list=0;
124
 
}
125
 
        
126
 
void delAt(struct intlist** list,int i) 
127
 
{
128
 
  if (!*list) return;
129
 
  if (i>0) 
130
 
    delAt(&(*list)->next,i-1);
131
 
  else 
132
 
    {
133
 
      struct intlist* temp = (*list)->next;
134
 
      free(*list);
135
 
      *list = temp;
136
 
    }
137
 
}
138
 
 
139
 
void delEnd(struct intlist** list) 
140
 
{
141
 
  if (!*list) return;
142
 
  if ((*list)->next) 
143
 
    delEnd(&(*list)->next);
144
 
  else 
145
 
    {
146
 
      free(*list);
147
 
      *list=0;
148
 
    }
149
 
}