summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/src2html.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/src2html.c')
-rw-r--r--src/tools/src2html.c184
1 files changed, 93 insertions, 91 deletions
diff --git a/src/tools/src2html.c b/src/tools/src2html.c
index 33dd77604f4..91780cd2fc6 100644
--- a/src/tools/src2html.c
+++ b/src/tools/src2html.c
@@ -21,7 +21,7 @@
#include <ctype.h>
#include <assert.h>
#include "osdcore.h"
-#include "astring.h"
+#include "corestr.h"
#include "corefile.h"
@@ -66,14 +66,14 @@ struct token_entry
struct include_path
{
include_path * next;
- astring path;
+ std::string path;
};
struct list_entry
{
list_entry * next;
- astring name;
+ std::string name;
};
@@ -202,17 +202,17 @@ static const token_entry c_token_table[] =
***************************************************************************/
// core output functions
-static int recurse_dir(int srcrootlen, int dstrootlen, astring &srcdir, astring &dstdir, astring &tempheader, astring &tempfooter);
-static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &srcfile, astring &dstfile, bool link_to_file, astring &tempheader, astring &tempfooter);
+static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std::string &dstdir, std::string &tempheader, std::string &tempfooter);
+static int output_file(file_type type, int srcrootlen, int dstrootlen, std::string &srcfile, std::string &dstfile, bool link_to_file, std::string &tempheader, std::string &tempfooter);
// HTML helpers
-static core_file *create_file_and_output_header(astring &filename, astring &templatefile, astring &path);
-static void output_footer_and_close_file(core_file *file, astring &templatefile, astring &path);
+static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path);
+static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &path);
// path helpers
-static astring &normalized_subpath(astring &dest, astring &path, int start);
-static void output_path_as_links(core_file *file, astring &path, bool end_is_directory, bool link_to_file);
-static bool find_include_file(astring &srcincpath, int srcrootlen, int dstrootlen, astring &srcfile, astring &dstfile, astring &filename);
+static std::string &normalized_subpath(std::string &dest, std::string &path, int start);
+static void output_path_as_links(core_file *file, std::string &path, bool end_is_directory, bool link_to_file);
+static bool find_include_file(std::string &srcincpath, int srcrootlen, int dstrootlen, std::string &srcfile, std::string &dstfile, std::string &filename);
@@ -234,7 +234,7 @@ int main(int argc, char *argv[])
{
// loop over arguments
include_path **incpathhead = &incpaths;
- astring srcdir, dstdir, tempfilename, tempheader, tempfooter;
+ std::string srcdir, dstdir, tempfilename, tempheader, tempfooter;
int unadorned = 0;
for (int argnum = 1; argnum < argc; argnum++)
{
@@ -247,7 +247,7 @@ int main(int argc, char *argv[])
if (*incpathhead != NULL)
{
(*incpathhead)->next = NULL;
- (*incpathhead)->path.cpy(&arg[2]).replacechr('/', PATH_SEPARATOR[0]);
+ strreplacechr((*incpathhead)->path.assign(&arg[2]), '/', PATH_SEPARATOR[0]);
incpathhead = &(*incpathhead)->next;
}
}
@@ -255,17 +255,17 @@ int main(int argc, char *argv[])
// other parameter
else if (arg[0] != '-' && unadorned == 0)
{
- srcdir.cpy(arg);
+ srcdir.assign(arg);
unadorned++;
}
else if (arg[0] != '-' && unadorned == 1)
{
- dstdir.cpy(arg);
+ dstdir.assign(arg);
unadorned++;
}
else if (arg[0] != '-' && unadorned == 2)
{
- tempfilename.cpy(arg);
+ tempfilename.assign(arg);
unadorned++;
}
else
@@ -273,35 +273,35 @@ int main(int argc, char *argv[])
}
// make sure we got 3 parameters
- if (srcdir.len() == 0 || dstdir.len() == 0 || tempfilename.len() == 0)
+ if (srcdir.length() == 0 || dstdir.length() == 0 || tempfilename.length() == 0)
usage(argv[0]);
- // read the template file into an astring
+ // read the template file into an std::string
UINT32 bufsize;
void *buffer;
if (core_fload(tempfilename.c_str(), &buffer, &bufsize) == FILERR_NONE)
{
- tempheader.cpy((const char *)buffer, bufsize);
+ tempheader.assign((const char *)buffer, bufsize);
osd_free(buffer);
}
// verify the template
- if (tempheader.len() == 0)
+ if (tempheader.length() == 0)
{
fprintf(stderr, "Unable to read template file\n");
return 1;
}
- int result = tempheader.find(0, "<!--CONTENT-->");
+ int result = tempheader.find("<!--CONTENT-->");
if (result == -1)
{
fprintf(stderr, "Template is missing a <!--CONTENT--> marker\n");
return 1;
}
- tempfooter.cpy(tempheader).substr(result + 14, -1);
+ tempfooter.assign(tempheader).substr(result + 14, -1);
tempheader.substr(0, result);
// recurse over subdirectories
- return recurse_dir(srcdir.len(), dstdir.len(), srcdir, dstdir, tempheader, tempfooter);
+ return recurse_dir(srcdir.length(), dstdir.length(), srcdir, dstdir, tempheader, tempfooter);
}
@@ -314,7 +314,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 entry1->name.cmp(entry2->name);
+ return entry1->name.compare(entry2->name);
}
@@ -322,17 +322,17 @@ static int compare_list_entries(const void *p1, const void *p2)
recurse_dir - recurse through a directory
-------------------------------------------------*/
-static int recurse_dir(int srcrootlen, int dstrootlen, astring &srcdir, astring &dstdir, astring &tempheader, astring &tempfooter)
+static int recurse_dir(int srcrootlen, int dstrootlen, std::string &srcdir, std::string &dstdir, std::string &tempheader, std::string &tempfooter)
{
static const osd_dir_entry_type typelist[] = { ENTTYPE_DIR, ENTTYPE_FILE };
// extract a normalized subpath
- astring srcdir_subpath;
+ std::string srcdir_subpath;
normalized_subpath(srcdir_subpath, srcdir, srcrootlen + 1);
// create an index file
- astring indexname;
- indexname.printf("%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], "index.html");
+ std::string indexname;
+ strprintf(indexname,"%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], "index.html");
core_file *indexfile = create_file_and_output_header(indexname, tempheader, srcdir_subpath);
// output the directory navigation
@@ -362,7 +362,7 @@ static int recurse_dir(int srcrootlen, int dstrootlen, astring &srcdir, astring
if (entry->type == entry_type && entry->name[0] != '.')
{
list_entry *lentry = new list_entry;
- lentry->name.cpy(entry->name);
+ lentry->name.assign(entry->name);
lentry->next = list;
list = lentry;
found++;
@@ -401,11 +401,11 @@ static int recurse_dir(int srcrootlen, int dstrootlen, astring &srcdir, astring
core_fprintf(indexfile, "\t<h2>%s</h2>\n\t<ul>\n", (entry_type == ENTTYPE_DIR) ? "Directories" : "Files");
// build the source filename
- astring srcfile;
- srcfile.printf("%s%c%s", srcdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
+ std::string srcfile;
+ strprintf(srcfile, "%s%c%s", srcdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
// if we have a file, output it
- astring dstfile;
+ std::string dstfile;
if (entry_type == ENTTYPE_FILE)
{
// make sure we care, first
@@ -420,17 +420,17 @@ static int recurse_dir(int srcrootlen, int dstrootlen, astring &srcdir, astring
// if we got a valid file, process it
if (type != FILE_TYPE_INVALID)
{
- dstfile.printf("%s%c%s.html", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
+ strprintf(dstfile, "%s%c%s.html", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
if (indexfile != NULL)
core_fprintf(indexfile, "\t<li><a href=\"%s.html\">%s</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
- result = output_file(type, srcrootlen, dstrootlen, srcfile, dstfile, srcdir == dstdir, tempheader, tempfooter);
+ result = output_file(type, srcrootlen, dstrootlen, srcfile, dstfile, srcdir.compare(dstdir) == 0, tempheader, tempfooter);
}
}
// if we have a directory, recurse
else
{
- dstfile.printf("%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
+ strprintf(dstfile, "%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str());
if (indexfile != NULL)
core_fprintf(indexfile, "\t<li><a href=\"%s/index.html\">%s/</a></li>\n", curlist->name.c_str(), curlist->name.c_str());
result = recurse_dir(srcrootlen, dstrootlen, srcfile, dstfile, tempheader, tempfooter);
@@ -461,10 +461,10 @@ static int recurse_dir(int srcrootlen, int dstrootlen, astring &srcdir, astring
HTML
-------------------------------------------------*/
-static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &srcfile, astring &dstfile, bool link_to_file, astring &tempheader, astring &tempfooter)
+static int output_file(file_type type, int srcrootlen, int dstrootlen, std::string &srcfile, std::string &dstfile, bool link_to_file, std::string &tempheader, std::string &tempfooter)
{
// extract a normalized subpath
- astring srcfile_subpath;
+ std::string srcfile_subpath;
normalized_subpath(srcfile_subpath, srcfile, srcrootlen + 1);
fprintf(stderr, "Processing %s\n", srcfile_subpath.c_str());
@@ -547,8 +547,8 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
while (core_fgets(srcline, ARRAY_LENGTH(srcline), src) != NULL)
{
// start with the line number
- astring dstline;
- dstline.catprintf("<span class=\"linenum\">%5d</span>&nbsp;&nbsp;", linenum++);
+ std::string dstline;
+ strcatprintf(dstline, "<span class=\"linenum\">%5d</span>&nbsp;&nbsp;", linenum++);
// iterate over characters in the source line
bool escape = false;
@@ -568,7 +568,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
{
if (!in_comment && ch == comment_start[0] && strncmp(srcptr - 1, comment_start, strlen(comment_start)) == 0)
{
- dstline.catprintf("<span class=\"comment\">%s", comment_start_esc);
+ strcatprintf(dstline, "<span class=\"comment\">%s", comment_start_esc);
curcol += strlen(comment_start);
srcptr += strlen(comment_start) - 1;
ch = 0;
@@ -576,7 +576,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
}
else if (in_comment && ch == comment_end[0] && strncmp(srcptr - 1, comment_end, strlen(comment_end)) == 0)
{
- dstline.catprintf("%s</span>", comment_end_esc);
+ strcatprintf(dstline, "%s</span>", comment_end_esc);
curcol += strlen(comment_end);
srcptr += strlen(comment_end) - 1;
ch = 0;
@@ -587,7 +587,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
// track whether or not we are within an inline (C++-style) comment
if (!in_quotes && !in_comment && !in_inline_comment && ch == comment_inline[0] && strncmp(srcptr - 1, comment_inline, strlen(comment_inline)) == 0)
{
- dstline.catprintf("<span class=\"comment\">%s", comment_inline_esc);
+ strcatprintf(dstline, "<span class=\"comment\">%s", comment_inline_esc);
curcol += strlen(comment_inline);
srcptr += strlen(comment_inline) - 1;
ch = 0;
@@ -611,7 +611,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
for (curtoken = token_table; curtoken->token != NULL; curtoken++)
if (strncmp(srcptr - 1, curtoken->token, toklength) == 0 && strlen(curtoken->token) == toklength)
{
- dstline.catprintf("<span class=\"%s\">%s</span>", curtoken->color, curtoken->token);
+ strcatprintf(dstline, "<span class=\"%s\">%s</span>", curtoken->color, curtoken->token);
curcol += strlen(curtoken->token);
srcptr += strlen(curtoken->token) - 1;
ch = 0;
@@ -631,7 +631,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
int spaces = 4 - curcol % 4;
while (spaces--)
{
- dstline.cat(' ');
+ dstline.push_back(' ');
curcol++;
}
}
@@ -643,9 +643,9 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
if (!in_comment && !in_inline_comment && !in_quotes && (ch == '"' || ch == '\''))
{
if (color_quotes)
- dstline.catprintf("<span class=\"string\">%c", ch);
+ strcatprintf(dstline, "<span class=\"string\">%c", ch);
else
- dstline.cat(ch);
+ dstline.push_back(ch);
in_quotes = true;
curquote = ch;
@@ -655,11 +655,11 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
char *endquote = strchr(srcptr, ch);
if (endquote != NULL)
{
- astring filename(srcptr, endquote - srcptr);
- astring target;
+ std::string filename(srcptr, endquote - srcptr);
+ std::string target;
if (find_include_file(target, srcrootlen, dstrootlen, srcfile, dstfile, filename))
{
- dstline.catprintf("<a href=\"%s\">", target.c_str());
+ strcatprintf(dstline, "<a href=\"%s\">", target.c_str());
quotes_are_linked = true;
}
}
@@ -670,11 +670,11 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
else if (!in_comment && !in_inline_comment && in_quotes && (ch == curquote) && !escape)
{
if (quotes_are_linked)
- dstline.catprintf("</a>");
+ dstline.append("</a>");
if (color_quotes)
- dstline.catprintf("%c</span>", ch);
+ strcatprintf(dstline, "%c</span>", ch);
else
- dstline.cat(ch);
+ dstline.push_back(ch);
in_quotes = false;
curquote = 0;
quotes_are_linked = false;
@@ -682,13 +682,13 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
// else just output the current character
else if (ch == '&')
- dstline.catprintf("&amp;");
+ dstline.append("&amp;");
else if (ch == '<')
- dstline.catprintf("&lt;");
+ dstline.append("&lt;");
else if (ch == '>')
- dstline.catprintf("&gt;");
+ dstline.append("&gt;");
else
- dstline.cat(ch);
+ dstline.push_back(ch);
curcol++;
}
@@ -700,12 +700,12 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
// finish inline comments
if (in_inline_comment)
{
- dstline.catprintf("</span>");
+ dstline.append("</span>");
in_inline_comment = false;
}
// append a break and move on
- dstline.catprintf("\n");
+ dstline.append("\n");
core_fputs(dst, dstline.c_str());
}
@@ -729,7 +729,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &
HTML file with a standard header
-------------------------------------------------*/
-static core_file *create_file_and_output_header(astring &filename, astring &templatefile, astring &path)
+static core_file *create_file_and_output_header(std::string &filename, std::string &templatefile, std::string &path)
{
// create the indexfile
core_file *file;
@@ -737,9 +737,9 @@ static core_file *create_file_and_output_header(astring &filename, astring &temp
return NULL;
// print a header
- astring modified(templatefile);
- modified.replace(0, "<!--PATH-->", path.c_str());
- core_fwrite(file, modified.c_str(), modified.len());
+ std::string modified(templatefile);
+ strreplace(modified, "<!--PATH-->", path.c_str());
+ core_fwrite(file, modified.c_str(), modified.length());
// return the file
return file;
@@ -751,11 +751,11 @@ static core_file *create_file_and_output_header(astring &filename, astring &temp
standard footer to an HTML file and close it
-------------------------------------------------*/
-static void output_footer_and_close_file(core_file *file, astring &templatefile, astring &path)
+static void output_footer_and_close_file(core_file *file, std::string &templatefile, std::string &path)
{
- astring modified(templatefile);
- modified.replace(0, "<!--PATH-->", path.c_str());
- core_fwrite(file, modified.c_str(), modified.len());
+ std::string modified(templatefile);
+ strreplace(modified, "<!--PATH-->", path.c_str());
+ core_fwrite(file, modified.c_str(), modified.length());
core_fclose(file);
}
@@ -770,9 +770,10 @@ static void output_footer_and_close_file(core_file *file, astring &templatefile,
forward slashes and extract a subpath
-------------------------------------------------*/
-static astring &normalized_subpath(astring &dest, astring &path, int start)
+static std::string &normalized_subpath(std::string &dest, std::string &path, int start)
{
- return dest.cpysubstr(path, start, -1).replacechr(PATH_SEPARATOR[0], '/');
+ strreplacechr(dest.assign(path.substr(start, -1)),PATH_SEPARATOR[0], '/');
+ return dest;
}
@@ -781,11 +782,11 @@ static astring &normalized_subpath(astring &dest, astring &path, int start)
series of links
-------------------------------------------------*/
-static void output_path_as_links(core_file *file, astring &path, bool end_is_directory, bool link_to_file)
+static void output_path_as_links(core_file *file, std::string &path, bool end_is_directory, bool link_to_file)
{
// first count how deep we are
int srcdepth = 0;
- for (int slashindex = path.chr(0, '/'); slashindex != -1; slashindex = path.chr(slashindex + 1, '/'))
+ for (int slashindex = path.find_first_of('/'); slashindex != -1; slashindex = path.find_first_of('/', slashindex + 1))
srcdepth++;
if (end_is_directory)
srcdepth++;
@@ -799,9 +800,9 @@ static void output_path_as_links(core_file *file, astring &path, bool end_is_dir
// now output links to each path up the chain
int curdepth = 0;
int lastslash = 0;
- for (int slashindex = path.chr(lastslash, '/'); slashindex != -1; slashindex = path.chr(lastslash, '/'))
+ for (int slashindex = path.find_first_of('/', lastslash); slashindex != -1; slashindex = path.find_first_of('/', lastslash))
{
- astring substr(path, lastslash, slashindex - lastslash);
+ std::string substr(path, lastslash, slashindex - lastslash);
curdepth++;
core_fprintf(file, "<a href=\"");
@@ -813,7 +814,7 @@ static void output_path_as_links(core_file *file, astring &path, bool end_is_dir
}
// and a final link to the current directory
- astring substr(path, lastslash, -1);
+ std::string substr(path, lastslash, -1);
if (end_is_directory)
core_fprintf(file, "<a href=\"index.html\">%s</a>", substr.c_str());
else if (link_to_file)
@@ -827,41 +828,41 @@ static void output_path_as_links(core_file *file, astring &path, bool end_is_dir
find_include_file - find an include file
-------------------------------------------------*/
-static bool find_include_file(astring &srcincpath, int srcrootlen, int dstrootlen, astring &srcfile, astring &dstfile, astring &filename)
+static bool find_include_file(std::string &srcincpath, int srcrootlen, int dstrootlen, std::string &srcfile, std::string &dstfile, std::string &filename)
{
// iterate over include paths and find the file
for (include_path *curpath = incpaths; curpath != NULL; curpath = curpath->next)
{
// a '.' include path is specially treated
- if (curpath->path == ".")
- srcincpath.cpysubstr(srcfile, 0, srcfile.rchr(0, PATH_SEPARATOR[0]));
+ if (curpath->path.compare(".") == 0)
+ srcincpath.assign(srcfile.substr(0, srcfile.find_last_of(PATH_SEPARATOR[0])));
else
- srcincpath.cpysubstr(srcfile, 0, srcrootlen + 1).cat(curpath->path);
+ srcincpath.assign(srcfile.substr(0, srcrootlen + 1)).append(curpath->path);
// append the filename piecemeal to account for directories
int lastsepindex = 0;
int sepindex;
- while ((sepindex = filename.chr(lastsepindex, '/')) != -1)
+ while ((sepindex = filename.find_first_of('/', lastsepindex)) != -1)
{
// handle .. by removing a chunk from the incpath
- astring pathpart(filename, lastsepindex, sepindex - lastsepindex);
- if (pathpart == "..")
+ std::string pathpart(filename, lastsepindex, sepindex - lastsepindex);
+ if (pathpart.compare("..")==0)
{
- sepindex = srcincpath.rchr(0, PATH_SEPARATOR[0]);
+ sepindex = srcincpath.find_last_of(PATH_SEPARATOR[0]);
if (sepindex != -1)
srcincpath.substr(0, sepindex);
}
// otherwise, append a path separator and the pathpart
else
- srcincpath.cat(PATH_SEPARATOR).cat(pathpart);
+ srcincpath.append(PATH_SEPARATOR).append(pathpart);
// advance past the previous index
lastsepindex = sepindex + 1;
}
// now append the filename
- srcincpath.cat(PATH_SEPARATOR).catsubstr(filename, lastsepindex, -1);
+ srcincpath.append(PATH_SEPARATOR).append(filename.substr(lastsepindex, -1));
// see if we can open it
core_file *testfile;
@@ -872,29 +873,30 @@ static bool find_include_file(astring &srcincpath, int srcrootlen, int dstrootle
// find the longest matching directory substring between the include and source file
lastsepindex = 0;
- while ((sepindex = srcincpath.chr(lastsepindex, PATH_SEPARATOR[0])) != -1)
+ while ((sepindex = srcincpath.find_first_of(PATH_SEPARATOR[0], lastsepindex)) != -1)
{
// get substrings up to the current directory
- astring tempfile(srcfile, 0, sepindex);
- astring tempinc(srcincpath, 0, sepindex);
+ std::string tempfile(srcfile, 0, sepindex);
+ std::string tempinc(srcincpath, 0, sepindex);
// if we don't match, stop
- if (tempfile != tempinc)
+ if (tempfile.compare(tempinc)!=0)
break;
lastsepindex = sepindex + 1;
}
// chop off the common parts of the paths
- astring tempfile(srcfile, lastsepindex, -1);
- srcincpath.substr(lastsepindex, -1).replacechr(PATH_SEPARATOR[0], '/');
+ std::string tempfile(srcfile, lastsepindex, -1);
+ srcincpath = srcincpath.substr(lastsepindex, -1);
+ strreplacechr(srcincpath, PATH_SEPARATOR[0], '/');
// for each directory left in the filename, we need to prepend a "../"
- while ((sepindex = tempfile.chr(0, PATH_SEPARATOR[0])) != -1)
+ while ((sepindex = tempfile.find_first_of(PATH_SEPARATOR[0])) != -1)
{
tempfile.substr(sepindex + 1, -1);
- srcincpath.ins(0, "../");
+ srcincpath.insert(0, "../");
}
- srcincpath.cat(".html");
+ srcincpath.append(".html");
// free the strings and return the include path
return true;