summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2013-05-19 23:54:33 +0200
committerportix <portix@gmx.net>2013-05-19 23:54:33 +0200
commit0a888d838e370623d7d741f72b3b5c4022bca7fa (patch)
treebb9584c86ee210b7454c32b24aee02ec0101453b
parent8e8577f02d8c577adb93d3b7b6473bfa8525d940 (diff)
downloaddwb-0a888d838e370623d7d741f72b3b5c4022bca7fa.zip
Remove exar_cat
-rw-r--r--dwbem/dwbem.c10
-rw-r--r--exar/exar.c98
-rw-r--r--exar/exar.h18
-rw-r--r--exar/main.c10
-rw-r--r--src/dwb.c2
5 files changed, 32 insertions, 106 deletions
diff --git a/dwbem/dwbem.c b/dwbem/dwbem.c
index 93cc02e1..10e9abcc 100644
--- a/dwbem/dwbem.c
+++ b/dwbem/dwbem.c
@@ -67,7 +67,6 @@ enum {
EXAR_FLAG_V = 1<<0,
EXAR_FLAG_P = 1<<3,
EXAR_FLAG_U = 1<<4,
- EXAR_FLAG_C = 1<<5,
EXAR_FLAG_E = 1<<6,
EXAR_FLAG_D = 1<<7,
EXAR_FLAG_I = 1<<8,
@@ -1170,8 +1169,6 @@ exar_help(int ret)
" dwbem --archive option [arguments]\n\n"
"OPTIONS:\n"
" h Print this help and exit.\n"
- " c[v] archive file Concatenates a file, directory or archive to \n"
- " an existing archive.\n"
" d[v] archive file Deletes a file from an archive, the file path is the\n"
" relative file path of the file in the archive\n"
" e[v] archive file Extracts a file from an archive and writes the content\n"
@@ -1188,8 +1185,6 @@ exar_help(int ret)
" get more verbose messages.\n\n"
"EXAMPLES:\n"
" dwbem --archive p /tmp/foo -- pack /tmp/foo to foo.exar\n"
- " dwbem --archive c foo.exar bar.txt -- Concatenates bar.txt to archive foo.exar\n"
- " dwbem --archive c foo.exar bar.exar -- Concatenates archive bar.exar to archive foo.exar\n"
" dwbem --archive s foo.js > foo.js -- Extract foo.js from the archive\n"
" dwbem --archive uvvv foo.exar -- unpack foo.exar to current directory,\n"
" verbosity level 3\n"
@@ -1232,9 +1227,6 @@ parse_exar_options(char **argv)
case 'u' :
flag |= EXAR_FLAG_U;
break;
- case 'c' :
- flag |= EXAR_FLAG_C;
- break;
case 'e' :
flag |= EXAR_FLAG_E;
break;
@@ -1266,8 +1258,6 @@ parse_exar_options(char **argv)
exar_pack(argv[1]);
else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_I))
exar_info(argv[1]);
- else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_C) && argc > 2)
- exar_cat(argv[1], argv[2]);
else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_D) && argc > 2)
exar_delete(argv[1], argv[2]);
else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_E) && argc > 2)
diff --git a/exar/exar.c b/exar/exar.c
index 407c60ed..0e466934 100644
--- a/exar/exar.c
+++ b/exar/exar.c
@@ -36,7 +36,7 @@
#define SZ_VERSION 8
#define SZ_DFLAG 1
-#define SZ_NAME 108
+#define SZ_NAME 100
#define SZ_SIZE 12
#define SZ_CHKSUM 7
@@ -102,9 +102,14 @@ check_version(FILE *f, int verbose)
LOG(2, "Reading version header\n");
if (fread(version, 1, SZ_VERSION, f) != SZ_VERSION)
{
- if (verbose)
- fprintf(stderr, "Not an exar file?\n");
- return -1;
+ if (feof(f))
+ return 0;
+ else
+ {
+ if (verbose)
+ fprintf(stderr, "Not an exar file?\n");
+ return -1;
+ }
}
memcpy(orig_version, EXAR_VERSION, sizeof(orig_version));
LOG(2, "Checking filetype\n");
@@ -142,7 +147,7 @@ write_version_header(FILE *f)
* Opens archive and checks version, mode is either read or read-write
* */
static FILE *
-open_archive(const char *path, const char *mode, int *ret_version_check, int verbose)
+open_archive(const char *path, const char *mode)
{
FILE *f = NULL;
LOG(3, "Opening %s for %s\n", path, strcmp(mode, "r") == 0 ? "reading" : "reading and writing");
@@ -151,7 +156,6 @@ open_archive(const char *path, const char *mode, int *ret_version_check, int ver
perror(path);
return NULL;
}
- *ret_version_check = check_version(f, verbose);
return f;
}
static void
@@ -184,6 +188,10 @@ get_file_header(FILE *f, char *name, char *flag, size_t *size)
size_t fs;
int chksum, fsum = 0;
*size = 0;
+
+ if (check_version(f, 1) != 0)
+ return -1;
+
LOG(2, "Reading file header\n");
if (fread(header, 1, HDR_END, f) != HDR_END)
return -1;
@@ -237,11 +245,10 @@ extract(const char *archive, const char *file, size_t *s, int (*cmp)(const char
size_t fs = 0;
FILE *f = NULL;
unsigned char *ret = NULL;
- int vers_check = -1;
if (s != NULL)
*s = 0;
- if ((f = open_archive(archive, "r", &vers_check, 1)) == NULL || vers_check != 0)
+ if ((f = open_archive(archive, "r")) == NULL)
goto finish;
while (get_file_header(f, name, &flag, &fs) == 0)
{
@@ -286,6 +293,8 @@ write_file_header(FILE *f, const char *name, char flag, size_t r)
int chksum;
LOG(2, "Writing file header for %s\n", name);
+ if (write_version_header(f) != 0)
+ return -1;
memset(buffer, 0, sizeof(buffer));
strncpy(buffer + HDR_NAME, name, SZ_NAME);
@@ -372,9 +381,6 @@ exar_pack(const char *path)
return -1;
}
- if (write_version_header(s_out) != 0)
- return -1;
-
ret = ftw(path, pack, MAX_FILE_HANDLES);
LOG(3, "Closing %s\n", buffer);
@@ -391,12 +397,11 @@ exar_unpack(const char *archive, const char *dest)
char name[SZ_NAME], flag;
size_t fs = 0;
FILE *of, *f = NULL;
- int vers_check = 1;
unsigned char buf[512];
size_t r = 0;
- f = open_archive(archive, "r", &vers_check, 1);
- if (f == NULL || vers_check == -1)
+ f = open_archive(archive, "r");
+ if (f == NULL)
goto finish;
if (dest != NULL)
@@ -451,52 +456,6 @@ finish:
close_file(f, archive);
return ret;
}
-int
-exar_cat(const char *file1, const char *file2)
-{
- assert(file1 != NULL && file2 != NULL);
-
- int ret = -1;
- size_t r;
- FILE *f1 = NULL, *f2 = NULL;
- unsigned char buffer[64];
- char offset_buffer[512];
- int vers_check = -1;
-
- LOG(3, "Opening file %s for writing\n", file1);
- if ((f1 = fopen(file1, "a")) == NULL)
- {
- perror(file1);
- goto finish;
- }
- if ((f2 = open_archive(file2, "r", &vers_check, 0)) == NULL)
- goto finish;
-
- if (vers_check == 0)
- {
- LOG(1, "Concatenating archive\n");
- while ((r = fread(buffer, 1, sizeof(buffer), f2)) > 0)
- {
- if (fwrite(buffer, 1, r, f1) != r)
- {
- fprintf(stderr, "Failed to write %zu bytes\n", r);
- goto finish;
- }
- }
- }
- else
- {
- s_offset = get_offset(offset_buffer, sizeof(offset_buffer), file2, NULL);
- LOG(1, "Concatenating regular files\n");
- s_out = f1;
- ftw(file2, pack, MAX_FILE_HANDLES);
- }
- ret = 0;
-finish:
- close_file(f1, file1);
- close_file(f2, file2);
- return ret;
-}
unsigned char *
exar_extract(const char *archive, const char *file, size_t *s)
@@ -521,13 +480,12 @@ exar_delete(const char *archive, const char *file)
char name[SZ_NAME] = {0}, flag = 0;
size_t fs = 0;
FILE *f = NULL, *ftmp = NULL;
- int vers_check;
char tmp_file[128];
char dir_name[SZ_NAME + 1] = {0};
unsigned char rbuf;
size_t dir_length = 0;
- if ((f = open_archive(archive, "r", &vers_check, 1)) == NULL || vers_check != 0)
+ if ((f = open_archive(archive, "r")) == NULL)
goto finish;
snprintf(tmp_file, sizeof(tmp_file), "%s.XXXXXX", archive);
@@ -540,8 +498,6 @@ exar_delete(const char *archive, const char *file)
LOG(3, "Opening %s for writing\n", tmp_file);
if ((ftmp = fopen(tmp_file, "w")) == NULL)
goto finish;
- if (write_version_header(ftmp) != 0)
- goto finish;
while (get_file_header(f, name, &flag, &fs) == 0)
{
@@ -594,9 +550,8 @@ exar_info(const char *archive)
FILE *f = NULL;
char name[SZ_NAME], flag;
size_t fs;
- int vers_check;
- if ((f = open_archive(archive, "r", &vers_check, 1)) == NULL || vers_check != 0)
+ if ((f = open_archive(archive, "r")) == NULL)
goto finish;
while(get_file_header(f, name, &flag, &fs) == 0)
{
@@ -609,14 +564,15 @@ finish:
}
int
-exar_check_version(const char *archive, int verbose)
+exar_check_version(const char *archive)
{
assert(archive != NULL);
-
- int vers_check;
- FILE *f = open_archive(archive, "r", &vers_check, verbose);
+ int result = -1;
+ FILE *f;
+ if ( (f = fopen(archive, "r")) != NULL && check_version(f, 0))
+ result = 0;
close_file(f, archive);
- return vers_check;
+ return result;
}
void
exar_verbose(unsigned char v)
diff --git a/exar/exar.h b/exar/exar.h
index 52b9655e..ca061761 100644
--- a/exar/exar.h
+++ b/exar/exar.h
@@ -25,11 +25,11 @@
*
* File format:
*
- * [version header][file header][file][file header][file][file header...
+ * [version header][file header][file][version header][file header][file][version ...
*
- * version header : 8 bytes
* file header : 128 bytes
- * - filename : 108 bytes, (char*)
+ * - version : 8 bytes
+ * - filename : 100 bytes, (char*)
* - directory flag(d|f) : 1 byte (char)
* - file size : 12 bytes (char*, octal representation)
* - checksum: : 7 bytes (char*, octal representation)
@@ -65,16 +65,6 @@ int
exar_unpack(const char *path, const char *dest);
/*
- * Concatenates two archives or an archive and a file or directory
- * @file1: The archive to append
- * @file2: The archive, file or directory that will be appended
- *
- * @returns 0 on success and -1 on error
- * */
-int
-exar_cat(const char *file1, const char *file2);
-
-/*
* Extracts a file from an extension archive
* @archive The archive
* @file The path of the file in the archive
@@ -121,7 +111,7 @@ exar_delete(const char *archive, const char *file);
* @returns 0 on success and -1 on error
*/
int
-exar_check_version(const char *archive, int verbose);
+exar_check_version(const char *archive);
/*
* Print info about the archive to stdout.
diff --git a/exar/main.c b/exar/main.c
index c401c4ec..57c13f75 100644
--- a/exar/main.c
+++ b/exar/main.c
@@ -24,7 +24,6 @@ enum {
EXAR_FLAG_V = 1<<0,
EXAR_FLAG_P = 1<<3,
EXAR_FLAG_U = 1<<4,
- EXAR_FLAG_C = 1<<5,
EXAR_FLAG_E = 1<<6,
EXAR_FLAG_D = 1<<7,
EXAR_FLAG_I = 1<<8,
@@ -47,8 +46,6 @@ help(int ret)
" exar option [arguments]\n\n"
"OPTIONS:\n"
" h Print this help and exit.\n"
- " c[v] archive file Concatenates a file, directory or archive to \n"
- " an existing archive.\n"
" d[v] archive file Deletes a file from an archive, the file path is the\n"
" relative file path of the file in the archive\n"
" e[v] archive file Extracts a file from an archive and writes the content\n"
@@ -65,8 +62,6 @@ help(int ret)
" get more verbose messages.\n\n"
"EXAMPLES:\n"
" exar p /tmp/foo -- pack /tmp/foo to foo.exar\n"
- " exar c foo.exar bar.txt -- Concatenates bar.txt to archive foo.exar\n"
- " exar c foo.exar bar.exar -- Concatenates archive bar.exar to archive foo.exar\n"
" exar s foo.js > foo.js -- Extract foo.js from the archive\n"
" exar uvvv foo.exar -- unpack foo.exar to current directory,\n"
" verbosity level 3\n"
@@ -105,9 +100,6 @@ main (int argc, char **argv)
case 'u' :
flag |= EXAR_FLAG_U;
break;
- case 'c' :
- flag |= EXAR_FLAG_C;
- break;
case 'e' :
flag |= EXAR_FLAG_E;
break;
@@ -139,8 +131,6 @@ main (int argc, char **argv)
exar_pack(argv[2]);
else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_I))
exar_info(argv[2]);
- else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_C) && argc > 3)
- exar_cat(argv[2], argv[3]);
else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_D) && argc > 3)
exar_delete(argv[2], argv[3]);
else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_E) && argc > 3)
diff --git a/src/dwb.c b/src/dwb.c
index 6ae0327a..0c77590e 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -3441,7 +3441,7 @@ dwb_get_scripts()
}
if (dwb.misc.js_api != JS_API_DISABLED)
{
- if (exar_check_version(path, 0) == 0)
+ if (exar_check_version(path) == 0)
{
content = (char *) exar_search_extract(path, "main.js", NULL);
if (content != NULL)