$ 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
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.
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <unistd.h>
/* The failure code to exit with */
#ifndef EXIT_FAILURE
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];
/* 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]);
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 = */
}
}
+ /* 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 */
/* Close the files */
fclose(ConfigSH);
fclose(Config_H);
+ if (ifile) fclose(Extra_Subs);
}
void