Open SCAP Library
|
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 00414 SEXP_t *SEXP_list_replace (SEXP_t *list, uint32_t n, const SEXP_t *s_exp); 00415 00421 SEXP_t *SEXP_listref_first (SEXP_t *list); 00422 00428 SEXP_t *SEXP_listref_rest (SEXP_t *list); 00429 00435 SEXP_t *SEXP_listref_last (SEXP_t *list); 00436 00443 SEXP_t *SEXP_listref_nth (SEXP_t *list, uint32_t n); 00444 00445 typedef struct SEXP_it SEXP_it_t; 00446 00447 #define SEXP_IT_RECURSIVE 0x01 00448 #define SEXP_IT_HARDREF 0x02 00449 00450 SEXP_it_t *SEXP_listit_new (const SEXP_t *list, int flags); 00451 SEXP_t *SEXP_listit_next(SEXP_it_t *it); 00452 SEXP_t *SEXP_listit_prev (SEXP_it_t *it); 00453 SEXP_t *SEXP_listit_length (SEXP_it_t *it); 00454 SEXP_t *SEXP_listit_seek (SEXP_it_t *it, uint32_t n); 00455 void SEXP_listit_free (SEXP_it_t *it); 00456 00457 #if __STDC_VERSION__ >= 199901L 00458 # include <common/util.h> 00459 00460 /* TODO: use alloca & softref_r here */ 00466 #define SEXP_list_foreach(var, list) \ 00467 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)) 00468 00476 #define SEXP_sublist_foreach(var, list, beg, end) \ 00477 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)) 00478 00479 #define SEXP_LIST_END (UINT32_MAX - 1) 00480 00481 #endif /* __STDC_VERSION__ >= 199901L */ 00482 00483 /* 00484 * generic 00485 */ 00486 SEXP_t *SEXP_new (void); 00487 00488 bool SEXP_emptyp(SEXP_t *sexp); 00489 00494 SEXP_t *SEXP_ref (const SEXP_t *s_exp); 00495 00496 SEXP_t *SEXP_unref (SEXP_t *s_exp_o); 00497 00502 SEXP_t *SEXP_softref (SEXP_t *s_exp); 00503 00508 bool SEXP_softrefp(const SEXP_t *s_exp); 00509 00514 uint32_t SEXP_refs (const SEXP_t *ref); 00515 00516 bool SEXP_eq (const SEXP_t *a, const SEXP_t *b); 00517 00518 #if defined(NDEBUG) 00519 00523 void SEXP_free (SEXP_t *s_exp); 00524 00531 void SEXP_vfree (SEXP_t *s_exp, ...); 00532 #else 00533 # define SEXP_free(ptr) __SEXP_free (ptr, __FILE__, __LINE__, __PRETTY_FUNCTION__) 00534 void __SEXP_free (SEXP_t *s_exp, const char *file, uint32_t line, const char *func); 00535 # define SEXP_vfree(...) __SEXP_vfree (__FILE__, __LINE__, __PRETTY_FUNCTION__, __VA_ARGS__) 00536 void __SEXP_vfree (const char *file, uint32_t line, const char *func, SEXP_t *s_exp, ...); 00537 #endif 00538 00543 const char *SEXP_datatype (const SEXP_t *s_exp); 00544 00549 int SEXP_datatype_set (SEXP_t *s_exp, const char *name) __attribute__ ((nonnull (2))); 00550 00557 int SEXP_datatype_set_nth (SEXP_t *list, uint32_t n, const char *name) __attribute__ ((nonnull (3))); 00558 00563 SEXP_type_t SEXP_typeof (const SEXP_t *s_exp); 00564 00569 const char *SEXP_strtype (const SEXP_t *s_exp); 00570 00571 SEXP_t *SEXP_build (const char *s_str, ...); 00572 00573 size_t SEXP_sizeof (const SEXP_t *s_exp); 00574 00575 #if !defined(NDEBUG) 00576 # define SEXP_VALIDATE(s) __SEXP_VALIDATE(s, __FILE__, __LINE__, __PRETTY_FUNCTION__) 00577 # include <stdlib.h> 00578 00579 void __SEXP_VALIDATE(const SEXP_t *s_exp, const char *file, uint32_t line, const char *func); 00580 00581 #else 00582 # define SEXP_VALIDATE(s) 00583 #endif 00584 00585 #ifdef __cplusplus 00586 } 00587 #endif 00588 00589 #endif /* SEXP_MANIP_H */ 00590 /* @}@}@} */