File: 0007-Issue-679-Fix-invalid-output-of-export-config.patch

package info (click to toggle)
tidy-html5 2%3A5.6.0-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,508 kB
  • sloc: ansic: 40,477; ruby: 841; sh: 293; makefile: 30; cpp: 30
file content (161 lines) | stat: -rw-r--r-- 5,612 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
From: Geoff McLane <ubuntu@geoffair.info>
Date: Mon, 19 Feb 2018 03:21:04 +0100
Subject: Issue #679 - Fix invalid output of -export-config

Applied-Upstream: https://github.com/htacg/tidy-html5/commit/e10c29bde822690bda7d62a0e8cfebb2499224cf
---
 console/tidy.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 src/config.c   |  3 ++
 2 files changed, 93 insertions(+), 6 deletions(-)

diff --git a/console/tidy.c b/console/tidy.c
index fce4d94..d6f3ec7 100644
--- a/console/tidy.c
+++ b/console/tidy.c
@@ -1445,6 +1445,24 @@ static void printOptionValues(TidyDoc ARG_UNUSED(tdoc),  /**< The Tidy document.
             }
         }
             break;
+        case TidyPriorityAttributes: /* Is #697 - This case seems missing */
+        {
+            TidyIterator itAttr = tidyOptGetPriorityAttrList(tdoc);
+            if (itAttr && (itAttr != (TidyIterator)-1))
+            {
+                while (itAttr)
+                {
+                    d->def = tidyOptGetNextPriorityAttr(tdoc, &itAttr);
+                    if (itAttr)
+                    {
+                        printf(fmt, d->name, d->type, d->def);
+                        d->name = "";
+                        d->type = "";
+                    }
+                }
+            }
+        }
+            break;
         default:
             break;
     }
@@ -1484,6 +1502,33 @@ static void optionvalues( TidyDoc tdoc )
  ** @{
  */
 
+/* Is #697 - specialised service to 'invert' a buffers content
+   split on a space character */
+static void invertBuffer(TidyBuffer *src, TidyBuffer *dst)
+{
+    uint len = src->size;
+    char *in = (char *)src->bp;
+    char *cp;
+    if (!in)
+        return;
+    while (len)
+    {
+        unsigned char uc;
+        len--;
+        uc = in[len];
+        if (uc == ' ')
+        {
+            in[len] = 0;
+            cp = &in[len + 1];
+            if (dst->size)
+                tidyBufAppend(dst, " ", 1);
+            tidyBufAppend(dst, cp, strlen(cp));
+        }
+    }
+    if (dst->size)
+        tidyBufAppend(dst, " ", 1);
+    tidyBufAppend(dst, in, strlen(in));
+}
 
 /** Prints the option value for a given option.
  */
@@ -1493,6 +1538,7 @@ static void printOptionExportValues(TidyDoc ARG_UNUSED(tdoc),  /**< The Tidy doc
                                     )
 {
     TidyOptionId optId = tidyOptGetId( topt );
+    TidyBuffer buf1, buf2;
 
     if ( tidyOptGetCategory(topt) == TidyInternalCategory )
         return;
@@ -1505,18 +1551,56 @@ static void printOptionExportValues(TidyDoc ARG_UNUSED(tdoc),  /**< The Tidy doc
         case TidyPreTags:
         {
             TidyIterator pos = tidyOptGetDeclTagList( tdoc );
-            while ( pos )
+            if ( pos )  /* Is #697 - one or more values */
             {
-                d->def = tidyOptGetNextDeclTag(tdoc, optId, &pos);
-                if ( pos )
+                tidyBufInit(&buf1);
+                tidyBufInit(&buf2);
+                while (pos)
                 {
-                    printf( "%s: %s\n", d->name, d->def );
-                    d->name = "";
-                    d->type = "";
+                    d->def = tidyOptGetNextDeclTag(tdoc, optId, &pos);
+                    if (d->def)
+                    {
+                        if (buf1.size)
+                            tidyBufAppend(&buf1, " ", 1);
+                        tidyBufAppend(&buf1, d->def, strlen(d->def));
+                    }
                 }
+                invertBuffer(&buf1, &buf2); /* Is #697 - specialised service to invert words */
+                tidyBufAppend(&buf2, (void *)"\0", 1); /* is this really required? */
+                printf("%s: %s\n", d->name, buf2.bp);
+                d->name = "";
+                d->type = "";
+                d->def = 0;
+                tidyBufFree(&buf1);
+                tidyBufFree(&buf2);
             }
         }
             break;
+        case TidyPriorityAttributes: /* Is #697 - This case seems missing */
+        {
+            TidyIterator itAttr = tidyOptGetPriorityAttrList(tdoc);
+            if (itAttr && (itAttr != (TidyIterator)-1))
+            {
+                tidyBufInit(&buf1);
+                while (itAttr)
+                {
+                    d->def = tidyOptGetNextPriorityAttr(tdoc, &itAttr);
+                    if (d->def)
+                    {
+                        if (buf1.size)
+                            tidyBufAppend(&buf1, " ", 1);
+                        tidyBufAppend(&buf1, d->def, strlen(d->def));
+                    }
+                }
+                tidyBufAppend(&buf1, (void *)"\0", 1); /* is this really required? */
+                printf("%s: %s\n", d->name, buf1.bp);
+                d->name = "";
+                d->type = "";
+                d->def = 0;
+                tidyBufFree(&buf1);
+            }
+        }
+        break;
         default:
             break;
     }
diff --git a/src/config.c b/src/config.c
index cb53989..f2c4cb6 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1476,9 +1476,12 @@ Bool ParseCSS1Selector( TidyDocImpl* doc, const TidyOptionImpl* option )
         return no;
     }
 
+    buf[i] = 0; /* Is #697 - Do *not* add '-' */
+#if 0   /* Is #697 - Is this still required? KEEP HISTORY - DO NOT DELETE */
     buf[i++] = '-';  /* Make sure any escaped Unicode is terminated */
     buf[i] = 0;      /* so valid class names are generated after */
                      /* Tidy appends last digits. */
+#endif /* Is #697 - Is this still required? */
 
     SetOptionValue( doc, option->id, buf );
     return yes;