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

  Example: scan handler looking for #defines. Scan handlers are plain functions 
  (LoadSeg'ed by GED): no standard C startup code, no library calls. 
  
  DICE-C:
  
  dcc define.c -// -l0 -md -mRR -o ram:Defines

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

#include <exec/types.h>

#define UPPER(a) ((a) & 95)

ULONG
ScanHandlerGuide(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
{
    const char *version = "$VER: Define 1.3 (16.6.95)";

    if (**text == '#') {

        if (len > 8) {

            UBYTE *next = *text + 1;

            if (UPPER(*next++) == 'D') {

                if (UPPER(*next++) == 'E') {

                    if (UPPER(*next++) == 'F') {

                        if (UPPER(*next++) == 'I') {

                            if (UPPER(*next++) == 'N') {

                                if (UPPER(*next++) == 'E') {

                                    if (*next++ == ' ') {

                                        UWORD letters = 0;

                                        for (len -= 8; (*next == 32) && len; --len)
                                            ++next;

                                        for (*text = next; len && (*next++ != ' '); --len)
                                            ++letters;

                                        return(letters);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return(NULL);
}
