groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 33/80: [pic]: Align with modern groff conventions.


From: G. Branden Robinson
Subject: [groff] 33/80: [pic]: Align with modern groff conventions.
Date: Sat, 30 Nov 2024 04:02:18 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 3ec90d3c9cb7ecc94f3612dccb8c7d53e81517a5
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Wed Nov 27 19:13:41 2024 -0600

    [pic]: Align with modern groff conventions.
    
    * src/preproc/pic/common.cpp:
    * src/preproc/pic/lex.cpp:
    * src/preproc/pic/main.cpp:
    * src/preproc/pic/pic.ypp:
    * src/preproc/pic/tex.cpp:
    * src/preproc/pic/troff.cpp: Add Autoconf "<config.h>"-inclusion
      boilerplate to these translation units.
    
    * src/preproc/pic/pic.h: Move inclusions of system headers and fallback
      declarations for system symbols from here...
    * src/preproc/pic/pic.ypp: ...to here, where they're used.
    
    * src/preproc/pic/common.cpp:
    * src/preproc/pic/lex.cpp:
    * src/preproc/pic/main.cpp:
    * src/preproc/pic/object.cpp:
    * src/preproc/pic/pic.ypp:
    * src/preproc/pic/tex.cpp:
    * src/preproc/pic/troff.cpp: Include requisite system headers.
    
    * src/preproc/pic/pic.ypp: `sizeof` is an operator, not a function, so
      don't parenthesize its operand when it's an lvalue (as opposed to a
      type name).  Use libgroff's newfangled `array_length()` template
      function to measure arrays.
---
 ChangeLog                  | 29 +++++++++++++++++++++++
 src/preproc/pic/common.cpp | 16 +++++++++++--
 src/preproc/pic/common.h   |  6 ++++-
 src/preproc/pic/lex.cpp    | 17 +++++++++++---
 src/preproc/pic/main.cpp   | 13 +++++++++++
 src/preproc/pic/object.cpp | 20 +++++++++-------
 src/preproc/pic/object.h   |  6 ++++-
 src/preproc/pic/output.h   |  7 +++++-
 src/preproc/pic/pic.h      | 35 +---------------------------
 src/preproc/pic/pic.ypp    | 58 ++++++++++++++++++++++++++++++++++++----------
 src/preproc/pic/position.h |  6 ++++-
 src/preproc/pic/tex.cpp    | 24 +++++++++++++++----
 src/preproc/pic/text.h     |  7 +++++-
 src/preproc/pic/troff.cpp  | 11 +++++++--
 14 files changed, 183 insertions(+), 72 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 427fc5d3f..81151527c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2024-11-27  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [pic]: Align with modern groff conventions.
+
+       * src/preproc/pic/common.cpp:
+       * src/preproc/pic/lex.cpp:
+       * src/preproc/pic/main.cpp:
+       * src/preproc/pic/pic.ypp:
+       * src/preproc/pic/tex.cpp:
+       * src/preproc/pic/troff.cpp: Add Autoconf "<config.h>"-inclusion
+       boilerplate to these translation units.
+
+       * src/preproc/pic/pic.h: Move inclusions of system headers and
+       fallback declarations for system symbols from here...
+       * src/preproc/pic/pic.ypp: ...to here, where they're used.
+
+       * src/preproc/pic/common.cpp:
+       * src/preproc/pic/lex.cpp:
+       * src/preproc/pic/main.cpp:
+       * src/preproc/pic/object.cpp:
+       * src/preproc/pic/pic.ypp:
+       * src/preproc/pic/tex.cpp:
+       * src/preproc/pic/troff.cpp: Include requisite system headers.
+
+       * src/preproc/pic/pic.ypp: `sizeof` is an operator, not a
+       function, so don't parenthesize its operand when it's an lvalue
+       {as opposed to a type name}.  Use libgroff's newfangled
+       `array_length()` template function to measure arrays.
+
 2024-11-27  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [grn]: Align with modern groff conventions.
diff --git a/src/preproc/pic/common.cpp b/src/preproc/pic/common.cpp
index 6a4a93eb9..e61df9323 100644
--- a/src/preproc/pic/common.cpp
+++ b/src/preproc/pic/common.cpp
@@ -1,5 +1,4 @@
-// -*- C++ -*-
-/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
 This file is part of groff.
@@ -17,6 +16,13 @@ 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/>. */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <math.h> // M_PI, atan2(), ceil(), cos(), sin(), sqrt()
+
 #include "pic.h"
 #include "common.h"
 
