Fossil SCM

Restructured the wiki format parser's ATTR_ and AMSK_ macros to enums to simplify extension. Tried to add data-* attribute support but assumptions about attributes in the parser make it not worth the effort.

stephan 2014-03-16 10:17 UTC trunk
Commit 0652717eb050ba54c13796925db6e5e8ac70a378
1 file changed +97 -88
+97 -88
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -35,103 +35,112 @@
3535
3636
3737
/*
3838
** These are the only markup attributes allowed.
3939
*/
40
-#define ATTR_ALIGN 1
41
-#define ATTR_ALT 2
42
-#define ATTR_BGCOLOR 3
43
-#define ATTR_BORDER 4
44
-#define ATTR_CELLPADDING 5
45
-#define ATTR_CELLSPACING 6
46
-#define ATTR_CLASS 7
47
-#define ATTR_CLEAR 8
48
-#define ATTR_COLOR 9
49
-#define ATTR_COLSPAN 10
50
-#define ATTR_COMPACT 11
51
-#define ATTR_FACE 12
52
-#define ATTR_HEIGHT 13
53
-#define ATTR_HREF 14
54
-#define ATTR_HSPACE 15
55
-#define ATTR_ID 16
56
-#define ATTR_LINKS 17
57
-#define ATTR_NAME 18
58
-#define ATTR_ROWSPAN 19
59
-#define ATTR_SIZE 20
60
-#define ATTR_SRC 21
61
-#define ATTR_START 22
62
-#define ATTR_STYLE 23
63
-#define ATTR_TARGET 24
64
-#define ATTR_TYPE 25
65
-#define ATTR_VALIGN 26
66
-#define ATTR_VALUE 27
67
-#define ATTR_VSPACE 28
68
-#define ATTR_WIDTH 29
69
-#define AMSK_ALIGN 0x00000001
70
-#define AMSK_ALT 0x00000002
71
-#define AMSK_BGCOLOR 0x00000004
72
-#define AMSK_BORDER 0x00000008
73
-#define AMSK_CELLPADDING 0x00000010
74
-#define AMSK_CELLSPACING 0x00000020
75
-#define AMSK_CLASS 0x00000040
76
-#define AMSK_CLEAR 0x00000080
77
-#define AMSK_COLOR 0x00000100
78
-#define AMSK_COLSPAN 0x00000200
79
-#define AMSK_COMPACT 0x00000400
80
-#define AMSK_FACE 0x00000800
81
-#define AMSK_HEIGHT 0x00001000
82
-#define AMSK_HREF 0x00002000
83
-#define AMSK_HSPACE 0x00004000
84
-#define AMSK_ID 0x00008000
85
-#define AMSK_LINKS 0x00010000
86
-#define AMSK_NAME 0x00020000
87
-#define AMSK_ROWSPAN 0x00040000
88
-#define AMSK_SIZE 0x00080000
89
-#define AMSK_SRC 0x00100000
90
-#define AMSK_START 0x00200000
91
-#define AMSK_STYLE 0x00400000
92
-#define AMSK_TARGET 0x00800000
93
-#define AMSK_TYPE 0x01000000
94
-#define AMSK_VALIGN 0x02000000
95
-#define AMSK_VALUE 0x04000000
96
-#define AMSK_VSPACE 0x08000000
97
-#define AMSK_WIDTH 0x10000000
40
+enum allowed_attr_t {
41
+ ATTR_ALIGN = 1,
42
+ ATTR_ALT,
43
+ ATTR_BGCOLOR,
44
+ ATTR_BORDER,
45
+ ATTR_CELLPADDING,
46
+ ATTR_CELLSPACING,
47
+ ATTR_CLASS,
48
+ ATTR_CLEAR,
49
+ ATTR_COLOR,
50
+ ATTR_COLSPAN,
51
+ ATTR_COMPACT,
52
+ ATTR_FACE,
53
+ ATTR_HEIGHT,
54
+ ATTR_HREF,
55
+ ATTR_HSPACE,
56
+ ATTR_ID,
57
+ ATTR_LINKS,
58
+ ATTR_NAME,
59
+ ATTR_ROWSPAN,
60
+ ATTR_SIZE,
61
+ ATTR_SRC,
62
+ ATTR_START,
63
+ ATTR_STYLE,
64
+ ATTR_TARGET,
65
+ ATTR_TYPE,
66
+ ATTR_VALIGN,
67
+ ATTR_VALUE,
68
+ ATTR_VSPACE,
69
+ ATTR_WIDTH
70
+};
71
+
72
+enum amsk_t {
73
+ AMSK_ALIGN = 0x00000001,
74
+ AMSK_ALT = 0x00000002,
75
+ AMSK_BGCOLOR = 0x00000004,
76
+ AMSK_BORDER = 0x00000008,
77
+ AMSK_CELLPADDING = 0x00000010,
78
+ AMSK_CELLSPACING = 0x00000020,
79
+ AMSK_CLASS = 0x00000040,
80
+ AMSK_CLEAR = 0x00000080,
81
+ AMSK_COLOR = 0x00000100,
82
+ AMSK_COLSPAN = 0x00000200,
83
+ AMSK_COMPACT = 0x00000400,
84
+ /* re-use = 0x00000800, */
85
+ AMSK_FACE = 0x00001000,
86
+ AMSK_HEIGHT = 0x00002000,
87
+ AMSK_HREF = 0x00004000,
88
+ AMSK_HSPACE = 0x00008000,
89
+ AMSK_ID = 0x00010000,
90
+ AMSK_LINKS = 0x00020000,
91
+ AMSK_NAME = 0x00040000,
92
+ AMSK_ROWSPAN = 0x00080000,
93
+ AMSK_SIZE = 0x00100000,
94
+ AMSK_SRC = 0x00200000,
95
+ AMSK_START = 0x00400000,
96
+ AMSK_STYLE = 0x00800000,
97
+ AMSK_TARGET = 0x01000000,
98
+ AMSK_TYPE = 0x02000000,
99
+ AMSK_VALIGN = 0x04000000,
100
+ AMSK_VALUE = 0x08000000,
101
+ AMSK_VSPACE = 0x10000000,
102
+ AMSK_WIDTH = 0x20000000
103
+};
98104
99105
static const struct AllowedAttribute {
100106
const char *zName;
101107
unsigned int iMask;
102108
} aAttribute[] = {
109
+ /* These indexes MUST line up with their
110
+ corresponding allowed_attr_t enum values.
111
+ */
103112
{ 0, 0 },
104
- { "align", AMSK_ALIGN, },
105
- { "alt", AMSK_ALT, },
106
- { "bgcolor", AMSK_BGCOLOR, },
107
- { "border", AMSK_BORDER, },
108
- { "cellpadding", AMSK_CELLPADDING, },
109
- { "cellspacing", AMSK_CELLSPACING, },
110
- { "class", AMSK_CLASS, },
111
- { "clear", AMSK_CLEAR, },
112
- { "color", AMSK_COLOR, },
113
- { "colspan", AMSK_COLSPAN, },
114
- { "compact", AMSK_COMPACT, },
115
- { "face", AMSK_FACE, },
116
- { "height", AMSK_HEIGHT, },
117
- { "href", AMSK_HREF, },
118
- { "hspace", AMSK_HSPACE, },
119
- { "id", AMSK_ID, },
120
- { "links", AMSK_LINKS, },
121
- { "name", AMSK_NAME, },
122
- { "rowspan", AMSK_ROWSPAN, },
123
- { "size", AMSK_SIZE, },
124
- { "src", AMSK_SRC, },
125
- { "start", AMSK_START, },
126
- { "style", AMSK_STYLE, },
127
- { "target", AMSK_TARGET, },
128
- { "type", AMSK_TYPE, },
129
- { "valign", AMSK_VALIGN, },
130
- { "value", AMSK_VALUE, },
131
- { "vspace", AMSK_VSPACE, },
132
- { "width", AMSK_WIDTH, },
113
+ { "align", AMSK_ALIGN },
114
+ { "alt", AMSK_ALT },
115
+ { "bgcolor", AMSK_BGCOLOR },
116
+ { "border", AMSK_BORDER },
117
+ { "cellpadding", AMSK_CELLPADDING },
118
+ { "cellspacing", AMSK_CELLSPACING },
119
+ { "class", AMSK_CLASS },
120
+ { "clear", AMSK_CLEAR },
121
+ { "color", AMSK_COLOR },
122
+ { "colspan", AMSK_COLSPAN },
123
+ { "compact", AMSK_COMPACT },
124
+ { "face", AMSK_FACE },
125
+ { "height", AMSK_HEIGHT },
126
+ { "href", AMSK_HREF },
127
+ { "hspace", AMSK_HSPACE },
128
+ { "id", AMSK_ID },
129
+ { "links", AMSK_LINKS },
130
+ { "name", AMSK_NAME },
131
+ { "rowspan", AMSK_ROWSPAN },
132
+ { "size", AMSK_SIZE },
133
+ { "src", AMSK_SRC },
134
+ { "start", AMSK_START },
135
+ { "style", AMSK_STYLE },
136
+ { "target", AMSK_TARGET },
137
+ { "type", AMSK_TYPE },
138
+ { "valign", AMSK_VALIGN },
139
+ { "value", AMSK_VALUE },
140
+ { "vspace", AMSK_VSPACE },
141
+ { "width", AMSK_WIDTH },
133142
};
134143
135144
/*
136145
** Use binary search to locate a tag in the aAttribute[] table.
137146
*/
@@ -789,11 +798,11 @@
789798
p->nAttr = 1;
790799
if( c=='>' ) return;
791800
}
792801
while( fossil_isspace(z[i]) ){ i++; }
793802
while( c!='>' && p->nAttr<8 && fossil_isalpha(z[i]) ){
794
- int attrOk; /* True to preserver attribute. False to ignore it */
803
+ int attrOk; /* True to preserve attribute. False to ignore it */
795804
j = 0;
796805
while( fossil_isalnum(z[i]) ){
797806
if( j<sizeof(zTag)-1 ) zTag[j++] = fossil_tolower(z[i]);
798807
i++;
799808
}
800809
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -35,103 +35,112 @@
35
36
37 /*
38 ** These are the only markup attributes allowed.
39 */
40 #define ATTR_ALIGN 1
41 #define ATTR_ALT 2
42 #define ATTR_BGCOLOR 3
43 #define ATTR_BORDER 4
44 #define ATTR_CELLPADDING 5
45 #define ATTR_CELLSPACING 6
46 #define ATTR_CLASS 7
47 #define ATTR_CLEAR 8
48 #define ATTR_COLOR 9
49 #define ATTR_COLSPAN 10
50 #define ATTR_COMPACT 11
51 #define ATTR_FACE 12
52 #define ATTR_HEIGHT 13
53 #define ATTR_HREF 14
54 #define ATTR_HSPACE 15
55 #define ATTR_ID 16
56 #define ATTR_LINKS 17
57 #define ATTR_NAME 18
58 #define ATTR_ROWSPAN 19
59 #define ATTR_SIZE 20
60 #define ATTR_SRC 21
61 #define ATTR_START 22
62 #define ATTR_STYLE 23
63 #define ATTR_TARGET 24
64 #define ATTR_TYPE 25
65 #define ATTR_VALIGN 26
66 #define ATTR_VALUE 27
67 #define ATTR_VSPACE 28
68 #define ATTR_WIDTH 29
69 #define AMSK_ALIGN 0x00000001
70 #define AMSK_ALT 0x00000002
71 #define AMSK_BGCOLOR 0x00000004
72 #define AMSK_BORDER 0x00000008
73 #define AMSK_CELLPADDING 0x00000010
74 #define AMSK_CELLSPACING 0x00000020
75 #define AMSK_CLASS 0x00000040
76 #define AMSK_CLEAR 0x00000080
77 #define AMSK_COLOR 0x00000100
78 #define AMSK_COLSPAN 0x00000200
79 #define AMSK_COMPACT 0x00000400
80 #define AMSK_FACE 0x00000800
81 #define AMSK_HEIGHT 0x00001000
82 #define AMSK_HREF 0x00002000
83 #define AMSK_HSPACE 0x00004000
84 #define AMSK_ID 0x00008000
85 #define AMSK_LINKS 0x00010000
86 #define AMSK_NAME 0x00020000
87 #define AMSK_ROWSPAN 0x00040000
88 #define AMSK_SIZE 0x00080000
89 #define AMSK_SRC 0x00100000
90 #define AMSK_START 0x00200000
91 #define AMSK_STYLE 0x00400000
92 #define AMSK_TARGET 0x00800000
93 #define AMSK_TYPE 0x01000000
94 #define AMSK_VALIGN 0x02000000
95 #define AMSK_VALUE 0x04000000
96 #define AMSK_VSPACE 0x08000000
97 #define AMSK_WIDTH 0x10000000
 
 
 
 
 
 
98
99 static const struct AllowedAttribute {
100 const char *zName;
101 unsigned int iMask;
102 } aAttribute[] = {
 
 
 
103 { 0, 0 },
104 { "align", AMSK_ALIGN, },
105 { "alt", AMSK_ALT, },
106 { "bgcolor", AMSK_BGCOLOR, },
107 { "border", AMSK_BORDER, },
108 { "cellpadding", AMSK_CELLPADDING, },
109 { "cellspacing", AMSK_CELLSPACING, },
110 { "class", AMSK_CLASS, },
111 { "clear", AMSK_CLEAR, },
112 { "color", AMSK_COLOR, },
113 { "colspan", AMSK_COLSPAN, },
114 { "compact", AMSK_COMPACT, },
115 { "face", AMSK_FACE, },
116 { "height", AMSK_HEIGHT, },
117 { "href", AMSK_HREF, },
118 { "hspace", AMSK_HSPACE, },
119 { "id", AMSK_ID, },
120 { "links", AMSK_LINKS, },
121 { "name", AMSK_NAME, },
122 { "rowspan", AMSK_ROWSPAN, },
123 { "size", AMSK_SIZE, },
124 { "src", AMSK_SRC, },
125 { "start", AMSK_START, },
126 { "style", AMSK_STYLE, },
127 { "target", AMSK_TARGET, },
128 { "type", AMSK_TYPE, },
129 { "valign", AMSK_VALIGN, },
130 { "value", AMSK_VALUE, },
131 { "vspace", AMSK_VSPACE, },
132 { "width", AMSK_WIDTH, },
133 };
134
135 /*
136 ** Use binary search to locate a tag in the aAttribute[] table.
137 */
@@ -789,11 +798,11 @@
789 p->nAttr = 1;
790 if( c=='>' ) return;
791 }
792 while( fossil_isspace(z[i]) ){ i++; }
793 while( c!='>' && p->nAttr<8 && fossil_isalpha(z[i]) ){
794 int attrOk; /* True to preserver attribute. False to ignore it */
795 j = 0;
796 while( fossil_isalnum(z[i]) ){
797 if( j<sizeof(zTag)-1 ) zTag[j++] = fossil_tolower(z[i]);
798 i++;
799 }
800
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -35,103 +35,112 @@
35
36
37 /*
38 ** These are the only markup attributes allowed.
39 */
40 enum allowed_attr_t {
41 ATTR_ALIGN = 1,
42 ATTR_ALT,
43 ATTR_BGCOLOR,
44 ATTR_BORDER,
45 ATTR_CELLPADDING,
46 ATTR_CELLSPACING,
47 ATTR_CLASS,
48 ATTR_CLEAR,
49 ATTR_COLOR,
50 ATTR_COLSPAN,
51 ATTR_COMPACT,
52 ATTR_FACE,
53 ATTR_HEIGHT,
54 ATTR_HREF,
55 ATTR_HSPACE,
56 ATTR_ID,
57 ATTR_LINKS,
58 ATTR_NAME,
59 ATTR_ROWSPAN,
60 ATTR_SIZE,
61 ATTR_SRC,
62 ATTR_START,
63 ATTR_STYLE,
64 ATTR_TARGET,
65 ATTR_TYPE,
66 ATTR_VALIGN,
67 ATTR_VALUE,
68 ATTR_VSPACE,
69 ATTR_WIDTH
70 };
71
72 enum amsk_t {
73 AMSK_ALIGN = 0x00000001,
74 AMSK_ALT = 0x00000002,
75 AMSK_BGCOLOR = 0x00000004,
76 AMSK_BORDER = 0x00000008,
77 AMSK_CELLPADDING = 0x00000010,
78 AMSK_CELLSPACING = 0x00000020,
79 AMSK_CLASS = 0x00000040,
80 AMSK_CLEAR = 0x00000080,
81 AMSK_COLOR = 0x00000100,
82 AMSK_COLSPAN = 0x00000200,
83 AMSK_COMPACT = 0x00000400,
84 /* re-use = 0x00000800, */
85 AMSK_FACE = 0x00001000,
86 AMSK_HEIGHT = 0x00002000,
87 AMSK_HREF = 0x00004000,
88 AMSK_HSPACE = 0x00008000,
89 AMSK_ID = 0x00010000,
90 AMSK_LINKS = 0x00020000,
91 AMSK_NAME = 0x00040000,
92 AMSK_ROWSPAN = 0x00080000,
93 AMSK_SIZE = 0x00100000,
94 AMSK_SRC = 0x00200000,
95 AMSK_START = 0x00400000,
96 AMSK_STYLE = 0x00800000,
97 AMSK_TARGET = 0x01000000,
98 AMSK_TYPE = 0x02000000,
99 AMSK_VALIGN = 0x04000000,
100 AMSK_VALUE = 0x08000000,
101 AMSK_VSPACE = 0x10000000,
102 AMSK_WIDTH = 0x20000000
103 };
104
105 static const struct AllowedAttribute {
106 const char *zName;
107 unsigned int iMask;
108 } aAttribute[] = {
109 /* These indexes MUST line up with their
110 corresponding allowed_attr_t enum values.
111 */
112 { 0, 0 },
113 { "align", AMSK_ALIGN },
114 { "alt", AMSK_ALT },
115 { "bgcolor", AMSK_BGCOLOR },
116 { "border", AMSK_BORDER },
117 { "cellpadding", AMSK_CELLPADDING },
118 { "cellspacing", AMSK_CELLSPACING },
119 { "class", AMSK_CLASS },
120 { "clear", AMSK_CLEAR },
121 { "color", AMSK_COLOR },
122 { "colspan", AMSK_COLSPAN },
123 { "compact", AMSK_COMPACT },
124 { "face", AMSK_FACE },
125 { "height", AMSK_HEIGHT },
126 { "href", AMSK_HREF },
127 { "hspace", AMSK_HSPACE },
128 { "id", AMSK_ID },
129 { "links", AMSK_LINKS },
130 { "name", AMSK_NAME },
131 { "rowspan", AMSK_ROWSPAN },
132 { "size", AMSK_SIZE },
133 { "src", AMSK_SRC },
134 { "start", AMSK_START },
135 { "style", AMSK_STYLE },
136 { "target", AMSK_TARGET },
137 { "type", AMSK_TYPE },
138 { "valign", AMSK_VALIGN },
139 { "value", AMSK_VALUE },
140 { "vspace", AMSK_VSPACE },
141 { "width", AMSK_WIDTH },
142 };
143
144 /*
145 ** Use binary search to locate a tag in the aAttribute[] table.
146 */
@@ -789,11 +798,11 @@
798 p->nAttr = 1;
799 if( c=='>' ) return;
800 }
801 while( fossil_isspace(z[i]) ){ i++; }
802 while( c!='>' && p->nAttr<8 && fossil_isalpha(z[i]) ){
803 int attrOk; /* True to preserve attribute. False to ignore it */
804 j = 0;
805 while( fossil_isalnum(z[i]) ){
806 if( j<sizeof(zTag)-1 ) zTag[j++] = fossil_tolower(z[i]);
807 i++;
808 }
809

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button