cpack is a packaging utility for C source code, but can be applied to
other files as well. cpack is in the same spirit as "shar" files,
which are self-extracting shell archive files.
Usage: cpack [option] file ... [ > outfile.c]
- Next file is binary
- file is a text list of files, one file per line (generated
with ls -1 or dir /b or dir /col=1 depending on your OS). If the
file is to be processed as binary, "-b " should appear before
the file name (do not include the quotes, but do put in one space).
Note: all directory separators must be a slash (/) character
regardless of the OS.
cpack 0Readme.txt Makefile mycode.c > mycode-dist.c
dir /b *.c Makefile > dirlist.txt
cpack @dirlist.txt > this-dist.c
cpack Makefile file1.c -b table.xls file2.c > spreadsheet.c
unpacking is the easy part.
If you are using a Microsoft ® C compiler, you may need to
increase the size of the heap
cl /Zm400 this-dist.c
Q: Why not use getopt?
A: getopt is non standard on platforms besides unix. The code would be
complicated by #ifdefs if getopt was implemented.
Q: The resulting file is so large!
Q: What if I don't have a C compiler?
- Disk space is cheap
- Most people have High Speed Internet
- If the file is compressed with zip, it can be decompressed with
either unzip, or gunzip (single file in a .zip archive). If the
files are small enough, a zipped cpack file will be smaller than
the zipped archive of the collection of files.
- Previous Q: is not technically a question, and this A: is a
comment, not an answer.
Q: Why not write this in Java?
- cpack is intended for archiving source code which is a variant of
C. (C, C++, C#)
- Most source will require a C compiler, anyway.
- If you don't have a C compiler, you cannot use the C source.
- The cpack archive is still human-readable.
- If the source is not C code, the cpack can still be
pre-compiled and distributed as a self-extracting
executable. (The resulting executable is often smaller than
a comparable "tar" file)
A: Java has .jar files, and C is more portable than Java.
These things are not done because they are so
- Allow for original date modification to be restored
- Allow for other directory separators (Micorosoft \ OpenVMS [.])
- Automatic md5 verification after extraction
- Option not to overwrite files
Last modified: Thu Nov 30 22:28:01 Central Standard Time 2006