gmerlin
utils.h
1 /*****************************************************************
2  * gmerlin - a general purpose multimedia framework and applications
3  *
4  * Copyright (c) 2001 - 2011 Members of the Gmerlin project
5  * gmerlin-general@lists.sourceforge.net
6  * http://gmerlin.sourceforge.net
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  * *****************************************************************/
21 
22 #ifndef __BG_UTILS_H_
23 #define __BG_UTILS_H_
24 
25 #include <gavl/gavl.h>
26 #include <gavl/metadata.h>
27 
49 /* Append a trailing '/' if it's missing. Argument must be free()able */
50 
51 char * bg_fix_path(char * path);
52 
60 int bg_ensure_directory(const char * dir);
61 
62 
74 char * bg_search_file_read(const char * directory, const char * file);
75 
88 char * bg_search_file_write(const char * directory, const char * file);
89 
99 int bg_search_file_exec(const char * file, char ** path);
100 
109 char * bg_find_url_launcher();
110 
118 void bg_display_html_help(const char * path);
119 
127 char * bg_create_unique_filename(char * format);
128 
136 char * bg_canonical_filename(const char * name);
137 
149 char * bg_filename_ensure_extension(const char * filename,
150  const char * ext);
151 
152 
153 
172 char * bg_strdup(char * old_string, const char * new_string);
173 
184 char * bg_strndup(char * old_string,
185  const char * new_start,
186  const char * new_end);
187 
194 char * bg_strcat(char * old_string, const char * tail);
195 
203 char * bg_strncat(char * old_string, const char * start, const char * end);
204 
210 char * bg_toupper(const char * str);
211 
212 
221 int bg_string_is_url(const char * str);
222 
238 int bg_url_split(const char * url,
239  char ** protocol,
240  char ** user,
241  char ** password,
242  char ** hostname,
243  int * port,
244  char ** path);
245 
255 void bg_get_filename_hash(const char * gml, char ret[33]);
256 
265 char * bg_sprintf(const char * format,...) __attribute__ ((format (printf, 1, 2)));
266 
275 char ** bg_strbreak(const char * str, char delim);
276 
283 void bg_strbreak_free(char ** retval);
284 
295 char * bg_scramble_string(const char * str);
296 
307 char * bg_descramble_string(const char * str);
308 
316 char * bg_string_to_uri(const char * pos1, int len);
317 
325 char * bg_uri_to_string(const char * pos1, int len);
326 
337 char ** bg_urilist_decode(const char * str, int len);
338 
343 void bg_urilist_free(char ** uri_list);
344 
353 char * bg_system_to_utf8(const char * str, int len);
354 
363 char * bg_utf8_to_system(const char * str, int len);
364 
370 const char * bg_get_language_name(const char * iso);
371 
378 int bg_string_match(const char * str, const char * key_list);
379 
380 /* @} */
381 
397 void bg_hexdump(uint8_t * data, int len, int linebreak);
398 
405 char * bg_audio_format_to_string(gavl_audio_format_t * format, int use_tabs);
406 
407 
414 char * bg_video_format_to_string(gavl_video_format_t * format, int use_tabs);
415 
422 char * bg_get_stream_label(int index, const gavl_metadata_t * m);
423 
428 void bg_dprintf(const char * format, ...) __attribute__ ((format (printf, 1, 2)));
429 
435 void bg_diprintf(int indent, const char * format, ...) __attribute__ ((format (printf, 2, 3)));
436 
443 void * bg_read_file(const char * filename, int * len);
444 
452 int bg_write_file(const char * filename, void * data, int len);
453 
454 
460 const char * bg_iso639_b_to_t(const char * code);
461 
462 
463 /* @} */
464 
465 extern char const * const bg_language_codes[];
466 extern char const * const bg_language_labels[];
467 
468 #ifdef DEBUG
469 #define bg_debug(f,...) fprintf(stderr, f, __VA_ARGS__)
470 #else
471 #define bg_debug(f,...)
472 #endif
473 
474 
475 
476 #endif // __BG_UTILS_H_
char * bg_strndup(char *old_string, const char *new_start, const char *new_end)
Duplicate a string from a part of a source string.
char * bg_video_format_to_string(gavl_video_format_t *format, int use_tabs)
Convert a video format to a string.
char * bg_find_url_launcher()
Find an URL launcher.
int bg_ensure_directory(const char *dir)
Ensure that a directory exists.
void bg_hexdump(uint8_t *data, int len, int linebreak)
Do a hexdump of binary data.
char * bg_search_file_read(const char *directory, const char *file)
Search for a file for reading.
int bg_string_is_url(const char *str)
Check if a string looks like an URL.
int bg_search_file_exec(const char *file, char **path)
Search for an executable.
char * bg_canonical_filename(const char *name)
Get the canonical filename.
char * bg_search_file_write(const char *directory, const char *file)
Search for a file for writing.
char * bg_sprintf(const char *format,...) __attribute__((format(printf
Print into a string.
void void void * bg_read_file(const char *filename, int *len)
Read an entire file into a buffer.
char * bg_strcat(char *old_string, const char *tail)
Concatenate two strings.
void void bg_diprintf(int indent, const char *format,...) __attribute__((format(printf
Dump to stderr with intendation.
void bg_dprintf(const char *format,...) __attribute__((format(printf
Dump to stderr.
void bg_display_html_help(const char *path)
Display html help.
char * bg_uri_to_string(const char *pos1, int len)
Convert an URI to a a binary string (in system charset)
int bg_write_file(const char *filename, void *data, int len)
Write an entire file into a buffer.
char * bg_filename_ensure_extension(const char *filename, const char *ext)
Ensure a file extension.
char * bg_strncat(char *old_string, const char *start, const char *end)
Append a part of a string to another string.
void bg_strbreak_free(char **retval)
Free a substrings array.
char * bg_audio_format_to_string(gavl_audio_format_t *format, int use_tabs)
Convert an audio format to a string.
char * bg_create_unique_filename(char *format)
Create a unique filename.
int bg_string_match(const char *str, const char *key_list)
Check if a string occurs in a space-separated list of strings.
char * bg_fix_path(char *path)
Append a trailing slash to a path name.
int bg_url_split(const char *url, char **protocol, char **user, char **password, char **hostname, int *port, char **path)
Split an URL into their parts.
char * bg_descramble_string(const char *str)
Descramble a string.
char * bg_scramble_string(const char *str)
Scramble a string.
char ** bg_urilist_decode(const char *str, int len)
Decode an URI list.
char * bg_strdup(char *old_string, const char *new_string)
Duplicate a string.
char * bg_string_to_uri(const char *pos1, int len)
Convert a binary string (in system charset) to an URI.
const char * bg_iso639_b_to_t(const char *code)
Convert a ISO 639-2/B language code to a ISO 639-2/T code.
char * bg_utf8_to_system(const char *str, int len)
Convert a string from UTF-8 to the system character set.
void bg_get_filename_hash(const char *gml, char ret[33])
Get MD5 hash of a filename.
void bg_urilist_free(char **uri_list)
Free an URI list.
const char * bg_get_language_name(const char *iso)
Get a language name.
char * bg_toupper(const char *str)
Convert an UTF-8 string to uppercase.
char * bg_get_stream_label(int index, const gavl_metadata_t *m)
Create a stream label.
char * bg_system_to_utf8(const char *str, int len)
Convert a string from the system character set to UTF-8.
char char ** bg_strbreak(const char *str, char delim)
Break a string into substrings.