forked from Radmind/radmind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllist.c
81 lines (66 loc) · 1.61 KB
/
llist.c
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
/*
* Copyright (c) 2003 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
*/
#include "config.h"
#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "applefile.h"
#include "transcript.h"
#include "llist.h"
/* Allocate a new list node */
struct llist *
ll_allocate( char *name )
{
struct llist *new;
/* allocate space for next item in list */
if (( new = (struct llist *)malloc( sizeof( struct llist ))) == NULL ) {
perror( "malloc" );
exit( 2 );
}
/* copy info into new item */
strcpy( new->ll_name, name );
new->ll_next = NULL;
return new;
}
/* Free the whole list */
void
ll_free( struct llist *head )
{
struct llist *next;
for ( ; head != NULL; head = next ) {
next = head->ll_next;
free( head );
}
}
void
ll_insert( struct llist **headp, struct llist *new )
{
struct llist **current;
/* find where in the list to put the new entry */
for ( current = headp; *current != NULL; current = &(*current)->ll_next) {
if ( strcmp( new->ll_name, (*current)->ll_name ) <= 0 ) {
break;
}
}
new->ll_next = *current;
*current = new;
return;
}
/* Insert a new node into the list */
void
ll_insert_case( struct llist **headp, struct llist *new )
{
struct llist **current;
/* find where in the list to put the new entry */
for ( current = headp; *current != NULL; current = &(*current)->ll_next) {
if ( strcasecmp( new->ll_name, (*current)->ll_name ) <= 0 ) {
break;
}
}
new->ll_next = *current;
*current = new;
return;
}