1.1 --- a/main.c Fri Dec 09 19:33:15 2022 +0100
1.2 +++ b/main.c Sat Dec 10 01:28:22 2022 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Main program.
1.6 *
1.7 - * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2019, 2022 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -26,70 +26,11 @@
1.13 #include <strings.h>
1.14 #include "common.h"
1.15 #include "config.h"
1.16 -#include "program.h"
1.17 +#include "imports.h"
1.18 +#include "summary.h"
1.19 #include "templates.h"
1.20 #include "version.h"
1.21
1.22 -/* Parser functions and settings. */
1.23 -
1.24 -extern void yyparse(void);
1.25 -extern void yyrestart(FILE *);
1.26 -extern int yydebug;
1.27 -
1.28 -/* Specialised parser functions. */
1.29 -
1.30 -extern void reset(void);
1.31 -
1.32 -
1.33 -
1.34 -/* Return a copy of the given string without any extension. */
1.35 -
1.36 -static char *make_prefix(const char *s)
1.37 -{
1.38 - char *copy = strdup(s);
1.39 - char *ext;
1.40 -
1.41 - if (copy == NULL)
1.42 - return NULL;
1.43 -
1.44 - ext = strrchr(copy, '.');
1.45 -
1.46 - if (ext != NULL)
1.47 - *ext = '\0';
1.48 -
1.49 - return copy;
1.50 -}
1.51 -
1.52 -static int get_compound_prefix_conflict(int argc, char *argv[])
1.53 -{
1.54 - char *arg, *prefix, *name;
1.55 - int index, result;
1.56 -
1.57 - for (index = optind; index < argc; index++)
1.58 - {
1.59 - arg = argv[index];
1.60 - prefix = make_prefix(arg);
1.61 - result = 0;
1.62 -
1.63 - if (prefix != NULL)
1.64 - {
1.65 - name = make_basename(prefix);
1.66 -
1.67 - if (name != NULL)
1.68 - {
1.69 - result = strcasecmp(name, conf.compound);
1.70 - free(name);
1.71 - }
1.72 -
1.73 - free(prefix);
1.74 - }
1.75 -
1.76 - if (!result)
1.77 - return index;
1.78 - }
1.79 -
1.80 - return 0;
1.81 -}
1.82
1.83
1.84 /* Option definitions. */
1.85 @@ -98,13 +39,13 @@
1.86 /* long opt following var pointer short opt */
1.87 {"all", no_argument, NULL, 'a' },
1.88 {"client", no_argument, NULL, 'c' },
1.89 - {"comp", required_argument, NULL, 'C' },
1.90 {"dir", required_argument, NULL, 'd' },
1.91 + {"files", no_argument, NULL, 'f' },
1.92 {"headers", no_argument, NULL, 'h' },
1.93 {"help", no_argument, NULL, '?' },
1.94 {"interfaces", no_argument, NULL, 'i' },
1.95 {"language", required_argument, NULL, 'l' },
1.96 - {"comp-name", required_argument, NULL, 'N' },
1.97 + {"recursive", no_argument, NULL, 'R' },
1.98 {"routines", no_argument, NULL, 'r' },
1.99 {"server", no_argument, NULL, 's' },
1.100 {"verbose", no_argument, NULL, 'v' },
1.101 @@ -117,19 +58,21 @@
1.102
1.103 int main(int argc, char *argv[])
1.104 {
1.105 - FILE *fp;
1.106 char *arg, *progname;
1.107 int option, index, selected_content = 0, selected_role = 0;
1.108 + struct interface *iface;
1.109
1.110 #if YYDEBUG == 1
1.111 yydebug = 0;
1.112 #endif
1.113
1.114 + /* The configuration structure is already initialised in config.c. */
1.115 +
1.116 /* Accept various options. */
1.117
1.118 while (1)
1.119 {
1.120 - option = getopt_long(argc, argv, "acC:d:hil:N:rsvV?", long_options, NULL);
1.121 + option = getopt_long(argc, argv, "acd:fhil:rRsvV?", long_options, NULL);
1.122 if (option == -1)
1.123 break;
1.124
1.125 @@ -149,19 +92,16 @@
1.126 selected_role = 1;
1.127 break;
1.128
1.129 - /* Select compound interface filename prefix and output. */
1.130 - case 'C':
1.131 - conf.compound = optarg;
1.132 - if (conf.compound_name == NULL)
1.133 - conf.compound_name = conf.compound;
1.134 - selected_role = 1;
1.135 - break;
1.136 -
1.137 /* Set output directory. */
1.138 case 'd':
1.139 conf.output_dir = optarg;
1.140 break;
1.141
1.142 + /* Only report processed file basenames. */
1.143 + case 'f':
1.144 + conf.show_filenames = 1;
1.145 + break;
1.146 +
1.147 /* Generate headers. */
1.148 case 'h':
1.149 conf.headers = 1;
1.150 @@ -187,20 +127,17 @@
1.151 }
1.152 break;
1.153
1.154 - /* Select compound interface name and output. */
1.155 - case 'N':
1.156 - conf.compound_name = optarg;
1.157 - if (conf.compound == NULL)
1.158 - conf.compound = conf.compound_name;
1.159 - selected_role = 1;
1.160 - break;
1.161 -
1.162 /* Generate routines (definitions). */
1.163 case 'r':
1.164 conf.routines = 1;
1.165 selected_content = 1;
1.166 break;
1.167
1.168 + /* Also generate files associated with base interfaces. */
1.169 + case 'R':
1.170 + conf.generate_all = 1;
1.171 + break;
1.172 +
1.173 /* Select server output. */
1.174 case 's':
1.175 conf.server = 1;
1.176 @@ -241,18 +178,6 @@
1.177 conf.client = 1; conf.server = 1;
1.178 }
1.179
1.180 - /* Check any compound interface prefix against named files. */
1.181 -
1.182 - if (conf.compound != NULL)
1.183 - {
1.184 - if ((index = get_compound_prefix_conflict(argc, argv)))
1.185 - {
1.186 - fprintf(stderr, "Compound interface prefix %s conflicts with filename %s.\n",
1.187 - conf.compound, argv[index]);
1.188 - return 1;
1.189 - }
1.190 - }
1.191 -
1.192 /* Produce an error without any input files. */
1.193
1.194 if (optind >= argc)
1.195 @@ -261,52 +186,27 @@
1.196 return 1;
1.197 }
1.198
1.199 - /* Begin generating any compound interface code. */
1.200 -
1.201 - if (!begin_compound_output())
1.202 - {
1.203 - end_compound_output();
1.204 - return 1;
1.205 - }
1.206 -
1.207 /* Process named files. */
1.208
1.209 for (index = optind; index < argc; index++)
1.210 {
1.211 arg = argv[index];
1.212
1.213 - /* Handle actual files. */
1.214 -
1.215 - conf.output_prefix = make_prefix(arg);
1.216 -
1.217 - if (conf.output_prefix != NULL)
1.218 - {
1.219 - fp = fopen(arg, "r");
1.220 + /* Import each file for processing. */
1.221
1.222 - if (fp != NULL)
1.223 - {
1.224 - yyrestart(fp);
1.225 - yyparse();
1.226 - fclose(fp);
1.227 -
1.228 - /* Reset any specialised parser state. */
1.229 + iface = import_file(arg, 1);
1.230
1.231 - reset();
1.232 - }
1.233 -
1.234 - free(conf.output_prefix);
1.235 + if (iface == NULL)
1.236 + {
1.237 + fprintf(stderr, "Could not process file: %s\n", arg);
1.238 + return 1;
1.239 + }
1.240
1.241 - if (fp == NULL)
1.242 - {
1.243 - fprintf(stderr, "Could not open file: %s\n", arg);
1.244 - return 1;
1.245 - }
1.246 - }
1.247 + /* Summarise interfaces if requested. */
1.248 +
1.249 + if (conf.verbose)
1.250 + show_interfaces(iface);
1.251 }
1.252
1.253 - /* End generating any compound interface code. */
1.254 -
1.255 - end_compound_output();
1.256 -
1.257 return 0;
1.258 }