Imported Upstream version 1.23.0
[platform/upstream/groff.git] / src / devices / grops / psrm.cpp
index 152f9d9..3c9a8b7 100644 (file)
@@ -1,5 +1,4 @@
-// -*- C++ -*-
-/* Copyright (C) 1989-2018 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.
@@ -259,8 +258,8 @@ void resource_manager::document_setup(ps_output &out)
        *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)
@@ -271,7 +270,8 @@ void resource_manager::document_setup(ps_output &out)
   }
 }
 
-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)
@@ -317,7 +317,8 @@ void resource_manager::output_prolog(ps_output &out)
   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);
@@ -335,8 +336,8 @@ void resource_manager::import_file(const char *filename, ps_output &out)
   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';
@@ -347,15 +348,16 @@ void resource_manager::supply_resource(resource *r, int rank, FILE *outfp,
   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 {
@@ -363,8 +365,8 @@ void resource_manager::supply_resource(resource *r, int rank, FILE *outfp,
       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;
+       delete[] r->filename;
+       r->filename = 0 /* nullptr */;
       }
       else
        path = r->filename;
@@ -608,8 +610,8 @@ int resource_manager::do_begin_resource(const char *ptr, int, FILE *,
   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) {
@@ -634,8 +636,8 @@ int resource_manager::do_begin_document(const char *ptr, int, FILE *,
   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)
@@ -658,8 +660,8 @@ int resource_manager::do_begin_procset(const char *ptr, int, FILE *,
   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)
@@ -682,8 +684,8 @@ int resource_manager::do_begin_file(const char *ptr, int, FILE *,
   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)
@@ -727,7 +729,8 @@ int resource_manager::change_to_end_resource(const char *, int, FILE *,
   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 {
@@ -934,18 +937,19 @@ static unsigned parse_extensions(const char *ptr)
   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:",
@@ -956,7 +960,7 @@ void resource_manager::process_file(int rank, FILE *fp, const char *filename,
     "DocumentNeededFiles:",
     "DocumentSuppliedFiles:",
   };
-  
+
   const int NHEADER_COMMENTS = sizeof(header_comment_table)
                               / sizeof(header_comment_table[0]);
   struct comment_info {
@@ -964,7 +968,7 @@ void resource_manager::process_file(int rank, FILE *fp, const char *filename,
     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 },
@@ -1074,20 +1078,21 @@ void resource_manager::process_file(int rank, FILE *fp, const char *filename,
 
 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);
   }
   free(path);
@@ -1176,3 +1181,9 @@ void resource_manager::print_language_level_comment(FILE *outfp)
   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: