Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LSH
lsh
Commits
6cb09fac
Commit
6cb09fac
authored
Sep 27, 2001
by
Niels Möller
Browse files
Use const struct sexp * in more places.
Rev: src/sexp.c:1.41 Rev: src/sexp.h:1.35
parent
778899dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/sexp.c
View file @
6cb09fac
...
...
@@ -177,7 +177,7 @@ do_format_sexp_string(struct sexp *s,
/* Consumes its args (display may be NULL) */
struct
sexp
*
sexp_s
(
struct
lsh_string
*
d
,
struct
lsh_string
*
c
)
sexp_s
(
const
struct
lsh_string
*
d
,
const
struct
lsh_string
*
c
)
{
NEW
(
sexp_string
,
s
);
assert
(
c
);
...
...
@@ -270,24 +270,11 @@ sexp_check_type_l(struct sexp *e, UINT32 length,
return
NULL
;
}
/* Returns 1 if the type matches.
*
* FIXME: Do we relly need this interface, that allows res == NULL? */
int
sexp_check_type
(
struct
sexp
*
e
,
int
type
,
struct
sexp_iterator
**
res
)
/* Returns i if the type matches, or NULL if it doesn't. */
struct
sexp_iterator
*
sexp_check_type
(
struct
sexp
*
e
,
int
type
)
{
struct
sexp_iterator
*
i
=
sexp_check_type_l
(
e
,
get_atom_length
(
type
),
get_atom_name
(
type
));
if
(
i
)
{
if
(
res
)
*
res
=
i
;
else
KILL
(
i
);
return
1
;
}
return
0
;
return
sexp_check_type_l
(
e
,
get_atom_length
(
type
),
get_atom_name
(
type
));
}
static
int
...
...
@@ -715,7 +702,7 @@ sexp_atomp(const struct sexp *e)
/* Checks that the sexp is a simple string (i.e. no display part) */
const
struct
lsh_string
*
sexp2string
(
struct
sexp
*
e
)
sexp2string
(
const
struct
sexp
*
e
)
{
return
(
(
e
&&
sexp_atomp
(
e
)
&&
!
sexp_display
(
e
))
?
sexp_contents
(
e
)
:
NULL
);
...
...
@@ -723,7 +710,7 @@ sexp2string(struct sexp *e)
int
sexp2atom
(
struct
sexp
*
e
)
sexp2atom
(
const
struct
sexp
*
e
)
{
const
struct
lsh_string
*
s
=
sexp2string
(
e
);
return
s
?
lookup_atom
(
s
->
length
,
s
->
data
)
:
0
;
...
...
@@ -731,7 +718,7 @@ sexp2atom(struct sexp *e)
/* If limit is nonzero, at most that number of octets are allowed. */
int
sexp2bignum_u
(
struct
sexp
*
e
,
mpz_t
n
,
UINT32
limit
)
sexp2bignum_u
(
const
struct
sexp
*
e
,
mpz_t
n
,
UINT32
limit
)
{
const
struct
lsh_string
*
s
=
sexp2string
(
e
);
...
...
@@ -748,7 +735,7 @@ sexp2bignum_u(struct sexp *e, mpz_t n, UINT32 limit)
}
int
sexp2uint32
(
struct
sexp
*
e
,
UINT32
*
n
)
sexp2uint32
(
const
struct
sexp
*
e
,
UINT32
*
n
)
{
const
struct
lsh_string
*
digits
=
sexp2string
(
e
);
...
...
@@ -789,7 +776,7 @@ sexp2uint32(struct sexp *e, UINT32 *n)
}
int
sexp_eq
(
struct
sexp
*
e
,
UINT32
length
,
const
UINT8
*
name
)
sexp_eq
(
const
struct
sexp
*
e
,
UINT32
length
,
const
UINT8
*
name
)
{
const
struct
lsh_string
*
c
=
sexp2string
(
e
);
...
...
@@ -801,14 +788,14 @@ sexp_eq(struct sexp *e, UINT32 length, const UINT8 *name)
*
* This naming seems a little confusing. */
int
sexp_atom_eq
(
struct
sexp
*
e
,
int
atom
)
sexp_atom_eq
(
const
struct
sexp
*
e
,
int
atom
)
{
return
sexp_eq
(
e
,
get_atom_length
(
atom
),
get_atom_name
(
atom
));
}
/* Assumes that both expressions are atoms */
int
sexp_atoms_eq
(
struct
sexp
*
a
,
struct
sexp
*
b
)
sexp_atoms_eq
(
const
struct
sexp
*
a
,
const
struct
sexp
*
b
)
{
const
struct
lsh_string
*
ac
=
sexp_contents
(
a
);
const
struct
lsh_string
*
ad
=
sexp_display
(
a
);
...
...
src/sexp.h
View file @
6cb09fac
...
...
@@ -39,9 +39,6 @@
#include "sexp.h.x"
#undef GABA_DECLARE
/* FIXME: Do some constification. Strings inside sexpressions should
* always be const. */
/* GABA:
(class
(name sexp)
...
...
@@ -94,46 +91,61 @@ encode_base64(const struct lsh_string *s,
/* Creating sexps */
/* Consumes its args (display may be NULL) */
struct
sexp
*
sexp_s
(
struct
lsh_string
*
d
,
struct
lsh_string
*
c
);
struct
sexp
*
sexp_s
(
const
struct
lsh_string
*
d
,
const
struct
lsh_string
*
c
);
/* atom->sexp */
struct
sexp
*
sexp_a
(
const
int
a
);
struct
sexp
*
sexp_a
(
const
int
a
);
/* cstring->sexp */
struct
sexp
*
sexp_z
(
const
char
*
s
);
struct
sexp
*
sexp_z
(
const
char
*
s
);
/* mpz->sexp */
struct
sexp
*
sexp_un
(
const
mpz_t
n
);
struct
sexp
*
sexp_sn
(
const
mpz_t
n
);
struct
sexp
*
sexp_un
(
const
mpz_t
n
);
struct
sexp
*
sexp_sn
(
const
mpz_t
n
);
/* Small unsigned int -> sexp */
struct
sexp
*
sexp_uint32
(
UINT32
n
);
struct
sexp
*
sexp_uint32
(
UINT32
n
);
/* list */
struct
sexp
*
sexp_l
(
unsigned
n
,
...);
struct
sexp
*
sexp_l
(
unsigned
n
,
...);
/* vector */
struct
sexp
*
sexp_v
(
struct
object_list
*
l
);
struct
sexp
*
sexp_v
(
struct
object_list
*
l
);
int
sexp_nullp
(
const
struct
sexp
*
e
);
int
sexp_atomp
(
const
struct
sexp
*
e
);
/* Checks that the sexp is a simple string (i.e. no display part).
* e == NULL is allowed. */
const
struct
lsh_string
*
sexp2string
(
struct
sexp
*
e
);
const
struct
lsh_string
*
sexp2string
(
const
struct
sexp
*
e
);
/* Returns an ATOM_FOO constant if e is a simple sexp string
* corresponding to an atom. Or zero if that is not the case. */
int
sexp2atom
(
struct
sexp
*
e
);
int
sexp2atom
(
const
struct
sexp
*
e
);
int
sexp2bignum_u
(
struct
sexp
*
e
,
mpz_t
n
,
UINT32
limit
);
sexp2bignum_u
(
const
struct
sexp
*
e
,
mpz_t
n
,
UINT32
limit
);
int
sexp2uint32
(
struct
sexp
*
e
,
UINT32
*
n
);
sexp2uint32
(
const
struct
sexp
*
e
,
UINT32
*
n
);
const
struct
lsh_string
*
sexp_contents
(
const
struct
sexp
*
e
);
const
struct
lsh_string
*
sexp_display
(
const
struct
sexp
*
e
);
const
struct
lsh_string
*
sexp_contents
(
const
struct
sexp
*
e
);
const
struct
lsh_string
*
sexp_display
(
const
struct
sexp
*
e
);
int
sexp_atom
(
const
struct
sexp
*
e
);
int
sexp_bignum_u
(
const
struct
sexp
*
e
,
mpz_t
n
);
int
sexp_bignum_s
(
const
struct
sexp
*
e
,
mpz_t
n
);
...
...
@@ -141,13 +153,13 @@ int sexp_bignum_s(const struct sexp *e, mpz_t n);
/* Utility functions for parsing spki objects. */
int
sexp_eq
(
struct
sexp
*
e
,
UINT32
length
,
const
UINT8
*
name
);
sexp_eq
(
const
struct
sexp
*
e
,
UINT32
length
,
const
UINT8
*
name
);
int
sexp_atom_eq
(
struct
sexp
*
e
,
int
atom
);
sexp_atom_eq
(
const
struct
sexp
*
e
,
int
atom
);
int
sexp_atoms_eq
(
struct
sexp
*
a
,
struct
sexp
*
b
);
sexp_atoms_eq
(
const
struct
sexp
*
a
,
const
struct
sexp
*
b
);
struct
sexp
*
sexp_assq
(
struct
sexp_iterator
*
i
,
int
atom
);
...
...
@@ -156,8 +168,8 @@ struct sexp_iterator *
sexp_check_type_l
(
struct
sexp
*
e
,
UINT32
length
,
const
UINT8
*
name
);
int
sexp_check_type
(
struct
sexp
*
e
,
int
type
,
struct
sexp_iterator
**
res
);
struct
sexp_iterator
*
sexp_check_type
(
struct
sexp
*
e
,
int
type
);
int
sexp_get_un
(
struct
sexp_iterator
*
i
,
int
atom
,
mpz_t
n
,
UINT32
limit
);
...
...
@@ -180,15 +192,6 @@ struct sexp *
string_to_sexp
(
int
style
,
const
struct
lsh_string
*
src
,
int
free
);
#if 0
/* Streamed parser */
struct read_handler *
make_read_sexp(int style, int goon,
struct command_continuation *c,
struct exception_handler *e);
#endif
extern
const
struct
argp
sexp_input_argp
;
extern
const
struct
argp
sexp_output_argp
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment