| 1 | /** |
| 2 | This software and ancillary information (herein called "SOFTWARE") |
| 3 | called Supermon is made available under the terms described |
| 4 | here. The SOFTWARE has been approved for release with associated |
| 5 | LA-CC Number LA-CC 99-51. |
| 6 | |
| 7 | Unless otherwise indicated, this SOFTWARE has been authored by an |
| 8 | employee or employees of the University of California, operator of the |
| 9 | Los Alamos National Laboratory under Contract No. W-7405-ENG-36 with |
| 10 | the U.S. Department of Energy. The U.S. Government has rights to use, |
| 11 | reproduce, and distribute this SOFTWARE, and to allow others to do so. |
| 12 | The public may copy, distribute, prepare derivative works and publicly |
| 13 | display this SOFTWARE without charge, provided that this Notice and |
| 14 | any statement of authorship are reproduced on all copies. Neither the |
| 15 | Government nor the University makes any warranty, express or implied, |
| 16 | or assumes any liability or responsibility for the use of this |
| 17 | SOFTWARE. |
| 18 | |
| 19 | If SOFTWARE is modified to produce derivative works, such modified |
| 20 | SOFTWARE should be clearly marked, so as not to confuse it with the |
| 21 | version available from LANL. |
| 22 | **/ |
| 23 | /** NOTICE: This software is licensed under the GNU Public License, which |
| 24 | is included as LICENSE_GPL in this source distribution. **/ |
| 25 | /** NOTE: This library is part of the supermon project, hence the name |
| 26 | supermon above. **/ |
| 27 | #ifndef __SEXP_OPS_H__ |
| 28 | #define __SEXP_OPS_H__ |
| 29 | |
| 30 | /** |
| 31 | * \file sexp_ops.h |
| 32 | * |
| 33 | * \brief A collection of useful operations to perform on s-expressions. |
| 34 | * |
| 35 | * A set of routines for operating on s-expressions. Note that cons, |
| 36 | * car, and cdr do <B>not</B> currently have any guarantee to behave in a |
| 37 | * identical manner as their LISP or Scheme equivalents. This would be |
| 38 | * fairly easy to fix, but not high on the priority list currently. |
| 39 | */ |
| 40 | |
| 41 | #include "sexp.h" |
| 42 | |
| 43 | #ifdef __cplusplus |
| 44 | extern "C" { |
| 45 | #endif |
| 46 | |
| 47 | /*========*/ |
| 48 | /* MACROS */ |
| 49 | /*========*/ |
| 50 | |
| 51 | /** |
| 52 | * Return the head of a list \a s by reference, not copy. |
| 53 | */ |
| 54 | #define hd_sexp(s) ((s)->list) |
| 55 | |
| 56 | /** |
| 57 | * Return the tail of a list \a s by reference, not copy. |
| 58 | */ |
| 59 | #define tl_sexp(s) ((s)->list->next) |
| 60 | |
| 61 | /** |
| 62 | * Return the element following the argument \a s. |
| 63 | */ |
| 64 | #define next_sexp(s) ((s)->next) |
| 65 | |
| 66 | /** |
| 67 | * Reset the continuation \a c by setting the \c lastPos pointer to |
| 68 | * \c NULL. |
| 69 | */ |
| 70 | #define reset_pcont(c) ((c)->lastPos = NULL) |
| 71 | |
| 72 | /** |
| 73 | * Find an atom in a sexpression data structure and return a pointer to |
| 74 | * it. Return NULL if the string doesn't occur anywhere as an atom. |
| 75 | * This is a depth-first search algorithm. |
| 76 | */ |
| 77 | sexp_t *find_sexp(char *name, sexp_t *start); |
| 78 | |
| 79 | /** |
| 80 | * Breadth first search for s-expressions. Depth first search will find |
| 81 | * the first occurance of a string in an s-expression by basically finding |
| 82 | * the earliest occurance in the string representation of the expression |
| 83 | * itself. Breadth first search will find the first occurance of a string |
| 84 | * in relation to the structure of the expression itself (IE: the instance |
| 85 | * with the lowest depth will be found). |
| 86 | */ |
| 87 | sexp_t *bfs_find_sexp(char *str, sexp_t *sx); |
| 88 | |
| 89 | /** |
| 90 | * Copy an s-expression. This is a deep copy - so the resulting s-expression |
| 91 | * shares no pointers with the original. The new one can be changed without |
| 92 | * damaging the contents of the original. |
| 93 | */ |
| 94 | sexp_t *copy_sexp(sexp_t *s); |
| 95 | |
| 96 | /** |
| 97 | * Cons: Concatenate two s-expressions together, without references to the |
| 98 | * originals. |
| 99 | */ |
| 100 | sexp_t *cons_sexp(sexp_t *r, sexp_t *l); |
| 101 | |
| 102 | /** |
| 103 | * car: Like hd(), but returning a copy of the head, not a reference to it. |
| 104 | */ |
| 105 | sexp_t *car_sexp(sexp_t *s); |
| 106 | |
| 107 | /** |
| 108 | * cdr: Like tl(), but returning a copy of the tail, not a reference to it. |
| 109 | */ |
| 110 | sexp_t *cdr_sexp(sexp_t *s); |
| 111 | |
| 112 | #ifdef __cplusplus |
| 113 | } |
| 114 | #endif |
| 115 | |
| 116 | #endif /* __SEXP_OPS_H__ */ |