Open SCAP Library
/home/pvrabec/project/openscap/openscap-0.7.4/src/OVAL/probes/SEAP/public/sexp-manip.h
Go to the documentation of this file.
00001 
00013 /*
00014  * Copyright 2009 Red Hat Inc., Durham, North Carolina.
00015  * All Rights Reserved.
00016  *
00017  * This library is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU Lesser General Public
00019  * License as published by the Free Software Foundation; either
00020  * version 2.1 of the License, or (at your option) any later version.
00021  *
00022  * This library is distributed in the hope that it will be useful, 
00023  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * Lesser General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU Lesser General Public
00028  * License along with this library; if not, write to the Free Software 
00029  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00030  *
00031  * Authors:
00032  *      Daniel Kopecek <dkopecek@redhat.com>
00033  */
00034 
00035 #pragma once
00036 #ifndef SEXP_MANIP_H
00037 #define SEXP_MANIP_H
00038 
00039 #include <stdarg.h>
00040 #include <stddef.h>
00041 #include <stdint.h>
00042 #include <stdbool.h>
00043 #include <sexp-types.h>
00044 
00045 #ifdef __cplusplus
00046 extern "C" {
00047 #endif
00048 
00049 /*
00050  * number
00051  */
00052 
00058 SEXP_t *SEXP_number_new (SEXP_numtype_t t, const void *n) __attribute__ ((nonnull (2)));
00059 
00064 SEXP_t *SEXP_number_newb (bool n);
00065 
00070 SEXP_t *SEXP_number_newi_8 (int8_t n);
00071 
00076 SEXP_t *SEXP_number_newu_8 (uint8_t n);
00077 
00082 uint8_t SEXP_number_getu_8 (const SEXP_t *s_exp);
00083 
00088 SEXP_t *SEXP_number_newi_16 (int16_t n);
00089 
00094 SEXP_t *SEXP_number_newu_16 (uint16_t n);
00095 
00100 #define SEXP_number_newi SEXP_number_newi_32
00101 
00106 SEXP_t *SEXP_number_newi_32 (int32_t n);
00107 
00112 #define SEXP_number_geti SEXP_number_geti_32
00113 
00118 int32_t SEXP_number_geti_32 (const SEXP_t *s_exp);
00119 
00124 bool SEXP_number_getb (const SEXP_t *s_exp);
00125 
00130 #define SEXP_number_newu SEXP_number_newu_32
00131 
00136 SEXP_t *SEXP_number_newu_32 (uint32_t n);
00137 
00142 #define  SEXP_number_getu SEXP_number_getu_32
00143 
00148 uint32_t SEXP_number_getu_32 (const SEXP_t *s_exp);
00149 
00154 SEXP_t *SEXP_number_newi_64 (int64_t n);
00155 
00160 int64_t SEXP_number_geti_64 (const SEXP_t *s_exp);
00161 
00166 SEXP_t *SEXP_number_newu_64 (uint64_t n);
00167 
00172 uint64_t SEXP_number_getu_64 (const SEXP_t *s_exp);
00173 
00178 SEXP_t *SEXP_number_newf (double n);
00179 
00184 double  SEXP_number_getf (const SEXP_t *s_exp);
00185 
00192 int SEXP_number_get (const SEXP_t *s_exp, void *dst, SEXP_numtype_t type);
00193 
00198 uint16_t SEXP_number_getu_16 (const SEXP_t *s_exp);
00199 
00204 void    SEXP_number_free (SEXP_t *s_exp);
00205 
00210 bool    SEXP_numberp (const SEXP_t *s_exp);
00211 
00216 SEXP_numtype_t SEXP_number_type (const SEXP_t *sexp);
00217 
00218 /*
00219  * string
00220  */
00221 
00227 SEXP_t *SEXP_string_new  (const void *string, size_t strlen) __attribute__ ((nonnull (1)));
00228 
00234 SEXP_t *SEXP_string_newf (const char *format, ...) __attribute__ ((format (printf, 1, 2), nonnull (1)));
00235 
00240 void SEXP_string_free (SEXP_t *s_exp);
00241 
00246 bool SEXP_stringp (const SEXP_t *s_exp);
00247 
00252 size_t SEXP_string_length (const SEXP_t *s_exp);
00253 
00259 int SEXP_strcmp (const SEXP_t *s_exp, const char *str) __attribute__ ((nonnull (2)));
00260 
00267 int SEXP_strncmp (const SEXP_t *s_exp, const char *str, size_t n) __attribute__ ((nonnull (2)));
00268 
00274 int SEXP_string_nth (const SEXP_t *s_exp, size_t n);
00275 
00279 char  *SEXP_string_cstr (const SEXP_t *s_exp);
00280 
00288 size_t SEXP_string_cstr_r (const SEXP_t *s_exp, char *buf, size_t len) __attribute__ ((nonnull (2)));
00289 
00293 char  *SEXP_string_cstrp (const SEXP_t *s_exp);
00294 
00301 char *SEXP_string_subcstr (const SEXP_t *s_exp, size_t beg, size_t len);
00302 
00308 int SEXP_string_cmp (const SEXP_t *str_a, const SEXP_t *str_b);
00309 
00314 bool SEXP_string_getb (const SEXP_t *s_exp);
00315 
00316 /*
00317  * list
00318  */
00319 
00326 SEXP_t *SEXP_list_new (SEXP_t *memb, ...);
00327 
00332 void    SEXP_list_free (SEXP_t *s_exp);
00333 
00338 bool    SEXP_listp (const SEXP_t *s_exp);
00339 
00344 size_t  SEXP_list_length (const SEXP_t *s_exp);
00345 
00351 SEXP_t *SEXP_list_first (const SEXP_t *list);
00352 
00358 SEXP_t *SEXP_list_rest  (const SEXP_t *list);
00359 
00365 SEXP_t *SEXP_list_last (const SEXP_t *list);
00366 
00373 SEXP_t *SEXP_list_nth (const SEXP_t *list, uint32_t n);
00374 
00381 SEXP_t *SEXP_list_add (SEXP_t *list, const SEXP_t *s_exp);
00382 
00389 SEXP_t *SEXP_list_join (const SEXP_t *list_a, const SEXP_t *list_b);
00390 
00397 SEXP_t *SEXP_list_push (SEXP_t *list, const SEXP_t *s_exp);
00398 
00404 SEXP_t *SEXP_list_pop (SEXP_t *list);
00405 
00409 SEXP_t *SEXP_list_sort(SEXP_t *list, int(*compare)(const SEXP_t *, const SEXP_t *));
00410 
00419 SEXP_t *SEXP_list_replace (SEXP_t *list, uint32_t n, const SEXP_t *s_exp);
00420 
00426 SEXP_t *SEXP_listref_first (SEXP_t *list);
00427 
00433 SEXP_t *SEXP_listref_rest (SEXP_t *list);
00434 
00440 SEXP_t *SEXP_listref_last (SEXP_t *list);
00441 
00448 SEXP_t *SEXP_listref_nth (SEXP_t *list, uint32_t n);
00449 
00450 typedef struct SEXP_it SEXP_it_t;
00451 
00452 #define SEXP_IT_RECURSIVE 0x01
00453 #define SEXP_IT_HARDREF   0x02
00454 
00455 SEXP_it_t *SEXP_listit_new (const SEXP_t *list, int flags);
00456 SEXP_t    *SEXP_listit_next(SEXP_it_t *it);
00457 SEXP_t    *SEXP_listit_prev (SEXP_it_t *it);
00458 SEXP_t    *SEXP_listit_length (SEXP_it_t *it);
00459 SEXP_t    *SEXP_listit_seek (SEXP_it_t *it, uint32_t n);
00460 void       SEXP_listit_free (SEXP_it_t *it);
00461 
00462 typedef struct SEXP_list_it SEXP_list_it;
00463 
00464 SEXP_list_it *SEXP_list_it_new(SEXP_t *list);
00465 SEXP_t *SEXP_list_it_next(SEXP_list_it *it);
00466 void SEXP_list_it_free(SEXP_list_it *it);
00467 
00468 #if __STDC_VERSION__ >= 199901L
00469 # include <common/util.h>
00470 
00471 /* TODO: use alloca & softref_r here */
00477 #define SEXP_list_foreach(var, list)                                    \
00478         for (uint32_t OSCAP_CONCAT(i,__LINE__) = 1; ((var) = SEXP_list_nth (list, OSCAP_CONCAT(i,__LINE__))) != NULL; ++OSCAP_CONCAT(i,__LINE__), SEXP_free (var))
00479 
00487 #define SEXP_sublist_foreach(var, list, beg, end)                       \
00488         for (uint32_t OSCAP_CONCAT(i,__LINE__) = (beg); OSCAP_CONCAT(i,__LINE__) <= ((size_t)(end)) && ((var) = SEXP_list_nth (list, OSCAP_CONCAT(i,__LINE__))) != NULL; ++OSCAP_CONCAT(i,__LINE__), SEXP_free (var))
00489 
00490 #define SEXP_LIST_END (UINT32_MAX - 1)
00491 
00492 #endif /* __STDC_VERSION__ >= 199901L */
00493 
00494 /*
00495  * generic
00496  */
00497 SEXP_t *SEXP_new (void);
00498 
00499 bool SEXP_emptyp(SEXP_t *sexp);
00500 
00505 SEXP_t *SEXP_ref (const SEXP_t *s_exp);
00506 
00507 SEXP_t *SEXP_unref (SEXP_t *s_exp_o);
00508 
00513 SEXP_t *SEXP_softref (SEXP_t *s_exp);
00514 
00519 bool SEXP_softrefp(const SEXP_t *s_exp);
00520 
00525 uint32_t SEXP_refs (const SEXP_t *ref);
00526 
00527 bool SEXP_eq (const SEXP_t *a, const SEXP_t *b);
00528 
00532 int SEXP_refcmp(const SEXP_t *a, const SEXP_t *b);
00533 
00534 bool SEXP_deepcmp(const SEXP_t *a, const SEXP_t *b);
00535 
00536 #if defined(NDEBUG)
00537 
00541 void     SEXP_free (SEXP_t *s_exp);
00542 
00549 void     SEXP_vfree (SEXP_t *s_exp, ...);
00550 #else
00551 # define SEXP_free(ptr) __SEXP_free (ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00552 void     __SEXP_free (SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00553 # define SEXP_vfree(...) __SEXP_vfree (__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__)
00554 void     __SEXP_vfree (const char *file, uint32_t line, const char *func, SEXP_t *s_exp, ...);
00555 #endif
00556 
00561 const char *SEXP_datatype (const SEXP_t *s_exp);
00562 
00567 int SEXP_datatype_set (SEXP_t *s_exp, const char *name) __attribute__ ((nonnull (2)));
00568 
00575 int SEXP_datatype_set_nth (SEXP_t *list, uint32_t n, const char *name) __attribute__ ((nonnull (3)));
00576 
00581 SEXP_type_t SEXP_typeof (const SEXP_t *s_exp);
00582 
00587 const char *SEXP_strtype (const SEXP_t *s_exp);
00588 
00589 SEXP_t *SEXP_build (const char *s_str, ...);
00590 
00591 size_t SEXP_sizeof (const SEXP_t *s_exp);
00592 
00593 #if !defined(NDEBUG)
00594 # define SEXP_VALIDATE(s) __SEXP_VALIDATE(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00595 # include <stdlib.h>
00596 
00597 void __SEXP_VALIDATE(const SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00598 
00599 #else
00600 # define SEXP_VALIDATE(s)
00601 #endif
00602 
00603 #ifdef __cplusplus
00604 }
00605 #endif
00606 
00607 #endif /* SEXP_MANIP_H */
00608 /* @}@}@} */