File: list.c

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (139 lines) | stat: -rw-r--r-- 2,037 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* Copyright INRIA */
#include <string.h>
#include <malloc.h>

#include "list.h"
#include "graph.h"
#include "metio.h"

typedef int (*PF)();

list *ListAlloc()
{
  list *l;
  if ((l = (list*)malloc((unsigned)sizeof(list))) == NULL) {
    fprintf(stderr,"Running out of memory\n");
    return 0;
  }
  l->first = 0;
  return l;
}

mylink *MylinkAlloc(e,n)
ptr e;
mylink *n;
{
  mylink *p;
  
  if ((p = (mylink*)malloc(sizeof(mylink))) == NULL) {
    fprintf(stderr,"Running out of memory\n");
    return 0;
  }
  p->element = e;
  p->next = n;
  return p;
}

void AddListElement(e,l)
ptr e;
list *l;
{
  if (l->first == 0)
    l->first = MylinkAlloc(e,(mylink*)0);
  else
    l->first = MylinkAlloc(e,l->first);
}

void RemoveListElement(e,l)
ptr e;
list *l;
{
  mylink *pn, *p;

  if (l->first == 0) return;
  pn = l->first->next;
  if (l->first->element == e) {
    l->first = pn;
  }
  else {
    p = l->first;
    while (pn) {
      if(pn->element == e) {
	p->next = pn->next;
	free((char*)pn);
	break;
      }
      p = pn;
      pn = pn->next;
    }
  }
}

int FindInLarray(s,lar)
char *s;
char *lar[];
{
 int n = 0;

 while (lar[n] != 0) {
   if (strcmp(lar[n++],s) == 0) return n;
 }

 return 0;
}

int CompString(s1, s2)
char **s1, **s2;
{
  return strcmp((char*)*s1,(char*)*s2);
}

void SortLarray(lar)
char *lar[];
{
  int n = 0;

  while (lar[n++] != 0) {}

  qsort((char*)lar,n - 1,sizeof(char*),(PF)CompString);
}

void PrintArcList(l,level)
list *l;
int level;
{
  mylink *p;

  if (!l->first) {
    sprintf(Description,"nil\n");
    AddText(Description);
    return;
  }
  p = l->first;
  while (p) {
    PrintArc((arc*)p->element,level);
    p = p->next;
  }
  sprintf(Description,"\n");
  AddText(Description);
}

void PrintNodeList(l,level)
list *l;
int level;
{
  mylink *p;

  if (!l->first) {
    sprintf(Description,"nil\n");
    AddText(Description);
    return;
  }
  p = l->first;
  while (p) {
    PrintNode((node*)p->element,level);
    p = p->next;
  }
  sprintf(Description,"\n");
  AddText(Description);
}