~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to lefty/dot2l/triefa.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* File - TrieFA.ins.c
 
2
 *
 
3
 *    This file contains code to be included in the scanner file using a
 
4
 *    generated trie-based FA.
 
5
 */
 
6
 
 
7
#include "triefa.h"
 
8
 
 
9
#ifdef UNDERLINE
 
10
static long CharMask[28] = {
 
11
    0x0000001, 0x0000000, 0x0000004, 0x0000008,
 
12
    0x0000010, 0x0000020, 0x0000040, 0x0000080,
 
13
    0x0000100, 0x0000200, 0x0000400, 0x0000800,
 
14
    0x0001000, 0x0002000, 0x0004000, 0x0008000,
 
15
    0x0010000, 0x0020000, 0x0040000, 0x0080000,
 
16
    0x0100000, 0x0200000, 0x0400000, 0x0800000,
 
17
    0x1000000, 0x2000000, 0x4000000, 0x8000000,
 
18
};
 
19
 
 
20
#define IN_MASK_RANGE(C) (islower (C) || ((C) == '_'))
 
21
#define MASK_INDEX(C)    ((C) - '_')
 
22
 
 
23
#else
 
24
static long CharMask[26] = {
 
25
    0x0000001, 0x0000002, 0x0000004, 0x0000008,
 
26
    0x0000010, 0x0000020, 0x0000040, 0x0000080,
 
27
    0x0000100, 0x0000200, 0x0000400, 0x0000800,
 
28
    0x0001000, 0x0002000, 0x0004000, 0x0008000,
 
29
    0x0010000, 0x0020000, 0x0040000, 0x0080000,
 
30
    0x0100000, 0x0200000, 0x0400000, 0x0800000,
 
31
    0x1000000, 0x2000000
 
32
};
 
33
 
 
34
#define IN_MASK_RANGE(C) islower (C)
 
35
#define MASK_INDEX(C)    ((C) - 'a')
 
36
 
 
37
#endif
 
38
 
 
39
static short TFA_State;
 
40
 
 
41
/* TFA_Init:
 
42
 *
 
43
 *    Initialize the trie FA.
 
44
 */
 
45
#define TFA_Init() TFA_State = 0
 
46
 
 
47
/* TFA_Advance:
 
48
 *
 
49
 * Advance to the next state (or -1) on the lowercase letter c.
 
50
 * This should be an inline routine, but the C++ implementation
 
51
 * isn't advanced enough so we use a macro.
 
52
 */
 
53
#define TFA_Advance(C) { \
 
54
    char c = C; \
 
55
    if (TFA_State >= 0) { \
 
56
        if (isupper (c)) \
 
57
            c = tolower (c); \
 
58
        else if (! IN_MASK_RANGE (c)) { \
 
59
            TFA_State = -1; \
 
60
            goto TFA_done; \
 
61
        } \
 
62
        if (TrieStateTbl[TFA_State].mask & CharMask[MASK_INDEX (c)]) { \
 
63
            short i = TrieStateTbl[TFA_State].trans_base; \
 
64
            while (TrieTransTbl[i].c != c) \
 
65
                i++; \
 
66
            TFA_State = TrieTransTbl[i].next_state; \
 
67
        } \
 
68
        else \
 
69
            TFA_State = -1; \
 
70
    } \
 
71
  TFA_done:; \
 
72
} /* end of TFA_Advance. */
 
73
 
 
74
/* TFA_Definition:
 
75
 *
 
76
 *    Return the definition (if any) associated with the current state.
 
77
 */
 
78
#define TFA_Definition() \
 
79
    ((TFA_State < 0) ? -1 : TrieStateTbl[TFA_State].def)