]> wimlib.net Git - wimlib/commitdiff
wimlib-imagex: Support being invoked as wimCOMMAND
authorEric Biggers <ebiggers3@gmail.com>
Wed, 14 Aug 2013 02:12:36 +0000 (21:12 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Wed, 14 Aug 2013 02:13:08 +0000 (21:13 -0500)
18 files changed:
Makefile.am
NEWS
doc/imagex-apply.1.in
doc/imagex-capture.1.in
doc/imagex-delete.1.in
doc/imagex-dir.1.in
doc/imagex-export.1.in
doc/imagex-extract.1.in
doc/imagex-info.1.in
doc/imagex-join.1.in
doc/imagex-mount.1.in
doc/imagex-optimize.1.in
doc/imagex-split.1.in
doc/imagex-update.1.in
doc/imagex.1.in
include/wimlib_tchar.h
programs/imagex.c
src/mount_image.c

index b6d4da951ebddbc1a8d9009e1a2fb52478e468cc..4cf31bf9419a300f7eb66e73ba23fab98f5d6df9 100644 (file)
@@ -153,17 +153,49 @@ imagex_SOURCES += programs/imagex-win32.c \
                  programs/wgetopt.h
 endif
 
+imagex_cmds =  append  \
+               apply   \
+               capture \
+               delete  \
+               dir     \
+               export  \
+               extract \
+               info    \
+               join    \
+               mount   \
+               mountrw \
+               optimize\
+               split   \
+               unmount \
+               update
+
 install-exec-hook:
-       if [ "@IMAGEX_PROGNAME@" != imagex ]; then \
+       if [ "@IMAGEX_PROGNAME@" != imagex ]; then                          \
                cd $(DESTDIR)$(bindir) && mv -f imagex "@IMAGEX_PROGNAME@"; \
-               cd $(DESTDIR)$(bindir) && ln -s "@IMAGEX_PROGNAME@" imagex; \
        fi
+       for cmd in $(imagex_cmds); do                           \
+               cd $(DESTDIR)$(bindir) &&                       \
+                       ln -f "@IMAGEX_PROGNAME@" wim$${cmd};   \
+       done
+
+install-data-hook:
+       for cmd in $(imagex_cmds); do                                       \
+               cd $(DESTDIR)$(mandir)/man1 &&                              \
+                       ln -sf "@IMAGEX_PROGNAME@-$${cmd}.1" wim$${cmd}.1;  \
+       done
 
 uninstall-hook:
-       if [ "@IMAGEX_PROGNAME@" != imagex ]; then \
-               cd $(DESTDIR)$(bindir) && rm -f "@IMAGEX_PROGNAME@"; \
-               cd $(DESTDIR)$(bindir) && rm -f imagex; \
+       if [ "@IMAGEX_PROGNAME@" != imagex ]; then              \
+               rm -f $(DESTDIR)$(bindir)/"@IMAGEX_PROGNAME@"   \
+               rm -f $(DESTDIR)$(bindir)/imagex                \
        fi
+       for cmd in $(imagex_cmds); do                           \
+               rm -f $(DESTDIR)$(bindir)/wim$${cmd};           \
+       done
+       for cmd in $(imagex_cmds); do                           \
+               rm -f $(DESTDIR)$(mandir)/man1/wim$${cmd}.1;    \
+       done
+
 
 dist_bin_SCRIPTS = programs/mkwinpeimg
 
diff --git a/NEWS b/NEWS
index d0d257530e12e5120c4e8340f5225e9070b98e31..e499cf00d238e682add165cbfaa2f1c079afa678 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,8 +9,14 @@ Version 1.5.0:
        support this: wimlib_write_to_fd() and wimlib_extract_image_from_pipe().
 
        wimlib now preserve WIM integrity tables by default, even if
-       WIMLIB_WRITE_FLAG_CHECK_INTEGRITY is not specified.  This affects
-       wimlib-imagex's behavior when --check is not specified.
+       WIMLIB_WRITE_FLAG_CHECK_INTEGRITY is not specified.  This changes the
+       behavior of `wimlib-imagex' whenever the WIM being operated on contains
+       an integrity table and the '--check' option is not specified.
+
+       `wimlib-imagex capture' now creates LZX-compressed WIMs by default
+       (when --compress is not specified).  This provides the best compression
+       ratio by default, which is usually what is desired, at a cost of some
+       speed.
 
        Security descriptors are now extracted correctly on Windows.
 
index 4b1a79aaaa71486284b04028797692d1e9dc0674..9ec08a314f01aa48085da08d7a5f5b00bfd441dc 100644 (file)
@@ -7,6 +7,8 @@
 \fB@IMAGEX_PROGNAME@ apply\fR extracts an image, or all images, from the Windows
 Imaging (WIM) file \fIWIMFILE\fR.  \fIWIMFILE\fR may be "-" to read the WIM from
 standard input, but see \fBPIPABLE WIMS\fR.
+This command is also available as simply \fBwimapply\fR if the appropriate hard
+link is installed.
 .PP
 This command is designed to extract, or "apply", one or more full WIM images.
 If you instead want to extract only certain files or directories contained in a
index cb651651d69c37349fb0434985e9cb74aad6b563..79a85b1b8701ecbd3dcf7c9c7fd390e1ce3936d1 100644 (file)
@@ -13,156 +13,185 @@ create a Windows Imaging (WIM) image from a directory tree.  The
 \fB@IMAGEX_PROGNAME@ capture\fR command creates a new WIM file containing the
 captured image, while the \fB@IMAGEX_PROGNAME@ append\fR command appends the
 captured image to an existing WIM file.
+These commands are also available as simply \fBwimcapture\fR and \fBwimappend\fR
+if the appropriate hard links or batch files are installed.
 .PP
-A WIM image is an independent directory tree in the WIM file.  A WIM file may
-contain any number of separate images.  However, files are stored only one time
+Background information: A WIM image is an independent directory tree in a WIM
+file.  A WIM file may contain any number of separate images.  WIM files are
+single-instancing with regards to file data, so a file is stored only one time
 in the entire WIM, regardless of how many images the file appears in.
 .PP
 \fISOURCE\fR specifies the location of the files to create the new WIM image
 from.  If \fISOURCE\fR is a directory, the WIM image is captured from that
-directory.   Alternatively, if the \fB--source-list\fR option is given,
+directory (see \fBDIRECTORY CAPTURE (UNIX)\fR or \fBDIRECTORY CAPTURE
+(WINDOWS)\fR.   Alternatively, if the \fB--source-list\fR option is specified,
 \fISOURCE\fR is interpreted as a file that itself provides a list of
 files and directories to include in the new WIM image.  Still
-alternatively, only on UNIX builds of wimlib, if \fISOURCE\fR is a
+alternatively, only on UNIX-like systems, if \fISOURCE\fR is a
 regular file or block device, it is interpreted as an NTFS volume from
-which a WIM image is to be captured. 
+which a WIM image is to be captured using libntfs-3g (see \fBNTFS VOLUME CAPTURE
+(UNIX)\fR.
 .PP
-\fIIMAGE_NAME\fR and \fIIMAGE_DESCRIPTION\fR specify the name and description of
-the new image.  If \fIIMAGE_NAME\fR is not given, it is taken to be the same as
-the base name of \fISOURCE\fR.  If \fIIMAGE_DESCRIPTION\fR is not given, no
-description is given to the new image.
+\fIIMAGE_NAME\fR and \fIIMAGE_DESCRIPTION\fR specify the name and description to
+give the new WIM image.  If \fIIMAGE_NAME\fR is not specified, it defaults to
+the base name (excluding path to parent directory) of \fISOURCE\fR, but if this
+name already exists in \fIWIMFILE\fR, a unique suffix is added.  Otherwise,
+\fIIMAGE_NAME\fR must be either a name that does not already exist as an image in
+\fIWIMFILE\fR, or the empty string to create an image with no name.  If
+\fIIMAGE_DESCRIPTION\fR is not specified, no description is given to the new
+image.
 .PP
 As a special case, if \fIWIMFILE\fR is "-", the \fB--pipable\fR option is
 assumed and the WIM file is written to standard output in a special pipable
 format.   See the documentation for \fB--pipable\fR for more details.
-.SH NORMAL MODE (UNIX)
-This section documents how files are captured from a directory on UNIX.  See
-\fBWINDOWS VERSION\fR for the corresponding documentation for the Windows
-version.
-.PP
-On UNIX, the "normal" image capture mode is entered when \fISOURCE\fR specifies
-a directory.  The WIM image will be captured from the directory tree rooted at
-this directory.  The directory may be on any type of filesystem.
+.SH DIRECTORY CAPTURE (UNIX)
+This section documents how \fB@IMAGEX_PROGNAME@\fR captures files from a
+directory tree on UNIX-like systems.  See \fBDIRECTORY CAPTURE (WINDOWS)\fR for
+the corresponding documentation for Windows.
 .PP
-In this mode, the following information is captured from the directory tree:
+On UNIX-like systems, when \fISOURCE\fR specifies a directory or a symbolic link
+to a directory, the WIM image will be captured from the directory tree rooted at
+this directory.  This directory can be on any type of filesystem, and mount
+points are followed recursively.  However, it is important to keep in mind that
+the WIM format was designed for Windows, so it cannot store all possible
+metadata from filesystems used on UNIX-like systems.  The main information that
+will \fInot\fR be stored is:
 .IP \[bu] 4
-The "normal" name and contents of each file and directory
-.IP \[bu]
-File and directory creation, access, and modification timestamps to the nearest
-100 nanoseconds, if supported by the underlying filesystem
+UNIX file owners, groups, and modes.  (Exception: see the \fB--unix-data\fR
+option.)  As a result, file permissions will not be stored, and files that are
+neither regular files, directories, nor symbolic links, such as device files and
+FIFOs, cannot be captured.
 .IP \[bu]
-Hard links and symbolic links
+Extended attributes.  This mainly includes extensions to the traditional UNIX
+security model, such as SELinux security labels, POSIX ACLs, and capabilities
+labels.
 .PP
-However, in this mode, the following information is \fInot\fR captured from the
-directory tree:
-.IP \[bu] 4
-UNIX file owners, groups, and modes.  The resulting WIM image will contain no
-security information (file permissions).  (Exception: see the \fB--unix-data\fR
-option.)
-.IP \[bu]
-Extended attributes.
-.SH NTFS MODE (UNIX)
-This section documents how files are captured from an NTFS volume image on UNIX.
-See \fBWINDOWS VERSION\fR for the corresponding documentation for the Windows
-version.
+Notes: hard links and symbolic links are supported by the WIM format and
+\fIare\fR stored.  (Symbolic links are turned into "native" Windows symbolic
+links via reparse points; this process is reversible, e.g. automatically by
+\fB@IMAGEX_PROGNAME@ apply\fR.)  Timestamps are stored with 100 nanosecond
+granularity and include last modification time (mtime) and last access time
+(atime), but not last status change time (ctime).
+.SH NTFS VOLUME CAPTURE (UNIX)
+This section documents how \fB@IMAGEX_PROGNAME@\fR captures files from an NTFS
+volume image on UNIX-like systems.  See \fBDIRECTORY CAPTURE (WINDOWS)\fR for
+the corresponding documentation for Windows.
 .PP
-On UNIX, a special image capture mode is entered when \fISOURCE\fR is a regular
-file or block device.  \fISOURCE\fR is interpreted as an NTFS volume and opened
-using libntfs-3g.  If successful, a WIM image is captured containing the
-contents of the NTFS volume, including NTFS-specific data.
+On UNIX-like systems, a special image capture mode is entered when \fISOURCE\fR
+is a regular file or block device.  In this mode, \fISOURCE\fR is assumed to be
+a NTFS volume or volume image, and wimlib will capture a WIM image containing a
+full contents of the NTFS volume, including NTFS-specific data.  This is done
+using libntfs-3g.
 .PP
-Please note that the NTFS image capture mode is \fInot\fR entered if
+Please note that the NTFS volume capture mode is \fInot\fR entered if
 \fISOURCE\fR is a directory, even if an NTFS filesystem is mounted on
-\fISOURCE\fR.  You must specify the NTFS volume itself (and it must be
-unmounted, and you must have permission to read from it).
+\fISOURCE\fR using ntfs-3g.  You must specify the NTFS volume itself (and it
+must be unmounted, and you must have permission to read from it).
 .PP
-More specifically, in this mode, the following types of information are captured
-from the NTFS volume:
+The NTFS volume capture mode attempts to capture as much data as
+possible, including:
 .IP \[bu] 4
-All data streams of all files, including the un-named data stream as well as all
+All data streams of all files, including the unnamed data stream as well as all
 named data streams.
 .IP \[bu]
 Reparse points, including symbolic links, junction points, and other reparse
 points.
 .IP \[bu]
-File and directory creation, access, and modification timestamps from NTFS
-inodes (these have a resolution of 100 nanoseconds).
+File and directory creation, access, and modification timestamps, using the
+native NTFS resolution of 100 nanoseconds.
 .IP \[bu]
-The security descriptor for each NTFS inode.
+Windows security descriptors, including all components (owner, group, DACL, and
+SACL).
 .IP \[bu]
-File attribute flags.
+DOS/Windows file attribute flags.
 .IP \[bu]
 All names of all files, including names in the Win32 namespace, DOS namespace,
 Win32+DOS namespace, and POSIX namespace.  This includes hard links.
-.SH WINDOWS VERSION
-The Windows versions of \fB@IMAGEX_PROGNAME@ capture\fR and \fB@IMAGEX_PROGNAME@
-append\fR act similarly to the corresponding commands of Microsoft's ImageX.
-For best results, the directory being captured should be on an NTFS volume and
-you should be running with Administrator privileges; however, non-NTFS
-filesystems and running without Administrator privileges are also supported.
+.SH DIRECTORY CAPTURE (WINDOWS)
+On Windows, \fB@IMAGEX_PROGNAME@ capture\fR and \fB@IMAGEX_PROGNAME@ append\fR
+natively support Windows-specific and NTFS-specific data.  They therefore act
+similarly to the corresponding commands of Microsoft's ImageX.  For best
+results, the directory being captured should be on an NTFS volume and you should
+be running with Administrator privileges; however, non-NTFS filesystems and
+running without Administrator privileges are also supported.
 .PP
 On Windows, \fB@IMAGEX_PROGNAME@ capture\fR and \fB@IMAGEX_PROGNAME@ append\fR
-try to archive as much data as possible.  This includes:
+try to archive as much data as possible, including:
 .IP \[bu] 4
-All data streams of all files.  This includes the default file contents, as well
-as named data streams if supported by the filesystem and if the version of
-Windows is Vista or later.
+All data streams of all files, unless running on a version of Windows prior to
+Vista, in which case named data streams (if supported by the source filesystem)
+will not be captured.
 .IP \[bu]
 Reparse points, including symbolic links, junction points, and other reparse
-points, if supported by the underlying filesystem.  (Note: see
-\fB--rpfix\fR and \fB--norpfix\fR for documentation on how absolute symbolic
-links and junctions are captured.)
+points, if supported by the source filesystem.  (Note: see \fB--rpfix\fR and
+\fB--norpfix\fR for documentation on exactly how absolute symbolic links and
+junctions are captured.)
 .IP \[bu]
-File and directory creation, access, and modification timestamps to the nearest
-100 nanoseconds.
+File and directory creation, access, and modification timestamps.  These are
+stored with Windows NT's native timestamp resolution of 100 nanoseconds.
 .IP \[bu]
-Security descriptors, if supported by the filesystem and \fB--no-acls\fR is not
-specified.  Furthermore, unless \fB--strict-acls\fR is specified, the security
-descriptor for individual files or directories may be omitted or only partially
-captured if the user does not have permission to read them.
+Security descriptors, if supported by the source filesystem and \fB--no-acls\fR
+is not specified.  However, beware that unless \fB--strict-acls\fR is specified,
+the security descriptor for individual files or directories may be omitted or
+only partially captured if the user does not have permission to read it, which
+is mainly a problem if \fB@IMAGEX_PROGNAME@\fR is run as a non-Administrator.
 .IP \[bu]
 File attributes, including hidden, sparse, compressed, encrypted, etc.
 Encrypted files will be stored in encrypted form rather than in plain text.
+Transparently compressed files will be read as uncompressed and stored subject
+to the WIM's own compression.  There is no special handling for storing sparse
+files, but they are likely to compress to a small size.
 .IP \[bu]
 DOS names (8.3) names of files; however, the failure to read them is not
 considered an error condition.
 .IP \[bu]
-Hard links, excluding directory hard links (which aren't supposed to exist
-anyway).
+Hard links, if supported by the source filesystem.
+.PP
+Note: the capture process is reversible, since when \fB@IMAGEX_PROGNAME@
+apply\fR (on Windows) extracts the captured WIM image, it will extract all of
+the above information, at least to the extent supported by the destination
+filesystem.  One exception is that since encrypted files are stored as
+unencrypted, their data will not be available if restored on a Windows system
+that does not have the decryption key.
 .SH OPTIONS
 .TP 6
 \fB--boot\fR
 Specifies that the new image is to be made the bootable image of the WIM archive.
 .TP
 \fB--check\fR
-For \fB@IMAGEX_PROGNAME@ append\fR, check the integrity of \fIWIMFILE\fR if an
-integrity was present.  Furthermore, include an integrity table in the new WIM
-file (\fB@IMAGEX_PROGNAME@ capture\fR) or the modified WIM file
-(\fB@IMAGEX_PROGNAME@ append\fR).  If this option is not specified, no integrity
-table is included in a WIM file created with \fB@IMAGEX_PROGNAME@ capture\fR,
-while a WIM file updated with \fB@IMAGEX_PROGNAME@ append\fR will be written
-with an integrity table if and only if one was present before.
+For \fB@IMAGEX_PROGNAME@ append\fR, before performing the append operation,
+check the integrity of \fIWIMFILE\fR if an integrity table is present.
+Furthermore, include an integrity table in the new WIM file
+(\fB@IMAGEX_PROGNAME@ capture\fR) or the modified WIM file (\fB@IMAGEX_PROGNAME@
+append\fR).  If this option is not specified, no integrity table is included in
+a WIM file created with \fB@IMAGEX_PROGNAME@ capture\fR, while a WIM file
+updated with \fB@IMAGEX_PROGNAME@ append\fR will be written with an integrity
+table if and only if one was present before.
 .TP
 \fB--compress\fR=\fITYPE\fR
 Specifies the compression type for the new WIM file.  This flag is only valid
 for \fB@IMAGEX_PROGNAME@ capture\fR, since the compression mode for
-\fB@IMAGEX_PROGNAME@ append\fR must be the same as that of the existing WIM.
-\fITYPE\fR may be "none", "maximum", or "fast".  By default, it is "fast".
+\fB@IMAGEX_PROGNAME@ append\fR must be the same as that of the existing WIM (and
+is automatically set as such).
+\fITYPE\fR may be "none", "fast", or "maximum".  By default, it is "maximum".
+This default behavior is different from Microsoft's ImageX, where the default is
+"fast". \fB@IMAGEX_PROGNAME@ capture\fR instead gives you the best compression
+ratio by default and makes up for the slightly slower compression by being
+faster than Microsoft's software in the first place and using multiple CPUs when
+available.
 .IP ""
 You may also specify the actual names of the compression algorithms, "XPRESS"
 and "LZX", instead of "fast" and "maximum", respectively.
 .TP
 \fB--threads\fR=\fINUM_THREADS\fR
 Number of threads to use for compressing data.  Default: autodetect (number of
-processors).  Note: if creating or appending to an uncompressed WIM, additional
-threads will not be used, regardless of this parameter, since no compression
-needs to be done in this case.
+available CPUs).
 .TP
 \fB--rebuild\fR
 For \fB@IMAGEX_PROGNAME@ append\fR: rebuild the entire WIM rather than appending the new
 data to the end of it.  Rebuilding the WIM is slower, but will save a little bit
 of space that would otherwise be left as a hole in the WIM.  Also see \fB@IMAGEX_PROGNAME@
-optimize\fR.
+optimize\fR(1).
 .TP
 \fB--flags\fR=\fIEDITIONID\fR
 Specify a string to use in the <FLAGS> element of the XML data for the new
@@ -172,8 +201,8 @@ image.
 Print the names of files and directories as they are captured.
 .TP
 \fB--dereference\fR
-(UNIX only) Follow symbolic links and archive the files they point to, rather
-than archiving the links themselves.
+(UNIX-like systems only) Follow symbolic links and archive the files they point
+to, rather than archiving the links themselves.
 .TP
 \fB--config\fR=\fIFILE\fR
 Specifies a configuration file for capturing the new image.  The configuration
@@ -188,14 +217,14 @@ exclude from capture, while the [ExclusionException] section specifies a list of
 path globs to include in the capture even if the matched file or directory name
 also appears in the [ExclusionList].
 .IP ""
-Relative globs with only one path component (e.g. *.mp3) match against a filename in any
-directory.  Relative globs with multiple path components (e.g. dir/file),
-as well as absolute globs (e.g. /dir/file), are treated as paths starting at the
-root directory of capture, or the root of the NTFS volume for NTFS capture mode.
-If a directory is matched by a glob in the [ExclusionList], the entire directory
-tree rooted at that directory is excluded from the capture, unless
-\fB--dereference\fR is specified and there is another path into that directory
-through a symbolic link.
+Relative globs with only one path component (e.g. *.mp3) match against a
+filename in any directory.  Relative globs with multiple path components (e.g.
+dir/file), as well as absolute globs (e.g. /dir/file), are treated as paths
+starting at the root directory of capture, or the root of the NTFS volume for
+NTFS volume capture mode.  If a directory is matched by a glob in the
+[ExclusionList], the entire directory tree rooted at that directory is excluded
+from the capture, unless \fB--dereference\fR is specified and there is another
+path into that directory through a symbolic link.
 .IP ""
 For compatibility with Windows, the path separators in the globs may be either
 forward slashes or backslashes, and the line separators may be either UNIX-style
@@ -224,26 +253,25 @@ used:
 .fi
 .TP
 \fB--unix-data\fR
-(UNIX only) Store the UNIX owner, group, and mode of all captured files.  This
-is done by adding a special alternate data stream to each directory entry that
-contains this information.  Please note that this flag is for convenience only,
-in case you want to use \fB@IMAGEX_PROGNAME@\fR to archive files on UNIX.
-Microsoft's software will not understand this special information.  You also may
-run into problems when applying an image with UNIX data from a pipable WIM.
+(UNIX-like systems only) Store the UNIX owner, group, and mode of all captured
+files.  This is done by adding a special alternate data stream to each directory
+entry that contains this information.  Please note that this flag is for
+convenience only, in case you want to use \fB@IMAGEX_PROGNAME@\fR to archive
+files on UNIX.  Microsoft's software will not understand this special
+information.  You also may run into problems when applying an image with UNIX
+data from a pipable WIM.
 .TP
 \fB--no-acls\fR
-Do not capture files' security descriptors.  This option is available in the
-Windows version, as well as on UNIX in NTFS capture mode.
+Do not capture files' security descriptors.
 .TP
 \fB--strict-acls\fR
-(Windows only) Fail immediately if the full security descriptor of any file
-cannot be read.  The default behavior without this option is to first try
-omitting the SACL from the security descriptor, then to try omitting the
-security descriptor entirely.  The purpose of this is to capture as much data as
-possible without always requiring Administrator privileges.  However, if you
-desire that all security descriptors be captured exactly, you may wish to
-provide this option, although the Administrator should have permission to read
-everything anyway.
+Fail immediately if the full security descriptor of any file cannot be read.  On
+Windows, the default behavior without this option is to first try omitting the
+SACL from the security descriptor, then to try omitting the security descriptor
+entirely.  The purpose of this is to capture as much data as possible without
+always requiring Administrator privileges.  However, if you desire that all
+security descriptors be captured exactly, you may wish to provide this option,
+although the Administrator should have permission to read everything anyway.
 .TP
 \fB--rpfix\fR, \fB--norpfix\fR
 Set whether to fix targets of absolute symbolic links (reparse points in Windows
@@ -267,20 +295,22 @@ behavior from the previous paragraph.
 .TP
 \fB--source-list\fR
 \fB@IMAGEX_PROGNAME@ capture\fR and \fB@IMAGEX_PROGNAME@ append\fR support
-creating a WIM image from multiple files or directories.  When
+creating a WIM image from multiple separate files or directories.  When
 \fB--source-list\fR is specified, the \fISOURCE\fR argument specifies the name
 of a text file, each line of which is either 1 or 2 whitespace separated file
 paths.  The first file path, the source, specifies the path to a file or
 directory to capture into the WIM image.  It may be either absolute or relative
 to the current working directory.  The second file path, if provided, is the
 target and specifies the path  in the WIM image that this file or directory will
-be saved as.  Leading and trailing slashes are ignored.  "/" indicates that the
-directory is to become the root of the WIM image.  If not specified, the target
-string defaults to the same as the source string.
+be saved as.  Leading and trailing slashes in the target are ignored, except if
+it consists entirely of slashes (e.g. "/"), which indicates that the directory
+is to become the root of the WIM image.  If omitted, the target string defaults
+to the same as the source string.
 .IP ""
 An example source list file is as follows:
 .IP ""
 .RS
+.RS
 .nf
 # Make the WIM image from the 'winpe' directory
 winpe  /
@@ -292,6 +322,7 @@ overlay     /overlay
 # This is only legal if there are no conflicting files.
 /data/stuff    /
 .RE
+.RE
 .fi
 .IP ""
 Subdirectories in the WIM are created as needed.  Multiple source directories
@@ -307,8 +338,8 @@ optional whitespace are ignored.
 As a special case, if \fISOURCE\fR is "-", the source list is read from standard
 input rather than an external file.
 .IP ""
-The NTFS capture mode cannot be used with \fB--source-list\fR, as only capturing
-a full NTFS volume is supported.
+The NTFS volume capture mode on UNIX-like systems cannot be used with
+\fB--source-list\fR, as only capturing a full NTFS volume is supported.
 .TP
 \fB--pipable\fR
 Create a "pipable" WIM, which can be applied fully sequentially, including from
@@ -324,7 +355,7 @@ efficient piping it will be, since more unneeded data will be sent through the
 pipe.
 .IP ""
 When wimlib creates a pipable WIM, it carefully re-arranges the components of
-the WIM so that they can be read sequentially, and also makes several other
+the WIM so that they can be read sequentially and also makes several other
 modifications.  As a result, these "pipable" WIMs are \fInot compatible with
 Microsoft's software\fR, so keep this in mind if you're going to use them.  If
 desired, you can use \fB@IMAGEX_PROGNAME@ optimize --not-pipable\fR to re-write
@@ -334,8 +365,9 @@ vice versa.)
 .IP ""
 For the most part, wimlib operates on pipable WIMs transparently.  You can
 modify them, add or delete images, export images, and even create split pipable
-WIMs.  The main disadvantages are that appending is (currently) less efficient,
-and also they aren't compatible with Microsoft's software.
+WIMs.  The main disadvantages are that appending is (currently) less efficient
+(\fB--rebuild\fR is always implied), and also they aren't compatible with
+Microsoft's software.
 .IP ""
 \fB@IMAGEX_PROGNAME@ capture\fR and \fB@IMAGEX_PROGNAME@ append\fR can both
 write a pipable WIM directly to standard output; this is done automatically if
@@ -344,63 +376,111 @@ write a pipable WIM directly to standard output; this is done automatically if
 \fB--not-pipable\fR
 Ensure the resulting WIM is in the normal, non-pipable WIM format.  This is the
 default for \fB@IMAGEX_PROGNAME@ capture\fR, except when writing to standard
-output, and for \fB@IMAGEX_PROGNAME@ append\fR, except when appending to a WIM
-that is already pipable.
+output (\fIWIMFILE\fR specified as "-"), and also for \fB@IMAGEX_PROGNAME@
+append\fR, except when appending to a WIM that is already pipable.
 .SH NOTES
 \fB@IMAGEX_PROGNAME@ append\fR does not support appending an image to a split WIM.
 .PP
-The different capture modes only specify the data that is captured and don't
-specify a special WIM format.  A WIM file can contain images captured using
-different modes.  However, all images in a WIM must have the same compression
-type, and \fB@IMAGEX_PROGNAME@\fR always enforces this.
-.PP
-\fB@IMAGEX_PROGNAME@\fR writes WIMs having the version number 0x10d00 and a
-compressed stream chunk size of 32768.  The only WIMs I've seen that are
-different from this are some pre-Vista WIMs that had a different version number.
-.PP
 It is safe to abort an \fB@IMAGEX_PROGNAME@ append\fR command partway through;
 however, after doing this, it is recommended to run \fB@IMAGEX_PROGNAME@
 optimize\fR to remove any data that was appended to the physical WIM file but
-not yet incorporated into the structure of the WIM, unless \fB--rebuild\fR was
-specified, in which case you should delete the temporary file left over.
-.PP
-\fISOURCE\fR may be a symbolic link to a directory rather than a directory
-itself.  However, additional symbolic links in subdirectories, or in additional
-source directories not destined for the WIM image root (with
-\fB--source-list\fR), are not dereferenced unless \fB--dereference\fR is
-specified.
+not yet incorporated into the structure of the WIM, unless the WIM was being
+fully rebuilt (e.g. with \fB--rebuild\fR), in which case you should delete the
+temporary file left over.
 .PP
-With the UNIX version of \fB@IMAGEX_PROGNAME@\fR, it is possible to create a WIM
-image containing files with names differing only in case, or files with names
-containing the characters ':', '*', '?', '"', '<', '>', '|', or '\\', which are
-valid on POSIX-compliant filesystems but not Windows.  Be warned that such files
-will not be extracted by default by the Windows version of
-\fB@IMAGEX_PROGNAME@\fR, and Microsoft's ImageX might get confused by such
-names.
+\fB@IMAGEX_PROGNAME@\fR creates WIMs compatible with Microsoft's software
+(imagex.exe, Dism.exe, wimgapi.dll), with some caveats:
+.IP \[bu] 4
+With \fB@IMAGEX_PROGNAME@\fR on UNIX-like systems, it is possible to create a
+WIM image containing files with names differing only in case, or files with
+names containing the characters ':', '*', '?', '"', '<', '>', '|', or '\\',
+which are valid on POSIX-compliant filesystems but not Windows.  Be warned that
+such files will not be extracted by default by the Windows version of
+\fB@IMAGEX_PROGNAME@\fR, and (even worse) Microsoft's ImageX can be confused by
+such names and quit extracting the image partway through.  (It perhaps is worth
+pointing out that Windows' own default filesystem, NTFS, supports these
+characters, although Windows does not!)
+.IP \[bu]
+WIMs captured with \fB--unix-data\fR should be assumed to be incompatible with
+Microsoft's software.
+.IP \[bu]
+Pipable WIMs are incompatible with Microsoft's software.  Pipable WIMs are
+created only if \fIWIMFILE\fR was specified as "-" (standard output) or if
+the \fB--pipable\fR flag was specified.
 .SH EXAMPLES
-Create a new WIM 'mywim.wim' from the directory 'somedir', using LZX compression and
-including an integrity table:
+First example:  Create a new WIM 'mywim.wim' with "maximum" (LZX) compression
+that will contain a captured image of the directory tree 'somedir'.  Note that
+\fB@IMAGEX_PROGNAME@\fR uses "maximum" (LZX) compression by default, so
+\fB--compress\fR does \fInot\fR need to be specified; furthermore, the image
+name need not be specified and will default to 'somedir':
 .RS
 .PP
-@IMAGEX_PROGNAME@ capture somedir mywim.wim --compress=maximum --check
+@IMAGEX_PROGNAME@ capture somedir mywim.wim
 .RE
 .PP
-Append an image to the WIM we just captured, but do it from an NTFS volume on the
-partition /dev/sda2 and name the image "Windows 7".  You do not need to specify
-the compression type, because the WIM already is using LZX compression and this
-cannot be changed.  You need to specify \fB--check\fR if you don't want the
-integrity table to be discarded.
+or, if the \fBwimcapture\fR hard link or batch file is installed, the
+abbreviated form can be used:
 .RS
 .PP
-@IMAGEX_PROGNAME@ append /dev/sda2 mywim.wim --check "Windows 7"
+wimcapture somedir mywim.wim
 .RE
 .PP
-Capture a WIM from a NTFS volume and write it directly to standard output, using
-the wimlib-specific pipable WIM format:
+The remaining examples will use the long form, however.  Next, append the image
+of a different directory tree to the WIM created above:
 .RS
 .PP
-@IMAGEX_PROGNAME@ capture /dev/sda1 -
+@IMAGEX_PROGNAME@ append anotherdir mywim.wim
 .RE
 .PP
+Easy enough, and the above examples of imaging directory trees work on both
+UNIX-like systems and Windows.  Next, capture a WIM with several non-default
+options, including "fast" (XPRESS) compression, an integrity table, no messing
+with absolute symbolic links, and an image name and description:
+.RS
+.PP
+@IMAGEX_PROGNAME@ capture somedir mywim.wim --compress=fast \\
+.RS
+--check --norpfix "Some Name" "Some Description"
+.RE
+.RE
+.PP
+Capture an entire NTFS volume into a new WIM file and name the image "Windows
+7".  On UNIX-like systems, this requires using the special mode described in
+\fBNTFS VOLUME CAPTURE (UNIX)\fR where \fISOURCE\fR is a file or block device
+containing a NTFS filesystem:
+.RS
+.PP
+@IMAGEX_PROGNAME@ capture /dev/sda2 windows7.wim "Windows 7"
+.RE
+.PP
+or, on Windows, to capture a full NTFS volume you instead need to specify the
+root directory of the mounted volume, for example:
+.RS
+.PP
+@IMAGEX_PROGNAME@ capture E:\\ windows7.wim "Windows 7"
+.RE
+.PP
+Same as above example with capturing a NTFS volume from \fB@IMAGEX_PROGNAME@\fR
+running on a UNIX-like system, but capture the WIM in the wimlib-specific
+"pipable" format that can be piped to \fB@IMAGEX_PROGNAME@ apply\fR:
+.RS
+.PP
+@IMAGEX_PROGNAME@ capture /dev/sda2 windows7.wim "Windows 7" \\
+.br
+.RS
+--pipable
+.RE
+.RE
+.PP
+Same as above, but instead of writing the pipable WIM to the file
+"windows7.wim", write it directly to standard output through a pipe into some
+other program "someprog", which could, for example, be a program or script that
+streams the data to a server.  Note that \fB--pipable\fR need not be explicitly
+specified when using standard output as the WIM "file":
+.RS
+.PP
+@IMAGEX_PROGNAME@ capture /dev/sda2 - "Windows 7" | someprog
+.RE
 .SH SEE ALSO
-.BR @IMAGEX_PROGNAME@ (1)
+.BR @IMAGEX_PROGNAME@ (1),
+.BR @IMAGEX_PROGNAME@-apply (1)
index b6158c4ba65a3427606b537862299f27f866e25b..34277a1ba3b500d1e1034d4bfd21b07349880f99 100644 (file)
@@ -11,6 +11,8 @@ file \fIWIMFILE\fR.
 image in the WIM, the name of an image in the WIM, or the keyword "all" to
 indicate that all images are to be deleted.  Use the \fB@IMAGEX_PROGNAME@ info\fR (1)
 command to show what images a WIM file contains.
+This command is also available as simply \fBwimdelete\fR if the appropriate hard
+link is installed.
 .SH NOTES
 By default, the WIM file is rebuilt with all unnecessary file data removed.
 This is different from Microsoft's imagex.exe, which only will delete the
index a000340a8950b6ae4ee99d679adb64abaa961d9d..bba3a9aa554341589e2e0026dd7f3074168b73cc 100644 (file)
@@ -6,6 +6,8 @@
 .SH DESCRIPTION
 Lists all the files and directories contained in the specified image of the
 Windows Imaging (WIM) file \fIWIMFILE\fR.
+This command is also available as simply \fBwiminfo\fR if the appropriate hard
+link is installed.
 .PP
 \fIIMAGE\fR specifies the WIM image to show the files of.  It may be a 1-based
 index of an image in the WIM, the name of an image in the WIM, or the keyword
index daca7ea19cf1926e20cac2335065fb536402ea0e..10e0e152127efe63af9aa32bbe7584159121a8a2 100644 (file)
@@ -11,6 +11,8 @@ optionally changing its name and/or description and/or compression type.
 If \fIDEST_WIMFILE\fR exists, it is taken be be a WIM archive to which the image
 will be appended.  Otherwise, it is created as a new WIM archive containing only
 the exported image.
+This command is also available as simply \fBwimexport\fR if the appropriate hard
+link is installed.
 .PP
 \fISRC_IMAGE\fR specifies the image in \fISRC_WIMFILE\fR to export.  It may be a
 1-based index of an image in the WIM, the name of an image in the WIM, or the
index dee6eb250e3fd8b2984d359a0e481c31a9973d75..1cf1c516121fe4a15e0f94c5a2c7493a5137acc3 100644 (file)
@@ -7,6 +7,8 @@
 \fB@IMAGEX_PROGNAME@ extract\fR extracts one or more files or directory trees
 from the specified \fIIMAGE\fR contained in the Windows Imaging (WIM) file
 \fIWIMFILE\fR.
+This command is also available as simply \fBwimextract\fR if the appropriate hard
+link is installed.
 .PP
 \fB@IMAGEX_PROGNAME@ extract\fR is intended for extracting only a subset of a
 WIM image.  If you want to extract or "apply" a full WIM image to a directory or
index b3b4a5b7142f44d57332b341867434674918846d..d5c274fe30d6899f1ff954923874ca183b372141 100644 (file)
@@ -9,6 +9,8 @@ an image
 \fB@IMAGEX_PROGNAME@ info\fR displays information about \fIWIMFILE\fR, and optionally
 changes which image is bootable, or what the name and description of an image
 are.
+This command is also available as simply \fBwiminfo\fR if the appropriate hard
+link is installed.
 .PP
 If neither an image nor any flags other than \fB--check\fR are specified, some
 basic information about the WIM archive as well as information about the images
index f2d2c3626ab69488f05462c7d1b60758b209bb60..c3112fdb319c50e4780448012a394ea859006f4a 100644 (file)
@@ -5,6 +5,8 @@
 \fB@IMAGEX_PROGNAME@ join\fR [\fIOPTION\fR...] \fIOUT_WIMFILE\fR \fISPLIT_WIM\fR...
 .SH DESCRIPTION
 Joins the \fISPLIT_WIMs\fR into a standalone one-part WIM \fIOUT_WIMFILE\fR.
+This command is also available as simply \fBwimjoin\fR if the appropriate hard
+link is installed.
 .PP
 All parts of the split WIM  must be specified.  You probably want to do so using
 a shell wildcard.
index 6c040f7a80eb12addf7d334167c7adce3484dfc2..0553055bfe8c850a99936ddf71535eb5ee43ecfa 100644 (file)
@@ -13,6 +13,8 @@ will mount the image in the Windows Imaging (WIM) file \fIWIMFILE\fR specified
 by \fIIMAGE\fR on the directory \fIDIRECTORY\fR using FUSE (Filesystem in
 Userspace).  \fB@IMAGEX_PROGNAME@ mount\fR will mount the image read-only, while
 \fB@IMAGEX_PROGNAME@ mountrw\fR will mount the image read-write.
+These commands are also available as simply \fBwimmount\fR, \fBwimmountrw\fR,
+and \fBwimunmount\fR if the appropriate hard links are installed.
 .PP
 \fIIMAGE\fR may be a 1-based index of the image in the WIM to mount, or it may
 be the name of an image in the WIM.  Use the \fB@IMAGEX_PROGNAME@ info\fR (1)
index aa3b947d92c06c8564da3be8a2e555ef973657ea..b4ec85fb9f2e7cc6501120822e5f8a7adc6ca406 100644 (file)
@@ -10,6 +10,8 @@ it's ready.  This action will remove any holes that have been left as a result
 of appending images, so the new WIM may be slightly smaller than the old WIM.
 In addition, some errors in the original WIM may be fixed by re-writing it
 (although most cannot).
+This command is also available as simply \fBwimoptimize\fR if the appropriate
+hard link is installed.
 .SH OPTIONS
 .TP 6
 \fB--check\fR
index 5c21576d2bf18f6f3f057229b51ce0f4a6bb846c..7dd52d49388bad445526727b6d1ea2669825f3bf 100644 (file)
@@ -7,6 +7,8 @@
 Splits \fIWIMFILE\fR into parts with size at most \fIPART_SIZE\fR mebibytes,
 with the first part having the name \fISPLIT_WIM_PART\fR and the other parts
 having names numbered in order of the parts.
+This command is also available as simply \fBwimsplit\fR if the appropriate
+hard link is installed.
 .PP
 \fB@IMAGEX_PROGNAME@ split\fR can split both non-pipable and pipable WIMs.
 .SH OPTIONS
index fe2ef9b2b1023d5bb7b8406ab4749fe499026998..a426ffc2882133c28a878cf19ec998ce6a32c837 100644 (file)
@@ -7,6 +7,8 @@
 \fB@IMAGEX_PROGNAME@ update\fR modifies the specified \fIIMAGE\fR in the Windows
 Imaging (WIM) file \fIWIMFILE\fR by adding, deleting, or renaming files or
 directories in it.
+This command is also available as simply \fBwimupdate\fR if the appropriate
+hard link is installed.
 .PP
 \fIIMAGE\fR specifies the image in \fIWIMFILE\fR to update.  It may be a 1-based
 index of an image in the WIM or the name of an image in the WIM.  Use the
index b913c45e52cbb31fd7667eba892f0567d53a2f61..ffdbe79623204f30eb66338a96b9a6454ad9ab80 100644 (file)
@@ -40,7 +40,11 @@ To do its work, \fB@IMAGEX_PROGNAME@\fR uses \fBwimlib\fR, a library which
 provides interfaces for manipulating WIM archives.  You could wimlib in your own
 programs if you wanted to.  wimlib's public interface is documented.
 .SH COMMANDS
-There is a separate manual page for each \fB@IMAGEX_PROGNAME@\fR command.
+The available commands were listed above, and there is a separate manual page
+for each.  Note: to save typing, if the appropriate hard links are installed, a
+command \fB@IMAGEX_PROGNAME@ \fICOMMAND\fR can be accessed as simply
+\fBwim\fICOMMAND\fR; for example, \fBwimapply\fR for
+\fB@IMAGEX_PROGNAME@ apply\fR.
 .SH SUPPORTED FEATURES
 The following general features are currently supported (note: this is not a
 complete list; also, certain features, such as mounting, are supported on UNIX
index 3ec85fc58007002ba70abb32a7f79a96a28fd912..fefaabc491158d345191aba11bfc68905c8b8fe2 100644 (file)
@@ -30,6 +30,7 @@ typedef wchar_t tchar;
 #  define istalpha     iswalpha
 #  define istspace     iswspace
 #  define tstrcmp      wcscmp
+#  define tstrncmp     wcsncmp
 #  define tstrchr      wcschr
 #  define tstrpbrk     wcspbrk
 #  define tstrrchr     wcsrchr
@@ -89,6 +90,7 @@ typedef char tchar;
 #  define istalpha     isalpha
 #  define istspace     isspace
 #  define tstrcmp      strcmp
+#  define tstrncmp     strncmp
 #  define tstrchr      strchr
 #  define tstrpbrk     strpbrk
 #  define tstrrchr     strrchr
index f66bcd5bf5d1021c0c2613a1277d680f62d5c41b..7433347b69c30257592057aae24fb2e29ec90fe2 100644 (file)
@@ -71,26 +71,30 @@ static inline void set_fd_to_binary_mode(int fd)
 #define for_opt(c, opts) while ((c = getopt_long_only(argc, (tchar**)argv, T(""), \
                                opts, NULL)) != -1)
 
