/* -----------------------------------------------------------------------------

  Scan handler looking for AutoDoc nodes. This handler is faster than the
  built-in AutoDoc handler since it simply looks for formfeeds. Won't work
  with all AutoDocs, though. Commodore's AutoDocs are handled properly.

  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:

  dcc autodoc.c -// -l0 -md -mRR -o golded:etc/scanner/autodoc

  ------------------------------------------------------------------------------
*/

#include <exec/types.h>

#define FORMFEED 12

ULONG
ScanHandlerGuide(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
{
    // look for node header

    const char *version = "$VER: ADoc 1.3 (" __COMMODORE_DATE__ ")";

    if (**text == FORMFEED) {

        // look for beginning of header string (e.g. "Dos.Library/Open")

        while (len && (**text <= ' ')) {

            ++*text;
            --len;
        }

        // ignore first part of header string

        while (len && (**text != '/')) {

            ++*text;
            len--;
        }

        // extract node name

        if (len) {

            UWORD letters;

            ++*text;
            --len;

            for (letters = 0; len && ((*text)[letters] != 32); --len)
                ++letters;

            return(letters);
        }
    }

    return(FALSE);
}
