mptsd reads mpegts streams from udp/multicast or http and combines them into one multiple program stream that is suitable for outputting to DVB-C modulator. Tested with Dektec DTE-3114 Quad QAM Modulator and used in production in small DVB-C networks. https://georgi.unixsol.org/programs/mptsd/

iniparser.c 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. Copyright (c) 2000-2007 by Nicolas Devillard.
  3. MIT License
  4. Permission is hereby granted, free of charge, to any person obtaining a
  5. copy of this software and associated documentation files (the "Software"),
  6. to deal in the Software without restriction, including without limitation
  7. the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. and/or sell copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  18. DEALINGS IN THE SOFTWARE.
  19. */
  20. /*-------------------------------------------------------------------------*/
  21. /**
  22. @file iniparser.c
  23. @author N. Devillard
  24. @date Sep 2007
  25. @version 3.0
  26. @brief Parser for ini files.
  27. */
  28. /*--------------------------------------------------------------------------*/
  29. /*
  30. Id: iniparser.c,v 2.18 2008-01-03 18:35:39 ndevilla Exp
  31. Revision: 2.18
  32. Date: 2008-01-03 18:35:39
  33. */
  34. /*---------------------------- Includes ------------------------------------*/
  35. #include <ctype.h>
  36. #include "iniparser.h"
  37. /*---------------------------- Defines -------------------------------------*/
  38. #define ASCIILINESZ (1024)
  39. #define INI_INVALID_KEY ((char*)-1)
  40. #define MSG_PREFIX "confparser: "
  41. /*---------------------------------------------------------------------------
  42. Private to this module
  43. ---------------------------------------------------------------------------*/
  44. /**
  45. * This enum stores the status for each parsed line (internal use only).
  46. */
  47. typedef enum _line_status_ {
  48. LINE_UNPROCESSED,
  49. LINE_ERROR,
  50. LINE_EMPTY,
  51. LINE_COMMENT,
  52. LINE_SECTION,
  53. LINE_VALUE
  54. } line_status ;
  55. /*-------------------------------------------------------------------------*/
  56. /**
  57. @brief Convert a string to lowercase.
  58. @param s String to convert.
  59. @return ptr to statically allocated string.
  60. This function returns a pointer to a statically allocated string
  61. containing a lowercased version of the input string. Do not free
  62. or modify the returned string! Since the returned string is statically
  63. allocated, it will be modified at each function call (not re-entrant).
  64. */
  65. /*--------------------------------------------------------------------------*/
  66. static char * strlwc(const char * s)
  67. {
  68. static char l[ASCIILINESZ+1];
  69. int i ;
  70. if (s==NULL) return NULL ;
  71. memset(l, 0, ASCIILINESZ+1);
  72. i=0 ;
  73. while (s[i] && i<ASCIILINESZ) {
  74. l[i] = (char)tolower((int)s[i]);
  75. i++ ;
  76. }
  77. l[ASCIILINESZ]=(char)0;
  78. return l ;
  79. }
  80. /*-------------------------------------------------------------------------*/
  81. /**
  82. @brief Remove blanks at the beginning and the end of a string.
  83. @param s String to parse.
  84. @return ptr to statically allocated string.
  85. This function returns a pointer to a statically allocated string,
  86. which is identical to the input string, except that all blank
  87. characters at the end and the beg. of the string have been removed.
  88. Do not free or modify the returned string! Since the returned string
  89. is statically allocated, it will be modified at each function call
  90. (not re-entrant).
  91. */
  92. /*--------------------------------------------------------------------------*/
  93. static char * strstrip(char * s)
  94. {
  95. static char l[ASCIILINESZ+1];
  96. char * last ;
  97. if (s==NULL) return NULL ;
  98. while (isspace((int)*s) && *s) s++;
  99. memset(l, 0, ASCIILINESZ+1);
  100. strcpy(l, s);
  101. last = l + strlen(l);
  102. while (last > l) {
  103. if (!isspace((int)*(last-1)))
  104. break ;
  105. last -- ;
  106. }
  107. *last = (char)0;
  108. return (char*)l ;
  109. }
  110. /*-------------------------------------------------------------------------*/
  111. /**
  112. @brief Get number of sections in a dictionary
  113. @param d Dictionary to examine
  114. @return int Number of sections found in dictionary
  115. This function returns the number of sections found in a dictionary.
  116. The test to recognize sections is done on the string stored in the
  117. dictionary: a section name is given as "section" whereas a key is
  118. stored as "section:key", thus the test looks for entries that do not
  119. contain a colon.
  120. This clearly fails in the case a section name contains a colon, but
  121. this should simply be avoided.
  122. This function returns -1 in case of error.
  123. */
  124. /*--------------------------------------------------------------------------*/
  125. int iniparser_getnsec(dictionary * d)
  126. {
  127. int i ;
  128. int nsec ;
  129. if (d==NULL) return -1 ;
  130. nsec=0 ;
  131. for (i=0 ; i<d->size ; i++) {
  132. if (d->key[i]==NULL)
  133. continue ;
  134. if (strchr(d->key[i], ':')==NULL) {
  135. nsec ++ ;
  136. }
  137. }
  138. return nsec ;
  139. }
  140. /*-------------------------------------------------------------------------*/
  141. /**
  142. @brief Get name for section n in a dictionary.
  143. @param d Dictionary to examine
  144. @param n Section number (from 0 to nsec-1).
  145. @return Pointer to char string
  146. This function locates the n-th section in a dictionary and returns
  147. its name as a pointer to a string statically allocated inside the
  148. dictionary. Do not free or modify the returned string!
  149. This function returns NULL in case of error.
  150. */
  151. /*--------------------------------------------------------------------------*/
  152. char * iniparser_getsecname(dictionary * d, int n)
  153. {
  154. int i ;
  155. int foundsec ;
  156. if (d==NULL || n<0) return NULL ;
  157. foundsec=0 ;
  158. for (i=0 ; i<d->size ; i++) {
  159. if (d->key[i]==NULL)
  160. continue ;
  161. if (strchr(d->key[i], ':')==NULL) {
  162. foundsec++ ;
  163. if (foundsec>n)
  164. break ;
  165. }
  166. }
  167. if (foundsec<=n) {
  168. return NULL ;
  169. }
  170. return d->key[i] ;
  171. }
  172. /*-------------------------------------------------------------------------*/
  173. /**
  174. @brief Dump a dictionary to an opened file pointer.
  175. @param d Dictionary to dump.
  176. @param f Opened file pointer to dump to.
  177. @return void
  178. This function prints out the contents of a dictionary, one element by
  179. line, onto the provided file pointer. It is OK to specify @c stderr
  180. or @c stdout as output files. This function is meant for debugging
  181. purposes mostly.
  182. */
  183. /*--------------------------------------------------------------------------*/
  184. void iniparser_dump(dictionary * d, FILE * f)
  185. {
  186. int i ;
  187. if (d==NULL || f==NULL) return ;
  188. for (i=0 ; i<d->size ; i++) {
  189. if (d->key[i]==NULL)
  190. continue ;
  191. if (d->val[i]!=NULL) {
  192. fprintf(f, "[%s]=[%s]\n", d->key[i], d->val[i]);
  193. } else {
  194. fprintf(f, "[%s]=UNDEF\n", d->key[i]);
  195. }
  196. }
  197. return ;
  198. }
  199. /*-------------------------------------------------------------------------*/
  200. /**
  201. @brief Save a dictionary to a loadable ini file
  202. @param d Dictionary to dump
  203. @param f Opened file pointer to dump to
  204. @return void
  205. This function dumps a given dictionary into a loadable ini file.
  206. It is Ok to specify @c stderr or @c stdout as output files.
  207. */
  208. /*--------------------------------------------------------------------------*/
  209. void iniparser_dump_ini(dictionary * d, FILE * f)
  210. {
  211. int i, j ;
  212. char keym[ASCIILINESZ+1];
  213. int nsec ;
  214. char * secname ;
  215. int seclen ;
  216. if (d==NULL || f==NULL) return ;
  217. nsec = iniparser_getnsec(d);
  218. if (nsec<1) {
  219. /* No section in file: dump all keys as they are */
  220. for (i=0 ; i<d->size ; i++) {
  221. if (d->key[i]==NULL)
  222. continue ;
  223. fprintf(f, "%s = %s\n", d->key[i], d->val[i]);
  224. }
  225. return ;
  226. }
  227. for (i=0 ; i<nsec ; i++) {
  228. secname = iniparser_getsecname(d, i) ;
  229. seclen = (int)strlen(secname);
  230. fprintf(f, "\n[%s]\n", secname);
  231. sprintf(keym, "%s:", secname);
  232. for (j=0 ; j<d->size ; j++) {
  233. if (d->key[j]==NULL)
  234. continue ;
  235. if (!strncmp(d->key[j], keym, seclen+1)) {
  236. fprintf(f,
  237. "%-30s = %s\n",
  238. d->key[j]+seclen+1,
  239. d->val[j] ? d->val[j] : "");
  240. }
  241. }
  242. }
  243. fprintf(f, "\n");
  244. return ;
  245. }
  246. /*-------------------------------------------------------------------------*/
  247. /**
  248. @brief Get the string associated to a key
  249. @param d Dictionary to search
  250. @param key Key string to look for
  251. @param def Default value to return if key not found.
  252. @return pointer to statically allocated character string
  253. This function queries a dictionary for a key. A key as read from an
  254. ini file is given as "section:key". If the key cannot be found,
  255. the pointer passed as 'def' is returned.
  256. The returned char pointer is pointing to a string allocated in
  257. the dictionary, do not free or modify it.
  258. */
  259. /*--------------------------------------------------------------------------*/
  260. char * iniparser_getstring(dictionary * d, const char * key, char * def)
  261. {
  262. char * lc_key ;
  263. char * sval ;
  264. if (d==NULL || key==NULL)
  265. return def ;
  266. lc_key = strlwc(key);
  267. sval = dictionary_get(d, lc_key, def);
  268. return sval ;
  269. }
  270. /*-------------------------------------------------------------------------*/
  271. /**
  272. @brief Get the string associated to a key, convert to an int
  273. @param d Dictionary to search
  274. @param key Key string to look for
  275. @param notfound Value to return in case of error
  276. @return integer
  277. This function queries a dictionary for a key. A key as read from an
  278. ini file is given as "section:key". If the key cannot be found,
  279. the notfound value is returned.
  280. Supported values for integers include the usual C notation
  281. so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
  282. are supported. Examples:
  283. "42" -> 42
  284. "042" -> 34 (octal -> decimal)
  285. "0x42" -> 66 (hexa -> decimal)
  286. Warning: the conversion may overflow in various ways. Conversion is
  287. totally outsourced to strtol(), see the associated man page for overflow
  288. handling.
  289. Credits: Thanks to A. Becker for suggesting strtol()
  290. */
  291. /*--------------------------------------------------------------------------*/
  292. int iniparser_getint(dictionary * d, const char * key, int notfound)
  293. {
  294. char * str ;
  295. str = iniparser_getstring(d, key, INI_INVALID_KEY);
  296. if (str==INI_INVALID_KEY) return notfound ;
  297. return (int)strtol(str, NULL, 0);
  298. }
  299. /*-------------------------------------------------------------------------*/
  300. /**
  301. @brief Get the string associated to a key, convert to a double
  302. @param d Dictionary to search
  303. @param key Key string to look for
  304. @param notfound Value to return in case of error
  305. @return double
  306. This function queries a dictionary for a key. A key as read from an
  307. ini file is given as "section:key". If the key cannot be found,
  308. the notfound value is returned.
  309. */
  310. /*--------------------------------------------------------------------------*/
  311. double iniparser_getdouble(dictionary * d, char * key, double notfound)
  312. {
  313. char * str ;
  314. str = iniparser_getstring(d, key, INI_INVALID_KEY);
  315. if (str==INI_INVALID_KEY) return notfound ;
  316. return atof(str);
  317. }
  318. /*-------------------------------------------------------------------------*/
  319. /**
  320. @brief Get the string associated to a key, convert to a boolean
  321. @param d Dictionary to search
  322. @param key Key string to look for
  323. @param notfound Value to return in case of error
  324. @return integer
  325. This function queries a dictionary for a key. A key as read from an
  326. ini file is given as "section:key". If the key cannot be found,
  327. the notfound value is returned.
  328. A true boolean is found if one of the following is matched:
  329. - A string starting with 'y'
  330. - A string starting with 'Y'
  331. - A string starting with 't'
  332. - A string starting with 'T'
  333. - A string starting with '1'
  334. A false boolean is found if one of the following is matched:
  335. - A string starting with 'n'
  336. - A string starting with 'N'
  337. - A string starting with 'f'
  338. - A string starting with 'F'
  339. - A string starting with '0'
  340. The notfound value returned if no boolean is identified, does not
  341. necessarily have to be 0 or 1.
  342. */
  343. /*--------------------------------------------------------------------------*/
  344. int iniparser_getboolean(dictionary * d, const char * key, int notfound)
  345. {
  346. char * c ;
  347. int ret ;
  348. c = iniparser_getstring(d, key, INI_INVALID_KEY);
  349. if (c==INI_INVALID_KEY) return notfound ;
  350. if (c[0]=='y' || c[0]=='Y' || c[0]=='1' || c[0]=='t' || c[0]=='T') {
  351. ret = 1 ;
  352. } else if (c[0]=='n' || c[0]=='N' || c[0]=='0' || c[0]=='f' || c[0]=='F') {
  353. ret = 0 ;
  354. } else {
  355. ret = notfound ;
  356. }
  357. return ret;
  358. }
  359. /*-------------------------------------------------------------------------*/
  360. /**
  361. @brief Finds out if a given entry exists in a dictionary
  362. @param ini Dictionary to search
  363. @param entry Name of the entry to look for
  364. @return integer 1 if entry exists, 0 otherwise
  365. Finds out if a given entry exists in the dictionary. Since sections
  366. are stored as keys with NULL associated values, this is the only way
  367. of querying for the presence of sections in a dictionary.
  368. */
  369. /*--------------------------------------------------------------------------*/
  370. int iniparser_find_entry(
  371. dictionary * ini,
  372. char * entry
  373. )
  374. {
  375. int found=0 ;
  376. if (iniparser_getstring(ini, entry, INI_INVALID_KEY)!=INI_INVALID_KEY) {
  377. found = 1 ;
  378. }
  379. return found ;
  380. }
  381. /*-------------------------------------------------------------------------*/
  382. /**
  383. @brief Set an entry in a dictionary.
  384. @param ini Dictionary to modify.
  385. @param entry Entry to modify (entry name)
  386. @param val New value to associate to the entry.
  387. @return int 0 if Ok, -1 otherwise.
  388. If the given entry can be found in the dictionary, it is modified to
  389. contain the provided value. If it cannot be found, -1 is returned.
  390. It is Ok to set val to NULL.
  391. */
  392. /*--------------------------------------------------------------------------*/
  393. int iniparser_set(dictionary * ini, char * entry, char * val)
  394. {
  395. return dictionary_set(ini, strlwc(entry), val) ;
  396. }
  397. /*-------------------------------------------------------------------------*/
  398. /**
  399. @brief Delete an entry in a dictionary
  400. @param ini Dictionary to modify
  401. @param entry Entry to delete (entry name)
  402. @return void
  403. If the given entry can be found, it is deleted from the dictionary.
  404. */
  405. /*--------------------------------------------------------------------------*/
  406. void iniparser_unset(dictionary * ini, char * entry)
  407. {
  408. dictionary_unset(ini, strlwc(entry));
  409. }
  410. /*-------------------------------------------------------------------------*/
  411. /**
  412. @brief Load a single line from an INI file
  413. @param input_line Input line, may be concatenated multi-line input
  414. @param section Output space to store section
  415. @param key Output space to store key
  416. @param value Output space to store value
  417. @return line_status value
  418. */
  419. /*--------------------------------------------------------------------------*/
  420. static line_status iniparser_line(
  421. char * input_line,
  422. char * section,
  423. char * key,
  424. char * value)
  425. {
  426. line_status sta ;
  427. char line[ASCIILINESZ+1];
  428. int len ;
  429. strcpy(line, strstrip(input_line));
  430. len = (int)strlen(line);
  431. if (len<1) {
  432. /* Empty line */
  433. sta = LINE_EMPTY ;
  434. } else if (line[0]=='#') {
  435. /* Comment line */
  436. sta = LINE_COMMENT ;
  437. } else if (line[0]=='[' && line[len-1]==']') {
  438. /* Section name */
  439. sscanf(line, "[%[^]]", section);
  440. strcpy(section, strstrip(section));
  441. strcpy(section, strlwc(section));
  442. sta = LINE_SECTION ;
  443. } else if (sscanf (line, "%[^=] = \"%[^\"]\"", key, value) == 2
  444. || sscanf (line, "%[^=] = '%[^\']'", key, value) == 2
  445. || sscanf (line, "%[^=] = %[^;#]", key, value) == 2) {
  446. /* Usual key=value, with or without comments */
  447. strcpy(key, strstrip(key));
  448. strcpy(key, strlwc(key));
  449. strcpy(value, strstrip(value));
  450. /*
  451. * sscanf cannot handle '' or "" as empty values
  452. * this is done here
  453. */
  454. if (!strcmp(value, "\"\"") || (!strcmp(value, "''"))) {
  455. value[0]=0 ;
  456. }
  457. sta = LINE_VALUE ;
  458. } else if (sscanf(line, "%[^=] = %[;#]", key, value)==2
  459. || sscanf(line, "%[^=] %[=]", key, value) == 2) {
  460. /*
  461. * Special cases:
  462. * key=
  463. * key=;
  464. * key=#
  465. */
  466. char *skey = strstrip(key);
  467. if (skey)
  468. strcpy(key, skey);
  469. strcpy(key, strlwc(key));
  470. value[0]=0 ;
  471. sta = LINE_VALUE ;
  472. } else {
  473. /* Generate syntax error */
  474. sta = LINE_ERROR ;
  475. }
  476. return sta ;
  477. }
  478. /*-------------------------------------------------------------------------*/
  479. /**
  480. @brief Parse an ini file and return an allocated dictionary object
  481. @param ininame Name of the ini file to read.
  482. @return Pointer to newly allocated dictionary
  483. This is the parser for ini files. This function is called, providing
  484. the name of the file to be read. It returns a dictionary object that
  485. should not be accessed directly, but through accessor functions
  486. instead.
  487. The returned dictionary must be freed using iniparser_freedict().
  488. */
  489. /*--------------------------------------------------------------------------*/
  490. dictionary * iniparser_load(const char * ininame)
  491. {
  492. FILE * in ;
  493. char line [ASCIILINESZ+1] ;
  494. char section [ASCIILINESZ+1] ;
  495. char key [ASCIILINESZ+1] ;
  496. char tmp [ASCIILINESZ+1] ;
  497. char val [ASCIILINESZ+1] ;
  498. int last=0 ;
  499. int len ;
  500. int lineno=0 ;
  501. int errs=0;
  502. dictionary * dict ;
  503. if ((in=fopen(ininame, "r"))==NULL) {
  504. fprintf(stderr, MSG_PREFIX "cannot open %s\n", ininame);
  505. return NULL ;
  506. }
  507. dict = dictionary_new(0) ;
  508. if (!dict) {
  509. fclose(in);
  510. return NULL ;
  511. }
  512. memset(line, 0, ASCIILINESZ);
  513. memset(section, 0, ASCIILINESZ);
  514. memset(key, 0, ASCIILINESZ);
  515. memset(val, 0, ASCIILINESZ);
  516. last=0 ;
  517. while (fgets(line+last, ASCIILINESZ-last, in)!=NULL) {
  518. lineno++ ;
  519. len = (int)strlen(line)-1;
  520. /* Safety check against buffer overflows */
  521. if (line[len]!='\n') {
  522. fprintf(stderr,
  523. MSG_PREFIX "input line too long in %s (%d)\n",
  524. ininame,
  525. lineno);
  526. dictionary_del(dict);
  527. fclose(in);
  528. return NULL ;
  529. }
  530. /* Get rid of \n and spaces at end of line */
  531. while ((len>=0) &&
  532. ((line[len]=='\n') || (isspace(line[len])))) {
  533. line[len]=0 ;
  534. len-- ;
  535. }
  536. /* Detect multi-line */
  537. if (line[len]=='\\') {
  538. /* Multi-line value */
  539. last=len ;
  540. continue ;
  541. }
  542. switch (iniparser_line(line, section, key, val)) {
  543. case LINE_EMPTY:
  544. case LINE_COMMENT:
  545. break ;
  546. case LINE_SECTION:
  547. errs = dictionary_set(dict, section, NULL);
  548. break ;
  549. case LINE_VALUE:
  550. sprintf(tmp, "%s:%s", section, key);
  551. errs = dictionary_set(dict, tmp, val) ;
  552. break ;
  553. case LINE_ERROR:
  554. fprintf(stderr, MSG_PREFIX "syntax error in %s (%d):\n",
  555. ininame,
  556. lineno);
  557. fprintf(stderr, "-> %s\n", line);
  558. errs++ ;
  559. break;
  560. default:
  561. break ;
  562. }
  563. memset(line, 0, ASCIILINESZ);
  564. last=0;
  565. if (errs<0) {
  566. fprintf(stderr, MSG_PREFIX "memory allocation failure\n");
  567. break ;
  568. }
  569. }
  570. if (errs) {
  571. dictionary_del(dict);
  572. dict = NULL ;
  573. }
  574. fclose(in);
  575. return dict ;
  576. }
  577. /*-------------------------------------------------------------------------*/
  578. /**
  579. @brief Free all memory associated to an ini dictionary
  580. @param d Dictionary to free
  581. @return void
  582. Free all memory associated to an ini dictionary.
  583. It is mandatory to call this function before the dictionary object
  584. gets out of the current context.
  585. */
  586. /*--------------------------------------------------------------------------*/
  587. void iniparser_freedict(dictionary **d)
  588. {
  589. if (*d) {
  590. dictionary_del(*d);
  591. *d = NULL;
  592. }
  593. }
  594. /* vim: set ts=4 et sw=4 tw=75 */
  595. #include <stdarg.h>
  596. #define __handle_format \
  597. char key[128]; \
  598. { \
  599. va_list args; \
  600. va_start(args, keyfmt); \
  601. vsnprintf(key, sizeof(key)-1, keyfmt, args); \
  602. va_end(args); \
  603. }
  604. char *ini_get_string(dictionary *d, char *def, const char *keyfmt, ...) {
  605. __handle_format;
  606. return iniparser_getstring(d, key, def);
  607. }
  608. char *ini_get_string_copy(dictionary *d, char *def , const char *keyfmt, ...) {
  609. __handle_format;
  610. char *ret = iniparser_getstring(d, key, def);
  611. if (ret)
  612. ret = strdup(ret);
  613. return ret;
  614. }
  615. int ini_get_int(dictionary *d, int def, const char *keyfmt, ...) {
  616. __handle_format;
  617. return iniparser_getint(d, key, def);
  618. }
  619. double ini_get_double(dictionary *d, double def, const char *keyfmt, ...) {
  620. __handle_format;
  621. return iniparser_getdouble(d, key, def);
  622. }
  623. int ini_get_bool(dictionary *d, int def , const char *keyfmt, ...) {
  624. __handle_format;
  625. return iniparser_getboolean(d, key, def);
  626. }
  627. #undef __handle_format