Add "examples" directory
authorEric Biggers <ebiggers3@gmail.com>
Wed, 15 May 2013 02:50:59 +0000 (21:50 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Wed, 15 May 2013 02:50:59 +0000 (21:50 -0500)
Makefile.am
examples/Makefile [new file with mode: 0644]
examples/README [new file with mode: 0644]
examples/applywim.c [new file with mode: 0644]
examples/makewim.c [new file with mode: 0644]

index a5cd054..d0d9f38 100644 (file)
@@ -164,6 +164,7 @@ EXTRA_DIST =                                        \
        archlinux                               \
        debian                                  \
        rpm                                     \
+       examples                                \
        README.WINDOWS                          \
        programs/install.cmd                    \
        programs/wimapply.c                     \
diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644 (file)
index 0000000..ef84a9b
--- /dev/null
@@ -0,0 +1,13 @@
+CFLAGS := -Wall -s
+LDLIBS := -lwim
+
+all:applywim makewim
+
+applywim:applywim.c
+
+makewim:makewim.c
+
+clean:
+       rm -f applywim makewim
+
+.PHONY: all clean
diff --git a/examples/README b/examples/README
new file mode 100644 (file)
index 0000000..dcf550a
--- /dev/null
@@ -0,0 +1,2 @@
+This directory shows some simple examples of C programs that use the wimlib
+library.  See programs/imagex.c for a more complete example.
diff --git a/examples/applywim.c b/examples/applywim.c
new file mode 100644 (file)
index 0000000..ba62a95
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * applywim.c - A simple program to extract all images from a WIM file to a
+ * directory.
+ */
+
+#include <wimlib.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+       int ret;
+       WIMStruct *wim;
+
+       if (argc != 3) {
+               fprintf(stderr, "Usage: applywim WIM DIR\n");
+               ret = 2;
+               goto out;
+       }
+
+       /* Initialize the library. */
+       ret = wimlib_global_init(0);
+       if (ret)
+               goto out;
+
+       /* Open the WIM file. */
+       ret = wimlib_open_wim(argv[1], 0, &wim, NULL);
+       if (ret)
+               goto out_wimlib_global_cleanup;
+
+       /* Extract all the images. */
+       ret = wimlib_extract_image(wim, WIMLIB_ALL_IMAGES, argv[2], 0,
+                                  NULL, 0, NULL);
+
+       /* Free the WIM file */
+       wimlib_free(wim);
+
+out_wimlib_global_cleanup:
+       /* Finalize the library */
+       wimlib_global_cleanup();
+out:
+       return ret;
+}
diff --git a/examples/makewim.c b/examples/makewim.c
new file mode 100644 (file)
index 0000000..08ed728
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * makewim.c - A simple program to make a LZX-compressed WIM file from a
+ * directory.
+ */
+
+#include <wimlib.h>
+#include <stdio.h>
+
+int main(int argc, char **argv)
+{
+       int ret;
+       WIMStruct *wim;
+
+       if (argc != 3) {
+               fprintf(stderr, "Usage: makewim DIR WIM\n");
+               ret = 2;
+               goto out;
+       }
+
+       /* Initialize the library. */
+       ret = wimlib_global_init(0);
+       if (ret)
+               goto out;
+
+       /* Create a WIMStruct for a LZX-compressed WIM. */
+       ret = wimlib_create_new_wim(WIMLIB_COMPRESSION_TYPE_LZX, &wim);
+       if (ret)
+               goto out_wimlib_global_cleanup;
+
+       /* Add the directory tree to the WIMStruct as an image. */
+       ret = wimlib_add_image(wim, argv[1], "1", NULL, 0, NULL);
+       if (ret)
+               goto out_wimlib_free;
+
+       /* Write the desired WIM file. */
+       ret = wimlib_write(wim, argv[2], WIMLIB_ALL_IMAGES, 0, 0, NULL);
+
+out_wimlib_free:
+       /* Free the WIM file */
+       wimlib_free(wim);
+
+out_wimlib_global_cleanup:
+       /* Finalize the library */
+       wimlib_global_cleanup();
+out:
+       return ret;
+}