@@ -645,3 +651,9 @@ void common_output::filled_rounded_box(const position &cent,
   vec[3] = cent + position(dim.x/2.0 - rad, -dim.y/2.0);
   polygon(vec, 4, ilt, fill);
 }
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/common.h b/src/preproc/pic/common.h
index a2d5f701e..0ab0b2a34 100644
--- a/src/preproc/pic/common.h
+++ b/src/preproc/pic/common.h
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 /* Copyright (C) 1989-2020 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
@@ -77,3 +76,8 @@ public:
 int compute_arc_center(const position &start, const position &cent,
                       const position &end, position *result);
 
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/lex.cpp b/src/preproc/pic/lex.cpp
index 91802f595..c437e2b30 100644
--- a/src/preproc/pic/lex.cpp
+++ b/src/preproc/pic/lex.cpp
@@ -16,8 +16,19 @@ 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/>. */
 
-#include "pic.h"
-#include "ptable.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <errno.h>
+#include <math.h> // pow()
+#include <stdio.h> // EOF, FILE, fclose(), fopen(), getc(), ungetc()
+#include <string.h> // strerror()
+
+#include "pic.h" // must precede object.h
+
+#include "ptable.h" // must precede object.h
 #include "object.h"
 #include "pic.hpp"
 
@@ -95,7 +106,7 @@ int file_input::read_line()
        lex_error("invalid input character code %1", c);
       else {
        line += char(c);
-       if (c == '\n') 
+       if (c == '\n')
          break;
       }
     }
diff --git a/src/preproc/pic/main.cpp b/src/preproc/pic/main.cpp
index 51f99291d..1c56583c0 100644
--- a/src/preproc/pic/main.cpp
+++ b/src/preproc/pic/main.cpp
@@ -16,6 +16,19 @@ 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/>. */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <errno.h>
+#include <locale.h> // setlocale()
+#include <stdio.h> // EOF, FILE, fclose(), ferror(), fflush(), fopen(),
+                  // fprintf(), fputs(), getc(), printf(), setbuf(),
+                  // stderr, stdin, stdout, ungetc()
+#include <stdlib.h> // free(), exit()
+#include <string.h> // strerror()
+
 #include "pic.h"
 
 extern int yyparse();
diff --git a/src/preproc/pic/object.cpp b/src/preproc/pic/object.cpp
index b197a02fa..9ebf4bbae 100644
--- a/src/preproc/pic/object.cpp
+++ b/src/preproc/pic/object.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
 This file is part of groff.
@@ -20,9 +20,11 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <config.h>
 #endif
 
-#include <stdlib.h>
+#include <assert.h>
+#include <math.h> // M_PI, acos(), atan2(), cos(), sin()
+#include <stdlib.h> // free()
 
-#include "pic.h"
+#include "pic.h" // includes cset.h, which declares csupper()
 #include "ptable.h"
 #include "object.h"
 
@@ -395,7 +397,7 @@ segment::segment(const position &a, int n, segment *p)
 }
 
 text_item::text_item(char *t, const char *fn, int ln)
-: next(0), text(t), filename(fn), lineno(ln) 
+: next(0), text(t), filename(fn), lineno(ln)
 {
   adj.h = CENTER_ADJUST;
   adj.v = NONE_ADJUST;
@@ -736,13 +738,13 @@ void closed_object::set_fill(double f)
   fill = f;
 }
 
-/* accept positive and negative values */ 
+/* accept positive and negative values */
 void closed_object::set_xslanted(double s)
 {
   //assert(s >= 0.0);
   xslanted = s;
 }
-/* accept positive and negative values */ 
+/* accept positive and negative values */
 void closed_object::set_yslanted(double s)
 {
   //assert(s >= 0.0);
@@ -1206,7 +1208,7 @@ graphic_object *object_spec::make_move(position *curpos, 
direction *dirp)
   for (segment *s = segment_list; s; s = s->next)
     if (s->is_absolute)
       endpos = s->pos;
-    else 
+    else
       endpos += s->pos;
   have_last_move = 1;
   last_move = endpos - startpos;
@@ -1352,7 +1354,7 @@ void line_object::move_by(const position &pos)
   for (int i = 0; i < n; i++)
     v[i] += pos;
 }
