From b8df70f45ca97dc1aea9a3654d73acda2dcba123 Mon Sep 17 00:00:00 2001 From: "Craig A. Berry" Date: Sun, 18 Feb 2007 03:54:46 +0000 Subject: [PATCH] Make vms/munchconfig.c able to take a list of substitutions from a file so we don't overflow the command buffer on older systems. p4raw-id: //depot/perl@30343 --- configure.com | 29 +++++++++++++++++++--- vms/munchconfig.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 87 insertions(+), 16 deletions(-) diff --git a/configure.com b/configure.com index 8cfee8b..de59a89 100644 --- a/configure.com +++ b/configure.com @@ -6801,14 +6801,35 @@ $ ENDIF $ ELSE $ DECTERM_REPLACE = "DECTERMLIB=DECTERMLIB=" $ ENDIF +$! +$! In order not to stress the tiny command buffer on pre-7.3-2 systems, +$! we put the following substitutions in a file and pass the file to +$! munchconfig. +$! +$ open/write CONFIG extra_subs.txt +$ WC := write CONFIG +$ WC "''DECC_REPLACE'" +$ WC "''DECCXX_REPLACE'" +$ WC "''ARCH_TYPE'" +$ WC "''GNUC_REPLACE'" +$ WC "''SOCKET_REPLACE'" +$ WC "''THREAD_REPLACE'" +$ WC "''C_Compiler_Replace'" +$ WC "''MALLOC_REPLACE'" +$ WC "''THREAD_UPCALLS'" +$ WC "''THREAD_KERNEL'" +$ WC "PV=''version'" +$ WC "FLAGS=FLAGS=''extra_flags'" +$ WC "''LARGEFILE_REPLACE'" +$ WC "''DECTERM_REPLACE'" +$ close CONFIG +$! $ echo4 "Extracting ''defmakefile' (with variable substitutions)" $ DEFINE/USER_MODE sys$output 'UUmakefile' -$ mcr []munchconfig 'config_sh' 'Makefile_SH' "''DECC_REPLACE'" "''DECCXX_REPLACE'" "''ARCH_TYPE'" "''GNUC_REPLACE'" - -"''SOCKET_REPLACE'" "''THREAD_REPLACE'" "''C_Compiler_Replace'" "''MALLOC_REPLACE'" - -"''THREAD_UPCALLS'" "''THREAD_KERNEL'" "PV=''version'" "FLAGS=FLAGS=''extra_flags'" "''LARGEFILE_REPLACE'" - -"''DECTERM_REPLACE'" +$ mcr []munchconfig 'config_sh' 'Makefile_SH' -f extra_subs.txt $! Clean up after ourselves $ DELETE/NOLOG/NOCONFIRM []munchconfig.exe; +$ DELETE/NOLOG/NOCONFIRM []extra_subs.txt; $! $ echo4 "Extracting make_ext.com (without variable substitutions)" $ Create Sys$Disk:[-]make_ext.com diff --git a/vms/munchconfig.c b/vms/munchconfig.c index ccbf638..aaec595 100644 --- a/vms/munchconfig.c +++ b/vms/munchconfig.c @@ -4,11 +4,12 @@ non-unix systems. usage: - munchconfig config.sh config_h.sh [foo=bar [baz=xyzzy [...]]] >config.h + munchconfig config.sh config_h.sh [-f file] [foo=bar [baz=xyzzy [...]]] >config.h - which is to say, it takes as its firt parameter a config.sh (or - equivalent), as its second a config_h.sh (or equvalent), and a list of - optional tag=value pairs. + which is to say, it takes as its first parameter a config.sh (or + equivalent), as its second a config_h.sh (or equivalent), an optional file + containing tag=value pairs (one on each line), and an optional list of + tag=value pairs on the command line. It spits the processed config.h out to STDOUT. @@ -19,6 +20,7 @@ #include #include #include +#include /* The failure code to exit with */ #ifndef EXIT_FAILURE @@ -45,7 +47,10 @@ void tilde_sub(char [], Translate [], int); int main(int argc, char *argv[]) { - FILE *ConfigSH, *Config_H; + int c, i; + char *ifile = NULL; + char WorkString[LINEBUFFERSIZE]; + FILE *ConfigSH, *Config_H, *Extra_Subs; char LineBuffer[LINEBUFFERSIZE], *TempValue, *StartTilde, *EndTilde; char SecondaryLineBuffer[LINEBUFFERSIZE], OutBuf[LINEBUFFERSIZE]; char TokenBuffer[TOKENBUFFERSIZE]; @@ -59,11 +64,24 @@ main(int argc, char *argv[]) /* and config substitutions, */ /* respectively */ if (argc < 3) { - printf("Usage: munchconfig config.sh config_h.sh [foo=bar [baz=xyzzy [...]]]\n"); + printf("Usage: munchconfig config.sh config_h.sh [-f file] [foo=bar [baz=xyzzy [...]]]\n"); exit(EXIT_FAILURE); } - + optind = 3; /* skip config.sh and config_h.sh */ + while ((c = getopt(argc, argv, "f:")) != -1) { + switch (c) { + case 'f': + ifile = optarg; + break; + case ':': + fprintf(stderr, "Option -%c requires an operand\n", optopt); + break; + case '?': + fprintf(stderr,"Unrecognised option: -%c\n", optopt); + } + } + /* First, open the input files */ if (NULL == (ConfigSH = fopen(argv[1], "r"))) { printf("Error %i trying to open config.sh file %s\n", errno, argv[1]); @@ -75,12 +93,14 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } + if (ifile != NULL && NULL == (Extra_Subs = fopen(ifile, "r"))) { + printf("Error %i trying to open extra substitutions file %s\n", errno, ifile); + exit(EXIT_FAILURE); + } + /* Any tag/value pairs on the command line? */ - if (argc > 3) { - int i; - char WorkString[LINEBUFFERSIZE]; - for (i=3; i < argc && argv[i]; i++) { - + if (argc > optind) { + for (i=optind; i < argc && argv[i]; i++) { /* Local copy */ strcpy(WorkString, argv[i]); /* Stick a NULL over the = */ @@ -94,6 +114,35 @@ main(int argc, char *argv[]) } } + /* Now read in the tag/value pairs from the extra substitutions file, if any */ + while(ifile && fgets(LineBuffer, LINEBUFFERSIZE - 1, Extra_Subs)) { + /* Force a trailing null, just in case */ + LineBuffer[LINEBUFFERSIZE - 1] = '\0'; + LineBufferLength = strlen(LineBuffer); + + /* Chop trailing control characters */ + while((LineBufferLength > 0) && (LineBuffer[LineBufferLength-1] < ' ')) { + LineBuffer[LineBufferLength - 1] = '\0'; + LineBufferLength--; + } + + /* If it's empty, then try again */ + if (!*LineBuffer) + continue; + + /* Local copy */ + strcpy(WorkString, LineBuffer); + /* Stick a NULL over the = */ + TempValue = strchr(WorkString, '='); + *TempValue++ = '\0'; + + /* Copy the tag and value into the holding array */ + strcpy(TildeSub[TildeSubCount].Tag, WorkString); + strcpy(TildeSub[TildeSubCount].Value, TempValue); + TildeSubCount++; + } + + /* Now read in the config.sh file. */ while(fgets(LineBuffer, LINEBUFFERSIZE - 1, ConfigSH)) { /* Force a trailing null, just in case */ @@ -297,6 +346,7 @@ main(int argc, char *argv[]) /* Close the files */ fclose(ConfigSH); fclose(Config_H); + if (ifile) fclose(Extra_Subs); } void -- 2.7.4