Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file main.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief libyang's YANG Regular Expression tool |
| 5 | * |
| 6 | * Copyright (c) 2017 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
Christian Hopps | 32874e1 | 2021-05-01 09:43:54 -0400 | [diff] [blame] | 15 | #define _GNU_SOURCE /* asprintf, strdup */ |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 16 | |
aPiecek | e29b164 | 2023-06-30 10:28:14 +0200 | [diff] [blame] | 17 | #include <assert.h> |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 18 | #include <errno.h> |
Radek Krejci | 4001a10 | 2020-11-13 15:43:05 +0100 | [diff] [blame] | 19 | #include <getopt.h> |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 22 | #include <string.h> |
Radek Krejci | 4001a10 | 2020-11-13 15:43:05 +0100 | [diff] [blame] | 23 | #include <sys/types.h> |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 24 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 25 | #include "libyang.h" |
| 26 | |
Michal Vasko | 5aa44c0 | 2020-06-29 11:47:02 +0200 | [diff] [blame] | 27 | #include "compat.h" |
Radek Krejci | 4001a10 | 2020-11-13 15:43:05 +0100 | [diff] [blame] | 28 | #include "tools/config.h" |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 29 | |
| 30 | void |
| 31 | help(void) |
| 32 | { |
| 33 | fprintf(stdout, "YANG Regular Expressions processor.\n"); |
| 34 | fprintf(stdout, "Usage:\n"); |
| 35 | fprintf(stdout, " yangre [-hv]\n"); |
| 36 | fprintf(stdout, " yangre [-V] -p <regexp1> [-i] [-p <regexp2> [-i] ...] <string>\n"); |
| 37 | fprintf(stdout, " yangre [-V] -f <file>\n"); |
aPiecek | bfdf83b | 2023-06-29 13:55:09 +0200 | [diff] [blame] | 38 | fprintf(stdout, "Returns 0 if string matches the pattern(s) or if otherwise successful.\n"); |
| 39 | fprintf(stdout, "Returns 1 on error.\n"); |
| 40 | fprintf(stdout, "Returns 2 if string does not match the pattern(s).\n\n"); |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 41 | fprintf(stdout, "Options:\n" |
Radek Krejci | 4001a10 | 2020-11-13 15:43:05 +0100 | [diff] [blame] | 42 | " -h, --help Show this help message and exit.\n" |
| 43 | " -v, --version Show version number and exit.\n" |
| 44 | " -V, --verbose Print the processing information.\n" |
| 45 | " -i, --invert-match Invert-match modifier for the closest preceding\n" |
| 46 | " pattern.\n" |
| 47 | " -p, --pattern=\"REGEXP\" Regular expression including the quoting,\n" |
| 48 | " which is applied the same way as in a YANG module.\n" |
| 49 | " -f, --file=\"FILE\" List of patterns and the <string> (separated by an\n" |
| 50 | " empty line) are taken from <file>. Invert-match is\n" |
| 51 | " indicated by the single space character at the \n" |
| 52 | " beginning of the pattern line. YANG quotation around\n" |
| 53 | " patterns is still expected, but that avoids issues with\n" |
| 54 | " reading quotation by shell. Avoid newline at the end\n" |
| 55 | " of the string line to represent empty <string>."); |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 56 | fprintf(stdout, "Examples:\n" |
Radek Krejci | 4001a10 | 2020-11-13 15:43:05 +0100 | [diff] [blame] | 57 | " pattern \"[0-9a-fA-F]*\"; -> yangre -p '\"[0-9a-fA-F]*\"' '1F'\n" |
| 58 | " pattern '[a-zA-Z0-9\\-_.]*'; -> yangre -p \"'[a-zA-Z0-9\\-_.]*'\" 'a-b'\n" |
| 59 | " pattern [xX][mM][lL].*; -> yangre -p '[xX][mM][lL].*' 'xml-encoding'\n\n"); |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 60 | fprintf(stdout, "Note that to pass YANG quoting through your shell, you are supposed to use\n" |
Radek Krejci | 4001a10 | 2020-11-13 15:43:05 +0100 | [diff] [blame] | 61 | "the other quotation around. For not-quoted patterns, use single quotes.\n\n"); |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void |
| 65 | version(void) |
| 66 | { |
| 67 | fprintf(stdout, "yangre %s\n", PROJECT_VERSION); |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | pattern_error(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 72 | { |
| 73 | (void) path; /* unused */ |
| 74 | |
Radek Krejci | d785726 | 2020-11-06 10:29:22 +0100 | [diff] [blame] | 75 | if (level == LY_LLERR) { |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 76 | fprintf(stderr, "yangre error: %s\n", msg); |
| 77 | } |
| 78 | } |
| 79 | |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 80 | static int |
| 81 | add_pattern(char ***patterns, int **inverts, int *counter, char *pattern) |
| 82 | { |
| 83 | void *reallocated1, *reallocated2; |
aPiecek | b2b5136 | 2023-06-22 09:14:59 +0200 | [diff] [blame] | 84 | int orig_counter; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 85 | |
aPiecek | b2b5136 | 2023-06-22 09:14:59 +0200 | [diff] [blame] | 86 | /* Store the original number of items. */ |
| 87 | orig_counter = *counter; |
| 88 | |
| 89 | /* Reallocate 'patterns' memory with additional space. */ |
| 90 | reallocated1 = realloc(*patterns, (orig_counter + 1) * sizeof **patterns); |
| 91 | if (!reallocated1) { |
| 92 | goto error; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 93 | } |
| 94 | (*patterns) = reallocated1; |
aPiecek | b2b5136 | 2023-06-22 09:14:59 +0200 | [diff] [blame] | 95 | /* Allocated memory is now larger. */ |
| 96 | (*counter)++; |
| 97 | /* Copy the pattern and store it to the additonal space. */ |
| 98 | (*patterns)[orig_counter] = strdup(pattern); |
| 99 | if (!(*patterns)[orig_counter]) { |
| 100 | goto error; |
| 101 | } |
| 102 | |
| 103 | /* Reallocate 'inverts' memory with additional space. */ |
| 104 | reallocated2 = realloc(*inverts, (orig_counter + 1) * sizeof **inverts); |
| 105 | if (!reallocated2) { |
| 106 | goto error; |
| 107 | } |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 108 | (*inverts) = reallocated2; |
aPiecek | b2b5136 | 2023-06-22 09:14:59 +0200 | [diff] [blame] | 109 | (*inverts)[orig_counter] = 0; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 110 | |
aPiecek | bfdf83b | 2023-06-29 13:55:09 +0200 | [diff] [blame] | 111 | return 0; |
aPiecek | b2b5136 | 2023-06-22 09:14:59 +0200 | [diff] [blame] | 112 | |
| 113 | error: |
| 114 | fprintf(stderr, "yangre error: memory allocation error.\n"); |
aPiecek | bfdf83b | 2023-06-29 13:55:09 +0200 | [diff] [blame] | 115 | return 1; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 116 | } |
| 117 | |
aPiecek | e29b164 | 2023-06-30 10:28:14 +0200 | [diff] [blame] | 118 | /** |
| 119 | * @brief Open the @p filepath, parse patterns and given string-argument. |
| 120 | * |
| 121 | * @param[in] filepath File to parse. Contains patterns and string. |
| 122 | * @param[out] infile The file descriptor of @p filepath. |
| 123 | * @param[out] patterns Storage of patterns. |
| 124 | * @param[out] invert_match Array of flags indicates which patterns are inverted. |
| 125 | * @param[out] patterns_count Number of items in @p patterns (and @p invert_match too). |
| 126 | * @param[out] strarg The string-argument to check. |
| 127 | * @return 0 on success. |
| 128 | */ |
| 129 | static int |
| 130 | parse_patterns_file(const char *filepath, FILE **infile, char ***patterns, int **invert_match, int *patterns_count, |
| 131 | char **strarg) |
| 132 | { |
| 133 | int blankline = 0; |
| 134 | char *str = NULL; |
| 135 | size_t len = 0; |
| 136 | ssize_t l; |
| 137 | |
| 138 | *infile = fopen(filepath, "rb"); |
| 139 | if (!(*infile)) { |
| 140 | fprintf(stderr, "yangre error: unable to open input file %s (%s).\n", optarg, strerror(errno)); |
| 141 | goto error; |
| 142 | } |
| 143 | |
| 144 | while ((l = getline(&str, &len, *infile)) != -1) { |
| 145 | if (!blankline && (str[0] == '\n')) { |
| 146 | /* blank line */ |
| 147 | blankline = 1; |
| 148 | continue; |
| 149 | } |
| 150 | if ((str[0] != '\n') && (str[l - 1] == '\n')) { |
| 151 | /* remove ending newline */ |
| 152 | str[l - 1] = '\0'; |
| 153 | } |
| 154 | if (blankline) { |
| 155 | /* done - str is now the string to check */ |
| 156 | blankline = 0; |
| 157 | *strarg = str; |
| 158 | break; |
| 159 | /* else read the patterns */ |
| 160 | } else if (add_pattern(patterns, invert_match, patterns_count, |
| 161 | (str[0] == ' ') ? &str[1] : str)) { |
| 162 | goto error; |
| 163 | } |
| 164 | if (str[0] == ' ') { |
| 165 | /* set invert-match */ |
| 166 | (*invert_match)[*patterns_count - 1] = 1; |
| 167 | } |
| 168 | } |
| 169 | assert(str); |
| 170 | if (blankline && (str[0] != '\0')) { |
| 171 | /* corner case, no input after blankline meaning the pattern to check is empty */ |
| 172 | free(str); |
| 173 | str = malloc(sizeof(char)); |
| 174 | if (!str) { |
| 175 | fprintf(stderr, "yangre error: memory allocation failed.\n"); |
| 176 | goto error; |
| 177 | } |
| 178 | str[0] = '\0'; |
| 179 | } |
| 180 | *strarg = str; |
| 181 | |
| 182 | return 0; |
| 183 | |
| 184 | error: |
| 185 | free(str); |
| 186 | if (*infile) { |
| 187 | fclose(*infile); |
| 188 | *infile = NULL; |
| 189 | } |
| 190 | *strarg = NULL; |
| 191 | |
| 192 | return 1; |
| 193 | } |
| 194 | |
aPiecek | c5cf371 | 2023-06-30 11:27:33 +0200 | [diff] [blame^] | 195 | static char * |
| 196 | modstr_init(void) |
| 197 | { |
| 198 | const char *module_start = "module yangre {" |
| 199 | "yang-version 1.1;" |
| 200 | "namespace urn:cesnet:libyang:yangre;" |
| 201 | "prefix re;" |
| 202 | "leaf pattern {" |
| 203 | " type string {"; |
| 204 | |
| 205 | return strdup(module_start); |
| 206 | } |
| 207 | |
| 208 | static char * |
| 209 | modstr_add_pattern(char **modstr, const char *pattern, int invert_match) |
| 210 | { |
| 211 | char *new; |
| 212 | const char *module_invertmatch = " { modifier invert-match; }"; |
| 213 | const char *module_match = ";"; |
| 214 | |
| 215 | if (asprintf(&new, "%s pattern %s%s", *modstr, pattern, invert_match ? module_invertmatch : module_match) == -1) { |
| 216 | fprintf(stderr, "yangre error: memory allocation failed.\n"); |
| 217 | return NULL; |
| 218 | } |
| 219 | free(*modstr); |
| 220 | *modstr = NULL; |
| 221 | |
| 222 | return new; |
| 223 | } |
| 224 | |
| 225 | static char * |
| 226 | modstr_add_ending(char **modstr) |
| 227 | { |
| 228 | char *new; |
| 229 | static const char *module_end = "}}}"; |
| 230 | |
| 231 | if (asprintf(&new, "%s%s", *modstr, module_end) == -1) { |
| 232 | fprintf(stderr, "yangre error: memory allocation failed.\n"); |
| 233 | return NULL; |
| 234 | } |
| 235 | free(*modstr); |
| 236 | *modstr = NULL; |
| 237 | |
| 238 | return new; |
| 239 | } |
| 240 | |
| 241 | static int |
| 242 | create_module(char **patterns, int *invert_match, int patterns_count, char **mod) |
| 243 | { |
| 244 | int i; |
| 245 | char *new = NULL, *modstr; |
| 246 | |
| 247 | if (!(modstr = modstr_init())) { |
| 248 | goto error; |
| 249 | } |
| 250 | |
| 251 | for (i = 0; i < patterns_count; i++) { |
| 252 | if (!(new = modstr_add_pattern(&modstr, patterns[i], invert_match[i]))) { |
| 253 | goto error; |
| 254 | } |
| 255 | modstr = new; |
| 256 | } |
| 257 | |
| 258 | if (!(new = modstr_add_ending(&modstr))) { |
| 259 | goto error; |
| 260 | } |
| 261 | |
| 262 | *mod = new; |
| 263 | |
| 264 | return 0; |
| 265 | |
| 266 | error: |
| 267 | *mod = NULL; |
| 268 | free(new); |
| 269 | free(modstr); |
| 270 | |
| 271 | return 1; |
| 272 | } |
| 273 | |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 274 | int |
Radek Krejci | 4001a10 | 2020-11-13 15:43:05 +0100 | [diff] [blame] | 275 | main(int argc, char *argv[]) |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 276 | { |
| 277 | LY_ERR match; |
aPiecek | e29b164 | 2023-06-30 10:28:14 +0200 | [diff] [blame] | 278 | int i, opt_index = 0, ret = 1, verbose = 0; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 279 | struct option options[] = { |
| 280 | {"help", no_argument, NULL, 'h'}, |
| 281 | {"file", required_argument, NULL, 'f'}, |
| 282 | {"invert-match", no_argument, NULL, 'i'}, |
| 283 | {"pattern", required_argument, NULL, 'p'}, |
| 284 | {"version", no_argument, NULL, 'v'}, |
| 285 | {"verbose", no_argument, NULL, 'V'}, |
| 286 | {NULL, 0, NULL, 0} |
| 287 | }; |
aPiecek | c5cf371 | 2023-06-30 11:27:33 +0200 | [diff] [blame^] | 288 | char **patterns = NULL, *str = NULL, *modstr = NULL; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 289 | int *invert_match = NULL; |
| 290 | int patterns_count = 0; |
| 291 | struct ly_ctx *ctx = NULL; |
Michal Vasko | 4de7d07 | 2021-07-09 09:13:18 +0200 | [diff] [blame] | 292 | struct lys_module *mod; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 293 | FILE *infile = NULL; |
aPiecek | bfdf83b | 2023-06-29 13:55:09 +0200 | [diff] [blame] | 294 | ly_bool info_printed = 0; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 295 | |
| 296 | opterr = 0; |
| 297 | while ((i = getopt_long(argc, argv, "hf:ivVp:", options, &opt_index)) != -1) { |
| 298 | switch (i) { |
| 299 | case 'h': |
| 300 | help(); |
aPiecek | bfdf83b | 2023-06-29 13:55:09 +0200 | [diff] [blame] | 301 | info_printed = 1; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 302 | break; |
| 303 | case 'f': |
| 304 | if (infile) { |
| 305 | help(); |
| 306 | fprintf(stderr, "yangre error: multiple input files are not supported.\n"); |
| 307 | goto cleanup; |
| 308 | } else if (patterns_count) { |
| 309 | help(); |
| 310 | fprintf(stderr, "yangre error: command line patterns cannot be mixed with file input.\n"); |
| 311 | goto cleanup; |
| 312 | } |
aPiecek | e29b164 | 2023-06-30 10:28:14 +0200 | [diff] [blame] | 313 | if (parse_patterns_file(optarg, &infile, &patterns, &invert_match, &patterns_count, &str)) { |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 314 | goto cleanup; |
| 315 | } |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 316 | break; |
| 317 | case 'i': |
| 318 | if (!patterns_count || invert_match[patterns_count - 1]) { |
| 319 | help(); |
| 320 | fprintf(stderr, "yangre error: invert-match option must follow some pattern.\n"); |
| 321 | goto cleanup; |
| 322 | } |
| 323 | invert_match[patterns_count - 1] = 1; |
| 324 | break; |
| 325 | case 'p': |
| 326 | if (infile) { |
| 327 | help(); |
| 328 | fprintf(stderr, "yangre error: command line patterns cannot be mixed with file input.\n"); |
| 329 | goto cleanup; |
| 330 | } |
| 331 | if (add_pattern(&patterns, &invert_match, &patterns_count, optarg)) { |
| 332 | goto cleanup; |
| 333 | } |
| 334 | break; |
| 335 | case 'v': |
| 336 | version(); |
aPiecek | bfdf83b | 2023-06-29 13:55:09 +0200 | [diff] [blame] | 337 | info_printed = 1; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 338 | break; |
| 339 | case 'V': |
| 340 | verbose = 1; |
| 341 | break; |
| 342 | default: |
| 343 | help(); |
| 344 | if (optopt) { |
| 345 | fprintf(stderr, "yangre error: invalid option: -%c\n", optopt); |
| 346 | } else { |
| 347 | fprintf(stderr, "yangre error: invalid option: %s\n", argv[optind - 1]); |
| 348 | } |
| 349 | goto cleanup; |
| 350 | } |
| 351 | } |
| 352 | |
aPiecek | bfdf83b | 2023-06-29 13:55:09 +0200 | [diff] [blame] | 353 | if (info_printed) { |
| 354 | ret = 0; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 355 | goto cleanup; |
| 356 | } |
| 357 | |
| 358 | if (!str) { |
| 359 | /* check options compatibility */ |
| 360 | if (optind >= argc) { |
| 361 | help(); |
| 362 | fprintf(stderr, "yangre error: missing <string> parameter to process.\n"); |
| 363 | goto cleanup; |
| 364 | } else if (!patterns_count) { |
| 365 | help(); |
| 366 | fprintf(stderr, "yangre error: missing pattern parameter to use.\n"); |
| 367 | goto cleanup; |
| 368 | } |
| 369 | str = argv[optind]; |
| 370 | } |
| 371 | |
aPiecek | c5cf371 | 2023-06-30 11:27:33 +0200 | [diff] [blame^] | 372 | if (create_module(patterns, invert_match, patterns_count, &modstr)) { |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 373 | goto cleanup; |
| 374 | } |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 375 | |
| 376 | if (ly_ctx_new(NULL, 0, &ctx)) { |
| 377 | goto cleanup; |
| 378 | } |
| 379 | |
| 380 | ly_set_log_clb(pattern_error, 0); |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 381 | if (lys_parse_mem(ctx, modstr, LYS_IN_YANG, &mod) || !mod->compiled || !mod->compiled->data) { |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 382 | goto cleanup; |
| 383 | } |
| 384 | |
Radek Krejci | d785726 | 2020-11-06 10:29:22 +0100 | [diff] [blame] | 385 | /* check the value */ |
Michal Vasko | aebbce0 | 2021-04-06 09:23:37 +0200 | [diff] [blame] | 386 | match = lyd_value_validate(ctx, mod->compiled->data, str, strlen(str), NULL, NULL, NULL); |
Radek Krejci | d785726 | 2020-11-06 10:29:22 +0100 | [diff] [blame] | 387 | |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 388 | if (verbose) { |
| 389 | for (i = 0; i < patterns_count; i++) { |
| 390 | fprintf(stdout, "pattern %d: %s\n", i + 1, patterns[i]); |
| 391 | fprintf(stdout, "matching %d: %s\n", i + 1, invert_match[i] ? "inverted" : "regular"); |
| 392 | } |
| 393 | fprintf(stdout, "string : %s\n", str); |
| 394 | if (match == LY_SUCCESS) { |
| 395 | fprintf(stdout, "result : matching\n"); |
| 396 | } else if (match == LY_EVALID) { |
| 397 | fprintf(stdout, "result : not matching\n"); |
| 398 | } else { |
Radek Krejci | d785726 | 2020-11-06 10:29:22 +0100 | [diff] [blame] | 399 | fprintf(stdout, "result : error (%s)\n", ly_errmsg(ctx)); |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | if (match == LY_SUCCESS) { |
| 403 | ret = 0; |
| 404 | } else if (match == LY_EVALID) { |
aPiecek | bfdf83b | 2023-06-29 13:55:09 +0200 | [diff] [blame] | 405 | ret = 2; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 406 | } else { |
aPiecek | bfdf83b | 2023-06-29 13:55:09 +0200 | [diff] [blame] | 407 | ret = 1; |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | cleanup: |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 411 | ly_ctx_destroy(ctx); |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 412 | for (i = 0; i < patterns_count; i++) { |
| 413 | free(patterns[i]); |
| 414 | } |
| 415 | free(patterns); |
| 416 | free(invert_match); |
aPiecek | c5cf371 | 2023-06-30 11:27:33 +0200 | [diff] [blame^] | 417 | free(modstr); |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 418 | if (infile) { |
| 419 | fclose(infile); |
| 420 | free(str); |
| 421 | } |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 422 | |
| 423 | return ret; |
| 424 | } |