From 8c6c4ca2330d6fabf74f7b9d790a7093ee29effa Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 7 Jul 2016 06:04:46 -0400
Subject: [PATCH 16/25] FIXME: unify implementations of convert_oct and
 convert_oct_ranges

---
 libcpp/charset.c | 86 ++++++++++++++++++++------------------------------------
 1 file changed, 30 insertions(+), 56 deletions(-)

diff --git a/libcpp/charset.c b/libcpp/charset.c
index b9a7c45..a17825c 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -1369,19 +1369,12 @@ convert_hex_ranges (cpp_reader *pfile, const uchar *from, const uchar *limit,
 			      char_range, loc_reader, &ranges);
 }
 
-/* Convert an octal escape, pointed to by FROM, to the execution
-   character set and write it into the string buffer TBUF.  Returns an
-   advanced pointer, and issues diagnostics as necessary.
-   No character set translation occurs; this routine always produces the
-   execution-set character with numeric value equal to the given octal
-   number.  */
 static const uchar *
-convert_oct (cpp_reader *pfile, const uchar *from, const uchar *limit,
-	     struct _cpp_strbuf *tbuf, struct cset_converter cvt)//
-#if 0
-	     source_range char_range,
-	     cpp_string_location_reader *loc_reader)
-#endif
+convert_oct_unified (cpp_reader *pfile, const uchar *from, const uchar *limit,
+		     struct _cpp_strbuf *tbuf, struct cset_converter cvt,
+		     source_range char_range,
+		     cpp_string_location_reader *loc_reader,
+		     cpp_substring_ranges *ranges)
 {
   size_t count = 0;
   cppchar_t c, n = 0;
@@ -1395,7 +1388,8 @@ convert_oct (cpp_reader *pfile, const uchar *from, const uchar *limit,
       if (c < '0' || c > '7')
 	break;
       from++;
-      //char_range.m_finish = loc_reader->get_next ().m_finish;
+      if (loc_reader)
+	char_range.m_finish = loc_reader->get_next ().m_finish;
       overflow |= n ^ (n << 3 >> 3);
       n = (n << 3) + c - '0';
     }
@@ -1407,58 +1401,38 @@ convert_oct (cpp_reader *pfile, const uchar *from, const uchar *limit,
       n &= mask;
     }
 
-  emit_numeric_escape (pfile, n, tbuf, cvt);
-
-#if 0
-  tbuf->loc.add_char_at (char_range, 1,
-			 pfile->line_table);
-#endif
+  if (ranges)
+    ranges->add_range (char_range);
+  else
+    emit_numeric_escape (pfile, n, tbuf, cvt);
 
   return from;
 }
 
+/* Convert an octal escape, pointed to by FROM, to the execution
+   character set and write it into the string buffer TBUF.  Returns an
+   advanced pointer, and issues diagnostics as necessary.
+   No character set translation occurs; this routine always produces the
+   execution-set character with numeric value equal to the given octal
+   number.  */
 static const uchar *
-convert_oct_ranges (cpp_reader */*pfile*/, const uchar *from, const uchar *limit,
-		    /*struct _cpp_strbuf *tbuf, struct cset_converter cvt, */
+convert_oct (cpp_reader *pfile, const uchar *from, const uchar *limit,
+	     struct _cpp_strbuf *tbuf, struct cset_converter cvt)
+{
+  source_range dummy;
+  return convert_oct_unified (pfile, from, limit, tbuf, cvt,
+			      dummy, NULL, NULL);
+}
+
+static const uchar *
+convert_oct_ranges (cpp_reader *pfile, const uchar *from, const uchar *limit,
 		    source_range char_range,
 		    cpp_string_location_reader *loc_reader,
 		    cpp_substring_ranges &ranges)
 {
-  size_t count = 0;
-  cppchar_t c, n = 0;
-#if 0
-  size_t width = cvt.width;
-  size_t mask = width_to_mask (width);
-  bool overflow = false;
-#endif
-
-  while (from < limit && count++ < 3)
-    {
-      c = *from;
-      if (c < '0' || c > '7')
-	break;
-      from++;
-      char_range.m_finish = loc_reader->get_next ().m_finish;
-      //overflow |= n ^ (n << 3 >> 3);
-      n = (n << 3) + c - '0';
-    }
-
-#if 0
-  if (n != (n & mask))
-    {
-      cpp_error (pfile, CPP_DL_PEDWARN,
-		 "octal escape sequence out of range");
-      n &= mask;
-    }
-#endif
-
-#if 0
-  emit_numeric_escape (pfile, n, tbuf, cvt);
-#endif
-
-  ranges.add_range (char_range);
-
-  return from;
+  struct cset_converter dummy;
+  return convert_oct_unified (pfile, from, limit, NULL, dummy,
+			      char_range, loc_reader, &ranges);
 }
 
 /* Convert an escape sequence (pointed to by FROM) to its value on
-- 
1.8.5.3

