/* depend: */
/* cflags: */
-/* linker: atoi.o code.o debug.o fprintf.o */
+/* linker: atoi.o code.o debug.o fdprintf.o */
#include <fcntl.h>
#include <unistd.h>
#include "atoi.h"
#include "code.h"
#include "debug.h"
-#include "fprintf.h"
+#include "fdprintf.h"
/* constants */
int usage (int ret)
{
- int fd = ret ? _fderr : _fdout;
+ int fd = ret ? stdfderr : stdfdout;
fdprintf (fd, "usage: %s\n", progname);
+ fdprintf (fd, " -c : mode compress\n");
+ fdprintf (fd, " -d : mode decompress\n");
fdprintf (fd, " -h : help message\n");
fdprintf (fd, " -i <file>: input file\n");
fdprintf (fd, " -o <file>: output file\n");
leaf_t **init_forest (int *table)
{
- static leaf_t *leafs[NB_BYTES] = {0};
+ static leaf_t *leafs[NB_BYTES + 1] = {0};
int nb_leafs = 0;
int i, l;
VERBOSE (DEBUG, PRINTOUT ("rem: %d\n", size % 256));
/* header */
- codcpy ((char *)header, sizeof (buffer), (mode == 1) ? "MZ1 " : "MZ2 ");
+ codcpy ((char *)header, sizeof (buffer), (mode == 1) ? "M1Z " : "M2Z ");
header += 6;
/* size */
/* read magic number */
nb = read (fid, buffer, 6);
VERBOSE (DEBUG, PRINTOUT ("nb, buffer: %d 0x%02x 0x%02x\n", nb, buffer[0], buffer[1]));
- if ((nb == 6) && (buffer[0] == 'M') && (buffer[1] == 'Z')) {
- mode = (buffer[2] == '1') ? 1 : (buffer[2] == '2') ? 2 : 0;
+ if ((nb == 6) && (buffer[0] == 'M') && (buffer[2] == 'Z')) {
+ mode = (buffer[1] == '1') ? 1 : (buffer[1] == '2') ? 2 : 0;
size = (buffer[3] << 8) + buffer[4];
VERBOSE (DEBUG, PRINTOUT ("mode, size: %d %d\n", mode, size));
if (size > NB_BYTES * (NB_BYTES - 1) / 2 / 8 + NB_BYTES) {
PRINTERR ("%s: missing verbose level\n", progname);
return usage (1);
}
- verbose = myatoi (arg);
+ verbose = atoi (arg);
VERBOSE (INFO, PRINTOUT ("verbose: %d\n", verbose));
break;
case 'h':
// test: compress.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
// test: compress.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
// test: compress.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
+// test: compress.exe -v 2>&1 | grep -q 'missing verbose level'
+// test: compress.exe -c -i compress.c 2>&1 | grep -q 'missing file'
+// test: compress.exe -c -v 4 -i compress.c -o compress.mz | grep -q "Occurence table"
// test: compress.exe -c -i compress.c -o compress.mz
-// test: ls -sS1 compress.c compress.mz | tail -1 | grep compress.mz
+// test: ls -sS1 compress.c compress.mz | tail -1 | grep -q compress.mz
// test: compress.exe -d -i compress.mz -o tmp.c
-// test: cmp compress.c tmp.c
-// test: rm compress.mz tmp.c
+// test: cmp compress.c tmp.c; x=$?; rm compress.mz tmp.c; test x$x = x0
+// test: compress.exe -c -i test/compress.c -o compress.mz 2>&1 | grep -q "can't open file"
+// test: compress.exe -c -i compress.c -o test/compress.mz 2>&1 | grep -q "can't open file"
/* vim: set ts=4 sw=4 et: */