summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Chappa <chappa@washington.edu>2016-12-27 11:09:57 -0700
committerEduardo Chappa <chappa@washington.edu>2016-12-27 11:09:57 -0700
commit054440ecce3a1ea1292cc52f37a84ad21d04cd6d (patch)
tree0ec521ecf06666c104ef192d8e00df3f56aa304c
parentd8c7c96e90a471b381080c7c12b6c526dfc4820e (diff)
downloadalpine-054440ecce3a1ea1292cc52f37a84ad21d04cd6d.tar.xz
* Add support for the TYPE and VALUE attributes of the html OL tag.
-rw-r--r--pith/filter.c51
-rw-r--r--pith/pine.hlp5
-rw-r--r--pith/string.c69
-rw-r--r--pith/string.h2
4 files changed, 121 insertions, 6 deletions
diff --git a/pith/filter.c b/pith/filter.c
index 78462cab..697ede61 100644
--- a/pith/filter.c
+++ b/pith/filter.c
@@ -2786,6 +2786,14 @@ gf_enriched2plain_opt(int *plain)
#define RSS_ITEM_LIMIT 20 /* RSS 2.0 ITEM depth limit */
+/* types of lists that we will support */
+#define LIST_DECIMAL (long) 0
+#define LIST_ALPHALO (long) 1
+#define LIST_ALPHAUP (long) 2
+#define LIST_ROMANLO (long) 3
+#define LIST_ROMANUP (long) 4
+#define LIST_UNKNOWN (long) 10
+
/*
* Handler data, state information including function that uses it
*/
@@ -5624,12 +5632,34 @@ html_ol(HANDLER_S *hd, int ch, int cmd)
html_output_raw_tag(hd->html_data, "ol");
}
else{
+ PARAMETER *p;
/*
* Signal that we're expecting to see <LI> as our next elemnt
* and set the the initial ordered count.
*/
+ hd->x = 1L; /* set default */
+ hd->y = LIST_DECIMAL; /* set default */
+ for(p = HD(hd->html_data)->el_data->attribs;
+ p && p->attribute;
+ p = p->next)
+ if(p->value){
+ if(!strucmp(p->attribute, "TYPE")){
+ if(!strucmp(p->value, "a")) /* alpha, capital */
+ hd->y = LIST_ALPHALO;
+ else if(!strucmp(p->value, "A")) /* alpha, lowercase */
+ hd->y = LIST_ALPHAUP;
+ else if(!strucmp(p->value, "i")) /* roman, capital */
+ hd->y = LIST_ROMANLO;
+ else if(!strucmp(p->value, "I")) /* roman, lowercase */
+ hd->y = LIST_ROMANUP;
+ else if(strucmp(p->value, "1")) /* decimal, the default */
+ hd->y = LIST_UNKNOWN;
+ }
+ else if(!strucmp(p->attribute, "START"))
+ hd->x = atol(p->value);
+// else ADD SUPPORT FOR OTHER ATTRIBUTES... LATER
+ }
HD(hd->html_data)->li_pending = 1;
- hd->x = 1L;
html_blank(hd->html_data, 0);
}
}
@@ -5753,7 +5783,7 @@ html_li(HANDLER_S *hd, int ch, int cmd)
if(PASS_HTML(hd->html_data)){
}
else{
- char buf[8], *p;
+ char buf[16], tmp[16], *p;
int wrapstate;
/* Start a new line */
@@ -5771,8 +5801,20 @@ html_li(HANDLER_S *hd, int ch, int cmd)
strncpy(buf, " ", sizeof(buf));
buf[1] = (l < 5) ? '*' : (l < 9) ? '+' : (l < 17) ? 'o' : '#';
}
- else if(EL(found)->handler == html_ol)
- snprintf(buf, sizeof(buf), "%2ld.", found->x++);
+ else if(EL(found)->handler == html_ol){
+ if(found->y == LIST_DECIMAL || found->y == LIST_UNKNOWN)
+ snprintf(tmp, sizeof(tmp), "%ld", found->x++);
+ else if(found->y == LIST_ALPHALO)
+ convert_decimal_to_alpha(tmp, sizeof(tmp), found->x++, 'a');
+ else if(found->y == LIST_ALPHAUP)
+ convert_decimal_to_alpha(tmp, sizeof(tmp), found->x++, 'A');
+ else if(found->y == LIST_ROMANLO)
+ convert_decimal_to_roman(tmp, sizeof(tmp), found->x++, 'i');
+ else if(found->y == LIST_ROMANUP)
+ convert_decimal_to_roman(tmp, sizeof(tmp), found->x++, 'I');
+ snprintf(buf, sizeof(buf), " %s.", tmp);
+ buf[sizeof(buf)-1] = '\0';
+ }
else if(EL(found)->handler == html_menu){
strncpy(buf, " ->", sizeof(buf));
buf[sizeof(buf)-1] = '\0';
@@ -5787,7 +5829,6 @@ html_li(HANDLER_S *hd, int ch, int cmd)
html_write_indent(hd->html_data, HD(hd->html_data)->indent_level);
for(p = buf; *p; p++)
html_output(hd->html_data, (int) *p);
-
HD(hd->html_data)->wrapstate = wrapstate;
html_indent(hd->html_data, 4, HTML_ID_INC);
}
diff --git a/pith/pine.hlp b/pith/pine.hlp
index 0004b755..3ff77947 100644
--- a/pith/pine.hlp
+++ b/pith/pine.hlp
@@ -140,7 +140,7 @@ with help text for the config screen and the composer that didn't have any
reasonable place to be called from.
Dummy change to get revision in pine.hlp
============= h_revision =================
-Alpine Commit 199 2016-12-22 23:43:01
+Alpine Commit 200 2016-12-27 11:09:52
============= h_news =================
<HTML>
<HEAD>
@@ -243,6 +243,9 @@ Additions include:
as well as autocompletes automatically when only one possibility exists
for the ^J attach command.
+ <LI> Add support for the &quot;TYPE&quot; and &quot;VALUE&quot; attributes of
+ the html OL tag.
+
<LI> Ignore message from smtp server after a successful authentication
challenge.
diff --git a/pith/string.c b/pith/string.c
index afc9dacc..0b65fe3f 100644
--- a/pith/string.c
+++ b/pith/string.c
@@ -2913,3 +2913,72 @@ free_strlist(STRLIST_S **strp)
fs_give((void **) strp);
}
}
+
+void
+convert_decimal_to_roman (char *rn, size_t len, long n, char l)
+{
+ char *symbols;
+ int amo[6];
+ int i, j, k;
+
+ rn[0] = '\0';
+ if(n >= 4000L || n <= 0L)
+ return;
+
+ if(l == 'i')
+ symbols = "mdclxvi";
+ else
+ symbols = "MDCLXVI";
+
+ amo[0] = n/1000; n -= amo[0]*1000;
+ amo[1] = n/500; n -= amo[1]*500;
+ amo[2] = n/100; n -= amo[2]*100;
+ amo[3] = n/50; n -= amo[3]*50;
+ amo[4] = n/10; n -= amo[4]*10;
+ amo[5] = n/5; n -= amo[5]*5;
+ amo[6] = n;
+
+ for(i = 0, j = 0; j < strlen(symbols); j++){
+ if(amo[j] < 4){
+ if(amo[j+1] != 4){
+ for(k = 0; k < amo[j]; k++)
+ rn[i++] = symbols[j];
+ }
+ } else {
+ if(amo[j-1] == 0){
+ rn[i++] = symbols[j];
+ rn[i++] = symbols[j-1];
+ } else {
+ rn[i++] = symbols[j];
+ rn[i++] = symbols[j-2];
+ }
+ }
+ }
+ rn[i++] = '\0';
+ rn[len] = '\0';
+}
+
+void
+convert_decimal_to_alpha (char *rn, size_t len, long n, char l)
+{
+ char *symbols;
+ int amo[16];
+ int i, j, k;
+
+ rn[0] = '\0';
+
+ if(n < 0)
+ return;
+
+ for(i = 0; n > 0; i++){
+ amo[i] = n % 26;
+ n = (n - amo[i])/26;
+ }
+ amo[i] = -1;
+
+ for(i = 0; amo[i] >= 0; i++)
+ rn[i] = l + amo[i] - 1;
+ rn[i] = '\0';
+ rn[len] = '\0';
+}
+
diff --git a/pith/string.h b/pith/string.h
index b142c7dc..9d446b23 100644
--- a/pith/string.h
+++ b/pith/string.h
@@ -149,5 +149,7 @@ void combine_strlists(STRLIST_S **, STRLIST_S *);
void free_strlist(STRLIST_S **);
int read_octal(char **);
time_t date_to_local_time_t(char *);
+void convert_decimal_to_roman (char *, size_t, long, char);
+void convert_decimal_to_alpha (char *, size_t, long, char);
#endif /* PITH_STRING_INCLUDED */