File: list.c

package info (click to toggle)
jove 4.16.0.73-5
  • links: PTS
  • area: main
  • in suites: buster
  • size: 2,024 kB
  • sloc: ansic: 27,589; makefile: 454; sh: 49
file content (51 lines) | stat: -rw-r--r-- 1,034 bytes parent folder | download | duplicates (12)
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
/**************************************************************************
 * This program is Copyright (C) 1986-2002 by Jonathan Payne.  JOVE is    *
 * provided by Jonathan and Jovehacks without charge and without          *
 * warranty.  You may copy, modify, and/or distribute JOVE, provided that *
 * this notice is included in all the source files and documentation.     *
 **************************************************************************/

#include "jove.h"
#include "list.h"

private List *
list_new()
{
	List	*new;

	new = (List *) emalloc(sizeof (List));
	new->car = NULL;
	return new;
}

/* push an object to the beginning of list */

UnivPtr
list_push(list, element)
register List	**list;
UnivPtr element;
{
	List	*new;

	new = list_new();
	new->cdr = *list;
	new->car = element;
	*list = new;
	return element;
}

UnivPtr
list_pop(list)
List	**list;
{
	List	*cell = *list;
	UnivPtr	element;

	if (cell == NULL)
		return NULL;

	element = cell->car;
	*list = cell->cdr;
	free((UnivPtr) cell);
	return element;
}