1 /* Copyright (C) 2000-2004 Damir Zucic */
2
3 /*=============================================================================
4
5 exclude.c
6
7 Purpose:
8 Identify chains, residue ranges, residue names and atom names
9 which have to be excluded from selection.
10
11 Input:
12 (1) Pointer to SelectS structure, where data will be stored.
13 (2) Pointer to the selection string.
14
15 Output:
16 (1) SelectS structure filled with data.
17 (2) Return value.
18
19 Return value:
20 (1) Positive on success.
21 (2) Negative on failure.
22
23 ========includes:============================================================*/
24
25 #include <stdio.h>
26
27 #include <string.h>
28
29 #include <X11/Xlib.h>
30 #include <X11/Xutil.h>
31 #include <X11/Xos.h>
32 #include <X11/Xatom.h>
33
34 #include "defines.h"
35 #include "typedefs.h"
36
37 /*======function prototypes:=================================================*/
38
39 char *ExtractToken_ (char *, int, char *, char *);
40 char *SkipKeyword_ (char *, char *);
41 int ExtractChains_ (SelectS *, char *);
42 int ExtractResidueRanges_ (SelectS *, char *);
43 int ExtractResidueNames_ (SelectS *, char *);
44 int ExtractAtomNames_ (SelectS *, char *);
45
46 /*======identify excluded ranges and names:==================================*/
47
Exclude_(SelectS * exclude_selectSP,char * stringP)48 int Exclude_ (SelectS *exclude_selectSP, char *stringP)
49 {
50 char string_copyA[STRINGSIZE];
51 char *remainderP;
52 char tokenA[STRINGSIZE];
53 char *exceptP, *dataP;
54
55 /* Copy the input string to preserve it: */
56 strncpy (string_copyA, stringP, STRINGSIZE - 1);
57 string_copyA[STRINGSIZE - 1] = '\0';
58
59 /* Pointer to the remainder of the string */
60 /* initially points to the whole string: */
61 remainderP = stringP;
62
63 /* The first token should contain chain identifiers: */
64 remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/");
65 if (remainderP == NULL) return -1;
66
67 /* If keyword exc is present, skip one token and extract chain identifiers: */
68 if ((exceptP = strstr (tokenA, "EXC")) != NULL)
69 {
70 /** Skip one token: **/
71 if ((dataP = SkipKeyword_ (exceptP, " \t,;")) == NULL) return -2;
72
73 /** Extract chain identifiers: **/
74 if (ExtractChains_ (exclude_selectSP, dataP) < 0) return -3;
75 }
76
77 /* If keyword exc is not present, initialize flag and count: */
78 else
79 {
80 /** Initialize all_chainsF (1 = select all chains): **/
81 exclude_selectSP->all_chainsF = 0;
82
83 /** Initialize the number of chain identifiers: **/
84 exclude_selectSP->chainsN = 0;
85 }
86
87 /* The second token should contain residue ranges: */
88 remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/");
89 if (remainderP == NULL) return -4;
90
91 /* If keyword exc is present, skip one token and extract residue ranges: */
92 if ((exceptP = strstr (tokenA, "EXC")) != NULL)
93 {
94 /** Skip one token: **/
95 if ((dataP = SkipKeyword_ (exceptP, " \t,;")) == NULL) return -5;
96
97 /** Extract residue ranges: **/
98 if (ExtractResidueRanges_ (exclude_selectSP, dataP) < 0) return -6;
99 }
100
101 /* If keyword exc is not present, initialize flag and count: */
102 else
103 {
104 /* Initialize all_residue_serialF (1 = select all serial numbers): */
105 exclude_selectSP->all_residue_serialF = 0;
106
107 /* Initialize the number of ranges: */
108 exclude_selectSP->residue_serial_rangesN = 0;
109 }
110
111 /* The third token should contain residue names: */
112 remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/");
113 if (remainderP == NULL) return -7;
114
115 /* If keyword exc is present, skip one token and extract residue names: */
116 if ((exceptP = strstr (tokenA, "EXC")) != NULL)
117 {
118 /** Skip one token: **/
119 if ((dataP = SkipKeyword_ (exceptP, " \t,;")) == NULL) return -8;
120
121 /** Extract residue names: **/
122 if (ExtractResidueNames_ (exclude_selectSP, dataP) < 0) return -9;
123 }
124
125 /* If keyword exc is not present, initialize flag and count: */
126 else
127 {
128 /* Initialize all_residue_namesF (1 = select all residue names): */
129 exclude_selectSP->all_residue_namesF = 0;
130
131 /* Initialize the number of residue names: */
132 exclude_selectSP->residue_namesN = 0;
133 }
134
135 /* The fourth (the last) token should contain atom names: */
136 remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, "/");
137 if (remainderP == NULL) return -10;
138
139 /* If keyword exc is present, skip one token and extract atom names: */
140 if ((exceptP = strstr (tokenA, "EXC")) != NULL)
141 {
142 /** Skip one token: **/
143 if ((dataP = SkipKeyword_ (exceptP, " \t,;")) == NULL) return -11;
144
145 /** Extract chain identifiers: **/
146 if (ExtractAtomNames_ (exclude_selectSP, dataP) < 0) return -12;
147 }
148
149 /* If keyword exc is not present, initialize flag and count: */
150 else
151 {
152 /* Initialize all_atom_namesF (1 = select all atom names): */
153 exclude_selectSP->all_atom_namesF = 0;
154
155 /* Initialize the number of atom names: */
156 exclude_selectSP->atom_namesN = 0;
157 }
158
159 /* Return positive value on success: */
160 return 1;
161 }
162
163 /*===========================================================================*/
164
165
166