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

  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 C functions. Scan handlers are plain
  functions (LoadSeg'ed by GED): no standard C startup code, no library calls.
  
  DICE-C:
  
  dcc c.c -// -l0 -md -mRR -o ram:c

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

#include <exec/types.h>

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

    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);
}

