list.c 1.93 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* list.h
 *
 * Variable length lists of atoms (or other integers).
 *
 * $Id$ */

/* lsh, an implementation of the ssh protocol
 *
 * Copyright (C) 1998 Niels Mller
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
J.H.M. Dassen's avatar
J.H.M. Dassen committed
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
25
26
27
 */

#include "list.h"

28
29
30
#include <assert.h>
#include <stdarg.h>

31
#define GABA_DEFINE
32
#include "list.h.x"
33
#undef GABA_DEFINE
34
35
36

#include "xalloc.h"

37
struct int_list *make_int_listv(unsigned n, va_list args)
38
{
39
  unsigned i;
40
  
41
  struct int_list *l = alloc_int_list(n);
42
43
44
45
46
47
48
49
50
51
52
53

  for (i=0; i<n; i++)
    {
      int atom = va_arg(args, int);
      assert(atom >= 0);
      LIST(l)[i] = atom;
    }

  assert(va_arg(args, int) == -1);

  return l;
}
54

55
struct int_list *make_int_list(unsigned n, ...)
56
57
{
  va_list args;
58
  struct int_list *l;
59
60
  
  va_start(args, n);
61
62
63
64
65
66
67
68
69
  l = make_int_listv(n, args);
  va_end(args);

  return l;
}

struct object_list *make_object_listv(unsigned n, va_list args)
{
  unsigned i;
70
  
71
72
  struct object_list *l = alloc_object_list(n);

Niels Möller's avatar
Niels Möller committed
73
  /* FIXME: Add sanity type checking */
74
75
76
77
78
79
80
81
  for (i=0; i<n; i++)
    LIST(l)[i] = va_arg(args, struct lsh_object *);

  assert(va_arg(args, int) == -1);

  return l;
}

82
83
84
85
86
87
88
89
90
91
92
93
94

struct object_list *make_object_list(unsigned n, ...)
{
  va_list args;
  struct object_list *l;

  va_start(args, n);
  l = make_object_listv(n, args);
  va_end(args);

  return l;
}