From: Joel E. Denny Date: Fri, 5 Oct 2007 02:54:33 +0000 (+0000) Subject: Implement --print-datadir. X-Git-Tag: v2.3b~90 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/d4bd22956952464408f6d1c7aa3f82fd60f9f17d Implement --print-datadir. * src/getargs.c (usage): Mention. (PRINT_DATADIR_OPTION): New anonymous enum member. (long_options): Add entry for it. (getargs): Add case for it calling compute_pkgdatadir. * src/output.c (output_skeleton): Encapsulate data directory computation from here... (prepare): ... and from here... (compute_pkgdatadir): ... into this new function. * src/output.h (compute_pkgdatadir): Prototype. --- diff --git a/ChangeLog b/ChangeLog index 358179b2..62d14dba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2007-10-04 Joel E. Denny + + Implement --print-datadir. + * src/getargs.c (usage): Mention. + (PRINT_DATADIR_OPTION): New anonymous enum member. + (long_options): Add entry for it. + (getargs): Add case for it calling compute_pkgdatadir. + * src/output.c (output_skeleton): Encapsulate data directory + computation from here... + (prepare): ... and from here... + (compute_pkgdatadir): ... into this new function. + * src/output.h (compute_pkgdatadir): Prototype. + 2007-09-29 Joel E. Denny * src/print-xml.c (escape_bufs): New static global variable diff --git a/src/getargs.c b/src/getargs.c index 45b0dc84..ff0aa3bc 100644 --- a/src/getargs.c +++ b/src/getargs.c @@ -21,6 +21,7 @@ #include #include "system.h" #include "revision.h" +#include "output.h" #include #include @@ -261,6 +262,7 @@ Operation modes:\n\ -h, --help display this help and exit\n\ -V, --version output version information and exit\n\ --print-localedir output directory containing locale-dependent data\n\ + --print-datadir output directory containing skeletons and XSLT\n\ -y, --yacc emulate POSIX Yacc\n\ \n\ "), stdout); @@ -393,7 +395,8 @@ static char const short_options[] = "yvegxdhr:L:ltknVo:b:p:S:T::W"; enum { LOCATIONS_OPTION = CHAR_MAX + 1, - PRINT_LOCALEDIR_OPTION + PRINT_LOCALEDIR_OPTION, + PRINT_DATADIR_OPTION }; static struct option const long_options[] = @@ -402,6 +405,7 @@ static struct option const long_options[] = { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'V' }, { "print-localedir", no_argument, 0, PRINT_LOCALEDIR_OPTION }, + { "print-datadir", no_argument, 0, PRINT_DATADIR_OPTION }, { "warnings", optional_argument, 0, 'W' }, /* Parser. */ @@ -555,6 +559,10 @@ getargs (int argc, char *argv[]) printf ("%s\n", LOCALEDIR); exit (EXIT_SUCCESS); + case PRINT_DATADIR_OPTION: + printf ("%s\n", compute_pkgdatadir ()); + exit (EXIT_SUCCESS); + default: usage (EXIT_FAILURE); } diff --git a/src/output.c b/src/output.c index 6cdc17bc..c9400e69 100644 --- a/src/output.c +++ b/src/output.c @@ -482,7 +482,7 @@ output_skeleton (void) char *full_skeleton; char const *p; char const *m4 = (p = getenv ("M4")) ? p : M4; - char const *pkgdatadir = (p = getenv ("BISON_PKGDATADIR")) ? p : PKGDATADIR; + char const *pkgdatadir = compute_pkgdatadir (); size_t skeleton_size = strlen (skeleton) + 1; size_t pkgdatadirlen = strlen (pkgdatadir); while (pkgdatadirlen && pkgdatadir[pkgdatadirlen - 1] == '/') @@ -602,12 +602,10 @@ prepare (void) /* About the skeletons. */ { - char const *pkgdatadir = getenv ("BISON_PKGDATADIR"); /* b4_pkgdatadir is used inside m4_include in the skeletons, so digraphs would never be expanded. Hopefully no one has M4-special characters in his Bison installation path. */ - MUSCLE_INSERT_STRING_RAW ("pkgdatadir", - pkgdatadir ? pkgdatadir : PKGDATADIR); + MUSCLE_INSERT_STRING_RAW ("pkgdatadir", compute_pkgdatadir ()); } } @@ -633,3 +631,10 @@ output (void) obstack_free (&format_obstack, NULL); } + +char const * +compute_pkgdatadir (void) +{ + char const *pkgdatadir = getenv ("BISON_PKGDATADIR"); + return pkgdatadir ? pkgdatadir : PKGDATADIR; +} diff --git a/src/output.h b/src/output.h index 9bd5717d..abd88f5c 100644 --- a/src/output.h +++ b/src/output.h @@ -1,5 +1,6 @@ /* Output the generated parsing program for bison, - Copyright (C) 2000, 2001, 2002, 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2002, 2003, 2006, 2007 Free Software Foundation, + Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -21,5 +22,6 @@ /* Output the parsing tables and the parser code to FTABLE. */ void output (void); +char const *compute_pkgdatadir (void); #endif /* !OUTPUT_H_ */