| 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 | /** |
| 28 | * Matt's smaller s-expression parsing library |
| 29 | * |
| 30 | * Written by Matt Sottile ([email protected]), January 2002. |
| 31 | ***/ |
| 32 | |
| 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <string.h> |
| 36 | #include <assert.h> |
| 37 | #include "sexp.h"cxx . . $ `<file>/src/sexpr/sexp.h`/ |
| 38 | #include "faststack.h"cxx . . $ `<file>/src/sexpr/faststack.h`/ |
| 39 | |
| 40 | /* |
| 41 | * constants related to atom buffer sizes and growth. |
| 42 | */ |
| 43 | static int sexp_val_start_sizecxx . . $ sexp_val_start_size. = 256; |
| 44 | static int sexp_val_grow_sizecxx . . $ sexp_val_grow_size. = 64; |
| 45 | |
| 46 | /* |
| 47 | * Function for tuning growth parameters. |
| 48 | */ |
| 49 | void set_parser_buffer_paramscxx . . $ set_parser_buffer_params(3e454b8ccf442868).(int ss, int gs) { |
| 50 | if (ss > 0) |
| 51 | sexp_val_start_sizecxx . . $ sexp_val_start_size. = ss; |
| 52 | else |
| 53 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"PARSER.C: Cannot set buffer start size to a value<1.\n"); |
| 54 | |
| 55 | if (gs > 0) |
| 56 | sexp_val_grow_sizecxx . . $ sexp_val_grow_size. = gs; |
| 57 | else |
| 58 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"PARSER.C: Cannot set buffer grow size to a value<1.\n"); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * this structure is pushed onto the stack so we can keep track of the |
| 63 | * first and last elements in a list. |
| 64 | * !!!!DON'T USE THESE OUTSIDE THIS FILE!!! |
| 65 | */ |
| 66 | typedef struct parse_stack_datacxx . . $ parse_stack_data# |
| 67 | { |
| 68 | sexp_tcxx . . $ sexp_t# *fstcxx . . $ parse_stack_data#fst., *lstcxx . . $ parse_stack_data#lst.; |
| 69 | } |
| 70 | parse_data_tcxx . . $ parse_data_t#; |
| 71 | |
| 72 | /** |
| 73 | * parse_data_t stack - similar malloc prevention to sexp_t_cache. |
| 74 | */ |
| 75 | faststack_tcxx . . $ faststack_t# *pd_cachecxx . . $ pd_cache.; |
| 76 | |
| 77 | /** |
| 78 | * The global <I>sexp_t_cache</I> is a faststack implementing a cache of |
| 79 | * pre-alloced s-expression element entities. Odds are a user should never |
| 80 | * touch this. If you do, you're on your own. This is used internally by |
| 81 | * the parser and related code to store unused but allocated sexp_t elements. |
| 82 | * This should be left alone and manipulated only by the sexp_t_allocate and |
| 83 | * sexp_t_deallocate functions. Touching the stack is bad. |
| 84 | */ |
| 85 | faststack_tcxx . . $ faststack_t# *sexp_t_cachecxx . . $ sexp_t_cache.; |
| 86 | |
| 87 | /** |
| 88 | * sexp_t allocation |
| 89 | */ |
| 90 | #ifdef _NO_MEMORY_MANAGEMENT_ |
| 91 | sexp_t * |
| 92 | sexp_t_allocate() { |
| 93 | sexp_t *sx = (sexp_t *) calloc(1, sizeof(sexp_t)); |
| 94 | assert(sx != NULL); |
| 95 | return(sx); |
| 96 | } |
| 97 | #else |
| 98 | sexp_tcxx . . $ sexp_t# * |
| 99 | sexp_t_allocatecxx . . $ sexp_t_allocate(99317b48064593fe).() { |
| 100 | sexp_tcxx . . $ sexp_t# *sx; |
| 101 | stack_lvl_tcxx . . $ stack_lvl_t# *l; |
| 102 | |
| 103 | if (sexp_t_cachecxx . . $ sexp_t_cache. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 104 | sexp_t_cachecxx . . $ sexp_t_cache. = make_stackcxx . . $ make_stack(1c8f112e2b573392).(); |
| 105 | sx = (sexp_tcxx . . $ sexp_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(sexp_tcxx . . $ sexp_t#)); |
| 106 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 107 | sx->nextcxx . . $ elt#next. = sx->listcxx . . $ elt#list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 108 | } else { |
| 109 | if (empty_stackcxx . . $ `src/sexpr/faststack.h:141:9`!(sexp_t_cache)) { |
| 110 | sx = (sexp_tcxx . . $ sexp_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(sexp_tcxx . . $ sexp_t#)); |
| 111 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 112 | sx->nextcxx . . $ elt#next. = sx->listcxx . . $ elt#list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 113 | } else { |
| 114 | l = popcxx . . $ pop(9a0813c18f9d6a07).(sexp_t_cachecxx . . $ sexp_t_cache.); |
| 115 | sx = (sexp_tcxx . . $ sexp_t# *)l->datacxx . . $ stack_level#data.; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | return sx; |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | /** |
| 124 | * sexp_t de-allocation |
| 125 | */ |
| 126 | #ifdef _NO_MEMORY_MANAGEMENT_ |
| 127 | void |
| 128 | sexp_t_deallocate(sexp_t *s) { |
| 129 | /* free(s);*/ |
| 130 | } |
| 131 | #else |
| 132 | void |
| 133 | sexp_t_deallocatecxx . . $ sexp_t_deallocate(7420e001cc8f68ca).(sexp_tcxx . . $ sexp_t# *s) { |
| 134 | if (sexp_t_cachecxx . . $ sexp_t_cache. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) sexp_t_cachecxx . . $ sexp_t_cache. = make_stackcxx . . $ make_stack(1c8f112e2b573392).(); |
| 135 | |
| 136 | s->listcxx . . $ elt#list. = s->nextcxx . . $ elt#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 137 | sexp_t_cachecxx . . $ sexp_t_cache. = pushcxx . . $ push(7d506e2a0f2f01b7).(sexp_t_cachecxx . . $ sexp_t_cache., s); |
| 138 | } |
| 139 | #endif |
| 140 | |
| 141 | /** |
| 142 | * cleanup the sexp library. Note this is implemented HERE since we need |
| 143 | * to know about pd_cache, which is local to this file. |
| 144 | */ |
| 145 | #ifdef _NO_MEMORY_MANAGEMENT_ |
| 146 | void sexp_cleanup() { |
| 147 | } |
| 148 | #else |
| 149 | void sexp_cleanupcxx . . $ sexp_cleanup(d878ad36e69247c7).() { |
| 150 | stack_lvl_tcxx . . $ stack_lvl_t# *l; |
| 151 | |
| 152 | if (pd_cachecxx . . $ pd_cache. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 153 | l = pd_cachecxx . . $ pd_cache.->topcxx . . $ stack_wrapper#top.; |
| 154 | while (l != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 155 | freecxx . . $ free(5d22bdacc48458e8).(l->datacxx . . $ stack_level#data.); |
| 156 | l = l->belowcxx . . $ stack_level#below.; |
| 157 | } |
| 158 | destroy_stackcxx . . $ destroy_stack(9dbdd0cf8baf323b).(pd_cachecxx . . $ pd_cache.); |
| 159 | pd_cachecxx . . $ pd_cache. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 160 | } |
| 161 | |
| 162 | if (sexp_t_cachecxx . . $ sexp_t_cache. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 163 | l = sexp_t_cachecxx . . $ sexp_t_cache.->topcxx . . $ stack_wrapper#top.; |
| 164 | while (l != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 165 | freecxx . . $ free(5d22bdacc48458e8).(l->datacxx . . $ stack_level#data.); |
| 166 | l = l->belowcxx . . $ stack_level#below.; |
| 167 | } |
| 168 | destroy_stackcxx . . $ destroy_stack(9dbdd0cf8baf323b).(sexp_t_cachecxx . . $ sexp_t_cache.); |
| 169 | sexp_t_cachecxx . . $ sexp_t_cache. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 170 | } |
| 171 | } |
| 172 | #endif |
| 173 | |
| 174 | /** |
| 175 | * allocation |
| 176 | */ |
| 177 | parse_data_tcxx . . $ parse_data_t# * |
| 178 | pd_allocatecxx . . $ pd_allocate(eb637da6c6031bbf).() { |
| 179 | parse_data_tcxx . . $ parse_data_t# *p; |
| 180 | stack_lvl_tcxx . . $ stack_lvl_t# *l; |
| 181 | |
| 182 | if (pd_cachecxx . . $ pd_cache. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 183 | pd_cachecxx . . $ pd_cache. = make_stackcxx . . $ make_stack(1c8f112e2b573392).(); |
| 184 | p = (parse_data_tcxx . . $ parse_data_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(parse_data_tcxx . . $ parse_data_t#)); |
| 185 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(p!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 186 | } else { |
| 187 | if (empty_stackcxx . . $ `src/sexpr/faststack.h:141:9`!(pd_cache)) { |
| 188 | p = (parse_data_tcxx . . $ parse_data_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(parse_data_tcxx . . $ parse_data_t#)); |
| 189 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(p!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 190 | } else { |
| 191 | l = popcxx . . $ pop(9a0813c18f9d6a07).(pd_cachecxx . . $ pd_cache.); |
| 192 | p = (parse_data_tcxx . . $ parse_data_t# *)l->datacxx . . $ stack_level#data.; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return p; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * de-allocation |
| 201 | */ |
| 202 | void |
| 203 | pd_deallocatecxx . . $ pd_deallocate(a43a35238b772380).(parse_data_tcxx . . $ parse_data_t# *p) { |
| 204 | if (pd_cachecxx . . $ pd_cache. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) pd_cachecxx . . $ pd_cache. = make_stackcxx . . $ make_stack(1c8f112e2b573392).(); |
| 205 | |
| 206 | pd_cachecxx . . $ pd_cache. = pushcxx . . $ push(7d506e2a0f2f01b7).(pd_cachecxx . . $ pd_cache., p); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Destroy a continuation by freeing all of its fields that it is responsible |
| 211 | * for managing, and then free the continuation itself. This includes internal |
| 212 | * buffers, stacks, etc.. |
| 213 | */ |
| 214 | void |
| 215 | destroy_continuationcxx . . $ destroy_continuation(4ab61756d5c8fbe4). (pcont_tcxx . . $ pcont_t# * pc) |
| 216 | { |
| 217 | stack_lvl_tcxx . . $ stack_lvl_t# *lvl; |
| 218 | parse_data_tcxx . . $ parse_data_t# *lvl_data; |
| 219 | |
| 220 | if (pc == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return; /* return if null passed in */ |
| 221 | |
| 222 | if (pc->stackcxx . . $ pcont#stack. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 223 | lvl = pc->stackcxx . . $ pcont#stack.->topcxx . . $ stack_wrapper#top.; |
| 224 | |
| 225 | /* |
| 226 | * note that destroy_stack() does not free the data hanging off of the |
| 227 | * stack. we have to walk down the stack and do that here. |
| 228 | */ |
| 229 | |
| 230 | while (lvl != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 231 | lvl_data = (parse_data_tcxx . . $ parse_data_t# *)lvl->datacxx . . $ stack_level#data.; |
| 232 | |
| 233 | /** |
| 234 | * Seems to have fixed bug with destroying partially parsed |
| 235 | * expression continuations with the short three lines below. |
| 236 | */ |
| 237 | if (lvl_data != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 238 | lvl_data->lstcxx . . $ parse_stack_data#lst. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 239 | destroy_sexpcxx . . $ destroy_sexp(7420e001cc8f68ca).(lvl_data->fstcxx . . $ parse_stack_data#fst.); |
| 240 | lvl_data->fstcxx . . $ parse_stack_data#fst. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 241 | |
| 242 | /* free(lvl_data); */ |
| 243 | pd_deallocatecxx . . $ pd_deallocate(a43a35238b772380).(lvl_data); |
| 244 | lvl->datacxx . . $ stack_level#data. = lvl_data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 245 | } |
| 246 | |
| 247 | lvl = lvl->belowcxx . . $ stack_level#below.; |
| 248 | } |
| 249 | |
| 250 | // |
| 251 | // stack has no data on it anymore, so we can free it. |
| 252 | // |
| 253 | destroy_stackcxx . . $ destroy_stack(9dbdd0cf8baf323b).(pc->stackcxx . . $ pcont#stack.); |
| 254 | pc->stackcxx . . $ pcont#stack. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 255 | } |
| 256 | |
| 257 | // |
| 258 | // free up other allocated data |
| 259 | // |
| 260 | freecxx . . $ free(5d22bdacc48458e8). (pc->valcxx . . $ pcont#val.); |
| 261 | freecxx . . $ free(5d22bdacc48458e8). (pc); |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * wrapper around cparse_sexp. assumes s contains a single, complete, |
| 266 | * null terminated s-expression. partial sexps or strings containing more |
| 267 | * than one will act up. |
| 268 | */ |
| 269 | sexp_tcxx . . $ sexp_t# * |
| 270 | parse_sexpcxx . . $ parse_sexp(27d8bd52a6d96499). (char *s, int len) |
| 271 | { |
| 272 | pcont_tcxx . . $ pcont_t# *pc = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 273 | sexp_tcxx . . $ sexp_t# *sx = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 274 | |
| 275 | pc = cparse_sexpcxx . . $ cparse_sexp(a78678ab65c90ce8). (s, len, pc); |
| 276 | sx = pc->last_sexpcxx . . $ pcont#last_sexp.; |
| 277 | |
| 278 | destroy_continuationcxx . . $ destroy_continuation(4ab61756d5c8fbe4).(pc); |
| 279 | |
| 280 | return sx; |
| 281 | } |
| 282 | |
| 283 | pcont_tcxx . . $ pcont_t# * |
| 284 | init_continuationcxx . . $ init_continuation(95d626482290b376).(char *str) |
| 285 | { |
| 286 | pcont_tcxx . . $ pcont_t# *cc; |
| 287 | /* new continuation... */ |
| 288 | cc = (pcont_tcxx . . $ pcont_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(pcont_tcxx . . $ pcont_t#)); |
| 289 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cc != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 290 | |
| 291 | /* allocate atom buffer */ |
| 292 | cc->valcxx . . $ pcont#val. = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(char)*sexp_val_start_sizecxx . . $ sexp_val_start_size.); |
| 293 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cc->val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 294 | |
| 295 | cc->val_allocatedcxx . . $ pcont#val_allocated. = sexp_val_start_sizecxx . . $ sexp_val_start_size.; |
| 296 | cc->val_usedcxx . . $ pcont#val_used. = 0; |
| 297 | |
| 298 | /* allocate stack */ |
| 299 | cc->esccxx . . $ pcont#esc. = 0; |
| 300 | cc->stackcxx . . $ pcont#stack. = make_stackcxx . . $ make_stack(1c8f112e2b573392).(); |
| 301 | cc->sbuffercxx . . $ pcont#sbuffer. = str; |
| 302 | cc->lastPoscxx . . $ pcont#lastPos. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 303 | cc->statecxx . . $ pcont#state. = 1; |
| 304 | cc->vcurcxx . . $ pcont#vcur. = cc->valcxx . . $ pcont#val.; |
| 305 | cc->depthcxx . . $ pcont#depth. = 0; |
| 306 | cc->qdepthcxx . . $ pcont#qdepth. = 0; |
| 307 | |
| 308 | return cc; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Iterative parser. Wrapper around parse_sexp that is slightly more |
| 313 | * intelligent and allows users to iteratively "pop" the expressions |
| 314 | * out of a string that contains a bunch of expressions. |
| 315 | * Useful if you have a string like "(foo bar)(goo har)(moo mar)" and |
| 316 | * want to get "(foo bar)", "(goo har)", and "(moo mar)" individually on |
| 317 | * repeated calls. |
| 318 | */ |
| 319 | sexp_tcxx . . $ sexp_t# * |
| 320 | iparse_sexpcxx . . $ iparse_sexp(81661097bb59bdf4). (char *s, int len, pcont_tcxx . . $ pcont_t# *cc) { |
| 321 | pcont_tcxx . . $ pcont_t# *pc; |
| 322 | sexp_tcxx . . $ sexp_t# *sx = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 323 | |
| 324 | /* |
| 325 | * sanity check. |
| 326 | */ |
| 327 | if (cc == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 328 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"iparse_sexp called with null continuation!\n"); |
| 329 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 330 | } |
| 331 | |
| 332 | /* call the parser */ |
| 333 | pc = cparse_sexpcxx . . $ cparse_sexp(a78678ab65c90ce8).(s,len,cc); |
| 334 | |
| 335 | if (cc->last_sexpcxx . . $ pcont#last_sexp. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 336 | sx = cc->last_sexpcxx . . $ pcont#last_sexp.; |
| 337 | cc->last_sexpcxx . . $ pcont#last_sexp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 338 | } |
| 339 | |
| 340 | return sx; |
| 341 | } |
| 342 | |
| 343 | /*************************************************************************/ |
| 344 | /*************************************************************************/ |
| 345 | /*************************************************************************/ |
| 346 | /*************************************************************************/ |
| 347 | /*************************************************************************/ |
| 348 | |
| 349 | /** |
| 350 | * Continuation based parser - the guts of the package. |
| 351 | */ |
| 352 | pcont_tcxx . . $ pcont_t# * |
| 353 | cparse_sexpcxx . . $ cparse_sexp(a78678ab65c90ce8). (char *str, int len, pcont_tcxx . . $ pcont_t# *lc) |
| 354 | { |
| 355 | char *t, *s; |
| 356 | register unsigned int val_allocated = 0; |
| 357 | register unsigned int val_used = 0; |
| 358 | register unsigned int state = 1; |
| 359 | register unsigned int depth = 0; |
| 360 | register unsigned int qdepth = 0; |
| 361 | register unsigned int elts = 0; |
| 362 | register unsigned int esc = 0; |
| 363 | pcont_tcxx . . $ pcont_t# *cc; |
| 364 | char *val, *vcur; |
| 365 | sexp_tcxx . . $ sexp_t# *sx = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 366 | faststack_tcxx . . $ faststack_t# *stack; |
| 367 | parse_data_tcxx . . $ parse_data_t# *data; |
| 368 | stack_lvl_tcxx . . $ stack_lvl_t# *lvl; |
| 369 | #ifdef _DEBUG_ |
| 370 | unsigned long fsm_iterations = 0; |
| 371 | unsigned long maxdepth = 0; |
| 372 | #endif /* _DEBUG_ */ |
| 373 | char *bufEnd; |
| 374 | |
| 375 | /* make sure non-null string */ |
| 376 | if (str == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 377 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"cparse_sexp: called with null string.\n"); |
| 378 | return lc; |
| 379 | } |
| 380 | |
| 381 | /* first, if we have a non null continuation passed in, restore state. */ |
| 382 | if (lc != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 383 | cc = lc; |
| 384 | val_used = cc->val_usedcxx . . $ pcont#val_used.; |
| 385 | val_allocated = cc->val_allocatedcxx . . $ pcont#val_allocated.; |
| 386 | val = cc->valcxx . . $ pcont#val.; |
| 387 | vcur = cc->vcurcxx . . $ pcont#vcur.; |
| 388 | state = cc->statecxx . . $ pcont#state.; |
| 389 | depth = cc->depthcxx . . $ pcont#depth.; |
| 390 | qdepth = cc->qdepthcxx . . $ pcont#qdepth.; |
| 391 | stack = cc->stackcxx . . $ pcont#stack.; |
| 392 | esc = cc->esccxx . . $ pcont#esc.; |
| 393 | s = str; |
| 394 | if (cc->lastPoscxx . . $ pcont#lastPos. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 395 | t = cc->lastPoscxx . . $ pcont#lastPos.; |
| 396 | else { |
| 397 | t = s; |
| 398 | cc->sbuffercxx . . $ pcont#sbuffer. = str; |
| 399 | } |
| 400 | } else { |
| 401 | /* new continuation... */ |
| 402 | cc = (pcont_tcxx . . $ pcont_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(pcont_tcxx . . $ pcont_t#)); |
| 403 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cc != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 404 | |
| 405 | /* allocate atom buffer */ |
| 406 | cc->valcxx . . $ pcont#val. = val = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(char)*sexp_val_start_sizecxx . . $ sexp_val_start_size.); |
| 407 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 408 | |
| 409 | cc->val_usedcxx . . $ pcont#val_used. = val_used = 0; |
| 410 | cc->val_allocatedcxx . . $ pcont#val_allocated. = val_allocated = sexp_val_start_sizecxx . . $ sexp_val_start_size.; |
| 411 | |
| 412 | vcur = val; |
| 413 | |
| 414 | /* allocate stack */ |
| 415 | cc->stackcxx . . $ pcont#stack. = stack = make_stackcxx . . $ make_stack(1c8f112e2b573392).(); |
| 416 | |
| 417 | /* t is temp pointer into s for current position */ |
| 418 | s = str; |
| 419 | t = s; |
| 420 | cc->sbuffercxx . . $ pcont#sbuffer. = str; |
| 421 | } |
| 422 | |
| 423 | bufEnd = cc->sbuffercxx . . $ pcont#sbuffer.+len; |
| 424 | |
| 425 | /*==================*/ |
| 426 | /* main parser loop */ |
| 427 | /*==================*/ |
| 428 | while (t[0] != '\0' && t != bufEnd) |
| 429 | { |
| 430 | #ifdef _DEBUG_ |
| 431 | printf("PARSER: STATE=%d CURCHAR=%c (0x%x)\n",state,t[0],t); |
| 432 | printf(" VAL_ALLOCATED=%d VAL_USED=%d\n",val_allocated,val_used); |
| 433 | fsm_iterations++; |
| 434 | #endif |
| 435 | |
| 436 | /* based on the current state in the FSM, do something */ |
| 437 | switch (state) |
| 438 | { |
| 439 | case 1: |
| 440 | switch (t[0]) |
| 441 | { |
| 442 | /* space,tab,CR,LF considered white space */ |
| 443 | case '\n': |
| 444 | case ' ': |
| 445 | case '\t': |
| 446 | case '\r': |
| 447 | t++; |
| 448 | break; |
| 449 | /* semicolon starts a comment that extends until a \n is |
| 450 | encountered. */ |
| 451 | case ';': |
| 452 | t++; |
| 453 | state = 11; |
| 454 | break; |
| 455 | /* enter state 2 for open paren */ |
| 456 | case '(': |
| 457 | state = 2; |
| 458 | t++; |
| 459 | break; |
| 460 | /* enter state 3 for close paran */ |
| 461 | case ')': |
| 462 | state = 3; |
| 463 | break; |
| 464 | /* begin quoted string - enter state 5 */ |
| 465 | case '\"': |
| 466 | state = 5; |
| 467 | /* set cur pointer to beginning of val buffer */ |
| 468 | vcur = val; |
| 469 | t++; |
| 470 | break; |
| 471 | /* single quote - enter state 7 */ |
| 472 | case '\'': |
| 473 | state = 7; |
| 474 | t++; |
| 475 | break; |
| 476 | /* other characters are assumed to be atom parts */ |
| 477 | default: |
| 478 | /* set cur pointer to beginning of val buffer */ |
| 479 | vcur = val; |
| 480 | |
| 481 | /** NOTE: the following code originally required a transition |
| 482 | to state 4 before processing the first atom character -- |
| 483 | this required two iterations for the first character |
| 484 | of each atom. merging this into here allows us to process |
| 485 | what we already know to be a valid atom character before |
| 486 | entering state 4. **/ |
| 487 | vcur[0] = t[0]; |
| 488 | if (t[0] == '\\') esc = 1; |
| 489 | else esc = 0; |
| 490 | val_used++; |
| 491 | |
| 492 | if (val_used == val_allocated) { |
| 493 | val = (char *)realloccxx . . $ realloc(417ab160f6baadc6).(val,val_allocated+sexp_val_grow_sizecxx . . $ sexp_val_grow_size.); |
| 494 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 495 | vcur = val + val_used; |
| 496 | val_allocated += sexp_val_grow_sizecxx . . $ sexp_val_grow_size.; |
| 497 | } else vcur++; |
| 498 | |
| 499 | t++; |
| 500 | |
| 501 | /* enter state 4 */ |
| 502 | state = 4; |
| 503 | break; |
| 504 | } |
| 505 | break; |
| 506 | case 2: |
| 507 | /* open paren */ |
| 508 | depth++; |
| 509 | /* sx = (sexp_t *) malloc (sizeof (sexp_t)); */ |
| 510 | sx = sexp_t_allocatecxx . . $ sexp_t_allocate(99317b48064593fe).(); |
| 511 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sx!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 512 | elts++; |
| 513 | sx->tycxx . . $ elt#ty. = SEXP_LISTcxx . . $ SEXP_LIST.; |
| 514 | sx->nextcxx . . $ elt#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 515 | sx->listcxx . . $ elt#list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 516 | |
| 517 | if (stack->heightcxx . . $ stack_wrapper#height. < 1) |
| 518 | { |
| 519 | /* data = (parse_data_t *) malloc (sizeof (parse_data_t)); */ |
| 520 | data = pd_allocatecxx . . $ pd_allocate(eb637da6c6031bbf).(); |
| 521 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(data!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 522 | data->fstcxx . . $ parse_stack_data#fst. = data->lstcxx . . $ parse_stack_data#lst. = sx; |
| 523 | pushcxx . . $ push(7d506e2a0f2f01b7). (stack, data); |
| 524 | } |
| 525 | else |
| 526 | { |
| 527 | data = (parse_data_tcxx . . $ parse_data_t# *) top_datacxx . . $ `src/sexpr/faststack.h:135:9`! (stack); |
| 528 | if (data->lstcxx . . $ parse_stack_data#lst. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 529 | data->lstcxx . . $ parse_stack_data#lst.->nextcxx . . $ elt#next. = sx; |
| 530 | else |
| 531 | data->fstcxx . . $ parse_stack_data#fst. = sx; |
| 532 | data->lstcxx . . $ parse_stack_data#lst. = sx; |
| 533 | } |
| 534 | |
| 535 | /* data = (parse_data_t *) malloc (sizeof (parse_data_t)); */ |
| 536 | data = pd_allocatecxx . . $ pd_allocate(eb637da6c6031bbf).(); |
| 537 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(data!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 538 | data->fstcxx . . $ parse_stack_data#fst. = data->lstcxx . . $ parse_stack_data#lst. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 539 | pushcxx . . $ push(7d506e2a0f2f01b7). (stack, data); |
| 540 | |
| 541 | state = 1; |
| 542 | break; |
| 543 | case 3: |
| 544 | /** close paren **/ |
| 545 | #ifdef _DEBUG_ |
| 546 | if (depth > maxdepth) maxdepth = depth; |
| 547 | #endif /* _DEBUG_ */ |
| 548 | |
| 549 | /* check for close parens that were never opened. */ |
| 550 | if (depth == 0) { |
| 551 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Badly formed s-expression. Parser exiting.\n"); |
| 552 | cc->valcxx . . $ pcont#val. = val; |
| 553 | cc->val_usedcxx . . $ pcont#val_used. = val_used; |
| 554 | cc->val_allocatedcxx . . $ pcont#val_allocated. = val_allocated; |
| 555 | cc->vcurcxx . . $ pcont#vcur. = vcur; |
| 556 | cc->lastPoscxx . . $ pcont#lastPos. = t; |
| 557 | cc->depthcxx . . $ pcont#depth. = depth; |
| 558 | cc->qdepthcxx . . $ pcont#qdepth. = qdepth; |
| 559 | cc->statecxx . . $ pcont#state. = 1; |
| 560 | cc->stackcxx . . $ pcont#stack. = stack; |
| 561 | cc->esccxx . . $ pcont#esc. = 0; |
| 562 | cc->last_sexpcxx . . $ pcont#last_sexp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 563 | cc->errorcxx . . $ pcont#error. = 1; |
| 564 | |
| 565 | #ifdef _DEBUG_ |
| 566 | fprintf(stderr,"State Machine Iterations: %d\nMaxdepth: %d\n", |
| 567 | fsm_iterations,maxdepth); |
| 568 | #endif /* debug */ |
| 569 | |
| 570 | return cc; |
| 571 | } |
| 572 | |
| 573 | t++; |
| 574 | depth--; |
| 575 | |
| 576 | lvl = popcxx . . $ pop(9a0813c18f9d6a07). (stack); |
| 577 | data = (parse_data_tcxx . . $ parse_data_t# *) lvl->datacxx . . $ stack_level#data.; |
| 578 | sx = data->fstcxx . . $ parse_stack_data#fst.; |
| 579 | /* free (data); */ |
| 580 | pd_deallocatecxx . . $ pd_deallocate(a43a35238b772380).(data); |
| 581 | lvl->datacxx . . $ stack_level#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 582 | |
| 583 | if (stack->topcxx . . $ stack_wrapper#top. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 584 | { |
| 585 | data = (parse_data_tcxx . . $ parse_data_t# *) top_datacxx . . $ `src/sexpr/faststack.h:135:9`! (stack); |
| 586 | data->lstcxx . . $ parse_stack_data#lst.->listcxx . . $ elt#list. = sx; |
| 587 | } |
| 588 | else |
| 589 | { |
| 590 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Hmmm. Stack->top is null.\n"); |
| 591 | } |
| 592 | |
| 593 | state = 1; |
| 594 | |
| 595 | /** if depth = 0 then we finished a sexpr, and we return **/ |
| 596 | if (depth == 0) { |
| 597 | cc->errorcxx . . $ pcont#error. = 0; |
| 598 | cc->valcxx . . $ pcont#val. = val; |
| 599 | cc->val_allocatedcxx . . $ pcont#val_allocated. = val_allocated; |
| 600 | cc->val_usedcxx . . $ pcont#val_used. = val_used; |
| 601 | cc->vcurcxx . . $ pcont#vcur. = vcur; |
| 602 | cc->lastPoscxx . . $ pcont#lastPos. = t; |
| 603 | cc->depthcxx . . $ pcont#depth. = depth; |
| 604 | cc->qdepthcxx . . $ pcont#qdepth. = qdepth; |
| 605 | cc->statecxx . . $ pcont#state. = 1; |
| 606 | cc->stackcxx . . $ pcont#stack. = stack; |
| 607 | cc->esccxx . . $ pcont#esc. = 0; |
| 608 | while (stack->topcxx . . $ stack_wrapper#top. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 609 | { |
| 610 | lvl = popcxx . . $ pop(9a0813c18f9d6a07). (stack); |
| 611 | data = (parse_data_tcxx . . $ parse_data_t# *) lvl->datacxx . . $ stack_level#data.; |
| 612 | sx = data->fstcxx . . $ parse_stack_data#fst.; |
| 613 | /* free (data); */ |
| 614 | pd_deallocatecxx . . $ pd_deallocate(a43a35238b772380).(data); |
| 615 | lvl->datacxx . . $ stack_level#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 616 | } |
| 617 | cc->last_sexpcxx . . $ pcont#last_sexp. = sx; |
| 618 | |
| 619 | #ifdef _DEBUG_ |
| 620 | fprintf(stderr,"State Machine Iterations: %d\nMaxdepth: %d\n", |
| 621 | fsm_iterations,maxdepth); |
| 622 | #endif /* debug */ |
| 623 | |
| 624 | return cc; |
| 625 | } |
| 626 | break; |
| 627 | case 4: /** parsing atom **/ |
| 628 | if (esc == 1 && (t[0] == '\"' || t[0] == '(' || |
| 629 | t[0] == ')' || t[0] == '\'' || |
| 630 | t[0] == '\\')) { |
| 631 | vcur--; /* back up to overwrite the \ */ |
| 632 | vcur[0] = t[0]; |
| 633 | vcur++; |
| 634 | t++; |
| 635 | esc = 0; |
| 636 | break; |
| 637 | } |
| 638 | |
| 639 | /* look at an ascii table - these ranges are the non-whitespace, non |
| 640 | paren and quote characters that are legal in atoms */ |
| 641 | if (!((t[0] >= '*' && t[0] <= '~') || |
| 642 | ((unsigned char)(t[0]) > 127) || |
| 643 | (t[0] == '!') || |
| 644 | (t[0] >= '#' && t[0] <= '&'))) |
| 645 | { |
| 646 | vcur[0] = '\0'; |
| 647 | val_used++; |
| 648 | |
| 649 | sx = sexp_t_allocatecxx . . $ sexp_t_allocate(99317b48064593fe).(); |
| 650 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sx!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 651 | elts++; |
| 652 | sx->tycxx . . $ elt#ty. = SEXP_VALUEcxx . . $ SEXP_VALUE.; |
| 653 | sx->valcxx . . $ elt#val. = val; |
| 654 | sx->val_allocatedcxx . . $ elt#val_allocated. = val_allocated; |
| 655 | sx->val_usedcxx . . $ elt#val_used. = val_used; |
| 656 | sx->nextcxx . . $ elt#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 657 | sx->atycxx . . $ elt#aty. = SEXP_BASICcxx . . $ SEXP_BASIC.; |
| 658 | |
| 659 | val = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(char)*sexp_val_start_sizecxx . . $ sexp_val_start_size.); |
| 660 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 661 | val_allocated = sexp_val_start_sizecxx . . $ sexp_val_start_size.; |
| 662 | val_used = 0; |
| 663 | vcur = val; |
| 664 | |
| 665 | if (!empty_stackcxx . . $ `src/sexpr/faststack.h:141:9`! (stack)) |
| 666 | { |
| 667 | data = (parse_data_tcxx . . $ parse_data_t# *) top_datacxx . . $ `src/sexpr/faststack.h:135:9`! (stack); |
| 668 | if (data->fstcxx . . $ parse_stack_data#fst. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 669 | { |
| 670 | data->fstcxx . . $ parse_stack_data#fst. = data->lstcxx . . $ parse_stack_data#lst. = sx; |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | data->lstcxx . . $ parse_stack_data#lst.->nextcxx . . $ elt#next. = sx; |
| 675 | data->lstcxx . . $ parse_stack_data#lst. = sx; |
| 676 | } |
| 677 | } |
| 678 | else |
| 679 | { |
| 680 | /* looks like this expression was just a basic atom - so |
| 681 | return it. */ |
| 682 | cc->errorcxx . . $ pcont#error. = 0; |
| 683 | cc->valcxx . . $ pcont#val. = val; |
| 684 | cc->val_usedcxx . . $ pcont#val_used. = val_used; |
| 685 | cc->val_allocatedcxx . . $ pcont#val_allocated. = val_allocated; |
| 686 | cc->vcurcxx . . $ pcont#vcur. = vcur; |
| 687 | cc->lastPoscxx . . $ pcont#lastPos. = t; |
| 688 | cc->depthcxx . . $ pcont#depth. = depth; |
| 689 | cc->qdepthcxx . . $ pcont#qdepth. = qdepth; |
| 690 | cc->statecxx . . $ pcont#state. = 1; |
| 691 | cc->stackcxx . . $ pcont#stack. = stack; |
| 692 | cc->esccxx . . $ pcont#esc. = 0; |
| 693 | cc->last_sexpcxx . . $ pcont#last_sexp. = sx; |
| 694 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 695 | |
| 696 | return cc; |
| 697 | } |
| 698 | |
| 699 | switch (t[0]) { |
| 700 | case ' ': |
| 701 | case '\t': |
| 702 | case '\n': |
| 703 | case '\r': |
| 704 | /** NOTE: we know whitespace following atom, so spin ahead |
| 705 | one and let state 1 do what it needs to for the next |
| 706 | character. **/ |
| 707 | state = 1; |
| 708 | t++; |
| 709 | break; |
| 710 | case ')': |
| 711 | state = 3; |
| 712 | break; |
| 713 | default: |
| 714 | state = 1; |
| 715 | } |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | vcur[0] = t[0]; |
| 720 | if (t[0] == '\\') esc = 1; |
| 721 | else esc = 0; |
| 722 | val_used++; |
| 723 | |
| 724 | if (val_used == val_allocated) { |
| 725 | val = (char *)realloccxx . . $ realloc(417ab160f6baadc6).(val,val_allocated+sexp_val_grow_sizecxx . . $ sexp_val_grow_size.); |
| 726 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 727 | vcur = val + val_used; |
| 728 | val_allocated += sexp_val_grow_sizecxx . . $ sexp_val_grow_size.; |
| 729 | } else vcur++; |
| 730 | |
| 731 | t++; |
| 732 | } |
| 733 | break; |
| 734 | case 5: |
| 735 | if (esc == 1 && (t[0] == '\"' || |
| 736 | t[0] == '\'' || |
| 737 | t[0] == '(' || |
| 738 | t[0] == ')' || |
| 739 | t[0] == '\\')) { |
| 740 | vcur--; |
| 741 | vcur[0] = t[0]; |
| 742 | vcur++; |
| 743 | /** NO NEED TO UPDATE VAL COUNTS **/ |
| 744 | t++; |
| 745 | esc = 0; |
| 746 | } |
| 747 | |
| 748 | if (t[0] == '\"') |
| 749 | { |
| 750 | state = 6; |
| 751 | vcur[0] = '\0'; |
| 752 | val_used++; |
| 753 | /* sx = (sexp_t *) malloc (sizeof (sexp_t)); */ |
| 754 | sx = sexp_t_allocatecxx . . $ sexp_t_allocate(99317b48064593fe).(); |
| 755 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sx!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 756 | elts++; |
| 757 | sx->tycxx . . $ elt#ty. = SEXP_VALUEcxx . . $ SEXP_VALUE.; |
| 758 | sx->valcxx . . $ elt#val. = val; |
| 759 | sx->val_usedcxx . . $ elt#val_used. = val_used; |
| 760 | sx->val_allocatedcxx . . $ elt#val_allocated. = val_allocated; |
| 761 | sx->nextcxx . . $ elt#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 762 | sx->atycxx . . $ elt#aty. = SEXP_DQUOTEcxx . . $ SEXP_DQUOTE.; |
| 763 | |
| 764 | val = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(char)*sexp_val_start_sizecxx . . $ sexp_val_start_size.); |
| 765 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 766 | val_allocated = sexp_val_start_sizecxx . . $ sexp_val_start_size.; |
| 767 | val_used = 0; |
| 768 | vcur = val; |
| 769 | |
| 770 | if (!empty_stackcxx . . $ `src/sexpr/faststack.h:141:9`! (stack)) |
| 771 | { |
| 772 | data = (parse_data_tcxx . . $ parse_data_t# *) top_datacxx . . $ `src/sexpr/faststack.h:135:9`! (stack); |
| 773 | if (data->fstcxx . . $ parse_stack_data#fst. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 774 | { |
| 775 | data->fstcxx . . $ parse_stack_data#fst. = data->lstcxx . . $ parse_stack_data#lst. = sx; |
| 776 | } |
| 777 | else |
| 778 | { |
| 779 | data->lstcxx . . $ parse_stack_data#lst.->nextcxx . . $ elt#next. = sx; |
| 780 | data->lstcxx . . $ parse_stack_data#lst. = sx; |
| 781 | } |
| 782 | } |
| 783 | else |
| 784 | { |
| 785 | /* looks like this expression was just a basic double |
| 786 | quoted atom - so return it. */ |
| 787 | t++; /* spin past the quote */ |
| 788 | |
| 789 | cc->errorcxx . . $ pcont#error. = 0; |
| 790 | cc->valcxx . . $ pcont#val. = val; |
| 791 | cc->val_usedcxx . . $ pcont#val_used. = val_used; |
| 792 | cc->val_allocatedcxx . . $ pcont#val_allocated. = val_allocated; |
| 793 | cc->vcurcxx . . $ pcont#vcur. = vcur; |
| 794 | cc->lastPoscxx . . $ pcont#lastPos. = t++; |
| 795 | cc->depthcxx . . $ pcont#depth. = depth; |
| 796 | cc->qdepthcxx . . $ pcont#qdepth. = qdepth; |
| 797 | cc->statecxx . . $ pcont#state. = 1; |
| 798 | cc->stackcxx . . $ pcont#stack. = stack; |
| 799 | cc->esccxx . . $ pcont#esc. = 0; |
| 800 | cc->last_sexpcxx . . $ pcont#last_sexp. = sx; |
| 801 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 802 | |
| 803 | return cc; |
| 804 | } |
| 805 | } |
| 806 | else |
| 807 | { |
| 808 | vcur[0] = t[0]; |
| 809 | val_used++; |
| 810 | |
| 811 | if (val_used == val_allocated) { |
| 812 | val = (char *)realloccxx . . $ realloc(417ab160f6baadc6).(val,val_allocated+sexp_val_grow_sizecxx . . $ sexp_val_grow_size.); |
| 813 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 814 | vcur = val + val_used; |
| 815 | val_allocated += sexp_val_grow_sizecxx . . $ sexp_val_grow_size.; |
| 816 | } else vcur++; |
| 817 | |
| 818 | if (t[0] == '\\') { |
| 819 | esc = 1; |
| 820 | } else |
| 821 | esc = 0; |
| 822 | } |
| 823 | t++; |
| 824 | break; |
| 825 | case 6: |
| 826 | vcur = val; |
| 827 | state = 1; |
| 828 | break; |
| 829 | case 7: |
| 830 | if (t[0] == '\"') |
| 831 | { |
| 832 | state = 5; |
| 833 | vcur = val; |
| 834 | } |
| 835 | else if (t[0] == '(') |
| 836 | { |
| 837 | vcur = val; |
| 838 | state = 8; |
| 839 | } |
| 840 | else |
| 841 | { |
| 842 | vcur = val; |
| 843 | state = 4; |
| 844 | } |
| 845 | break; |
| 846 | case 8: |
| 847 | if (esc == 0) { |
| 848 | if (t[0] == '(') |
| 849 | { |
| 850 | qdepth++; |
| 851 | } |
| 852 | else if (t[0] == ')') |
| 853 | { |
| 854 | qdepth--; |
| 855 | state = 9; |
| 856 | } |
| 857 | else if (t[0] == '\"') |
| 858 | { |
| 859 | state = 10; |
| 860 | } |
| 861 | } else { |
| 862 | esc = 0; |
| 863 | } |
| 864 | vcur[0] = t[0]; |
| 865 | if (t[0] == '\\') esc = 1; |
| 866 | else esc = 0; |
| 867 | val_used++; |
| 868 | |
| 869 | if (val_used == val_allocated) { |
| 870 | val = (char *)realloccxx . . $ realloc(417ab160f6baadc6).(val,val_allocated+sexp_val_grow_sizecxx . . $ sexp_val_grow_size.); |
| 871 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 872 | vcur = val + val_used; |
| 873 | val_allocated += sexp_val_grow_sizecxx . . $ sexp_val_grow_size.; |
| 874 | } else vcur++; |
| 875 | |
| 876 | t++; |
| 877 | /* let it fall through to state 9 if we know we're transitioning |
| 878 | into that state */ |
| 879 | if (state != 9) |
| 880 | break; |
| 881 | case 9: |
| 882 | if (qdepth == 0) |
| 883 | { |
| 884 | state = 1; |
| 885 | vcur[0] = '\0'; |
| 886 | /* sx = (sexp_t *) malloc (sizeof (sexp_t)); */ |
| 887 | sx = sexp_t_allocatecxx . . $ sexp_t_allocate(99317b48064593fe).(); |
| 888 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sx!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 889 | elts++; |
| 890 | sx->tycxx . . $ elt#ty. = SEXP_VALUEcxx . . $ SEXP_VALUE.; |
| 891 | sx->valcxx . . $ elt#val. = val; |
| 892 | sx->val_allocatedcxx . . $ elt#val_allocated. = val_allocated; |
| 893 | sx->val_usedcxx . . $ elt#val_used. = val_used; |
| 894 | sx->nextcxx . . $ elt#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 895 | sx->atycxx . . $ elt#aty. = SEXP_SQUOTEcxx . . $ SEXP_SQUOTE.; |
| 896 | |
| 897 | val = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(char)*sexp_val_start_sizecxx . . $ sexp_val_start_size.); |
| 898 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 899 | val_allocated = sexp_val_start_sizecxx . . $ sexp_val_start_size.; |
| 900 | val_used = 0; |
| 901 | vcur = val; |
| 902 | |
| 903 | if (!empty_stackcxx . . $ `src/sexpr/faststack.h:141:9`! (stack)) |
| 904 | { |
| 905 | data = (parse_data_tcxx . . $ parse_data_t# *) top_datacxx . . $ `src/sexpr/faststack.h:135:9`! (stack); |
| 906 | if (data->fstcxx . . $ parse_stack_data#fst. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 907 | { |
| 908 | data->fstcxx . . $ parse_stack_data#fst. = data->lstcxx . . $ parse_stack_data#lst. = sx; |
| 909 | } |
| 910 | else |
| 911 | { |
| 912 | data->lstcxx . . $ parse_stack_data#lst.->nextcxx . . $ elt#next. = sx; |
| 913 | data->lstcxx . . $ parse_stack_data#lst. = sx; |
| 914 | } |
| 915 | } |
| 916 | else |
| 917 | { |
| 918 | /* looks like the whole expression was a single |
| 919 | quoted value! So return it. */ |
| 920 | cc->errorcxx . . $ pcont#error. = 0; |
| 921 | cc->valcxx . . $ pcont#val. = val; |
| 922 | cc->val_usedcxx . . $ pcont#val_used. = val_used; |
| 923 | cc->val_allocatedcxx . . $ pcont#val_allocated. = val_allocated; |
| 924 | cc->vcurcxx . . $ pcont#vcur. = vcur; |
| 925 | cc->lastPoscxx . . $ pcont#lastPos. = t; |
| 926 | cc->depthcxx . . $ pcont#depth. = depth; |
| 927 | cc->qdepthcxx . . $ pcont#qdepth. = qdepth; |
| 928 | cc->statecxx . . $ pcont#state. = 1; |
| 929 | cc->stackcxx . . $ pcont#stack. = stack; |
| 930 | cc->esccxx . . $ pcont#esc. = 0; |
| 931 | cc->last_sexpcxx . . $ pcont#last_sexp. = sx; |
| 932 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sx != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 933 | |
| 934 | return cc; |
| 935 | } |
| 936 | } |
| 937 | else |
| 938 | state = 8; |
| 939 | break; |
| 940 | case 10: |
| 941 | if (t[0] == '\"' && esc == 0) |
| 942 | { |
| 943 | state = 8; |
| 944 | } |
| 945 | vcur[0] = t[0]; |
| 946 | if (t[0] == '\\') esc = 1; |
| 947 | else esc = 0; |
| 948 | val_used++; |
| 949 | |
| 950 | if (val_used == val_allocated) { |
| 951 | val = (char *)realloccxx . . $ realloc(417ab160f6baadc6).(val,val_allocated+sexp_val_grow_sizecxx . . $ sexp_val_grow_size.); |
| 952 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 953 | vcur = val + val_used; |
| 954 | val_allocated += sexp_val_grow_sizecxx . . $ sexp_val_grow_size.; |
| 955 | } else vcur++; |
| 956 | |
| 957 | t++; |
| 958 | break; |
| 959 | case 11: |
| 960 | if (t[0] == '\n') { |
| 961 | state = 1; |
| 962 | } |
| 963 | t++; |
| 964 | break; |
| 965 | default: |
| 966 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac). (stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Unknown parser state %d.\n", state); |
| 967 | break; |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | #ifdef _DEBUG_ |
| 972 | fprintf(stderr,"State Machine Iterations: %d\nMax Paren Depth: %d\n", |
| 973 | fsm_iterations, maxdepth); |
| 974 | #endif /* _DEBUG_ */ |
| 975 | |
| 976 | if (depth == 0 && elts > 0) { |
| 977 | cc->errorcxx . . $ pcont#error. = 0; |
| 978 | cc->valcxx . . $ pcont#val. = val; |
| 979 | cc->val_usedcxx . . $ pcont#val_used. = val_used; |
| 980 | cc->val_allocatedcxx . . $ pcont#val_allocated. = val_allocated; |
| 981 | cc->vcurcxx . . $ pcont#vcur. = vcur; |
| 982 | cc->lastPoscxx . . $ pcont#lastPos. = t; |
| 983 | cc->depthcxx . . $ pcont#depth. = depth; |
| 984 | cc->qdepthcxx . . $ pcont#qdepth. = qdepth; |
| 985 | cc->statecxx . . $ pcont#state. = 1; |
| 986 | cc->stackcxx . . $ pcont#stack. = stack; |
| 987 | cc->esccxx . . $ pcont#esc. = 0; |
| 988 | while (stack->topcxx . . $ stack_wrapper#top. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 989 | { |
| 990 | lvl = popcxx . . $ pop(9a0813c18f9d6a07). (stack); |
| 991 | data = (parse_data_tcxx . . $ parse_data_t# *) lvl->datacxx . . $ stack_level#data.; |
| 992 | sx = data->fstcxx . . $ parse_stack_data#fst.; |
| 993 | /* free (data); */ |
| 994 | pd_deallocatecxx . . $ pd_deallocate(a43a35238b772380).(data); |
| 995 | lvl->datacxx . . $ stack_level#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 996 | } |
| 997 | cc->last_sexpcxx . . $ pcont#last_sexp. = sx; |
| 998 | } else { |
| 999 | cc->valcxx . . $ pcont#val. = val; |
| 1000 | cc->esccxx . . $ pcont#esc. = esc; |
| 1001 | cc->vcurcxx . . $ pcont#vcur. = vcur; |
| 1002 | cc->val_allocatedcxx . . $ pcont#val_allocated. = val_allocated; |
| 1003 | cc->val_usedcxx . . $ pcont#val_used. = val_used; |
| 1004 | if (t[0] == '\0' || t == bufEnd) |
| 1005 | cc->lastPoscxx . . $ pcont#lastPos. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1006 | else |
| 1007 | cc->lastPoscxx . . $ pcont#lastPos. = t; |
| 1008 | cc->depthcxx . . $ pcont#depth. = depth; |
| 1009 | cc->qdepthcxx . . $ pcont#qdepth. = qdepth; |
| 1010 | cc->statecxx . . $ pcont#state. = state; |
| 1011 | cc->stackcxx . . $ pcont#stack. = stack; |
| 1012 | cc->last_sexpcxx . . $ pcont#last_sexp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1013 | cc->errorcxx . . $ pcont#error. = 0; |
| 1014 | } |
| 1015 | |
| 1016 | return cc; |
| 1017 | } |