1 /* 2 * GPAC - Multimedia Framework C SDK 3 * 4 * Authors: Jean Le Feuvre 5 * Copyright (c) Telecom ParisTech 2017-2019 6 * All rights reserved 7 * 8 * This file is part of GPAC 9 * 10 * GPAC is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License as published by 12 * the Free Software Foundation; either version 2, or (at your option) 13 * any later version. 14 * 15 * GPAC is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; see the file COPYING. If not, write to 22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 23 * 24 */ 25 26 #ifndef _GF_MAIN_H_ 27 #define _GF_MAIN_H_ 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /*! 34 \file <gpac/main.h> 35 \brief main() macro for win32. 36 */ 37 38 /*! 39 \addtogroup sysmain_grp 40 @{ 41 42 Thiis section decribes functions useful when developping an application using libgpac such as: 43 - quick UTF8 conversion of arguments for main() on windows 44 - setting, checking and printing libgpac arguments as given from command line 45 */ 46 47 #include <gpac/setup.h> 48 #include <gpac/utf.h> 49 50 51 52 53 #if defined(WIN32) && !defined(NO_WMAIN) 54 /*! macro for main() with wide to char conversion on windows platforms*/ 55 #define GF_MAIN_FUNC(__fun) \ 56 int wmain( int argc, wchar_t** wargv )\ 57 {\ 58 int i;\ 59 int res;\ 60 size_t len;\ 61 size_t res_len;\ 62 char **argv;\ 63 argv = (char **)malloc(argc*sizeof(wchar_t *));\ 64 for (i = 0; i < argc; i++) {\ 65 wchar_t *src_str = wargv[i];\ 66 len = UTF8_MAX_BYTES_PER_CHAR*gf_utf8_wcslen(wargv[i]);\ 67 argv[i] = (char *)malloc(len + 1);\ 68 res_len = gf_utf8_wcstombs(argv[i], len, &src_str);\ 69 argv[i][res_len] = 0;\ 70 if (res_len > len) {\ 71 fprintf(stderr, "Length allocated for conversion of wide char to UTF-8 not sufficient\n");\ 72 return -1;\ 73 }\ 74 }\ 75 res = __fun(argc, argv);\ 76 for (i = 0; i < argc; i++) {\ 77 free(argv[i]);\ 78 }\ 79 free(argv);\ 80 return res;\ 81 } 82 83 #else 84 85 /*! macro for main() with wide to char conversion on windows platforms*/ 86 #define GF_MAIN_FUNC(__fun) \ 87 int main(int argc, char **argv) {\ 88 return __fun( argc, argv ); \ 89 } 90 91 #endif //win32 92 93 /*! structure holding a gpac arg (not a filter arg)*/ 94 typedef struct 95 { 96 /*! name of arg*/ 97 const char *name; 98 /*! alternate name of arg*/ 99 const char *altname; 100 /*! description of arg*/ 101 const char *description; 102 /*! default value of arg*/ 103 const char *val; 104 /*! possible value of arg*/ 105 const char *values; 106 /*! argument type for UI construction - note that argument values are not parsed and shall be set as strings*/ 107 u16 type; 108 /*! argument flags*/ 109 u16 flags; 110 } GF_GPACArg; 111 112 //these 3 values match argument hints of filters 113 /*! argument is of advanced type*/ 114 #define GF_ARG_HINT_ADVANCED (1<<1) 115 /*! argument is of expert type*/ 116 #define GF_ARG_HINT_EXPERT (1<<2) 117 /*! argument should not be presented in UIs*/ 118 #define GF_ARG_HINT_HIDE (1<<3) 119 /*! argument is highly experimental*/ 120 #define GF_ARG_HINT_EXPERIMENTAL (1<<4) 121 122 /*! argument applies to the libgpac core subsystem*/ 123 #define GF_ARG_SUBSYS_CORE (1<<5) 124 /*! argument applies to the log subsystem*/ 125 #define GF_ARG_SUBSYS_LOG (1<<6) 126 /*! argument applies to the filter subsystem*/ 127 #define GF_ARG_SUBSYS_FILTERS (1<<7) 128 /*! argument applies to the HTTP subsystem*/ 129 #define GF_ARG_SUBSYS_HTTP (1<<8) 130 /*! argument applies to the video subsystem*/ 131 #define GF_ARG_SUBSYS_VIDEO (1<<9) 132 /*! argument applies to the audio subsystem*/ 133 #define GF_ARG_SUBSYS_AUDIO (1<<10) 134 /*! argument applies to the font and text subsystem*/ 135 #define GF_ARG_SUBSYS_TEXT (1<<11) 136 /*! argument applies to the remotery subsystem*/ 137 #define GF_ARG_SUBSYS_RMT (1<<12) 138 139 /*! argument is a boolean*/ 140 #define GF_ARG_BOOL 0 141 /*! argument is a 32 bit integer*/ 142 #define GF_ARG_INT 1 143 /*! argument is a double*/ 144 #define GF_ARG_DOUBLE 2 145 /*! argument is a string*/ 146 #define GF_ARG_STRING 3 147 /*! argument is a camma-separated list of strings*/ 148 #define GF_ARG_STRINGS 4 149 150 /*! macros for defining a GF_GPACArg argument*/ 151 #define GF_DEF_ARG(_a, _b, _c, _d, _e, _f, _g) {_a, _b, _c, _d, _e, _f, _g} 152 153 /*! gets the options defined for libgpac 154 \return array of options*/ 155 const GF_GPACArg *gf_sys_get_options(); 156 157 /*! check if the given option is a libgpac argument 158 \param arg_name name of the argument 159 \return 0 if not a libgpac core option, 1 if option not consuming an argument, 2 if option consuming an argument*/ 160 u32 gf_sys_is_gpac_arg(const char *arg_name); 161 162 /*! parses config string and update config accordingly 163 \param opt_string section/key/val formatted as Section:Key (discard key), Section:Key=null (discard key), Section:Key=Val (set key) or Section:*=null (discard section) 164 \return GF_TRUE if update is OK, GF_FALSE otherwise*/ 165 Bool gf_sys_set_cfg_option(const char *opt_string); 166 167 /*! argument dump hint options */ 168 typedef enum 169 { 170 /*! only dumps simple arguments*/ 171 GF_ARGMODE_BASE=0, 172 /*! only dumps advanced arguments*/ 173 GF_ARGMODE_ADVANCED, 174 /*! only dumps expert arguments*/ 175 GF_ARGMODE_EXPERT, 176 /*! dumps all arguments*/ 177 GF_ARGMODE_ALL 178 } GF_SysArgMode; 179 180 /*! flags for help formating*/ 181 typedef enum 182 { 183 /*! first word in format string should be highlighted */ 184 GF_PRINTARG_HIGHLIGHT_FIRST = 1, 185 /*! prints <br/> instead of new line*/ 186 GF_PRINTARG_NL_TO_BR = 1<<1, 187 /*! first word in format string is an option descritptor*/ 188 GF_PRINTARG_OPT_DESC = 1<<2, 189 /*! the format string is an application string, not a gpac core one*/ 190 GF_PRINTARG_IS_APP = 1<<3, 191 /*! insert an extra '-' at the begining*/ 192 GF_PRINTARG_ADD_DASH = 1<<4, 193 /*! the generation is for markdown*/ 194 GF_PRINTARG_MD = 1<<16, 195 /*! the generation is for man pages*/ 196 GF_PRINTARG_MAN = 1<<17, 197 /*! XML < and > should be escaped (for markdown generation only) */ 198 GF_PRINTARG_ESCAPE_XML = 1<<18, 199 /*! '|' should be escaped (for markdown generation only) */ 200 GF_PRINTARG_ESCAPE_PIPE = 1<<19, 201 } GF_SysPrintArgFlags; 202 203 204 /*! prints a argument 205 \param helpout destination file - if NULL, uses stderr 206 \param flags dump flags 207 \param arg argument to print 208 \param arg_subsystem name of subsystem of argument (core, gpac, filter name) for localization) 209 */ 210 void gf_sys_print_arg(FILE *helpout, GF_SysPrintArgFlags flags, const GF_GPACArg *arg, const char *arg_subsystem); 211 212 /*! prints libgpac help for builton core options to stderr 213 \param helpout destination file - if NULL, uses stderr 214 \param flags dump flags 215 \param mode filtering mode based on argument type 216 \param subsystem_flags filtering mode based on argument subsytem flags 217 */ 218 void gf_sys_print_core_help(FILE *helpout, GF_SysPrintArgFlags flags, GF_SysArgMode mode, u32 subsystem_flags); 219 220 /*! gets localized version of string identified by module name and identifier. 221 \param sec_name name of the module to query, such as "gpac", "core", or filter name 222 \param str_name name of string to query, such as acore/app option or a filter argument 223 \param def_val default value to return if no locaization exists 224 \return localized version of the string 225 */ 226 const char *gf_sys_localized(const char *sec_name, const char *str_name, const char *def_val); 227 228 /*! formats help to output 229 \param output output file to dump to 230 \param flags help formatting flags 231 \param fmt arguments of the format 232 */ 233 void gf_sys_format_help(FILE *output, GF_SysPrintArgFlags flags, const char *fmt, ...); 234 235 /*! very basic word match, check the number of source characters in order in dest 236 \param orig word to test 237 \param dst word to compare to 238 \return GF_TRUE if words are similar, GF_FALSE otherwise 239 */ 240 Bool gf_sys_word_match(const char *orig, const char *dst); 241 242 /*! @} */ 243 244 #ifdef __cplusplus 245 } 246 #endif 247 248 #endif //_GF_MAIN_H_ 249 250