Removed old C-based interface to astrings. astring exists only as

a class now. Updated all stragglers (mostly tools) to use the class
form. [Aaron Giles]
This commit is contained in:
Aaron Giles 2012-01-03 00:21:13 +00:00
parent 8b492b8d80
commit 64f1231c63
27 changed files with 1069 additions and 1831 deletions

View File

@ -57,45 +57,41 @@
TYPE DEFINITIONS
***************************************************************************/
typedef struct _include_path include_path;
struct _include_path
struct include_path
{
include_path * next;
const astring * path;
astring path;
};
typedef struct _exclude_path exclude_path;
struct _exclude_path
struct exclude_path
{
exclude_path * next;
const astring * path;
astring path;
int pathlen;
UINT8 recursive;
};
typedef struct _list_entry list_entry;
struct _list_entry
struct list_entry
{
list_entry * next;
const astring * name;
astring name;
};
typedef struct _file_entry file_entry;
struct file_entry;
typedef struct _dependency dependency;
struct _dependency
struct dependency
{
dependency * next;
file_entry * file;
};
struct _file_entry
struct file_entry
{
astring * name;
astring name;
dependency * deplist;
};
@ -107,7 +103,7 @@ struct _file_entry
static include_path *incpaths;
static exclude_path *excpaths;
static tagmap *file_map;
static tagmap_t<file_entry *> file_map;
@ -115,25 +111,12 @@ static tagmap *file_map;
PROTOTYPES
***************************************************************************/
/* core output functions */
static int recurse_dir(int srcrootlen, const astring *srcdir);
static file_entry *compute_dependencies(int srcrootlen, const astring *srcfile);
// core output functions
static int recurse_dir(int srcrootlen, astring &srcdir);
static file_entry &compute_dependencies(int srcrootlen, astring &srcfile);
/* path helpers */
static astring *find_include_file(int srcrootlen, const astring *srcfile, const astring *filename);
/***************************************************************************
INLINE FUNCTIONS
***************************************************************************/
/* core output functions */
static int recurse_dir(int srcrootlen, const astring *srcdir);
static file_entry *compute_dependencies(int srcrootlen, const astring *srcfile);
/* path helpers */
static astring *find_include_file(int srcrootlen, const astring *srcfile, const astring *filename);
// path helpers
static bool find_include_file(astring &srcincpath, int srcrootlen, const astring &srcfile, const astring &filename);
@ -145,82 +128,66 @@ static astring *find_include_file(int srcrootlen, const astring *srcfile, const
main - main entry point
-------------------------------------------------*/
void usage(const char *argv0)
{
fprintf(stderr, "Usage:\n%s <srcroot> [-Iincpath [-Iincpath [...]]]\n", argv0);
exit(1);
}
int main(int argc, char *argv[])
{
include_path **incpathhead = &incpaths;
exclude_path **excpathhead = &excpaths;
astring *srcdir = NULL;
astring srcdir;
int unadorned = 0;
int result;
int argnum;
/* loop over arguments */
for (argnum = 1; argnum < argc; argnum++)
// loop over arguments
for (int argnum = 1; argnum < argc; argnum++)
{
char *arg = argv[argnum];
/* include path? */
// include path?
if (arg[0] == '-' && arg[1] == 'I')
{
*incpathhead = (include_path *)malloc(sizeof(**incpathhead));
if (*incpathhead != NULL)
{
(*incpathhead)->next = NULL;
(*incpathhead)->path = astring_replacechr(astring_dupc(&arg[2]), '/', PATH_SEPARATOR[0]);
incpathhead = &(*incpathhead)->next;
}
*incpathhead = new include_path;
(*incpathhead)->next = NULL;
(*incpathhead)->path.cpy(&arg[2]).replacechr('/', PATH_SEPARATOR[0]);
incpathhead = &(*incpathhead)->next;
}
/* exclude path? */
// exclude path?
else if (arg[0] == '-' && arg[1] == 'X')
{
*excpathhead = (exclude_path *)malloc(sizeof(**excpathhead));
if (*excpathhead != NULL)
{
astring *path;
(*excpathhead)->next = NULL;
path = astring_replacechr(astring_dupc(&arg[2]), PATH_SEPARATOR[0], '/');
(*excpathhead)->recursive = (astring_replacec(path, astring_len(path) - 4, "/...", "") != 0);
(*excpathhead)->path = path;
(*excpathhead)->pathlen = astring_len(path);
excpathhead = &(*excpathhead)->next;
}
*excpathhead = new exclude_path;
(*excpathhead)->next = NULL;
(*excpathhead)->path.cpy(&arg[2]).replacechr(PATH_SEPARATOR[0], '/');
(*excpathhead)->recursive = ((*excpathhead)->path.replace((*excpathhead)->path.len() - 4, "/...", "") != 0);
(*excpathhead)->pathlen = (*excpathhead)->path.len();
excpathhead = &(*excpathhead)->next;
}
/* ignore -include which is used by sdlmame to include sdlprefix.h before all other includes */
// ignore -include which is used by sdlmame to include sdlprefix.h before all other includes
else if (strcmp(arg,"-include") == 0)
{
argnum++;
}
/* other parameter */
// other parameter
else if (arg[0] != '-' && unadorned == 0)
{
srcdir = astring_replacechr(astring_dupc(arg), '/', PATH_SEPARATOR[0]);
srcdir.cpy(arg).replacechr('/', PATH_SEPARATOR[0]);
unadorned++;
}
else
goto usage;
usage(argv[0]);
}
/* make sure we got 1 parameter */
if (srcdir == NULL)
goto usage;
// make sure we got 1 parameter
if (srcdir.len() == 0)
usage(argv[0]);
/* create a tagmap for tracking files we've visited */
file_map = tagmap_alloc();
/* recurse over subdirectories */
result = recurse_dir(astring_len(srcdir), srcdir);
/* free source and destination directories */
tagmap_free(file_map);
astring_free(srcdir);
return result;
usage:
fprintf(stderr, "Usage:\n%s <srcroot> [-Iincpath [-Iincpath [...]]]\n", argv[0]);
return 1;
// recurse over subdirectories
return recurse_dir(srcdir.len(), srcdir);
}
@ -233,7 +200,7 @@ static int compare_list_entries(const void *p1, const void *p2)
{
const list_entry *entry1 = *(const list_entry **)p1;
const list_entry *entry2 = *(const list_entry **)p2;
return strcmp(astring_c(entry1->name), astring_c(entry2->name));
return entry1->name.cmp(entry2->name);
}
@ -243,25 +210,22 @@ static int compare_list_entries(const void *p1, const void *p2)
unless we already exist in the map
-------------------------------------------------*/
static void recurse_dependencies(file_entry *file, tagmap *map)
static void recurse_dependencies(file_entry &file, tagmap_t<astring *> &map)
{
int filelen = astring_len(file->name);
exclude_path *exclude;
dependency *dep;
/* skip if we're in an exclude path */
for (exclude = excpaths; exclude != NULL; exclude = exclude->next)
if (exclude->pathlen < filelen && strncmp(astring_c(file->name), astring_c(exclude->path), exclude->pathlen) == 0)
if (exclude->recursive || astring_chr(file->name, exclude->pathlen + 1, '/') == -1)
// skip if we're in an exclude path
int filelen = file.name.len();
for (exclude_path *exclude = excpaths; exclude != NULL; exclude = exclude->next)
if (exclude->pathlen < filelen && strncmp(file.name, exclude->path, exclude->pathlen) == 0)
if (exclude->recursive || file.name.chr(exclude->pathlen + 1, '/') == -1)
return;
/* attempt to add; if we get an error, we're already present */
if (tagmap_add(map, astring_c(file->name), file->name, FALSE) != TMERR_NONE)
// attempt to add; if we get an error, we're already present
if (map.add(file.name, &file.name) != TMERR_NONE)
return;
/* recurse the list from there */
for (dep = file->deplist; dep != NULL; dep = dep->next)
recurse_dependencies(dep->file, map);
// recurse the list from there
for (dependency *dep = file.deplist; dep != NULL; dep = dep->next)
recurse_dependencies(*dep->file, map);
}
@ -269,122 +233,106 @@ static void recurse_dependencies(file_entry *file, tagmap *map)
recurse_dir - recurse through a directory
-------------------------------------------------*/
static int recurse_dir(int srcrootlen, const astring *srcdir)
static int recurse_dir(int srcrootlen, astring &srcdir)
{
static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE };
int result = 0;
int entindex;
/* iterate first over directories, then over files */
for (entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++)
// iterate first over directories, then over files
for (int entindex = 0; entindex < ARRAY_LENGTH(typelist) && result == 0; entindex++)
{
osd_dir_entry_type entry_type = typelist[entindex];
const osd_directory_entry *entry;
list_entry **listarray = NULL;
list_entry *list = NULL;
list_entry *curlist;
osd_directory *dir;
int found = 0;
/* open the directory and iterate through it */
dir = osd_opendir(astring_c(srcdir));
// open the directory and iterate through it
osd_directory *dir = osd_opendir(srcdir);
if (dir == NULL)
{
result = 1;
goto error;
}
/* build up the list of files */
// build up the list of files
const osd_directory_entry *entry;
list_entry *list = NULL;
int found = 0;
while ((entry = osd_readdir(dir)) != NULL)
if (entry->type == entry_type && entry->name[0] != '.')
{
list_entry *lentry = (list_entry *)malloc(sizeof(*lentry));
lentry->name = astring_dupc(entry->name);
list_entry *lentry = new list_entry;
lentry->name.cpy(entry->name);
lentry->next = list;
list = lentry;
found++;
}
/* close the directory */
// close the directory
osd_closedir(dir);
/* skip if nothing found */
// skip if nothing found
if (found == 0)
continue;
/* allocate memory for sorting */
listarray = (list_entry **)malloc(sizeof(list_entry *) * found);
// allocate memory for sorting
list_entry **listarray = new list_entry *[found];
found = 0;
for (curlist = list; curlist != NULL; curlist = curlist->next)
for (list_entry *curlist = list; curlist != NULL; curlist = curlist->next)
listarray[found++] = curlist;
/* sort the list */
// sort the list
qsort(listarray, found, sizeof(listarray[0]), compare_list_entries);
/* rebuild the list */
// rebuild the list
list = NULL;
while (--found >= 0)
{
listarray[found]->next = list;
list = listarray[found];
}
free(listarray);
delete[] listarray;
/* iterate through each file */
for (curlist = list; curlist != NULL && result == 0; curlist = curlist->next)
// iterate through each file
for (list_entry *curlist = list; curlist != NULL && result == 0; curlist = curlist->next)
{
astring *srcfile;
astring srcfile;
/* build the source filename */
srcfile = astring_alloc();
astring_printf(srcfile, "%s%c%s", astring_c(srcdir), PATH_SEPARATOR[0], astring_c(curlist->name));
// build the source filename
srcfile.printf("%s%c%s", srcdir.cstr(), PATH_SEPARATOR[0], curlist->name.cstr());
/* if we have a file, output it */
// if we have a file, output it
if (entry_type == ENTTYPE_FILE)
{
/* make sure we care, first */
if (core_filename_ends_with(astring_c(curlist->name), ".c"))
// make sure we care, first
if (core_filename_ends_with(curlist->name, ".c"))
{
tagmap *depend_map = tagmap_alloc();
tagmap_entry *map_entry;
file_entry *file;
astring *target;
int taghash;
tagmap_t<astring *> depend_map;
/* find dependencies */
file = compute_dependencies(srcrootlen, srcfile);
// find dependencies
file_entry &file = compute_dependencies(srcrootlen, srcfile);
recurse_dependencies(file, depend_map);
/* convert the target from source to object (makes assumptions about rules) */
target = astring_dup(file->name);
astring_replacec(target, 0, "src/", "$(OBJ)/");
astring_replacec(target, 0, ".c", ".o");
printf("\n%s : \\\n", astring_c(target));
// convert the target from source to object (makes assumptions about rules)
astring target(file.name);
target.replace(0, "src/", "$(OBJ)/");
target.replace(0, ".c", ".o");
printf("\n%s : \\\n", target.cstr());
/* iterate over the hashed dependencies and output them as well */
for (taghash = 0; taghash < TAGMAP_HASH_SIZE; taghash++)
for (map_entry = depend_map->table[taghash]; map_entry != NULL; map_entry = map_entry->next)
printf("\t%s \\\n", astring_c((astring *)map_entry->object));
astring_free(target);
tagmap_free(depend_map);
// iterate over the hashed dependencies and output them as well
for (int taghash = 0; taghash < TAGMAP_HASH_SIZE; taghash++)
for (tagmap_entry *map_entry = depend_map.table[taghash]; map_entry != NULL; map_entry = map_entry->next)
printf("\t%s \\\n", ((astring *)map_entry->object)->cstr());
}
}
/* if we have a directory, recurse */
// if we have a directory, recurse
else
result = recurse_dir(srcrootlen, srcfile);
/* free memory for the names */
astring_free(srcfile);
}
/* free all the allocated entries */
// free all the allocated entries
while (list != NULL)
{
list_entry *next = list->next;
astring_free((astring *)list->name);
free(list);
delete list;
list = next;
}
}
@ -399,84 +347,73 @@ error:
HTML
-------------------------------------------------*/
static file_entry *compute_dependencies(int srcrootlen, const astring *srcfile)
static file_entry &compute_dependencies(int srcrootlen, astring &srcfile)
{
astring *normalfile;
// see if we already have an entry
astring normalfile(srcfile);
normalfile.replacechr(PATH_SEPARATOR[0], '/');
file_entry *foundfile = file_map.find(normalfile);
if (foundfile != NULL)
return *foundfile;
// create a new header entry
file_entry &file = *new file_entry;
file.deplist = NULL;
file.name = normalfile;
file_map.add(file.name, &file);
// read the source file
UINT32 filelength;
file_entry *file;
char *filedata;
int index;
/* see if we already have an entry */
normalfile = astring_dup(srcfile);
astring_replacechr(normalfile, PATH_SEPARATOR[0], '/');
file = (file_entry *)tagmap_find(file_map, astring_c(normalfile));
if (file != NULL)
return file;
/* create a new header entry */
file = (file_entry *)malloc(sizeof(*file));
file->deplist = NULL;
file->name = normalfile;
tagmap_add(file_map, astring_c(file->name), file, FALSE);
/* read the source file */
if (core_fload(astring_c(srcfile), (void **)&filedata, &filelength) != FILERR_NONE)
if (core_fload(srcfile, (void **)&filedata, &filelength) != FILERR_NONE)
{
fprintf(stderr, "Unable to read file '%s'\n", astring_c(srcfile));
fprintf(stderr, "Unable to read file '%s'\n", srcfile.cstr());
return file;
}
/* find the #include directives in this file */
for (index = 0; index < filelength; index++)
// find the #include directives in this file
for (int index = 0; index < filelength; index++)
if (filedata[index] == '#' && strncmp(&filedata[index + 1], "include", 7) == 0)
{
astring *filename, *target;
int scan = index;
dependency *dep;
int start;
int just_continue = 0;
/* first make sure we're not commented or quoted */
for (scan = index; scan > 2 && filedata[scan] != 13 && filedata[scan] != 10; scan--)
// first make sure we're not commented or quoted
bool just_continue = false;
for (int scan = index; scan > 2 && filedata[scan] != 13 && filedata[scan] != 10; scan--)
if ((filedata[scan] == '/' && filedata[scan - 1] == '/') || filedata[scan] == '"')
{
just_continue = 1;
just_continue = true;
break;
}
if (just_continue)
continue;
/* scan forward to find the quotes or bracket */
// scan forward to find the quotes or bracket
index += 7;
int scan;
for (scan = index; scan < filelength && filedata[scan] != '<' && filedata[scan] != '"' && filedata[scan] != 13 && filedata[scan] != 10; scan++) ;
/* ignore if not found or if it's bracketed */
// ignore if not found or if it's bracketed
if (scan >= filelength || filedata[scan] != '"')
continue;
start = ++scan;
int start = ++scan;
/* find the closing quote */
// find the closing quote
while (scan < filelength && filedata[scan] != '"')
scan++;
if (scan >= filelength)
continue;
/* find the include file */
filename = astring_dupch(&filedata[start], scan - start);
target = find_include_file(srcrootlen, srcfile, filename);
// find the include file
astring filename(&filedata[start], scan - start);
astring target;
/* create a new dependency */
if (target != NULL)
// create a new dependency
if (find_include_file(target, srcrootlen, srcfile, filename))
{
dep = (dependency *)malloc(sizeof(*dep));
dep->next = file->deplist;
file->deplist = dep;
dep->file = compute_dependencies(srcrootlen, target);
astring_free(target);
dependency *dep = new dependency;
dep->next = file.deplist;
file.deplist = dep;
dep->file = &compute_dependencies(srcrootlen, target);
}
astring_free(filename);
}
osd_free(filedata);
@ -493,59 +430,51 @@ static file_entry *compute_dependencies(int srcrootlen, const astring *srcfile)
find_include_file - find an include file
-------------------------------------------------*/
static astring *find_include_file(int srcrootlen, const astring *srcfile, const astring *filename)
static bool find_include_file(astring &srcincpath, int srcrootlen, const astring &srcfile, const astring &filename)
{
include_path *curpath;
/* iterate over include paths and find the file */
for (curpath = incpaths; curpath != NULL; curpath = curpath->next)
// iterate over include paths and find the file
for (include_path *curpath = incpaths; curpath != NULL; curpath = curpath->next)
{
astring *srcincpath = astring_dup(curpath->path);
core_file *testfile;
// a '.' include path is specially treated
if (curpath->path == ".")
srcincpath.cpysubstr(srcfile, 0, srcfile.rchr(0, PATH_SEPARATOR[0]));
else
srcincpath.cpy(curpath->path);
// append the filename piecemeal to account for directories
int lastsepindex = 0;
int sepindex;
/* a '.' include path is specially treated */
if (astring_cmpc(curpath->path, ".") == 0)
astring_cpysubstr(srcincpath, srcfile, 0, astring_rchr(srcfile, 0, PATH_SEPARATOR[0]));
/* append the filename piecemeal to account for directories */
while ((sepindex = astring_chr(filename, lastsepindex, '/')) != -1)
while ((sepindex = filename.chr(lastsepindex, '/')) != -1)
{
astring *pathpart = astring_dupsubstr(filename, lastsepindex, sepindex - lastsepindex);
astring pathpart(filename, lastsepindex, sepindex - lastsepindex);
/* handle .. by removing a chunk from the incpath */
if (astring_cmpc(pathpart, "..") == 0)
// handle .. by removing a chunk from the incpath
if (pathpart == "..")
{
int sepindex_part = astring_rchr(srcincpath, 0, PATH_SEPARATOR[0]);
int sepindex_part = srcincpath.rchr(0, PATH_SEPARATOR[0]);
if (sepindex_part != -1)
astring_substr(srcincpath, 0, sepindex_part);
srcincpath.substr(0, sepindex_part);
}
/* otherwise, append a path separator and the pathpart */
// otherwise, append a path separator and the pathpart
else
astring_cat(astring_catc(srcincpath, PATH_SEPARATOR), pathpart);
srcincpath.cat(PATH_SEPARATOR).cat(pathpart);
/* advance past the previous index */
// advance past the previous index
lastsepindex = sepindex + 1;
/* free the path part we extracted */
astring_free(pathpart);
}
/* now append the filename */
astring_catsubstr(astring_catc(srcincpath, PATH_SEPARATOR), filename, lastsepindex, -1);
// now append the filename
srcincpath.cat(PATH_SEPARATOR).catsubstr(filename, lastsepindex, -1);
/* see if we can open it */
if (core_fopen(astring_c(srcincpath), OPEN_FLAG_READ, &testfile) == FILERR_NONE)
// see if we can open it
core_file *testfile;
if (core_fopen(srcincpath, OPEN_FLAG_READ, &testfile) == FILERR_NONE)
{
/* close the file */
// close the file
core_fclose(testfile);
return srcincpath;
return true;
}
/* free our include path */
astring_free(srcincpath);
}
return NULL;
return false;
}

View File

@ -166,7 +166,7 @@ int cli_frontend::execute(int argc, char **argv)
// determine the base name of the EXE
astring exename;
core_filename_extract_base(&exename, argv[0], TRUE);
core_filename_extract_base(exename, argv[0], true);
// if we have a command, execute that
if (strlen(m_options.command()) != 0)
@ -345,7 +345,7 @@ void cli_frontend::listsource(const char *gamename)
// iterate through drivers and output the info
astring filename;
while (drivlist.next())
mame_printf_info("%-16s %s\n", drivlist.driver().name, core_filename_extract_base(&filename, drivlist.driver().source_file, FALSE)->cstr());
mame_printf_info("%-16s %s\n", drivlist.driver().name, core_filename_extract_base(filename, drivlist.driver().source_file).cstr());
}
@ -435,7 +435,7 @@ void cli_frontend::listbrothers(const char *gamename)
while (drivlist.next())
{
int clone_of = drivlist.clone();
mame_printf_info("%-16s %-16s %-16s\n", core_filename_extract_base(&filename, drivlist.driver().source_file, FALSE)->cstr(), drivlist.driver().name, (clone_of == -1 ? "" : drivlist.driver(clone_of).name));
mame_printf_info("%-16s %-16s %-16s\n", core_filename_extract_base(filename, drivlist.driver().source_file).cstr(), drivlist.driver().name, (clone_of == -1 ? "" : drivlist.driver(clone_of).name));
}
}
@ -1488,7 +1488,7 @@ void media_identifier::identify_file(const char *name)
{
// output the name
astring basename;
mame_printf_info("%-20s", core_filename_extract_base(&basename, name, FALSE)->cstr());
mame_printf_info("%-20s", core_filename_extract_base(basename, name).cstr());
m_total++;
// attempt to open as a CHD; fail if not
@ -1570,7 +1570,7 @@ void media_identifier::identify_data(const char *name, const UINT8 *data, int le
// output the name
m_total++;
astring basename;
mame_printf_info("%-20s", core_filename_extract_base(&basename, name, FALSE)->cstr());
mame_printf_info("%-20s", core_filename_extract_base(basename, name).cstr());
// see if we can find a match in the ROMs
int found = find_by_hash(hashes, length);

View File

@ -51,9 +51,6 @@
#include "xmlfile.h"
#include <ctype.h>
#include <zlib.h>
#if defined(SDLMAME_FREEBSD) || defined(SDLMAME_NETBSD) || defined(SDLMAME_OS2)
# undef tolower
#endif
/***************************************************************************
@ -1712,7 +1709,7 @@ device_debug::device_debug(device_t &device)
// add all registers into it
astring tempstr;
for (const device_state_entry *entry = m_state->state_first(); entry != NULL; entry = entry->next())
m_symtable.add(tempstr.cpy(entry->symbol()).tolower(), (void *)(FPTR)entry->index(), get_state, set_state);
m_symtable.add(tempstr.cpy(entry->symbol()).makelower(), (void *)(FPTR)entry->index(), get_state, set_state);
}
// set up execution-related stuff
@ -3056,8 +3053,7 @@ UINT32 device_debug::dasm_wrapped(astring &buffer, offs_t pc)
}
// disassemble to our buffer
buffer.expand(200);
return disassemble(buffer.text, pc, opbuf, argbuf);
return disassemble(buffer.stringbuffer(200), pc, opbuf, argbuf);
}

View File

@ -955,15 +955,15 @@ void parsed_expression::parse_symbol_or_number(parse_token &token, const char *&
// if we have an 0x prefix, we must be a hex value
if (buffer[0] == '0' && buffer[1] == 'x')
return parse_number(token, &buffer[2], 16, expression_error::INVALID_NUMBER);
return parse_number(token, buffer.cstr() + 2, 16, expression_error::INVALID_NUMBER);
// if we have a # prefix, we must be a decimal value
if (buffer[0] == '#')
return parse_number(token, &buffer[1], 10, expression_error::INVALID_NUMBER);
return parse_number(token, buffer.cstr() + 1, 10, expression_error::INVALID_NUMBER);
// if we have a $ prefix, we are a hex value
if (buffer[0] == '$')
return parse_number(token, &buffer[1], 16, expression_error::INVALID_NUMBER);
return parse_number(token, buffer.cstr() + 1, 16, expression_error::INVALID_NUMBER);
// check for a symbol match
symbol_entry *symbol = m_symtable->find_deep(buffer);

View File

@ -285,7 +285,6 @@ static DView *dview_alloc(render_target *target, running_machine &machine, debug
static void dview_free(DView *dv)
{
//astring_free(dv->title);
LIST_REMOVE(list, dv, DView);
auto_free(dv->machine(), dv);
}

View File

@ -182,7 +182,7 @@ void device_image_interface::device_compute_hash(hash_collection &hashes, const
image_error_t device_image_interface::set_image_filename(const char *filename)
{
m_image_name = filename;
zippath_parent(&m_working_directory, filename);
zippath_parent(m_working_directory, filename);
m_basename.cpy(m_image_name);
int loc1 = m_image_name.rchr(0,'\\');
@ -352,7 +352,7 @@ bool device_image_interface::try_change_working_directory(const char *subdir)
/* did we successfully identify the directory? */
if (success)
zippath_combine(&m_working_directory, m_working_directory, subdir);
zippath_combine(m_working_directory, m_working_directory, subdir);
return success;
}
@ -532,10 +532,9 @@ UINT32 device_image_interface::crc()
-------------------------------------------------*/
void device_image_interface::battery_load(void *buffer, int length, int fill)
{
astring *fname = astring_assemble_4(astring_alloc(), device().machine().system().name, PATH_SEPARATOR, m_basename_noext, ".nv");
astring fname(device().machine().system().name, PATH_SEPARATOR, m_basename_noext, ".nv");
image_battery_load_by_name(device().machine().options(), astring_c(fname), buffer, length, fill);
astring_free(fname);
image_battery_load_by_name(device().machine().options(), fname, buffer, length, fill);
}
/*-------------------------------------------------
@ -546,10 +545,9 @@ void device_image_interface::battery_load(void *buffer, int length, int fill)
-------------------------------------------------*/
void device_image_interface::battery_save(const void *buffer, int length)
{
astring *fname = astring_assemble_4(astring_alloc(), device().machine().system().name, PATH_SEPARATOR, m_basename_noext, ".nv");
astring fname(device().machine().system().name, PATH_SEPARATOR, m_basename_noext, ".nv");
image_battery_save_by_name(device().machine().options(), astring_c(fname), buffer, length);
astring_free(fname);
image_battery_save_by_name(device().machine().options(), fname, buffer, length);
}
//-------------------------------------------------
@ -605,7 +603,7 @@ image_error_t device_image_interface::load_image_by_path(UINT32 open_flags, cons
astring revised_path;
/* attempt to read the file */
filerr = zippath_fopen(path, open_flags, &m_file, &revised_path);
filerr = zippath_fopen(path, open_flags, m_file, revised_path);
/* did the open succeed? */
switch(filerr)

View File

@ -33,9 +33,9 @@
// core system includes
#include "osdcomm.h"
#include "astring.h"
#include "emualloc.h"
#include "corestr.h"
#include "astring.h"
#include "bitmap.h"
#include "tagmap.h"

View File

@ -448,10 +448,10 @@ void emu_options::parse_standard_inis(astring &error_string)
// next parse "source/<sourcefile>.ini"; if that doesn't exist, try <sourcefile>.ini
astring sourcename;
core_filename_extract_base(&sourcename, cursystem->source_file, TRUE)->ins(0, "source" PATH_SEPARATOR);
core_filename_extract_base(sourcename, cursystem->source_file, true).ins(0, "source" PATH_SEPARATOR);
if (!parse_one_ini(sourcename, OPTION_PRIORITY_SOURCE_INI, &error_string))
{
core_filename_extract_base(&sourcename, cursystem->source_file, TRUE);
core_filename_extract_base(sourcename, cursystem->source_file, true);
parse_one_ini(sourcename, OPTION_PRIORITY_SOURCE_INI, &error_string);
}
@ -474,7 +474,7 @@ void emu_options::parse_standard_inis(astring &error_string)
const game_driver *emu_options::system() const
{
astring tempstr;
int index = driver_list::find(*core_filename_extract_base(&tempstr, system_name(), TRUE));
int index = driver_list::find(core_filename_extract_base(tempstr, system_name(), true));
return (index != -1) ? &driver_list::driver(index) : NULL;
}

View File

@ -590,7 +590,7 @@ const char *hash_collection::macro_string(astring &buffer) const
buffer.reset();
for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next())
{
buffer.cat(temp.cpy(hash->name()).toupper());
buffer.cat(temp.cpy(hash->name()).makeupper());
buffer.cat("(").cat(hash->string(temp)).cat(") ");
}

View File

@ -371,17 +371,17 @@ static char *strip_extension(const char *filename)
string with the image info text
-------------------------------------------------*/
astring *image_info_astring(running_machine &machine, astring *string)
astring &image_info_astring(running_machine &machine, astring &string)
{
device_image_interface *image = NULL;
astring_printf(string, "%s\n\n", machine.system().description);
string.printf("%s\n\n", machine.system().description);
#if 0
if (mess_ram_size > 0)
{
char buf2[RAM_STRING_BUFLEN];
astring_catprintf(string, "RAM: %s\n\n", ram_string(buf2, mess_ram_size));
string.catprintf("RAM: %s\n\n", ram_string(buf2, mess_ram_size));
}
#endif
@ -398,28 +398,28 @@ astring *image_info_astring(running_machine &machine, astring *string)
base_filename_noextension = strip_extension(base_filename);
/* display device type and filename */
astring_catprintf(string, "%s: %s\n", image->device().name(), base_filename);
string.catprintf("%s: %s\n", image->device().name(), base_filename);
/* display long filename, if present and doesn't correspond to name */
info = image->longname();
if (info && (!base_filename_noextension || mame_stricmp(info, base_filename_noextension)))
astring_catprintf(string, "%s\n", info);
string.catprintf("%s\n", info);
/* display manufacturer, if available */
info = image->manufacturer();
if (info != NULL)
{
astring_catprintf(string, "%s", info);
string.catprintf("%s", info);
info = stripspace(image->year());
if (info && *info)
astring_catprintf(string, ", %s", info);
astring_catprintf(string,"\n");
string.catprintf(", %s", info);
string.catprintf("\n");
}
/* display supported information, if available */
switch(image->supported()) {
case SOFTWARE_SUPPORTED_NO : astring_catprintf(string, "Not supported\n"); break;
case SOFTWARE_SUPPORTED_PARTIAL : astring_catprintf(string, "Partialy supported\n"); break;
case SOFTWARE_SUPPORTED_NO : string.catprintf("Not supported\n"); break;
case SOFTWARE_SUPPORTED_PARTIAL : string.catprintf("Partialy supported\n"); break;
default : break;
}
@ -428,7 +428,7 @@ astring *image_info_astring(running_machine &machine, astring *string)
}
else
{
astring_catprintf(string, "%s: ---\n", image->device().name());
string.catprintf("%s: ---\n", image->device().name());
}
}
return string;

