Add of %source_extension and %header_extension which specify

the source or/and the header output file extension.
* src/files.c (compute_base_names): Remove initialisation of
src_extension and header_extension.
(compute_exts_from_gf): Update.
(compute_exts_from_src): Update.
(output_files): Update.
* src/reader.c (parse_header_extension_decl): New.
(parse_source_extension_decl): New.
(read_declarations): New case statements for the new tokens.
* src/lex.c (percent_table): Add entries for %source_extension
and %header_extension.
* src/lex.h (token_e): New tokens tok_hdrext and tok_srcext.
This commit is contained in:
Akim Demaille
2001-08-06 08:51:41 +00:00
parent 8416323152
commit 7333d40316
20 changed files with 348 additions and 217 deletions

View File

@@ -46,9 +46,9 @@ static char *base_name = NULL;
static char *short_base_name = NULL;
/* C source file extension (the parser source). */
static const char *src_extension = NULL;
const char *src_extension = NULL;
/* Header file extension (if option ``-d'' is specified). */
static const char *header_extension = NULL;
const char *header_extension = NULL;
/*--------------------------.
@@ -209,19 +209,29 @@ get_extension_index(const char *filename)
static void
compute_exts_from_gf(const char *ext)
{
src_extension = tr(ext, 'y', 'c');
src_extension = tr(src_extension, 'Y', 'C');
header_extension = tr(ext, 'y', 'h');
header_extension = tr(header_extension, 'Y', 'H');
if (!src_extension)
{
src_extension = tr(ext, 'y', 'c');
src_extension = tr(src_extension, 'Y', 'C');
}
if (!header_extension)
{
header_extension = tr(ext, 'y', 'h');
header_extension = tr(header_extension, 'Y', 'H');
}
}
/* Computes extensions from the given c source file extension. */
static void
compute_exts_from_src(const char *ext)
{
src_extension = xstrdup(ext);
header_extension = tr(ext, 'c', 'h');
header_extension = tr(header_extension, 'C', 'H');
if (!src_extension)
src_extension = xstrdup(ext);
if (!header_extension)
{
header_extension = tr(ext, 'c', 'h');
header_extension = tr(header_extension, 'C', 'H');
}
}
/* FIXME: Should use xstrndup. */
@@ -233,10 +243,6 @@ compute_base_names (void)
size_t short_base_length;
size_t ext_index;
/* Set default extensions */
src_extension = ".c";
header_extension = ".h";
/* If --output=foo.c was specified (SPEC_OUTFILE == foo.c),
BASE_NAME and SHORT_BASE_NAME are `foo'.
@@ -357,6 +363,12 @@ output_files (void)
compute_base_names ();
/* Set default extensions */
if (!src_extension)
src_extension = ".c";
if (!header_extension)
header_extension = ".h";
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
#ifndef MSDOS
stringappend (attrsfile, header_extension);

View File

@@ -60,6 +60,9 @@ extern struct obstack output_obstack;
extern char *infile;
extern char *attrsfile;
extern const char *src_extension;
extern const char *header_extension;
void open_files PARAMS((void));
void output_files PARAMS((void));

View File

@@ -551,6 +551,8 @@ struct percent_table_struct percent_table[] =
{ "output_file", &spec_outfile, tok_setopt }, /* -o */
{ "file_prefix", &spec_file_prefix, tok_setopt }, /* -b */
{ "name_prefix", &spec_name_prefix, tok_setopt }, /* -p */
{ "header_extension", NULL, tok_hdrext},
{ "source_extension", NULL, tok_srcext},
#endif
{ "verbose", &verbose_flag, tok_noop }, /* -v */
{ "debug", &debug_flag, tok_noop }, /* -t */

View File

@@ -47,6 +47,8 @@ typedef enum token_e
tok_number,
tok_expect,
tok_thong,
tok_hdrext,
tok_srcext,
tok_noop,
tok_setopt,
tok_illegal,

View File

@@ -874,6 +874,45 @@ parse_thong_decl (void)
nsyms--;
}
/*------------------------------------------.
| Parse what comes after %header_extension. |
`------------------------------------------*/
static void
parse_header_extension_decl (void)
{
char buff[32];
int len;
if (header_extension)
complain (_("multiple %%header_extension declarations"));
fscanf (finput, "%s", buff);
printf("-> %s\n", buff);
len = strlen (buff);
buff[len] = '\0';
src_extension = XMALLOC (char, len + 1);
stpcpy (header_extension, buff);
}
/*------------------------------------------.
| Parse what comes after %source_extension. |
`------------------------------------------*/
static void
parse_source_extension_decl (void)
{
char buff[32];
int len;
if (src_extension)
complain (_("multiple %%source_extension declarations"));
fscanf (finput, "%s", buff);
printf("-> %s\n", buff);
len = strlen (buff);
buff[len] = '\0';
src_extension = XMALLOC (char, len + 1);
stpcpy (src_extension, buff);
}
/*----------------------------------------------------------------.
| Read from finput until `%%' is seen. Discard the `%%'. Handle |
@@ -944,6 +983,13 @@ read_declarations (void)
parse_assoc_decl (non_assoc);
break;
case tok_hdrext:
break;
case tok_srcext:
parse_source_extension_decl();
break;
case tok_noop:
break;