1
2
3 /*
4 A* -------------------------------------------------------------------
5 B* This file contains source code for the PyMOL computer program
6 C* Copyright (c) Schrodinger, LLC.
7 D* -------------------------------------------------------------------
8 E* It is unlawful to modify or remove this copyright notice.
9 F* -------------------------------------------------------------------
10 G* Please see the accompanying LICENSE file for further information.
11 H* -------------------------------------------------------------------
12 I* Additional authors of this source file include:
13 -*
14 -*
15 -*
16 Z* -------------------------------------------------------------------
17 */
18 #ifndef _H_Word
19 #define _H_Word
20
21 #include "PyMOLGlobals.h"
22 #include "Lex.h"
23
24 #define WordLength 256
25
26 typedef char WordType[WordLength];
27
28 typedef struct {
29 WordType word;
30 int value;
31 } WordKeyValue;
32
33 typedef struct {
34 char *word;
35 char **start;
36 int n_word;
37 } CWordList;
38
39 #define cWordMatchOptionNoRanges 0
40 #define cWordMatchOptionNumericRanges 1
41 #define cWordMatchOptionAlphaRanges 2
42
43 typedef struct {
44 int range_mode; /* 0 = none, 1 = numeric, 2 = alpha */
45 int lists;
46 int ignore_case;
47 int allow_hyphen;
48 int allow_plus;
49 int space_lists;
50 char wildcard;
51 } CWordMatchOptions;
52
53 typedef struct _CWordMatcher CWordMatcher;
54
55 void WordMatchOptionsConfigInteger(CWordMatchOptions * I);
56 void WordMatchOptionsConfigAlpha(CWordMatchOptions * I, char wildcard, int ignore_case);
57 void WordMatchOptionsConfigAlphaList(CWordMatchOptions * I, char wildcard,
58 int ignore_case);
59 void WordMatchOptionsConfigMixed(CWordMatchOptions * I, char wildcard, int ignore_case);
60 void WordMatchOptionsConfigNameList(CWordMatchOptions * I, char wildcard,
61 int ignore_case);
62
63 CWordMatcher *WordMatcherNew(PyMOLGlobals * G, const char *st, CWordMatchOptions * option,
64 int force);
65 int WordMatcherMatchAlpha(CWordMatcher * I, const char *text);
66 int WordMatcherMatchMixed(CWordMatcher * I, const char *text, int value);
67 int WordMatcherMatchInteger(CWordMatcher * I, int value);
68 void WordMatcherFree(CWordMatcher * I);
69 int WordMatchNoWild(PyMOLGlobals * G, const char *p, const char *q, int ignCase);
70
71 CWordList *WordListNew(PyMOLGlobals * G, const char *st);
72 void WordListFreeP(CWordList * I);
73 void WordListDump(CWordList * I, const char *prefix);
74 int WordListIterate(PyMOLGlobals * G, CWordList * I, const char **ptr, int *hidden);
75 int WordListMatch(PyMOLGlobals * G, CWordList * I, const char *name, int ignore_case);
76
77 int WordInit(PyMOLGlobals * G);
78 void WordFree(PyMOLGlobals * G);
79
80 int WordMatch(PyMOLGlobals * G, const char *p, const char *q, int ignCase);
81 int WordMatchExact(PyMOLGlobals * G, const char *p, const char *q, int ignCase);
82 void WordPrimeCommaMatch(PyMOLGlobals * G, char *p);
83 int WordMatchComma(PyMOLGlobals * G, const char *p, const char *q, int ignCase);
84 int WordMatchCommaInt(PyMOLGlobals * G, const char *p, int number);
85 int WordMatchCommaExact(PyMOLGlobals * G, const char *p, const char *q, int ignCase);
86
87
88 /* (<0) exact match, (>0) inexact match, =0 no match */
89
90 int WordIndex(PyMOLGlobals * G, WordType * list, const char *word, int minMatch, int ignCase);
91 int WordKey(PyMOLGlobals * G, WordKeyValue * list, const char *word, int minMatch, int ignCase,
92 int *exact);
93
94 int WordCompare(PyMOLGlobals * G, const char *p, const char *q, int ignCase);
95
WordCompare(PyMOLGlobals * G,const lexidx_t & s1,const lexidx_t & s2,int ignCase)96 inline int WordCompare(PyMOLGlobals * G, const lexidx_t& s1, const lexidx_t& s2, int ignCase) {
97 if (s1 == s2)
98 return 0;
99 return WordCompare(G, LexStr(G, s1), LexStr(G, s2), ignCase);
100 }
101
WordMatch(PyMOLGlobals * G,const lexidx_t & s1,const lexidx_t & s2,int ignCase)102 inline int WordMatch(PyMOLGlobals * G, const lexidx_t& s1, const lexidx_t& s2, int ignCase) {
103 if (s1 == s2)
104 return -1; // negative = perfect match
105 return WordMatch(G, LexStr(G, s1), LexStr(G, s2), ignCase);
106 }
107
WordMatchNoWild(PyMOLGlobals * G,const lexidx_t & s1,const lexidx_t & s2,int ignCase)108 inline int WordMatchNoWild(PyMOLGlobals * G, const lexidx_t& s1, const lexidx_t& s2, int ignCase) {
109 if (s1 == s2)
110 return -1; // negative = perfect match
111 return WordMatchNoWild(G, LexStr(G, s1), LexStr(G, s2), ignCase);
112 }
113
WordMatchExact(PyMOLGlobals * G,const lexidx_t & s1,const lexidx_t & s2,int ignCase)114 inline int WordMatchExact(PyMOLGlobals * G, const lexidx_t& s1, const lexidx_t& s2, int ignCase) {
115 if (s1 == s2)
116 return 1; // non-zero = perfect match
117 if (!ignCase)
118 return 0; // 0 = no match
119 return WordMatchExact(G, LexStr(G, s1), LexStr(G, s2), ignCase);
120 }
121
WordMatchExact(PyMOLGlobals * G,char c1,char c2,int ignCase)122 inline int WordMatchExact(PyMOLGlobals * G, char c1, char c2, int ignCase) {
123 if (c1 == c2)
124 return 1; // non-zero = perfect match
125 if (!ignCase)
126 return 0; // 0 = no match
127 return c1 && c2 && toupper(c1) == toupper(c2);
128 }
129
130 #endif
131