gmerlin
utils.h
1 /*****************************************************************
2  * gmerlin - a general purpose multimedia framework and applications
3  *
4  * Copyright (c) 2001 - 2012 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 <stdio.h>
26 #include <wchar.h>
27 
28 #include <gavl/gavl.h>
29 #include <gavl/metadata.h>
30 #include <gavl/utils.h>
31 
53 /* Append a trailing '/' if it's missing. Argument must be free()able */
54 
55 char * bg_fix_path(char * path);
56 
64 int bg_ensure_directory(const char * dir, int priv);
65 
66 
78 char * bg_search_file_read(const char * directory, const char * file);
79 
92 char * bg_search_file_write(const char * directory, const char * file);
93 
103 int bg_search_file_exec(const char * file, char ** path);
104 
114 
122 void bg_display_html_help(const char * path);
123 
131 char * bg_create_unique_filename(char * format);
132 
140 char * bg_canonical_filename(const char * name);
141 
153 char * bg_filename_ensure_extension(const char * filename,
154  const char * ext);
155 
164 char * bg_path_to_label(const char * path);
165 
166 
181 char * bg_toupper(const char * str);
182 
191 int bg_string_is_url(const char * str);
192 
208 int bg_url_split(const char * url,
209  char ** protocol,
210  char ** user,
211  char ** password,
212  char ** hostname,
213  int * port,
214  char ** path);
215 
216 /*
217  * \brief Split off URL variables
218  * \param path Path component of an URL
219  * \param vars Place to store the variables
220  *
221  * This will split off variables
222  * like path?var1=val1&var2=val2 and store them into the
223  * metadata structure.
224  *
225  */
226 
227 void bg_url_get_vars(char * path,
228  gavl_metadata_t * vars);
229 
230 
240 void bg_get_filename_hash(const char * gml, char ret[33]);
241 
250 char * bg_sprintf(const char * format,...) __attribute__ ((format (printf, 1, 2)));
251 
260 char ** bg_strbreak(const char * str, char delim);
261 
268 void bg_strbreak_free(char ** retval);
269 
280 char * bg_scramble_string(const char * str);
281 
292 char * bg_descramble_string(const char * str);
293 
301 char * bg_string_to_uri(const char * pos1, int len);
302 
310 char * bg_uri_to_string(const char * pos1, int len);
311 
322 char ** bg_urilist_decode(const char * str, int len);
323 
328 void bg_urilist_free(char ** uri_list);
329 
338 char * bg_system_to_utf8(const char * str, int len);
339 
348 char * bg_utf8_to_system(const char * str, int len);
349 
355 const char * bg_get_language_name(const char * iso);
356 
363 int bg_string_match(const char * str, const char * key_list);
364 
370 wchar_t * bg_str_to_wchar(const char * str);
371 
377 char * bg_wchar_to_str(const wchar_t * wstr);
378 
384 char * bg_capitalize(const char * str);
385 
391 char * bg_strip_space(char * str);
392 
393 /* @} */
394 
410 void bg_hexdump(uint8_t * data, int len, int linebreak);
411 
418 char * bg_audio_format_to_string(gavl_audio_format_t * format, int use_tabs);
419 
420 
427 char * bg_video_format_to_string(gavl_video_format_t * format, int use_tabs);
428 
435 char * bg_get_stream_label(int index, const gavl_metadata_t * m);
436 
441 void bg_dprintf(const char * format, ...) __attribute__ ((format (printf, 1, 2)));
442 
448 void bg_diprintf(int indent, const char * format, ...) __attribute__ ((format (printf, 2, 3)));
449 
456 void * bg_read_file(const char * filename, int * len);
457 
465 int bg_write_file(const char * filename, void * data, int len);
466 
473 int bg_lock_file(FILE * f, int wr);
474 
480 int bg_unlock_file(FILE * f);
481 
487 size_t bg_file_size(FILE * f);
488 
494 const char * bg_iso639_b_to_t(const char * code);
495 
501 const char * bg_iso639_t_to_b(const char * code);
502 
503 
509 void bg_metadata_date_now(gavl_metadata_t * m, const char * key);
510 
515 
516 
517 /* @} */
518 
519 extern char const * const bg_language_codes[];
520 extern char const * const bg_language_labels[];
521 
522 #ifdef DEBUG
523 #define bg_debug(f,...) fprintf(stderr, f, __VA_ARGS__)
524 #else
525 #define bg_debug(f,...)
526 #endif
527 
528 
529 
530 #endif // __BG_UTILS_H_
char * bg_search_file_read(const char *directory, const char *file)
Search for a file for reading.
char * bg_create_unique_filename(char *format)
Create a unique filename.
char * bg_fix_path(char *path)
Append a trailing slash to a path name.
char * bg_path_to_label(const char *path)
Get the base name of a path.
char * bg_search_file_write(const char *directory, const char *file)
Search for a file for writing.
int bg_ensure_directory(const char *dir, int priv)
Ensure that a directory exists.
char * bg_filename_ensure_extension(const char *filename, const char *ext)
Ensure a file extension.
int bg_search_file_exec(const char *file, char **path)
Search for an executable.
void bg_display_html_help(const char *path)
Display html help.
char * bg_find_url_launcher()
Find an URL launcher.
char * bg_canonical_filename(const char *name)
Get the canonical filename.
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_get_stream_label(int index, const gavl_metadata_t *m)
Create a stream label.
int bg_write_file(const char *filename, void *data, int len)
Write an entire file into a buffer.
void bg_daemonize()
Make the current process become a daemon.
char * bg_video_format_to_string(gavl_video_format_t *format, int use_tabs)
Convert a video format to a string.
int bg_lock_file(FILE *f, int wr)
Lock a file for exclusive access.
void bg_metadata_date_now(gavl_metadata_t *m, const char *key)
Set a date and time field of the metadata from the lcoal time.
void bg_dprintf(const char *format,...) __attribute__((format(printf
Dump to stderr.
void bg_hexdump(uint8_t *data, int len, int linebreak)
Do a hexdump of binary data.
void void void * bg_read_file(const char *filename, int *len)
Read an entire file into a buffer.
int bg_unlock_file(FILE *f)
Unlock a file for exclusive access.
const char * bg_iso639_t_to_b(const char *code)
Convert a ISO 639-2/T language code to a ISO 639-2/B code.
size_t bg_file_size(FILE *f)
Get the size of an open file.
void void bg_diprintf(int indent, const char *format,...) __attribute__((format(printf
Dump to stderr with intendation.
char * bg_audio_format_to_string(gavl_audio_format_t *format, int use_tabs)
Convert an audio format to a string.
char * bg_strip_space(char *str)
Strip leading and trailing whitespace from a string.
char * bg_utf8_to_system(const char *str, int len)
Convert a string from UTF-8 to the system character set.
char * bg_string_to_uri(const char *pos1, int len)
Convert a binary string (in system charset) to an URI.
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.
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.
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_wchar_to_str(const wchar_t *wstr)
Convert a wide character string to a byte string.
char * bg_descramble_string(const char *str)
Descramble a string.
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_urilist_decode(const char *str, int len)
Decode an URI list.
int bg_string_is_url(const char *str)
Check if a string looks like an URL.
void bg_urilist_free(char **uri_list)
Free an URI list.
void bg_get_filename_hash(const char *gml, char ret[33])
Get MD5 hash of a filename.
char * bg_scramble_string(const char *str)
Scramble a string.
char * bg_sprintf(const char *format,...) __attribute__((format(printf
Print into a string.
wchar_t * bg_str_to_wchar(const char *str)
Convert a multibyte string to a wide character string.
char * bg_capitalize(const char *str)
Capitalize the first character of each word in a string.
char * bg_uri_to_string(const char *pos1, int len)
Convert an URI to a a binary string (in system charset)
void bg_strbreak_free(char **retval)
Free a substrings array.