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

  Scan handler looking for C functions.
  
  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 c.c -// -l0 -md -mRR -o golded:etc/scanner/c

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

#include <exec/types.h>

ULONG
ScanHandlerC(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
{
    const char *version = "$VER: C 1.0 (" __COMMODORE_DATE__ ")";

    if (len) {

        UBYTE *from = *text;

        if (*from != 32) {

            UBYTE *last;

            for (last = from + len - 1; len && (*last == 32); --len)
                --last;

            if ((*last == ')') && (((*from >= 'A') && (*from <= 'Z')) || ((*from >= 'a') && (*from <= 'z')))) {

                UBYTE *nextChar;
                UWORD  words;

                for (words = 0, nextChar = from; nextChar < last; ++nextChar) {

                    if (*nextChar == '(') {

                        *text = from;

                        return((ULONG)(nextChar - from));
                    }
                    else if (*nextChar < '0') {

                        from = nextChar + 1;

                        if (++words > 3)
                            break;
                    }
                }
            }
        }
    }

    return(FALSE);
}

