mirror of
https://github.com/ckolivas/lrzip.git
synced 2026-04-21 06:03:54 +00:00
move more code out of main.c, allocate outfile suffix
This commit is contained in:
parent
08d2294e5e
commit
133b201867
6 changed files with 169 additions and 168 deletions
165
util.c
165
util.c
|
|
@ -56,6 +56,13 @@
|
|||
#include "util.h"
|
||||
#include "sha4.h"
|
||||
#include "aes.h"
|
||||
#ifdef HAVE_CTYPE_H
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
|
||||
/* Macros for testing parameters */
|
||||
#define isparameter( parmstring, value ) (!strcasecmp( parmstring, value ))
|
||||
#define iscaseparameter( parmvalue, value ) (!strcmp( parmvalue, value ))
|
||||
|
||||
void register_infile(rzip_control *control, const char *name, char delete)
|
||||
{
|
||||
|
|
@ -187,6 +194,164 @@ void get_rand(rzip_control *control, uchar *buf, int len)
|
|||
}
|
||||
}
|
||||
|
||||
void read_config(rzip_control *control)
|
||||
{
|
||||
/* check for lrzip.conf in ., $HOME/.lrzip and /etc/lrzip */
|
||||
char *HOME, *homeconf;
|
||||
char *parametervalue;
|
||||
char *parameter;
|
||||
char *line;
|
||||
FILE *fp;
|
||||
|
||||
line = malloc(255);
|
||||
homeconf = malloc(255);
|
||||
if (line == NULL || homeconf == NULL)
|
||||
fatal(control, "Fatal Memory Error in read_config");
|
||||
|
||||
fp = fopen("lrzip.conf", "r");
|
||||
if (fp)
|
||||
fprintf(control->msgout, "Using configuration file ./lrzip.conf\n");
|
||||
if (fp == NULL) {
|
||||
fp = fopen("/etc/lrzip/lrzip.conf", "r");
|
||||
if (fp)
|
||||
fprintf(control->msgout, "Using configuration file /etc/lrzip/lrzip.conf\n");
|
||||
}
|
||||
if (fp == NULL) {
|
||||
HOME=getenv("HOME");
|
||||
if (HOME) {
|
||||
strcpy(homeconf, HOME);
|
||||
strcat(homeconf,"/.lrzip/lrzip.conf");
|
||||
fp = fopen(homeconf, "r");
|
||||
if (fp)
|
||||
fprintf(control->msgout, "Using configuration file %s\n", homeconf);
|
||||
}
|
||||
}
|
||||
if (fp == NULL)
|
||||
goto out;
|
||||
|
||||
/* if we get here, we have a file. read until no more. */
|
||||
|
||||
while ((fgets(line, 255, fp)) != NULL) {
|
||||
if (strlen(line))
|
||||
line[strlen(line) - 1] = '\0';
|
||||
parameter = strtok(line, " =");
|
||||
if (parameter == NULL)
|
||||
continue;
|
||||
/* skip if whitespace or # */
|
||||
if (isspace(*parameter))
|
||||
continue;
|
||||
if (*parameter == '#')
|
||||
continue;
|
||||
|
||||
parametervalue = strtok(NULL, " =");
|
||||
if (parametervalue == NULL)
|
||||
continue;
|
||||
|
||||
/* have valid parameter line, now assign to control */
|
||||
|
||||
if (isparameter(parameter, "window"))
|
||||
control->window = atoi(parametervalue);
|
||||
else if (isparameter(parameter, "unlimited")) {
|
||||
if (isparameter(parametervalue, "yes"))
|
||||
control->flags |= FLAG_UNLIMITED;
|
||||
} else if (isparameter(parameter, "compressionlevel")) {
|
||||
control->compression_level = atoi(parametervalue);
|
||||
if ( control->compression_level < 1 || control->compression_level > 9 )
|
||||
failure(control, "CONF.FILE error. Compression Level must between 1 and 9");
|
||||
} else if (isparameter(parameter, "compressionmethod")) {
|
||||
/* valid are rzip, gzip, bzip2, lzo, lzma (default), and zpaq */
|
||||
if (control->flags & FLAG_NOT_LZMA)
|
||||
failure(control, "CONF.FILE error. Can only specify one compression method");
|
||||
if (isparameter(parametervalue, "bzip2"))
|
||||
control->flags |= FLAG_BZIP2_COMPRESS;
|
||||
else if (isparameter(parametervalue, "gzip"))
|
||||
control->flags |= FLAG_ZLIB_COMPRESS;
|
||||
else if (isparameter(parametervalue, "lzo"))
|
||||
control->flags |= FLAG_LZO_COMPRESS;
|
||||
else if (isparameter(parametervalue, "rzip"))
|
||||
control->flags |= FLAG_NO_COMPRESS;
|
||||
else if (isparameter(parametervalue, "zpaq"))
|
||||
control->flags |= FLAG_ZPAQ_COMPRESS;
|
||||
else if (!isparameter(parametervalue, "lzma")) /* oops, not lzma! */
|
||||
failure(control, "CONF.FILE error. Invalid compression method %s specified\n",parametervalue);
|
||||
} else if (isparameter(parameter, "lzotest")) {
|
||||
/* default is yes */
|
||||
if (isparameter(parametervalue, "no"))
|
||||
control->flags &= ~FLAG_THRESHOLD;
|
||||
} else if (isparameter(parameter, "hashcheck")) {
|
||||
if (isparameter(parametervalue, "yes")) {
|
||||
control->flags |= FLAG_CHECK;
|
||||
control->flags |= FLAG_HASH;
|
||||
}
|
||||
} else if (isparameter(parameter, "showhash")) {
|
||||
if (isparameter(parametervalue, "yes"))
|
||||
control->flags |= FLAG_HASH;
|
||||
} else if (isparameter(parameter, "outputdirectory")) {
|
||||
control->outdir = malloc(strlen(parametervalue) + 2);
|
||||
if (!control->outdir)
|
||||
fatal(control, "Fatal Memory Error in read_config");
|
||||
strcpy(control->outdir, parametervalue);
|
||||
if (strcmp(parametervalue + strlen(parametervalue) - 1, "/"))
|
||||
strcat(control->outdir, "/");
|
||||
} else if (isparameter(parameter,"verbosity")) {
|
||||
if (control->flags & FLAG_VERBOSE)
|
||||
failure(control, "CONF.FILE error. Verbosity already defined.");
|
||||
if (isparameter(parametervalue, "yes"))
|
||||
control->flags |= FLAG_VERBOSITY;
|
||||
else if (isparameter(parametervalue,"max"))
|
||||
control->flags |= FLAG_VERBOSITY_MAX;
|
||||
else /* oops, unrecognized value */
|
||||
print_err("lrzip.conf: Unrecognized verbosity value %s. Ignored.\n", parametervalue);
|
||||
} else if (isparameter(parameter, "showprogress")) {
|
||||
/* Yes by default */
|
||||
if (isparameter(parametervalue, "NO"))
|
||||
control->flags &= ~FLAG_SHOW_PROGRESS;
|
||||
} else if (isparameter(parameter,"nice")) {
|
||||
control->nice_val = atoi(parametervalue);
|
||||
if (control->nice_val < -20 || control->nice_val > 19)
|
||||
failure(control, "CONF.FILE error. Nice must be between -20 and 19");
|
||||
} else if (isparameter(parameter, "keepbroken")) {
|
||||
if (isparameter(parametervalue, "yes" ))
|
||||
control->flags |= FLAG_KEEP_BROKEN;
|
||||
} else if (iscaseparameter(parameter, "DELETEFILES")) {
|
||||
/* delete files must be case sensitive */
|
||||
if (iscaseparameter(parametervalue, "YES"))
|
||||
control->flags &= ~FLAG_KEEP_FILES;
|
||||
} else if (iscaseparameter(parameter, "REPLACEFILE")) {
|
||||
/* replace lrzip file must be case sensitive */
|
||||
if (iscaseparameter(parametervalue, "YES"))
|
||||
control->flags |= FLAG_FORCE_REPLACE;
|
||||
} else if (isparameter(parameter, "tmpdir")) {
|
||||
control->tmpdir = realloc(NULL, strlen(parametervalue) + 2);
|
||||
if (!control->tmpdir)
|
||||
fatal(control, "Fatal Memory Error in read_config");
|
||||
strcpy(control->tmpdir, parametervalue);
|
||||
if (strcmp(parametervalue + strlen(parametervalue) - 1, "/"))
|
||||
strcat(control->tmpdir, "/");
|
||||
} else if (isparameter(parameter, "encrypt")) {
|
||||
if (isparameter(parameter, "YES"))
|
||||
control->flags |= FLAG_ENCRYPT;
|
||||
} else
|
||||
/* oops, we have an invalid parameter, display */
|
||||
print_err("lrzip.conf: Unrecognized parameter value, %s = %s. Continuing.\n",\
|
||||
parameter, parametervalue);
|
||||
}
|
||||
|
||||
if (unlikely(fclose(fp)))
|
||||
fatal(control, "Failed to fclose fp in read_config\n");
|
||||
out:
|
||||
/* clean up */
|
||||
free(line);
|
||||
free(homeconf);
|
||||
|
||||
/* fprintf(stderr, "\nWindow = %d \
|
||||
\nCompression Level = %d \
|
||||
\nThreshold = %1.2f \
|
||||
\nOutput Directory = %s \
|
||||
\nFlags = %d\n", control->window,control->compression_level, control->threshold, control->outdir, control->flags);
|
||||
*/
|
||||
}
|
||||
|
||||
static void xor128 (void *pa, const void *pb)
|
||||
{
|
||||
i64 *a = pa;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue