int emu_file::puts(const char *s) { // write the data if we can if (m_file != NULL) return core_fputs(m_file, s); return 0; }
static void core_loadimage_svg(GVJ_t * job, usershape_t *us, boxf b, bool filled) { assert(job); assert(us); assert(us->name); assert(us->f); core_fputs(job, "<image xlink:href=\""); core_fputs(job, us->name); if (job->rotation) { core_printf (job, "\" width=\"%gpx\" height=\"%gpx\" preserveAspectRatio=\"xMidYMid meet\" x=\"%g\" y=\"%g\"", b.UR.y - b.LL.y, b.UR.x - b.LL.x, b.LL.x, b.UR.y); core_printf (job, " transform=\"rotate(%d %g %g)\"", job->rotation, b.LL.x, b.UR.y); } else { core_printf (job, "\" width=\"%gpx\" height=\"%gpx\" preserveAspectRatio=\"xMidYMid meet\" x=\"%g\" y=\"%g\"", b.UR.x - b.LL.x, b.UR.y - b.LL.y, b.LL.x, b.LL.y); } core_fputs(job, "/>\n"); }
/* core_printf: * Note that this function is unsafe due to the fixed buffer size. * It should only be used when the caller is sure the input will not * overflow the buffer. In particular, it should be avoided for * input coming from users. Also, if vsnprintf is available, the * code should check for return values to use it safely. */ void core_printf(GVJ_t * job, const char *format, ...) { char buf[BUFSIZ]; va_list argp; va_start(argp, format); #ifdef HAVE_VSNPRINTF (void) vsnprintf(buf, sizeof(buf), format, argp); #else (void) vsprintf(buf, format, argp); #endif va_end(argp); core_fputs(job, buf); }
static void figptarray(GVJ_t *job, pointf * A, int n, int close) { int i; point p; for (i = 0; i < n; i++) { PF2P(A[i],p); core_printf(job, " %d %d", p.x, p.y); } if (close) { PF2P(A[0],p); core_printf(job, " %d %d", p.x, p.y); } core_fputs(job, "\n"); }
static void map_end_page(GVJ_t * job) { obj_state_t *obj = job->obj; switch (job->render.id) { case FORMAT_CMAP: map_output_shape(job, obj->url_map_shape, obj->url_map_p,obj->url_map_n, obj->url, obj->tooltip, obj->target); break; case FORMAT_CMAPX: map_output_shape(job, obj->url_map_shape, obj->url_map_p,obj->url_map_n, obj->url, obj->tooltip, obj->target); core_fputs(job, "</map>\n"); break; default: break; } }
static void map_output_shape (GVJ_t *job, map_shape_t map_shape, pointf * AF, int nump, char* url, char *tooltip, char *target) { int i; static point *A; static int size_A; if (!AF || !nump) return; if (size_A < nump) { size_A = nump + 10; A = realloc(A, size_A * sizeof(point)); } for (i = 0; i < nump; i++) PF2P(AF[i], A[i]); if (job->render.id == FORMAT_IMAP && url && url[0]) { switch (map_shape) { case MAP_RECTANGLE: /* Y_GOES_DOWN so need UL to LR */ core_printf(job, "rect %s %d,%d %d,%d\n", url, A[0].x, A[1].y, A[1].x, A[0].y); break; case MAP_CIRCLE: core_printf(job, "circle %s %d,%d,%d\n", url, A[0].x, A[0].y, A[1].x-A[0].x); break; case MAP_POLYGON: core_printf(job, "poly %s", url); for (i = 0; i < nump; i++) core_printf(job, " %d,%d", A[i].x, A[i].y); core_fputs(job, "\n"); break; default: assert(0); break; } } else if (job->render.id == FORMAT_ISMAP && url && url[0]) { switch (map_shape) { case MAP_RECTANGLE: /* Y_GOES_DOWN so need UL to LR */ core_printf(job, "rectangle (%d,%d) (%d,%d) %s %s\n", A[0].x, A[1].y, A[1].x, A[0].y, url, tooltip); break; default: assert(0); break; } } else if (job->render.id == FORMAT_CMAP || job->render.id == FORMAT_CMAPX) { switch (map_shape) { case MAP_CIRCLE: core_fputs(job, "<area shape=\"circle\""); break; case MAP_RECTANGLE: core_fputs(job, "<area shape=\"rect\""); break; case MAP_POLYGON: core_fputs(job, "<area shape=\"poly\""); break; default: assert(0); break; } if (url && url[0]) { core_fputs(job, " href=\""); core_fputs(job, xml_string(url)); core_fputs(job, "\""); } if (target && target[0]) { core_fputs(job, " target=\""); core_fputs(job, xml_string(target)); core_fputs(job, "\""); } if (tooltip && tooltip[0]) { core_fputs(job, " title=\""); core_fputs(job, xml_string(tooltip)); core_fputs(job, "\""); } /* * alt text is intended for the visually impaired, but such * folk are not likely to be clicking around on a graph anyway. * IE on the PC platform (but not on Macs) incorrectly * uses (non-empty) alt strings instead of title strings for tooltips. * To make tooltips work and avoid this IE issue, * while still satisfying usability guidelines * that require that there is always an alt string, * we generate just an empty alt string. */ core_fputs(job, " alt=\"\""); core_fputs(job, " coords=\""); switch (map_shape) { case MAP_CIRCLE: core_printf(job, "%d,%d,%d", A[0].x, A[0].y, A[1].x); break; case MAP_RECTANGLE: /* Y_GOES_DOWN so need UL to LR */ core_printf(job, "%d,%d,%d,%d", A[0].x, A[1].y, A[1].x, A[0].y); break; case MAP_POLYGON: core_printf(job, "%d,%d", A[0].x, A[0].y); for (i = 1; i < nump; i++) core_printf(job, " %d,%d", A[i].x, A[i].y); break; default: break; } if (job->render.id == FORMAT_CMAPX) core_fputs(job, "\"/>\n"); else core_fputs(job, "\">\n"); } }
static void map_begin_page(GVJ_t * job) { obj_state_t *obj = job->obj; char *s; switch (job->render.id) { case FORMAT_IMAP: core_fputs(job, "base referer\n"); if (obj->url && obj->url[0]) { core_fputs(job, "default "); core_fputs(job, xml_string(obj->url)); core_fputs(job, "\n"); } break; case FORMAT_ISMAP: if (obj->url && obj->url[0]) { core_fputs(job, "default "); core_fputs(job, xml_string(obj->url)); core_fputs(job, " "); core_fputs(job, xml_string(obj->u.g->name)); core_fputs(job, "\n"); } break; case FORMAT_CMAPX: s = xml_string(obj->u.g->name); core_fputs(job, "<map id=\""); core_fputs(job, s); core_fputs(job, "\" name=\""); core_fputs(job, s); core_fputs(job, "\">\n"); break; default: break; } }
int core_vfprintf(core_file *f, const char *fmt, va_list va) { char buf[1024]; vsnprintf(buf, sizeof(buf), fmt, va); return core_fputs(f, buf); }
static int output_file(file_type type, int srcrootlen, int dstrootlen, astring &srcfile, astring &dstfile, bool link_to_file, astring &tempheader, astring &tempfooter) { // extract a normalized subpath astring srcfile_subpath; normalized_subpath(srcfile_subpath, srcfile, srcrootlen + 1); fprintf(stderr, "Processing %s\n", srcfile_subpath.cstr()); // set some defaults bool color_quotes = false; const char *comment_start = ""; const char *comment_start_esc = ""; const char *comment_end = ""; const char *comment_end_esc = ""; const char *comment_inline = ""; const char *comment_inline_esc = ""; const char *token_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_#"; const token_entry *token_table = dummy_token_table; // based on the file type, set the comment info switch (type) { case FILE_TYPE_C: color_quotes = true; comment_start = comment_start_esc = "/*"; comment_end = comment_end_esc = "*/"; comment_inline = comment_inline_esc = "//"; token_table = c_token_table; break; case FILE_TYPE_MAKE: color_quotes = true; comment_inline = comment_inline_esc = "#"; break; case FILE_TYPE_XML: color_quotes = true; comment_start = "<!--"; comment_start_esc = "<!--"; comment_end = "-->"; comment_end_esc = "-->"; break; default: case FILE_TYPE_TEXT: break; } // make the token lookup table bool is_token[256]; memset(is_token, 0, sizeof(is_token)); for (int toknum = 0; token_chars[toknum] != 0; toknum++) is_token[(UINT8)token_chars[toknum]] = true; // open the source file core_file *src; if (core_fopen(srcfile, OPEN_FLAG_READ, &src) != FILERR_NONE) { fprintf(stderr, "Unable to read file '%s'\n", srcfile.cstr()); return 1; } // open the output file core_file *dst = create_file_and_output_header(dstfile, tempheader, srcfile_subpath); if (dst == NULL) { fprintf(stderr, "Unable to write file '%s'\n", dstfile.cstr()); core_fclose(src); return 1; } // output the directory navigation core_fprintf(dst, "<h3>Viewing File: "); output_path_as_links(dst, srcfile_subpath, false, link_to_file); core_fprintf(dst, "</h3>"); // start with some tags core_fprintf(dst, "\t<pre class=\"source\">\n"); // iterate over lines in the source file int linenum = 1; bool in_comment = false; char srcline[4096]; while (core_fgets(srcline, ARRAY_LENGTH(srcline), src) != NULL) { // start with the line number astring dstline; dstline.catprintf("<span class=\"linenum\">%5d</span> ", linenum++); // iterate over characters in the source line bool escape = false; bool in_quotes = false; bool in_inline_comment = false; bool last_token_was_include = false; bool last_was_token = false; bool quotes_are_linked = false; UINT8 curquote = 0; int curcol = 0; for (char *srcptr = srcline; *srcptr != 0; ) { UINT8 ch = *srcptr++; // track whether or not we are within an extended (C-style) comment if (!in_quotes && !in_inline_comment) { 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); curcol += strlen(comment_start); srcptr += strlen(comment_start) - 1; ch = 0; in_comment = true; } else if (in_comment && ch == comment_end[0] && strncmp(srcptr - 1, comment_end, strlen(comment_end)) == 0) { dstline.catprintf("%s</span>", comment_end_esc); curcol += strlen(comment_end); srcptr += strlen(comment_end) - 1; ch = 0; in_comment = false; } } // 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); curcol += strlen(comment_inline); srcptr += strlen(comment_inline) - 1; ch = 0; in_inline_comment = true; } // if this is the start of a new token, see if we want to color it if (!in_quotes && !in_comment && !in_inline_comment && !last_was_token && is_token[ch]) { const token_entry *curtoken; char *temp = srcptr; int toklength; // find the end of the token while (*temp != 0 && is_token[(UINT8)*temp]) temp++; toklength = temp - (srcptr - 1); // scan the token table last_token_was_include = false; 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); curcol += strlen(curtoken->token); srcptr += strlen(curtoken->token) - 1; ch = 0; // look for include tokens specially if (type == FILE_TYPE_C && strcmp(curtoken->token, "#include") == 0) last_token_was_include = true; break; } } last_was_token = is_token[ch]; // if we hit a tab, expand it if (ch == 0x09) { // compute how many spaces int spaces = 4 - curcol % 4; while (spaces--) { dstline.cat(' '); curcol++; } } // otherwise, copy the source character else if (ch != 0x0a && ch != 0x0d && ch != 0) { // track opening quotes if (!in_comment && !in_inline_comment && !in_quotes && (ch == '"' || ch == '\'')) { if (color_quotes) dstline.catprintf("<span class=\"string\">%c", ch); else dstline.cat(ch); in_quotes = true; curquote = ch; // handle includes if (last_token_was_include) { char *endquote = strchr(srcptr, ch); if (endquote != NULL) { astring filename(srcptr, endquote - srcptr); astring target; if (find_include_file(target, srcrootlen, dstrootlen, srcfile, dstfile, filename)) { dstline.catprintf("<a href=\"%s\">", target.cstr()); quotes_are_linked = true; } } } } // track closing quotes else if (!in_comment && !in_inline_comment && in_quotes && (ch == curquote) && !escape) { if (quotes_are_linked) dstline.catprintf("</a>"); if (color_quotes) dstline.catprintf("%c</span>", ch); else dstline.cat(ch); in_quotes = false; curquote = 0; quotes_are_linked = false; } // else just output the current character else if (ch == '&') dstline.catprintf("&"); else if (ch == '<') dstline.catprintf("<"); else if (ch == '>') dstline.catprintf(">"); else dstline.cat(ch); curcol++; } // Update escape state if (in_quotes) escape = (ch == '\\' && type == FILE_TYPE_C) ? !escape : false; } // finish inline comments if (in_inline_comment) { dstline.catprintf("</span>"); in_inline_comment = false; } // append a break and move on dstline.catprintf("\n"); core_fputs(dst, dstline); } // close tags core_fprintf(dst, "\t</pre>\n"); // close the file output_footer_and_close_file(dst, tempfooter, srcfile_subpath); core_fclose(src); return 0; }
static int output_file(file_type type, int srcrootlen, int dstrootlen, const astring *srcfile, const astring *dstfile, int link_to_file) { const char *comment_start, *comment_end, *comment_inline, *token_chars; const char *comment_start_esc, *comment_end_esc, *comment_inline_esc; const token_entry *token_table; const astring *srcfile_subpath; char srcline[4096], *srcptr; int in_comment = FALSE; UINT8 is_token[256]; int color_quotes; core_file *src; core_file *dst; int toknum; int linenum = 1; /* extract a normalized subpath */ srcfile_subpath = normalized_subpath(srcfile, srcrootlen + 1); if (srcfile_subpath == NULL) return 1; fprintf(stderr, "Processing %s\n", astring_c(srcfile_subpath)); /* set some defaults */ color_quotes = FALSE; comment_start = comment_start_esc = ""; comment_end = comment_end_esc = ""; comment_inline = comment_inline_esc = ""; token_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_#"; token_table = dummy_token_table; /* based on the file type, set the comment info */ switch (type) { case FILE_TYPE_C: color_quotes = TRUE; comment_start = comment_start_esc = "/*"; comment_end = comment_end_esc = "*/"; comment_inline = comment_inline_esc = "//"; token_table = c_token_table; break; case FILE_TYPE_MAKE: color_quotes = TRUE; comment_inline = comment_inline_esc = "#"; break; case FILE_TYPE_XML: color_quotes = TRUE; comment_start = "<!--"; comment_start_esc = "<!--"; comment_end = "-->"; comment_end_esc = "-->"; break; default: case FILE_TYPE_TEXT: break; } /* make the token lookup table */ memset(is_token, 0, sizeof(is_token)); for (toknum = 0; token_chars[toknum] != 0; toknum++) is_token[(UINT8)token_chars[toknum]] = TRUE; /* open the source file */ if (core_fopen(astring_c(srcfile), OPEN_FLAG_READ, &src) != FILERR_NONE) { fprintf(stderr, "Unable to read file '%s'\n", astring_c(srcfile)); return 1; } /* open the output file */ dst = create_file_and_output_header(dstfile, "MAME Source Code", astring_c(srcfile_subpath)); if (dst == NULL) { fprintf(stderr, "Unable to write file '%s'\n", astring_c(dstfile)); core_fclose(src); return 1; } /* output the directory navigation */ core_fprintf(dst, "<h3>Viewing File: "); output_path_as_links(dst, srcfile_subpath, FALSE, link_to_file); core_fprintf(dst, "</h3>"); astring_free((astring *)srcfile_subpath); /* start with some tags */ core_fprintf(dst, "\t<pre style=\"font-family:'Courier New','Courier',monospace; font-size:12px;\">\n"); /* iterate over lines in the source file */ while (core_fgets(srcline, ARRAY_LENGTH(srcline), src) != NULL) { char dstline[4096], *dstptr = dstline; int in_inline_comment = FALSE; int last_token_was_include = FALSE; int last_was_token = FALSE; int quotes_are_linked = FALSE; char in_quotes = 0; int curcol = 0; /* start with the line number */ dstptr += sprintf(dstptr, "<span style=\"" LINENUM_STYLE "\">%5d</span> ", linenum++); /* iterate over characters in the source line */ for (srcptr = srcline; *srcptr != 0; ) { UINT8 ch = *srcptr++; /* track whether or not we are within an extended (C-style) comment */ if (!in_quotes && !in_inline_comment) { if (!in_comment && ch == comment_start[0] && strncmp(srcptr - 1, comment_start, strlen(comment_start)) == 0) { dstptr += sprintf(dstptr, "<span style=\"" COMMENT_STYLE "\">%s", comment_start_esc); curcol += strlen(comment_start); srcptr += strlen(comment_start) - 1; ch = 0; in_comment = TRUE; } else if (in_comment && ch == comment_end[0] && strncmp(srcptr - 1, comment_end, strlen(comment_end)) == 0) { dstptr += sprintf(dstptr, "%s</span>", comment_end_esc); curcol += strlen(comment_end); srcptr += strlen(comment_end) - 1; ch = 0; in_comment = FALSE; } } /* 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) { dstptr += sprintf(dstptr, "<span style=\"" COMMENT_STYLE "\">%s", comment_inline_esc); curcol += strlen(comment_inline); srcptr += strlen(comment_inline) - 1; ch = 0; in_inline_comment = TRUE; } /* if this is the start of a new token, see if we want to color it */ if (!in_quotes && !in_comment && !in_inline_comment && !last_was_token && is_token[ch]) { const token_entry *curtoken; char *temp = srcptr; int toklength; /* find the end of the token */ while (*temp != 0 && is_token[(UINT8)*temp]) temp++; toklength = temp - (srcptr - 1); /* scan the token table */ last_token_was_include = FALSE; for (curtoken = token_table; curtoken->token != NULL; curtoken++) if (strncmp(srcptr - 1, curtoken->token, toklength) == 0 && strlen(curtoken->token) == toklength) { dstptr += sprintf(dstptr, "<span style=\"%s\">%s</span>", curtoken->color, curtoken->token); curcol += strlen(curtoken->token); srcptr += strlen(curtoken->token) - 1; ch = 0; /* look for include tokens specially */ if (type == FILE_TYPE_C && strcmp(curtoken->token, "#include") == 0) last_token_was_include = TRUE; break; } } last_was_token = is_token[ch]; /* if we hit a tab, expand it */ if (ch == 0x09) { /* compute how many spaces */ int spaces = 4 - curcol % 4; while (spaces--) { *dstptr++ = ' '; curcol++; } } /* otherwise, copy the source character */ else if (ch != 0x0a && ch != 0x0d && ch != 0) { /* track opening quotes */ if (!in_comment && !in_inline_comment && !in_quotes && (ch == '"' || ch == '\'')) { if (color_quotes) dstptr += sprintf(dstptr, "<span style=\"" STRING_STYLE "\">%c", ch); else *dstptr++ = ch; in_quotes = ch; /* handle includes */ if (last_token_was_include) { char *endquote = strchr(srcptr, ch); if (endquote != NULL) { astring *filename = astring_dupch(srcptr, endquote - srcptr); astring *target = find_include_file(srcrootlen, dstrootlen, srcfile, dstfile, filename); if (target != NULL) { dstptr += sprintf(dstptr, "<a href=\"%s\">", astring_c(target)); quotes_are_linked = TRUE; astring_free(target); } astring_free(filename); } } } /* track closing quotes */ else if (!in_comment && !in_inline_comment && in_quotes && ch == in_quotes && (type != FILE_TYPE_C || srcptr[-2] != '\\' || srcptr[-3] == '\\')) { if (quotes_are_linked) dstptr += sprintf(dstptr, "</a>"); if (color_quotes) dstptr += sprintf(dstptr, "%c</span>", ch); else *dstptr++ = ch; in_quotes = 0; quotes_are_linked = FALSE; } /* else just output the current character */ else if (ch == '&') dstptr += sprintf(dstptr, "&"); else if (ch == '<') dstptr += sprintf(dstptr, "<"); else if (ch == '>') dstptr += sprintf(dstptr, ">"); else *dstptr++ = ch; curcol++; } } /* finish inline comments */ if (in_inline_comment) { dstptr += sprintf(dstptr, "</span>"); in_inline_comment = FALSE; } /* append a break and move on */ dstptr += sprintf(dstptr, "\n"); core_fputs(dst, dstline); } /* close tags */ core_fprintf(dst, "\t</pre>\n"); /* close the file */ output_footer_and_close_file(dst); core_fclose(src); return 0; }