jbsrc/lib/src/core/jb-util.h (4686B) - raw
1 /* 2 * JB, the Jean-Yves Lefort's Build System 3 * Copyright (C) 2008 Jean-Yves Lefort <jylefort@brutele.be> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef _JB_UTIL_H 21 #define _JB_UTIL_H 22 23 #include <glib.h> 24 #include <sys/types.h> 25 #include <sys/stat.h> 26 27 #define JB_SEPARATOR "===============================================================================" 28 29 #define JB_MODE_FORMAT "0%03o" 30 31 void jb_set_log_file (const char *filename); 32 void jb_log (const char *format, ...) G_GNUC_PRINTF(1, 2); 33 34 void jb_message (const char *format, ...) G_GNUC_PRINTF(1, 2); 35 void jb_message_expand (const char *str, ...) G_GNUC_NULL_TERMINATED; 36 37 void jb_message_action (const char *format, ...) G_GNUC_PRINTF(1, 2); 38 39 void jb_message_checking (const char *format, ...) G_GNUC_PRINTF(1, 2); 40 41 void jb_message_result_bool (gboolean result); 42 void jb_message_result_string (const char *result); 43 void jb_message_result_string_format (const char *format, ...) G_GNUC_PRINTF(1, 2); 44 45 void jb_warning (const char *format, ...) G_GNUC_PRINTF(1, 2); 46 void jb_warning_expand (const char *str, ...) G_GNUC_NULL_TERMINATED; 47 48 /* 49 * Do not use this function to report errors that are caused by an 50 * invalid jb.c. They are programming errors, use g_error(). 51 */ 52 void jb_error (const char *format, ...) G_GNUC_PRINTF(1, 2) G_GNUC_NORETURN; 53 void jb_error_expand (const char *str, ...) G_GNUC_NULL_TERMINATED G_GNUC_NORETURN; 54 55 #define JB_LIST_FOREACH(var, head) \ 56 for ((var) = (head); \ 57 (var) != NULL; \ 58 (var) = (var)->next) 59 60 void jb_g_slist_free_deep (GSList *list); 61 void jb_g_slist_free_deep_custom (GSList *list, 62 GFunc element_free_func, 63 gpointer user_data); 64 65 #define JB_STRDUP_VPRINTF(result, format) \ 66 G_STMT_START{ \ 67 va_list _jb_strdup_vprintf_args; \ 68 \ 69 va_start(_jb_strdup_vprintf_args, format); \ 70 result = g_strdup_vprintf(format, _jb_strdup_vprintf_args); \ 71 va_end(_jb_strdup_vprintf_args); \ 72 }G_STMT_END 73 74 char *jb_strdelimit (const char *str, const char *delimiters, char new_delimiter); 75 76 char *jb_strip_newline (const char *str); 77 78 char *jb_c_quote (const char *str); 79 80 char *jb_strip_extension (const char *filename); 81 82 char *jb_strip_chars (const char *str, const char *chars); 83 84 char *jb_utf8_escape (const char *str); 85 86 gboolean jb_parse_uint32 (const char *str, int base, guint32 *value, GError **err); 87 gboolean jb_parse_uint64 (const char *str, int base, guint64 *value, GError **err); 88 89 gboolean jb_write_file (const char *filename, const char *contents, GError **err); 90 void jb_write_file_or_exit (const char *filename, const char *contents); 91 92 char *jb_read_file (const char *filename, GError **err); 93 char *jb_read_file_or_exit (const char *filename); 94 95 GSList *jb_match_files (const char *pattern); 96 97 void jb_chdir (const char *path); 98 99 void jb_mkdir (const char *pathname); 100 void jb_mkdir_of_file (const char *filename); 101 102 void jb_rename (const char *oldpath, const char *newpath); 103 104 void jb_chmod (const char *path, mode_t mode); 105 106 gboolean jb_fchown_by_name (int fd, 107 const char *owner, 108 const char *group, 109 GError **err); 110 111 void jb_rmtree (const char *dir); 112 113 void jb_subst (const char *infile, 114 const char *outfile, 115 GHashTable *variables); 116 117 gboolean jb_exec (char **standard_output, 118 char **standard_error, 119 const char *format, 120 ...) G_GNUC_PRINTF(3, 4); 121 gboolean jb_exec_expand (char **standard_output, 122 char **standard_error, 123 const char *str, 124 ...) G_GNUC_NULL_TERMINATED; 125 126 typedef GHashTable JBStringHashSet; 127 128 JBStringHashSet *jb_string_hash_set_new (void); 129 gboolean jb_string_hash_set_add (JBStringHashSet *set, const char *value); 130 gboolean jb_string_hash_set_contains (JBStringHashSet *set, const char *value); 131 132 gboolean jb_is_uptodate (const char *dst, const char *src); 133 gboolean jb_is_uptodate_list (const char *dst, GSList *src_list); 134 gboolean jb_is_uptodate_list_list (GSList *dst_list, GSList *src_list); 135 136 char *jb_string_list_join (GSList *list, const char *separator); 137 138 #endif /* _JB_UTIL_H */