00001 /* 00002 * Copyright 2009 Red Hat Inc., Durham, North Carolina. 00003 * All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 * Authors: 00020 * "Daniel Kopecek" <dkopecek@redhat.com> 00021 */ 00022 #pragma once 00023 #ifndef SEXP_PARSER_H 00024 #define SEXP_PARSER_H 00025 00026 #include <stddef.h> 00027 #include <stdint.h> 00028 #include "public/sexp-parser.h" 00029 #include "_sexp-manip.h" 00030 #include "generic/spb.h" 00031 00032 OSCAP_HIDDEN_START; 00033 00034 /* Number classes */ 00035 #define SEXP_NUMCLASS_INV 0 00036 #define SEXP_NUMCLASS_INT 1 00037 #define SEXP_NUMCLASS_UINT 2 00038 #define SEXP_NUMCLASS_FLT 3 00039 #define SEXP_NUMCLASS_EXP 4 00040 #define SEXP_NUMCLASS_FRA 5 00041 #define SEXP_NUMCLASS_PRE 6 00042 00043 /* 00044 * Parser state 00045 */ 00046 struct SEXP_pstate { 00047 /* 00048 * Input data 00049 */ 00050 spb_t *p_buffer; /* input buffer */ 00051 spb_size_t p_bufoff; /* start index - everything before this index in the buffer is already parsed */ 00052 spb_size_t p_explen; /* length of already parsed/checked part of the expression */ 00053 SEXP_pflags_t p_flags; /* current parser flags */ 00054 SEXP_t *p_sexp; /* last S-exp object */ 00055 SEXP_pflags_t p_flags0; /* initial parser flags */ 00056 00057 void *sp_data; /* subparser data */ 00058 void (*sp_free)(void *); /* function for freeing the subparser data */ 00059 00060 uint8_t p_label; /* where to jump if p_explen > 0 */ 00061 00062 uint8_t p_numclass; /* number class */ 00063 uint8_t p_numbase; /* number base */ 00064 uint8_t p_numstage; /* number parsing stage */ 00065 00066 /* 00067 * Output data 00068 */ 00069 SEXP_lstack_t l_stack; /* output list stack */ 00070 00071 /* 00072 * Value cache 00073 */ 00074 uintptr_t v_bool[2]; /* true, false pre-allocated values */ 00075 }; 00076 00077 struct SEXP_psetup { 00078 SEXP_format_t p_format; /* expected or required format (depends on p_flags) */ 00079 SEXP_pflags_t p_flags; /* initial parser flags */ 00080 }; 00081 00082 #define SEXP_PSLOT_MAX 1024 00083 00084 #define SEXP_PRET_SUCCESS 0 00085 #define SEXP_PRET_EUNFIN 1 /* incomplete token */ 00086 #define SEXP_PRET_EINVAL 2 /* syntax error, invalid token */ 00087 #define SEXP_PRET_EUNDEF 255 /* unknown, unexpected error */ 00088 00089 #ifdef __GNUC__ 00090 # define __predict(expr, v) __builtin_expect (expr, v) 00091 #else 00092 # define __predict(expr, v) expr 00093 #endif /* __GNUC__ */ 00094 00095 OSCAP_HIDDEN_END; 00096 00097 #endif /* SEXP_PARSER_H */