commit c4c60ec518bf08206a591e98e032e7cbbefc0ac7
parent 9873cb011aa46b45ea25c0930cce85cdd1afd8a0
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Sun, 1 Sep 2024 12:00:42 +0200
options-generator: portability fixes and updates
Changes by Christian and Evgeny
Diffstat:
1 file changed, 52 insertions(+), 34 deletions(-)
diff --git a/src/include/options-generator.c b/src/include/options-generator.c
@@ -21,14 +21,16 @@
* @brief Generates code based on Recutils database
* @author Christian Grothoff
*/
-#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
-#include <unistd.h>
+#if ! defined(_WIN32) || defined(__CYGWIN__)
+# include <unistd.h>
+#endif
#include <sys/stat.h>
+#include <errno.h>
#define MAX_ARGS 3
@@ -408,13 +410,13 @@ dump_option_macros (const char *name,
desc));
}
if (0 == desct)
- printf (" * @param val the value of the parameter");
+ printf (" * @param value the value of the parameter");
printf (" * @return structure with the requested setting\n */\n");
printf ("# define MHD_%c_OPTION_%s(",
(char) toupper (*category),
uppercase (name));
if (0 == argc)
- printf ("val");
+ printf ("value");
else
for (unsigned int i = 0; i<argc; i++)
{
@@ -432,7 +434,7 @@ dump_option_macros (const char *name,
(char) toupper (*category),
uppercase (name));
if (0 == argc)
- printf (" .val.%s = (val) \\\n",
+ printf (" .val.%s = (value) \\\n",
lowercase (name));
else
for (unsigned int i = 0; i<argc; i++)
@@ -489,7 +491,7 @@ dump_option_static_functions (const char *name,
desc));
}
if (0 == desct)
- printf (" * @param val the value of the parameter");
+ printf (" * @param value the value of the parameter");
printf (" * @return structure with the requested setting\n */\n");
printf ("static MHD_INLINE struct MHD_%sOptionAndValue\n"
"MHD_%c_OPTION_%s (\n",
@@ -497,7 +499,7 @@ dump_option_static_functions (const char *name,
(char) toupper (*category),
uppercase (name));
if (0 == argc)
- printf (" %s val",
+ printf (" %s value",
NULL != type
? type
: arguments[0]);
@@ -525,7 +527,7 @@ dump_option_static_functions (const char *name,
(char) toupper (*category),
uppercase (name));
if (0 == argc)
- printf (" opt_val.val.%s = (val); \\\n",
+ printf (" opt_val.val.%s = (value); \\\n",
lowercase (name));
else
for (unsigned int i = 0; i<argc; i++)
@@ -574,7 +576,7 @@ dump_option_documentation_functions (const char *name,
desc));
}
if (0 == desct)
- fprintf (f, " * @param val the value of the parameter");
+ fprintf (f, " * @param value the value of the parameter");
fprintf (f, " * @return structure with the requested setting\n */\n");
fprintf (f,"struct MHD_%sOptionAndValue\n"
"MHD_%c_OPTION_%s (\n",
@@ -583,7 +585,7 @@ dump_option_documentation_functions (const char *name,
uppercase (name));
if (0 == argc)
fprintf (f,
- " %s val",
+ " %s value",
NULL != type
? type
: arguments[0]);
@@ -714,8 +716,9 @@ main (int argc,
if (NULL == f)
{
fprintf (stderr,
- "Failed to open %s\n",
- fn);
+ "Failed to open %s: %s\n",
+ fn,
+ strerror (errno));
free (fn);
return 2;
}
@@ -976,8 +979,9 @@ TOP:
if (NULL == f)
{
fprintf (stderr,
- "Failed to open `%s'\n",
- doc_in);
+ "Failed to open `%s': %s\n",
+ doc_in,
+ strerror (errno));
return 2;
}
fprintf (f,
@@ -1006,8 +1010,9 @@ TOP:
if (NULL == f)
{
fprintf (stderr,
- "Failed to open `%s'\n",
- so_c);
+ "Failed to open `%s': %s\n",
+ so_c,
+ strerror (errno));
return 2;
}
fprintf (f,
@@ -1016,26 +1021,38 @@ TOP:
"/* *INDENT-OFF* */\n"
"/**\n"
" * @file %s_set_options.c\n"
- " * @author %s-options-generator.c\n"
+ " * @author options-generator.c\n"
" */\n"
- "\n"
- "#include \"mhd_sys_options.h\"\n"
- "#include \"sys_bool_type.h\"\n"
- "#include \"sys_base_types.h\"\n"
- "#include \"sys_malloc.h\"\n"
- "#include <string.h>\n"
- "#include \"mhd_%s.h\"\n"
- "#include \"%s_options.h\"\n"
- "#include \"mhd_public_api.h\"\n",
- category,
- category,
- category,
+ "\n",
category);
- if (0 == strcmp (category, "response"))
+ if (0 == strcmp (category, "daemon"))
+ {
fprintf (f,
+ "#include \"mhd_sys_options.h\"\n"
+ "#include \"sys_base_types.h\"\n"
+ "#include \"sys_malloc.h\"\n"
+ "#include <string.h>\n"
+ "#include \"mhd_daemon.h\"\n"
+ "#include \"daemon_options.h\"\n"
+ "#include \"mhd_public_api.h\"\n"
+ "\n");
+ }
+ else if (0 == strcmp (category, "response"))
+ {
+ fprintf (f,
+ "#include \"mhd_sys_options.h\"\n"
+ "#include \"response_set_options.h\"\n"
+ "#include \"sys_base_types.h\"\n"
+ "#include \"sys_bool_type.h\"\n"
+ "#include \"response_options.h\"\n"
+ "#include \"mhd_response.h\"\n"
+ "#include \"mhd_public_api.h\"\n"
"#include \"mhd_locks.h\"\n"
"#include \"mhd_assert.h\"\n"
- "#include \"response_funcs.h\"\n");
+ "#include \"response_funcs.h\"\n"
+ "\n");
+ }
+
fprintf (f,
"\n"
"MHD_FN_PAR_NONNULL_ALL_ MHD_EXTERN_\n"
@@ -1076,7 +1093,7 @@ TOP:
" if (! mhd_mutex_lock(&response->reuse.settings_lock))\n"
" return MHD_SC_RESPONSE_MUTEX_LOCK_FAILED;\n"
" mhd_assert (1 == mhd_atomic_counter_get(&response->reuse.counter));\n"
- " if (! response->frozen) /* Firm re-check under the lock */\n"
+ " if (response->frozen) /* Firm re-check under the lock */\n"
" {\n"
" mhd_mutex_unlock_chk(&response->reuse.settings_lock);\n"
" return MHD_SC_TOO_LATE;\n"
@@ -1144,8 +1161,9 @@ TOP:
if (NULL == f)
{
fprintf (stderr,
- "Failed to open `%s'\n",
- do_h);
+ "Failed to open `%s': %s\n",
+ do_h,
+ strerror (errno));
return 2;
}
fprintf (f,