home *** CD-ROM | disk | FTP | other *** search
- /* -----------------------------------------------------------------------------
-
- COPYIGHT
-
- ©1995 Dietmar Eilert (e-mail: DIETMAR@TOMATE.TNG.OCHE.DE). All Rights
- Reserved. Code may not be reused/reproduced without written permission of
- the author.
-
- Dietmar Eilert
- Mies-v-d-Rohe-Str.31, 52074 Aachen, Germany
- E-Mail: DIETMAR@TOMATE.TNG.OCHE.DE
- Tel: +49-(0)241-81665
- +49-(0)2525-7776
- Fax: +49-(0)241-81665
-
- Example: scan handler looking for HTML anchors. Known bug: can not handle
- more than one anchor per line due to the scanner interface design.
-
- Scan handlers are plain functions (LoadSeg'ed by GED): no standard C startup
- code, no library calls. String constants have to be put into the code chunk.
- That's why below a string constant is (ab)used as a buffer instead of using
- a static array.
-
- DICE-C:
-
- dcc html.c -// -l0 -md -ms2 -mRR -o ram: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.0 (5.2.95)";
-
- if (len >= 12) { // minimum strings: <A NAME="X">
- // <A HREF="X">
- UBYTE *from, *start, *last;
-
- UBYTE *buffer =
-
- " "
- " "
- " "
- " ";
-
- from = *text;
- last = *text + len - 12;
-
- while (from <= last) {
-
- if (*from == '<') {
-
- // anchor detected ?
-
- if ((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 ((*start == 34) || (len == 255)) {
-
- *text = buffer;
-
- return(len);
- }
- else
- *result++ = *start++;
- }
-
- return(FALSE);
- }
- }
- }
- }
- }
- }
-
- 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 ((*start == 34) || (len == 255)) {
-
- *text = buffer;
-
- return(len);
- }
- else
- *result++ = *start++;
- }
-
- return(FALSE);
- }
- }
- }
- }
- }
- }
- }
-
- break;
- }
- else
- ++from;
- }
- else
- ++from;
- }
- }
-
- return(FALSE);
- }
-
-