-// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004,
- 2009
- Free Software Foundation, Inc.
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
for more details.
You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>. */
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "driver.h"
#include "stringclass.h"
const int NEXTENSIONS = sizeof(extension_table)/sizeof(extension_table[0]);
+// this must stay in sync with 'resource_type' in 'ps.h'
const char *resource_table[] = {
"font",
+ "fontset",
"procset",
"file",
"encoding",
resource::~resource()
{
- a_delete filename;
+ free(filename);
}
void resource::print_type_and_name(FILE *outfp)
*tail[i] = resource_list;
resource_list = head[i];
}
- a_delete head;
- a_delete tail;
+ delete[] head;
+ delete[] tail;
// check it
for (r = resource_list; r; r = r->next)
if (r->next)
}
}
-void resource_manager::print_resources_comment(unsigned flag, FILE *outfp)
+void resource_manager::print_resources_comment(unsigned flag,
+ FILE *outfp)
{
int continued = 0;
for (resource *r = resource_list; r; r = r->next)
char *prologue = getenv("GROPS_PROLOGUE");
FILE *fp = font::open_file(prologue, &path);
if (!fp)
- fatal("can't find `%1'", prologue);
+ fatal("failed to open PostScript prologue '%1': %2", prologue,
+ strerror(errno));
fputs("%%BeginResource: ", outfp);
procset_resource->print_type_and_name(outfp);
putc('\n', outfp);
process_file(-1, fp, path, outfp);
fclose(fp);
- a_delete path;
+ free(path);
fputs("%%EndResource\n", outfp);
}
supply_resource(r, -1, out.get_file(), 1);
}
-void resource_manager::supply_resource(resource *r, int rank, FILE *outfp,
- int is_document)
+void resource_manager::supply_resource(resource *r, int rank,
+ FILE *outfp, int is_document)
{
if (r->flags & resource::BUSY) {
r->name += '\0';
- fatal("loop detected in dependency graph for %1 `%2'",
+ fatal("loop detected in dependency graph for %1 '%2'",
resource_table[r->type],
r->name.contents());
}
r->flags |= resource::BUSY;
if (rank > r->rank)
r->rank = rank;
- char *path = 0; // pacify compiler
- FILE *fp = 0;
- if (r->filename != 0) {
+ char *path = 0 /* nullptr */;
+ FILE *fp = 0 /* nullptr */;
+ if (r->filename != 0 /* nullptr */) {
if (r->type == RESOURCE_FONT) {
fp = font::open_file(r->filename, &path);
if (!fp) {
- error("can't find `%1'", r->filename);
- a_delete r->filename;
- r->filename = 0;
+ error("failed to open PostScript resource '%1': %2",
+ r->filename, strerror(errno));
+ delete[] r->filename;
+ r->filename = 0 /* nullptr */;
}
}
else {
errno = 0;
fp = include_search_path.open_file_cautious(r->filename);
if (!fp) {
- error("can't open `%1': %2", r->filename, strerror(errno));
- a_delete r->filename;
- r->filename = 0;
+ error("can't open '%1': %2", r->filename, strerror(errno));
+ delete[] r->filename;
+ r->filename = 0 /* nullptr */;
}
else
path = r->filename;
process_file(rank, fp, path, outfp);
fclose(fp);
if (r->type == RESOURCE_FONT)
- a_delete path;
+ free(path);
if (outfp) {
if (r->type == RESOURCE_FILE && is_document)
fputs("%%EndDocument\n", outfp);
int ri;
for (ri = 0; ri < NRESOURCES; ri++)
if (strlen(resource_table[ri]) == size_t(*ptr - name)
- && memcmp(resource_table[ri], name, *ptr - name) == 0)
+ && strncasecmp(resource_table[ri], name, *ptr - name) == 0)
break;
if (ri >= NRESOURCES) {
error("unknown resource type");
return 1;
}
-int resource_manager::do_include_resource(const char *ptr, int rank, FILE *,
- FILE *outfp)
+int resource_manager::do_include_resource(const char *ptr, int rank,
+ FILE *, FILE *outfp)
{
resource *r = read_resource_arg(&ptr);
if (r) {
return 1;
}
-int resource_manager::do_include_document(const char *ptr, int rank, FILE *,
- FILE *outfp)
+int resource_manager::do_include_document(const char *ptr, int rank,
+ FILE *, FILE *outfp)
{
resource *r = read_file_arg(&ptr);
if (r)
return 0;
}
-int resource_manager::do_include_procset(const char *ptr, int rank, FILE *,
- FILE *outfp)
+int resource_manager::do_include_procset(const char *ptr, int rank,
+ FILE *, FILE *outfp)
{
resource *r = read_procset_arg(&ptr);
if (r)
return 0;
}
-int resource_manager::do_include_file(const char *ptr, int rank, FILE *,
- FILE *outfp)
+int resource_manager::do_include_file(const char *ptr, int rank,
+ FILE *, FILE *outfp)
{
resource *r = read_file_arg(&ptr);
if (r)
return 0;
}
-int resource_manager::do_begin_preview(const char *, int, FILE *fp, FILE *)
+int resource_manager::do_begin_preview(const char *, int, FILE *fp,
+ FILE *)
{
string buf;
do {
if (*ptr != '\0') {
unit = read_one_of(&ptr, units, 2);
if (unit < 0) {
- error("expected `Bytes' or `Lines'");
+ error("expected 'Bytes' or 'Lines'");
return 0;
}
}
current_lineno++;
}
if (cc != EOF)
- ungetc(c, fp);
+ ungetc(cc, fp);
}
else if (c == '\n') {
linecount++;
if (i >= NEXTENSIONS) {
string s(name, ptr - name);
s += '\0';
- error("unknown extension `%1'", s.contents());
+ error("unknown extension '%1'", s.contents());
}
}
return flags;
}
-// XXX if it has not been surrounded with {Begin,End}Document need to strip
-// out Page: Trailer {Begin,End}Prolog {Begin,End}Setup sections.
+// XXX if it has not been surrounded with {Begin,End}Document need to
+// strip out Page: Trailer {Begin,End}Prolog {Begin,End}Setup sections.
// XXX Perhaps the decision whether to use BeginDocument or
// BeginResource: file should be postponed till we have seen
// the first line of the file.
-void resource_manager::process_file(int rank, FILE *fp, const char *filename,
- FILE *outfp)
+void resource_manager::process_file(int rank, FILE *fp,
+ const char *filename, FILE *outfp)
{
// If none of these comments appear in the header section, and we are
- // just analyzing the file (ie outfp is 0), then we can return immediately.
+ // just analyzing the file (i.e., outfp is 0), then we can return
+ // immediately.
static const char *header_comment_table[] = {
"DocumentNeededResources:",
"DocumentSuppliedResources:",
"DocumentNeededFiles:",
"DocumentSuppliedFiles:",
};
-
+
const int NHEADER_COMMENTS = sizeof(header_comment_table)
/ sizeof(header_comment_table[0]);
struct comment_info {
int (resource_manager::*proc)(const char *, int, FILE *, FILE *);
};
- static comment_info comment_table[] = {
+ static const comment_info comment_table[] = {
{ "BeginResource:", &resource_manager::do_begin_resource },
{ "IncludeResource:", &resource_manager::do_include_resource },
{ "BeginDocument:", &resource_manager::do_begin_document },
void resource_manager::read_download_file()
{
- char *path = 0;
+ char *path = 0 /* nullptr */;
FILE *fp = font::open_file("download", &path);
- if (!fp)
- fatal("can't find `download'");
+ if (0 /* nullptr */ == fp)
+ fatal("failed to open 'download' file: %1", strerror(errno));
char buf[512];
int lineno = 0;
while (fgets(buf, sizeof(buf), fp)) {
lineno++;
char *p = strtok(buf, " \t\r\n");
- if (p == 0 || *p == '#')
+ if (p == 0 /* nullptr */ || *p == '#')
continue;
- char *q = strtok(0, " \t\r\n");
+ char *q = strtok(0 /* nullptr */, " \t\r\n");
if (!q)
- fatal_with_file_and_line(path, lineno, "missing filename");
+ fatal_with_file_and_line(path, lineno, "file name missing for"
+ " font '%1'", p);
lookup_font(p)->filename = strsave(q);
}
- a_delete path;
+ free(path);
fclose(fp);
}
if (language_level)
fprintf(outfp, "%%%%LanguageLevel: %u\n", language_level);
}
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72: