SourceForge.net Logo

cpack

download files

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]

Options are:

-b
Next file is binary
@file
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.

Examples

Packing

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

unpacking is the easy part.

cc this-dist.c
./this-dist
If you are using a Microsoft ® C compiler, you may need to increase the size of the heap
cl /Zm400 this-dist.c
.\this-dist

FAQ

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!
A:
  1. Disk space is cheap
  2. Most people have High Speed Internet
  3. 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.
  4. Previous Q: is not technically a question, and this A: is a comment, not an answer. :-)
Q: What if I don't have a C compiler?
A:
  • 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)
Q: Why not write this in Java?
A: Java has .jar files, and C is more portable than Java.

Things to do

These things are not done because they are so unportable.


Last modified: Thu Nov 30 22:28:01 Central Standard Time 2006