-enum imagex_op_type {
-       APPEND = 0,
-       APPLY,
-       CAPTURE,
-       DELETE,
-       DIR,
-       EXPORT,
-       EXTRACT,
-       INFO,
-       JOIN,
-       MOUNT,
-       MOUNTRW,
-       OPTIMIZE,
-       SPLIT,
-       UNMOUNT,
-       UPDATE,
+enum {
+       CMD_NONE = -1,
+       CMD_APPEND = 0,
+       CMD_APPLY,
+       CMD_CAPTURE,
+       CMD_DELETE,
+       CMD_DIR,
+       CMD_EXPORT,
+       CMD_EXTRACT,
+       CMD_INFO,
+       CMD_JOIN,
+       CMD_MOUNT,
+       CMD_MOUNTRW,
+       CMD_OPTIMIZE,
+       CMD_SPLIT,
+       CMD_UNMOUNT,
+       CMD_UPDATE,
+       CMD_MAX,
 };
 
-static void usage(int cmd_type);
-static void usage_all(void);
+static void usage(int cmd, FILE *fp);
+static void usage_all(FILE *fp);
+static void recommend_man_page(int cmd, FILE *fp);
+static const tchar *get_cmd_string(int cmd, bool nospace);
 
 static bool imagex_be_quiet = false;
 static FILE *imagex_info_file;
@@ -98,119 +102,6 @@ static FILE *imagex_info_file;
 #define imagex_printf(format, ...) \
                tfprintf(imagex_info_file, format, ##__VA_ARGS__)
 
-
-static const tchar *usage_strings[] = {
-[APPEND] =
-T(
-IMAGEX_PROGNAME" append (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n"
-"                    [DESCRIPTION] [--boot] [--check] [--nocheck]\n"
-"                    [--flags EDITION_ID] [--verbose] [--dereference]\n"
-"                    [--config=FILE] [--threads=NUM_THREADS] [--rebuild]\n"
-"                    [--unix-data] [--source-list] [--no-acls]\n"
-"                    [--strict-acls] [--rpfix] [--norpfix] [--pipable]\n"
-"                    [--not-pipable]\n"
-),
-[APPLY] =
-T(
-IMAGEX_PROGNAME" apply WIMFILE [IMAGE_NUM | IMAGE_NAME | all]\n"
-"                    (DIRECTORY | NTFS_VOLUME) [--check] [--hardlink]\n"
-"                    [--symlink] [--verbose] [--ref=\"GLOB\"] [--unix-data]\n"
-"                    [--no-acls] [--strict-acls] [--rpfix] [--norpfix]\n"
-"                    [--include-invalid-names]\n"
-),
-[CAPTURE] =
-T(
-IMAGEX_PROGNAME" capture (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n"
-"                    [DESCRIPTION] [--boot] [--check] [--nocheck]\n"
-"                    [--compress=TYPE] [--flags EDITION_ID] [--verbose]\n"
-"                    [--dereference] [--config=FILE]\n"
-"                    [--threads=NUM_THREADS] [--unix-data] [--source-list]\n"
-"                    [--no-acls] [--strict-acls] [--rpfix] [--norpfix]\n"
-"                    [--pipable] [--not-pipable]\n"
-),
-[DELETE] =
-T(
-IMAGEX_PROGNAME" delete WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check]\n"
-"                    [--soft]\n"
-),
-[DIR] =
-T(
-IMAGEX_PROGNAME" dir WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--path=PATH]\n"
-),
-[EXPORT] =
-T(
-IMAGEX_PROGNAME" export SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME | all ) \n"
-"                    DEST_WIMFILE [DEST_IMAGE_NAME] [DEST_IMAGE_DESCRIPTION]\n"
-"                    [--boot] [--check] [--nocheck] [--compress=TYPE]\n"
-"                    [--ref=\"GLOB\"] [--threads=NUM_THREADS] [--rebuild]\n"
-"                    [--pipable] [--not-pipable]\n"
-),
-[EXTRACT] =
-T(
-IMAGEX_PROGNAME" extract WIMFILE (IMAGE_NUM | IMAGE_NAME) [PATH...]\n"
-"                    [--check] [--ref=\"GLOB\"] [--verbose] [--unix-data]\n"
-"                    [--no-acls] [--strict-acls] [--to-stdout] [--dest-dir=DIR]\n"
-"                    [--include-invalid-names]\n"
-),
-[INFO] =
-T(
-IMAGEX_PROGNAME" info WIMFILE [IMAGE_NUM | IMAGE_NAME] [NEW_NAME]\n"
-"                    [NEW_DESC] [--boot] [--check] [--nocheck] [--header]\n"
-"                    [--lookup-table] [--xml] [--extract-xml FILE]\n"
-"                    [--metadata]\n"
-),
-[JOIN] =
-T(
-IMAGEX_PROGNAME" join [--check] WIMFILE SPLIT_WIM...\n"
-),
-[MOUNT] =
-T(
-IMAGEX_PROGNAME" mount WIMFILE (IMAGE_NUM | IMAGE_NAME) DIRECTORY\n"
-"                    [--check] [--debug] [--streams-interface=INTERFACE]\n"
-"                    [--ref=\"GLOB\"] [--unix-data] [--allow-other]\n"
-),
-[MOUNTRW] =
-T(
-IMAGEX_PROGNAME" mountrw WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n"
-"                    [--check] [--debug] [--streams-interface=INTERFACE]\n"
-"                    [--staging-dir=DIR] [--unix-data] [--allow-other]\n"
-),
-[OPTIMIZE] =
-T(
-IMAGEX_PROGNAME" optimize WIMFILE [--check] [--nocheck] [--recompress]\n"
-"                    [--threads=NUM_THREADS] [--pipable] [--not-pipable]\n"
-),
-[SPLIT] =
-T(
-IMAGEX_PROGNAME" split WIMFILE SPLIT_WIMFILE PART_SIZE_MB [--check]\n"
-),
-[UNMOUNT] =
-T(
-IMAGEX_PROGNAME" unmount DIRECTORY [--commit] [--check] [--rebuild] [--lazy]\n"
-),
-[UPDATE] =
-T(
-IMAGEX_PROGNAME" update WIMFILE [IMAGE_NUM | IMAGE_NAME] [--check] [--rebuild]\n"
-"                    [--threads=NUM_THREADS] [DEFAULT_ADD_OPTIONS]\n"
-"                    [DEFAULT_DELETE_OPTIONS] [--command=STRING] [< CMDFILE]\n"
-),
-};
-
-
-static void
-recommend_man_page(const tchar *cmd_name)
-{
-       const tchar *format_str;
-#ifdef __WIN32__
-       format_str = T("See "IMAGEX_PROGNAME"%"TS"%"TS".pdf in the "
-                      "doc directory for more details.\n");
-#else
-       format_str = T("Try `man "IMAGEX_PROGNAME"%"TS"%"TS"' "
-                      "for more details.\n");
-#endif
-       tprintf(format_str, *cmd_name ? T("-") : T(""), cmd_name);
-}
-
 enum {
        IMAGEX_ALLOW_OTHER_OPTION,
        IMAGEX_BOOT_OPTION,
@@ -270,6 +161,7 @@ static const struct option apply_options[] = {
        {T("include-invalid-names"), no_argument,       NULL, IMAGEX_INCLUDE_INVALID_NAMES_OPTION},
        {NULL, 0, NULL, 0},
 };
+
 static const struct option capture_or_append_options[] = {
        {T("boot"),        no_argument,       NULL, IMAGEX_BOOT_OPTION},
        {T("check"),       no_argument,       NULL, IMAGEX_CHECK_OPTION},
@@ -293,6 +185,7 @@ static const struct option capture_or_append_options[] = {
        {T("not-pipable"), no_argument,       NULL, IMAGEX_NOT_PIPABLE_OPTION},
        {NULL, 0, NULL, 0},
 };
+
 static const struct option delete_options[] = {
        {T("check"), no_argument, NULL, IMAGEX_CHECK_OPTION},
        {T("soft"),  no_argument, NULL, IMAGEX_SOFT_OPTION},
@@ -452,9 +345,9 @@ verify_image_exists(int image, const tchar *image_name, const tchar *wim_name)
                imagex_error(T("\"%"TS"\" is not a valid image in \"%"TS"\"!\n"
                             "       Please specify a 1-based image index or "
                             "image name.\n"
-                            "       You may use `"IMAGEX_PROGNAME" info' to list the images "
+                            "       You may use `%"TS"' to list the images "
                             "contained in a WIM."),
-                            image_name, wim_name);
+                            image_name, wim_name, get_cmd_string(CMD_INFO, false));
                return -1;
        }
        return 0;
@@ -1250,7 +1143,7 @@ imagex_progress_func(enum wimlib_progress_msg msg,
        default:
                break;
        }
-       fflush(stdout);
+       fflush(imagex_info_file);
        return 0;
 }
 
@@ -1542,7 +1435,7 @@ parse_update_command_file(tchar **cmd_file_contents_p, size_t cmd_file_nchars,
 /* Apply one image, or all images, from a WIM file into a directory, OR apply
  * one image from a WIM file to a NTFS volume.  */
 static int
-imagex_apply(int argc, tchar **argv)
+imagex_apply(int argc, tchar **argv, int cmd)
 {
        int c;
        int open_flags = WIMLIB_OPEN_FLAG_SPLIT_OK;
@@ -1710,7 +1603,7 @@ out:
        return ret;
 
 out_usage:
-       usage(APPLY);
+       usage(CMD_APPLY, stderr);
        ret = -1;
        goto out;
 }
@@ -1720,13 +1613,13 @@ out_usage:
  * the desired image.  'wimlib-imagex append': add a new image to an existing
  * WIM file. */
 static int
-imagex_capture_or_append(int argc, tchar **argv)
+imagex_capture_or_append(int argc, tchar **argv, int cmd)
 {
        int c;
        int open_flags = WIMLIB_OPEN_FLAG_WRITE_ACCESS;
        int add_image_flags = WIMLIB_ADD_IMAGE_FLAG_EXCLUDE_VERBOSE;
        int write_flags = 0;
-       int compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS;
+       int compression_type = WIMLIB_COMPRESSION_TYPE_LZX;
        const tchar *wimfile;
        int wim_fd;
        const tchar *name;
@@ -1734,7 +1627,6 @@ imagex_capture_or_append(int argc, tchar **argv)
        const tchar *flags_element = NULL;
        WIMStruct *wim;
        int ret;
-       int cmd = tstrcmp(argv[0], T("append")) ? CAPTURE : APPEND;
        unsigned num_threads = 0;
 
        tchar *source;
@@ -1838,7 +1730,7 @@ imagex_capture_or_append(int argc, tchar **argv)
        #else
                write_flags |= WIMLIB_WRITE_FLAG_PIPABLE;
        #endif
-               if (cmd == APPEND) {
+               if (cmd == CMD_APPEND) {
                        imagex_error(T("Using standard output for append does "
                                       "not make sense."));
                        goto out_err;
@@ -1917,7 +1809,7 @@ imagex_capture_or_append(int argc, tchar **argv)
                config = &default_capture_config;
        }
 
-       if (cmd == APPEND)
+       if (cmd == CMD_APPEND)
                ret = wimlib_open_wim(wimfile, open_flags, &wim,
                                      imagex_progress_func);
        else
@@ -1946,7 +1838,7 @@ imagex_capture_or_append(int argc, tchar **argv)
        }
 #endif
 
-       if (cmd == APPEND && name_defaulted) {
+       if (cmd == CMD_APPEND && name_defaulted) {
                /* If the user did not specify an image name, and the basename
                 * of the source already exists as an image name in the WIM
                 * file, append a suffix to make it unique. */
@@ -1999,7 +1891,7 @@ imagex_capture_or_append(int argc, tchar **argv)
 
        /* Write the new WIM or overwrite the existing WIM with the new image
         * appended.  */
-       if (cmd == APPEND) {
+       if (cmd == CMD_APPEND) {
                ret = wimlib_overwrite(wim, write_flags, num_threads,
                                       imagex_progress_func);
        } else if (wimfile) {
@@ -2032,7 +1924,7 @@ out:
        return ret;
 
 out_usage:
-       usage(cmd);
+       usage(cmd, stderr);
 out_err:
        ret = -1;
        goto out;
@@ -2040,7 +1932,7 @@ out_err:
 
 /* Remove image(s) from a WIM. */
 static int
-imagex_delete(int argc, tchar **argv)
+imagex_delete(int argc, tchar **argv, int cmd)
 {
        int c;
        int open_flags = WIMLIB_OPEN_FLAG_WRITE_ACCESS;
@@ -2106,7 +1998,7 @@ out:
        return ret;
 
 out_usage:
-       usage(DELETE);
+       usage(CMD_DELETE, stderr);
        ret = -1;
        goto out;
 }
@@ -2120,7 +2012,7 @@ print_full_path(const struct wimlib_dir_entry *wdentry, void *_ignore)
 
 /* Print the files contained in an image(s) in a WIM file. */
 static int
-imagex_dir(int argc, tchar **argv)
+imagex_dir(int argc, tchar **argv, int cmd)
 {
        const tchar *wimfile;
        WIMStruct *wim = NULL;
@@ -2187,7 +2079,7 @@ out:
        return ret;
 
 out_usage:
-       usage(DIR);
+       usage(CMD_DIR, stderr);
        ret = -1;
        goto out;
 }
@@ -2195,7 +2087,7 @@ out_usage:
 /* Exports one, or all, images from a WIM file to a new WIM file or an existing
  * WIM file. */
 static int
-imagex_export(int argc, tchar **argv)
+imagex_export(int argc, tchar **argv, int cmd)
 {
        int c;
        int open_flags = 0;
@@ -2399,7 +2291,7 @@ out:
        return ret;
 
 out_usage:
-       usage(EXPORT);
+       usage(CMD_EXPORT, stderr);
 out_err:
        ret = -1;
        goto out;
@@ -2468,7 +2360,7 @@ prepare_extract_commands(tchar **paths, unsigned num_paths,
 
 /* Extract files or directories from a WIM image */
 static int
-imagex_extract(int argc, tchar **argv)
+imagex_extract(int argc, tchar **argv, int cmd)
 {
        int c;
        int open_flags = WIMLIB_OPEN_FLAG_SPLIT_OK;
@@ -2573,9 +2465,10 @@ imagex_extract(int argc, tchar **argv)
                if (!imagex_be_quiet)
                        imagex_printf(T("Done extracting files.\n"));
        } else if (ret == WIMLIB_ERR_PATH_DOES_NOT_EXIST) {
-               tfprintf(stderr, T("Note: You can use `"IMAGEX_PROGNAME" dir' to see what "
+               tfprintf(stderr, T("Note: You can use `%"TS"' to see what "
                                   "files and directories\n"
-                                  "      are in the WIM image.\n"));
+                                  "      are in the WIM image.\n"),
+                               get_cmd_string(CMD_INFO, false));
        }
 #ifdef __WIN32__
        win32_release_restore_privileges();
@@ -2591,7 +2484,7 @@ out:
        return ret;
 
 out_usage:
-       usage(EXTRACT);
+       usage(CMD_EXTRACT, stderr);
 out_err:
        ret = -1;
        goto out;
@@ -2672,7 +2565,7 @@ print_lookup_table(WIMStruct *wim)
 /* Prints information about a WIM file; also can mark an image as bootable,
  * change the name of an image, or change the description of an image. */
 static int
-imagex_info(int argc, tchar **argv)
+imagex_info(int argc, tchar **argv, int cmd)
 {
        int c;
        bool boot         = false;
@@ -2939,7 +2832,7 @@ out:
        return ret;
 
 out_usage:
-       usage(INFO);
+       usage(CMD_INFO, stderr);
 out_err:
        ret = -1;
        goto out;
@@ -2947,7 +2840,7 @@ out_err:
 
 /* Join split WIMs into one part WIM */
 static int
-imagex_join(int argc, tchar **argv)
+imagex_join(int argc, tchar **argv, int cmd)
 {
        int c;
        int swm_open_flags = WIMLIB_OPEN_FLAG_SPLIT_OK;
@@ -2984,14 +2877,14 @@ out:
        return ret;
 
 out_usage:
-       usage(JOIN);
+       usage(CMD_JOIN, stderr);
        ret = -1;
        goto out;
 }
 
 /* Mounts an image using a FUSE mount. */
 static int
-imagex_mount_rw_or_ro(int argc, tchar **argv)
+imagex_mount_rw_or_ro(int argc, tchar **argv, int cmd)
 {
        int c;
        int mount_flags = 0;
@@ -3006,7 +2899,7 @@ imagex_mount_rw_or_ro(int argc, tchar **argv)
        WIMStruct **additional_swms;
        unsigned num_additional_swms;
 
-       if (!tstrcmp(argv[0], T("mountrw"))) {
+       if (cmd == CMD_MOUNTRW) {
                mount_flags |= WIMLIB_MOUNT_FLAG_READWRITE;
                open_flags |= WIMLIB_OPEN_FLAG_WRITE_ACCESS;
        }
@@ -3109,15 +3002,14 @@ out:
        return ret;
 
 out_usage:
-       usage((mount_flags & WIMLIB_MOUNT_FLAG_READWRITE)
-                       ? MOUNTRW : MOUNT);
+       usage(cmd, stderr);
        ret = -1;
        goto out;
 }
 
 /* Rebuild a WIM file */
 static int
-imagex_optimize(int argc, tchar **argv)
+imagex_optimize(int argc, tchar **argv, int cmd)
 {
        int c;
        int open_flags = WIMLIB_OPEN_FLAG_WRITE_ACCESS;
@@ -3203,7 +3095,7 @@ out:
        return ret;
 
 out_usage:
-       usage(OPTIMIZE);
+       usage(CMD_OPTIMIZE, stderr);
 out_err:
        ret = -1;
        goto out;
@@ -3211,7 +3103,7 @@ out_err:
 
 /* Split a WIM into a spanned set */
 static int
-imagex_split(int argc, tchar **argv)
+imagex_split(int argc, tchar **argv, int cmd)
 {
        int c;
        int open_flags = 0;
@@ -3254,7 +3146,7 @@ out:
        return ret;
 
 out_usage:
-       usage(SPLIT);
+       usage(CMD_SPLIT, stderr);
 out_err:
        ret = -1;
        goto out;
@@ -3262,7 +3154,7 @@ out_err:
 
 /* Unmounts a mounted WIM image. */
 static int
-imagex_unmount(int argc, tchar **argv)
+imagex_unmount(int argc, tchar **argv, int cmd)
 {
        int c;
        int unmount_flags = 0;
@@ -3299,7 +3191,7 @@ out:
        return ret;
 
 out_usage:
-       usage(UNMOUNT);
+       usage(CMD_UNMOUNT, stderr);
        ret = -1;
        goto out;
 }
@@ -3308,7 +3200,7 @@ out_usage:
  * Add, delete, or rename files in a WIM image.
  */
 static int
-imagex_update(int argc, tchar **argv)
+imagex_update(int argc, tchar **argv, int cmd)
 {
        const tchar *wimfile;
        int image;
@@ -3453,7 +3345,7 @@ imagex_update(int argc, tchar **argv)
        } else {
                if (isatty(STDIN_FILENO)) {
                        tputs(T("Reading update commands from standard input..."));
-                       recommend_man_page(T("update"));
+                       recommend_man_page(CMD_UPDATE, stdout);
                }
                cmd_file_contents = stdin_get_text_contents(&cmd_file_nchars);
                if (!cmd_file_contents) {
@@ -3522,46 +3414,161 @@ out_free_command_str:
        return ret;
 
 out_usage:
-       usage(UPDATE);
+       usage(CMD_UPDATE, stderr);
 out_err:
        ret = -1;
        goto out_free_command_str;
 }
 
+
+
 struct imagex_command {
        const tchar *name;
-       int (*func)(int , tchar **);
-       int cmd;
+       int (*func)(int argc, tchar **argv, int cmd);
 };
 
-
-#define for_imagex_command(p) for (p = &imagex_commands[0]; \
-               p != &imagex_commands[ARRAY_LEN(imagex_commands)]; p++)
-
 static const struct imagex_command imagex_commands[] = {
-       {T("append"),  imagex_capture_or_append, APPEND},
-       {T("apply"),   imagex_apply,             APPLY},
-       {T("capture"), imagex_capture_or_append, CAPTURE},
-       {T("delete"),  imagex_delete,            DELETE},
-       {T("dir"),     imagex_dir,               DIR},
-       {T("export"),  imagex_export,            EXPORT},
-       {T("extract"), imagex_extract,           EXTRACT},
-       {T("info"),    imagex_info,              INFO},
-       {T("join"),    imagex_join,              JOIN},
-       {T("mount"),   imagex_mount_rw_or_ro,    MOUNT},
-       {T("mountrw"), imagex_mount_rw_or_ro,    MOUNTRW},
-       {T("optimize"),imagex_optimize,          OPTIMIZE},
-       {T("split"),   imagex_split,             SPLIT},
-       {T("unmount"), imagex_unmount,           UNMOUNT},
-       {T("update"),  imagex_update,            UPDATE},
+       [CMD_APPEND]   = {T("append"),   imagex_capture_or_append},
+       [CMD_APPLY]    = {T("apply"),    imagex_apply},
+       [CMD_CAPTURE]  = {T("capture"),  imagex_capture_or_append},
+       [CMD_DELETE]   = {T("delete"),   imagex_delete},
+       [CMD_DIR ]     = {T("dir"),      imagex_dir},
+       [CMD_EXPORT]   = {T("export"),   imagex_export},
+       [CMD_EXTRACT]  = {T("extract"),  imagex_extract},
+       [CMD_INFO]     = {T("info"),     imagex_info},
+       [CMD_JOIN]     = {T("join"),     imagex_join},
+       [CMD_MOUNT]    = {T("mount"),    imagex_mount_rw_or_ro},
+       [CMD_MOUNTRW]  = {T("mountrw"),  imagex_mount_rw_or_ro},
+       [CMD_OPTIMIZE] = {T("optimize"), imagex_optimize},
+       [CMD_SPLIT]    = {T("split"),    imagex_split},
+       [CMD_UNMOUNT]  = {T("unmount"),  imagex_unmount},
+       [CMD_UPDATE]   = {T("update"),   imagex_update},
 };
 
+static const tchar *usage_strings[] = {
+[CMD_APPEND] =
+T(
+"    %"TS" (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n"
+"                    [DESCRIPTION] [--boot] [--check] [--nocheck]\n"
+"                    [--flags EDITION_ID] [--verbose] [--dereference]\n"
+"                    [--config=FILE] [--threads=NUM_THREADS] [--rebuild]\n"
+"                    [--unix-data] [--source-list] [--no-acls]\n"
+"                    [--strict-acls] [--rpfix] [--norpfix] [--pipable]\n"
+"                    [--not-pipable]\n"
+),
+[CMD_APPLY] =
+T(
+"    %"TS" WIMFILE [IMAGE_NUM | IMAGE_NAME | all]\n"
+"                    (DIRECTORY | NTFS_VOLUME) [--check] [--hardlink]\n"
+"                    [--symlink] [--verbose] [--ref=\"GLOB\"] [--unix-data]\n"
+"                    [--no-acls] [--strict-acls] [--rpfix] [--norpfix]\n"
+"                    [--include-invalid-names]\n"
+),
+[CMD_CAPTURE] =
+T(
+"    %"TS" (DIRECTORY | NTFS_VOLUME) WIMFILE [IMAGE_NAME]\n"
+"                    [DESCRIPTION] [--boot] [--check] [--nocheck]\n"
+"                    [--compress=TYPE] [--flags EDITION_ID] [--verbose]\n"
+"                    [--dereference] [--config=FILE]\n"
+"                    [--threads=NUM_THREADS] [--unix-data] [--source-list]\n"
+"                    [--no-acls] [--strict-acls] [--rpfix] [--norpfix]\n"
+"                    [--pipable] [--not-pipable]\n"
+),
+[CMD_DELETE] =
+T(
+"    %"TS" WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--check]\n"
+"                    [--soft]\n"
+),
+[CMD_DIR] =
+T(
+"    %"TS" WIMFILE (IMAGE_NUM | IMAGE_NAME | all) [--path=PATH]\n"
+),
+[CMD_EXPORT] =
+T(
+"    %"TS" SRC_WIMFILE (SRC_IMAGE_NUM | SRC_IMAGE_NAME | all ) \n"
+"                    DEST_WIMFILE [DEST_IMAGE_NAME] [DEST_IMAGE_DESCRIPTION]\n"
+"                    [--boot] [--check] [--nocheck] [--compress=TYPE]\n"
+"                    [--ref=\"GLOB\"] [--threads=NUM_THREADS] [--rebuild]\n"
+"                    [--pipable] [--not-pipable]\n"
+),
+[CMD_EXTRACT] =
+T(
+"    %"TS" WIMFILE (IMAGE_NUM | IMAGE_NAME) [PATH...]\n"
+"                    [--check] [--ref=\"GLOB\"] [--verbose] [--unix-data]\n"
+"                    [--no-acls] [--strict-acls] [--to-stdout] [--dest-dir=CMD_DIR]\n"
+"                    [--include-invalid-names]\n"
+),
+[CMD_INFO] =
+T(
+"    %"TS" WIMFILE [IMAGE_NUM | IMAGE_NAME] [NEW_NAME]\n"
+"                    [NEW_DESC] [--boot] [--check] [--nocheck] [--header]\n"
+"                    [--lookup-table] [--xml] [--extract-xml FILE]\n"
+"                    [--metadata]\n"
+),
+[CMD_JOIN] =
+T(
+"    %"TS" [--check] WIMFILE SPLIT_WIM...\n"
+),
+[CMD_MOUNT] =
+T(
+"    %"TS" WIMFILE (IMAGE_NUM | IMAGE_NAME) DIRECTORY\n"
+"                    [--check] [--debug] [--streams-interface=INTERFACE]\n"
+"                    [--ref=\"GLOB\"] [--unix-data] [--allow-other]\n"
+),
+[CMD_MOUNTRW] =
+T(
+"    %"TS" WIMFILE [IMAGE_NUM | IMAGE_NAME] DIRECTORY\n"
+"                    [--check] [--debug] [--streams-interface=INTERFACE]\n"
+"                    [--staging-dir=CMD_DIR] [--unix-data] [--allow-other]\n"
+),
+[CMD_OPTIMIZE] =
+T(
+"    %"TS" WIMFILE [--check] [--nocheck] [--recompress]\n"
+"                    [--threads=NUM_THREADS] [--pipable] [--not-pipable]\n"
+),
+[CMD_SPLIT] =
+T(
+"    %"TS" WIMFILE SPLIT_WIMFILE PART_SIZE_MB [--check]\n"
+),
+[CMD_UNMOUNT] =
+T(
+"    %"TS" DIRECTORY [--commit] [--check] [--rebuild] [--lazy]\n"
+),
+[CMD_UPDATE] =
+T(
+"    %"TS" WIMFILE [IMAGE_NUM | IMAGE_NAME] [--check] [--rebuild]\n"
+"                    [--threads=NUM_THREADS] [DEFAULT_ADD_OPTIONS]\n"
+"                    [DEFAULT_DELETE_OPTIONS] [--command=STRING] [< CMDFILE]\n"
+),
+};
+
+static const tchar *invocation_name;
+static bool using_cmd_from_invocation_name = false;
+
+static const tchar *get_cmd_string(int cmd, bool nospace)
+{
+
+       if (using_cmd_from_invocation_name || cmd == CMD_NONE) {
+               return invocation_name;
+       } else {
+               const tchar *format;
+               static tchar buf[50];
+
+               if (nospace)
+                       format = T("%"TS"-%"TS"");
+               else
+                       format = T("%"TS" %"TS"");
+               tsprintf(buf, format, invocation_name, imagex_commands[cmd].name);
+               return buf;
+       }
+}
+
 static void
 version(void)
 {
-       static const tchar *s =
+       static const tchar *format =
        T(
-IMAGEX_PROGNAME " (" PACKAGE ") " PACKAGE_VERSION "\n"
+"%"TS" (" PACKAGE ") " PACKAGE_VERSION "\n"
 "Copyright (C) 2012, 2013 Eric Biggers\n"
 "License GPLv3+; GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
 "This is free software: you are free to change and redistribute it.\n"
@@ -3569,72 +3576,79 @@ IMAGEX_PROGNAME " (" PACKAGE ") " PACKAGE_VERSION "\n"
 "\n"
 "Report bugs to "PACKAGE_BUGREPORT".\n"
        );
-       tfputs(s, stdout);
+       tprintf(format, invocation_name);
 }
 
 
 static void
-help_or_version(int argc, tchar **argv)
+help_or_version(int argc, tchar **argv, int cmd)
 {
        int i;
        const tchar *p;
-       const struct imagex_command *cmd;
 
        for (i = 1; i < argc; i++) {
                p = argv[i];
-               if (*p == T('-'))
-                       p++;
-               else
-                       continue;
-               if (*p == T('-'))
-                       p++;
-               if (!tstrcmp(p, T("help"))) {
-                       for_imagex_command(cmd) {
-                               if (!tstrcmp(cmd->name, argv[1])) {
-                                       usage(cmd->cmd);
-                                       exit(0);
-                               }
+               if (p[0] == T('-') && p[1] == T('-')) {
+                       p += 2;
+                       if (!tstrcmp(p, T("help"))) {
+                               if (cmd == CMD_NONE)
+                                       usage_all(stdout);
+                               else
+                                       usage(cmd, stdout);
+                               exit(0);
+                       } else if (!tstrcmp(p, T("version"))) {
+                               version();
+                               exit(0);
                        }
-                       usage_all();
-                       exit(0);
-               }
-               if (!tstrcmp(p, T("version"))) {
-                       version();
-                       exit(0);
                }
        }
 }
 
+static void
+print_usage_string(int cmd, FILE *fp)
+{
+       tfprintf(fp, usage_strings[cmd], get_cmd_string(cmd, false));
+}
 
 static void
-usage(int cmd_type)
+recommend_man_page(int cmd, FILE *fp)
 {
-       const struct imagex_command *cmd;
-       tprintf(T("Usage:\n%"TS), usage_strings[cmd_type]);
-       for_imagex_command(cmd) {
-               if (cmd->cmd == cmd_type) {
-                       tputc(T('\n'), stdout);
-                       recommend_man_page(cmd->name);
-               }
-       }
+       const tchar *format_str;
+#ifdef __WIN32__
+       format_str = T("See %"TS".pdf in the doc directory for more details.\n");
+#else
+       format_str = T("Try `man %"TS"' for more details.\n");
+#endif
+       tfprintf(fp, format_str, get_cmd_string(cmd, true));
+}
+
+static void
+usage(int cmd, FILE *fp)
+{
+       tfprintf(fp, T("Usage:\n"));
+       print_usage_string(cmd, fp);
+       tfprintf(fp, T("\n"));
+       recommend_man_page(cmd, fp);
 }
 
 static void
-usage_all(void)
+usage_all(FILE *fp)
 {
-       tfputs(T("Usage:\n"), stdout);
-       for (int i = 0; i < ARRAY_LEN(usage_strings); i++)
-               tprintf(T("    %"TS"\n"), usage_strings[i]);
+       tfprintf(fp, T("Usage:\n"));
+       for (int cmd = 0; cmd < CMD_MAX; cmd++) {
+               print_usage_string(cmd, fp);
+               tfprintf(fp, T("\n"));
+       }
        static const tchar *extra =
        T(
-"    "IMAGEX_PROGNAME" --help\n"
-"    "IMAGEX_PROGNAME" --version\n"
+"    %"TS" --help\n"
+"    %"TS" --version\n"
 "\n"
 "    The compression TYPE may be \"maximum\", \"fast\", or \"none\".\n"
 "\n"
        );
-       tfputs(extra, stdout);
-       recommend_man_page(T(""));
+       tfprintf(fp, extra, invocation_name, invocation_name);
+       recommend_man_page(CMD_NONE, fp);
 }
 
 /* Entry point for wimlib's ImageX implementation.  On UNIX the command
@@ -3648,11 +3662,12 @@ wmain(int argc, wchar_t **argv, wchar_t **envp)
 main(int argc, char **argv)
 #endif
 {
-       const struct imagex_command *cmd;
        int ret;
        int init_flags = 0;
+       int cmd;
 
        imagex_info_file = stdout;
+       invocation_name = basename(argv[0]);
 
 #ifndef __WIN32__
        if (getenv("WIMLIB_IMAGEX_USE_UTF8")) {
@@ -3667,67 +3682,86 @@ main(int argc, char **argv)
                    !strstr(codeset, "utf-8") &&
                    !strstr(codeset, "utf8"))
                {
-                       fputs(
-"WARNING: Running "IMAGEX_PROGNAME" in a UTF-8 locale is recommended!\n"
+                       fprintf(stderr,
+"WARNING: Running %"TS" in a UTF-8 locale is recommended!\n"
 "         Maybe try: `export LANG=en_US.UTF-8'?\n"
 "         Alternatively, set the environmental variable WIMLIB_IMAGEX_USE_UTF8\n"
 "         to any value to force wimlib to use UTF-8.\n",
-                       stderr);
+                       invocation_name);
 
                }
        }
 #endif /* !__WIN32__ */
 
-       if (argc < 2) {
-               imagex_error(T("No command specified"));
-               usage_all();
-               ret = 2;
-               goto out;
+       /* Allow being invoked as wimCOMMAND (e.g. wimapply).  */
+       cmd = CMD_NONE;
+       if (!tstrncmp(invocation_name, T("wim"), 3) &&
+           tstrcmp(invocation_name, T(IMAGEX_PROGNAME))) {
+               for (int i = 0; i < CMD_MAX; i++) {
+                       if (!tstrcmp(invocation_name + 3,
+                                    imagex_commands[i].name))
+                       {
+                               using_cmd_from_invocation_name = true;
+                               cmd = i;
+                               break;
+                       }
+               }
+       }
+
+       /* Unless already known from the invocation name, search for the
+        * function to handle the specified subcommand.  */
+       if (cmd == CMD_NONE) {
+               if (argc < 2) {
+                       imagex_error(T("No command specified!\n"));
+                       usage_all(stderr);
+                       exit(2);
+               }
+               for (int i = 0; i < CMD_MAX; i++) {
+                       if (!tstrcmp(argv[1], imagex_commands[i].name)) {
+                               cmd = i;
+                               break;
+                       }
+               }
+               if (cmd != CMD_NONE) {
+                       argc--;
+                       argv++;
+               }
        }
 
        /* Handle --help and --version for all commands.  Note that this will
         * not return if either of these arguments are present. */
-       help_or_version(argc, argv);
-       argc--;
-       argv++;
+       help_or_version(argc, argv, cmd);
+
+       if (cmd == CMD_NONE) {
+               imagex_error(T("Unrecognized command: `%"TS"'\n"), argv[1]);
+               usage_all(stderr);
+               exit(2);
+       }
 
-       /* The user may like to see more informative error messages. */
+       /* The user may like to see more informative error messages.  */
        wimlib_set_print_errors(true);
 
-       /* Do any initializations that the library needs */
+       /* Initialize the library.  */
        ret = wimlib_global_init(init_flags);
        if (ret)
                goto out_check_status;
 
-       /* Search for the function to handle the ImageX subcommand. */
-       for_imagex_command(cmd) {
-               if (!tstrcmp(cmd->name, *argv)) {
-                       ret = cmd->func(argc, argv);
-                       goto out_check_write_error;
-               }
-       }
-
-       imagex_error(T("Unrecognized command: `%"TS"'"), argv[0]);
-       usage_all();
-       ret = 2;
-       goto out_cleanup;
-out_check_write_error:
-       /* For 'wimlib-imagex info' and 'wimlib-imagex dir', data printed to
-        * standard output is part of the program's actual behavior and not just
-        * for informational purposes, so we should set a failure exit status if
-        * there was a write error. */
-       if (cmd == &imagex_commands[INFO] || cmd == &imagex_commands[DIR]) {
-               if (ferror(stdout) || fclose(stdout)) {
-                       imagex_error_with_errno(T("error writing to standard output"));
-                       if (ret == 0)
-                               ret = -1;
-               }
+       /* Call the command handler function.  */
+       ret = imagex_commands[cmd].func(argc, argv, cmd);
+
+       /* Check for error writing to standard output, especially since for some
+        * commands, writing to standard output is part of the program's actual
+        * behavior and not just for informational purposes.  */
+       if (ferror(stdout) || fclose(stdout)) {
+               imagex_error_with_errno(T("error writing to standard output"));
+               if (ret == 0)
+                       ret = -1;
        }
 out_check_status:
        /* Exit status (ret):  -1 indicates an error found by 'wimlib-imagex'
         * outside of the wimlib library code.  0 indicates success.  > 0
         * indicates a wimlib error code from which an error message can be
-        * printed. */
+        * printed.  */
        if (ret > 0) {
                imagex_error(T("Exiting with error code %d:\n"
                               "       %"TS"."), ret,
@@ -3735,10 +3769,8 @@ out_check_status:
                if (ret == WIMLIB_ERR_NTFS_3G && errno != 0)
                        imagex_error_with_errno(T("errno"));
        }
-out_cleanup:
        /* Make the library free any resources it's holding (not strictly
-        * necessary because the process is ending anyway). */
+        * necessary because the process is ending anyway).  */
        wimlib_global_cleanup();
-out:
        return ret;
 }
index 2f9f440efb86eab662780cca5d16fb2b39e9d582..d54fd23671389adc861dc4db9e5309e0371e5bd3 100644 (file)
@@ -116,9 +116,9 @@ struct wimfs_context {
        /* Name and message queue descriptors for message queues between the
         * filesystem daemon process and the unmount process.  These are used
         * when the filesystem is unmounted and the process running
-        * wimlib_unmount_image() (i.e. the `imagex unmount' command) needs to
-        * communicate with the filesystem daemon running fuse_main() (i.e. the
-        * daemon created by the `imagex mount' or `imagex mountrw' commands */
+        * wimlib_unmount_image() needs to communicate with the filesystem
+        * daemon running fuse_main() (i.e. the process created by a call to
+        * wimlib_mount_image().  */
        char *unmount_to_daemon_mq_name;
        char *daemon_to_unmount_mq_name;
        mqd_t unmount_to_daemon_mq;
@@ -2478,7 +2478,7 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
                goto out_free_message_queue_names;
 
        argc = 0;
-       argv[argc++] = IMAGEX_PROGNAME;
+       argv[argc++] = "wimlib";
        argv[argc++] = dir_copy;
 
        /* disable multi-threaded operation */