Use new substitution technology which doesn't depend on shell scripts.
(Faster, and better for MS-DOS port!)
#
# A fast substitution command for fixing up man pages, shell scripts, etc.
#
-SUBSTITUTE= $(top_builddir)/lib/substitute_sh
+SUBST_CONF=$(top_builddir)/util/subst.conf
+SUBSTITUTE= $(top_builddir)/util/subst -f $(SUBST_CONF)
+DEP_SUBSTITUTE= $(top_builddir)/util/subst $(SUBST_CONF)
#
# Warning flags
$(MV) $(srcdir)/Makefile.in.new $(srcdir)/Makefile.in; \
else :; fi
-
-
-
-
# End of file MCONFIG
realclean: realclean-recursive realclean-local
-include/linux/types.h: $(SUBSTITUTE) $(srcdir)/include/linux/types.h.in
- -chmod +x $(SUBSTITUTE)
+include/linux/types.h: $(DEP_SUBSTITUTE) $(srcdir)/include/linux/types.h.in
$(SUBSTITUTE) $(srcdir)/include/linux/types.h.in \
- include/linux/types.h
+ > include/linux/types.h
mostlyclean-local:
$(RM) -f \#* *~ core MAKELOG
ac_given_srcdir=$srcdir
ac_given_INSTALL="$INSTALL"
-trap 'rm -fr `echo "MCONFIG lib/substitute_sh Makefile lib/et/Makefile
+trap 'rm -fr `echo "MCONFIG Makefile util/Makefile util/subst.conf lib/et/Makefile
lib/ss/Makefile lib/ext2fs/Makefile lib/e2p/Makefile lib/uuid/Makefile
misc/Makefile e2fsck/Makefile debugfs/Makefile tests/Makefile
tests/progs/Makefile $rmakefile doc/Makefile" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
cat >> $CONFIG_STATUS <<EOF
-CONFIG_FILES=\${CONFIG_FILES-"MCONFIG lib/substitute_sh Makefile lib/et/Makefile
+CONFIG_FILES=\${CONFIG_FILES-"MCONFIG Makefile util/Makefile util/subst.conf lib/et/Makefile
lib/ss/Makefile lib/ext2fs/Makefile lib/e2p/Makefile lib/uuid/Makefile
misc/Makefile e2fsck/Makefile debugfs/Makefile tests/Makefile
tests/progs/Makefile $rmakefile doc/Makefile"}
if test -d ${srcdir}/resize ; then
rmakefile=resize/Makefile
fi
-AC_OUTPUT(MCONFIG lib/substitute_sh Makefile lib/et/Makefile
+AC_OUTPUT(MCONFIG Makefile util/Makefile util/subst.conf lib/et/Makefile
lib/ss/Makefile lib/ext2fs/Makefile lib/e2p/Makefile lib/uuid/Makefile
misc/Makefile e2fsck/Makefile debugfs/Makefile tests/Makefile
tests/progs/Makefile $rmakefile doc/Makefile)
debug_cmds.c debug_cmds.h: debug_cmds.ct
$(MK_CMDS) $(srcdir)/debug_cmds.ct
-debugfs.8: $(SUBSTITUTE) $(srcdir)/debugfs.8.in
- -$(CHMOD) +x $(SUBSTITUTE)
+debugfs.8: $(DEP_SUBSTITUTE) $(srcdir)/debugfs.8.in
$(SUBSTITUTE) $(srcdir)/debugfs.8.in debugfs.8
installdirs:
profiled:
mkdir profiled
-e2fsck.8: $(SUBSTITUTE) $(srcdir)/e2fsck.8.in
- -$(CHMOD) +x $(SUBSTITUTE)
+e2fsck.8: $(DEP_SUBSTITUTE) $(srcdir)/e2fsck.8.in
$(SUBSTITUTE) $(srcdir)/e2fsck.8.in e2fsck.8
installdirs:
+++ /dev/null
-#
-# This is the actual gots of substitute_sh. It is in a separate file to
-# protect it from autoconf substitutions
-#
-
-$SED -e "s%@AWK@%$AWK%g" \
- -e "s%@SED@%$SED%g" \
- -e "s%@ET_DIR@%$ET_DIR%g" \
- -e "s%@SS_DIR@%$SS_DIR%g" \
- -e "s%@E2FSPROGS_MONTH@%$E2FSPROGS_MONTH%g" \
- -e "s%@E2FSPROGS_YEAR@%$E2FSPROGS_YEAR%g" \
- -e "s%@E2FSPROGS_VERSION@%$E2FSPROGS_VERSION%g" \
- -e "s%@SIZEOF_LONG_LONG@%$SIZEOF_LONG_LONG%g" \
- -e "s%@SIZEOF_LONG@%$SIZEOF_LONG%g" \
- -e "s%@SIZEOF_INT@%$SIZEOF_INT%g" \
- -e "s%@SIZEOF_SHORT@%$SIZEOF_SHORT%g" \
- $1 > $2.tmp
-
-if [ -f $2 ]; then
- if cmp $2 $2.tmp > /dev/null 2>&1 ; then
- $RM $2.tmp
- else
- echo "substitute_sh: Replacing $2"
- $MV $2.tmp $2
- fi
-else
- echo "substitute_sh: Creating $2"
- $MV $2.tmp $2
-fi
@MAKEFILE_PROFILE@
@MAKEFILE_CHECKER@
-compile_et: $(SUBSTITUTE) $(srcdir)/compile_et.sh.in
- -$(CHMOD) +x $(SUBSTITUTE)
+compile_et: $(DEP_SUBSTITUTE) $(srcdir)/compile_et.sh.in
$(SUBSTITUTE) $(srcdir)/compile_et.sh.in compile_et
$(CHMOD) +x compile_et
DISTFILES= Makefile *.c *.h image
-ext2_err.et: $(SUBSTITUTE) $(srcdir)/ext2_err.et.in
- -$(CHMOD) +x $(SUBSTITUTE)
+ext2_err.et: $(DEP_SUBSTITUTE) $(srcdir)/ext2_err.et.in
$(SUBSTITUTE) $(srcdir)/ext2_err.et.in ext2_err.et
ext2_err.c ext2_err.h: ext2_err.et
# $(LD) -r -s -o $@ $(OBJS)
# $(CHMOD) -x $@
-mk_cmds: $(SUBSTITUTE) $(srcdir)/mk_cmds.sh.in
- -$(CHMOD) +x $(SUBSTITUTE)
+mk_cmds: $(DEP_SUBSTITUTE) $(srcdir)/mk_cmds.sh.in
$(SUBSTITUTE) $(srcdir)/mk_cmds.sh.in mk_cmds
$(CHMOD) +x mk_cmds
+++ /dev/null
-#!/bin/sh
-#
-# substitute <source> <dest>
-
-AWK=@AWK@
-SED=@SED@
-ET_DIR=@ET_DIR@
-SS_DIR=@SS_DIR@
-E2FSPROGS_MONTH=@E2FSPROGS_MONTH@
-E2FSPROGS_YEAR=@E2FSPROGS_YEAR@
-E2FSPROGS_VERSION=@E2FSPROGS_VERSION@
-SIZEOF_LONG_LONG=@SIZEOF_LONG_LONG@
-SIZEOF_LONG=@SIZEOF_LONG@
-SIZEOF_INT=@SIZEOF_INT@
-SIZEOF_SHORT=@SIZEOF_SHORT@
-
-MV=@MV@
-RM=@RM@
-CP=@CP@
-
-@DO_SUBSTITUTE_SCRIPT@
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
-all:: $(SPROGS) $(UPROGS) $(USPROGS) fix_substitute $(SMANPAGES) $(UMANPAGES)
+all:: $(SPROGS) $(UPROGS) $(USPROGS) $(SMANPAGES) $(UMANPAGES)
tune2fs: $(TUNE2FS_OBJS) $(DEPLIBS_E2P) $(LIBUUID)
$(CC) $(ALL_LDFLAGS) -o tune2fs $(TUNE2FS_OBJS) $(LIBS_E2P) $(LIBUUID)
badblocks: $(BADBLOCKS_OBJS) $(DEPLIBS)
$(CC) $(ALL_LDFLAGS) -o badblocks $(BADBLOCKS_OBJS) $(LIBS)
-fix_substitute:
- -$(CHMOD) +x $(SUBSTITUTE)
-
-tune2fs.8: $(SUBSTITUTE) $(srcdir)/tune2fs.8.in
+tune2fs.8: $(DEP_SUBSTITUTE) $(srcdir)/tune2fs.8.in
$(SUBSTITUTE) $(srcdir)/tune2fs.8.in tune2fs.8
-mklost+found.8: $(SUBSTITUTE) $(srcdir)/mklost+found.8.in
+mklost+found.8: $(DEP_SUBSTITUTE) $(srcdir)/mklost+found.8.in
$(SUBSTITUTE) $(srcdir)/mklost+found.8.in mklost+found.8
-mke2fs.8: $(SUBSTITUTE) $(srcdir)/mke2fs.8.in
+mke2fs.8: $(DEP_SUBSTITUTE) $(srcdir)/mke2fs.8.in
$(SUBSTITUTE) $(srcdir)/mke2fs.8.in mke2fs.8
-dumpe2fs.8: $(SUBSTITUTE) $(srcdir)/dumpe2fs.8.in
+dumpe2fs.8: $(DEP_SUBSTITUTE) $(srcdir)/dumpe2fs.8.in
$(SUBSTITUTE) $(srcdir)/dumpe2fs.8.in dumpe2fs.8
-badblocks.8: $(SUBSTITUTE) $(srcdir)/badblocks.8.in
+badblocks.8: $(DEP_SUBSTITUTE) $(srcdir)/badblocks.8.in
$(SUBSTITUTE) $(srcdir)/badblocks.8.in badblocks.8
-fsck.8: $(SUBSTITUTE) $(srcdir)/fsck.8.in
+fsck.8: $(DEP_SUBSTITUTE) $(srcdir)/fsck.8.in
$(SUBSTITUTE) $(srcdir)/fsck.8.in fsck.8
-chattr.1: $(SUBSTITUTE) $(srcdir)/chattr.1.in
+chattr.1: $(DEP_SUBSTITUTE) $(srcdir)/chattr.1.in
$(SUBSTITUTE) $(srcdir)/chattr.1.in chattr.1
-lsattr.1: $(SUBSTITUTE) $(srcdir)/lsattr.1.in
+lsattr.1: $(DEP_SUBSTITUTE) $(srcdir)/lsattr.1.in
$(SUBSTITUTE) $(srcdir)/lsattr.1.in lsattr.1
installdirs:
resize2fs: $(RESIZE_OBJS) $(DEPLIBS)
$(CC) $(ALL_LDFLAGS) -o resize2fs $(RESIZE_OBJS) $(LIBS)
-resize2fs.8: $(SUBSTITUTE) $(srcdir)/resize2fs.8.in
- -$(CHMOD) +x $(SUBSTITUTE)
+resize2fs.8: $(DEP_SUBSTITUTE) $(srcdir)/resize2fs.8.in
$(SUBSTITUTE) $(srcdir)/resize2fs.8.in resize2fs.8
test_extent: $(TEST_EXTENT_OBJS)
--- /dev/null
+#
+# Standard e2fsprogs prologue....
+#
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+top_builddir = ..
+my_dir = util
+INSTALL = @INSTALL@
+
+SRCS = $(srcdir)/subst.c
+
+@MCONFIG@
+
+.c.o:
+ $(CC) -c $(ALL_CFLAGS) $< -o $@
+
+PROGS= subst
+
+all:: $(PROGS)
+
+subst: subst.o
+ $(CC) $(ALL_LDFLAGS) -o subst subst.o
+
+clean:
+ $(RM) -f $(PROGS) \#* *.s *.o *.a *~ core
+
+mostlyclean: clean
+
+distclean: clean
+ $(RM) -f .depend Makefile
+
+# +++ Dependency line eater +++
+#
+# Makefile dependencies follow. This must be the last section in
+# the Makefile.in file
+#
+subst.o: $(srcdir)/subst.c
--- /dev/null
+/*
+ * subst.c --- substitution program
+ *
+ * Subst is used as a quicky program to do @ substitutions
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <ctype.h>
+
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
+
+struct subst_entry {
+ char *name;
+ char *value;
+ struct subst_entry *next;
+};
+
+struct subst_entry *subst_table = 0;
+
+static int add_subst(char *name, char *value)
+{
+ struct subst_entry *ent = 0;
+ int retval;
+
+ retval = ENOMEM;
+ ent = malloc(sizeof(struct subst_entry));
+ if (!ent)
+ goto fail;
+ ent->name = malloc(strlen(name)+1);
+ if (!ent->name)
+ goto fail;
+ ent->value = malloc(strlen(value)+1);
+ if (!ent->value)
+ goto fail;
+ strcpy(ent->name, name);
+ strcpy(ent->value, value);
+ ent->next = subst_table;
+ subst_table = ent;
+ return 0;
+fail:
+ if (ent) {
+ if (ent->name)
+ free(ent->name);
+ if (ent->value)
+ free(ent->value);
+ free(ent);
+ }
+ return retval;
+}
+
+static struct subst_entry *fetch_subst_entry(char *name)
+{
+ struct subst_entry *ent;
+
+ for (ent = subst_table; ent; ent = ent->next) {
+ if (strcmp(name, ent->name) == 0)
+ break;
+ }
+ return ent;
+}
+
+static void substitute_line(char *line)
+{
+ char *ptr, *name_ptr, *end_ptr;
+ struct subst_entry *ent;
+ char replace_name[128];
+ int len, replace_len;
+
+ ptr = line;
+ while (ptr) {
+ name_ptr = strchr(ptr, '@');
+ if (!name_ptr)
+ break;
+ end_ptr = strchr(name_ptr+1, '@');
+ if (!end_ptr)
+ break;
+ len = end_ptr - name_ptr - 1;
+ memcpy(replace_name, name_ptr+1, len);
+ replace_name[len] = 0;
+ ent = fetch_subst_entry(replace_name);
+ if (!ent) {
+ fprintf(stderr, "Unfound expansion: '%s'\n",
+ replace_name);
+ ptr = end_ptr + 1;
+ continue;
+ }
+#if 0
+ fprintf(stderr, "Replace name = '%s' with '%s'\n",
+ replace_name, ent->value);
+#endif
+ replace_len = strlen(ent->value);
+ if (replace_len != len+2)
+ memmove(end_ptr+(replace_len-len-2), end_ptr,
+ strlen(end_ptr)+1);
+ memcpy(name_ptr, ent->value, replace_len);
+ ptr = name_ptr;
+ }
+}
+
+static void parse_config_file(FILE *f)
+{
+ char line[2048];
+ char *cp, *ptr;
+
+ while (!feof(f)) {
+ memset(line, 0, sizeof(line));
+ if (fgets(line, sizeof(line), f) == NULL)
+ break;
+ /*
+ * Strip newlines and comments.
+ */
+ cp = strchr(line, '\n');
+ if (cp)
+ *cp = 0;
+ cp = strchr(line, '#');
+ if (cp)
+ *cp = 0;
+ /*
+ * Skip trailing and leading whitespace
+ */
+ for (cp = line + strlen(line) - 1; cp >= line; cp--) {
+ if (*cp == ' ' || *cp == '\t')
+ *cp = 0;
+ else
+ break;
+ }
+ cp = line;
+ while (*cp && isspace(*cp))
+ cp++;
+ ptr = cp;
+ /*
+ * Skip empty lines
+ */
+ if (*ptr == 0)
+ continue;
+ /*
+ * Ignore future extensions
+ */
+ if (*ptr == '$')
+ continue;
+ /*
+ * Parse substitutions
+ */
+ for (cp = ptr; *cp; cp++)
+ if (isspace(*cp))
+ break;
+ *cp = 0;
+ for (cp++; *cp; cp++)
+ if (!isspace(*cp))
+ break;
+#if 0
+ printf("Substitute: '%s' for '%s'\n", ptr, cp);
+#endif
+ add_subst(ptr, cp);
+ }
+}
+
+/*
+ * Return 0 if the files are different, 1 if the files are the same.
+ */
+static int compare_file(const char *outfn, const char *newfn)
+{
+ FILE *old, *new;
+ char oldbuf[2048], newbuf[2048], *oldcp, *newcp;
+ int retval;
+
+ old = fopen(outfn, "r");
+ if (!old)
+ return 0;
+ new = fopen(newfn, "r");
+ if (!new)
+ return 0;
+
+ while (1) {
+ oldcp = fgets(oldbuf, sizeof(oldbuf), old);
+ newcp = fgets(newbuf, sizeof(newbuf), new);
+ if (!oldcp && !newcp) {
+ retval = 1;
+ break;
+ }
+ if (!oldcp || !newcp || strcmp(oldbuf, newbuf)) {
+ retval = 0;
+ break;
+ }
+ }
+ return retval;
+}
+
+
+
+
+int main(int argc, char **argv)
+{
+ char line[2048];
+ int c;
+ FILE *in, *out;
+ char *outfn = NULL, *newfn = NULL;
+ int verbose = 0;
+
+ while ((c = getopt (argc, argv, "f:v")) != EOF) {
+ switch (c) {
+ case 'f':
+ in = fopen(optarg, "r");
+ if (!in) {
+ perror(optarg);
+ exit(1);
+ }
+ parse_config_file(in);
+ fclose(in);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ default:
+ fprintf(stderr, "%s: [-f config-file] [file]\n",
+ argv[0]);
+ break;
+ }
+ }
+ if (optind < argc) {
+ in = fopen(argv[optind], "r");
+ if (!in) {
+ perror(argv[optind]);
+ exit(1);
+ }
+ optind++;
+ } else
+ in = stdin;
+
+ if (optind < argc) {
+ outfn = argv[optind];
+ newfn = malloc(strlen(outfn)+20);
+ if (!newfn) {
+ fprintf(stderr, "Memory error! Exiting.\n");
+ exit(1);
+ }
+ strcpy(newfn, outfn);
+ strcat(newfn, ".new");
+ out = fopen(newfn, "w");
+ if (!out) {
+ perror(newfn);
+ exit(1);
+ }
+ } else {
+ out = stdout;
+ outfn = 0;
+ }
+
+ while (!feof(in)) {
+ if (fgets(line, sizeof(line), in) == NULL)
+ break;
+ substitute_line(line);
+ fputs(line, out);
+ }
+ fclose(in);
+ fclose(out);
+ if (outfn) {
+ if (compare_file(outfn, newfn)) {
+ if (verbose)
+ printf("No change, keeping %s.\n", outfn);
+ unlink(newfn);
+ } else {
+ if (verbose)
+ printf("Creating or replacing %s.\n", outfn);
+ rename(newfn, outfn);
+ }
+ }
+ return (0);
+}
+
+
--- /dev/null
+AWK @AWK@
+SED @SED@
+ET_DIR @ET_DIR@
+SS_DIR @SS_DIR@
+E2FSPROGS_MONTH @E2FSPROGS_MONTH@
+E2FSPROGS_YEAR @E2FSPROGS_YEAR@
+E2FSPROGS_VERSION @E2FSPROGS_VERSION@
+SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@
+SIZEOF_LONG @SIZEOF_LONG@
+SIZEOF_INT @SIZEOF_INT@
+SIZEOF_SHORT @SIZEOF_SHORT@
* redistributed under the GNU Public License.
*/
-#define E2FSPROGS_VERSION "1.11"
-#define E2FSPROGS_DATE "16-Jun-97"
+#define E2FSPROGS_VERSION "1.11-test"
+#define E2FSPROGS_DATE "16-Aug-97"
+