Open SCAP Library
/home/pvrabec/project/openscap/openscap-0.8.1/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 #include <helpers.h>
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 /*
00051  * number
00052  */
00053 
00059 SEXP_t *SEXP_number_new (SEXP_numtype_t t, const void *n) __attribute__ ((nonnull (2)));
00060 
00065 SEXP_t *SEXP_number_newb (bool n);
00066 
00071 SEXP_t *SEXP_number_newi_8 (int8_t n);
00072 
00077 SEXP_t *SEXP_number_newu_8 (uint8_t n);
00078 
00083 uint8_t SEXP_number_getu_8 (const SEXP_t *s_exp);
00084 
00089 SEXP_t *SEXP_number_newi_16 (int16_t n);
00090 
00095 SEXP_t *SEXP_number_newu_16 (uint16_t n);
00096 
00101 #define SEXP_number_newi SEXP_number_newi_32
00102 
00107 SEXP_t *SEXP_number_newi_32 (int32_t n);
00108 
00113 #define SEXP_number_geti SEXP_number_geti_32
00114 
00119 int32_t SEXP_number_geti_32 (const SEXP_t *s_exp);
00120 
00125 bool SEXP_number_getb (const SEXP_t *s_exp);
00126 
00131 #define SEXP_number_newu SEXP_number_newu_32
00132 
00137 SEXP_t *SEXP_number_newu_32 (uint32_t n);
00138 
00143 #define  SEXP_number_getu SEXP_number_getu_32
00144 
00149 uint32_t SEXP_number_getu_32 (const SEXP_t *s_exp);
00150 
00155 SEXP_t *SEXP_number_newi_64 (int64_t n);
00156 
00161 int64_t SEXP_number_geti_64 (const SEXP_t *s_exp);
00162 
00167 SEXP_t *SEXP_number_newu_64 (uint64_t n);
00168 
00173 uint64_t SEXP_number_getu_64 (const SEXP_t *s_exp);
00174 
00179 SEXP_t *SEXP_number_newf (double n);
00180 
00185 double  SEXP_number_getf (const SEXP_t *s_exp);
00186 
00193 int SEXP_number_get (const SEXP_t *s_exp, void *dst, SEXP_numtype_t type);
00194 
00199 uint16_t SEXP_number_getu_16 (const SEXP_t *s_exp);
00200 
00205 void    SEXP_number_free (SEXP_t *s_exp);
00206 
00211 bool    SEXP_numberp (const SEXP_t *s_exp);
00212 
00217 SEXP_numtype_t SEXP_number_type (const SEXP_t *sexp);
00218 
00219 /*
00220  * string
00221  */
00222 
00228 SEXP_t *SEXP_string_new  (const void *string, size_t strlen) __attribute__ ((nonnull (1)));
00229 
00235 SEXP_t *SEXP_string_newf (const char *format, ...) __attribute__ ((format (printf, 1, 2), nonnull (1)));
00236 
00241 void SEXP_string_free (SEXP_t *s_exp);
00242 
00247 bool SEXP_stringp (const SEXP_t *s_exp);
00248 
00253 size_t SEXP_string_length (const SEXP_t *s_exp);
00254 
00260 int SEXP_strcmp (const SEXP_t *s_exp, const char *str) __attribute__ ((nonnull (2)));
00261 
00268 int SEXP_strncmp (const SEXP_t *s_exp, const char *str, size_t n) __attribute__ ((nonnull (2)));
00269 
00275 int SEXP_string_nth (const SEXP_t *s_exp, size_t n);
00276 
00280 char  *SEXP_string_cstr (const SEXP_t *s_exp);
00281 
00289 size_t SEXP_string_cstr_r (const SEXP_t *s_exp, char *buf, size_t len) __attribute__ ((nonnull (2)));
00290 
00294 char  *SEXP_string_cstrp (const SEXP_t *s_exp);
00295 
00302 char *SEXP_string_subcstr (const SEXP_t *s_exp, size_t beg, size_t len);
00303 
00309 int SEXP_string_cmp (const SEXP_t *str_a, const SEXP_t *str_b);
00310 
00315 bool SEXP_string_getb (const SEXP_t *s_exp);
00316 
00317 /*
00318  * list
00319  */
00320 
00327 SEXP_t *SEXP_list_new (SEXP_t *memb, ...);
00328 
00333 void    SEXP_list_free (SEXP_t *s_exp);
00334 
00339 bool    SEXP_listp (const SEXP_t *s_exp);
00340 
00345 size_t  SEXP_list_length (const SEXP_t *s_exp);
00346 
00352 SEXP_t *SEXP_list_first (const SEXP_t *list);
00353 
00359 SEXP_t *SEXP_list_rest  (const SEXP_t *list);
00360 
00366 SEXP_t *SEXP_list_last (const SEXP_t *list);
00367 
00374 SEXP_t *SEXP_list_nth (const SEXP_t *list, uint32_t n);
00375 
00382 SEXP_t *SEXP_list_add (SEXP_t *list, const SEXP_t *s_exp);
00383 
00390 SEXP_t *SEXP_list_join (const SEXP_t *list_a, const SEXP_t *list_b);
00391 
00398 SEXP_t *SEXP_list_push (SEXP_t *list, const SEXP_t *s_exp);
00399 
00405 SEXP_t *SEXP_list_pop (SEXP_t *list);
00406 
00410 SEXP_t *SEXP_list_sort(SEXP_t *list, int(*compare)(const SEXP_t *, const SEXP_t *));
00411 
00420 SEXP_t *SEXP_list_replace (SEXP_t *list, uint32_t n, const SEXP_t *s_exp);
00421 
00427 SEXP_t *SEXP_listref_first (SEXP_t *list);
00428 
00434 SEXP_t *SEXP_listref_rest (SEXP_t *list);
00435 
00441 SEXP_t *SEXP_listref_last (SEXP_t *list);
00442 
00449 SEXP_t *SEXP_listref_nth (SEXP_t *list, uint32_t n);
00450 
00451 typedef struct SEXP_it SEXP_it_t;
00452 
00453 #define SEXP_IT_RECURSIVE 0x01
00454 #define SEXP_IT_HARDREF   0x02
00455 
00456 SEXP_it_t *SEXP_listit_new (const SEXP_t *list, int flags);
00457 SEXP_t    *SEXP_listit_next(SEXP_it_t *it);
00458 SEXP_t    *SEXP_listit_prev (SEXP_it_t *it);
00459 SEXP_t    *SEXP_listit_length (SEXP_it_t *it);
00460 SEXP_t    *SEXP_listit_seek (SEXP_it_t *it, uint32_t n);
00461 void       SEXP_listit_free (SEXP_it_t *it);
00462 
00463 typedef struct SEXP_list_it SEXP_list_it;
00464 
00465 SEXP_list_it *SEXP_list_it_new(SEXP_t *list);
00466 SEXP_t *SEXP_list_it_next(SEXP_list_it *it);
00467 void SEXP_list_it_free(SEXP_list_it *it);
00468 
00469 #if __STDC_VERSION__ >= 199901L
00470 # include <common/util.h>
00471 
00472 /* TODO: use alloca & softref_r here */
00478 #define SEXP_list_foreach(var, list)                                    \
00479         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), (var) = NULL)
00480 
00488 #define SEXP_sublist_foreach(var, list, beg, end)                       \
00489         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), (var) = NULL)
00490 
00491 #define SEXP_LIST_END (UINT32_MAX - 1)
00492 
00493 #endif /* __STDC_VERSION__ >= 199901L */
00494 
00495 /*
00496  * generic
00497  */
00498 SEXP_t *SEXP_new (void);
00499 
00500 bool SEXP_emptyp(SEXP_t *sexp);
00501 
00506 SEXP_t *SEXP_ref (const SEXP_t *s_exp);
00507 
00508 SEXP_t *SEXP_unref (SEXP_t *s_exp_o);
00509 
00514 SEXP_t *SEXP_softref (SEXP_t *s_exp);
00515 
00520 bool SEXP_softrefp(const SEXP_t *s_exp);
00521 
00526 uint32_t SEXP_refs (const SEXP_t *ref);
00527 
00528 bool SEXP_eq (const SEXP_t *a, const SEXP_t *b);
00529 
00533 int SEXP_refcmp(const SEXP_t *a, const SEXP_t *b);
00534 
00535 bool SEXP_deepcmp(const SEXP_t *a, const SEXP_t *b);
00536 
00537 #if defined(NDEBUG)
00538 
00542 void     SEXP_free (SEXP_t *s_exp);
00543 
00550 void     __SEXP_vfree (int n, SEXP_t *s_exp, ...);
00551 # define SEXP_vfree(...) __SEXP_vfree(PP_NARG(__VA_ARGS__), __VA_ARGS__)
00552 #else
00553 # define SEXP_free(ptr) __SEXP_free (ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00554 void     __SEXP_free (SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00555 # define SEXP_vfree(...) __SEXP_vfree (__FILE__, __LINE__, __PRETTY_FUNCTION__, PP_NARG(__VA_ARGS__), __VA_ARGS__)
00556 void     __SEXP_vfree (const char *file, uint32_t line, const char *func, int n, SEXP_t *s_exp, ...);
00557 #endif
00558 
00563 const char *SEXP_datatype (const SEXP_t *s_exp);
00564 
00569 int SEXP_datatype_set (SEXP_t *s_exp, const char *name) __attribute__ ((nonnull (2)));
00570 
00577 int SEXP_datatype_set_nth (SEXP_t *list, uint32_t n, const char *name) __attribute__ ((nonnull (3)));
00578 
00583 SEXP_type_t SEXP_typeof (const SEXP_t *s_exp);
00584 
00589 const char *SEXP_strtype (const SEXP_t *s_exp);
00590 
00591 SEXP_t *SEXP_build (const char *s_str, ...);
00592 
00593 size_t SEXP_sizeof (const SEXP_t *s_exp);
00594 
00595 #if !defined(NDEBUG)
00596 # define SEXP_VALIDATE(s) __SEXP_VALIDATE(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00597 # include <stdlib.h>
00598 
00599 void __SEXP_VALIDATE(const SEXP_t *s_exp, const char *file, uint32_t line, const char *func);
00600 
00601 #else
00602 # define SEXP_VALIDATE(s)
00603 #endif
00604 
00605 #ifdef __cplusplus
00606 }
00607 #endif
00608 
00609 #endif /* SEXP_MANIP_H */
00610 /* @}@}@} */