| 1 | /* Foma: a finite-state toolkit and library. */cxx . . $ `<file>/apply.c`/ |
| 2 | /* Copyright © 2008-2021 Mans Hulden */ |
| 3 | |
| 4 | /* This file is part of foma. */ |
| 5 | |
| 6 | /* Licensed under the Apache License, Version 2.0 (the "License"); */ |
| 7 | /* you may not use this file except in compliance with the License. */ |
| 8 | /* You may obtain a copy of the License at */ |
| 9 | |
| 10 | /* http://www.apache.org/licenses/LICENSE-2.0 */ |
| 11 | |
| 12 | /* Unless required by applicable law or agreed to in writing, software */ |
| 13 | /* distributed under the License is distributed on an "AS IS" BASIS, */ |
| 14 | /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ |
| 15 | /* See the License for the specific language governing permissions and */ |
| 16 | /* limitations under the License. */ |
| 17 | |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <time.h> |
| 21 | #include <string.h> |
| 22 | #include <limits.h> |
| 23 | #include "foma.h"cxx . . $ `<file>/foma.h`/ |
| 24 | |
| 25 | #define RANDOMcxx . . $ `apply.c:25:9`! 1 |
| 26 | #define ENUMERATEcxx . . $ `apply.c:26:9`! 2 |
| 27 | #define MATCHcxx . . $ `apply.c:27:9`! 4 |
| 28 | #define UPcxx . . $ `apply.c:28:9`! 8 |
| 29 | #define DOWNcxx . . $ `apply.c:29:9`! 16 |
| 30 | #define LOWERcxx . . $ `apply.c:30:9`! 32 |
| 31 | #define UPPERcxx . . $ `apply.c:31:9`! 64 |
| 32 | #define SPACEcxx . . $ `apply.c:32:9`! 128 |
| 33 | |
| 34 | #define FAILcxx . . $ `apply.c:34:9`! 0 |
| 35 | #define SUCCEEDcxx . . $ `apply.c:35:9`! 1 |
| 36 | |
| 37 | #define DEFAULT_OUTSTRING_SIZEcxx . . $ `apply.c:37:9`! 4096 |
| 38 | #define DEFAULT_STACK_SIZEcxx . . $ `apply.c:38:9`! 128 |
| 39 | |
| 40 | #define APPLY_BINSEARCH_THRESHOLDcxx . . $ `apply.c:40:9`! 10 |
| 41 | |
| 42 | #define BITMASKcxx . . $ `apply.c:42:9`!(b) (1 << ((b) & 7)) |
| 43 | #define BITSLOTcxx . . $ `apply.c:43:9`!(b) ((b) >> 3) |
| 44 | #define BITSETcxx . . $ `apply.c:44:9`!(a,b) ((a)[BITSLOTcxx . . $ `apply.c:43:9`!(b)] |= BITMASKcxx . . $ `apply.c:42:9`!(b)) |
| 45 | #define BITCLEARcxx . . $ `apply.c:45:9`!(a,b) ((a)[BITSLOT(b)] &= ~BITMASK(b)) |
| 46 | #define BITTESTcxx . . $ `apply.c:46:9`!(a,b) ((a)[BITSLOTcxx . . $ `apply.c:43:9`!(b)] & BITMASKcxx . . $ `apply.c:42:9`!(b)) |
| 47 | #define BITNSLOTScxx . . $ `apply.c:47:9`!(nb) ((nb + CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`! - 1) / CHAR_BITcxx . . $ `<external>/67164224788392828/limits.h:64:9`!) |
| 48 | |
| 49 | |
| 50 | |
| 51 | static int apply_appendcxx . . $ apply_append(556b40fe8d924c4).(struct apply_handlecxx . . $ apply_handle# *h, int cptr, int sym); |
| 52 | static char *apply_netcxx . . $ apply_net(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h); |
| 53 | static void apply_create_statemapcxx . . $ apply_create_statemap(a7639cec993cd95d).(struct apply_handlecxx . . $ apply_handle# *h,struct fsmcxx . . $ fsm# *net); |
| 54 | static void apply_create_sigarraycxx . . $ apply_create_sigarray(a7639cec993cd95d).(struct apply_handlecxx . . $ apply_handle# *h,struct fsmcxx . . $ fsm# *net); |
| 55 | static void apply_create_sigmatchcxx . . $ apply_create_sigmatch(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h); |
| 56 | int apply_match_lengthcxx . . $ apply_match_length(f4e47f211469df87).(struct apply_handlecxx . . $ apply_handle# *h, int symbol); |
| 57 | static int apply_match_strcxx . . $ apply_match_str(556b40fe8d924c4).(struct apply_handlecxx . . $ apply_handle# *h,int symbol, int position); |
| 58 | static void apply_add_flagcxx . . $ apply_add_flag(259e9dc864900f19).(struct apply_handlecxx . . $ apply_handle# *h,char *name); |
| 59 | static int apply_check_flagcxx . . $ apply_check_flag(6d966aa81daf532d).(struct apply_handlecxx . . $ apply_handle# *h,int type, char *name, char *value); |
| 60 | static void apply_clear_flagscxx . . $ apply_clear_flags(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h); |
| 61 | void apply_set_iptrcxx . . $ apply_set_iptr(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h); |
| 62 | void apply_mark_flagstatescxx . . $ apply_mark_flagstates(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h); |
| 63 | void apply_clear_indexcxx . . $ apply_clear_index(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h); |
| 64 | |
| 65 | static void apply_stack_clearcxx . . $ apply_stack_clear(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h); |
| 66 | static int apply_stack_isemptycxx . . $ apply_stack_isempty(aafcfc4baa0a05e2).(struct apply_handlecxx . . $ apply_handle# *h); |
| 67 | static void apply_stack_popcxx . . $ apply_stack_pop(dcfc4a94b3eb08e5). (struct apply_handlecxx . . $ apply_handle# *h); |
| 68 | static void apply_stack_pushcxx . . $ apply_stack_push(ac3602237fb36a). (struct apply_handlecxx . . $ apply_handle# *h, int vmark, char *sflagname, char *sflagvalue, int sflagneg); |
| 69 | static void apply_force_clear_stackcxx . . $ apply_force_clear_stack(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h); |
| 70 | |
| 71 | |
| 72 | void apply_set_obey_flagscxx . . $ apply_set_obey_flags(984efd524d87fb50).(struct apply_handlecxx . . $ apply_handle# *h, int value) { |
| 73 | h->obey_flagscxx . . $ apply_handle#obey_flags. = value; |
| 74 | } |
| 75 | |
| 76 | void apply_set_show_flagscxx . . $ apply_set_show_flags(984efd524d87fb50).(struct apply_handlecxx . . $ apply_handle# *h, int value) { |
| 77 | h->show_flagscxx . . $ apply_handle#show_flags. = value; |
| 78 | } |
| 79 | |
| 80 | void apply_set_print_spacecxx . . $ apply_set_print_space(984efd524d87fb50).(struct apply_handlecxx . . $ apply_handle# *h, int value) { |
| 81 | h->print_spacecxx . . $ apply_handle#print_space. = value; |
| 82 | h->space_symbolcxx . . $ apply_handle#space_symbol. = strdupcxx . . $ strdup(a8b8e32347182212).(" "); |
| 83 | } |
| 84 | |
| 85 | void apply_set_separatorcxx . . $ apply_set_separator(259e9dc864900f19).(struct apply_handlecxx . . $ apply_handle# *h, char *symbol) { |
| 86 | h->separatorcxx . . $ apply_handle#separator. = strdupcxx . . $ strdup(a8b8e32347182212).(symbol); |
| 87 | } |
| 88 | |
| 89 | void apply_set_epsiloncxx . . $ apply_set_epsilon(259e9dc864900f19).(struct apply_handlecxx . . $ apply_handle# *h, char *symbol) { |
| 90 | freecxx . . $ free(5d22bdacc48458e8).(h->epsilon_symbolcxx . . $ apply_handle#epsilon_symbol.); |
| 91 | h->epsilon_symbolcxx . . $ apply_handle#epsilon_symbol. = strdupcxx . . $ strdup(a8b8e32347182212).(symbol); |
| 92 | (h->sigscxx . . $ apply_handle#sigs.+EPSILONcxx . . $ `fomalib.h:49:9`!)->symbolcxx . . $ sigs#symbol. = h->epsilon_symbolcxx . . $ apply_handle#epsilon_symbol.; |
| 93 | (h->sigscxx . . $ apply_handle#sigs.+EPSILONcxx . . $ `fomalib.h:49:9`!)->lengthcxx . . $ sigs#length. = strlencxx . . $ strlen(751346f8406fd082).(h->epsilon_symbolcxx . . $ apply_handle#epsilon_symbol.); |
| 94 | } |
| 95 | |
| 96 | void apply_set_space_symbolcxx . . $ apply_set_space_symbol(259e9dc864900f19).(struct apply_handlecxx . . $ apply_handle# *h, char *space) { |
| 97 | h->space_symbolcxx . . $ apply_handle#space_symbol. = strdupcxx . . $ strdup(a8b8e32347182212).(space); |
| 98 | h->print_spacecxx . . $ apply_handle#print_space. = 1; |
| 99 | } |
| 100 | |
| 101 | void apply_set_print_pairscxx . . $ apply_set_print_pairs(984efd524d87fb50).(struct apply_handlecxx . . $ apply_handle# *h, int value) { |
| 102 | h->print_pairscxx . . $ apply_handle#print_pairs. = value; |
| 103 | } |
| 104 | |
| 105 | static void apply_force_clear_stackcxx . . $ apply_force_clear_stack(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 106 | /* Make sure stack is empty and marks reset */ |
| 107 | if (!apply_stack_isemptycxx . . $ apply_stack_isempty(aafcfc4baa0a05e2).(h)) { |
| 108 | *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.) = 0; |
| 109 | while (!apply_stack_isemptycxx . . $ apply_stack_isempty(aafcfc4baa0a05e2).(h)) { |
| 110 | apply_stack_popcxx . . $ apply_stack_pop(dcfc4a94b3eb08e5).(h); |
| 111 | *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.) = 0; |
| 112 | } |
| 113 | h->iteratorcxx . . $ apply_handle#iterator. = 0; |
| 114 | h->iterate_oldcxx . . $ apply_handle#iterate_old. = 0; |
| 115 | apply_stack_clearcxx . . $ apply_stack_clear(dcfc4a94b3eb08e5).(h); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | char *apply_enumeratecxx . . $ apply_enumerate(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 120 | |
| 121 | char *result = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 122 | |
| 123 | if (h->last_netcxx . . $ apply_handle#last_net. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || h->last_netcxx . . $ apply_handle#last_net.->finalcountcxx . . $ fsm#finalcount. == 0) { |
| 124 | return (NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 125 | } |
| 126 | h->binsearchcxx . . $ apply_handle#binsearch. = 0; |
| 127 | if (h->iteratorcxx . . $ apply_handle#iterator. == 0) { |
| 128 | h->iterate_oldcxx . . $ apply_handle#iterate_old. = 0; |
| 129 | apply_force_clear_stackcxx . . $ apply_force_clear_stack(dcfc4a94b3eb08e5).(h); |
| 130 | result = apply_netcxx . . $ apply_net(99adbf620860b308).(h); |
| 131 | if ((h->modecxx . . $ apply_handle#mode. & RANDOMcxx . . $ `apply.c:25:9`!) != RANDOMcxx . . $ `apply.c:25:9`!) |
| 132 | (h->iteratorcxx . . $ apply_handle#iterator.)++; |
| 133 | } else { |
| 134 | h->iterate_oldcxx . . $ apply_handle#iterate_old. = 1; |
| 135 | result = apply_netcxx . . $ apply_net(99adbf620860b308).(h); |
| 136 | } |
| 137 | return(result); |
| 138 | } |
| 139 | |
| 140 | char *apply_wordscxx . . $ apply_words(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 141 | h->modecxx . . $ apply_handle#mode. = DOWNcxx . . $ `apply.c:29:9`! + ENUMERATEcxx . . $ `apply.c:26:9`! + LOWERcxx . . $ `apply.c:30:9`! + UPPERcxx . . $ `apply.c:31:9`!; |
| 142 | return(apply_enumeratecxx . . $ apply_enumerate(99adbf620860b308).(h)); |
| 143 | } |
| 144 | |
| 145 | char *apply_upper_wordscxx . . $ apply_upper_words(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 146 | h->modecxx . . $ apply_handle#mode. = DOWNcxx . . $ `apply.c:29:9`! + ENUMERATEcxx . . $ `apply.c:26:9`! + UPPERcxx . . $ `apply.c:31:9`!; |
| 147 | return(apply_enumeratecxx . . $ apply_enumerate(99adbf620860b308).(h)); |
| 148 | } |
| 149 | |
| 150 | char *apply_lower_wordscxx . . $ apply_lower_words(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 151 | h->modecxx . . $ apply_handle#mode. = DOWNcxx . . $ `apply.c:29:9`! + ENUMERATEcxx . . $ `apply.c:26:9`! + LOWERcxx . . $ `apply.c:30:9`!; |
| 152 | return(apply_enumeratecxx . . $ apply_enumerate(99adbf620860b308).(h)); |
| 153 | } |
| 154 | |
| 155 | char *apply_random_wordscxx . . $ apply_random_words(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 156 | apply_clear_flagscxx . . $ apply_clear_flags(dcfc4a94b3eb08e5).(h); |
| 157 | h->modecxx . . $ apply_handle#mode. = DOWNcxx . . $ `apply.c:29:9`! + ENUMERATEcxx . . $ `apply.c:26:9`! + LOWERcxx . . $ `apply.c:30:9`! + UPPERcxx . . $ `apply.c:31:9`! + RANDOMcxx . . $ `apply.c:25:9`!; |
| 158 | return(apply_enumeratecxx . . $ apply_enumerate(99adbf620860b308).(h)); |
| 159 | } |
| 160 | |
| 161 | char *apply_random_lowercxx . . $ apply_random_lower(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 162 | apply_clear_flagscxx . . $ apply_clear_flags(dcfc4a94b3eb08e5).(h); |
| 163 | h->modecxx . . $ apply_handle#mode. = DOWNcxx . . $ `apply.c:29:9`! + ENUMERATEcxx . . $ `apply.c:26:9`! + LOWERcxx . . $ `apply.c:30:9`! + RANDOMcxx . . $ `apply.c:25:9`!; |
| 164 | return(apply_enumeratecxx . . $ apply_enumerate(99adbf620860b308).(h)); |
| 165 | } |
| 166 | |
| 167 | char *apply_random_uppercxx . . $ apply_random_upper(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 168 | apply_clear_flagscxx . . $ apply_clear_flags(dcfc4a94b3eb08e5).(h); |
| 169 | h->modecxx . . $ apply_handle#mode. = DOWNcxx . . $ `apply.c:29:9`! + ENUMERATEcxx . . $ `apply.c:26:9`! + UPPERcxx . . $ `apply.c:31:9`! + RANDOMcxx . . $ `apply.c:25:9`!; |
| 170 | return(apply_enumeratecxx . . $ apply_enumerate(99adbf620860b308).(h)); |
| 171 | } |
| 172 | |
| 173 | /* Frees memory associated with applies */ |
| 174 | void apply_clearcxx . . $ apply_clear(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 175 | struct sigma_trie_arrayscxx . . $ sigma_trie_arrays# *sta, *stap; |
| 176 | for (sta = h->sigma_trie_arrayscxx . . $ apply_handle#sigma_trie_arrays.; sta != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; ) { |
| 177 | stap = sta; |
| 178 | freecxx . . $ free(5d22bdacc48458e8).(sta->arrcxx . . $ sigma_trie_arrays#arr.); |
| 179 | sta = sta->nextcxx . . $ sigma_trie_arrays#next.; |
| 180 | freecxx . . $ free(5d22bdacc48458e8).(stap); |
| 181 | } |
| 182 | h->sigma_trie_arrayscxx . . $ apply_handle#sigma_trie_arrays. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 183 | if (h->statemapcxx . . $ apply_handle#statemap. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 184 | freecxx . . $ free(5d22bdacc48458e8).(h->statemapcxx . . $ apply_handle#statemap.); |
| 185 | h->statemapcxx . . $ apply_handle#statemap. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 186 | } |
| 187 | if (h->numlinescxx . . $ apply_handle#numlines. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 188 | freecxx . . $ free(5d22bdacc48458e8).(h->numlinescxx . . $ apply_handle#numlines.); |
| 189 | h->numlinescxx . . $ apply_handle#numlines. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 190 | } |
| 191 | if (h->markscxx . . $ apply_handle#marks. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 192 | freecxx . . $ free(5d22bdacc48458e8).(h->markscxx . . $ apply_handle#marks.); |
| 193 | h->markscxx . . $ apply_handle#marks. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 194 | } |
| 195 | if (h->searchstackcxx . . $ apply_handle#searchstack. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 196 | freecxx . . $ free(5d22bdacc48458e8).(h->searchstackcxx . . $ apply_handle#searchstack.); |
| 197 | h->searchstackcxx . . $ apply_handle#searchstack. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 198 | } |
| 199 | if (h->sigscxx . . $ apply_handle#sigs. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 200 | freecxx . . $ free(5d22bdacc48458e8).(h->sigscxx . . $ apply_handle#sigs.); |
| 201 | h->sigscxx . . $ apply_handle#sigs. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 202 | } |
| 203 | if (h->flag_lookupcxx . . $ apply_handle#flag_lookup. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 204 | freecxx . . $ free(5d22bdacc48458e8).(h->flag_lookupcxx . . $ apply_handle#flag_lookup.); |
| 205 | h->flag_lookupcxx . . $ apply_handle#flag_lookup. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 206 | } |
| 207 | if (h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 208 | freecxx . . $ free(5d22bdacc48458e8).(h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.); |
| 209 | h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 210 | } |
| 211 | if (h->flagstatescxx . . $ apply_handle#flagstates. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 212 | freecxx . . $ free(5d22bdacc48458e8).(h->flagstatescxx . . $ apply_handle#flagstates.); |
| 213 | h->flagstatescxx . . $ apply_handle#flagstates. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 214 | } |
| 215 | apply_clear_indexcxx . . $ apply_clear_index(dcfc4a94b3eb08e5).(h); |
| 216 | h->last_netcxx . . $ apply_handle#last_net. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 217 | h->iteratorcxx . . $ apply_handle#iterator. = 0; |
| 218 | freecxx . . $ free(5d22bdacc48458e8).(h->outstringcxx . . $ apply_handle#outstring.); |
| 219 | freecxx . . $ free(5d22bdacc48458e8).(h->separatorcxx . . $ apply_handle#separator.); |
| 220 | freecxx . . $ free(5d22bdacc48458e8).(h->epsilon_symbolcxx . . $ apply_handle#epsilon_symbol.); |
| 221 | freecxx . . $ free(5d22bdacc48458e8).(h); |
| 222 | } |
| 223 | |
| 224 | char *apply_updowncxx . . $ apply_updown(464d3995f37e7d74).(struct apply_handlecxx . . $ apply_handle# *h, char *word) { |
| 225 | |
| 226 | char *result = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 227 | |
| 228 | if (h->last_netcxx . . $ apply_handle#last_net. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || h->last_netcxx . . $ apply_handle#last_net.->finalcountcxx . . $ fsm#finalcount. == 0) |
| 229 | return (NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 230 | |
| 231 | if (word == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 232 | h->iterate_oldcxx . . $ apply_handle#iterate_old. = 1; |
| 233 | result = apply_netcxx . . $ apply_net(99adbf620860b308).(h); |
| 234 | } |
| 235 | else if (word != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 236 | h->iterate_oldcxx . . $ apply_handle#iterate_old. = 0; |
| 237 | h->instringcxx . . $ apply_handle#instring. = word; |
| 238 | apply_create_sigmatchcxx . . $ apply_create_sigmatch(dcfc4a94b3eb08e5).(h); |
| 239 | |
| 240 | /* Remove old marks if necessary TODO: only pop marks */ |
| 241 | apply_force_clear_stackcxx . . $ apply_force_clear_stack(dcfc4a94b3eb08e5).(h); |
| 242 | result = apply_netcxx . . $ apply_net(99adbf620860b308).(h); |
| 243 | } |
| 244 | return(result); |
| 245 | } |
| 246 | |
| 247 | char *apply_downcxx . . $ apply_down(464d3995f37e7d74).(struct apply_handlecxx . . $ apply_handle# *h, char *word) { |
| 248 | |
| 249 | h->modecxx . . $ apply_handle#mode. = DOWNcxx . . $ `apply.c:29:9`!; |
| 250 | if (h->index_incxx . . $ apply_handle#index_in.) { |
| 251 | h->indexedcxx . . $ apply_handle#indexed. = 1; |
| 252 | } else { |
| 253 | h->indexedcxx . . $ apply_handle#indexed. = 0; |
| 254 | } |
| 255 | h->binsearchcxx . . $ apply_handle#binsearch. = (h->last_netcxx . . $ apply_handle#last_net.->arcs_sorted_incxx . . $ fsm#arcs_sorted_in. == 1) ? 1 : 0; |
| 256 | return(apply_updowncxx . . $ apply_updown(464d3995f37e7d74).(h, word)); |
| 257 | } |
| 258 | |
| 259 | char *apply_upcxx . . $ apply_up(464d3995f37e7d74).(struct apply_handlecxx . . $ apply_handle# *h, char *word) { |
| 260 | |
| 261 | h->modecxx . . $ apply_handle#mode. = UPcxx . . $ `apply.c:28:9`!; |
| 262 | if (h->index_outcxx . . $ apply_handle#index_out.) { |
| 263 | h->indexedcxx . . $ apply_handle#indexed. = 1; |
| 264 | } else { |
| 265 | h->indexedcxx . . $ apply_handle#indexed. = 0; |
| 266 | } |
| 267 | h->binsearchcxx . . $ apply_handle#binsearch. = (h->last_netcxx . . $ apply_handle#last_net.->arcs_sorted_outcxx . . $ fsm#arcs_sorted_out. == 1) ? 1 : 0; |
| 268 | return(apply_updowncxx . . $ apply_updown(464d3995f37e7d74).(h, word)); |
| 269 | } |
| 270 | |
| 271 | struct apply_handlecxx . . $ apply_handle# *apply_initcxx . . $ apply_init(97b8b102e62ddc10).(struct fsmcxx . . $ fsm# *net) { |
| 272 | struct apply_handlecxx . . $ apply_handle# *h; |
| 273 | |
| 274 | srandcxx . . $ srand(cb2f890c2fdad230).((unsigned int) timecxx . . $ time(7f38134db6521d23).(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)); |
| 275 | h = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1,sizeof(struct apply_handlecxx . . $ apply_handle#)); |
| 276 | /* Init */ |
| 277 | |
| 278 | h->iterate_oldcxx . . $ apply_handle#iterate_old. = 0; |
| 279 | h->iteratorcxx . . $ apply_handle#iterator. = 0; |
| 280 | h->instringcxx . . $ apply_handle#instring. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 281 | h->flag_listcxx . . $ apply_handle#flag_list. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 282 | h->flag_lookupcxx . . $ apply_handle#flag_lookup. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 283 | h->obey_flagscxx . . $ apply_handle#obey_flags. = 1; |
| 284 | h->show_flagscxx . . $ apply_handle#show_flags. = 0; |
| 285 | h->print_spacecxx . . $ apply_handle#print_space. = 0; |
| 286 | h->print_pairscxx . . $ apply_handle#print_pairs. = 0; |
| 287 | h->separatorcxx . . $ apply_handle#separator. = strdupcxx . . $ strdup(a8b8e32347182212).(":"); |
| 288 | h->epsilon_symbolcxx . . $ apply_handle#epsilon_symbol. = strdupcxx . . $ strdup(a8b8e32347182212).("0"); |
| 289 | h->last_netcxx . . $ apply_handle#last_net. = net; |
| 290 | h->outstringcxx . . $ apply_handle#outstring. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(char)*DEFAULT_OUTSTRING_SIZEcxx . . $ `apply.c:37:9`!); |
| 291 | h->outstringtopcxx . . $ apply_handle#outstringtop. = DEFAULT_OUTSTRING_SIZEcxx . . $ `apply.c:37:9`!; |
| 292 | *(h->outstringcxx . . $ apply_handle#outstring.) = '\0'; |
| 293 | h->gstatescxx . . $ apply_handle#gstates. = net->statescxx . . $ fsm#states.; |
| 294 | h->gsigmacxx . . $ apply_handle#gsigma. = net->sigmacxx . . $ fsm#sigma.; |
| 295 | h->printcountcxx . . $ apply_handle#printcount. = 1; |
| 296 | apply_create_statemapcxx . . $ apply_create_statemap(a7639cec993cd95d).(h, net); |
| 297 | h->searchstackcxx . . $ apply_handle#searchstack. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct searchstackcxx . . $ searchstack#) * DEFAULT_STACK_SIZEcxx . . $ `apply.c:38:9`!); |
| 298 | h->apply_stack_topcxx . . $ apply_handle#apply_stack_top. = DEFAULT_STACK_SIZEcxx . . $ `apply.c:38:9`!; |
| 299 | apply_stack_clearcxx . . $ apply_stack_clear(dcfc4a94b3eb08e5).(h); |
| 300 | apply_create_sigarraycxx . . $ apply_create_sigarray(a7639cec993cd95d).(h, net); |
| 301 | return(h); |
| 302 | } |
| 303 | |
| 304 | int apply_stack_isemptycxx . . $ apply_stack_isempty(aafcfc4baa0a05e2). (struct apply_handlecxx . . $ apply_handle# *h) { |
| 305 | if (h->apply_stack_ptrcxx . . $ apply_handle#apply_stack_ptr. == 0) { |
| 306 | return 1; |
| 307 | } |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | void apply_stack_clearcxx . . $ apply_stack_clear(dcfc4a94b3eb08e5). (struct apply_handlecxx . . $ apply_handle# *h) { |
| 312 | h->apply_stack_ptrcxx . . $ apply_handle#apply_stack_ptr. = 0; |
| 313 | } |
| 314 | |
| 315 | void apply_stack_popcxx . . $ apply_stack_pop(dcfc4a94b3eb08e5). (struct apply_handlecxx . . $ apply_handle# *h) { |
| 316 | struct flag_listcxx . . $ flag_list# *flist; |
| 317 | struct searchstackcxx . . $ searchstack# *ss; |
| 318 | (h->apply_stack_ptrcxx . . $ apply_handle#apply_stack_ptr.)--; |
| 319 | ss = h->searchstackcxx . . $ apply_handle#searchstack.+h->apply_stack_ptrcxx . . $ apply_handle#apply_stack_ptr.; |
| 320 | |
| 321 | h->iptrcxx . . $ apply_handle#iptr. = ss->iptrcxx . . $ searchstack#iptr.; |
| 322 | h->ptrcxx . . $ apply_handle#ptr. = ss->offsetcxx . . $ searchstack#offset.; |
| 323 | h->iposcxx . . $ apply_handle#ipos. = ss->iposcxx . . $ searchstack#ipos.; |
| 324 | h->oposcxx . . $ apply_handle#opos. = ss->oposcxx . . $ searchstack#opos.; |
| 325 | h->state_has_indexcxx . . $ apply_handle#state_has_index. = ss->state_has_indexcxx . . $ searchstack#state_has_index.; |
| 326 | /* Restore mark */ |
| 327 | *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.) = ss->visitmarkcxx . . $ searchstack#visitmark.; |
| 328 | |
| 329 | if (h->has_flagscxx . . $ apply_handle#has_flags. && ss->flagnamecxx . . $ searchstack#flagname. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 330 | /* Restore flag */ |
| 331 | for (flist = h->flag_listcxx . . $ apply_handle#flag_list.; flist != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; flist = flist->nextcxx . . $ flag_list#next.) { |
| 332 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(flist->namecxx . . $ flag_list#name., ss->flagnamecxx . . $ searchstack#flagname.) == 0) { |
| 333 | break; |
| 334 | } |
| 335 | } |
| 336 | if (flist == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 337 | perrorcxx . . $ perror(85c52e162fed56f9).("***Nothing to pop\n"); |
| 338 | flist->valuecxx . . $ flag_list#value. = ss->flagvaluecxx . . $ searchstack#flagvalue.; |
| 339 | flist->negcxx . . $ flag_list#neg. = ss->flagnegcxx . . $ searchstack#flagneg.; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | static void apply_stack_pushcxx . . $ apply_stack_push(ac3602237fb36a). (struct apply_handlecxx . . $ apply_handle# *h, int vmark, char *sflagname, char *sflagvalue, int sflagneg) { |
| 344 | struct searchstackcxx . . $ searchstack# *ss; |
| 345 | if (h->apply_stack_ptrcxx . . $ apply_handle#apply_stack_ptr. == h->apply_stack_topcxx . . $ apply_handle#apply_stack_top.) { |
| 346 | h->searchstackcxx . . $ apply_handle#searchstack. = realloccxx . . $ realloc(417ab160f6baadc6).(h->searchstackcxx . . $ apply_handle#searchstack., sizeof(struct searchstackcxx . . $ searchstack#)* ((h->apply_stack_topcxx . . $ apply_handle#apply_stack_top.)*2)); |
| 347 | if (h->searchstackcxx . . $ apply_handle#searchstack. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 348 | perrorcxx . . $ perror(85c52e162fed56f9).("Apply stack full!!!\n"); |
| 349 | exitcxx . . $ exit(3ca292c338df9bb3).(0); |
| 350 | } |
| 351 | h->apply_stack_topcxx . . $ apply_handle#apply_stack_top. *= 2; |
| 352 | } |
| 353 | ss = h->searchstackcxx . . $ apply_handle#searchstack.+h->apply_stack_ptrcxx . . $ apply_handle#apply_stack_ptr.; |
| 354 | ss->offsetcxx . . $ searchstack#offset. = h->curr_ptrcxx . . $ apply_handle#curr_ptr.; |
| 355 | ss->iposcxx . . $ searchstack#ipos. = h->iposcxx . . $ apply_handle#ipos.; |
| 356 | ss->oposcxx . . $ searchstack#opos. = h->oposcxx . . $ apply_handle#opos.; |
| 357 | ss->visitmarkcxx . . $ searchstack#visitmark. = vmark; |
| 358 | ss->iptrcxx . . $ searchstack#iptr. = h->iptrcxx . . $ apply_handle#iptr.; |
| 359 | ss->state_has_indexcxx . . $ searchstack#state_has_index. = h->state_has_indexcxx . . $ apply_handle#state_has_index.; |
| 360 | if (h->has_flagscxx . . $ apply_handle#has_flags.) { |
| 361 | ss->flagnamecxx . . $ searchstack#flagname. = sflagname; |
| 362 | ss->flagvaluecxx . . $ searchstack#flagvalue. = sflagvalue; |
| 363 | ss->flagnegcxx . . $ searchstack#flagneg. = sflagneg; |
| 364 | } |
| 365 | (h->apply_stack_ptrcxx . . $ apply_handle#apply_stack_ptr.)++; |
| 366 | } |
| 367 | |
| 368 | void apply_reset_enumeratorcxx . . $ apply_reset_enumerator(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 369 | int statecount, i; |
| 370 | statecount = h->last_netcxx . . $ apply_handle#last_net.->statecountcxx . . $ fsm#statecount.; |
| 371 | for (i=0; i < statecount; i++) { |
| 372 | *(h->markscxx . . $ apply_handle#marks.+i) = 0; |
| 373 | } |
| 374 | h->iteratorcxx . . $ apply_handle#iterator. = 0; |
| 375 | h->iterate_oldcxx . . $ apply_handle#iterate_old. = 0; |
| 376 | } |
| 377 | |
| 378 | void apply_clear_index_listcxx . . $ apply_clear_index_list(b4b3bd87c7c38aca).(struct apply_handlecxx . . $ apply_handle# *h, struct apply_state_indexcxx . . $ apply_state_index# **index) { |
| 379 | int i, j, statecount; |
| 380 | struct apply_state_indexcxx . . $ apply_state_index# *iptr, *iptr_tmp, *iptr_zero; |
| 381 | if (index == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 382 | return; |
| 383 | statecount = h->last_netcxx . . $ apply_handle#last_net.->statecountcxx . . $ fsm#statecount.; |
| 384 | for (i = 0; i < statecount; i++) { |
| 385 | iptr = *(index+i); |
| 386 | if (iptr == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 387 | continue; |
| 388 | } |
| 389 | iptr_zero = *(index+i); |
| 390 | for (j = h->sigma_sizecxx . . $ apply_handle#sigma_size. - 1 ; j >= 0; j--) { /* Make sure to not free the list in EPSILON */ |
| 391 | iptr = *(index+i) + j; /* as the other states lists' tails point to it */ |
| 392 | for (iptr = iptr->nextcxx . . $ apply_state_index#next. ; iptr != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && iptr != iptr_zero; iptr = iptr_tmp) { |
| 393 | iptr_tmp = iptr->nextcxx . . $ apply_state_index#next.; |
| 394 | freecxx . . $ free(5d22bdacc48458e8).(iptr); |
| 395 | } |
| 396 | } |
| 397 | freecxx . . $ free(5d22bdacc48458e8).(*(index+i)); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | void apply_clear_indexcxx . . $ apply_clear_index(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 402 | if (h->index_incxx . . $ apply_handle#index_in.) { |
| 403 | apply_clear_index_listcxx . . $ apply_clear_index_list(b4b3bd87c7c38aca).(h, h->index_incxx . . $ apply_handle#index_in.); |
| 404 | freecxx . . $ free(5d22bdacc48458e8).(h->index_incxx . . $ apply_handle#index_in.); |
| 405 | h->index_incxx . . $ apply_handle#index_in. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 406 | } |
| 407 | if (h->index_outcxx . . $ apply_handle#index_out.) { |
| 408 | apply_clear_index_listcxx . . $ apply_clear_index_list(b4b3bd87c7c38aca).(h, h->index_outcxx . . $ apply_handle#index_out.); |
| 409 | freecxx . . $ free(5d22bdacc48458e8).(h->index_outcxx . . $ apply_handle#index_out.); |
| 410 | h->index_outcxx . . $ apply_handle#index_out. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | void apply_indexcxx . . $ apply_index(a5c196c6f761629f).(struct apply_handlecxx . . $ apply_handle# *h, int inout, int densitycutoff, int mem_limit, int flags_only) { |
| 415 | struct fsm_statecxx . . $ fsm_state# *fsm; |
| 416 | unsigned int cnt = 0; |
| 417 | int i, j, maxtrans, numtrans, laststate, sym; |
| 418 | fsm = h->gstatescxx . . $ apply_handle#gstates.; |
| 419 | |
| 420 | struct apply_state_indexcxx . . $ apply_state_index# **indexptr, *iptr, *tempiptr; |
| 421 | |
| 422 | struct pre_indexcxx . . $ apply_index(a5c196c6f761629f).pre_index# { |
| 423 | int state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no.; |
| 424 | struct pre_indexcxx . . $ apply_index(a5c196c6f761629f).pre_index# *nextcxx . . $ apply_index(a5c196c6f761629f).pre_index#next.; |
| 425 | } *pre_index, *tp, *tpp; |
| 426 | if (flags_only && !h->has_flagscxx . . $ apply_handle#has_flags.) { |
| 427 | return; |
| 428 | } |
| 429 | /* get numtrans */ |
| 430 | for (i=0, laststate = 0, maxtrans = 0, numtrans = 0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) { |
| 431 | if ((fsm+i)->state_nocxx . . $ fsm_state#state_no. != laststate) { |
| 432 | maxtrans = numtrans > maxtrans ? numtrans : maxtrans; |
| 433 | numtrans = 0; |
| 434 | } |
| 435 | if ((fsm+i)->targetcxx . . $ fsm_state#target. != -1) { |
| 436 | numtrans++; |
| 437 | } |
| 438 | laststate = (fsm+i)->state_nocxx . . $ fsm_state#state_no.; |
| 439 | } |
| 440 | |
| 441 | pre_index = calloccxx . . $ calloc(63a7bf2941bfcd7a).(maxtrans+1, sizeof(struct pre_indexcxx . . $ apply_index(a5c196c6f761629f).pre_index#)); |
| 442 | for (i = 0; i <= maxtrans; i++) { |
| 443 | (pre_index+i)->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no. = -1; |
| 444 | } |
| 445 | |
| 446 | /* We create an array of states, indexed by how many transitions they have */ |
| 447 | /* so that later, we can traverse them in order densest first, in case we */ |
| 448 | /* only want to index to some predefined maximum memory usage. */ |
| 449 | |
| 450 | for (i = 0, laststate = 0, maxtrans = 0, numtrans = 0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) { |
| 451 | if ((fsm+i)->state_nocxx . . $ fsm_state#state_no. != laststate) { |
| 452 | if ((pre_index+numtrans)->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no. == -1) { |
| 453 | (pre_index+numtrans)->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no. = laststate; |
| 454 | } else { |
| 455 | tp = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct pre_indexcxx . . $ apply_index(a5c196c6f761629f).pre_index#)); |
| 456 | tp->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no. = laststate; |
| 457 | tp->nextcxx . . $ apply_index(a5c196c6f761629f).pre_index#next. = (pre_index+numtrans)->nextcxx . . $ apply_index(a5c196c6f761629f).pre_index#next.; |
| 458 | (pre_index+numtrans)->nextcxx . . $ apply_index(a5c196c6f761629f).pre_index#next. = tp; |
| 459 | } |
| 460 | maxtrans = numtrans > maxtrans ? numtrans : maxtrans; |
| 461 | numtrans = 0; |
| 462 | } |
| 463 | if ((fsm+i)->targetcxx . . $ fsm_state#target. != -1) { |
| 464 | numtrans++; |
| 465 | } |
| 466 | laststate = (fsm+i)->state_nocxx . . $ fsm_state#state_no.; |
| 467 | } |
| 468 | indexptr = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 469 | cnt += round_up_to_power_of_twocxx . . $ round_up_to_power_of_two(2141b656ce2cc063).(h->last_netcxx . . $ apply_handle#last_net.->statecountcxx . . $ fsm#statecount.*sizeof(struct apply_state_indexcxx . . $ apply_state_index# *)); |
| 470 | |
| 471 | if (cnt > mem_limit) { |
| 472 | cnt -= round_up_to_power_of_twocxx . . $ round_up_to_power_of_two(2141b656ce2cc063).(h->last_netcxx . . $ apply_handle#last_net.->statecountcxx . . $ fsm#statecount.*sizeof(struct apply_state_indexcxx . . $ apply_state_index# *)); |
| 473 | goto memlimitnoindex; |
| 474 | } |
| 475 | |
| 476 | indexptr = calloccxx . . $ calloc(63a7bf2941bfcd7a).(h->last_netcxx . . $ apply_handle#last_net.->statecountcxx . . $ fsm#statecount., sizeof(struct apply_state_indexcxx . . $ apply_state_index# *)); |
| 477 | |
| 478 | if (h->has_flagscxx . . $ apply_handle#has_flags. && flags_only) { |
| 479 | /* Mark states that have flags */ |
| 480 | if (!(h->flagstatescxx . . $ apply_handle#flagstates.)) { |
| 481 | apply_mark_flagstatescxx . . $ apply_mark_flagstates(dcfc4a94b3eb08e5).(h); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | for (i = maxtrans; i >= 0; i--) { |
| 486 | for (tp = pre_index+i; tp != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; tp = tp->nextcxx . . $ apply_index(a5c196c6f761629f).pre_index#next.) { |
| 487 | if (tp->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no. >= 0) { |
| 488 | if (i < densitycutoff) { |
| 489 | if (!(h->has_flagscxx . . $ apply_handle#has_flags. && flags_only && BITTESTcxx . . $ `apply.c:46:9`!(h->flagstates, tp->state_no))) { |
| 490 | continue; |
| 491 | } |
| 492 | } |
| 493 | cnt += round_up_to_power_of_twocxx . . $ round_up_to_power_of_two(2141b656ce2cc063).(h->sigma_sizecxx . . $ apply_handle#sigma_size.*sizeof(struct apply_state_indexcxx . . $ apply_state_index#)); |
| 494 | if (cnt > mem_limit) { |
| 495 | cnt -= round_up_to_power_of_twocxx . . $ round_up_to_power_of_two(2141b656ce2cc063).(h->sigma_sizecxx . . $ apply_handle#sigma_size.*sizeof(struct apply_state_indexcxx . . $ apply_state_index#)); |
| 496 | goto memlimit; |
| 497 | } |
| 498 | *(indexptr + tp->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no.) = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(h->sigma_sizecxx . . $ apply_handle#sigma_size.*sizeof(struct apply_state_indexcxx . . $ apply_state_index#)); |
| 499 | |
| 500 | /* We make the tail of all index linked lists point to the index */ |
| 501 | /* for EPSILON, so that we automatically when EPSILON transitions */ |
| 502 | /* also when traversing an index. */ |
| 503 | |
| 504 | for (j = 0; j < h->sigma_sizecxx . . $ apply_handle#sigma_size.; j++) { |
| 505 | (*(indexptr + tp->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no.) + j)->fsmptrcxx . . $ apply_state_index#fsmptr. = -1; |
| 506 | if (j == EPSILONcxx . . $ `fomalib.h:49:9`!) |
| 507 | (*(indexptr + tp->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no.) + j)->nextcxx . . $ apply_state_index#next. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 508 | else |
| 509 | (*(indexptr + tp->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no.) + j)->nextcxx . . $ apply_state_index#next. = (*(indexptr + tp->state_nocxx . . $ apply_index(a5c196c6f761629f).pre_index#state_no.)); /* all tails point to epsilon */ |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | memlimit: |
| 516 | |
| 517 | for (i=0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) { |
| 518 | iptr = *(indexptr + (fsm+i)->state_nocxx . . $ fsm_state#state_no.); |
| 519 | if (iptr == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || (fsm+i)->targetcxx . . $ fsm_state#target. == -1) { |
| 520 | continue; |
| 521 | } |
| 522 | sym = inout == APPLY_INDEX_INPUTcxx . . $ `fomalib.h:94:9`! ? (fsm+i)->incxx . . $ fsm_state#in. : (fsm+i)->outcxx . . $ fsm_state#out.; |
| 523 | |
| 524 | if (h->has_flagscxx . . $ apply_handle#has_flags. && (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+sym)->typecxx . . $ flag_lookup#type.) { |
| 525 | sym = EPSILONcxx . . $ `fomalib.h:49:9`!; |
| 526 | } |
| 527 | if (sym == UNKNOWNcxx . . $ `fomalib.h:50:9`!) { /* We make the index of UNKNOWN point to IDENTITY */ |
| 528 | sym = IDENTITYcxx . . $ `fomalib.h:51:9`!; /* since these are really the same symbol */ |
| 529 | } |
| 530 | if ((iptr+sym)->fsmptrcxx . . $ apply_state_index#fsmptr. == -1) { |
| 531 | (iptr+sym)->fsmptrcxx . . $ apply_state_index#fsmptr. = i; |
| 532 | } else { |
| 533 | cnt += round_up_to_power_of_twocxx . . $ round_up_to_power_of_two(2141b656ce2cc063).(sizeof(struct apply_state_indexcxx . . $ apply_state_index#)); |
| 534 | tempiptr = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct apply_state_indexcxx . . $ apply_state_index#)); |
| 535 | |
| 536 | tempiptr->nextcxx . . $ apply_state_index#next. = (iptr+sym)->nextcxx . . $ apply_state_index#next.; |
| 537 | tempiptr->fsmptrcxx . . $ apply_state_index#fsmptr. = i; |
| 538 | (iptr+sym)->nextcxx . . $ apply_state_index#next. = tempiptr; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | /* Free preindex */ |
| 543 | |
| 544 | memlimitnoindex: |
| 545 | |
| 546 | for (i = maxtrans; i >= 0; i--) { |
| 547 | for (tp = (pre_index+i)->nextcxx . . $ apply_index(a5c196c6f761629f).pre_index#next.; tp != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; tp = tpp) { |
| 548 | tpp = tp->nextcxx . . $ apply_index(a5c196c6f761629f).pre_index#next.; |
| 549 | freecxx . . $ free(5d22bdacc48458e8).(tp); |
| 550 | } |
| 551 | } |
| 552 | freecxx . . $ free(5d22bdacc48458e8).(pre_index); |
| 553 | |
| 554 | if (inout == APPLY_INDEX_INPUTcxx . . $ `fomalib.h:94:9`!) { |
| 555 | h->index_incxx . . $ apply_handle#index_in. = indexptr; |
| 556 | } else { |
| 557 | h->index_outcxx . . $ apply_handle#index_out. = indexptr; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | int apply_binarysearchcxx . . $ apply_binarysearch(aafcfc4baa0a05e2).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 562 | int thisstate, nextsym, seeksym, thisptr, lastptr, midptr; |
| 563 | |
| 564 | thisptr = h->curr_ptrcxx . . $ apply_handle#curr_ptr. = h->ptrcxx . . $ apply_handle#ptr.; |
| 565 | nextsym = (((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) ? (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->incxx . . $ fsm_state#in. : (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->outcxx . . $ fsm_state#out.; |
| 566 | if (nextsym == EPSILONcxx . . $ `fomalib.h:49:9`!) |
| 567 | return 1; |
| 568 | if (nextsym == -1) |
| 569 | return 0; |
| 570 | if (h->iposcxx . . $ apply_handle#ipos. >= h->current_instring_lengthcxx . . $ apply_handle#current_instring_length.) { |
| 571 | return 0; |
| 572 | } |
| 573 | seeksym = (h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+h->iposcxx . . $ apply_handle#ipos.)->signumbercxx . . $ sigmatch_array#signumber.; |
| 574 | if (seeksym == nextsym || (nextsym == UNKNOWNcxx . . $ `fomalib.h:50:9`! && seeksym == IDENTITYcxx . . $ `fomalib.h:51:9`!)) |
| 575 | return 1; |
| 576 | |
| 577 | thisstate = (h->gstatescxx . . $ apply_handle#gstates.+thisptr)->state_nocxx . . $ fsm_state#state_no.; |
| 578 | lastptr = *(h->statemapcxx . . $ apply_handle#statemap.+thisstate)+*(h->numlinescxx . . $ apply_handle#numlines.+thisstate)-1; |
| 579 | thisptr++; |
| 580 | |
| 581 | if (seeksym == IDENTITYcxx . . $ `fomalib.h:51:9`! || lastptr - thisptr < APPLY_BINSEARCH_THRESHOLDcxx . . $ `apply.c:40:9`!) { |
| 582 | for ( ; thisptr <= lastptr; thisptr++) { |
| 583 | nextsym = (((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) ? (h->gstatescxx . . $ apply_handle#gstates.+thisptr)->incxx . . $ fsm_state#in. : (h->gstatescxx . . $ apply_handle#gstates.+thisptr)->outcxx . . $ fsm_state#out.; |
| 584 | if ((nextsym == seeksym) || (nextsym == UNKNOWNcxx . . $ `fomalib.h:50:9`! && seeksym == IDENTITYcxx . . $ `fomalib.h:51:9`!)) { |
| 585 | h->curr_ptrcxx . . $ apply_handle#curr_ptr. = thisptr; |
| 586 | return 1; |
| 587 | } |
| 588 | if (nextsym > seeksym || nextsym == -1) { |
| 589 | return 0; |
| 590 | } |
| 591 | } |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | for (;;) { |
| 596 | if (thisptr > lastptr) { return 0; } |
| 597 | midptr = (thisptr+lastptr)/2; |
| 598 | nextsym = (((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) ? (h->gstatescxx . . $ apply_handle#gstates.+midptr)->incxx . . $ fsm_state#in. : (h->gstatescxx . . $ apply_handle#gstates.+midptr)->outcxx . . $ fsm_state#out.; |
| 599 | if (seeksym < nextsym) { |
| 600 | lastptr = midptr - 1; |
| 601 | continue; |
| 602 | } else if (seeksym > nextsym) { |
| 603 | thisptr = midptr + 1; |
| 604 | continue; |
| 605 | } else { |
| 606 | |
| 607 | while (((((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) ? (h->gstatescxx . . $ apply_handle#gstates.+(midptr-1))->incxx . . $ fsm_state#in. : (h->gstatescxx . . $ apply_handle#gstates.+(midptr-1))->outcxx . . $ fsm_state#out.) == seeksym) { |
| 608 | midptr--; /* Find first match in case of ties */ |
| 609 | } |
| 610 | h->curr_ptrcxx . . $ apply_handle#curr_ptr. = midptr; |
| 611 | return 1; |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | int apply_follow_next_arccxx . . $ apply_follow_next_arc(aafcfc4baa0a05e2).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 617 | char *fname, *fvalue; |
| 618 | int eatupi, eatupo, symin, symout, fneg; |
| 619 | int vcount, marksource, marktarget; |
| 620 | |
| 621 | /* Here we follow three possible search strategies: */ |
| 622 | /* (1) if the state in question has an index, we use that */ |
| 623 | /* (2) if the state is binary searchable, we use that */ |
| 624 | /* (3) otherwise we traverse arc-by-arc */ |
| 625 | /* Condition (2) needs arcs to be sorted in the proper */ |
| 626 | /* direction, and requires that the state be flag-free */ |
| 627 | /* For those states that aren't flag-free, (3) is used */ |
| 628 | |
| 629 | if (h->state_has_indexcxx . . $ apply_handle#state_has_index.) { |
| 630 | for ( ; h->iptrcxx . . $ apply_handle#iptr. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && h->iptrcxx . . $ apply_handle#iptr.->fsmptrcxx . . $ apply_state_index#fsmptr. != -1; ) { |
| 631 | |
| 632 | h->ptrcxx . . $ apply_handle#ptr. = h->curr_ptrcxx . . $ apply_handle#curr_ptr. = h->iptrcxx . . $ apply_handle#iptr.->fsmptrcxx . . $ apply_state_index#fsmptr.; |
| 633 | if (((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) { |
| 634 | symin = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->incxx . . $ fsm_state#in.; |
| 635 | symout = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->outcxx . . $ fsm_state#out.; |
| 636 | } else { |
| 637 | symin = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->outcxx . . $ fsm_state#out.; |
| 638 | symout = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->incxx . . $ fsm_state#in.; |
| 639 | } |
| 640 | |
| 641 | marksource = *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.); |
| 642 | marktarget = *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+(*(h->statemapcxx . . $ apply_handle#statemap.+(h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->targetcxx . . $ fsm_state#target.)))->state_nocxx . . $ fsm_state#state_no.); |
| 643 | eatupi = apply_match_lengthcxx . . $ apply_match_length(f4e47f211469df87).(h, symin); |
| 644 | if (!(eatupi == -1 || -1-(h->iposcxx . . $ apply_handle#ipos.)-eatupi == marktarget)) { /* input 2x EPSILON loop check */ |
| 645 | if ((eatupi = apply_match_strcxx . . $ apply_match_str(556b40fe8d924c4).(h, symin, h->iposcxx . . $ apply_handle#ipos.)) != -1) { |
| 646 | eatupo = apply_appendcxx . . $ apply_append(556b40fe8d924c4).(h, h->curr_ptrcxx . . $ apply_handle#curr_ptr., symout); |
| 647 | if (h->obey_flagscxx . . $ apply_handle#obey_flags. && h->has_flagscxx . . $ apply_handle#has_flags. && ((h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symin)->typecxx . . $ flag_lookup#type. & (FLAG_UNIFYcxx . . $ `fomalib.h:75:9`!|FLAG_CLEARcxx . . $ `fomalib.h:76:9`!|FLAG_POSITIVEcxx . . $ `fomalib.h:79:9`!|FLAG_NEGATIVEcxx . . $ `fomalib.h:78:9`!))) { |
| 648 | fname = (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symin)->namecxx . . $ flag_lookup#name.; |
| 649 | fvalue = h->oldflagvaluecxx . . $ apply_handle#oldflagvalue.; |
| 650 | fneg = h->oldflagnegcxx . . $ apply_handle#oldflagneg.; |
| 651 | } else { |
| 652 | fname = fvalue = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 653 | fneg = 0; |
| 654 | } |
| 655 | /* Push old position */ |
| 656 | apply_stack_pushcxx . . $ apply_stack_push(ac3602237fb36a).(h, marksource, fname, fvalue, fneg); |
| 657 | h->ptrcxx . . $ apply_handle#ptr. = *(h->statemapcxx . . $ apply_handle#statemap.+(h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->targetcxx . . $ fsm_state#target.); |
| 658 | h->iposcxx . . $ apply_handle#ipos. += eatupi; |
| 659 | h->oposcxx . . $ apply_handle#opos. += eatupo; |
| 660 | apply_set_iptrcxx . . $ apply_set_iptr(dcfc4a94b3eb08e5).(h); |
| 661 | return 1; |
| 662 | } |
| 663 | } |
| 664 | h->iptrcxx . . $ apply_handle#iptr. = h->iptrcxx . . $ apply_handle#iptr.->nextcxx . . $ apply_state_index#next.; |
| 665 | } |
| 666 | return 0; |
| 667 | } else if ((h->binsearchcxx . . $ apply_handle#binsearch. && !(h->has_flagscxx . . $ apply_handle#has_flags.)) || (h->binsearchcxx . . $ apply_handle#binsearch. && !(BITTESTcxx . . $ `apply.c:46:9`!(h->flagstates, (h->gstates+h->ptr)->state_no)))) { |
| 668 | for (;;) { |
| 669 | if (apply_binarysearchcxx . . $ apply_binarysearch(aafcfc4baa0a05e2).(h)) { |
| 670 | if (((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) { |
| 671 | symin = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->incxx . . $ fsm_state#in.; |
| 672 | symout = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->outcxx . . $ fsm_state#out.; |
| 673 | } else { |
| 674 | symin = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->outcxx . . $ fsm_state#out.; |
| 675 | symout = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->incxx . . $ fsm_state#in.; |
| 676 | } |
| 677 | |
| 678 | marksource = *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.); |
| 679 | marktarget = *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+(*(h->statemapcxx . . $ apply_handle#statemap.+(h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->targetcxx . . $ fsm_state#target.)))->state_nocxx . . $ fsm_state#state_no.); |
| 680 | |
| 681 | eatupi = apply_match_lengthcxx . . $ apply_match_length(f4e47f211469df87).(h, symin); |
| 682 | if (eatupi != -1 && -1-(h->iposcxx . . $ apply_handle#ipos.)-eatupi != marktarget) { |
| 683 | if ((eatupi = apply_match_strcxx . . $ apply_match_str(556b40fe8d924c4).(h, symin, h->iposcxx . . $ apply_handle#ipos.)) != -1) { |
| 684 | eatupo = apply_appendcxx . . $ apply_append(556b40fe8d924c4).(h, h->curr_ptrcxx . . $ apply_handle#curr_ptr., symout); |
| 685 | |
| 686 | /* Push old position */ |
| 687 | apply_stack_pushcxx . . $ apply_stack_push(ac3602237fb36a).(h, marksource, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, 0); |
| 688 | |
| 689 | /* Follow arc */ |
| 690 | h->ptrcxx . . $ apply_handle#ptr. = *(h->statemapcxx . . $ apply_handle#statemap.+(h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->targetcxx . . $ fsm_state#target.); |
| 691 | h->iposcxx . . $ apply_handle#ipos. += eatupi; |
| 692 | h->oposcxx . . $ apply_handle#opos. += eatupo; |
| 693 | apply_set_iptrcxx . . $ apply_set_iptr(dcfc4a94b3eb08e5).(h); |
| 694 | return 1; |
| 695 | } |
| 696 | } |
| 697 | if ((h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->state_nocxx . . $ fsm_state#state_no. == (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.+1)->state_nocxx . . $ fsm_state#state_no.) { |
| 698 | h->curr_ptrcxx . . $ apply_handle#curr_ptr.++; |
| 699 | h->ptrcxx . . $ apply_handle#ptr. = h->curr_ptrcxx . . $ apply_handle#curr_ptr.; |
| 700 | if ((h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)-> targetcxx . . $ fsm_state#target. == -1) { |
| 701 | return 0; |
| 702 | } |
| 703 | continue; |
| 704 | } |
| 705 | } |
| 706 | return 0; |
| 707 | } |
| 708 | } else { |
| 709 | for (h->curr_ptrcxx . . $ apply_handle#curr_ptr. = h->ptrcxx . . $ apply_handle#ptr.; (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->state_nocxx . . $ fsm_state#state_no. == (h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no. && (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)-> incxx . . $ fsm_state#in. != -1; (h->curr_ptrcxx . . $ apply_handle#curr_ptr.)++) { |
| 710 | |
| 711 | /* Select one random arc to follow out of all outgoing arcs */ |
| 712 | if ((h->modecxx . . $ apply_handle#mode. & RANDOMcxx . . $ `apply.c:25:9`!) == RANDOMcxx . . $ `apply.c:25:9`!) { |
| 713 | vcount = 0; |
| 714 | for (h->curr_ptrcxx . . $ apply_handle#curr_ptr. = h->ptrcxx . . $ apply_handle#ptr.; (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->state_nocxx . . $ fsm_state#state_no. == (h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no. && (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)-> incxx . . $ fsm_state#in. != -1; (h->curr_ptrcxx . . $ apply_handle#curr_ptr.)++) { |
| 715 | vcount++; |
| 716 | } |
| 717 | if (vcount > 0) { |
| 718 | h->curr_ptrcxx . . $ apply_handle#curr_ptr. = h->ptrcxx . . $ apply_handle#ptr. + (randcxx . . $ rand(b126dc7c1de90089).() % vcount); |
| 719 | } else { |
| 720 | h->curr_ptrcxx . . $ apply_handle#curr_ptr. = h->ptrcxx . . $ apply_handle#ptr.; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | if (((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) { |
| 725 | symin = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->incxx . . $ fsm_state#in.; |
| 726 | symout = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->outcxx . . $ fsm_state#out.; |
| 727 | } else { |
| 728 | symin = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->outcxx . . $ fsm_state#out.; |
| 729 | symout = (h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->incxx . . $ fsm_state#in.; |
| 730 | } |
| 731 | |
| 732 | marksource = *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.); |
| 733 | marktarget = *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+(*(h->statemapcxx . . $ apply_handle#statemap.+(h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->targetcxx . . $ fsm_state#target.)))->state_nocxx . . $ fsm_state#state_no.); |
| 734 | |
| 735 | eatupi = apply_match_lengthcxx . . $ apply_match_length(f4e47f211469df87).(h, symin); |
| 736 | |
| 737 | if (eatupi == -1 || -1-(h->iposcxx . . $ apply_handle#ipos.)-eatupi == marktarget) { continue; } /* loop check */ |
| 738 | if ((eatupi = apply_match_strcxx . . $ apply_match_str(556b40fe8d924c4).(h, symin, h->iposcxx . . $ apply_handle#ipos.)) != -1) { |
| 739 | eatupo = apply_appendcxx . . $ apply_append(556b40fe8d924c4).(h, h->curr_ptrcxx . . $ apply_handle#curr_ptr., symout); |
| 740 | if (h->obey_flagscxx . . $ apply_handle#obey_flags. && h->has_flagscxx . . $ apply_handle#has_flags. && ((h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symin)->typecxx . . $ flag_lookup#type. & (FLAG_UNIFYcxx . . $ `fomalib.h:75:9`!|FLAG_CLEARcxx . . $ `fomalib.h:76:9`!|FLAG_POSITIVEcxx . . $ `fomalib.h:79:9`!|FLAG_NEGATIVEcxx . . $ `fomalib.h:78:9`!))) { |
| 741 | |
| 742 | fname = (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symin)->namecxx . . $ flag_lookup#name.; |
| 743 | fvalue = h->oldflagvaluecxx . . $ apply_handle#oldflagvalue.; |
| 744 | fneg = h->oldflagnegcxx . . $ apply_handle#oldflagneg.; |
| 745 | } else { |
| 746 | fname = fvalue = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 747 | fneg = 0; |
| 748 | } |
| 749 | |
| 750 | /* Push old position */ |
| 751 | apply_stack_pushcxx . . $ apply_stack_push(ac3602237fb36a).(h, marksource, fname, fvalue, fneg); |
| 752 | |
| 753 | /* Follow arc */ |
| 754 | h->ptrcxx . . $ apply_handle#ptr. = *(h->statemapcxx . . $ apply_handle#statemap.+(h->gstatescxx . . $ apply_handle#gstates.+h->curr_ptrcxx . . $ apply_handle#curr_ptr.)->targetcxx . . $ fsm_state#target.); |
| 755 | h->iposcxx . . $ apply_handle#ipos. += eatupi; |
| 756 | h->oposcxx . . $ apply_handle#opos. += eatupo; |
| 757 | apply_set_iptrcxx . . $ apply_set_iptr(dcfc4a94b3eb08e5).(h); |
| 758 | return(1); |
| 759 | } |
| 760 | } |
| 761 | return(0); |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | char *apply_return_stringcxx . . $ apply_return_string(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 766 | /* Stick a 0 to endpos to avoid getting old accumulated gunk strings printed */ |
| 767 | *(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos.) = '\0'; |
| 768 | if (((h->modecxx . . $ apply_handle#mode.) & RANDOMcxx . . $ `apply.c:25:9`!) == RANDOMcxx . . $ `apply.c:25:9`!) { |
| 769 | /* To end or not to end */ |
| 770 | if (!(randcxx . . $ rand(b126dc7c1de90089).() % 2)) { |
| 771 | apply_stack_clearcxx . . $ apply_stack_clear(dcfc4a94b3eb08e5).(h); |
| 772 | h->iteratorcxx . . $ apply_handle#iterator. = 0; |
| 773 | h->iterate_oldcxx . . $ apply_handle#iterate_old. = 0; |
| 774 | return(h->outstringcxx . . $ apply_handle#outstring.); |
| 775 | } |
| 776 | } else { |
| 777 | return(h->outstringcxx . . $ apply_handle#outstring.); |
| 778 | } |
| 779 | return(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 780 | } |
| 781 | |
| 782 | void apply_mark_statecxx . . $ apply_mark_state(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 783 | |
| 784 | /* This controls the how epsilon-loops are traversed. Such loops can */ |
| 785 | /* only be followed once to reach a state already visited in the DFS. */ |
| 786 | /* This requires that we store the number of input symbols consumed */ |
| 787 | /* whenever we enter a new state. If we enter the same state twice */ |
| 788 | /* with the same number of input symbols consumed, we abandon the search */ |
| 789 | /* for that branch. Flags are epsilons from this point of view. */ |
| 790 | /* The encoding of h->marks is: */ |
| 791 | /* 0 = unseen, +ipos = seen at ipos, -ipos = seen second time at ipos */ |
| 792 | |
| 793 | if ((h->modecxx . . $ apply_handle#mode. & RANDOMcxx . . $ `apply.c:25:9`!) != RANDOMcxx . . $ `apply.c:25:9`!) { |
| 794 | if (*(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.) == h->iposcxx . . $ apply_handle#ipos.+1) { |
| 795 | *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.) = -(h->iposcxx . . $ apply_handle#ipos.+1); |
| 796 | } else { |
| 797 | *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.) = h->iposcxx . . $ apply_handle#ipos.+1; |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | void apply_skip_this_arccxx . . $ apply_skip_this_arc(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 803 | /* If we have index ptr */ |
| 804 | if (h->iptrcxx . . $ apply_handle#iptr.) { |
| 805 | h->ptrcxx . . $ apply_handle#ptr. = h->iptrcxx . . $ apply_handle#iptr.->fsmptrcxx . . $ apply_state_index#fsmptr.; |
| 806 | h->iptrcxx . . $ apply_handle#iptr. = h->iptrcxx . . $ apply_handle#iptr.->nextcxx . . $ apply_state_index#next.; |
| 807 | /* Otherwise */ |
| 808 | } else { |
| 809 | (h->ptrcxx . . $ apply_handle#ptr.)++; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | int apply_at_last_arccxx . . $ apply_at_last_arc(aafcfc4baa0a05e2).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 814 | int seeksym, nextsym; |
| 815 | if (h->state_has_indexcxx . . $ apply_handle#state_has_index.) { |
| 816 | if (h->iptrcxx . . $ apply_handle#iptr.->nextcxx . . $ apply_state_index#next. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || h->iptrcxx . . $ apply_handle#iptr.->nextcxx . . $ apply_state_index#next.->fsmptrcxx . . $ apply_state_index#fsmptr. == -1) { |
| 817 | return 1; |
| 818 | } |
| 819 | } else { |
| 820 | if ((h->binsearchcxx . . $ apply_handle#binsearch. && !(h->has_flagscxx . . $ apply_handle#has_flags.)) || (h->binsearchcxx . . $ apply_handle#binsearch. && !(BITTESTcxx . . $ `apply.c:46:9`!(h->flagstates, (h->gstates+h->ptr)->state_no)))) { |
| 821 | if ((h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no. != (h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.+1)->state_nocxx . . $ fsm_state#state_no.) { |
| 822 | return 1; |
| 823 | } |
| 824 | seeksym = (h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+h->iposcxx . . $ apply_handle#ipos.)->signumbercxx . . $ sigmatch_array#signumber.; |
| 825 | nextsym = (((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) ? (h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->incxx . . $ fsm_state#in. : (h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->outcxx . . $ fsm_state#out.; |
| 826 | if (nextsym == -1 || seeksym < nextsym) { |
| 827 | return 1; |
| 828 | } |
| 829 | } else { |
| 830 | if ((h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no. != (h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.+1)->state_nocxx . . $ fsm_state#state_no.) { |
| 831 | return 1; |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | /* map h->ptr (line pointer) to h->iptr (index pointer) */ |
| 839 | void apply_set_iptrcxx . . $ apply_set_iptr(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 840 | struct apply_state_indexcxx . . $ apply_state_index# **idx, *sidx; |
| 841 | int stateno, seeksym; |
| 842 | /* Check if state has index */ |
| 843 | if ((idx = ((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`! ? (h->index_incxx . . $ apply_handle#index_in.) : (h->index_outcxx . . $ apply_handle#index_out.)) == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 844 | return; |
| 845 | } |
| 846 | |
| 847 | h->iptrcxx . . $ apply_handle#iptr. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 848 | h->state_has_indexcxx . . $ apply_handle#state_has_index. = 0; |
| 849 | stateno = (h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.; |
| 850 | if (stateno < 0) { |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | sidx = *(idx + stateno); |
| 855 | if (sidx == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { return; } |
| 856 | seeksym = (h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+h->iposcxx . . $ apply_handle#ipos.)->signumbercxx . . $ sigmatch_array#signumber.; |
| 857 | h->state_has_indexcxx . . $ apply_handle#state_has_index. = 1; |
| 858 | sidx = sidx + seeksym; |
| 859 | if (sidx->fsmptrcxx . . $ apply_state_index#fsmptr. == -1) { |
| 860 | if (sidx->nextcxx . . $ apply_state_index#next. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 861 | return; |
| 862 | } else { |
| 863 | sidx = sidx->nextcxx . . $ apply_state_index#next.; |
| 864 | } |
| 865 | } |
| 866 | h->iptrcxx . . $ apply_handle#iptr. = sidx; |
| 867 | if (sidx->fsmptrcxx . . $ apply_state_index#fsmptr. == -1) { |
| 868 | h->iptrcxx . . $ apply_handle#iptr. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 869 | } |
| 870 | h->state_has_indexcxx . . $ apply_handle#state_has_index. = 1; |
| 871 | } |
| 872 | |
| 873 | char *apply_netcxx . . $ apply_net(99adbf620860b308).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 874 | |
| 875 | /* We perform a basic DFS on the graph, with two minor complications: */ |
| 876 | |
| 877 | /* 1. We keep a mark for each state which indicates how many input symbols */ |
| 878 | /* we had consumed the last time we entered that state on the current */ |
| 879 | /* "run." If we reach a state seen twice without consuming input, we */ |
| 880 | /* terminate that branch of the search. */ |
| 881 | /* As we pop a position, we also unmark the state we came from. */ |
| 882 | |
| 883 | /* 2. If the graph has flags, we push the previous flag value when */ |
| 884 | /* traversing a flag-modifying arc (P,U,N, or C). This is because a */ |
| 885 | /* flag may have been set during the previous "run" and may not apply. */ |
| 886 | /* Since we're doing a DFS, we can be sure to return to the previous */ |
| 887 | /* global flag state by just remembering that last flag change. */ |
| 888 | |
| 889 | /* 3. The whole system needs to work as an iterator, meaning we need to */ |
| 890 | /* store the global state of the search so we can resume it later to */ |
| 891 | /* to yield more possible output words with the same input string. */ |
| 892 | |
| 893 | char *returnstring; |
| 894 | |
| 895 | if (h->iterate_oldcxx . . $ apply_handle#iterate_old. == 1) { /* If called with NULL as the input word, this will be set */ |
| 896 | goto resume; |
| 897 | } |
| 898 | |
| 899 | h->iptrcxx . . $ apply_handle#iptr. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; h->ptrcxx . . $ apply_handle#ptr. = 0; h->iposcxx . . $ apply_handle#ipos. = 0; h->oposcxx . . $ apply_handle#opos. = 0; |
| 900 | apply_set_iptrcxx . . $ apply_set_iptr(dcfc4a94b3eb08e5).(h); |
| 901 | |
| 902 | apply_stack_clearcxx . . $ apply_stack_clear(dcfc4a94b3eb08e5).(h); |
| 903 | |
| 904 | if (h->has_flagscxx . . $ apply_handle#has_flags.) { |
| 905 | apply_clear_flagscxx . . $ apply_clear_flags(dcfc4a94b3eb08e5).(h); |
| 906 | } |
| 907 | |
| 908 | /* "The use of four-letter words like goto can occasionally be justified */ |
| 909 | /* even in the best of company." Knuth (1974). */ |
| 910 | |
| 911 | goto L2; |
| 912 | |
| 913 | while(!apply_stack_isemptycxx . . $ apply_stack_isempty(aafcfc4baa0a05e2).(h)) { |
| 914 | apply_stack_popcxx . . $ apply_stack_pop(dcfc4a94b3eb08e5).(h); |
| 915 | /* If last line was popped */ |
| 916 | if (apply_at_last_arccxx . . $ apply_at_last_arc(aafcfc4baa0a05e2).(h)) { |
| 917 | *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.) = 0; /* Unmark */ |
| 918 | continue; /* pop next */ |
| 919 | } |
| 920 | apply_skip_this_arccxx . . $ apply_skip_this_arc(dcfc4a94b3eb08e5).(h); /* skip old pushed arc */ |
| 921 | L1: |
| 922 | if (!apply_follow_next_arccxx . . $ apply_follow_next_arc(aafcfc4baa0a05e2).(h)) { |
| 923 | *(h->markscxx . . $ apply_handle#marks.+(h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->state_nocxx . . $ fsm_state#state_no.) = 0; /* Unmark */ |
| 924 | continue; /* pop next */ |
| 925 | } |
| 926 | L2: |
| 927 | /* Print accumulated string upon entry to state */ |
| 928 | if ((h->gstatescxx . . $ apply_handle#gstates.+h->ptrcxx . . $ apply_handle#ptr.)->final_statecxx . . $ fsm_state#final_state. == 1 && (h->iposcxx . . $ apply_handle#ipos. == h->current_instring_lengthcxx . . $ apply_handle#current_instring_length. || ((h->modecxx . . $ apply_handle#mode.) & ENUMERATEcxx . . $ `apply.c:26:9`!) == ENUMERATEcxx . . $ `apply.c:26:9`!)) { |
| 929 | if ((returnstring = (apply_return_stringcxx . . $ apply_return_string(99adbf620860b308).(h))) != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 930 | return(returnstring); |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | resume: |
| 935 | apply_mark_statecxx . . $ apply_mark_state(dcfc4a94b3eb08e5).(h); /* Mark upon arrival to new state */ |
| 936 | goto L1; |
| 937 | } |
| 938 | if ((h->modecxx . . $ apply_handle#mode. & RANDOMcxx . . $ `apply.c:25:9`!) == RANDOMcxx . . $ `apply.c:25:9`!) { |
| 939 | apply_stack_clearcxx . . $ apply_stack_clear(dcfc4a94b3eb08e5).(h); |
| 940 | h->iteratorcxx . . $ apply_handle#iterator. = 0; |
| 941 | h->iterate_oldcxx . . $ apply_handle#iterate_old. = 0; |
| 942 | return(h->outstringcxx . . $ apply_handle#outstring.); |
| 943 | } |
| 944 | apply_stack_clearcxx . . $ apply_stack_clear(dcfc4a94b3eb08e5).(h); |
| 945 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 946 | } |
| 947 | |
| 948 | int apply_appendcxx . . $ apply_append(556b40fe8d924c4).(struct apply_handlecxx . . $ apply_handle# *h, int cptr, int sym) { |
| 949 | |
| 950 | char *astring, *bstring, *pstring; |
| 951 | int symin, symout, len, alen, blen, idlen; |
| 952 | |
| 953 | symin = (h->gstatescxx . . $ apply_handle#gstates.+cptr)->incxx . . $ fsm_state#in.; |
| 954 | symout = (h->gstatescxx . . $ apply_handle#gstates.+cptr)->outcxx . . $ fsm_state#out.; |
| 955 | astring = ((h->sigscxx . . $ apply_handle#sigs.)+symin)->symbolcxx . . $ sigs#symbol.; |
| 956 | alen = ((h->sigscxx . . $ apply_handle#sigs.)+symin)->lengthcxx . . $ sigs#length.; |
| 957 | bstring = ((h->sigscxx . . $ apply_handle#sigs.)+symout)->symbolcxx . . $ sigs#symbol.; |
| 958 | blen = ((h->sigscxx . . $ apply_handle#sigs.)+symout)->lengthcxx . . $ sigs#length.; |
| 959 | |
| 960 | while (alen + blen + h->oposcxx . . $ apply_handle#opos. + 2 + strlencxx . . $ strlen(751346f8406fd082).(h->separatorcxx . . $ apply_handle#separator.) >= h->outstringtopcxx . . $ apply_handle#outstringtop.) { |
| 961 | // while (alen + blen + h->opos + 3 >= h->outstringtop) { |
| 962 | h->outstringcxx . . $ apply_handle#outstring. = realloccxx . . $ realloc(417ab160f6baadc6).(h->outstringcxx . . $ apply_handle#outstring., sizeof(char) * ((h->outstringtopcxx . . $ apply_handle#outstringtop.) * 2)); |
| 963 | (h->outstringtopcxx . . $ apply_handle#outstringtop.) *= 2; |
| 964 | } |
| 965 | |
| 966 | if ((h->has_flagscxx . . $ apply_handle#has_flags.) && !h->show_flagscxx . . $ apply_handle#show_flags. && (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symin)->typecxx . . $ flag_lookup#type.) { |
| 967 | astring = ""; alen = 0; |
| 968 | } |
| 969 | if (h->has_flagscxx . . $ apply_handle#has_flags. && !h->show_flagscxx . . $ apply_handle#show_flags. && (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symout)->typecxx . . $ flag_lookup#type.) { |
| 970 | bstring = ""; blen = 0; |
| 971 | } |
| 972 | if (((h->modecxx . . $ apply_handle#mode.) & ENUMERATEcxx . . $ `apply.c:26:9`!) == ENUMERATEcxx . . $ `apply.c:26:9`!) { |
| 973 | /* Print both sides separated by colon */ |
| 974 | /* if we're printing "words" */ |
| 975 | if (((h->modecxx . . $ apply_handle#mode.) & (UPPERcxx . . $ `apply.c:31:9`! | LOWERcxx . . $ `apply.c:30:9`!)) == (UPPERcxx . . $ `apply.c:31:9`!|LOWERcxx . . $ `apply.c:30:9`!)) { |
| 976 | |
| 977 | if (astring == bstring) { |
| 978 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos., astring); |
| 979 | len = alen; |
| 980 | } else { |
| 981 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos., astring); |
| 982 | // strcpy(h->outstring+h->opos+alen,":"); |
| 983 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos.+alen,h->separatorcxx . . $ apply_handle#separator.); |
| 984 | //strcpy(h->outstring+h->opos+alen+1,bstring); |
| 985 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos.+alen+strlencxx . . $ strlen(751346f8406fd082).(h->separatorcxx . . $ apply_handle#separator.),bstring); |
| 986 | // len = alen+blen+1; |
| 987 | len = alen+blen+strlencxx . . $ strlen(751346f8406fd082).(h->separatorcxx . . $ apply_handle#separator.); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | /* Print one side only */ |
| 992 | if (((h->modecxx . . $ apply_handle#mode.) & (UPPERcxx . . $ `apply.c:31:9`!|LOWERcxx . . $ `apply.c:30:9`!)) != (UPPERcxx . . $ `apply.c:31:9`!|LOWERcxx . . $ `apply.c:30:9`!)) { |
| 993 | |
| 994 | if (symin == EPSILONcxx . . $ `fomalib.h:49:9`!) { |
| 995 | astring = ""; alen = 0; |
| 996 | } |
| 997 | if (symout == EPSILONcxx . . $ `fomalib.h:49:9`!) { |
| 998 | bstring = ""; blen = 0; |
| 999 | } |
| 1000 | if (((h->modecxx . . $ apply_handle#mode.) & (UPPERcxx . . $ `apply.c:31:9`!|LOWERcxx . . $ `apply.c:30:9`!)) == UPPERcxx . . $ `apply.c:31:9`!) { |
| 1001 | pstring = astring; |
| 1002 | len = alen; |
| 1003 | } else { |
| 1004 | pstring = bstring; |
| 1005 | len = blen; |
| 1006 | } |
| 1007 | //strcpy(h->outstring+h->opos, pstring); |
| 1008 | memcpycxx . . $ memcpy(cc817cb175f282d).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos., pstring, len); |
| 1009 | } |
| 1010 | } |
| 1011 | if (((h->modecxx . . $ apply_handle#mode.) & ENUMERATEcxx . . $ `apply.c:26:9`!) != ENUMERATEcxx . . $ `apply.c:26:9`!) { |
| 1012 | /* Print pairs is ON and symbols are different */ |
| 1013 | if (h->print_pairscxx . . $ apply_handle#print_pairs. && (symin != symout)) { |
| 1014 | |
| 1015 | if (symin == UNKNOWNcxx . . $ `fomalib.h:50:9`! && ((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) |
| 1016 | strncpycxx . . $ strncpy(255158a415b673b0).(astring, h->instringcxx . . $ apply_handle#instring.+h->iposcxx . . $ apply_handle#ipos., 1); |
| 1017 | if (symout == UNKNOWNcxx . . $ `fomalib.h:50:9`! && ((h->modecxx . . $ apply_handle#mode.) & UPcxx . . $ `apply.c:28:9`!) == UPcxx . . $ `apply.c:28:9`!) |
| 1018 | strncpycxx . . $ strncpy(255158a415b673b0).(bstring, h->instringcxx . . $ apply_handle#instring.+h->iposcxx . . $ apply_handle#ipos., 1); |
| 1019 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos., "<"); |
| 1020 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos.+1, astring); |
| 1021 | //strcpy(h->outstring+h->opos+alen+1,":"); |
| 1022 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos.+alen+1,h->separatorcxx . . $ apply_handle#separator.); |
| 1023 | //strcpy(h->outstring+h->opos+alen+2,bstring); |
| 1024 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos.+alen+1+strlencxx . . $ strlen(751346f8406fd082).(h->separatorcxx . . $ apply_handle#separator.), bstring); |
| 1025 | //strcpy(h->outstring+h->opos+alen+blen+2,">"); |
| 1026 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos.+alen+blen+1+strlencxx . . $ strlen(751346f8406fd082).(h->separatorcxx . . $ apply_handle#separator.),">"); |
| 1027 | //len = alen+blen+3; |
| 1028 | len = alen+blen+2+strlencxx . . $ strlen(751346f8406fd082).(h->separatorcxx . . $ apply_handle#separator.); |
| 1029 | } |
| 1030 | |
| 1031 | else if (sym == IDENTITYcxx . . $ `fomalib.h:51:9`!) { |
| 1032 | /* Apply up/down */ |
| 1033 | //idlen = utf8skip(h->instring+h->ipos)+1; |
| 1034 | idlen = (h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+h->iposcxx . . $ apply_handle#ipos.)->consumescxx . . $ sigmatch_array#consumes.; // here |
| 1035 | strncpycxx . . $ strncpy(255158a415b673b0).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos., h->instringcxx . . $ apply_handle#instring.+h->iposcxx . . $ apply_handle#ipos., idlen); |
| 1036 | strncpycxx . . $ strncpy(255158a415b673b0).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos.+idlen,"", 1); |
| 1037 | len = idlen; |
| 1038 | } else if (sym == EPSILONcxx . . $ `fomalib.h:49:9`!) { |
| 1039 | return(0); |
| 1040 | } else { |
| 1041 | if (((h->modecxx . . $ apply_handle#mode.) & DOWNcxx . . $ `apply.c:29:9`!) == DOWNcxx . . $ `apply.c:29:9`!) { |
| 1042 | pstring = bstring; |
| 1043 | len = blen; |
| 1044 | } else { |
| 1045 | pstring = astring; |
| 1046 | len = alen; |
| 1047 | } |
| 1048 | memcpycxx . . $ memcpy(cc817cb175f282d).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos., pstring, len); |
| 1049 | } |
| 1050 | } |
| 1051 | if (h->print_spacecxx . . $ apply_handle#print_space. && len > 0) { |
| 1052 | strcpycxx . . $ strcpy(b7b3a83273496486).(h->outstringcxx . . $ apply_handle#outstring.+h->oposcxx . . $ apply_handle#opos.+len, h->space_symbolcxx . . $ apply_handle#space_symbol.); |
| 1053 | len++; |
| 1054 | } |
| 1055 | return(len); |
| 1056 | } |
| 1057 | |
| 1058 | int apply_match_lengthcxx . . $ apply_match_length(f4e47f211469df87).(struct apply_handlecxx . . $ apply_handle# *h, int symbol) { |
| 1059 | if (symbol == EPSILONcxx . . $ `fomalib.h:49:9`!) { |
| 1060 | return 0; |
| 1061 | } |
| 1062 | if (h->has_flagscxx . . $ apply_handle#has_flags. && (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symbol)->typecxx . . $ flag_lookup#type.) { |
| 1063 | return 0; |
| 1064 | } |
| 1065 | if (((h->modecxx . . $ apply_handle#mode.) & ENUMERATEcxx . . $ `apply.c:26:9`!) == ENUMERATEcxx . . $ `apply.c:26:9`!) { |
| 1066 | return 0; |
| 1067 | } |
| 1068 | if (h->iposcxx . . $ apply_handle#ipos. >= h->current_instring_lengthcxx . . $ apply_handle#current_instring_length.) { |
| 1069 | return -1; |
| 1070 | } |
| 1071 | if ((h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+(h->iposcxx . . $ apply_handle#ipos.))->signumbercxx . . $ sigmatch_array#signumber. == symbol) { |
| 1072 | return((h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+(h->iposcxx . . $ apply_handle#ipos.))->consumescxx . . $ sigmatch_array#consumes.); |
| 1073 | } |
| 1074 | if ((symbol == IDENTITYcxx . . $ `fomalib.h:51:9`!) || (symbol == UNKNOWNcxx . . $ `fomalib.h:50:9`!)) { |
| 1075 | if ((h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+h->iposcxx . . $ apply_handle#ipos.)->signumbercxx . . $ sigmatch_array#signumber. == IDENTITYcxx . . $ `fomalib.h:51:9`!) { |
| 1076 | return((h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+(h->iposcxx . . $ apply_handle#ipos.))->consumescxx . . $ sigmatch_array#consumes.); |
| 1077 | } |
| 1078 | } |
| 1079 | return -1; |
| 1080 | } |
| 1081 | |
| 1082 | /* Match a symbol from sigma against the current position in string */ |
| 1083 | /* Return the number of symbols consumed in input string */ |
| 1084 | /* For flags, we consume 0 symbols of the input string, naturally */ |
| 1085 | |
| 1086 | int apply_match_strcxx . . $ apply_match_str(556b40fe8d924c4).(struct apply_handlecxx . . $ apply_handle# *h, int symbol, int position) { |
| 1087 | if (((h->modecxx . . $ apply_handle#mode.) & ENUMERATEcxx . . $ `apply.c:26:9`!) == ENUMERATEcxx . . $ `apply.c:26:9`!) { |
| 1088 | if (h->has_flagscxx . . $ apply_handle#has_flags. && (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symbol)->typecxx . . $ flag_lookup#type.) { |
| 1089 | if (!h->obey_flagscxx . . $ apply_handle#obey_flags.) { |
| 1090 | return 0; |
| 1091 | } |
| 1092 | if (apply_check_flagcxx . . $ apply_check_flag(6d966aa81daf532d).(h,(h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symbol)->typecxx . . $ flag_lookup#type., (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symbol)->namecxx . . $ flag_lookup#name., (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symbol)->valuecxx . . $ flag_lookup#value.) == SUCCEEDcxx . . $ `apply.c:35:9`!) { |
| 1093 | return 0; |
| 1094 | } else { |
| 1095 | return -1; |
| 1096 | } |
| 1097 | } |
| 1098 | return(0); |
| 1099 | } |
| 1100 | |
| 1101 | |
| 1102 | if (symbol == EPSILONcxx . . $ `fomalib.h:49:9`!) { |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
| 1106 | /* If symbol is a flag, we need to check consistency */ |
| 1107 | if (h->has_flagscxx . . $ apply_handle#has_flags. && (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symbol)->typecxx . . $ flag_lookup#type.) { |
| 1108 | if (!h->obey_flagscxx . . $ apply_handle#obey_flags.) { |
| 1109 | return 0; |
| 1110 | } |
| 1111 | if (apply_check_flagcxx . . $ apply_check_flag(6d966aa81daf532d).(h,(h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symbol)->typecxx . . $ flag_lookup#type., (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symbol)->namecxx . . $ flag_lookup#name., (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+symbol)->valuecxx . . $ flag_lookup#value.) == SUCCEEDcxx . . $ `apply.c:35:9`!) { |
| 1112 | return 0; |
| 1113 | } else { |
| 1114 | return -1; |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | if (position >= h->current_instring_lengthcxx . . $ apply_handle#current_instring_length.) { |
| 1119 | return -1; |
| 1120 | } |
| 1121 | if ((h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+position)->signumbercxx . . $ sigmatch_array#signumber. == symbol) { |
| 1122 | return((h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+position)->consumescxx . . $ sigmatch_array#consumes.); |
| 1123 | } |
| 1124 | if ((symbol == IDENTITYcxx . . $ `fomalib.h:51:9`!) || (symbol == UNKNOWNcxx . . $ `fomalib.h:50:9`!)) { |
| 1125 | if ((h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+position)->signumbercxx . . $ sigmatch_array#signumber. == IDENTITYcxx . . $ `fomalib.h:51:9`!) { |
| 1126 | return((h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+position)->consumescxx . . $ sigmatch_array#consumes.); |
| 1127 | } |
| 1128 | } |
| 1129 | return -1; |
| 1130 | } |
| 1131 | |
| 1132 | void apply_create_statemapcxx . . $ apply_create_statemap(a7639cec993cd95d).(struct apply_handlecxx . . $ apply_handle# *h, struct fsmcxx . . $ fsm# *net) { |
| 1133 | int i; |
| 1134 | struct fsm_statecxx . . $ fsm_state# *fsm; |
| 1135 | fsm = net->statescxx . . $ fsm#states.; |
| 1136 | h->statemapcxx . . $ apply_handle#statemap. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(int)*net->statecountcxx . . $ fsm#statecount.); |
| 1137 | h->markscxx . . $ apply_handle#marks. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(int)*net->statecountcxx . . $ fsm#statecount.); |
| 1138 | h->numlinescxx . . $ apply_handle#numlines. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(int)*net->statecountcxx . . $ fsm#statecount.); |
| 1139 | |
| 1140 | for (i=0; i < net->statecountcxx . . $ fsm#statecount.; i++) { |
| 1141 | *(h->numlinescxx . . $ apply_handle#numlines.+i) = 0; /* Only needed in binary search */ |
| 1142 | *(h->statemapcxx . . $ apply_handle#statemap.+i) = -1; |
| 1143 | *(h->markscxx . . $ apply_handle#marks.+i) = 0; |
| 1144 | } |
| 1145 | for (i=0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) { |
| 1146 | *(h->numlinescxx . . $ apply_handle#numlines.+(fsm+i)->state_nocxx . . $ fsm_state#state_no.) = *(h->numlinescxx . . $ apply_handle#numlines.+(fsm+i)->state_nocxx . . $ fsm_state#state_no.)+1; |
| 1147 | if (*(h->statemapcxx . . $ apply_handle#statemap.+(fsm+i)->state_nocxx . . $ fsm_state#state_no.) == -1) { |
| 1148 | *(h->statemapcxx . . $ apply_handle#statemap.+(fsm+i)->state_nocxx . . $ fsm_state#state_no.) = i; |
| 1149 | } |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | void apply_add_sigma_triecxx . . $ apply_add_sigma_trie(655f8ce2d2509278).(struct apply_handlecxx . . $ apply_handle# *h, int number, char *symbol, int len) { |
| 1154 | |
| 1155 | /* Create a trie of sigma symbols (prefixes) so we can */ |
| 1156 | /* quickly (in O(n)) tokenize an arbitrary string into */ |
| 1157 | /* integer sequences representing symbols, using longest- */ |
| 1158 | /* leftmost factorization. */ |
| 1159 | |
| 1160 | int i; |
| 1161 | struct sigma_triecxx . . $ sigma_trie# *st; |
| 1162 | struct sigma_trie_arrayscxx . . $ sigma_trie_arrays# *sta; |
| 1163 | |
| 1164 | st = h->sigma_triecxx . . $ apply_handle#sigma_trie.; |
| 1165 | for (i = 0; i < len; i++) { |
| 1166 | st = st+(unsigned char)*(symbol+i); |
| 1167 | if (i == (len-1)) { |
| 1168 | st->signumcxx . . $ sigma_trie#signum. = number; |
| 1169 | } else { |
| 1170 | if (st->nextcxx . . $ sigma_trie#next. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1171 | st->nextcxx . . $ sigma_trie#next. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(256,sizeof(struct sigma_triecxx . . $ sigma_trie#)); |
| 1172 | st = st->nextcxx . . $ sigma_trie#next.; |
| 1173 | /* store these arrays to free them later */ |
| 1174 | sta = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct sigma_trie_arrayscxx . . $ sigma_trie_arrays#)); |
| 1175 | sta->arrcxx . . $ sigma_trie_arrays#arr. = st; |
| 1176 | sta->nextcxx . . $ sigma_trie_arrays#next. = h->sigma_trie_arrayscxx . . $ apply_handle#sigma_trie_arrays.; |
| 1177 | h->sigma_trie_arrayscxx . . $ apply_handle#sigma_trie_arrays. = sta; |
| 1178 | } else { |
| 1179 | st = st->nextcxx . . $ sigma_trie#next.; |
| 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | void apply_mark_flagstatescxx . . $ apply_mark_flagstates(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 1186 | int i; |
| 1187 | struct fsm_statecxx . . $ fsm_state# *fsm; |
| 1188 | |
| 1189 | /* Create bitarray with those states that have a flag symbol on an arc */ |
| 1190 | /* This is needed to decide whether we can perform a binary search. */ |
| 1191 | |
| 1192 | if (!h->has_flagscxx . . $ apply_handle#has_flags. || h->flag_lookupcxx . . $ apply_handle#flag_lookup. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1193 | return; |
| 1194 | } |
| 1195 | if (h->flagstatescxx . . $ apply_handle#flagstates.) { |
| 1196 | freecxx . . $ free(5d22bdacc48458e8).(h->flagstatescxx . . $ apply_handle#flagstates.); |
| 1197 | } |
| 1198 | h->flagstatescxx . . $ apply_handle#flagstates. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(BITNSLOTScxx . . $ `apply.c:47:9`!(h->last_net->statecount), sizeof(uint8_tcxx . . $ uint8_t#)); |
| 1199 | fsm = h->last_netcxx . . $ apply_handle#last_net.->statescxx . . $ fsm#states.; |
| 1200 | for (i=0; (fsm+i)->state_nocxx . . $ fsm_state#state_no. != -1; i++) { |
| 1201 | if ((fsm+i)->targetcxx . . $ fsm_state#target. == -1) { |
| 1202 | continue; |
| 1203 | } |
| 1204 | if ((h->flag_lookupcxx . . $ apply_handle#flag_lookup.+(fsm+i)->incxx . . $ fsm_state#in.)->typecxx . . $ flag_lookup#type.) { |
| 1205 | BITSETcxx . . $ `apply.c:44:9`!(h->flagstates,(fsm+i)->state_no); |
| 1206 | } |
| 1207 | if ((h->flag_lookupcxx . . $ apply_handle#flag_lookup.+(fsm+i)->outcxx . . $ fsm_state#out.)->typecxx . . $ flag_lookup#type.) { |
| 1208 | BITSETcxx . . $ `apply.c:44:9`!(h->flagstates,(fsm+i)->state_no); |
| 1209 | } |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | void apply_create_sigarraycxx . . $ apply_create_sigarray(a7639cec993cd95d).(struct apply_handlecxx . . $ apply_handle# *h, struct fsmcxx . . $ fsm# *net) { |
| 1214 | struct sigmacxx . . $ sigma# *sig; |
| 1215 | int i, maxsigma; |
| 1216 | |
| 1217 | maxsigma = sigma_maxcxx . . $ sigma_max(e25613b9dc6b48e4).(net->sigmacxx . . $ fsm#sigma.); |
| 1218 | h->sigma_sizecxx . . $ apply_handle#sigma_size. = maxsigma+1; |
| 1219 | // Default size created at init, resized later if necessary |
| 1220 | h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1024,sizeof(struct sigmatch_arraycxx . . $ sigmatch_array#)); |
| 1221 | h->sigmatch_array_sizecxx . . $ apply_handle#sigmatch_array_size. = 1024; |
| 1222 | |
| 1223 | h->sigscxx . . $ apply_handle#sigs. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct sigscxx . . $ sigs#)*(maxsigma+1)); |
| 1224 | h->has_flagscxx . . $ apply_handle#has_flags. = 0; |
| 1225 | h->flag_listcxx . . $ apply_handle#flag_list. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 1226 | |
| 1227 | /* Malloc first array of trie and store trie ptrs to be able to free later */ |
| 1228 | /* when apply_clear() is called. */ |
| 1229 | |
| 1230 | h->sigma_triecxx . . $ apply_handle#sigma_trie. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(256,sizeof(struct sigma_triecxx . . $ sigma_trie#)); |
| 1231 | h->sigma_trie_arrayscxx . . $ apply_handle#sigma_trie_arrays. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct sigma_trie_arrayscxx . . $ sigma_trie_arrays#)); |
| 1232 | h->sigma_trie_arrayscxx . . $ apply_handle#sigma_trie_arrays.->arrcxx . . $ sigma_trie_arrays#arr. = h->sigma_triecxx . . $ apply_handle#sigma_trie.; |
| 1233 | h->sigma_trie_arrayscxx . . $ apply_handle#sigma_trie_arrays.->nextcxx . . $ sigma_trie_arrays#next. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 1234 | |
| 1235 | for (i=0;i<256;i++) |
| 1236 | (h->sigma_triecxx . . $ apply_handle#sigma_trie.+i)->nextcxx . . $ sigma_trie#next. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 1237 | for (sig = h->gsigmacxx . . $ apply_handle#gsigma.; sig != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && sig->numbercxx . . $ sigma#number. != -1; sig = sig->nextcxx . . $ sigma#next.) { |
| 1238 | if (flag_checkcxx . . $ flag_check(1ef8e6ec083aabb9).(sig->symbolcxx . . $ sigma#symbol.)) { |
| 1239 | h->has_flagscxx . . $ apply_handle#has_flags. = 1; |
| 1240 | apply_add_flagcxx . . $ apply_add_flag(259e9dc864900f19).(h, flag_get_namecxx . . $ flag_get_name(7a9722d75b371431).(sig->symbolcxx . . $ sigma#symbol.)); |
| 1241 | } |
| 1242 | (h->sigscxx . . $ apply_handle#sigs.+(sig->numbercxx . . $ sigma#number.))->symbolcxx . . $ sigs#symbol. = sig->symbolcxx . . $ sigma#symbol.; |
| 1243 | (h->sigscxx . . $ apply_handle#sigs.+(sig->numbercxx . . $ sigma#number.))->lengthcxx . . $ sigs#length. = strlencxx . . $ strlen(751346f8406fd082).(sig->symbolcxx . . $ sigma#symbol.); |
| 1244 | /* Add sigma entry to trie */ |
| 1245 | if (sig->numbercxx . . $ sigma#number. > IDENTITYcxx . . $ `fomalib.h:51:9`!) { |
| 1246 | apply_add_sigma_triecxx . . $ apply_add_sigma_trie(655f8ce2d2509278).(h, sig->numbercxx . . $ sigma#number., sig->symbolcxx . . $ sigma#symbol., (h->sigscxx . . $ apply_handle#sigs.+(sig->numbercxx . . $ sigma#number.))->lengthcxx . . $ sigs#length.); |
| 1247 | } |
| 1248 | } |
| 1249 | if (maxsigma >= IDENTITYcxx . . $ `fomalib.h:51:9`!) { |
| 1250 | (h->sigscxx . . $ apply_handle#sigs.+EPSILONcxx . . $ `fomalib.h:49:9`!)->symbolcxx . . $ sigs#symbol. = h->epsilon_symbolcxx . . $ apply_handle#epsilon_symbol.; |
| 1251 | (h->sigscxx . . $ apply_handle#sigs.+EPSILONcxx . . $ `fomalib.h:49:9`!)->lengthcxx . . $ sigs#length. = strlencxx . . $ strlen(751346f8406fd082).(h->epsilon_symbolcxx . . $ apply_handle#epsilon_symbol.); |
| 1252 | (h->sigscxx . . $ apply_handle#sigs.+UNKNOWNcxx . . $ `fomalib.h:50:9`!)->symbolcxx . . $ sigs#symbol. = "?"; |
| 1253 | (h->sigscxx . . $ apply_handle#sigs.+UNKNOWNcxx . . $ `fomalib.h:50:9`!)->lengthcxx . . $ sigs#length. = 1; |
| 1254 | (h->sigscxx . . $ apply_handle#sigs.+IDENTITYcxx . . $ `fomalib.h:51:9`!)->symbolcxx . . $ sigs#symbol. = "@"; |
| 1255 | (h->sigscxx . . $ apply_handle#sigs.+IDENTITYcxx . . $ `fomalib.h:51:9`!)->lengthcxx . . $ sigs#length. = 1; |
| 1256 | } |
| 1257 | if (h->has_flagscxx . . $ apply_handle#has_flags.) { |
| 1258 | |
| 1259 | h->flag_lookupcxx . . $ apply_handle#flag_lookup. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct flag_lookupcxx . . $ flag_lookup#)*(maxsigma+1)); |
| 1260 | for (i=0; i <= maxsigma; i++) { |
| 1261 | (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+i)->typecxx . . $ flag_lookup#type. = 0; |
| 1262 | (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+i)->namecxx . . $ flag_lookup#name. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 1263 | (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+i)->valuecxx . . $ flag_lookup#value. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 1264 | } |
| 1265 | for (sig = h->gsigmacxx . . $ apply_handle#gsigma.; sig != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! ; sig = sig->nextcxx . . $ sigma#next.) { |
| 1266 | if (flag_checkcxx . . $ flag_check(1ef8e6ec083aabb9).(sig->symbolcxx . . $ sigma#symbol.)) { |
| 1267 | (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+sig->numbercxx . . $ sigma#number.)->typecxx . . $ flag_lookup#type. = flag_get_typecxx . . $ flag_get_type(1ef8e6ec083aabb9).(sig->symbolcxx . . $ sigma#symbol.); |
| 1268 | (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+sig->numbercxx . . $ sigma#number.)->namecxx . . $ flag_lookup#name. = flag_get_namecxx . . $ flag_get_name(7a9722d75b371431).(sig->symbolcxx . . $ sigma#symbol.); |
| 1269 | (h->flag_lookupcxx . . $ apply_handle#flag_lookup.+sig->numbercxx . . $ sigma#number.)->valuecxx . . $ flag_lookup#value. = flag_get_valuecxx . . $ flag_get_value(7a9722d75b371431).(sig->symbolcxx . . $ sigma#symbol.); |
| 1270 | } |
| 1271 | } |
| 1272 | apply_mark_flagstatescxx . . $ apply_mark_flagstates(dcfc4a94b3eb08e5).(h); |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | /* We need to know which symbols in sigma we can match for all positions */ |
| 1277 | /* in the input string. Alternatively, if there is no input string as is the case */ |
| 1278 | /* when we just list the words or randomly search the graph, we can match */ |
| 1279 | /* any symbol in sigma. */ |
| 1280 | |
| 1281 | /* We create an array that for each position in the input string */ |
| 1282 | /* has information on which symbol we can match at that position */ |
| 1283 | /* as well as how many symbols matching consumes */ |
| 1284 | |
| 1285 | void apply_create_sigmatchcxx . . $ apply_create_sigmatch(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 1286 | char *symbol; |
| 1287 | struct sigma_triecxx . . $ sigma_trie# *st; |
| 1288 | int i, j, inlen, lastmatch, consumes, cons; |
| 1289 | /* We create a sigmatch array only in case we match against a real string */ |
| 1290 | if (((h->modecxx . . $ apply_handle#mode.) & ENUMERATEcxx . . $ `apply.c:26:9`!) == ENUMERATEcxx . . $ `apply.c:26:9`!) { |
| 1291 | return; |
| 1292 | } |
| 1293 | symbol = h->instringcxx . . $ apply_handle#instring.; |
| 1294 | inlen = strlencxx . . $ strlen(751346f8406fd082).(symbol); |
| 1295 | h->current_instring_lengthcxx . . $ apply_handle#current_instring_length. = inlen; |
| 1296 | if (inlen >= h->sigmatch_array_sizecxx . . $ apply_handle#sigmatch_array_size.) { |
| 1297 | freecxx . . $ free(5d22bdacc48458e8).(h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.); |
| 1298 | h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct sigmatch_arraycxx . . $ sigmatch_array#)*(inlen)); |
| 1299 | h->sigmatch_array_sizecxx . . $ apply_handle#sigmatch_array_size. = inlen; |
| 1300 | } |
| 1301 | /* Find longest match in alphabet at current position */ |
| 1302 | /* by traversing the trie of alphabet symbols */ |
| 1303 | for (i=0; i < inlen; i += consumes ) { |
| 1304 | st = h->sigma_triecxx . . $ apply_handle#sigma_trie.; |
| 1305 | for (j=0, lastmatch = 0; ; j++) { |
| 1306 | if (*(symbol+i+j) == '\0') { |
| 1307 | break; |
| 1308 | } |
| 1309 | st = st+(unsigned char)*(symbol+i+j); |
| 1310 | if (st->signumcxx . . $ sigma_trie#signum. != 0) { |
| 1311 | lastmatch = st->signumcxx . . $ sigma_trie#signum.; |
| 1312 | if (st->nextcxx . . $ sigma_trie#next. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 1313 | break; |
| 1314 | st = st->nextcxx . . $ sigma_trie#next.; |
| 1315 | } else if (st->nextcxx . . $ sigma_trie#next. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1316 | st = st->nextcxx . . $ sigma_trie#next.; |
| 1317 | } else { |
| 1318 | break; |
| 1319 | } |
| 1320 | } |
| 1321 | if (lastmatch != 0) { |
| 1322 | (h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+i)->signumbercxx . . $ sigmatch_array#signumber. = lastmatch; |
| 1323 | consumes = (h->sigscxx . . $ apply_handle#sigs.+lastmatch)->lengthcxx . . $ sigs#length.; |
| 1324 | } else { |
| 1325 | /* Not found in trie */ |
| 1326 | (h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+i)->signumbercxx . . $ sigmatch_array#signumber. = IDENTITYcxx . . $ `fomalib.h:51:9`!; |
| 1327 | consumes = utf8skipcxx . . $ utf8skip(1ef8e6ec083aabb9).(symbol+i)+1; |
| 1328 | } |
| 1329 | |
| 1330 | /* If we now find trailing unicode combining characters (0300-036F): */ |
| 1331 | /* (1) Merge them all with current symbol */ |
| 1332 | /* (2) Declare the whole sequence one ? (IDENTITY) symbol */ |
| 1333 | /* Step 2 is motivated by the fact that */ |
| 1334 | /* if the input is S(symbol) + D(diacritic) */ |
| 1335 | /* and SD were a symbol in the alphabet, then this would have been */ |
| 1336 | /* found when searching the alphabet symbols earlier, so SD+ => ? */ |
| 1337 | /* Note that this means that a multi-char symbol followed by a */ |
| 1338 | /* diacritic gets converted to a single ?, e.g. */ |
| 1339 | /* [TAG] + D => ? if [TAG] is in the alphabet, but [TAG]+D isn't. */ |
| 1340 | |
| 1341 | for ( ; (cons = utf8iscombiningcxx . . $ utf8iscombining(b2e27cdb9bef2230).((unsigned char *)(symbol+i+consumes))); consumes += cons) { |
| 1342 | (h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+i)->signumbercxx . . $ sigmatch_array#signumber. = IDENTITYcxx . . $ `fomalib.h:51:9`!; |
| 1343 | } |
| 1344 | (h->sigmatch_arraycxx . . $ apply_handle#sigmatch_array.+i)->consumescxx . . $ sigmatch_array#consumes. = consumes; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | void apply_add_flagcxx . . $ apply_add_flag(259e9dc864900f19).(struct apply_handlecxx . . $ apply_handle# *h, char *name) { |
| 1349 | struct flag_listcxx . . $ flag_list# *flist, *flist_prev; |
| 1350 | if (h->flag_listcxx . . $ apply_handle#flag_list. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1351 | flist = h->flag_listcxx . . $ apply_handle#flag_list. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct flag_listcxx . . $ flag_list#)); |
| 1352 | } else { |
| 1353 | for (flist = h->flag_listcxx . . $ apply_handle#flag_list.; flist != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; flist_prev = flist, flist = flist->nextcxx . . $ flag_list#next.) { |
| 1354 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(flist->namecxx . . $ flag_list#name., name) == 0) { |
| 1355 | return; |
| 1356 | } |
| 1357 | } |
| 1358 | flist = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct flag_listcxx . . $ flag_list#)); |
| 1359 | flist_prev->nextcxx . . $ flag_list#next. = flist; |
| 1360 | } |
| 1361 | flist->namecxx . . $ flag_list#name. = name; |
| 1362 | flist->valuecxx . . $ flag_list#value. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 1363 | flist->negcxx . . $ flag_list#neg. = 0; |
| 1364 | flist->nextcxx . . $ flag_list#next. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 1365 | return; |
| 1366 | } |
| 1367 | |
| 1368 | void apply_clear_flagscxx . . $ apply_clear_flags(dcfc4a94b3eb08e5).(struct apply_handlecxx . . $ apply_handle# *h) { |
| 1369 | struct flag_listcxx . . $ flag_list# *flist; |
| 1370 | for (flist = h->flag_listcxx . . $ apply_handle#flag_list.; flist != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; flist = flist->nextcxx . . $ flag_list#next.) { |
| 1371 | flist->valuecxx . . $ flag_list#value. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 1372 | flist->negcxx . . $ flag_list#neg. = 0; |
| 1373 | } |
| 1374 | return; |
| 1375 | } |
| 1376 | |
| 1377 | /* Check for flag consistency by looking at the current states of */ |
| 1378 | /* flags in flist */ |
| 1379 | |
| 1380 | int apply_check_flagcxx . . $ apply_check_flag(6d966aa81daf532d).(struct apply_handlecxx . . $ apply_handle# *h, int type, char *name, char *value) { |
| 1381 | struct flag_listcxx . . $ flag_list# *flist, *flist2; |
| 1382 | for (flist = h->flag_listcxx . . $ apply_handle#flag_list.; flist != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; flist = flist->nextcxx . . $ flag_list#next.) { |
| 1383 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(flist->namecxx . . $ flag_list#name., name) == 0) { |
| 1384 | break; |
| 1385 | } |
| 1386 | } |
| 1387 | h->oldflagvaluecxx . . $ apply_handle#oldflagvalue. = flist->valuecxx . . $ flag_list#value.; |
| 1388 | h->oldflagnegcxx . . $ apply_handle#oldflagneg. = flist->negcxx . . $ flag_list#neg.; |
| 1389 | |
| 1390 | if (type == FLAG_UNIFYcxx . . $ `fomalib.h:75:9`!) { |
| 1391 | if (flist->valuecxx . . $ flag_list#value. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1392 | flist->valuecxx . . $ flag_list#value. = strdupcxx . . $ strdup(a8b8e32347182212).(value); |
| 1393 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1394 | } |
| 1395 | else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(value, flist->valuecxx . . $ flag_list#value.) == 0 && flist->negcxx . . $ flag_list#neg. == 0) { |
| 1396 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1397 | } else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(value, flist->valuecxx . . $ flag_list#value.) != 0 && flist->negcxx . . $ flag_list#neg. == 1) { |
| 1398 | flist->valuecxx . . $ flag_list#value. = strdupcxx . . $ strdup(a8b8e32347182212).(value); |
| 1399 | flist->negcxx . . $ flag_list#neg. = 0; |
| 1400 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1401 | } |
| 1402 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1403 | } |
| 1404 | |
| 1405 | if (type == FLAG_CLEARcxx . . $ `fomalib.h:76:9`!) { |
| 1406 | flist->valuecxx . . $ flag_list#value. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 1407 | flist->negcxx . . $ flag_list#neg. = 0; |
| 1408 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1409 | } |
| 1410 | |
| 1411 | if (type == FLAG_DISALLOWcxx . . $ `fomalib.h:77:9`!) { |
| 1412 | if (flist->valuecxx . . $ flag_list#value. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1413 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1414 | } |
| 1415 | if (value == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && flist->valuecxx . . $ flag_list#value. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1416 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1417 | } |
| 1418 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(value, flist->valuecxx . . $ flag_list#value.) != 0) { |
| 1419 | if (flist->negcxx . . $ flag_list#neg. == 1) |
| 1420 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1421 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1422 | } |
| 1423 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(value, flist->valuecxx . . $ flag_list#value.) == 0 && flist->negcxx . . $ flag_list#neg. == 1) { |
| 1424 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1425 | } |
| 1426 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1427 | } |
| 1428 | |
| 1429 | if (type == FLAG_NEGATIVEcxx . . $ `fomalib.h:78:9`!) { |
| 1430 | flist->valuecxx . . $ flag_list#value. = value; |
| 1431 | flist->negcxx . . $ flag_list#neg. = 1; |
| 1432 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1433 | } |
| 1434 | |
| 1435 | if (type == FLAG_POSITIVEcxx . . $ `fomalib.h:79:9`!) { |
| 1436 | flist->valuecxx . . $ flag_list#value. = value; |
| 1437 | flist->negcxx . . $ flag_list#neg. = 0; |
| 1438 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1439 | } |
| 1440 | |
| 1441 | if (type == FLAG_REQUIREcxx . . $ `fomalib.h:80:9`!) { |
| 1442 | |
| 1443 | if (value == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1444 | if (flist->valuecxx . . $ flag_list#value. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1445 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1446 | } else { |
| 1447 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1448 | } |
| 1449 | } else { |
| 1450 | if (flist->valuecxx . . $ flag_list#value. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1451 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1452 | } |
| 1453 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(value, flist->valuecxx . . $ flag_list#value.) != 0) { |
| 1454 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1455 | } else { |
| 1456 | if (flist->negcxx . . $ flag_list#neg. == 1) { |
| 1457 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1458 | } |
| 1459 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | if (type == FLAG_EQUALcxx . . $ `fomalib.h:81:9`!) { |
| 1465 | for (flist2 = h->flag_listcxx . . $ apply_handle#flag_list.; flist2 != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; flist2 = flist2->nextcxx . . $ flag_list#next.) { |
| 1466 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(flist2->namecxx . . $ flag_list#name., value) == 0) { |
| 1467 | break; |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | if (flist2 == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && flist->valuecxx . . $ flag_list#value. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 1472 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1473 | if (flist2 == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && flist->valuecxx . . $ flag_list#value. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1474 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1475 | } |
| 1476 | if (flist2->valuecxx . . $ flag_list#value. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || flist->valuecxx . . $ flag_list#value. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 1477 | if (flist2->valuecxx . . $ flag_list#value. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && flist->valuecxx . . $ flag_list#value. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && flist->negcxx . . $ flag_list#neg. == flist2->negcxx . . $ flag_list#neg.) { |
| 1478 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1479 | } else { |
| 1480 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1481 | } |
| 1482 | } else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(flist2->valuecxx . . $ flag_list#value., flist->valuecxx . . $ flag_list#value.) == 0 && flist->negcxx . . $ flag_list#neg. == flist2->negcxx . . $ flag_list#neg.) { |
| 1483 | return SUCCEEDcxx . . $ `apply.c:35:9`!; |
| 1484 | } |
| 1485 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1486 | } |
| 1487 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"***Don't know what do with flag [%i][%s][%s]\n", type, name, value); |
| 1488 | return FAILcxx . . $ `apply.c:34:9`!; |
| 1489 | } |