home *** CD-ROM | disk | FTP | other *** search
- /* -----------------------------------------------------------------------------
-
- Scan handler looking for HTML anchors.
-
- Scan handlers are plain functions (loadSeg()'ed): no standard C startup
- code and no library calls permitted. We have to put string constants into
- the code segment (DICE compiler: option -ms1).
-
- DICE-C:
-
- dcc html.c -// -l0 -md -ms2 -mRR -o golded:etc/scanner/html
-
- ------------------------------------------------------------------------------
- */
-
- #include <exec/types.h>
-
- #define UPPER(a) ((a) & 95)
-
- ULONG
- ScanHandlerHTML(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
- {
- const char *version = "$VER: HTML 1.3 (" __COMMODORE_DATE__ ")";
-
- // use string constant as result buffer (string constants go into the code section; remember: this program is compiled without startup code)
-
- UBYTE *buffer = " ";
-
- // minimum strings: <A NAME="X"> or <A HREF="X">
-
- if (len >= 12) {
-
- UBYTE *from, *start, *last;
-
- from = *text;
- last = *text + len;
-
- while ((from + 11) < last) {
-
- // anchor detected ?
-
- if ((from[0] == '<') && (UPPER(from[1]) == 'A') && (from[2] == ' ')) {
-
- // 1st try: look for <A HREF="..."> or <A NAME="...">
-
- for (start = from + 3; start < last; ++start) {
-
- if (UPPER(*start) == 'H') {
-
- if (UPPER(start[1]) == 'R') {
-
- if (UPPER(start[2]) == 'E') {
-
- if (UPPER(start[3]) == 'F') {
-
- for (start += 4; start < last; ++start) {
-
- // look for beginning of link string
-
- if (*start == 34) {
-
- UBYTE *result = buffer;
-
- *result++ = 'H';
- *result++ = 'R';
- *result++ = 'E';
- *result++ = 'F';
- *result++ = ' ';
-
- for (len = 5, ++start; start < last; ++len) {
-
- if (len == 50)
-
- break;
-
- if (*start == 34) {
-
- *text = buffer;
-
- return(len);
- }
- else
- *result++ = *start++;
- }
- }
- }
- }
- }
- }
- }
-
- if (UPPER(*start) == 'N') {
-
- if (UPPER(start[1]) == 'A') {
-
- if (UPPER(start[2]) == 'M') {
-
- if (UPPER(start[3]) == 'E') {
-
- for (start += 4; start < last; ++start) {
-
- // look for beginning of link string
-
- if (*start == 34) {
-
- UBYTE *result = buffer;
-
- *result++ = 'N';
- *result++ = 'A';
- *result++ = 'M';
- *result++ = 'E';
- *result++ = ' ';
-
- for (len = 5, ++start; start < last; ++len) {
-
- if (len == 50)
-
- break;
-
- if (*start == 34) {
-
- *text = buffer;
-
- return(len);
- }
- else
- *result++ = *start++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- ++from;
- }
- }
-
- return(FALSE);
- }
-
-