From: Eric Biggers Date: Wed, 15 May 2013 02:50:59 +0000 (-0500) Subject: Add "examples" directory X-Git-Tag: v1.4.0~44 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=16b6e19468c93a370ff2347031a62130c18ad7d7;ds=sidebyside Add "examples" directory --- diff --git a/Makefile.am b/Makefile.am index a5cd0540..d0d9f38a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 00000000..ef84a9b2 --- /dev/null +++ b/examples/Makefile @@ -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 index 00000000..dcf550aa --- /dev/null +++ b/examples/README @@ -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 index 00000000..ba62a957 --- /dev/null +++ b/examples/applywim.c @@ -0,0 +1,42 @@ +/* + * applywim.c - A simple program to extract all images from a WIM file to a + * directory. + */ + +#include +#include + +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 index 00000000..08ed728c --- /dev/null +++ b/examples/makewim.c @@ -0,0 +1,47 @@ +/* + * makewim.c - A simple program to make a LZX-compressed WIM file from a + * directory. + */ + +#include +#include + +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; +}