View File

@ -26,7 +26,7 @@ extern struct io_procs image_ioprocs;
void image_battery_load_by_name(emu_options &options, const char *filename, void *buffer, int length, int fill);
void image_battery_save_by_name(emu_options &options, const char *filename, const void *buffer, int length);
astring *image_info_astring(running_machine &machine, astring *string);
astring &image_info_astring(running_machine &machine, astring &string);
device_image_interface *image_from_absolute_index(running_machine &machine, int absolute_index);

View File

@ -2179,7 +2179,7 @@ input_device_item::input_device_item(input_device &device, const char *name, voi
// otherwise, create a tokenized name
else
m_token.cpy(name).toupper().delchr(' ').delchr('_');
m_token.cpy(name).makeupper().delchr(' ').delchr('_');
}

View File

@ -1911,9 +1911,8 @@ static const char *inputx_key_name(unicode_char ch)
a key based on natural keyboard characters
-------------------------------------------------*/
static astring *get_keyboard_key_name(const input_field_config *field)
static astring &get_keyboard_key_name(astring &name, const input_field_config *field)
{
astring *result = astring_alloc();
int i;
unicode_char ch;
@ -1922,17 +1921,17 @@ static astring *get_keyboard_key_name(const input_field_config *field)
for (i = 0; i < ARRAY_LENGTH(field->chars) && (field->chars[i] != '\0'); i++)
{
ch = get_keyboard_code(field, i);
astring_printf(result, "%s%-*s ", astring_c(result), MAX(SPACE_COUNT - 1, 0), inputx_key_name(ch));
name.catprintf("%-*s ", MAX(SPACE_COUNT - 1, 0), inputx_key_name(ch));
}
/* trim extra spaces */
astring_trimspace(result);
name.trimspace();
/* special case */
if (astring_len(result) == 0)
astring_cpyc(result, "Unnamed Key");
if (name.len() == 0)
name.cpy("Unnamed Key");
return result;
return name;
}
/*-------------------------------------------------
@ -2036,12 +2035,8 @@ static void init_port_state(running_machine &machine)
/* Name keyboard key names */
if ((field->type == IPT_KEYBOARD || field->type == IPT_KEYPAD) && (field->name == NULL))
{
astring *name = get_keyboard_key_name(field);
if (name != NULL)
{
field->state->name = auto_strdup(machine, astring_c(name));
astring_free(name);
}
astring name;
field->state->name = auto_strdup(machine, get_keyboard_key_name(name, field));
}
}
}

