/* cflags: */
/* linker: code.o debug.o */
-#include <assert.h>
-#include <getopt.h>
#include <malloc.h>
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "code.h"
#include "debug.h"
exit (ret);
}
+void blkcpy (void *dst, const void *src, int len)
+{
+ while (len--) {
+ *((char *)dst++) = *((char *)src++);
+ }
+}
+
/* create occurence table */
int *create_table (char *filename)
/* allocation */
header = (byte_t *) calloc (length + 6, 1);
- memcpy (header, buffer, length + 6);
+ blkcpy (header, buffer, length + 6);
VERBOSE (DEBUG, PRINTF ("end encoding header and code table\n"));
progname = argv[0];
int c;
+ char * arg;
VERBOSE (DEBUG, PRINTF ("start processing arguments\n"));
- while ((c = getopt(argc, argv, "cdhi:o:v:")) != EOF) {
+ while (argc-- > 1) {
+ arg = *(++argv);
+ if (arg[0] != '-') {
+ fprintf (stderr, "%s: invalid option -- %s\n", progname, arg);
+ usage (1);
+ }
+ c = arg[1];
VERBOSE (DEBUG, PRINTF ("option: %c\n", c));
switch (c) {
case 'c':
mode = DECOMPRESS;
break;
case 'i':
- input = optarg;
+ input = (arg[2]) ? arg + 2 : (--argc > 0 ) ? *(++argv) : NULL;
VERBOSE (DEBUG, PRINTF ("input: %s\n", input));
break;
case 'o':
- output = optarg;
+ output = (arg[2]) ? arg + 2 : (--argc > 0 ) ? *(++argv) : NULL;
VERBOSE (DEBUG, PRINTF ("output: %s\n", output));
break;
case 'v':
- verbose = atoi (optarg);
+ arg = (arg[2]) ? arg + 2 : (--argc > 0 ) ? *(++argv) : NULL;
+ if (arg == NULL) {
+ fprintf (stderr, "%s: missing verbose level\n", progname);
+ usage (1);
+ }
+ verbose = atoi (arg);
VERBOSE (INFO, printf ("verbose: %d\n", verbose));
break;
case 'h':
usage (c != 'h');
}
}
- if (argc - optind != 0) {
- fprintf (stderr, "%s: invalid option -- %s\n", progname, argv[optind]);
+ if ((input == NULL) || (output == NULL)) {
+ fprintf (stderr, "%s: missing file\n", progname);
usage (1);
}
VERBOSE (DEBUG, PRINTF ("end processing arguments\n"));