| 1 | /* |
| 2 | Copyright (c) 2016 Raspberry Pi (Trading) Ltd. |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifndef UTILS_H |
| 29 | #define UTILS_H |
| 30 | |
| 31 | typedef struct string_struct |
| 32 | { |
| 33 | struct string_struct *prev; |
| 34 | struct string_struct *next; |
| 35 | char data[0]; |
| 36 | } STRING_T; |
| 37 | |
| 38 | typedef struct string_vec_struct |
| 39 | { |
| 40 | int num_strings; |
| 41 | int max_strings; |
| 42 | char **strings; |
| 43 | } STRING_VEC_T; |
| 44 | |
| 45 | typedef struct overlay_help_state_struct OVERLAY_HELP_STATE_T; |
| 46 | |
| 47 | extern int opt_verbose; |
| 48 | extern int opt_dry_run; |
| 49 | |
| 50 | OVERLAY_HELP_STATE_T *overlay_help_open(const char *helpfile); |
| 51 | void overlay_help_close(OVERLAY_HELP_STATE_T *state); |
| 52 | int overlay_help_find(OVERLAY_HELP_STATE_T *state, const char *name); |
| 53 | int overlay_help_find_field(OVERLAY_HELP_STATE_T *state, const char *field); |
| 54 | const char *overlay_help_field_data(OVERLAY_HELP_STATE_T *state); |
| 55 | void overlay_help_print_field(OVERLAY_HELP_STATE_T *state, |
| 56 | const char *field, const char *label, |
| 57 | int indent, int strip_blanks); |
| 58 | |
| 59 | int run_cmd(const char *fmt, ...); |
| 60 | void free_string(const char *string); /* Not thread safe */ |
| 61 | void free_strings(void); /* Not thread safe */ |
| 62 | char *sprintf_dup(const char *fmt, ...); /* Not thread safe */ |
| 63 | char *vsprintf_dup(const char *fmt, va_list ap); /* Not thread safe */ |
| 64 | int dir_exists(const char *dirname); |
| 65 | int file_exists(const char *dirname); |
| 66 | void string_vec_init(STRING_VEC_T *vec); |
| 67 | char *string_vec_add(STRING_VEC_T *vec, const char *str, int len); |
| 68 | int string_vec_find(STRING_VEC_T *vec, const char *str, int len); |
| 69 | void string_vec_sort(STRING_VEC_T *vec); |
| 70 | void string_vec_uninit(STRING_VEC_T *vec); |
| 71 | int error(const char *fmt, ...); |
| 72 | void fatal_error(const char *fmt, ...); |
| 73 | |
| 74 | #endif |
| 75 | |