4 * hed - Hexadecimal editor
5 * Copyright (C) 2004 Petr Baudis <pasky@ucw.cz>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * 'You see: Mr. Drogo, he married poor Miss Primula Brandybuck. She was our
23 * Mr. Bilbo's first cousin on the mother's side (her mother being the youngest
24 * of the Old Took's daughters); and Mr. Drogo was his second cousin. So Mr.
25 * Frodo is his first _and_ second cousin, once removed either way, as the
26 * saying is, if you follow me.
38 #include <util/numbers.h>
39 #include <util/lists.h>
43 /* This is really just trivial implementation. */
45 #define SIZE_AUTO ((size_t)-1L)
48 struct list_head list
;
50 size_t len
; // SIZE_AUTO == auto (defaults to 1 at root)
62 /* atom_evaluator returns a flag bitmask, see the HED_AEF_xxx constants */
63 typedef long (*atom_evaluator
)(struct hed_expr
*expr
, struct atom
*atom
,
64 unsigned char *scramble
, size_t len
);
65 static long atom_un(struct hed_expr
*expr
, struct atom
*atom
,
66 unsigned char *scramble
, size_t len
);
67 static long atom_bin(struct hed_expr
*expr
, struct atom
*atom
,
68 unsigned char *scramble
, size_t len
);
69 static long atom_bytestr(struct hed_expr
*expr
, struct atom
*atom
,
70 unsigned char *scramble
, size_t len
);
71 static long atom_register(struct hed_expr
*expr
, struct atom
*atom
,
72 unsigned char *scramble
, size_t len
);
73 static long atom_mark(struct hed_expr
*expr
, struct atom
*atom
,
74 unsigned char *scramble
, size_t len
);
75 static atom_evaluator evals
[ATOM_T_MAX
] = {
76 atom_un
, atom_bin
, atom_bytestr
, atom_register
, atom_mark
79 typedef void (*atom_free
)(void *atom
);
80 static void free_un(void *p
);
81 static void free_bin(void *p
);
82 static void free_register(void *p
);
83 static atom_free frees
[ATOM_T_MAX
] = {
84 free_un
, free_bin
, free
, free_register
, free
87 static void expr_cleanup(struct hed_expr
*expr
);
116 struct atom_bytestr
{
118 size_t len
; /* Length of @bytes */
119 unsigned char bytes
[0]; /* [len] */
122 struct atom_register
{
125 struct hed_expr offset
;
134 free_atom(struct atom
*atom
)
136 frees
[atom
->type
](atom
);
143 static const char hx
[] = "0123456789abcdef89ABCDEF";
144 unsigned idx
= strchr(hx
, x
) - hx
;
145 return (idx
& 0x0f) | ((idx
& 0x10) >> 1);
149 skip_white(char **sexpr
)
151 while (isspace(**sexpr
))
155 static struct atom
*atom_parse(char **sexpr
);
156 static struct hed_expr
*compile_till(struct hed_expr
*expr
,
157 char **sexpr
, char till
);
159 #if __BYTE_ORDER == __LITTLE_ENDIAN
160 # define BYTESTR_LSB(s, len) (s)
161 # define BYTESTR_STEP (+1)
162 # define BYTESTR_MSB(s, len) ((s) + (len) - 1)
163 # define BYTESTR_LOPART(s, len, plen) (s)
164 # define BYTESTR_HIPART(s, len, plen) ((s) + (len) - (plen))
165 # define HED_AEF_NATIVEORDER HED_AEF_FORCELE
166 #elif __BYTE_ORDER == __BIG_ENDIAN
167 # define BYTESTR_LSB(s, len) ((s) + (len) - 1)
168 # define BYTESTR_STEP (-1)
169 # define BYTESTR_MSB(s, len) (s)
170 # define BYTESTR_LOPART(s, len, plen) ((s) + (len) - (plen))
171 # define BYTESTR_HIPART(s, len, plen) (s)
172 # define HED_AEF_NATIVEORDER HED_AEF_FORCEBE
174 # error "Unsupported byte order"
178 hed_bytestr2off(unsigned char *bytestr
, size_t len
, long flags
)
180 unsigned char *p
, *q
;
182 register hed_off_t ret
;
184 if ((flags
& HED_AEF_ENDIANMASK
) == HED_AEF_KEEPENDIAN
||
185 (flags
& HED_AEF_ENDIANMASK
) == HED_AEF_NATIVEORDER
) {
186 p
= BYTESTR_MSB(bytestr
, len
);
187 q
= BYTESTR_LSB(bytestr
, len
);
188 step
= -BYTESTR_STEP
;
190 p
= BYTESTR_LSB(bytestr
, len
);
191 q
= BYTESTR_MSB(bytestr
, len
);
195 if (flags
& HED_AEF_SIGNED
&& (signed char)*p
< 0)
196 flags
|= HED_AEF_NEGATIVE
;
197 ret
= flags
& HED_AEF_NEGATIVE
? -1 : 0;
208 /* The following function always uses the native byte order.
209 * FIXME? Should the API be more analogous to hed_bytestr2off?
212 hed_off2bytestr(unsigned char *bytestr
, size_t len
, hed_off_t num
)
214 unsigned char *p
= BYTESTR_LSB(bytestr
, len
);
215 unsigned char *q
= BYTESTR_MSB(bytestr
, len
) + BYTESTR_STEP
;
223 /* bytestr arithmetics */
225 bytestr_not(unsigned char *s
, size_t len
)
234 bytestr_and(unsigned char *s1
, unsigned char *s2
, size_t len
)
241 bytestr_or(unsigned char *s1
, unsigned char *s2
, size_t len
)
248 bytestr_xor(unsigned char *s1
, unsigned char *s2
, size_t len
)
254 /* Get the maximum length of the shift bytestr and check that the
255 * actual value in @s fits into that size. If @s is larger than
256 * the maximum shift for @len-sized numbers, return 0. This would
257 * be otherwise an invalid value, because even a zero-sized bytestr
261 max_shiftlen(unsigned char *s
, size_t len
)
263 size_t maxshiftoff
= ((bitsize(len
) + 3) - 1) >> 3;
264 unsigned char *p
= BYTESTR_LSB(s
, len
) + maxshiftoff
* BYTESTR_STEP
;
265 while (p
!= BYTESTR_MSB(s
, len
)) {
270 return maxshiftoff
+ 1;
273 /* Get the shift size in bytes. */
275 shift_bytecount(unsigned char *s
, size_t len
, size_t shiftlen
)
279 s
= BYTESTR_LSB(s
, len
) + shiftlen
* BYTESTR_STEP
;
282 ret
= (ret
<< 8) | carry
| (*s
>> 3);
283 carry
= (*s
& 7) << 5;
289 bytestr_shl(unsigned char *s1
, unsigned char *s2
, size_t len
)
291 size_t shiftlen
, byteoff
, bitshift
;
293 shiftlen
= max_shiftlen(s2
, len
);
294 byteoff
= shiftlen
? shift_bytecount(s2
, len
, shiftlen
) : len
;
298 bitshift
= *BYTESTR_LSB(s2
, len
) & 7;
299 for (p
= BYTESTR_MSB(s1
, len
) - byteoff
* BYTESTR_STEP
;
300 p
!= BYTESTR_LSB(s1
, len
);
302 p
[byteoff
* BYTESTR_STEP
] =
304 p
[-BYTESTR_STEP
] >> (8 - bitshift
);
305 p
[byteoff
* BYTESTR_STEP
] = *p
<< bitshift
;
308 memset(BYTESTR_LOPART(s1
, len
, byteoff
), 0, byteoff
);
312 bytestr_shr(unsigned char *s1
, unsigned char *s2
, size_t len
)
314 size_t shiftlen
, byteoff
, bitshift
;
316 shiftlen
= max_shiftlen(s2
, len
);
317 byteoff
= shiftlen
? shift_bytecount(s2
, len
, shiftlen
) : len
;
321 bitshift
= *BYTESTR_LSB(s2
, len
) & 7;
322 for (p
= BYTESTR_LSB(s1
, len
) + byteoff
* BYTESTR_STEP
;
323 p
!= BYTESTR_MSB(s1
, len
);
325 p
[-byteoff
* BYTESTR_STEP
] =
327 p
[BYTESTR_STEP
] << (8 - bitshift
);
328 p
[-byteoff
* BYTESTR_STEP
] = *p
>> bitshift
;
331 memset(BYTESTR_HIPART(s1
, len
, byteoff
), 0, byteoff
);
335 bytestr_inc(unsigned char *s
, size_t len
)
338 s
= BYTESTR_LSB(s
, len
);
342 } while (carry
&& --len
);
347 bytestr_add(unsigned char *s1
, unsigned char *s2
, size_t len
)
350 s1
= BYTESTR_LSB(s1
, len
);
351 s2
= BYTESTR_LSB(s2
, len
);
363 bytestr_sub(unsigned char *s1
, unsigned char *s2
, size_t len
)
366 s1
= BYTESTR_LSB(s1
, len
);
367 s2
= BYTESTR_LSB(s2
, len
);
378 /* multiply @src by @mul and add it to @dst */
380 muladd(unsigned char *dst
, unsigned char *src
, size_t len
, unsigned char mul
)
383 unsigned char *p
= BYTESTR_LSB(src
, len
);
384 unsigned char *q
= BYTESTR_LSB(dst
, len
);
385 while (p
!= BYTESTR_MSB(src
, len
) + BYTESTR_STEP
) {
386 carry
+= *p
* mul
+ *q
;
396 bytestr_mul(unsigned char *s1
, unsigned char *s2
, size_t len
)
398 unsigned char ret
[len
];
402 for (mlen
= len
; mlen
; --mlen
)
403 muladd(BYTESTR_HIPART(ret
, len
, mlen
),
404 BYTESTR_LOPART(s1
, len
, mlen
), mlen
,
405 BYTESTR_MSB(s2
, len
)[(1-mlen
) * BYTESTR_STEP
]);
406 memcpy(s1
, ret
, len
);
410 shl_one(unsigned char *s
, size_t len
, unsigned carry
)
412 unsigned char *p
= BYTESTR_LSB(s
, len
);
413 while (p
!= BYTESTR_MSB(s
, len
) + BYTESTR_STEP
) {
422 /* Simple non-restoring algorithm for now.
423 * Feel free to improve.
426 bytestr_div(unsigned char *s1
, unsigned char *s2
, size_t len
,
429 unsigned char *p
, mask
;
432 p
= BYTESTR_MSB(s1
, len
);
434 while (p
!= BYTESTR_LSB(s1
, len
) - BYTESTR_STEP
) {
435 if (shl_one(mod
, len
, !!(*p
& mask
)))
436 bytestr_add(mod
, s2
, len
);
438 bytestr_sub(mod
, s2
, len
);
440 if (*BYTESTR_MSB(mod
, len
) & 0x80)
445 if (! (mask
>>= 1) ) {
450 if (*BYTESTR_MSB(mod
, len
) & 0x80)
451 bytestr_add(mod
, s2
, len
);
454 /* Remove any MSB zeroes from @s and update *@plen. */
455 static unsigned char*
456 bytestr_shrink(unsigned char *s
, size_t *plen
)
458 size_t origlen
= *plen
;
459 unsigned char *p
= BYTESTR_MSB(s
, origlen
);
461 while (*plen
> 1 && !*p
) {
465 return memmove(s
, BYTESTR_LOPART(s
, origlen
, *plen
), *plen
);
468 static unsigned char*
469 bytestr_from_hex(char **nptr
, size_t *plen
)
472 unsigned char *ret
, *s
;
475 for (q
= p
= *nptr
; isxdigit(*q
); ++q
);
477 *plen
= ((size_t)(q
- p
) + 1) >> 1;
479 if (! (ret
= calloc(1, *plen
)) )
482 s
= BYTESTR_LSB(ret
, *plen
);
485 *s
|= unhex(*q
) << shift
;
496 static unsigned char*
497 bytestr_from_oct(char **nptr
, size_t *plen
)
500 unsigned char *ret
, *s
;
503 for (q
= p
= *nptr
; *q
>= '0' && *q
<= '7'; ++q
);
505 *plen
= ((size_t)(q
- p
) * 3 + 7)/8 ?: 1;
506 if (! (ret
= calloc(1, *plen
)) )
509 s
= BYTESTR_LSB(ret
, *plen
);
512 acc
|= (*q
- '0') << shift
;
524 return bytestr_shrink(ret
, plen
);
527 /* Number of bits per decimal digit scaled by 256 (8 bit shift) */
528 #define SBITSPERDECDIG 851
530 static unsigned char*
531 bytestr_from_dec(char **nptr
, size_t *plen
)
534 unsigned char *ret
, *s
;
536 /* We must make sure that the resulting bytestr will fit into
537 * the allocated space, so we must always round to the nearest
538 * higher integer. Because of this, the approximation of log2(10)
539 * and the dependency on the actual number, the allocated space
540 * may be larger than necessary.
542 for (p
= q
= *nptr
; isdigit(*q
); ++q
);
544 *plen
= (((size_t)(q
- p
) * SBITSPERDECDIG
+ 255)/256 + 7)/8 ?: 1;
545 if (! (ret
= calloc(1, *plen
)) )
549 unsigned carry
= *p
++ - '0';
550 for (s
= BYTESTR_LSB(ret
, *plen
);
551 s
!= BYTESTR_MSB(ret
, *plen
) + BYTESTR_STEP
;
559 return bytestr_shrink(ret
, plen
);
562 /* Convert an ascii representation to a bytestr */
563 static unsigned char*
564 bytestr_from_ascii(char **nptr
, size_t *plen
)
568 if ((**nptr
== 'x' || **nptr
== 'X') &&
569 isxdigit((*nptr
)[1])) {
571 return bytestr_from_hex(nptr
, plen
);
573 return bytestr_from_oct(nptr
, plen
);
575 return bytestr_from_dec(nptr
, plen
);
579 bytestr_unop(unsigned char *s
, size_t len
, long flags
, enum atom_un_op op
)
585 if (op
== AUO_MINUS
) {
586 if (!bytestr_inc(s
, len
))
587 flags
^= HED_AEF_NEGATIVE
;
598 bytestr_binop(unsigned char *s1
, unsigned char *s2
, size_t len
,
599 long flags1
, long flags2
, enum atom_bin_op op
)
603 int sign
= !!(flags1
& HED_AEF_NEGATIVE
);
604 int sign2
= !!(flags2
& HED_AEF_NEGATIVE
);
605 long ret
= (flags1
& ~HED_AEF_NEGATIVE
) | (flags2
& HED_AEF_DYNAMIC
);
610 bytestr_or(s1
, s2
, len
);
614 bytestr_and(s1
, s2
, len
);
618 bytestr_xor(s1
, s2
, len
);
621 carry
= bytestr_add(s1
, s2
, len
);
622 sign
^= (sign
^ sign2
) & (sign
^ !carry
);
625 carry
= bytestr_sub(s1
, s2
, len
);
626 sign
^= ((sign
^ sign2
) | (sign
^ !carry
)) ^ 1;
630 bytestr_mul(s1
, s2
, len
);
635 if (! (smod
= malloc(len
)) ) {
636 flags1
= HED_AEF_ERROR
;
639 bytestr_div(s1
, s2
, len
, smod
);
641 memcpy(s1
, smod
, len
);
645 bytestr_shl(s1
, s2
, len
);
648 bytestr_shr(s1
, s2
, len
);
654 ret
|= HED_AEF_NEGATIVE
& -sign
;
659 alloc_atom(enum atom_type type
, size_t len
)
661 static const size_t sizes
[] = {
662 sizeof(struct atom_un
),
663 sizeof(struct atom_bin
),
664 sizeof(struct atom_bytestr
),
665 sizeof(struct atom_register
),
666 sizeof(struct atom_mark
)
668 size_t asize
= sizes
[type
];
671 if (type
== ATOM_BYTESTR
)
674 a
= calloc(1, asize
);
681 val_parse(char **sexpr
)
683 char uopc
[] = "~-"; // in atom_un_op order
689 if (**sexpr
== '(') {
691 ret
= atom_parse(sexpr
);
693 } else if ( (uop
= strchr(uopc
, **sexpr
)) ) {
698 sa
= val_parse(sexpr
);
702 a
= alloc_atom(ATOM_UN
, sa
->len
);
707 } else if (**sexpr
== '"') {
708 struct atom_register
*a
;
715 a
= alloc_atom(ATOM_REGISTER
, SIZE_AUTO
);
718 INIT_LIST_HEAD(&a
->offset
.atoms
);
719 if (**sexpr
== '[') {
721 compile_till(&a
->offset
, sexpr
, ']');
727 } else if (**sexpr
== '@') {
735 a
= alloc_atom(ATOM_MARK
, sizeof(hed_off_t
));
739 } else if (**sexpr
== '\'') {
740 struct atom_bytestr
*a
;
746 while (**sexpr
&& **sexpr
!= '\'') {
747 if (**sexpr
== '\\') {
756 a
= alloc_atom(ATOM_BYTESTR
, i
);
758 for (i
= 0; base
< *sexpr
; i
++, base
++) {
766 } else if (**sexpr
== 'x') {
767 struct atom_bytestr
*a
;
773 while (isxdigit(**sexpr
))
776 a
= alloc_atom(ATOM_BYTESTR
, (*sexpr
- base
+ 1)/2);
780 if ((*sexpr
- base
) % 2)
781 a
->bytes
[i
++] = unhex(*base
++);
782 while (base
< *sexpr
) {
783 a
->bytes
[i
++] = (unhex(base
[0]) << 4) + unhex(base
[1]);
788 } else if (isdigit(**sexpr
)) {
789 struct atom_bytestr
*a
;
793 if (! (num
= bytestr_from_ascii(sexpr
, &len
)) )
796 a
= alloc_atom(ATOM_BYTESTR
, len
);
798 memcpy(a
->bytes
, num
, len
);
805 if (**sexpr
== '{') {
807 ret
->len
= strtoull(*sexpr
, sexpr
, 0);
808 if (**sexpr
!= '}') {
818 atom_lparse(char **sexpr
, struct atom
*sa1
)
822 char bopc
[] = "|&^+-*/%<>"; // in atom_bin_op order
828 if (**sexpr
== ')') {
830 return sa1
; // *SLAMM*
832 bop
= strchr(bopc
, **sexpr
);
836 if (*bop
== '<' || *bop
== '>') {
837 if (*(*sexpr
)++ != *bop
)
840 sa2
= val_parse(sexpr
);
844 //fprintf(stderr, "parse error at <%s>\n", *sexpr);
847 if (sa1
->len
== SIZE_AUTO
)
849 else if (sa2
->len
== SIZE_AUTO
)
851 /* Note that BOTH may be SIZE_AUTO, but that's ok */
853 a
= alloc_atom(ATOM_BIN
, max(sa1
->len
, sa2
->len
));
857 /* Try to expand the epxression */
858 return atom_lparse(sexpr
, &a
->a
) ? : &a
->a
;
862 atom_parse(char **sexpr
)
864 struct atom
*a
, *sa1
;
866 sa1
= val_parse(sexpr
);
868 //fprintf(stderr, "parse error at <%s>\n", *sexpr);
869 (*sexpr
)++; // no luck, maybe next char
872 a
= atom_lparse(sexpr
, sa1
);
880 static struct hed_expr
*
881 compile_till(struct hed_expr
*expr
, char **sexpr
, char till
)
884 while (**sexpr
!= till
) {
885 struct atom
*a
= atom_parse(sexpr
);
889 list_add_tail(&a
->list
, &expr
->atoms
);
890 if (a
->len
== SIZE_AUTO
)
892 if (a
->type
== ATOM_BIN
&& a
->len
> tmplen
)
898 expr
->buf
= realloc(expr
->buf
, expr
->len
+ tmplen
);
901 expr
->tmp
= expr
->buf
+ expr
->len
;
908 hed_expr_compile(char *sexpr
)
910 struct hed_expr
*expr
= calloc(1, sizeof(struct hed_expr
));
915 INIT_LIST_HEAD(&expr
->atoms
);
916 if (compile_till(expr
, &sexpr
, '\0'))
925 atom_eval(struct hed_expr
*expr
, struct atom
*atom
,
926 unsigned char *scramble
, size_t len
)
931 return evals
[atom
->type
](expr
, atom
, scramble
, len
);
935 atom_un(struct hed_expr
*expr
, struct atom
*atom
,
936 unsigned char *scramble
, size_t len
)
938 struct atom_un
*data
= (struct atom_un
*) atom
;
942 flags
= atom_eval(expr
, data
->atom
, scramble
, len
);
943 if (flags
& HED_AEF_ERROR
)
945 return bytestr_unop(scramble
, len
, flags
, data
->op
);
949 atom_bin(struct hed_expr
*expr
, struct atom
*atom
,
950 unsigned char *scramble
, size_t len
)
952 struct atom_bin
*data
= (struct atom_bin
*) atom
;
955 assert(data
->atom1
&& data
->atom2
);
957 flags1
= atom_eval(expr
, data
->atom1
, scramble
, len
);
958 if (flags1
& HED_AEF_ERROR
)
961 flags2
= atom_eval(expr
, data
->atom2
, expr
->tmp
, len
);
962 if (flags2
& HED_AEF_ERROR
)
965 return bytestr_binop(scramble
, expr
->tmp
, len
,
966 flags1
, flags2
, data
->op
);
970 atom_bytestr(struct hed_expr
*expr
, struct atom
*atom
,
971 unsigned char *scramble
, size_t len
)
973 struct atom_bytestr
*data
= (struct atom_bytestr
*) atom
;
975 if (len
> data
->len
) {
976 memcpy(BYTESTR_LOPART(scramble
, len
, data
->len
),
977 data
->bytes
, data
->len
);
978 memset(BYTESTR_HIPART(scramble
, len
, len
- data
->len
),
982 BYTESTR_LOPART(data
->bytes
, data
->len
, len
), len
);
987 atom_mark(struct hed_expr
*expr
, struct atom
*atom
,
988 unsigned char *scramble
, size_t len
)
990 struct atom_mark
*data
= (struct atom_mark
*) atom
;
992 if (!expr
->mark_cb
) {
993 memset(scramble
, 0, len
);
997 return expr
->mark_cb(expr
->cb_data
, data
->mark
, scramble
, len
);
1002 atom_register(struct hed_expr
*expr
, struct atom
*atom
,
1003 unsigned char *scramble
, size_t len
)
1005 struct atom_register
*data
= (struct atom_register
*) atom
;
1008 if (!expr
->reg_cb
) {
1009 memset(scramble
, 0, len
);
1013 if (hed_expr_eval(&data
->offset
, expr
->reg_cb
,
1014 expr
->mark_cb
, expr
->cb_data
)
1016 return HED_AEF_ERROR
;
1018 ofs
= hed_expr2off(&data
->offset
);
1020 if (data
->reg
== '.')
1021 ofs
+= expr
->cb_pos
;
1022 return expr
->reg_cb(expr
->cb_data
, data
->reg
, ofs
,
1028 hed_expr_eval(struct hed_expr
*expr
,
1029 hed_expr_reg_cb rcb
, hed_expr_mark_cb mcb
, void *data
)
1034 expr
->mark_cb
= mcb
;
1035 expr
->cb_data
= data
;
1039 assert(expr
&& expr
->len
>= 0);
1040 list_for_each_entry (a
, &expr
->atoms
, list
) {
1043 flags
= atom_eval(expr
, a
,
1044 expr
->buf
+ expr
->cb_pos
, a
->len
);
1045 expr
->flags
|= (flags
& (HED_AEF_DYNAMIC
| HED_AEF_ERROR
));
1047 expr
->flags
|= (flags
& HED_AEF_NEGATIVE
);
1049 expr
->flags
&= ~HED_AEF_NEGATIVE
;
1050 expr
->cb_pos
+= a
->len
;
1052 assert(expr
->cb_pos
== expr
->len
);
1059 struct atom_un
*un
= (struct atom_un
*) p
;
1060 free_atom(un
->atom
);
1067 struct atom_bin
*bin
= (struct atom_bin
*) p
;
1068 free_atom(bin
->atom1
);
1069 free_atom(bin
->atom2
);
1074 free_register(void *p
)
1076 struct atom_register
*reg
= (struct atom_register
*) p
;
1077 expr_cleanup(®
->offset
);
1082 expr_cleanup(struct hed_expr
*expr
)
1084 struct atom
*a
, *next
;
1086 list_for_each_entry_safe (a
, next
, &expr
->atoms
, list
)
1093 hed_expr_free(struct hed_expr
*expr
)