diff options
Diffstat (limited to 'src/tools/split.c')
-rw-r--r-- | src/tools/split.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/tools/split.c b/src/tools/split.c index 4e3d93c8bb8..302bc6d8d7f 100644 --- a/src/tools/split.c +++ b/src/tools/split.c @@ -13,7 +13,6 @@ #include <string.h> #include <ctype.h> #include <assert.h> -#include "astring.h" #include "corefile.h" #include "corestr.h" #include "sha1.h" @@ -33,7 +32,7 @@ hash over a buffer and return a string -------------------------------------------------*/ -static void compute_hash_as_string(astring &buffer, void *data, UINT32 length) +static void compute_hash_as_string(std::string &buffer, void *data, UINT32 length) { char expanded[SHA1_DIGEST_SIZE * 2]; UINT8 sha1digest[SHA1_DIGEST_SIZE]; @@ -54,7 +53,7 @@ static void compute_hash_as_string(astring &buffer, void *data, UINT32 length) } // copy it to the buffer - buffer.cpy(expanded, sizeof(expanded)); + buffer.assign(expanded, sizeof(expanded)); } @@ -64,9 +63,9 @@ static void compute_hash_as_string(astring &buffer, void *data, UINT32 length) static int split_file(const char *filename, const char *basename, UINT32 splitsize) { - astring outfilename, basefilename, splitfilename; + std::string outfilename, basefilename, splitfilename; core_file *outfile = NULL, *infile = NULL, *splitfile = NULL; - astring computedhash; + std::string computedhash; void *splitbuffer = NULL; int index, partnum; UINT64 totallength; @@ -111,13 +110,13 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi } // find the base name of the file - basefilename.cpy(basename); - index = basefilename.rchr(0, PATH_SEPARATOR[0]); + basefilename.assign(basename); + index = basefilename.find_last_of(PATH_SEPARATOR[0]); if (index != -1) - basefilename.del(0, index + 1); + basefilename.erase(0, index + 1); // compute the split filename - splitfilename.cpy(basename).cat(".split"); + splitfilename.assign(basename).append(".split"); // create the split file filerr = core_fopen(splitfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &splitfile); @@ -153,7 +152,7 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi core_fprintf(splitfile, "hash=%s file=%s.%03d\n", computedhash.c_str(), basefilename.c_str(), partnum); // compute the full filename for this guy - outfilename.printf("%s.%03d", basename, partnum); + strprintf(outfilename,"%s.%03d", basename, partnum); // create it filerr = core_fopen(outfilename.c_str(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile); @@ -216,9 +215,9 @@ cleanup: static int join_file(const char *filename, const char *outname, int write_output) { - astring expectedhash, computedhash; - astring outfilename, infilename; - astring basepath; + std::string expectedhash, computedhash; + std::string outfilename, infilename; + std::string basepath; core_file *outfile = NULL, *infile = NULL, *splitfile = NULL; void *splitbuffer = NULL; file_error filerr; @@ -241,21 +240,22 @@ static int join_file(const char *filename, const char *outname, int write_output fprintf(stderr, "Fatal error: corrupt or incomplete split file at line:\n%s\n", buffer); goto cleanup; } - outfilename.cpy(buffer + 10).trimspace(); + outfilename.assign(buffer + 10); + strtrimspace(outfilename); // compute the base path - basepath.cpy(filename); - index = basepath.rchr(0, PATH_SEPARATOR[0]); + basepath.assign(filename); + index = basepath.find_last_of(PATH_SEPARATOR[0]); if (index != -1) - basepath.del(index + 1); + basepath.erase(index + 1); else - basepath.reset(); + basepath.clear(); // override the output filename if specified, otherwise prepend the path if (outname != NULL) - outfilename.cpy(outname); + outfilename.assign(outname); else - outfilename.ins(0, basepath); + outfilename.insert(0, basepath); // read the split size if (!core_fgets(buffer, sizeof(buffer), splitfile) || sscanf(buffer, "splitsize=%d", &splitsize) != 1) @@ -299,13 +299,14 @@ static int join_file(const char *filename, const char *outname, int write_output fprintf(stderr, "Fatal error: corrupt or incomplete split file at line:\n%s\n", buffer); goto cleanup; } - expectedhash.cpy(buffer + 5, SHA1_DIGEST_SIZE * 2); - infilename.cpy(buffer + 5 + SHA1_DIGEST_SIZE * 2 + 6).trimspace(); + expectedhash.assign(buffer + 5, SHA1_DIGEST_SIZE * 2); + infilename.assign(buffer + 5 + SHA1_DIGEST_SIZE * 2 + 6); + strtrimspace(infilename); printf(" Reading file '%s'...", infilename.c_str()); // read the file's contents - infilename.ins(0, basepath); + infilename.insert(0, basepath); filerr = core_fload(infilename.c_str(), &splitbuffer, &length); if (filerr != FILERR_NONE) { @@ -318,7 +319,7 @@ static int join_file(const char *filename, const char *outname, int write_output compute_hash_as_string(computedhash, splitbuffer, length); // compare - if (computedhash != expectedhash) + if (computedhash.compare(expectedhash)!=0) { printf("\n"); fprintf(stderr, "Fatal error: file '%s' has incorrect hash\n Expected: %s\n Computed: %s\n", infilename.c_str(), expectedhash.c_str(), computedhash.c_str()); |