1.1 --- a/Makefile Tue Nov 12 22:47:39 2019 +0100
1.2 +++ b/Makefile Tue Nov 12 23:40:42 2019 +0100
1.3 @@ -1,6 +1,9 @@
1.4 # Original sources and final program.
1.5
1.6 -SOURCES = main.c client.c common.c declaration.c dispatch.c message.c program.c server.c structure.c summary.c
1.7 +SOURCES = \
1.8 + main.c client.c common.c declaration.c dispatch.c includes.c \
1.9 + message.c program.c server.c structure.c summary.c \
1.10 +
1.11 PROGRAM = idl
1.12
1.13 # Generated files from flex and bison.
2.1 --- a/docs/idl.1 Tue Nov 12 22:47:39 2019 +0100
2.2 +++ b/docs/idl.1 Tue Nov 12 23:40:42 2019 +0100
2.3 @@ -236,7 +236,7 @@
2.4 .IR name ".idl :"
2.5 .PP
2.6 .TP
2.7 -.IR name _client.c
2.8 +.IR name "_client.c or " name _client.cc
2.9 contains the function definitions needed for the operations of all the
2.10 interfaces.
2.11 .TP
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/includes.c Tue Nov 12 23:40:42 2019 +0100
3.3 @@ -0,0 +1,34 @@
3.4 +/*
3.5 + * Generation of include directives.
3.6 + *
3.7 + * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
3.8 + *
3.9 + * This program is free software; you can redistribute it and/or
3.10 + * modify it under the terms of the GNU General Public License as
3.11 + * published by the Free Software Foundation; either version 2 of
3.12 + * the License, or (at your option) any later version.
3.13 + *
3.14 + * This program is distributed in the hope that it will be useful,
3.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.17 + * GNU General Public License for more details.
3.18 + *
3.19 + * You should have received a copy of the GNU General Public License
3.20 + * along with this program; if not, write to the Free Software
3.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
3.22 + * Boston, MA 02110-1301, USA
3.23 + */
3.24 +
3.25 +#include "includes.h"
3.26 +
3.27 +
3.28 +
3.29 +void write_general_include(const char *filename, FILE *fp)
3.30 +{
3.31 + fprintf(fp, "#include %s\n", filename);
3.32 +}
3.33 +
3.34 +void write_include(const char *name, const char *suffix, FILE *fp)
3.35 +{
3.36 + fprintf(fp, "#include \"%s%s\"\n", name, suffix);
3.37 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/includes.h Tue Nov 12 23:40:42 2019 +0100
4.3 @@ -0,0 +1,27 @@
4.4 +/*
4.5 + * Generation of include directives.
4.6 + *
4.7 + * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
4.8 + *
4.9 + * This program is free software; you can redistribute it and/or
4.10 + * modify it under the terms of the GNU General Public License as
4.11 + * published by the Free Software Foundation; either version 2 of
4.12 + * the License, or (at your option) any later version.
4.13 + *
4.14 + * This program is distributed in the hope that it will be useful,
4.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 + * GNU General Public License for more details.
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License
4.20 + * along with this program; if not, write to the Free Software
4.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
4.22 + * Boston, MA 02110-1301, USA
4.23 + */
4.24 +
4.25 +#pragma once
4.26 +
4.27 +#include <stdio.h>
4.28 +
4.29 +void write_general_include(const char *filename, FILE *fp);
4.30 +void write_include(const char *name, const char *suffix, FILE *fp);
5.1 --- a/program.c Tue Nov 12 22:47:39 2019 +0100
5.2 +++ b/program.c Tue Nov 12 23:40:42 2019 +0100
5.3 @@ -24,6 +24,7 @@
5.4 #include "common.h"
5.5 #include "declaration.h"
5.6 #include "dispatch.h"
5.7 +#include "includes.h"
5.8 #include "message.h"
5.9 #include "program.h"
5.10 #include "server.h"
5.11 @@ -251,8 +252,7 @@
5.12 /* Add this interface's header to the compound interface includes. */
5.13
5.14 if (compound_interfaces_fp != NULL)
5.15 - fprintf(compound_interfaces_fp, "#include \"%s_interface.h\"\n",
5.16 - output_basename);
5.17 + write_include(output_basename, "_interface.h", compound_interfaces_fp);
5.18
5.19 processed_interfaces++;
5.20 }
5.21 @@ -264,10 +264,8 @@
5.22 {
5.23 if (compound_dispatch_header_fp != NULL)
5.24 {
5.25 - fprintf(compound_dispatch_header_fp, "#include \"%s_server.h\"\n",
5.26 - output_basename);
5.27 - fprintf(compound_dispatch_header_fp, "#include \"%s_common.h\"\n",
5.28 - output_basename);
5.29 + write_include(output_basename, "_server.h", compound_dispatch_header_fp);
5.30 + write_include(output_basename, "_common.h", compound_dispatch_header_fp);
5.31 }
5.32 }
5.33
5.34 @@ -291,7 +289,7 @@
5.35
5.36 if (compound_dispatch_header_fp != NULL)
5.37 {
5.38 - fprintf(compound_dispatch_header_fp, compound_dispatch_header_epilogue,
5.39 + fprintf(compound_dispatch_header_fp, expected_items_definition,
5.40 output_compound_name, max_input_items);
5.41 fclose(compound_dispatch_header_fp);
5.42 }
5.43 @@ -433,6 +431,8 @@
5.44
5.45 void write_interfaces(struct interface *iface)
5.46 {
5.47 + int input_items;
5.48 +
5.49 if (iface == NULL)
5.50 return;
5.51
5.52 @@ -502,7 +502,7 @@
5.53 /* Emit interface include where the type is employed by signatures. */
5.54
5.55 if (output_language == CPP_LANGUAGE)
5.56 - fprintf(server_header_fp, "#include \"%s_interface.h\"\n", output_basename);
5.57 + write_include(output_basename, "_interface.h", server_header_fp);
5.58
5.59 /* Emit signatures. */
5.60
5.61 @@ -536,6 +536,11 @@
5.62
5.63 if (output_language == CPP_LANGUAGE)
5.64 fputs(interface_epilogue_cpp, server_interface_fp);
5.65 +
5.66 + input_items = get_max_input_items(iface->signatures);
5.67 +
5.68 + fprintf(server_interface_fp, expected_items_definition,
5.69 + iface->name, max_input_items);
5.70 }
5.71
5.72 /* Emit common structures. */
5.73 @@ -567,8 +572,7 @@
5.74 /* The list is reversed. */
5.75
5.76 write_includes(inc->tail, fp);
5.77 -
5.78 - fprintf(fp, "#include %s\n", inc->filename);
5.79 + write_general_include(inc->filename, fp);
5.80 }
5.81
5.82 /* Generate signatures. */
6.1 --- a/templates.h Tue Nov 12 22:47:39 2019 +0100
6.2 +++ b/templates.h Tue Nov 12 23:40:42 2019 +0100
6.3 @@ -82,9 +82,6 @@
6.4 "#include <ipc/message.h>\n" \
6.5 "#include \"%s_interface.h\"\n"
6.6
6.7 -#define compound_dispatch_header_epilogue \
6.8 -"\n#define %s_expected_items %d\n"
6.9 -
6.10 /* Compound interface class definitions. */
6.11
6.12 #define compound_interface_prologue \
6.13 @@ -153,12 +150,17 @@
6.14 /* Interface class definitions. */
6.15
6.16 #define interface_prologue_cpp \
6.17 +"\n#ifdef __cplusplus\n" \
6.18 "\nclass %s\n" \
6.19 "{\n" \
6.20 "public:"
6.21
6.22 #define interface_epilogue_cpp \
6.23 -"};\n"
6.24 +"};\n\n" \
6.25 +"#endif /* __cplusplus */\n"
6.26 +
6.27 +#define expected_items_definition \
6.28 +"\n#define %s_expected_items %d\n"
6.29
6.30 /* Dispatch templates. */
6.31