-  
+
 void spline_object::update_bounding_box(bounding_box *p)
 {
   p->encompass(strt);
@@ -1468,7 +1470,7 @@ linear_object *object_spec::make_line(position *curpos, 
direction *dirp)
     if ((flags & IS_SAME) && (type == LINE_OBJECT || type == ARROW_OBJECT)
        && have_last_line)
       segment_pos = last_line;
-    else 
+    else
       switch (dir) {
       case UP_DIRECTION:
        segment_pos.y = segment_height;
diff --git a/src/preproc/pic/object.h b/src/preproc/pic/object.h
index e39b6a6cf..98eb638b8 100644
--- a/src/preproc/pic/object.h
+++ b/src/preproc/pic/object.h
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 /* Copyright (C) 1989-2020 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
@@ -225,3 +224,8 @@ void define_variable(const char *name, double val);
 
 void print_picture(object *);
 
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/output.h b/src/preproc/pic/output.h
index f01e0a152..84ebd4676 100644
--- a/src/preproc/pic/output.h
+++ b/src/preproc/pic/output.h
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 /* Copyright (C) 1989-2020 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
@@ -80,3 +79,9 @@ output *make_tpic_output();
 #ifdef FIG_SUPPORT
 output *make_fig_output();
 #endif /* FIG_SUPPORT */
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/pic.h b/src/preproc/pic/pic.h
index d681b327a..dfaa3dce9 100644
--- a/src/preproc/pic/pic.h
+++ b/src/preproc/pic/pic.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
 This file is part of groff.
@@ -18,39 +18,6 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 
 #include "lib.h"
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <assert.h>
-#include <errno.h>
-#include <math.h>
-#include <stdlib.h>
-
-#ifdef NEED_DECLARATION_RAND
-#undef rand
-extern "C" {
-  int rand();
-}
-#endif /* NEED_DECLARATION_RAND */
-
-#ifdef NEED_DECLARATION_SRAND
-#undef srand
-extern "C" {
-#ifdef RET_TYPE_SRAND_IS_VOID
-  void srand(unsigned int);
-#else
-  int srand(unsigned int);
-#endif
-}
-#endif /* NEED_DECLARATION_SRAND */
-
-#ifndef HAVE_FMOD
-extern "C" {
-  double fmod(double, double);
-}
-#endif
-
 #include "cset.h"
 #include "stringclass.h"
 #include "lf.h"
diff --git a/src/preproc/pic/pic.ypp b/src/preproc/pic/pic.ypp
index 2c7407fd5..8740b8c12 100644
--- a/src/preproc/pic/pic.ypp
+++ b/src/preproc/pic/pic.ypp
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
 This file is part of groff.
@@ -17,6 +17,42 @@ You should have received a copy of the GNU General Public 
License
 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 %{
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <errno.h> // EDOM, ERANGE, errno
+#include <math.h> // atan2(), cos(), floor(), fmod(), log10(), pow(),
+                 // sin(), sqrt()
+#include <stdio.h> // fflush(), fprintf(), snprintf(), sprintf(), stderr
+#include <stdlib.h> // rand(), srand(), system()
+#include <string.h> // strcat(), strchr(), strcmp(), strcpy(), strlen()
+
+#ifdef NEED_DECLARATION_RAND
+#undef rand
+extern "C" {
+  int rand();
+}
+#endif /* NEED_DECLARATION_RAND */
+
+#ifdef NEED_DECLARATION_SRAND
+#undef srand
+extern "C" {
+#ifdef RET_TYPE_SRAND_IS_VOID
+  void srand(unsigned int);
+#else
+  int srand(unsigned int);
+#endif
+}
+#endif /* NEED_DECLARATION_SRAND */
+
+#ifndef HAVE_FMOD
+extern "C" {
+  double fmod(double, double);
+}
+#endif
+
 #include "pic.h"
 #include "ptable.h"
 #include "object.h"
@@ -1141,12 +1177,12 @@ sprintf_args:
                      $$.maxv *= 2;
 #if 0
                      $$.v = new double[$$.maxv];
-                     memcpy($$.v, oldv, $$.nv*sizeof(double));
+                     memcpy($$.v, oldv, ($$.nv * sizeof(double)));
 #else
                      // workaround for bug in Compaq C++ V6.5-033
                      // for Compaq Tru64 UNIX V5.1A (Rev. 1885)
                      double *foo = new double[$$.maxv];
-                     memcpy(foo, oldv, $$.nv*sizeof(double));
+                     memcpy(foo, oldv, ($$.nv * sizeof(double)));
                      $$.v = foo;
 #endif
                      delete[] oldv;
@@ -1766,10 +1802,10 @@ void define_variable(const char *name, double val)
   if (strcmp(name, "scale") == 0) {
     // When the scale changes, reset all scaled predefined variables to
     // their default values.
-    for (unsigned int i = 0;
-        i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++) 
+    for (size_t i = 0; i < array_length(defaults_table); i++)
       if (defaults_table[i].scaled)
-       define_variable(defaults_table[i].name, val*defaults_table[i].val);
+       define_variable(defaults_table[i].name,
+                       (val * defaults_table[i].val));
   }
 }
 
@@ -1786,8 +1822,7 @@ void parse_init()
 
 void reset(const char *nm)
 {
-  for (unsigned int i = 0;
-       i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++)
+  for (size_t i = 0; i < array_length(defaults_table); i++)
     if (strcmp(nm, defaults_table[i].name) == 0) {
       double val = defaults_table[i].val;
       if (defaults_table[i].scaled) {
@@ -1807,8 +1842,7 @@ void reset_all()
   // aren't scaled because 'scale' is not scaled, and changing the
   // value of 'scale' will reset all the predefined variables that
   // are scaled.
-  for (unsigned int i = 0;
-       i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++)
+  for (size_t i = 0; i < array_length(defaults_table); i++)
     if (!defaults_table[i].scaled)
       define_variable(defaults_table[i].name, defaults_table[i].val);
 }
@@ -1921,7 +1955,7 @@ char *do_sprintf(const char *fmt, const double *v, int nv)
       }
       if ('%' == *fmt) {
        fmt++;
-       snprintf(sprintf_buf, sizeof(sprintf_buf), "%%");
+       snprintf(sprintf_buf, sizeof sprintf_buf, "%%");
       }
       else {
        if (i >= nv) {
@@ -1936,7 +1970,7 @@ char *do_sprintf(const char *fmt, const double *v, int nv)
 // rejected, including `n`.
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
-       snprintf(sprintf_buf, sizeof(sprintf_buf),
+       snprintf(sprintf_buf, sizeof sprintf_buf,
                 one_format.contents(), v[i++]);
 #pragma GCC diagnostic pop
       }
diff --git a/src/preproc/pic/position.h b/src/preproc/pic/position.h
index fb3273714..4aa79aa4b 100644
--- a/src/preproc/pic/position.h
+++ b/src/preproc/pic/position.h
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 /* Copyright (C) 1989-2020 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
@@ -44,3 +43,8 @@ double hypot(const position &a);
 
 typedef position distance;
 
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/tex.cpp b/src/preproc/pic/tex.cpp
index 0b7a03d6c..04d469b78 100644
--- a/src/preproc/pic/tex.cpp
+++ b/src/preproc/pic/tex.cpp
@@ -1,5 +1,4 @@
-// -*- C++ -*-
-/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
 This file is part of groff.
@@ -17,6 +16,15 @@ 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/>. */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <math.h> // M_PI, atan2()
+#include <stdlib.h> // strtol()
+#include <stdio.h> // fputs(), printf(), stdout
+
 #include "pic.h"
 
 #ifdef TEX_SUPPORT
@@ -96,7 +104,7 @@ void tex_output::set_pen_size(double ps)
     ps = -1.0;
   if (ps != pen_size) {
     pen_size = ps;
-    printf("    \\special{pn %d}%%\n", 
+    printf("    \\special{pn %d}%%\n",
           ps < 0.0 ? DEFAULT_PEN_SIZE : int(ps*(1000.0/72.0) + .5));
   }
 }
@@ -251,7 +259,7 @@ void tex_output::solid_arc(const position &cent, double rad,
         (-end_angle > -start_angle) ? (double)M_PI * 2 - start_angle
                                     : -start_angle);
 }
-  
+
 void tex_output::arc(const position &start, const position &cent,
                     const position &end, const line_type &lt)
 {
@@ -454,5 +462,11 @@ output *make_tpic_output()
 {
   return new tpic_output;
 }
- 
+
 #endif
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/text.h b/src/preproc/pic/text.h
index 9b9353f5d..7c7e93e5b 100644
--- a/src/preproc/pic/text.h
+++ b/src/preproc/pic/text.h
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 /* Copyright (C) 1989-2020 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
@@ -44,3 +43,9 @@ struct text_piece {
   text_piece();
   ~text_piece();
 };
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/troff.cpp b/src/preproc/pic/troff.cpp
index 7a1348ce9..aa5e00250 100644
--- a/src/preproc/pic/troff.cpp
+++ b/src/preproc/pic/troff.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
      Written by James Clark (jjc@jclark.com)
 
 This file is part of groff.
@@ -16,10 +16,17 @@ 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/>. */
 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h> // free()
+#include <stdio.h> // fputs(), printf(), putchar(), puts(), stdout
+
 #include "pic.h"
 #include "common.h"
 
-
 const double RELATIVE_THICKNESS = -1.0;
 const double BAD_THICKNESS = -2.0;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]