mirror of
https://github.com/ckolivas/lrzip.git
synced 2026-04-05 06:15:28 +00:00
header-mangling-part-1-move-functions-out-of-headers
This commit is contained in:
parent
f6f0a25ef6
commit
e5dfd2d9d8
5 changed files with 324 additions and 313 deletions
200
main.c
200
main.c
|
|
@ -19,6 +19,7 @@
|
|||
/* lrzip compression - main program */
|
||||
#define MAIN_C
|
||||
#include "rzip.h"
|
||||
|
||||
/* main() defines, different from liblrzip defines */
|
||||
#define FLAG_VERBOSE (FLAG_VERBOSITY | FLAG_VERBOSITY_MAX)
|
||||
#define FLAG_NOT_LZMA (FLAG_NO_COMPRESS | FLAG_LZO_COMPRESS | FLAG_BZIP2_COMPRESS | FLAG_ZLIB_COMPRESS | FLAG_ZPAQ_COMPRESS)
|
||||
|
|
@ -67,7 +68,50 @@
|
|||
print_output(format, ##args); \
|
||||
} while (0)
|
||||
|
||||
struct rzip_control control;
|
||||
rzip_control control;
|
||||
|
||||
#ifdef __APPLE__
|
||||
# include <sys/sysctl.h>
|
||||
static inline i64 get_ram(void)
|
||||
{
|
||||
int mib[2];
|
||||
size_t len;
|
||||
i64 *p, ramsize;
|
||||
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_MEMSIZE;
|
||||
sysctl(mib, 2, NULL, &len, NULL, 0);
|
||||
p = malloc(len);
|
||||
sysctl(mib, 2, p, &len, NULL, 0);
|
||||
ramsize = *p;
|
||||
|
||||
return ramsize;
|
||||
}
|
||||
#else /* __APPLE__ */
|
||||
static inline i64 get_ram(void)
|
||||
{
|
||||
i64 ramsize;
|
||||
FILE *meminfo;
|
||||
char aux[256];
|
||||
char *ignore;
|
||||
|
||||
ramsize = (i64)sysconf(_SC_PHYS_PAGES) * PAGE_SIZE;
|
||||
if (ramsize > 0)
|
||||
return ramsize;
|
||||
|
||||
/* Workaround for uclibc which doesn't properly support sysconf */
|
||||
if(!(meminfo = fopen("/proc/meminfo", "r")))
|
||||
fatal("fopen\n");
|
||||
|
||||
while(!feof(meminfo) && !fscanf(meminfo, "MemTotal: %Lu kB", &ramsize))
|
||||
ignore = fgets(aux, sizeof(aux), meminfo);
|
||||
if (fclose(meminfo) == -1)
|
||||
fatal("fclose");
|
||||
ramsize *= 1000;
|
||||
|
||||
return ramsize;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
|
|
@ -114,6 +158,7 @@ static void usage(void)
|
|||
|
||||
}
|
||||
|
||||
|
||||
static void show_summary(void)
|
||||
{
|
||||
/* OK, if verbosity set, print summary of options selected */
|
||||
|
|
@ -179,6 +224,159 @@ static void show_summary(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void read_config( struct rzip_control *control )
|
||||
{
|
||||
/* check for lrzip.conf in ., $HOME/.lrzip and /etc/lrzip */
|
||||
|
||||
FILE *fp;
|
||||
char *parameter;
|
||||
char *parametervalue;
|
||||
char *line, *s;
|
||||
char *HOME, *homeconf;
|
||||
|
||||
line = malloc(255);
|
||||
homeconf = malloc(255);
|
||||
if (line == NULL || homeconf == NULL)
|
||||
fatal("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)
|
||||
return;
|
||||
|
||||
/* if we get here, we have a file. read until no more. */
|
||||
|
||||
while ((s = 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("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("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("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("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("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("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("Fatal Memory Error in read_config");
|
||||
strcpy(control->tmpdir, parametervalue);
|
||||
if (strcmp(parametervalue + strlen(parametervalue) - 1, "/"))
|
||||
strcat(control->tmpdir, "/");
|
||||
} else
|
||||
/* oops, we have an invalid parameter, display */
|
||||
print_err("lrzip.conf: Unrecognized parameter value, %s = %s. Continuing.\n",\
|
||||
parameter, parametervalue);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
*/
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct timeval start_time, end_time;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue