diff options
author | Guido Guenther <agx@sigxcpu.org> | 2006-11-18 23:48:07 +0100 |
---|---|---|
committer | Guido Guenther <agx@bogon.sigxcpu.org> | 2006-11-18 23:48:07 +0100 |
commit | d1e063beb43e595680c65e3804d1f8ddff53373b (patch) | |
tree | f7256dfe1b807920270ec5113df6f6e4abf1ed0f /e2fslib/util |
Imported Debian version 0.3.8.80.3.8.8
Diffstat (limited to 'e2fslib/util')
-rw-r--r-- | e2fslib/util/.cvsignore | 1 | ||||
-rw-r--r-- | e2fslib/util/ChangeLog | 132 | ||||
-rw-r--r-- | e2fslib/util/Makefile | 231 | ||||
-rw-r--r-- | e2fslib/util/Makefile.in | 39 | ||||
-rw-r--r-- | e2fslib/util/gcc-wall-cleanup | 17 | ||||
-rw-r--r-- | e2fslib/util/libecho.c | 78 | ||||
-rwxr-xr-x | e2fslib/util/subst | bin | 0 -> 80037 bytes | |||
-rw-r--r-- | e2fslib/util/subst.c | 374 | ||||
-rw-r--r-- | e2fslib/util/subst.conf | 16 | ||||
-rw-r--r-- | e2fslib/util/subst.conf.in | 16 | ||||
-rw-r--r-- | e2fslib/util/subst.o | bin | 0 -> 16392 bytes |
11 files changed, 904 insertions, 0 deletions
diff --git a/e2fslib/util/.cvsignore b/e2fslib/util/.cvsignore new file mode 100644 index 0000000..6073b06 --- /dev/null +++ b/e2fslib/util/.cvsignore @@ -0,0 +1 @@ +subst diff --git a/e2fslib/util/ChangeLog b/e2fslib/util/ChangeLog new file mode 100644 index 0000000..e3ad187 --- /dev/null +++ b/e2fslib/util/ChangeLog @@ -0,0 +1,132 @@ +2001-09-20 Theodore Tso <tytso@thunk.org> + + * Release of E2fsprogs 1.25 + +2001-09-02 Theodore Tso <tytso@thunk.org> + + * Release of E2fsprogs 1.24a + +2001-08-30 Theodore Tso <tytso@thunk.org> + + * Release of E2fsprogs 1.24 + +2001-08-15 Theodore Tso <tytso@valinux.com> + + * Release of E2fsprogs 1.23 + +2001-07-27 Theodore Tso <tytso@valinux.com> + + * subst.conf.in: Enable documentation of the external journal + functionality in mke2fs, e2fsck, and tune2fs. + +2001-06-23 Theodore Tso <tytso@valinux.com> + + * Release of E2fsprogs 1.22 + +2001-06-15 Theodore Tso <tytso@valinux.com> + + * Release of E2fsprogs 1.21 + +2001-05-25 Theodore Tso <tytso@valinux.com> + + * Release of E2fsprogs 1.20 + +2001-04-21 Theodore Tso <tytso@valinux.com> + + * subst.conf.in: Add definition of JDEV for mke2fs' and tune2fs' + man page. + +2001-04-17 Theodore Tso <tytso@valinux.com> + + * subst.c (replace_string): Fix replace_string so that it + correctly handles replacing a substitution variable with a + zero-length string. + +2001-01-14 Theodore Ts'o <tytso@valinux.com> + + * gcc-wall-cleanup: Remove additional annoying warning messages + emited by gcc 2.95.2. + +2001-01-11 <tytso@snap.thunk.org> + + * gcc-wall-cleanup: New file which is used to clean up unnecessary + crud from gcc -Wall that we're not interested in seeing + +2000-07-13 <tytso@valinux.com> + + * Release of E2fsprogs 1.19 + +2000-04-03 Theodore Ts'o <tytso@valinux.com> + + * subst.c: For platforms that don't define optarg.h, manually + define optarg and optind. + +1999-11-19 <tytso@valinux.com> + + * Makefile.in (distclean): Remove TAGS and Makefile.in.old from + the source directory. + +1999-11-10 <tytso@valinux.com> + + * Release of E2fsprogs 1.18 + +1999-10-26 <tytso@valinux.com> + + * Release of E2fsprogs 1.17 + +1999-10-26 <tytso@valinux.com> + + * subst.c (substitute_line): Removed some unused variables. + +1999-10-22 <tytso@valinux.com> + + * Release of E2fsprogs 1.16 + +1999-07-18 Theodore Ts'o <tytso@rsts-11.mit.edu> + + * Release of E2fsprogs 1.15 + +1999-07-03 <tytso@valinux.com> + + * Makefile.in (subst): Build subst using $(BUILD_CC), since it's a + helper program which must be built using the native C + compiler during a cross-compilation. + +1999-01-09 Theodore Ts'o <tytso@rsts-11.mit.edu> + + * Release of E2fsprogs 1.14 + +1998-12-15 Theodore Ts'o <tytso@rsts-11.mit.edu> + + * Release of E2fsprogs 1.13 + +1998-12-15 Theodore Ts'o <tytso@rsts-11.mit.edu> + + * subst.c (get_subst_symbol): Add [0-9] to the list of valid + characters for a substitution symbol. + +1998-08-01 Theodore Ts'o <tytso@rsts-11.mit.edu> + + * subst.c: Add the ability to substitute apparent shell/make + variables such as ${prefix}, since this is needed to make + the shell scripts work correctly. + + * subst.conf.in: Add ${prefix} to the list of substitutions which + subst should make. + +1998-07-09 Theodore Ts'o <tytso@rsts-11.mit.edu> + + * Release of E2fsprogs 1.12 + +1998-03-31 Theodore Ts'o <tytso@rsts-11.mit.edu> + + * subst.conf.in: Add substitution for @datadir@ + +Mon Jan 19 09:25:24 1998 Theodore Ts'o <tytso@rsts-11.mit.edu> + + * subst.c: Rename "new" to "new_f" to avoid C++ reserved word + clash. + + * subst.c: Explicitly cast all assignments from void * to be + compatible with C++. + diff --git a/e2fslib/util/Makefile b/e2fslib/util/Makefile new file mode 100644 index 0000000..2ae1be5 --- /dev/null +++ b/e2fslib/util/Makefile @@ -0,0 +1,231 @@ +# Generated automatically from Makefile.in by configure. +# +# Standard e2fsprogs prologue.... +# + +srcdir = . +top_srcdir = .. +top_builddir = .. +my_dir = util +INSTALL = /usr/bin/install -c + +SRCS = $(srcdir)/subst.c + + +# Beginning of file MCONFIG + +all:: + +check:: + +SHELL = /bin/sh + +prefix = /usr +root_prefix = +exec_prefix = ${prefix} +root_bindir = $(root_prefix)/bin +root_sbindir = $(root_prefix)/sbin +root_libdir = $(root_prefix)/lib +bindir = ${exec_prefix}/bin +sbindir = ${exec_prefix}/sbin +libdir = ${exec_prefix}/lib +includedir = ${prefix}/include +mandir = ${prefix}/man +man1dir = $(mandir)/man1 +man3dir = $(mandir)/man3 +man8dir = $(mandir)/man8 +infodir = ${prefix}/info +datadir = ${prefix}/share + + + +INSTALL_PROGRAM = ${INSTALL} +INSTALL_DATA = ${INSTALL} -m 644 +CC = cc +BUILD_CC = cc +DEFS = -DENABLE_SWAPFS=1 -DPACKAGE=\"e2fsprogs\" -DVERSION=\"1.25\" -DSTDC_HEADERS=1 -DHAVE_ALLOCA_H=1 -DHAVE_ALLOCA=1 -DHAVE_UNISTD_H=1 -DHAVE_GETPAGESIZE=1 -DHAVE_MMAP=1 -DHAVE_ARGZ_H=1 -DHAVE_LIMITS_H=1 -DHAVE_LOCALE_H=1 -DHAVE_NL_TYPES_H=1 -DHAVE_MALLOC_H=1 -DHAVE_STRING_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_GETCWD=1 -DHAVE_MUNMAP=1 -DHAVE_PUTENV=1 -DHAVE_SETENV=1 -DHAVE_SETLOCALE=1 -DHAVE_STRCHR=1 -DHAVE_STRCASECMP=1 -DHAVE_STRDUP=1 -DHAVE___ARGZ_COUNT=1 -DHAVE___ARGZ_STRINGIFY=1 -DHAVE___ARGZ_NEXT=1 -DHAVE_STPCPY=1 -DHAVE_STPCPY=1 -DHAVE_LC_MESSAGES=1 -DHAVE_STDLIB_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STDARG_H=1 -DHAVE_ERRNO_H=1 -DHAVE_MALLOC_H=1 -DHAVE_MNTENT_H=1 -DHAVE_PATHS_H=1 -DHAVE_DIRENT_H=1 -DHAVE_GETOPT_H=1 -DHAVE_SETJMP_H=1 -DHAVE_SIGNAL_H=1 -DHAVE_TERMIOS_H=1 -DHAVE_LINUX_FD_H=1 -DHAVE_LINUX_MAJOR_H=1 -DHAVE_SYS_IOCTL_H=1 -DHAVE_SYS_MOUNT_H=1 -DHAVE_SYS_SYSMACROS_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_NET_IF_H=1 -DHAVE_NETINET_IN_H=1 -DHAVE_VPRINTF=1 -DHAVE_LSEEK64_PROTOTYPE=1 -DSIZEOF_SHORT=2 -DSIZEOF_INT=4 -DSIZEOF_LONG=4 -DSIZEOF_LONG_LONG=8 -DWORDS_BIGENDIAN=1 -DHAVE_GETRUSAGE=1 -DHAVE_LLSEEK=1 -DHAVE_LSEEK64=1 -DHAVE_OPEN64=1 -DHAVE_STRCASECMP=1 -DHAVE_SRANDOM=1 -DHAVE_FCHOWN=1 -DHAVE_MALLINFO=1 -DHAVE_FDATASYNC=1 -DHAVE_STRNLEN=1 -DHAVE_EXT2_IOCTLS=1 +CFLAGS = -g -O2 +CPPFLAGS = +ALL_CFLAGS = $(CPPFLAGS) $(DEFS) $(USE_WFLAGS) $(CFLAGS) $(XTRA_CFLAGS) \ + -I$(top_builddir)/lib -I$(top_srcdir)/lib \ + -I$(top_srcdir)/include $(LINUX_INCLUDE) +LDFLAGS = +ALL_LDFLAGS = $(LDFLAGS) +RM = /bin/rm +LN = /bin/ln +LN_S = ln -s +MV = /bin/mv +CP = /bin/cp +CHMOD = /bin/chmod +AR = ar +AWK = /usr/bin/awk +SED = /bin/sed +PERL = /usr/bin/perl +RANLIB = ranlib +STRIP = strip +LD = $(PURE) cc +ARUPD = $(AR) r +LDCONFIG = : + +# +# Library definitions +# +LIB = $(top_builddir)/lib +LIBSS = $(LIB)/libss.a +LIBCOM_ERR = $(LIB)/libcom_err.a +LIBE2P = $(LIB)/libe2p.a +LIBEXT2FS = $(LIB)/libext2fs.a +LIBUUID = $(LIB)/libuuid.a +DEPLIBUUID = $(LIB)/libuuid.a + +STATIC_LIBSS = $(LIB)/libss.a +STATIC_LIBCOM_ERR = $(LIB)/libcom_err.a +STATIC_LIBE2P = $(LIB)/libe2p.a +STATIC_LIBEXT2FS = $(LIB)/libext2fs.a +STATIC_LIBUUID = $(LIB)/libuuid.a +DEPSTATIC_LIBUUID = $(LIB)/libuuid.a + +PROFILED_LIBSS = $(LIB)/libss +PROFILED_LIBCOM_ERR = $(LIB)/libcom_err +PROFILED_LIBE2P = $(LIB)/libe2p +PROFILED_LIBEXT2FS = $(LIB)/libext2fs +PROFILED_LIBUUID = $(LIB)/libuuid +DEPPROFILED_LIBUUID = $(LIB)/libuuid + +# +# Use these definitions is you use tools 2.x, x < 16 +# +#DLL_BIN=/usr/dll/bin +#JUMP_PREFIX=/usr/dll/jump/ + +# +# Use these definitions if you use tools 2.16 or above +# +DLL_BIN=/usr/bin +JUMP_PREFIX=/usr/bin/jump + +# An include directive pointing to a directory holding enough linux-like +# include files to satisfy some programs here +LINUX_INCLUDE= + +# +# A fast substitution command for fixing up man pages, shell scripts, etc. +# +SUBST_CONF=$(top_builddir)/util/subst.conf +SUBSTITUTE= $(top_builddir)/util/subst -f $(SUBST_CONF) +DEP_SUBSTITUTE= $(top_builddir)/util/subst $(SUBST_CONF) + +$(top_builddir)/util/subst: + cd $(top_builddir)/util ; $(MAKE) subst + +# +# Warning flags +# +# Run make gcc-wall to do a build with warning messages. +# +# +WFLAGS= -ansi -D_POSIX_SOURCE -pedantic \ + -Wall -Wwrite-strings -Wpointer-arith \ + -Wcast-qual -Wcast-align -Wtraditional \ + -Wstrict-prototypes -Wmissing-prototypes \ + -Wnested-externs -Winline -DNO_INLINE_FUNCS -Wshadow + +gcc-wall-new: + (make USE_WFLAGS="$(WFLAGS)" > /dev/null) 2>&1 | sed -f $(top_srcdir)/util/gcc-wall-cleanup + +gcc-wall: + make clean > /dev/null + make gcc-wall-new + +# +# Installation user and groups +# +BINGRP= bin +BINOWN= bin +BINMODE= 555 +INCGRP= bin +INCOWN= bin +INCMODE= 444 +LIBOWN= bin +LIBGRP= bin +LIBMODE= 444 +MANGRP= bin +MANOWN= bin +MANMODE= 444 + +# +# Autoconf magic... +# + +DEP_LIB_MAKEFILES = $(top_srcdir)/lib/Makefile.elf-lib \ + $(top_srcdir)/lib/Makefile.dll-lib $(top_srcdir)/lib/Makefile.bsd-lib \ + $(top_srcdir)/lib/Makefile.checker $(top_srcdir)/lib/Makefile.profile + +$(top_builddir)/config.status: $(top_srcdir)/configure + cd $(top_builddir); ./config.status --recheck + +$(top_builddir)/lib/substitute_sh: $(top_srcdir)/lib/substitute_sh.in \ + $(top_builddir)/config.status + cd $(top_builddir); CONFIG_FILES=lib/substitute_sh ./config.status + +$(top_builddir)/util/subst.conf: $(top_srcdir)/util/subst.conf.in \ + $(top_builddir)/config.status + cd $(top_builddir); CONFIG_FILES=util/subst.conf ./config.status + +$(top_srcdir)/configure: $(top_srcdir)/configure.in + cd $(top_srcdir) && autoconf + +# +# Make depend magic... +# + +.depend: Makefile $(SRCS) $(top_srcdir)/depfix.sed $(top_srcdir)/wordwrap.pl + if test -n "$(SRCS)" ; then \ + $(CC) -M $(ALL_CFLAGS) $(SRCS) | \ + $(SED) -f $(top_srcdir)/depfix.sed \ + -e 's; $(srcdir)/; $$(srcdir)/;g' \ + -e 's; $(top_srcdir)/; $$(top_srcdir)/;g' \ + -e 's; $(top_builddir)/; $$(top_builddir)/;g' \ + -e 's; \./; ;g' \ + -e '/^ *\\$$/d' | \ + $(PERL) $(top_srcdir)/wordwrap.pl > .depend; \ + else :; fi + +depend:: .depend + if test -n "$(SRCS)" ; then \ + sed -e '/^# +++ Dependency line eater +++/,$$d' \ + < $(srcdir)/Makefile.in | cat - .depend \ + > $(srcdir)/Makefile.in.new; \ + if cmp -s $(srcdir)/Makefile.in $(srcdir)/Makefile.in.new ; then \ + $(RM) $(srcdir)/Makefile.in.new ; \ + else \ + $(MV) $(srcdir)/Makefile.in $(srcdir)/Makefile.in.old; \ + $(MV) $(srcdir)/Makefile.in.new $(srcdir)/Makefile.in; \ + fi ; else :; fi + +# End of file MCONFIG + +.c.o: + $(BUILD_CC) -c $(ALL_CFLAGS) $< -o $@ + +PROGS= subst + +all:: $(PROGS) + +subst: subst.o + $(BUILD_CC) $(ALL_LDFLAGS) -o subst subst.o + +clean: + $(RM) -f $(PROGS) \#* *.s *.o *.a *~ core + +mostlyclean: clean + +distclean: clean + $(RM) -f .depend Makefile $(srcdir)/TAGS $(srcdir)/Makefile.in.old + +# +++ 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/e2fslib/util/Makefile.in b/e2fslib/util/Makefile.in new file mode 100644 index 0000000..ed224a4 --- /dev/null +++ b/e2fslib/util/Makefile.in @@ -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: + $(BUILD_CC) -c $(ALL_CFLAGS) $< -o $@ + +PROGS= subst + +all:: $(PROGS) + +subst: subst.o + $(BUILD_CC) $(ALL_LDFLAGS) -o subst subst.o + +clean: + $(RM) -f $(PROGS) \#* *.s *.o *.a *~ core + +mostlyclean: clean + +distclean: clean + $(RM) -f .depend Makefile $(srcdir)/TAGS $(srcdir)/Makefile.in.old + +# +++ 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/e2fslib/util/gcc-wall-cleanup b/e2fslib/util/gcc-wall-cleanup new file mode 100644 index 0000000..4d817b1 --- /dev/null +++ b/e2fslib/util/gcc-wall-cleanup @@ -0,0 +1,17 @@ +#!/bin/sed -f +# +# This script filters out gcc-wall crud that we're not interested in seeing. +# +/^cc /d +/^kcc /d +/^gcc /d +/does not support `long long'/d +/does not support the `ll' length modifier/d +/ANSI C forbids long long integer constants/d +/traditional C rejects string concatenation/d +/integer constant is unsigned in ANSI C, signed with -traditional/d +/At top level:/d +/In file included from/d +/In function `.*':/d +/^[ ]*from/d + diff --git a/e2fslib/util/libecho.c b/e2fslib/util/libecho.c new file mode 100644 index 0000000..352ce1e --- /dev/null +++ b/e2fslib/util/libecho.c @@ -0,0 +1,78 @@ +/* + * libecho.c + * + * For each argument on the command line, echo it. Should expand + * DOS wildcards correctly. + * + * Syntax: libecho [-p prefix] list... + */ +#include <stdio.h> +#include <io.h> +#include <string.h> + +void echo_files(char *, char *); + +int +main(int argc, char *argv[]) +{ + int i; + char *prefix; + + prefix = ""; + + if (argc < 2) { + fprintf(stderr, "Usage: libecho [-p prefix] list...\n"); + return 1; + } + + for (i = 1 ; i < argc ; i++) + if (!stricmp(argv[i], "-p")) + prefix = argv[++i]; + else + echo_files(prefix, argv[i]); + + return 0; +} + +void +echo_files(char *prefix, char *f) +{ + long ff; + struct _finddata_t fdt; + char *slash; + char filepath[256]; + + /* + * We're unix based quite a bit here. Look for normal slashes and + * make them reverse slashes. + */ + while((slash = strrchr(f, '/')) != NULL) + *slash = '\\'; + + strcpy(filepath, f); + + slash = strrchr(filepath, '\\'); + + if (slash) { + slash++; + *slash = 0; + } else { + filepath[0] = '\0'; + } + + ff = _findfirst(f, &fdt); + + if (ff < 0) { + printf("%s%s\n", prefix, f); + return; + } + + printf("%s%s%s\n", prefix, filepath, fdt.name); + + for (;;) { + if (_findnext(ff, &fdt) < 0) + break; + printf("%s%s%s\n", prefix, filepath, fdt.name); + } + _findclose(ff); +} diff --git a/e2fslib/util/subst b/e2fslib/util/subst Binary files differnew file mode 100755 index 0000000..47f1b05 --- /dev/null +++ b/e2fslib/util/subst diff --git a/e2fslib/util/subst.c b/e2fslib/util/subst.c new file mode 100644 index 0000000..7b7ba83 --- /dev/null +++ b/e2fslib/util/subst.c @@ -0,0 +1,374 @@ +/* + * 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> +#else +extern char *optarg; +extern int optind; +#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 = (struct subst_entry *) malloc(sizeof(struct subst_entry)); + if (!ent) + goto fail; + ent->name = (char *) malloc(strlen(name)+1); + if (!ent->name) + goto fail; + ent->value = (char *) 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; +} + +/* + * Given the starting and ending position of the replacement name, + * check to see if it is valid, and pull it out if it is. + */ +static char *get_subst_symbol(const char *begin, int len, char prefix) +{ + static char replace_name[128]; + char *cp, *start; + + start = replace_name; + if (prefix) + *start++ = prefix; + + if (len > sizeof(replace_name)-2) + return NULL; + memcpy(start, begin, len); + start[len] = 0; + + /* + * The substitution variable must all be in the of [0-9A-Za-z_]. + * If it isn't, this must be an invalid symbol name. + */ + for (cp = start; *cp; cp++) { + if (!(*cp >= 'a' && *cp <= 'z') && + !(*cp >= 'A' && *cp <= 'Z') && + !(*cp >= '0' && *cp <= '9') && + !(*cp == '_')) + return NULL; + } + return (replace_name); +} + +static void replace_string(char *begin, char *end, char *newstr) +{ + int replace_len, len; + + replace_len = strlen(newstr); + len = end - begin; + if (replace_len == 0) + memmove(begin, end+1, strlen(end)+1); + else if (replace_len != len+1) + memmove(end+(replace_len-len-1), end, + strlen(end)+1); + memcpy(begin, newstr, replace_len); +} + +static void substitute_line(char *line) +{ + char *ptr, *name_ptr, *end_ptr; + struct subst_entry *ent; + char *replace_name; + int len; + + /* + * Expand all @FOO@ substitutions + */ + ptr = line; + while (ptr) { + name_ptr = strchr(ptr, '@'); + if (!name_ptr) + break; /* No more */ + if (*(++name_ptr) == '@') { + /* + * Handle tytso@@mit.edu --> tytso@mit.edu + */ + memmove(name_ptr-1, name_ptr, strlen(name_ptr)+1); + ptr = name_ptr+1; + continue; + } + end_ptr = strchr(name_ptr, '@'); + if (!end_ptr) + break; + len = end_ptr - name_ptr; + replace_name = get_subst_symbol(name_ptr, len, 0); + if (!replace_name) { + ptr = name_ptr; + continue; + } + 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 + ptr = name_ptr-1; + replace_string(ptr, end_ptr, ent->value); + } + /* + * Now do a second pass to expand ${FOO} + */ + ptr = line; + while (ptr) { + name_ptr = strchr(ptr, '$'); + if (!name_ptr) + break; /* No more */ + if (*(++name_ptr) != '{') { + ptr = name_ptr; + continue; + } + name_ptr++; + end_ptr = strchr(name_ptr, '}'); + if (!end_ptr) + break; + len = end_ptr - name_ptr; + replace_name = get_subst_symbol(name_ptr, len, '$'); + if (!replace_name) { + ptr = name_ptr; + continue; + } + ent = fetch_subst_entry(replace_name); + if (!ent) { + ptr = end_ptr + 1; + continue; + } +#if 0 + fprintf(stderr, "Replace name = '%s' with '%s'\n", + replace_name, ent->value); +#endif + ptr = name_ptr-2; + replace_string(ptr, end_ptr, ent->value); + } +} + +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 ? cp : "<NULL>"); +#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_f, *new_f; + char oldbuf[2048], newbuf[2048], *oldcp, *newcp; + int retval; + + old_f = fopen(outfn, "r"); + if (!old_f) + return 0; + new_f = fopen(newfn, "r"); + if (!new_f) + return 0; + + while (1) { + oldcp = fgets(oldbuf, sizeof(oldbuf), old_f); + newcp = fgets(newbuf, sizeof(newbuf), new_f); + if (!oldcp && !newcp) { + retval = 1; + break; + } + if (!oldcp || !newcp || strcmp(oldbuf, newbuf)) { + retval = 0; + break; + } + } + fclose(old_f); + fclose(new_f); + 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 = (char *) 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/e2fslib/util/subst.conf b/e2fslib/util/subst.conf new file mode 100644 index 0000000..eaa3811 --- /dev/null +++ b/e2fslib/util/subst.conf @@ -0,0 +1,16 @@ +AWK /usr/bin/awk +SED /bin/sed +ET_DIR et +SS_DIR et +E2FSPROGS_MONTH September +E2FSPROGS_YEAR 2001 +E2FSPROGS_VERSION 1.25 +SIZEOF_LONG_LONG 8 +SIZEOF_LONG 4 +SIZEOF_INT 4 +SIZEOF_SHORT 2 +datadir ${prefix}/share +$prefix /usr +# Enable the documentation for the journal device mke2fs, tune2fs, and +# e2fsck's man page +JDEV diff --git a/e2fslib/util/subst.conf.in b/e2fslib/util/subst.conf.in new file mode 100644 index 0000000..23c91f7 --- /dev/null +++ b/e2fslib/util/subst.conf.in @@ -0,0 +1,16 @@ +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@ +datadir @datadir@ +$prefix @prefix@ +# Enable the documentation for the journal device mke2fs, tune2fs, and +# e2fsck's man page +JDEV diff --git a/e2fslib/util/subst.o b/e2fslib/util/subst.o Binary files differnew file mode 100644 index 0000000..0f4f55a --- /dev/null +++ b/e2fslib/util/subst.o |