Whamcloud - gitweb
Many files:
authorTheodore Ts'o <tytso@mit.edu>
Wed, 15 Oct 1997 02:47:20 +0000 (02:47 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 15 Oct 1997 02:47:20 +0000 (02:47 +0000)
  Use new substitution technology which doesn't depend on shell scripts.
  (Faster, and better for MS-DOS port!)

17 files changed:
MCONFIG.in
Makefile.in
configure
configure.in
debugfs/Makefile.in
e2fsck/Makefile.in
lib/do_substitute [deleted file]
lib/et/Makefile.in
lib/ext2fs/Makefile.in
lib/ss/Makefile.in
lib/substitute_sh.in [deleted file]
misc/Makefile.in
resize/Makefile.in
util/Makefile.in [new file with mode: 0644]
util/subst.c [new file with mode: 0644]
util/subst.conf.in [new file with mode: 0644]
version.h

index f01e4e2..3f26b5e 100644 (file)
@@ -85,7 +85,9 @@ LINUX_INCLUDE=@LINUX_INCLUDE@
 #
 # 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
@@ -162,8 +164,4 @@ depend:: .depend
        $(MV) $(srcdir)/Makefile.in.new $(srcdir)/Makefile.in; \
        else :; fi
 
-
-
-
-
 # End of file MCONFIG
index 6507ee5..dd9ef7d 100644 (file)
@@ -69,10 +69,9 @@ distclean: distclean-recursive distclean-local
 
 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 
index d66611c..b030635 100644 (file)
--- a/configure
+++ b/configure
@@ -2483,7 +2483,7 @@ done
 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
@@ -2629,7 +2629,7 @@ EOF
 
 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"}
index f83c5a4..35f6f7e 100644 (file)
@@ -508,7 +508,7 @@ rmakefile=
 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)
index 7cb8cea..3fafc15 100644 (file)
@@ -36,8 +36,7 @@ debugfs: $(DEBUG_OBJS) $(DEPLIBS)
 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:
index e16c12f..03541c5 100644 (file)
@@ -109,8 +109,7 @@ iscan: iscan.o util.o
 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:
diff --git a/lib/do_substitute b/lib/do_substitute
deleted file mode 100644 (file)
index e18c3f4..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# 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
index a0b05b3..ab9bb23 100644 (file)
@@ -62,8 +62,7 @@ BSDLIB_INSTALL_DIR = $(libdir)
 @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
 
index 547f2a4..7eabde9 100644 (file)
@@ -150,8 +150,7 @@ COMPILE_ET=../et/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
index e3c3571..1042b2e 100644 (file)
@@ -123,8 +123,7 @@ ct.tab.c ct.tab.h: ct.y
 #      $(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
 
diff --git a/lib/substitute_sh.in b/lib/substitute_sh.in
deleted file mode 100644 (file)
index f80d4d9..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/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@
index 0c3126a..66cb76f 100644 (file)
@@ -45,7 +45,7 @@ DEPLIBS_E2P= $(LIBEXT2FS) $(LIBE2P) $(LIBCOM_ERR)
 .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)
@@ -81,31 +81,28 @@ fsck: $(FSCK_OBJS)
 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:
index 1c0a8e7..80ee969 100644 (file)
@@ -38,8 +38,7 @@ all:: $(PROGS) $(TEST_PROGS) $(MANPAGES)
 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)
diff --git a/util/Makefile.in b/util/Makefile.in
new file mode 100644 (file)
index 0000000..29751f5
--- /dev/null
@@ -0,0 +1,39 @@
+#
+# 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
diff --git a/util/subst.c b/util/subst.c
new file mode 100644 (file)
index 0000000..82779f9
--- /dev/null
@@ -0,0 +1,279 @@
+/*
+ * 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);
+}
+
+
diff --git a/util/subst.conf.in b/util/subst.conf.in
new file mode 100644 (file)
index 0000000..9108659
--- /dev/null
@@ -0,0 +1,11 @@
+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@
index 77e6ca3..e96ff84 100644 (file)
--- a/version.h
+++ b/version.h
@@ -6,5 +6,6 @@
  * 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"
+