gmerlin
|
00001 /***************************************************************** 00002 * gmerlin - a general purpose multimedia framework and applications 00003 * 00004 * Copyright (c) 2001 - 2012 Members of the Gmerlin project 00005 * gmerlin-general@lists.sourceforge.net 00006 * http://gmerlin.sourceforge.net 00007 * 00008 * This program is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation, either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 * *****************************************************************/ 00021 00022 #ifndef __BG_UTILS_H_ 00023 #define __BG_UTILS_H_ 00024 00025 #include <stdio.h> 00026 #include <wchar.h> 00027 00028 #include <gavl/gavl.h> 00029 #include <gavl/metadata.h> 00030 #include <gavl/utils.h> 00031 00053 /* Append a trailing '/' if it's missing. Argument must be free()able */ 00054 00055 char * bg_fix_path(char * path); 00056 00064 int bg_ensure_directory(const char * dir, int priv); 00065 00066 00078 char * bg_search_file_read(const char * directory, const char * file); 00079 00092 char * bg_search_file_write(const char * directory, const char * file); 00093 00103 int bg_search_file_exec(const char * file, char ** path); 00104 00113 char * bg_find_url_launcher(); 00114 00122 void bg_display_html_help(const char * path); 00123 00131 char * bg_create_unique_filename(char * format); 00132 00140 char * bg_canonical_filename(const char * name); 00141 00153 char * bg_filename_ensure_extension(const char * filename, 00154 const char * ext); 00155 00164 char * bg_path_to_label(const char * path); 00165 00166 00181 char * bg_toupper(const char * str); 00182 00191 int bg_string_is_url(const char * str); 00192 00208 int bg_url_split(const char * url, 00209 char ** protocol, 00210 char ** user, 00211 char ** password, 00212 char ** hostname, 00213 int * port, 00214 char ** path); 00215 00216 /* 00217 * \brief Split off URL variables 00218 * \param path Path component of an URL 00219 * \param vars Place to store the variables 00220 * 00221 * This will split off variables 00222 * like path?var1=val1&var2=val2 and store them into the 00223 * metadata structure. 00224 * 00225 */ 00226 00227 void bg_url_get_vars(char * path, 00228 gavl_metadata_t * vars); 00229 00230 00240 void bg_get_filename_hash(const char * gml, char ret[33]); 00241 00250 char * bg_sprintf(const char * format,...) __attribute__ ((format (printf, 1, 2))); 00251 00260 char ** bg_strbreak(const char * str, char delim); 00261 00268 void bg_strbreak_free(char ** retval); 00269 00280 char * bg_scramble_string(const char * str); 00281 00292 char * bg_descramble_string(const char * str); 00293 00301 char * bg_string_to_uri(const char * pos1, int len); 00302 00310 char * bg_uri_to_string(const char * pos1, int len); 00311 00322 char ** bg_urilist_decode(const char * str, int len); 00323 00328 void bg_urilist_free(char ** uri_list); 00329 00338 char * bg_system_to_utf8(const char * str, int len); 00339 00348 char * bg_utf8_to_system(const char * str, int len); 00349 00355 const char * bg_get_language_name(const char * iso); 00356 00363 int bg_string_match(const char * str, const char * key_list); 00364 00370 wchar_t * bg_str_to_wchar(const char * str); 00371 00377 char * bg_wchar_to_str(const wchar_t * wstr); 00378 00384 char * bg_capitalize(const char * str); 00385 00391 char * bg_strip_space(char * str); 00392 00393 /* @} */ 00394 00410 void bg_hexdump(uint8_t * data, int len, int linebreak); 00411 00418 char * bg_audio_format_to_string(gavl_audio_format_t * format, int use_tabs); 00419 00420 00427 char * bg_video_format_to_string(gavl_video_format_t * format, int use_tabs); 00428 00435 char * bg_get_stream_label(int index, const gavl_metadata_t * m); 00436 00441 void bg_dprintf(const char * format, ...) __attribute__ ((format (printf, 1, 2))); 00442 00448 void bg_diprintf(int indent, const char * format, ...) __attribute__ ((format (printf, 2, 3))); 00449 00456 void * bg_read_file(const char * filename, int * len); 00457 00465 int bg_write_file(const char * filename, void * data, int len); 00466 00473 int bg_lock_file(FILE * f, int wr); 00474 00480 int bg_unlock_file(FILE * f); 00481 00487 size_t bg_file_size(FILE * f); 00488 00494 const char * bg_iso639_b_to_t(const char * code); 00495 00501 const char * bg_iso639_t_to_b(const char * code); 00502 00503 00509 void bg_metadata_date_now(gavl_metadata_t * m, const char * key); 00510 00514 void bg_daemonize(); 00515 00516 00517 /* @} */ 00518 00519 extern char const * const bg_language_codes[]; 00520 extern char const * const bg_language_labels[]; 00521 00522 #ifdef DEBUG 00523 #define bg_debug(f,...) fprintf(stderr, f, __VA_ARGS__) 00524 #else 00525 #define bg_debug(f,...) 00526 #endif 00527 00528 00529 00530 #endif // __BG_UTILS_H_