File: Word.h

package info (click to toggle)
pymol 1.8.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 42,248 kB
  • ctags: 24,095
  • sloc: cpp: 474,635; python: 75,034; ansic: 22,888; sh: 236; makefile: 78; csh: 21
file content (175 lines) | stat: -rw-r--r-- 5,400 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175


/* 
A* -------------------------------------------------------------------
B* This file contains source code for the PyMOL computer program
C* Copyright (c) Schrodinger, LLC. 
D* -------------------------------------------------------------------
E* It is unlawful to modify or remove this copyright notice.
F* -------------------------------------------------------------------
G* Please see the accompanying LICENSE file for further information. 
H* -------------------------------------------------------------------
I* Additional authors of this source file include:
-* 
-* 
-*
Z* -------------------------------------------------------------------
*/
#ifndef _H_Word
#define _H_Word

#include "PyMOLGlobals.h"
#include "Lex.h"

#define WordLength 256

typedef char WordType[WordLength];

typedef struct {
  WordType word;
  int value;
} WordKeyValue;

typedef struct {
  char *word;
  char **start;
  int n_word;
} CWordList;

#define cWordMatchOptionNoRanges 0
#define cWordMatchOptionNumericRanges 1
#define cWordMatchOptionAlphaRanges 2

typedef struct {
  int range_mode;               /* 0 = none, 1 = numeric, 2 = alpha */
  int lists;
  int ignore_case;
  int allow_hyphen;
  int allow_plus;
  int space_lists;
  char wildcard;
} CWordMatchOptions;

typedef struct _CWordMatcher CWordMatcher;

void WordMatchOptionsConfigInteger(CWordMatchOptions * I);
void WordMatchOptionsConfigAlpha(CWordMatchOptions * I, char wildcard, int ignore_case);
void WordMatchOptionsConfigAlphaList(CWordMatchOptions * I, char wildcard,
                                     int ignore_case);
void WordMatchOptionsConfigMixed(CWordMatchOptions * I, char wildcard, int ignore_case);
void WordMatchOptionsConfigNameList(CWordMatchOptions * I, char wildcard,
                                    int ignore_case);

CWordMatcher *WordMatcherNew(PyMOLGlobals * G, const char *st, CWordMatchOptions * option,
                             int force);
int WordMatcherMatchAlpha(CWordMatcher * I, const char *text);
int WordMatcherMatchMixed(CWordMatcher * I, const char *text, int value);
int WordMatcherMatchInteger(CWordMatcher * I, int value);
void WordMatcherFree(CWordMatcher * I);
int WordMatchNoWild(PyMOLGlobals * G, const char *p, const char *q, int ignCase);

CWordList *WordListNew(PyMOLGlobals * G, const char *st);
void WordListFreeP(CWordList * I);
void WordListDump(CWordList * I, const char *prefix);
int WordListIterate(PyMOLGlobals * G, CWordList * I, const char **ptr, int *hidden);
int WordListMatch(PyMOLGlobals * G, CWordList * I, const char *name, int ignore_case);

int WordInit(PyMOLGlobals * G);
void WordFree(PyMOLGlobals * G);

void WordSetWildcard(PyMOLGlobals * G, char wc);
int WordMatch(PyMOLGlobals * G, const char *p, const char *q, int ignCase);
int WordMatchExact(PyMOLGlobals * G, const char *p, const char *q, int ignCase);
void WordPrimeCommaMatch(PyMOLGlobals * G, char *p);
int WordMatchComma(PyMOLGlobals * G, const char *p, const char *q, int ignCase);
int WordMatchCommaInt(PyMOLGlobals * G, const char *p, int number);
int WordMatchCommaExact(PyMOLGlobals * G, const char *p, const char *q, int ignCase);


/* (<0) exact match, (>0) inexact match, =0 no match */

int WordIndex(PyMOLGlobals * G, WordType * list, const char *word, int minMatch, int ignCase);
int WordKey(PyMOLGlobals * G, WordKeyValue * list, const char *word, int minMatch, int ignCase,
            int *exact);

#ifdef _PYMOL_INLINE
__inline__ static int WordCompare(PyMOLGlobals * G, const char *p, const char *q, int ignCase)


/* all things equal, shorter is smaller */
{
  int result = 0;
  char cp, cq, tlp, tlq;
  if(ignCase) {
    while((cp = *p) && (cq = *q)) {
      p++;
      q++;
      if(cp != cq) {
        (tlp = tolower(cp));
        (tlq = tolower(cq));
        if(tlp < tlq)
          return -1;
        else if(tlp > tlq) {
          return 1;
        }
      }
    }
  } else {
    while((cp = *p) && (cq = *q)) {
      p++;
      q++;
      if(cp != cq) {
        if(cp < cq) {
          return -1;
        } else if(cp > cq) {
          return 1;
        }
      }
    }
  }
  if((!result) && (!*p) && (*q))
    return -1;
  else if((!result) && (*p) && (!*q))
    return 1;
  return 0;
}
#else
int WordCompare(PyMOLGlobals * G, const char *p, const char *q, int ignCase);

#endif

inline int WordCompare(PyMOLGlobals * G, lexidx_t s1, lexidx_t s2, int ignCase) {
  if (s1 == s2)
    return 0;
  return WordCompare(G, LexStr(G, s1), LexStr(G, s2), ignCase);
}

inline int WordMatch(PyMOLGlobals * G, lexidx_t s1, lexidx_t s2, int ignCase) {
  if (s1 == s2)
    return -1; // negative = perfect match
  return WordMatch(G, LexStr(G, s1), LexStr(G, s2), ignCase);
}

inline int WordMatchNoWild(PyMOLGlobals * G, lexidx_t s1, lexidx_t s2, int ignCase) {
  if (s1 == s2)
    return -1; // negative = perfect match
  return WordMatchNoWild(G, LexStr(G, s1), LexStr(G, s2), ignCase);
}

inline int WordMatchExact(PyMOLGlobals * G, lexidx_t s1, lexidx_t s2, int ignCase) {
  if (s1 == s2)
    return 1; // non-zero = perfect match
  if (!ignCase)
    return 0; // 0 = no match
  return WordMatchExact(G, LexStr(G, s1), LexStr(G, s2), ignCase);
}

inline int WordMatchExact(PyMOLGlobals * G, char c1, char c2, int ignCase) {
  if (c1 == c2)
    return 1; // non-zero = perfect match
  if (!ignCase)
    return 0; // 0 = no match
  return c1 && c2 && toupper(c1) == toupper(c2);
}

#endif