View File

@ -1911,7 +1911,7 @@ void validate_softlists(emu_options &options)
}
/* check for duplicate descriptions */
if (descriptions.add(astring(swinfo->longname).tolower().cstr(), swinfo, FALSE) == TMERR_DUPLICATE)
if (descriptions.add(astring(swinfo->longname).makelower().cstr(), swinfo, FALSE) == TMERR_DUPLICATE)
{
mame_printf_error("%s: %s is a duplicate description (%s)\n", list->file->filename(), swinfo->longname, swinfo->shortname);
error = TRUE;

View File

@ -224,7 +224,7 @@ static int is_valid_filename_char(unicode_char unichar)
void ui_menu_file_create::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
{
extra_text_render(container, top, bottom, origx1, origy1, origx2, origy2,
astring_c(manager->current_directory),
manager->current_directory,
NULL);
}
@ -254,8 +254,8 @@ void ui_menu_file_create::populate()
/* append the "New Image Name" item */
if (get_selection() == ITEMREF_NEW_IMAGE_NAME)
{
astring_assemble_2(&buffer, filename_buffer, "_");
new_image_name = astring_c(&buffer);
buffer.cat(filename_buffer).cat("_");
new_image_name = buffer;
}
else
{
@ -286,17 +286,17 @@ void ui_menu_file_create::populate()
int ui_menu_file_create::create_new_image(device_image_interface *image, const char *directory, const char *filename, int *yes)
{
astring *path;
astring path;
osd_directory_entry *entry;
osd_dir_entry_type file_type;
int do_create, err;
int result = FALSE;
/* assemble the full path */
path = zippath_combine(astring_alloc(), directory, filename);
zippath_combine(path, directory, filename);
/* does a file or a directory exist at the path */
entry = osd_stat(astring_c(path));
entry = osd_stat(path);
file_type = (entry != NULL) ? entry->type : ENTTYPE_NONE;
if (entry != NULL)
free(entry);
@ -333,16 +333,13 @@ int ui_menu_file_create::create_new_image(device_image_interface *image, const c
/* create the image, if appropriate */
if (do_create)
{
err = image->create(astring_c(path), 0, NULL);
err = image->create(path, 0, NULL);
if (err != 0)
popmessage("Error: %s", image->error());
else
result = TRUE;
}
/* free the path */
astring_free(path);
return result;
}
@ -382,7 +379,7 @@ void ui_menu_file_create::handle()
{
if (create_new_image(
manager->selected_device,
astring_c(manager->current_directory),
manager->current_directory,
filename_buffer,
&confirm_save_as_yes))
{
@ -422,7 +419,7 @@ void ui_menu_file_selector::custom_render(void *selectedref, float top, float bo
{
extra_text_render(container, top, bottom,
origx1, origy1, origx2, origy2,
astring_c(manager->current_directory),
manager->current_directory,
NULL);
}
@ -506,7 +503,7 @@ ui_menu_file_selector::file_selector_entry *ui_menu_file_selector::append_entry(
ui_menu_file_selector::file_selector_entry *ui_menu_file_selector::append_dirent_entry(const osd_directory_entry *dirent)
{
astring *buffer;
astring buffer;
file_selector_entry_type entry_type;
file_selector_entry *entry;
@ -526,18 +523,17 @@ ui_menu_file_selector::file_selector_entry *ui_menu_file_selector::append_dirent
}
/* determine the full path */
buffer = zippath_combine(
astring_alloc(),
astring_c(manager->current_directory),
zippath_combine(
buffer,
manager->current_directory,
dirent->name);
/* create the file selector entry */
entry = append_entry(
entry_type,
dirent->name,
astring_c(buffer));
buffer);
astring_free(buffer);
return entry;
}
@ -610,7 +606,7 @@ void ui_menu_file_selector::populate()
int i;
const char *volume_name;
device_image_interface *device = manager->selected_device;
const char *path = astring_c(manager->current_directory);
const char *path = manager->current_directory;
/* open the directory */
err = zippath_opendir(path, &directory);
@ -654,7 +650,7 @@ void ui_menu_file_selector::populate()
selected_entry = entry;
/* do we have to select this file? */
if (!mame_stricmp(astring_c(manager->current_file), dirent->name))
if (!mame_stricmp(manager->current_file, dirent->name))
selected_entry = entry;
}
}
@ -731,7 +727,7 @@ void ui_menu_file_selector::handle()
ui_popup_time(1, "Error accessing %s", entry->fullpath);
break;
}
astring_cpyc(manager->current_directory, entry->fullpath);
manager->current_directory.cpy(entry->fullpath);
reset((ui_menu_reset_options)0);
break;
@ -845,10 +841,9 @@ void ui_menu_file_manager::fix_working_directory(device_image_interface *image)
/* if the image exists, set the working directory to the parent directory */
if (image->exists())
{
astring *astr = astring_alloc();
astring astr;
zippath_parent(astr, image->filename());
image->set_working_directory(astring_c(astr));
astring_free(astr);
image->set_working_directory(astr);
}
/* check to see if the path exists; if not clear it */
@ -882,8 +877,6 @@ void ui_menu_file_manager::custom_render(void *selectedref, float top, float bot
ui_menu_file_manager::ui_menu_file_manager(running_machine &machine, render_container *container) : ui_menu(machine, container)
{
current_directory = astring_alloc();
current_file = astring_alloc();
}
void ui_menu_file_manager::populate()
@ -941,8 +934,6 @@ void ui_menu_file_manager::populate()
ui_menu_file_manager::~ui_menu_file_manager()
{
astring_free(current_directory);
astring_free(current_file);
}
@ -967,8 +958,8 @@ void ui_menu_file_manager::handle()
fix_working_directory(selected_device);
/* set up current_directory and current_file - depends on whether we have an image */
astring_cpyc(current_directory, selected_device->working_directory());
astring_cpyc(current_file, selected_device->exists() ? selected_device->basename() : "");
current_directory.cpy(selected_device->working_directory());
current_file.cpy(selected_device->exists() ? selected_device->basename() : "");
/* reset the existing menu */
reset(UI_MENU_RESET_REMEMBER_POSITION);
@ -990,9 +981,8 @@ ui_menu_image_info::ui_menu_image_info(running_machine &machine, render_containe
void ui_menu_image_info::populate()
{
astring *tempstring = image_info_astring(machine(), astring_alloc());
item_append(astring_c(tempstring), NULL, MENU_FLAG_MULTILINE, NULL);
astring_free(tempstring);
astring tempstring;
item_append(image_info_astring(machine(), tempstring), NULL, MENU_FLAG_MULTILINE, NULL);
}
ui_menu_image_info::~ui_menu_image_info()
@ -1084,7 +1074,7 @@ int ui_menu_mess_bitbanger_control::bitbanger_count()
representation of the time
-------------------------------------------------*/
astring *tapecontrol_gettime(astring *dest, cassette_image_device *cassette, int *curpos, int *endpos)
astring &tapecontrol_gettime(astring &dest, cassette_image_device *cassette, int *curpos, int *endpos)
{
double t0, t1;
@ -1092,9 +1082,9 @@ astring *tapecontrol_gettime(astring *dest, cassette_image_device *cassette, int
t1 = cassette->get_length();
if (t1)
astring_printf(dest, "%04d/%04d", (int) t0, (int) t1);
dest.printf("%04d/%04d", (int) t0, (int) t1);
else
astring_printf(dest, "%04d/%04d", 0, (int) t1);
dest.printf("%04d/%04d", 0, (int) t1);
if (curpos != NULL)
*curpos = t0;
@ -1147,7 +1137,7 @@ void ui_menu_mess_tape_control::populate()
item_append(device->device().name(), device->filename(), flags, TAPECMD_SELECT);
/* state */
tapecontrol_gettime(&timepos, cassette, NULL, NULL);
tapecontrol_gettime(timepos, cassette, NULL, NULL);
state = cassette->get_state();
item_append(
(state & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED
@ -1156,7 +1146,7 @@ void ui_menu_mess_tape_control::populate()
? ((state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_ENABLED ? "playing" : "(playing)")
: ((state & CASSETTE_MASK_MOTOR) == CASSETTE_MOTOR_ENABLED ? "recording" : "(recording)")
),
astring_c(&timepos),
timepos,
tapeflags,
TAPECMD_SLIDER);

View File

@ -24,8 +24,8 @@ public:
class ui_menu_file_manager : public ui_menu {
public:
astring *current_directory;
astring *current_file;
astring current_directory;
astring current_file;
device_image_interface *selected_device;
ui_menu_file_manager(running_machine &machine, render_container *container);

File diff suppressed because it is too large Load Diff

View File

@ -46,278 +46,21 @@
#include <ctype.h>
#include "osdcomm.h"
#ifdef toupper
#undef toupper
#endif
#ifdef tolower
#undef tolower
#endif
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
/* base astring structure */
typedef struct _astring_base astring_base;
struct _astring_base
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
// derived class for C++
class astring
{
char * text;
int alloclen;
char smallbuf[64 - sizeof(int) - sizeof(char *)];
};
/* class for C++, direct map for C */
#ifdef __cplusplus
class astring;
#else
typedef astring_base astring;
#endif
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
/* ----- astring allocation ----- */
/* allocate a new astring */
astring *astring_alloc(void);
/* free an astring */
void astring_free(astring *str);
/* free an astring */
void astring_expand(astring *str, int length);
/* ----- inline astring changes ----- */
/* copy one astring into another */
astring *astring_cpy(astring *dst, const astring *src);
/* copy a C string into an astring */
astring *astring_cpyc(astring *dst, const char *src);
/* copy a character array into an astring */
astring *astring_cpych(astring *dst, const char *src, int count);
/* copy a substring of one string into another */
astring *astring_cpysubstr(astring *dst, const astring *src, int start, int count);
/* insert one astring into another */
astring *astring_ins(astring *dst, int insbefore, const astring *src);
/* insert a C string into an astring */
astring *astring_insc(astring *dst, int insbefore, const char *src);
/* insert a character array into an astring */
astring *astring_insch(astring *dst, int insbefore, const char *src, int count);
/* insert a substring of one string into another */
astring *astring_inssubstr(astring *dst, int insbefore, const astring *src, int start, int count);
/* extract a substring of ourself, removing everything else */
astring *astring_substr(astring *str, int start, int count);
/* delete a substring from ourself, keeping everything else */
astring *astring_del(astring *str, int start, int count);
/* formatted printf to an astring */
int astring_printf(astring *dst, const char *format, ...) ATTR_PRINTF(2,3);
/* formatted vprintf to an astring */
int astring_vprintf(astring *dst, const char *format, va_list args);
/* formatted printf to the end of an astring */
int astring_catprintf(astring *dst, const char *format, ...) ATTR_PRINTF(2,3);
/* formatted vprintf to the end of an astring */
int astring_catvprintf(astring *dst, const char *format, va_list args);
/* ----- astring queries ----- */
/* return a pointer to a C string from an astring */
const char *astring_c(const astring *str);
/* return the length of an astring */
int astring_len(const astring *str);
/* compare two astrings */
int astring_cmp(const astring *str1, const astring *str2);
/* compare an astring to a C string */
int astring_cmpc(const astring *str1, const char *str2);
/* compare an astring to a character buffer */
int astring_cmpch(const astring *str1, const char *str2, int count);
/* compare an astring to a character buffer */
int astring_cmpsubstr(const astring *str1, const astring *str2, int start, int count);
/* case-insenstive compare two astrings */
int astring_icmp(const astring *str1, const astring *str2);
/* case-insenstive compare an astring to a C string */
int astring_icmpc(const astring *str1, const char *str2);
/* case-insenstive compare an astring to a character buffer */
int astring_icmpch(const astring *str1, const char *str2, int count);
/* case-insenstive compare an astring to a character buffer */
int astring_icmpsubstr(const astring *str1, const astring *str2, int start, int count);
/* search an astring for a character, returning offset or -1 if not found */
int astring_chr(const astring *str, int start, int ch);
/* reverse search an astring for a character, returning offset or -1 if not found */
int astring_rchr(const astring *str, int start, int ch);
/* search in an astring for another astring, returning offset or -1 if not found */
int astring_find(const astring *str, int start, const astring *search);
/* search in an astring for a C string, returning offset or -1 if not found */
int astring_findc(const astring *str, int start, const char *search);
/* search in an astring for another astring, replacing all instances with a third and returning the number of matches */
int astring_replace(astring *str, int start, const astring *search, const astring *replace);
/* search in an astring for a C string, replacing all instances with another C string and returning the number of matches */
int astring_replacec(astring *str, int start, const char *search, const char *replace);
/* ----- astring utilties ----- */
/* delete all instances of 'ch' */
astring *astring_delchr(astring *str, int ch);
/* replace all instances of 'ch' with 'newch' */
astring *astring_replacechr(astring *str, int ch, int newch);
/* convert string to all upper-case */
astring *astring_toupper(astring *str);
/* convert string to all lower-case */
astring *astring_tolower(astring *str);
/* remove all space characters from beginning/end */
astring *astring_trimspace(astring *str);
/***************************************************************************
INLINE FUNCTIONS
***************************************************************************/
/* allocate a new duplicate of an astring */
INLINE astring *astring_dup(const astring *str)
{
return astring_cpy(astring_alloc(), str);
}
/* allocate a new duplicate of an astring */
INLINE astring *astring_dupc(const char *str)
{
return astring_cpyc(astring_alloc(), str);
}
/* allocate a new duplicate of an astring */
INLINE astring *astring_dupch(const char *str, int count)
{
return astring_cpych(astring_alloc(), str, count);
}
/* allocate a duplicate of a substring */
INLINE astring *astring_dupsubstr(const astring *str, int start, int count)
{
return astring_cpysubstr(astring_alloc(), str, start, count);
}
/* reset an astring to an empty string */
INLINE astring *astring_reset(astring *dst)
{
return astring_cpyc(dst, "");
}
/* concatenate one astring to the end of another */
INLINE astring *astring_cat(astring *dst, const astring *src)
{
return astring_ins(dst, -1, src);
}
/* concatenate a C string to the end of an astring */
INLINE astring *astring_catc(astring *dst, const char *src)
{
return astring_insc(dst, -1, src);
}
/* concatenate a character array to the end of an astring */
INLINE astring *astring_catch(astring *dst, const char *src, int count)
{
return astring_insch(dst, -1, src, count);
}
/* concatenate a substring of one string into another */
INLINE astring *astring_catsubstr(astring *dst, const astring *src, int start, int count)
{
return astring_inssubstr(dst, -1, src, start, count);
}
/* assemble an astring from 2 C strings */
INLINE astring *astring_assemble_2(astring *dst, const char *src1, const char *src2)
{
return astring_catc(astring_cpyc(dst, src1), src2);
}
/* assemble an astring from 3 C strings */
INLINE astring *astring_assemble_3(astring *dst, const char *src1, const char *src2, const char *src3)
{
return astring_catc(astring_assemble_2(dst, src1, src2), src3);
}
/* assemble an astring from 4 C strings */
INLINE astring *astring_assemble_4(astring *dst, const char *src1, const char *src2, const char *src3, const char *src4)
{
return astring_catc(astring_assemble_3(dst, src1, src2, src3), src4);
}
/* assemble an astring from 5 C strings */
INLINE astring *astring_assemble_5(astring *dst, const char *src1, const char *src2, const char *src3, const char *src4, const char *src5)
{
return astring_catc(astring_assemble_4(dst, src1, src2, src3, src4), src5);
}
/***************************************************************************
C++ WRAPPERS
***************************************************************************/
#ifdef __cplusplus
#ifdef SDLMAME_NETBSD
#undef toupper
#undef tolower
#endif
/* derived class for C++ */
class astring : public astring_base
{
private:
astring &init();
public:
// simple construction/destruction
astring() { init(); }
~astring();
// construction with copy
astring(const char *string) { init().cpy(string); }
astring(const char *string, int length) { init().cpy(string, length); }
astring(const char *str1, const char *str2) { init().cpy(str1).cat(str2); }
@ -327,14 +70,17 @@ public:
astring(const astring &string) { init().cpy(string); }
astring(const astring &string, int start, int count = -1) { init().cpysubstr(string, start, count); }
// assignment operators
astring &operator=(const char *string) { return cpy(string); }
astring &operator=(const astring &string) { return cpy(string); }
// concatenation operators
astring& operator+=(const astring &string) { return cat(string); }
friend astring operator+(const astring &lhs, const astring &rhs) { return astring(lhs) += rhs; }
friend astring operator+(const astring &lhs, const char *rhs) { return astring(lhs) += rhs; }
friend astring operator+(const char *lhs, const astring &rhs) { return astring(lhs) += rhs; }
// comparison operators
bool operator==(const char *string) const { return (cmp(string) == 0); }
bool operator==(const astring &string) const { return (cmp(string) == 0); }
bool operator!=(const char *string) const { return (cmp(string) != 0); }
@ -348,68 +94,97 @@ public:
bool operator>=(const char *string) const { return (cmp(string) >= 0); }
bool operator>=(const astring &string) const { return (cmp(string) >= 0); }
// character access operators
char operator[](int index) const { return (index < len()) ? m_text[index] : 0; }
// implicit boolean conversion operators
operator bool() { return m_text[0] != 0; }
operator bool() const { return m_text[0] != 0; }
// C string conversion operators and helpers
operator const char *() const { return m_text; }
const char *cstr() const { return m_text; }
char *stringbuffer(int size) { ensure_room(size); return m_text; }
// buffer management
astring &reset() { return cpy(""); }
astring &expand(int length) { astring_expand(this, length); return *this; }
astring &expand(int length) { ensure_room(length); return *this; }
operator bool() { return this->text[0] != 0; }
operator bool() const { return this->text[0] != 0; }
operator const char *() const { return astring_c(this); }
const char *cstr() const { return astring_c(this); }
int len() const { return astring_len(this); }
// length query
int len() const { return strlen(m_text); }
astring &cpy(const astring &src) { return *astring_cpy(this, &src); }
astring &cpy(const char *src) { return *astring_cpyc(this, src); }
astring &cpy(const char *src, int count) { return *astring_cpych(this, src, count); }
astring &cpysubstr(const astring &src, int start, int count) { return *astring_cpysubstr(this, &src, start, count); }
// copy helpers
astring &cpy(const char *src, int count);
astring &cpysubstr(const astring &src, int start, int count = -1);
astring &cpy(const astring &src) { return cpy(src.cstr(), src.len()); }
astring &cpy(const char *src) { return cpy(src, strlen(src)); }
astring &cat(char ch) { return *astring_insch(this, -1, &ch, 1); }
astring &cat(const astring &src) { return ins(-1, src); }
astring &cat(const char *src) { return ins(-1, src); }
// insertion helpers
astring &ins(int insbefore, const char *src, int count);
astring &inssubstr(int insbefore, const astring &src, int start, int count = -1);
astring &ins(int insbefore, const astring &src) { return ins(insbefore, src.cstr(), src.len()); }
astring &ins(int insbefore, const char *src) { return ins(insbefore, src, strlen(src)); }
// concatenation helpers (== insert at end)
astring &cat(const char *src, int count) { return ins(-1, src, count); }
astring &catsubstr(const astring &src, int start, int count) { return inssubstr(-1, src, start, count); }
astring &catsubstr(const astring &src, int start, int count = -1) { return inssubstr(-1, src, start, count); }
astring &cat(const astring &src) { return ins(-1, src.cstr(), src.len()); }
astring &cat(const char *src) { return ins(-1, src, strlen(src)); }
astring &cat(char ch) { return ins(-1, &ch, 1); }
astring &ins(int insbefore, const astring &src) { return *astring_ins(this, insbefore, &src); }
astring &ins(int insbefore, const char *src) { return *astring_insc(this, insbefore, src); }
astring &ins(int insbefore, const char *src, int count) { return *astring_insch(this, insbefore, src, count); }
astring &inssubstr(int insbefore, const astring &src, int start, int count) { return *astring_inssubstr(this, insbefore, &src, start, count); }
// substring helpers
astring &substr(int start, int count = -1);
astring &del(int start, int count = -1);
astring &substr(int start, int count) { return *astring_substr(this, start, count); }
astring &del(int start, int count) { return *astring_del(this, start, count); }
// formatted string helpers
int vprintf(const char *format, va_list args);
int catvprintf(const char *format, va_list args);
int printf(const char *format, ...) { va_list ap; va_start(ap, format); int result = this->vprintf(format, ap); va_end(ap); return result; }
int catprintf(const char *format, ...) { va_list ap; va_start(ap, format); int result = catvprintf(format, ap); va_end(ap); return result; }
astring &format(const char *format, ...) { va_list ap; va_start(ap, format); this->vprintf(format, ap); va_end(ap); return *this; }
astring &catformat(const char *format, ...) { va_list ap; va_start(ap, format); catvprintf(format, ap); va_end(ap); return *this; }
int printf(const char *format, ...) { va_list ap; va_start(ap, format); int result = astring_vprintf(this, format, ap); va_end(ap); return result; }
int vprintf(const char *format, va_list args) { return astring_vprintf(this, format, args); }
int catprintf(const char *format, ...) { va_list ap; va_start(ap, format); int result = astring_catvprintf(this, format, ap); va_end(ap); return result; }
int catvprintf(const char *format, va_list args) { return astring_catvprintf(this, format, args); }
// comparison helpers
int cmp(const char *str2, int count) const;
int cmpsubstr(const astring &str2, int start, int count = -1) const;
int cmp(const astring &str2) const { return cmp(str2.cstr(), str2.len()); }
int cmp(const char *str2) const { return cmp(str2, strlen(str2)); }
astring &format(const char *format, ...) { va_list ap; va_start(ap, format); astring_vprintf(this, format, ap); va_end(ap); return *this; }
// case-insensitive comparison helpers
int icmp(const char *str2, int count) const;
int icmpsubstr(const astring &str2, int start, int count = -1) const;
int icmp(const astring &str2) const { return icmp(str2.cstr(), str2.len()); }
int icmp(const char *str2) const { return icmp(str2, strlen(str2)); }
int cmp(const astring &str2) const { return astring_cmp(this, &str2); }
int cmp(const char *str2) const { return astring_cmpc(this, str2); }
int cmp(const char *str2, int count) const { return astring_cmpch(this, str2, count); }
int cmpsubstr(const astring &str2, int start, int count) const { return astring_cmpsubstr(this, &str2, start, count); }
// character searching helpers
int chr(int start, int ch) const;
int rchr(int start, int ch) const;
int icmp(const astring &str2) const { return astring_icmp(this, &str2); }
int icmp(const char *str2) const { return astring_icmpc(this, str2); }
int icmp(const char *str2, int count) const { return astring_icmpch(this, str2, count); }
int icmpsubstr(const astring &str2, int start, int count) const { return astring_icmpsubstr(this, &str2, start, count); }
// string searching/replacing helpers
int find(int start, const char *search) const;
int find(const char *search) const { return find(0, search); }
int replace(int start, const char *search, const char *replace);
int replace(const char *search, const char *_replace) { return replace(0, search, _replace); }
int chr(int start, int ch) const { return astring_chr(this, start, ch); }
int rchr(int start, int ch) const { return astring_rchr(this, start, ch); }
// misc utilities
astring &delchr(int ch);
astring &replacechr(int ch, int newch);
astring &makeupper();
astring &makelower();
astring &trimspace();
int find(int start, const astring &search) const { return astring_find(this, start, &search); }
int find(int start, const char *search) const { return astring_findc(this, start, search); }
private:
// internal helpers
astring &init();
char *safe_string_base(int start) const;
bool ensure_room(int length);
void normalize_substr(int &start, int &count, int length) const;
int replace(int start, const astring &search, const astring &replace) { return astring_replace(this, start, &search, &replace); }
int replace(int start, const char *search, const char *replace) { return astring_replacec(this, start, search, replace); }
astring &delchr(int ch) { return *astring_delchr(this, ch); }
astring &replacechr(int ch, int newch) { return *astring_replacechr(this, ch, newch); }
astring &toupper() { return *astring_toupper(this); }
astring &tolower() { return *astring_tolower(this); }
astring &trimspace() { return *astring_trimspace(this); }
// internal state
char * m_text;
int m_alloclen;
char m_smallbuf[64];
};
#endif
#endif /* __ASTRING_H__ */

View File

@ -883,7 +883,7 @@ int CLIB_DECL core_fprintf(core_file *f, const char *fmt, ...)
assumptions about path separators
-------------------------------------------------*/
astring *core_filename_extract_base(astring *result, const char *name, int strip_extension)
astring &core_filename_extract_base(astring &result, const char *name, bool strip_extension)
{
/* find the start of the name */
const char *start = name + strlen(name);
@ -891,11 +891,11 @@ astring *core_filename_extract_base(astring *result, const char *name, int strip
start--;
/* copy the rest into an astring */
astring_cpyc(result, start);
result.cpy(start);
/* chop the extension if present */
if (strip_extension)
astring_substr(result, 0, astring_rchr(result, 0, '.'));
result.substr(0, result.rchr(0, '.'));
return result;
}

View File

@ -149,7 +149,7 @@ int CLIB_DECL core_fprintf(core_file *f, const char *fmt, ...) ATTR_PRINTF(2,3);
/* ----- filename utilities ----- */
/* extract the base part of a filename (remove extensions and paths) */
astring *core_filename_extract_base(astring *result, const char *name, int strip_extension);
astring &core_filename_extract_base(astring &result, const char *name, bool strip_extension = false);
/* true if the given filename ends with a particular extension */
int core_filename_ends_with(const char *filename, const char *extension);

View File

@ -8,6 +8,7 @@
#include <ctype.h>
#include <stdlib.h>
#include <new>
#include "zippath.h"
#include "unzip.h"
#include "corestr.h"
@ -18,28 +19,35 @@
TYPE DEFINITIONS
***************************************************************************/
typedef struct _zippath_returned_directory zippath_returned_directory;
struct _zippath_returned_directory
struct zippath_returned_directory
{
zippath_returned_directory *next;
char name[1];
astring name;
};
struct _zippath_directory
class zippath_directory
{
public:
zippath_directory()
: returned_parent(false),
directory(NULL),
called_zip_first(false),
zipfile(NULL),
returned_dirlist(NULL) { }
/* common */
unsigned int returned_parent : 1;
bool returned_parent;
osd_directory_entry returned_entry;
/* specific to normal directories */
osd_directory *directory;
/* specific to ZIP directories */
unsigned int called_zip_first : 1;
bool called_zip_first;
zip_file *zipfile;
astring *zipprefix;
astring zipprefix;
zippath_returned_directory *returned_dirlist;
};
@ -99,13 +107,13 @@ static void parse_parent_path(const char *path, int *beginpos, int *endpos)
zippath_parent - retrieves the parent directory
-------------------------------------------------*/
astring *zippath_parent(astring *dst, const char *path)
astring &zippath_parent(astring &dst, const char *path)
{
int pos;
parse_parent_path(path, &pos, NULL);
/* return the result */
return (pos >= 0) ? astring_cpych(dst, path, pos + 1) : astring_cpyc(dst, "");
return (pos >= 0) ? dst.cpy(path, pos + 1) : dst.reset();
}
@ -115,12 +123,12 @@ astring *zippath_parent(astring *dst, const char *path)
directory basename
-------------------------------------------------*/
astring *zippath_parent_basename(astring *dst, const char *path)
astring &zippath_parent_basename(astring &dst, const char *path)
{
int beginpos, endpos;
parse_parent_path(path, &beginpos, &endpos);
return astring_cpych(dst, path + beginpos + 1, endpos - beginpos);
return dst.cpy(path + beginpos + 1, endpos - beginpos);
}
@ -129,31 +137,29 @@ astring *zippath_parent_basename(astring *dst, const char *path)
zippath_combine - combines two paths
-------------------------------------------------*/
astring *zippath_combine(astring *dst, const char *path1, const char *path2)
astring &zippath_combine(astring &dst, const char *path1, const char *path2)
{
astring *result;
if (!strcmp(path2, "."))
{
result = astring_cpyc(dst, path1);
dst.cpy(path1);
}
else if (!strcmp(path2, ".."))
{
result = zippath_parent(dst, path1);
zippath_parent(dst, path1);
}
else if (osd_is_absolute_path(path2))
{
result = astring_cpyc(dst, path2);
dst.cpy(path2);
}
else if ((path1[0] != '\0') && !is_path_separator(path1[strlen(path1) - 1]))
{
result = astring_assemble_3(dst, path1, PATH_SEPARATOR, path2);
dst.cpy(path1).cat(PATH_SEPARATOR).cat(path2);
}
else
{
result = astring_assemble_2(dst, path1, path2);
dst.cpy(path1).cat(path2);
}
return result;
return dst;
}
@ -200,7 +206,7 @@ static file_error file_error_from_zip_error(zip_error ziperr)
from a zip file entry
-------------------------------------------------*/
static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header *header, core_file **file)
static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header *header, core_file *&file)
{
file_error filerr;
zip_error ziperr;
@ -220,7 +226,7 @@ static file_error create_core_file_from_zip(zip_file *zip, const zip_file_header
goto done;
}
filerr = core_fopen_ram_copy(ptr, header->uncompressed_length, OPEN_FLAG_READ, file);
filerr = core_fopen_ram_copy(ptr, header->uncompressed_length, OPEN_FLAG_READ, &file);
if (filerr != FILERR_NONE)
goto done;
@ -235,36 +241,30 @@ done:
zippath_fopen - opens a zip path file
-------------------------------------------------*/
file_error zippath_fopen(const char *filename, UINT32 openflags, core_file **file, astring *revised_path)
file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&file, astring &revised_path)
{
file_error filerr = FILERR_NOT_FOUND;
zip_error ziperr;
zip_file *zip = NULL;
const zip_file_header *header;
osd_dir_entry_type entry_type;
astring *mainpath;
astring *subpath;
astring *temp;
astring *temp2;
char *alloc_fullpath = NULL;
int len;
/* first, set up the two types of paths */
mainpath = astring_cpyc(astring_alloc(), filename);
subpath = astring_alloc();
temp = astring_alloc();
temp2 = astring_alloc();
*file = NULL;
astring mainpath(filename);
astring subpath;
file = NULL;
/* loop through */
while((*file == NULL) && (astring_len(mainpath) > 0)
&& ((openflags == OPEN_FLAG_READ) || (astring_len(subpath) == 0)))
while((file == NULL) && (mainpath.len() > 0)
&& ((openflags == OPEN_FLAG_READ) || (subpath.len() == 0)))
{
/* is the mainpath a ZIP path? */
if (is_zip_file(astring_c(mainpath)))
if (is_zip_file(mainpath))
{
/* this file might be a zip file - lets take a look */
ziperr = zip_file_open(astring_c(mainpath), &zip);
ziperr = zip_file_open(mainpath, &zip);
if (ziperr == ZIPERR_NONE)
{
/* it is a zip file - error if we're not opening for reading */
@ -274,8 +274,8 @@ file_error zippath_fopen(const char *filename, UINT32 openflags, core_file **fil
goto done;
}
if (astring_len(subpath) > 0)
header = zippath_find_sub_path(zip, astring_c(subpath), &entry_type);
if (subpath.len() > 0)
header = zippath_find_sub_path(zip, subpath, &entry_type);
else
header = zip_file_first_file(zip);
@ -291,16 +291,16 @@ file_error zippath_fopen(const char *filename, UINT32 openflags, core_file **fil
goto done;
/* update subpath, if appropriate */
if (astring_len(subpath) == 0)
astring_cpyc(subpath, header->filename);
if (subpath.len() == 0)
subpath.cpy(header->filename);
/* we're done */
goto done;
}
}
if (astring_len(subpath) == 0)
filerr = core_fopen(filename, openflags, file);
if (subpath.len() == 0)
filerr = core_fopen(filename, openflags, &file);
else
filerr = FILERR_NOT_FOUND;
@ -308,56 +308,45 @@ file_error zippath_fopen(const char *filename, UINT32 openflags, core_file **fil
if (filerr != FILERR_NONE)
{
/* go up a directory */
zippath_parent(temp, astring_c(mainpath));
astring temp;
zippath_parent(temp, mainpath);
/* append to the sub path */
if (astring_len(subpath) > 0)
if (subpath.len() > 0)
{
astring_assemble_3(temp2, astring_c(mainpath) + astring_len(temp), PATH_SEPARATOR, astring_c(subpath));
astring_cpy(subpath, temp2);
astring temp2;
temp2.cpysubstr(mainpath, temp.len()).cat(PATH_SEPARATOR).cat(subpath);
subpath.cpy(temp2);
}
else
{
astring_cpyc(subpath, astring_c(mainpath) + astring_len(temp));
}
subpath.cpysubstr(mainpath, temp.len());
/* get the new main path, truncating path separators */
len = astring_len(temp);
while((len > 0) && is_zip_file_separator(astring_c(temp)[len - 1]))
len = temp.len();
while (len > 0 && is_zip_file_separator(temp[len - 1]))
len--;
astring_cpych(mainpath, astring_c(temp), len);
mainpath.cpysubstr(temp, 0, len);
}
}
done:
/* store the revised path if appropriate */
if (revised_path != NULL)
/* store the revised path */
revised_path.reset();
if (filerr == FILERR_NONE)
{
astring_cpyc(revised_path, "");
/* cannonicalize mainpath */
filerr = osd_get_full_path(&alloc_fullpath, mainpath);
if (filerr == FILERR_NONE)
{
/* cannonicalize mainpath */
filerr = osd_get_full_path(&alloc_fullpath, astring_c(mainpath));
if (filerr == FILERR_NONE)
{
if (astring_len(subpath) > 0)
astring_assemble_3(revised_path, alloc_fullpath, PATH_SEPARATOR, astring_c(subpath));
else
astring_cpyc(revised_path, alloc_fullpath);
}
if (subpath.len() > 0)
revised_path.cpy(alloc_fullpath).cat(PATH_SEPARATOR).cat(subpath);
else
revised_path.cpy(alloc_fullpath);
}
}
if (zip != NULL)
zip_file_close(zip);
if (mainpath != NULL)
astring_free(mainpath);
if (subpath != NULL)
astring_free(subpath);
if (temp != NULL)
astring_free(temp);
if (temp2 != NULL)
astring_free(temp2);
if (alloc_fullpath != NULL)
osd_free(alloc_fullpath);
return filerr;
@ -526,32 +515,32 @@ static const zip_file_header *zippath_find_sub_path(zip_file *zipfile, const cha
true path and ZIP entry components
-------------------------------------------------*/
static file_error zippath_resolve(const char *path, osd_dir_entry_type *entry_type,
zip_file **zipfile, astring *newpath)
static file_error zippath_resolve(const char *path, osd_dir_entry_type &entry_type, zip_file *&zipfile, astring &newpath)
{
file_error err;
osd_directory_entry *current_entry = NULL;
osd_dir_entry_type current_entry_type;
astring *apath = astring_cpyc(astring_alloc(), path);
astring *apath_trimmed = astring_alloc();
astring *parent = NULL;
int went_up = FALSE;
int i;
newpath.reset();
/* be conservative */
*entry_type = ENTTYPE_NONE;
*zipfile = NULL;
entry_type = ENTTYPE_NONE;
zipfile = NULL;
astring apath(path);
astring apath_trimmed;
do
{
/* trim the path of trailing path separators */
i = astring_len(apath);
while((i > 1) && is_path_separator(astring_c(apath)[i - 1]))
i = apath.len();
while (i > 1 && is_path_separator(apath[i - 1]))
i--;
apath_trimmed = astring_cpysubstr(apath_trimmed, apath, 0, i);
apath_trimmed.cpysubstr(apath, 0, i);
/* stat the path */
current_entry = osd_stat(astring_c(apath_trimmed));
current_entry = osd_stat(apath_trimmed);
/* did we find anything? */
if (current_entry != NULL)
@ -566,12 +555,11 @@ static file_error zippath_resolve(const char *path, osd_dir_entry_type *entry_ty
/* if we have not found the file or directory, go up */
current_entry_type = ENTTYPE_NONE;
went_up = TRUE;
parent = zippath_parent(astring_alloc(), astring_c(apath));
astring_free(apath);
apath = parent;
astring parent;
apath.cpy(zippath_parent(parent, apath));
}
}
while((current_entry_type == ENTTYPE_NONE) && (apath != NULL) && !is_root(astring_c(apath)));
while (current_entry_type == ENTTYPE_NONE && !is_root(apath));
/* if we did not find anything, then error out */
if (current_entry_type == ENTTYPE_NONE)
@ -581,16 +569,16 @@ static file_error zippath_resolve(const char *path, osd_dir_entry_type *entry_ty
}
/* is this file a ZIP file? */
if ((current_entry_type == ENTTYPE_FILE) && is_zip_file(astring_c(apath_trimmed))
&& (zip_file_open(astring_c(apath_trimmed), zipfile) == ZIPERR_NONE))
if ((current_entry_type == ENTTYPE_FILE) && is_zip_file(apath_trimmed)
&& (zip_file_open(apath_trimmed, &zipfile) == ZIPERR_NONE))
{
i = strlen(path + astring_len(apath));
while((i > 0) && is_zip_path_separator(path[astring_len(apath) + i - 1]))
i = strlen(path + apath.len());
while (i > 0 && is_zip_path_separator(path[apath.len() + i - 1]))
i--;
astring_cpych(newpath, path + astring_len(apath), i);
newpath.cpy(path + apath.len(), i);
/* this was a true ZIP path - attempt to identify the type of path */
zippath_find_sub_path(*zipfile, astring_c(newpath), &current_entry_type);
zippath_find_sub_path(zipfile, newpath, &current_entry_type);
if (current_entry_type == ENTTYPE_NONE)
{
err = FILERR_NOT_FOUND;
@ -605,18 +593,14 @@ static file_error zippath_resolve(const char *path, osd_dir_entry_type *entry_ty
err = FILERR_NOT_FOUND;
goto done;
}
astring_cpyc(newpath, path);
newpath.cpy(path);
}
/* success! */
*entry_type = current_entry_type;
entry_type = current_entry_type;
err = FILERR_NONE;
done:
if (apath != NULL)
astring_free(apath);
if (apath_trimmed != NULL)
astring_free(apath_trimmed);
return err;
}
@ -628,21 +612,18 @@ done:
file_error zippath_opendir(const char *path, zippath_directory **directory)
{
file_error err;
osd_dir_entry_type entry_type;
astring *newpath = astring_alloc();
zippath_directory *result;
/* allocate a directory */
result = (zippath_directory *) malloc(sizeof(*result));
zippath_directory *result = new(std::nothrow) zippath_directory;
if (result == NULL)
{
err = FILERR_OUT_OF_MEMORY;
goto done;
}
memset(result, 0, sizeof(*result));
/* resolve the path */
err = zippath_resolve(path, &entry_type, &result->zipfile, newpath);
osd_dir_entry_type entry_type;
err = zippath_resolve(path, entry_type, result->zipfile, result->zipprefix);
if (err != FILERR_NONE)
goto done;
@ -654,12 +635,7 @@ file_error zippath_opendir(const char *path, zippath_directory **directory)
}
/* was the result a ZIP? */
if (result->zipfile != NULL)
{
result->zipprefix = newpath;
newpath = NULL;
}
else
if (result->zipfile == NULL)
{
/* a conventional directory */
result->directory = osd_opendir(path);
@ -671,20 +647,15 @@ file_error zippath_opendir(const char *path, zippath_directory **directory)
/* is this path the root? if so, pretend we've already returned the parent */
if (is_root(path))
result->returned_parent = TRUE;
result->returned_parent = true;
}
done:
if (((directory == NULL) || (err != FILERR_NONE)) && (result != NULL))
if ((directory == NULL || err != FILERR_NONE) && result != NULL)
{
zippath_closedir(result);
result = NULL;
}
if (newpath != NULL)
{
astring_free(newpath);
newpath = NULL;
}
if (directory != NULL)
*directory = result;
return err;
@ -697,25 +668,20 @@ done:
void zippath_closedir(zippath_directory *directory)
{
zippath_returned_directory *dirlist;
if (directory->directory != NULL)
osd_closedir(directory->directory);
if (directory->zipfile != NULL)
zip_file_close(directory->zipfile);
if (directory->zipprefix != NULL)
astring_free(directory->zipprefix);
while(directory->returned_dirlist != NULL)
while (directory->returned_dirlist != NULL)
{
dirlist = directory->returned_dirlist;
zippath_returned_directory *dirlist = directory->returned_dirlist;
directory->returned_dirlist = directory->returned_dirlist->next;
free(dirlist);
delete dirlist;
}
free(directory);
delete directory;
}
@ -728,10 +694,10 @@ void zippath_closedir(zippath_directory *directory)
static const char *get_relative_path(zippath_directory *directory, const zip_file_header *header)
{
const char *result = NULL;
int len = astring_len(directory->zipprefix);
int len = directory->zipprefix.len();
if ((len <= strlen(header->filename))
&& !strncmp(astring_c(directory->zipprefix), header->filename, len))
&& !strncmp(directory->zipprefix, header->filename, len))
{
result = &header->filename[len];
while(is_zip_file_separator(*result))
@ -758,7 +724,7 @@ const osd_directory_entry *zippath_readdir(zippath_directory *directory)
if (!directory->returned_parent)
{
/* first thing's first - return parent directory */
directory->returned_parent = TRUE;
directory->returned_parent = true;
memset(&directory->returned_entry, 0, sizeof(directory->returned_entry));
directory->returned_entry.name = "..";
directory->returned_entry.type = ENTTYPE_DIR;
@ -793,7 +759,7 @@ const osd_directory_entry *zippath_readdir(zippath_directory *directory)
header = zip_file_first_file(directory->zipfile);
else
header = zip_file_next_file(directory->zipfile);
directory->called_zip_first = TRUE;
directory->called_zip_first = true;
relpath = NULL;
}
while((header != NULL) && ((relpath = get_relative_path(directory, header)) == NULL));
@ -817,10 +783,9 @@ const osd_directory_entry *zippath_readdir(zippath_directory *directory)
if (rdent == NULL)
{
/* we've found a new directory; add this to returned_dirlist */
rdent = (zippath_returned_directory *)malloc(sizeof(*rdent) + (separator - relpath));
rdent = new zippath_returned_directory;
rdent->next = directory->returned_dirlist;
memcpy(rdent->name, relpath, (separator - relpath) * sizeof(rdent->name[0]));
rdent->name[separator - relpath] = '\0';
rdent->name.cpy(relpath, separator - relpath);
directory->returned_dirlist = rdent;
/* ...and return it */

View File

@ -14,14 +14,13 @@
#include "corefile.h"
#include "astring.h"
#include "unzip.h"
#include "astring.h"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef struct _zippath_directory zippath_directory;
class zippath_directory;
@ -32,19 +31,19 @@ typedef struct _zippath_directory zippath_directory;
/* ----- path operations ----- */
/* retrieves the parent directory */
astring *zippath_parent(astring *dst, const char *path);
astring &zippath_parent(astring &dst, const char *path);
/* retrieves the parent directory basename */
astring *zippath_parent_basename(astring *dst, const char *path);
astring &zippath_parent_basename(astring &dst, const char *path);
/* combines two paths */
astring *zippath_combine(astring *dst, const char *path1, const char *path2);
astring &zippath_combine(astring &dst, const char *path1, const char *path2);
/* ----- file operations ----- */
/* opens a zip path file */
file_error zippath_fopen(const char *filename, UINT32 openflags, core_file **file, astring *revised_path);
file_error zippath_fopen(const char *filename, UINT32 openflags, core_file *&file, astring &revised_path);
/* ----- directory operations ----- */

View File

@ -515,14 +515,12 @@ static MACHINE_RESET( jaguar )
static emu_file *jaguar_nvram_fopen( running_machine &machine, UINT32 openflags)
{
device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart"));
astring *fname;
file_error filerr;
emu_file *file;
if (image->exists())
{
fname = astring_assemble_4( astring_alloc(), machine.system().name, PATH_SEPARATOR, image->basename_noext(), ".nv");
filerr = mame_fopen( SEARCHPATH_NVRAM, astring_c( fname), openflags, &file);
astring_free( fname);
astring fname(machine.system().name, PATH_SEPARATOR, image->basename_noext(), ".nv");
filerr = mame_fopen( SEARCHPATH_NVRAM, fname, openflags, &file);
return (filerr == FILERR_NONE) ? file : NULL;
}
else

View File

@ -706,7 +706,7 @@ osd_font sdl_osd_interface::font_open(const char *_name, int &height)
/* handle bdf fonts in the core */
if (name.len() > 4)
if (name.toupper().substr(name.len()-4,4) == ".BDF" )
if (name.makeupper().substr(name.len()-4,4) == ".BDF" )
return NULL;
font_name = CFStringCreateWithCString( NULL, _name, kCFStringEncodingUTF8 );

View File

@ -180,15 +180,15 @@ static int CLIB_DECL compare_file(const void *file0ptr, const void *file1ptr);
static summary_file *sort_file_list(void);
/* HTML helpers */
static core_file *create_file_and_output_header(const astring *filename, const astring *templatefile, const astring *title);
static void output_footer_and_close_file(core_file *file, const astring *templatefile, const astring *title);
static core_file *create_file_and_output_header(astring &filename, astring &templatefile, astring &title);
static void output_footer_and_close_file(core_file *file, astring &templatefile, astring &title);
/* report generators */
static void output_report(const astring *dirname, const astring *tempheader, const astring *tempfooter, summary_file *filelist);
static void output_report(astring &dirname, astring &tempheader, astring &tempfooter, summary_file *filelist);
static int compare_screenshots(summary_file *curfile);
static int generate_png_diff(const summary_file *curfile, const astring *destdir, const char *destname);
static void create_linked_file(const astring *dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, const char *pngfile, const astring *tempheader, const astring *tempfooter);
static void append_driver_list_table(const char *header, const astring *dirname, core_file *indexfile, const summary_file *listhead, const astring *tempheader, const astring *tempfooter);
static int generate_png_diff(const summary_file *curfile, astring &destdir, const char *destname);
static void create_linked_file(astring &dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, const char *pngfile, astring &tempheader, astring &tempfooter);
static void append_driver_list_table(const char *header, astring &dirname, core_file *indexfile, const summary_file *listhead, astring &tempheader, astring &tempfooter);
@ -250,7 +250,6 @@ INLINE int get_unique_index(const summary_file *curfile, int index)
int main(int argc, char *argv[])
{
astring *dirname = NULL, *tempfilename = NULL, *tempheader = NULL, *tempfooter = NULL;
UINT32 bufsize;
void *buffer;
int listnum;
@ -262,31 +261,33 @@ int main(int argc, char *argv[])
fprintf(stderr, "Usage:\nregrep <template> <outputdir> <summary1> [<summary2> [<summary3> ...]]\n");
return 1;
}
tempfilename = astring_dupc(argv[1]);
dirname = astring_dupc(argv[2]);
astring tempfilename(argv[1]);
astring dirname(argv[2]);
list_count = argc - 3;
/* read the template file into an astring */
if (core_fload(astring_c(tempfilename), &buffer, &bufsize) == FILERR_NONE)
astring tempheader;
if (core_fload(tempfilename, &buffer, &bufsize) == FILERR_NONE)
{
tempheader = astring_dupch((const char *)buffer, bufsize);
tempheader.cpy((const char *)buffer, bufsize);
osd_free(buffer);
}
/* verify the template */
if (tempheader == NULL)
if (tempheader.len() == 0)
{
fprintf(stderr, "Unable to read template file\n");
return 1;
}
result = astring_findc(tempheader, 0, "<!--CONTENT-->");
result = tempheader.find(0, "<!--CONTENT-->");
if (result == -1)
{
fprintf(stderr, "Template is missing a <!--CONTENT--> marker\n");
return 1;
}
tempfooter = astring_substr(astring_dup(tempheader), result + 14, -1);
tempheader = astring_substr(tempheader, 0, result);
astring tempfooter(tempheader);
tempfooter.substr(result + 14);
tempheader.substr(0, result);
/* loop over arguments and read the files */
for (listnum = 0; listnum < list_count; listnum++)
@ -298,11 +299,6 @@ int main(int argc, char *argv[])
/* output the summary */
output_report(dirname, tempheader, tempfooter, sort_file_list());
astring_free(dirname);
astring_free(tempfilename);
astring_free(tempheader);
astring_free(tempfooter);
return 0;
}
@ -613,22 +609,20 @@ static summary_file *sort_file_list(void)
HTML file with a standard header
-------------------------------------------------*/
static core_file *create_file_and_output_header(const astring *filename, const astring *templatefile, const astring *title)
static core_file *create_file_and_output_header(astring &filename, astring &templatefile, astring &title)
{
astring *modified;
core_file *file;
/* create the indexfile */
if (core_fopen(astring_c(filename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, &file) != FILERR_NONE)
if (core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS | OPEN_FLAG_NO_BOM, &file) != FILERR_NONE)
return NULL;
/* print a header */
modified = astring_dup(templatefile);
astring_replacec(modified, 0, "<!--TITLE-->", astring_c(title));
core_fwrite(file, astring_c(modified), astring_len(modified));
astring modified(templatefile);
modified.replace("<!--TITLE-->", title);
core_fwrite(file, modified.cstr(), modified.len());
/* return the file */
astring_free(modified);
return file;
}
@ -638,14 +632,11 @@ static core_file *create_file_and_output_header(const astring *filename, const a
standard footer to an HTML file and close it
-------------------------------------------------*/
static void output_footer_and_close_file(core_file *file, const astring *templatefile, const astring *title)
static void output_footer_and_close_file(core_file *file, astring &templatefile, astring &title)
{
astring *modified;
modified = astring_dup(templatefile);
astring_replacec(modified, 0, "<!--TITLE-->", astring_c(title));
core_fwrite(file, astring_c(modified), astring_len(modified));
astring_free(modified);
astring modified(templatefile);
modified.replace(0, "<!--TITLE-->", title);
core_fwrite(file, modified.cstr(), modified.len());
core_fclose(file);
}
@ -660,12 +651,12 @@ static void output_footer_and_close_file(core_file *file, const astring *templat
report HTML files
-------------------------------------------------*/
static void output_report(const astring *dirname, const astring *tempheader, const astring *tempfooter, summary_file *filelist)
static void output_report(astring &dirname, astring &tempheader, astring &tempfooter, summary_file *filelist)
{
summary_file *buckethead[BUCKET_COUNT], **buckettailptr[BUCKET_COUNT];
summary_file *curfile;
astring *title = astring_dupc("MAME Regressions");
astring *tempname = astring_alloc();
astring title("MAME Regressions");
astring tempname;
int listnum, bucknum;
core_file *indexfile;
int count = 0, total;
@ -744,13 +735,11 @@ static void output_report(const astring *dirname, const astring *tempheader, con
*buckettailptr[bucknum] = NULL;
/* output header */
astring_printf(tempname, "%s" PATH_SEPARATOR "%s", astring_c(dirname), "index.html");
tempname.printf("%s" PATH_SEPARATOR "%s", dirname.cstr(), "index.html");
indexfile = create_file_and_output_header(tempname, tempheader, title);
if (indexfile == NULL)
{
fprintf(stderr, "Error creating file '%s'\n", astring_c(tempname));
astring_free(tempname);
astring_free(title);
fprintf(stderr, "Error creating file '%s'\n", tempname.cstr());
return;
}
@ -768,8 +757,6 @@ static void output_report(const astring *dirname, const astring *tempheader, con
/* output footer */
output_footer_and_close_file(indexfile, tempfooter, title);
astring_free(tempname);
astring_free(title);
}
@ -791,24 +778,24 @@ static int compare_screenshots(summary_file *curfile)
bitmaps[listnum] = NULL;
if (curfile->status[listnum] == STATUS_SUCCESS)
{
astring *fullname = astring_alloc();
astring fullname;
file_error filerr;
core_file *file;
/* get the filename for the image */
astring_printf(fullname, "%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", lists[listnum].dir, curfile->name);
fullname.printf("%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", lists[listnum].dir, curfile->name);
/* open the file */
filerr = core_fopen(astring_c(fullname), OPEN_FLAG_READ, &file);
filerr = core_fopen(fullname, OPEN_FLAG_READ, &file);
/* if that failed, look in the old location */
if (filerr != FILERR_NONE)
{
/* get the filename for the image */
astring_printf(fullname, "%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "_%s.png", lists[listnum].dir, curfile->name);
fullname.printf("%s" PATH_SEPARATOR "snap" PATH_SEPARATOR "_%s.png", lists[listnum].dir, curfile->name);
/* open the file */
filerr = core_fopen(astring_c(fullname), OPEN_FLAG_READ, &file);
filerr = core_fopen(fullname, OPEN_FLAG_READ, &file);
}
/* if that worked, load the file */
@ -817,7 +804,6 @@ static int compare_screenshots(summary_file *curfile)
png_read_bitmap(file, &bitmaps[listnum]);
core_fclose(file);
}
astring_free(fullname);
}
}
@ -898,12 +884,12 @@ static int compare_screenshots(summary_file *curfile)
side with a third set of differences
-------------------------------------------------*/
static int generate_png_diff(const summary_file *curfile, const astring *destdir, const char *destname)
static int generate_png_diff(const summary_file *curfile, astring &destdir, const char *destname)
{
bitmap_t *bitmaps[MAX_COMPARES] = { NULL };
astring *srcimgname = astring_alloc();
astring *dstfilename = astring_alloc();
astring *tempname = astring_alloc();
astring srcimgname;
astring dstfilename;
astring tempname;
bitmap_t *finalbitmap = NULL;
int width, height, maxwidth;
int bitmapcount = 0;
@ -915,17 +901,17 @@ static int generate_png_diff(const summary_file *curfile, const astring *destdir
int starty;
/* generate the common source filename */
astring_printf(dstfilename, "%s" PATH_SEPARATOR "%s", astring_c(destdir), destname);
astring_printf(srcimgname, "snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name);
dstfilename.printf("%s" PATH_SEPARATOR "%s", destdir.cstr(), destname);
srcimgname.printf("snap" PATH_SEPARATOR "%s" PATH_SEPARATOR "final.png", curfile->name);
/* open and load all unique bitmaps */
for (listnum = 0; listnum < list_count; listnum++)
if (curfile->matchbitmap[listnum] == listnum)
{
astring_printf(tempname, "%s" PATH_SEPARATOR "%s", lists[listnum].dir, astring_c(srcimgname));
tempname.printf("%s" PATH_SEPARATOR "%s", lists[listnum].dir, srcimgname.cstr());
/* open the source image */
filerr = core_fopen(astring_c(tempname), OPEN_FLAG_READ, &file);
filerr = core_fopen(tempname, OPEN_FLAG_READ, &file);
if (filerr != FILERR_NONE)
goto error;
@ -999,7 +985,7 @@ static int generate_png_diff(const summary_file *curfile, const astring *destdir
}
/* write the final PNG */
filerr = core_fopen(astring_c(dstfilename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
filerr = core_fopen(dstfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
if (filerr != FILERR_NONE)
goto error;
pngerr = png_write_bitmap(file, NULL, *finalbitmap, 0, NULL);
@ -1015,10 +1001,7 @@ error:
for (bmnum = 0; bmnum < bitmapcount; bmnum++)
delete bitmaps[bmnum];
if (error)
osd_rmfile(astring_c(dstfilename));
astring_free(dstfilename);
astring_free(srcimgname);
astring_free(tempname);
osd_rmfile(dstfilename);
return error;
}
@ -1028,27 +1011,24 @@ error:
file between differing versions
-------------------------------------------------*/
static void create_linked_file(const astring *dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, const char *pngfile, const astring *tempheader, const astring *tempfooter)
static void create_linked_file(astring &dirname, const summary_file *curfile, const summary_file *prevfile, const summary_file *nextfile, const char *pngfile, astring &tempheader, astring &tempfooter)
{
astring *linkname = astring_alloc();
astring *filename = astring_alloc();
astring *title = astring_alloc();
astring linkname;
astring filename;
astring title;
core_file *linkfile;
int listnum;
/* create the filename */
astring_printf(filename, "%s.html", curfile->name);
filename.printf("%s.html", curfile->name);
/* output header */
astring_printf(title, "%s Regressions (%s)", curfile->name, curfile->source);
astring_printf(linkname, "%s" PATH_SEPARATOR "%s", astring_c(dirname), astring_c(filename));
title.printf("%s Regressions (%s)", curfile->name, curfile->source);
linkname.printf("%s" PATH_SEPARATOR "%s", dirname.cstr(), filename.cstr());
linkfile = create_file_and_output_header(linkname, tempheader, title);
if (linkfile == NULL)
{
fprintf(stderr, "Error creating file '%s'\n", astring_c(filename));
astring_free(title);
astring_free(filename);
astring_free(linkname);
fprintf(stderr, "Error creating file '%s'\n", filename.cstr());
return;
}
@ -1101,9 +1081,6 @@ static void create_linked_file(const astring *dirname, const summary_file *curfi
/* output footer */
output_footer_and_close_file(linkfile, tempfooter, title);
astring_free(title);
astring_free(filename);
astring_free(linkname);
}
@ -1112,7 +1089,7 @@ static void create_linked_file(const astring *dirname, const summary_file *curfi
of drivers from a list to an HTML file
-------------------------------------------------*/
static void append_driver_list_table(const char *header, const astring *dirname, core_file *indexfile, const summary_file *listhead, const astring *tempheader, const astring *tempfooter)
static void append_driver_list_table(const char *header, astring &dirname, core_file *indexfile, const summary_file *listhead, astring &tempheader, astring &tempfooter)
{
const summary_file *curfile, *prevfile;
int width = 100 / (2 + list_count);

View File

@ -61,7 +61,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(astring &buffer, void *data, UINT32 length)
{
char expanded[SHA1_DIGEST_SIZE * 2];
UINT8 sha1digest[SHA1_DIGEST_SIZE];
@ -82,7 +82,7 @@ static void compute_hash_as_string(astring *buffer, void *data, UINT32 length)
}
// copy it to the buffer
astring_cpych(buffer, expanded, sizeof(expanded));
buffer.cpy(expanded, sizeof(expanded));
}
@ -92,9 +92,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 = astring_alloc(), *basefilename = astring_alloc(), *splitfilename = astring_alloc();
astring outfilename, basefilename, splitfilename;
core_file *outfile = NULL, *infile = NULL, *splitfile = NULL;
astring *computedhash = astring_alloc();
astring computedhash;
void *splitbuffer = NULL;
int index, partnum;
UINT64 totallength;
@ -139,29 +139,28 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
}
// find the base name of the file
astring_cpyc(basefilename, basename);
index = astring_rchr(basefilename, 0, PATH_SEPARATOR[0]);
basefilename.cpy(basename);
index = basefilename.rchr(0, PATH_SEPARATOR[0]);
if (index != -1)
astring_del(basefilename, 0, index + 1);
basefilename.del(0, index + 1);
// compute the split filename
astring_cpyc(splitfilename, basename);
astring_catc(splitfilename, ".split");
splitfilename.cpy(basename).cat(".split");
// create the split file
filerr = core_fopen(astring_c(splitfilename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &splitfile);
filerr = core_fopen(splitfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &splitfile);
if (filerr != FILERR_NONE)
{
fprintf(stderr, "Fatal error: unable to create split file '%s'\n", astring_c(splitfilename));
fprintf(stderr, "Fatal error: unable to create split file '%s'\n", splitfilename.cstr());
goto cleanup;
}
// write the basics out
core_fprintf(splitfile, "splitfile=%s\n", astring_c(basefilename));
core_fprintf(splitfile, "splitfile=%s\n", basefilename.cstr());
core_fprintf(splitfile, "splitsize=%d\n", splitsize);
printf("Split file is '%s'\n", astring_c(splitfilename));
printf("Splitting file %s into chunks of %dMB...\n", astring_c(basefilename), splitsize / (1024 * 1024));
printf("Split file is '%s'\n", splitfilename.cstr());
printf("Splitting file %s into chunks of %dMB...\n", basefilename.cstr(), splitsize / (1024 * 1024));
// now iterate until done
for (partnum = 0; partnum < 1000; partnum++)
@ -179,21 +178,21 @@ static int split_file(const char *filename, const char *basename, UINT32 splitsi
compute_hash_as_string(computedhash, splitbuffer, length);
// write that info to the split file
core_fprintf(splitfile, "hash=%s file=%s.%03d\n", astring_c(computedhash), astring_c(basefilename), partnum);
core_fprintf(splitfile, "hash=%s file=%s.%03d\n", computedhash.cstr(), basefilename.cstr(), partnum);
// compute the full filename for this guy
astring_printf(outfilename, "%s.%03d", basename, partnum);
outfilename.printf("%s.%03d", basename, partnum);
// create it
filerr = core_fopen(astring_c(outfilename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile);
filerr = core_fopen(outfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile);
if (filerr != FILERR_NONE)
{
printf("\n");
fprintf(stderr, "Fatal error: unable to create output file '%s'\n", astring_c(outfilename));
fprintf(stderr, "Fatal error: unable to create output file '%s'\n", outfilename.cstr());
goto cleanup;
}
printf(" writing %s.%03d...", astring_c(basefilename), partnum);
printf(" writing %s.%03d...", basefilename.cstr(), partnum);
// write the data
actual = core_fwrite(outfile, splitbuffer, length);
@ -222,7 +221,7 @@ cleanup:
{
core_fclose(splitfile);
if (error != 0)
remove(astring_c(splitfilename));
remove(splitfilename);
}
if (infile != NULL)
core_fclose(infile);
@ -230,14 +229,10 @@ cleanup:
{
core_fclose(outfile);
if (error != 0)
remove(astring_c(outfilename));
remove(outfilename);
}
if (splitbuffer != NULL)
free(splitbuffer);
astring_free(splitfilename);
astring_free(basefilename);
astring_free(outfilename);
astring_free(computedhash);
return error;
}
@ -249,9 +244,9 @@ cleanup:
static int join_file(const char *filename, const char *outname, int write_output)
{
astring *expectedhash = astring_alloc(), *computedhash = astring_alloc();
astring *outfilename = astring_alloc(), *infilename = astring_alloc();
astring *basepath = astring_alloc();
astring expectedhash, computedhash;
astring outfilename, infilename;
astring basepath;
core_file *outfile = NULL, *infile = NULL, *splitfile = NULL;
void *splitbuffer = NULL;
file_error filerr;
@ -274,21 +269,21 @@ 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;
}
astring_trimspace(astring_cpyc(outfilename, buffer + 10));
outfilename.cpy(buffer + 10).trimspace();
// compute the base path
astring_cpyc(basepath, filename);
index = astring_rchr(basepath, 0, PATH_SEPARATOR[0]);
basepath.cpy(filename);
index = basepath.rchr(0, PATH_SEPARATOR[0]);
if (index != -1)
astring_del(basepath, index + 1, -1);
basepath.del(index + 1);
else
astring_reset(basepath);
basepath.reset();
// override the output filename if specified, otherwise prepend the path
if (outname != NULL)
astring_cpyc(outfilename, outname);
outfilename.cpy(outname);
else
astring_ins(outfilename, 0, basepath);
outfilename.ins(0, basepath);
// read the split size
if (!core_fgets(buffer, sizeof(buffer), splitfile) || sscanf(buffer, "splitsize=%d", &splitsize) != 1)
@ -301,25 +296,25 @@ static int join_file(const char *filename, const char *outname, int write_output
if (write_output)
{
// don't overwrite the original!
filerr = core_fopen(astring_c(outfilename), OPEN_FLAG_READ, &outfile);
filerr = core_fopen(outfilename, OPEN_FLAG_READ, &outfile);
if (filerr == FILERR_NONE)
{
core_fclose(outfile);
outfile = NULL;
fprintf(stderr, "Fatal error: output file '%s' already exists\n", astring_c(outfilename));
fprintf(stderr, "Fatal error: output file '%s' already exists\n", outfilename.cstr());
goto cleanup;
}
// open the output for write
filerr = core_fopen(astring_c(outfilename), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile);
filerr = core_fopen(outfilename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &outfile);
if (filerr != FILERR_NONE)
{
fprintf(stderr, "Fatal error: unable to create file '%s'\n", astring_c(outfilename));
fprintf(stderr, "Fatal error: unable to create file '%s'\n", outfilename.cstr());
goto cleanup;
}
}
printf("%s file '%s'...\n", write_output ? "Joining" : "Verifying", astring_c(outfilename));
printf("%s file '%s'...\n", write_output ? "Joining" : "Verifying", outfilename.cstr());
// now iterate through each file
while (core_fgets(buffer, sizeof(buffer), splitfile))
@ -332,18 +327,18 @@ 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;
}
astring_cpych(expectedhash, buffer + 5, SHA1_DIGEST_SIZE * 2);
astring_trimspace(astring_cpyc(infilename, buffer + 5 + SHA1_DIGEST_SIZE * 2 + 6));
expectedhash.cpy(buffer + 5, SHA1_DIGEST_SIZE * 2);
infilename.cpy(buffer + 5 + SHA1_DIGEST_SIZE * 2 + 6).trimspace();
printf(" Reading file '%s'...", astring_c(infilename));
printf(" Reading file '%s'...", infilename.cstr());
// read the file's contents
astring_ins(infilename, 0, basepath);
filerr = core_fload(astring_c(infilename), &splitbuffer, &length);
infilename.ins(0, basepath);
filerr = core_fload(infilename, &splitbuffer, &length);
if (filerr != FILERR_NONE)
{
printf("\n");
fprintf(stderr, "Fatal error: unable to load file '%s'\n", astring_c(infilename));
fprintf(stderr, "Fatal error: unable to load file '%s'\n", infilename.cstr());
goto cleanup;
}
@ -351,10 +346,10 @@ static int join_file(const char *filename, const char *outname, int write_output
compute_hash_as_string(computedhash, splitbuffer, length);
// compare
if (astring_cmp(computedhash, expectedhash) != 0)
if (computedhash != expectedhash)
{
printf("\n");
fprintf(stderr, "Fatal error: file '%s' has incorrect hash\n Expected: %s\n Computed: %s\n", astring_c(infilename), astring_c(expectedhash), astring_c(computedhash));
fprintf(stderr, "Fatal error: file '%s' has incorrect hash\n Expected: %s\n Computed: %s\n", infilename.cstr(), expectedhash.cstr(), computedhash.cstr());
goto cleanup;
}
@ -397,15 +392,10 @@ cleanup:
{
core_fclose(outfile);
if (error != 0)
remove(astring_c(outfilename));
remove(outfilename);
}
if (splitbuffer != NULL)
osd_free(splitbuffer);
astring_free(outfilename);
astring_free(infilename);
astring_free(basepath);
astring_free(expectedhash);
astring_free(computedhash);
return error;
}

File diff suppressed because it is too large Load Diff