commit 96bce9d943086789a0a80bdce973ddb7a43b3e43
parent 137f217bb55e5d4199d3699326a072da594e96ed
Author: Alexander Burger <abu@software-lab.de>
Date: Fri, 18 May 2012 11:07:14 +0200
Removed HtOK stuff from ht:Prin
Diffstat:
M | src/ht.c | | | 83 | +++++++++++++++++++++++++------------------------------------------------------ |
M | src64/ht.l | | | 116 | +++++++++++++++++++------------------------------------------------------------ |
2 files changed, 54 insertions(+), 145 deletions(-)
diff --git a/src/ht.c b/src/ht.c
@@ -1,34 +1,9 @@
-/* 22jul11abu
+/* 18may12abu
* (c) Software Lab. Alexander Burger
*/
#include "pico.h"
-static char *HtOK[] = {
- "<b>", "</b>",
- "<i>", "</i>",
- "<u>", "</u>",
- "<p>", "</p>",
- "<pre>", "</pre>",
- "<div ", "</div>",
- "<br>", "<hr>", NULL
-};
-
-static bool findHtOK(char *s) {
- char **p, *q, *t;
-
- for (p = HtOK; *p; ++p)
- for (q = *p, t = s;;) {
- if (*q != *t)
- break;
- if (*++q == '\0')
- return YES;
- if (*++t == '\0')
- break;
- }
- return NO;
-}
-
// (ht:Prin 'sym ..) -> sym
any Prin(any x) {
any y = Nil;
@@ -38,43 +13,37 @@ any Prin(any x) {
prin(y);
else {
int c;
- char *p, *q, nm[bufSize(y)];
+ char *p, nm[bufSize(y)];
bufString(y, nm);
for (p = nm; *p;) {
- if (findHtOK(p) && (q = strchr(p,'>')))
- do
- Env.put(*p++);
- while (p <= q);
- else {
- switch (*(byte*)p) {
- case '<':
- outString("<");
- break;
- case '>':
- outString(">");
- break;
- case '&':
- outString("&");
- break;
- case '"':
- outString(""");
- break;
- case 0xFF:
- Env.put(0xEF);
- Env.put(0xBF);
- Env.put(0xBF);
- break;
- default:
- Env.put(c = *p);
- if ((c & 0x80) != 0) {
+ switch (*(byte*)p) {
+ case '<':
+ outString("<");
+ break;
+ case '>':
+ outString(">");
+ break;
+ case '&':
+ outString("&");
+ break;
+ case '"':
+ outString(""");
+ break;
+ case 0xFF:
+ Env.put(0xEF);
+ Env.put(0xBF);
+ Env.put(0xBF);
+ break;
+ default:
+ Env.put(c = *p);
+ if ((c & 0x80) != 0) {
+ Env.put(*++p);
+ if ((c & 0x20) != 0)
Env.put(*++p);
- if ((c & 0x20) != 0)
- Env.put(*++p);
- }
}
- ++p;
}
+ ++p;
}
}
}
diff --git a/src64/ht.l b/src64/ht.l
@@ -1,27 +1,10 @@
-# 29sep11abu
+# 18may12abu
# (c) Software Lab. Alexander Burger
(data 'HtData)
initData
### Hypertext I/O functions ###
-(data 'HtOK)
-align 8 asciz "<b>"
-align 8 asciz "</b>"
-align 8 asciz "<i>"
-align 8 asciz "</i>"
-align 8 asciz "<u>"
-align 8 asciz "</u>"
-align 8 asciz "<p>"
-align 8 asciz "</p>"
-align 8 asciz "<pre>"
-align 8 asciz "</pre>"
-align 8 asciz "<div "
-align 8 asciz "</div>"
-align 8 asciz "<br>"
-align 8 asciz "<hr>"
-: HtOkEnd
-
: HtLt asciz "<"
: HtGt asciz ">"
: HtAmp asciz "&"
@@ -34,39 +17,6 @@ align 8 asciz "<hr>"
(code 'HtCode)
initCode
-(code 'findHtOkY_FE 0)
- push X
- ld X HtOK
- do
- push X
- push Y
- do
- ld B (X) # Compare bytes
- cmp B (Y) # Equal?
- while eq # Yes
- inc X # End of HtOk string?
- nul (X)
- if z # Yes: Found
- slen C Y # Length of the remaining string
- ld B (char ">") # Is there a closing tag?
- memb Y C
- ldz E Y # Yes: Return pointer to next char in E
- pop Y
- pop X
- pop X
- ret # 'z' or 'nz'
- end
- inc Y # End of data?
- nul (Y)
- until z # Yes
- pop Y
- pop X
- add X 8 # Try next
- cmp X HtOkEnd # Done?
- until gt # Yes
- pop X
- ret # 'nz'
-
# (ht:Prin 'sym ..) -> sym
(code 'Prin 2)
push X
@@ -90,66 +40,56 @@ align 8 asciz "<hr>"
do
nul (Y) # Null byte?
while nz # No
- call findHtOkY_FE # Preserved pattern?
- if z # Yes
- do
- ld B (Y) # Output partial string
- call (PutB)
- inc Y # till end pointer in E
- cmp Y E
- until eq
+ ld B (Y) # Next byte
+ cmp B (char "<") # Escape special characters
+ if eq
+ ld C HtLt # "<"
+ call outStringC
else
- ld B (Y) # Next byte
- cmp B (char "<") # Escape special characters
+ cmp B (char ">")
if eq
- ld C HtLt # "<"
+ ld C HtGt # ">"
call outStringC
else
- cmp B (char ">")
+ cmp B (char "&")
if eq
- ld C HtGt # ">"
+ ld C HtAmp # "&"
call outStringC
else
- cmp B (char "&")
+ cmp B (char "\"")
if eq
- ld C HtAmp # "&"
+ ld C HtQuot # """
call outStringC
else
- cmp B (char "\"")
+ cmp B (hex "FF")
if eq
- ld C HtQuot # """
- call outStringC
+ ld B (hex "EF")
+ call (PutB)
+ ld B (hex "BF")
+ call (PutB)
+ ld B (hex "BF")
+ call (PutB)
else
- cmp B (hex "FF")
- if eq
- ld B (hex "EF")
- call (PutB)
- ld B (hex "BF")
- call (PutB)
- ld B (hex "BF")
+ ld C A # Save char
+ call (PutB) # Output it
+ test C (hex "80") # Double byte?
+ if nz # Yes
+ inc Y # Next
+ ld B (Y) # Output second byte
call (PutB)
- else
- ld C A # Save char
- call (PutB) # Output it
- test C (hex "80") # Double byte?
+ test C (hex "20") # Triple byte?
if nz # Yes
inc Y # Next
- ld B (Y) # Output second byte
+ ld B (Y) # Output third byte
call (PutB)
- test C (hex "20") # Triple byte?
- if nz # Yes
- inc Y # Next
- ld B (Y) # Output third byte
- call (PutB)
- end
end
end
end
end
end
end
- inc Y # Increment string pointer
end
+ inc Y # Increment string pointer
loop
ld S Z # Drop buffer
pop E