1
/* Copyright (C) 2000 Damir Zucic */
3
/*=============================================================================
8
Extract residue ranges (serial numbers) from the list.
11
(1) Pointer to SelectS structure, where data will be stored.
12
(2) Pointer to the string with list of ranges.
15
(1) Some data added to SelectS structure.
19
(1) Positive on success.
20
(2) Negative on failure.
22
========includes:============================================================*/
29
#include <X11/Xutil.h>
31
#include <X11/Xatom.h>
36
/*======function prototypes:=================================================*/
38
char *ExtractToken_ (char *, int, char *, char *);
39
int ExtractSerials_ (int *, int *, char *);
41
/*======extract residue ranges:==============================================*/
43
int ExtractResidueRanges_ (SelectS *selectSP, char *stringP)
46
char tokenA[SHORTSTRINGSIZE];
51
/* Check the string length: */
52
if (strlen (stringP) == 0) return -1;
54
/* Initialize all_residue_serialF (1 = select all serial numbers): */
55
selectSP->all_residue_serialF = 0;
57
/* Initialize the number of ranges: */
58
selectSP->residue_serial_rangesN = 0;
60
/* If wildcard (asterisk) is present, set */
61
/* all_residue_serialF to one and return: */
62
if (strstr (stringP, "*"))
64
selectSP->all_residue_serialF = 1;
68
/* Parse the list of ranges: */
70
max = SHORTSTRINGSIZE;
71
while ((remainderP = ExtractToken_ (tokenA, max, remainderP, " \t,;")) != NULL)
73
/** Extract serial numbers: **/
74
if (ExtractSerials_ (&n1, &n2, tokenA) < 0) return -2;
76
/** Copy serial numbers: **/
77
rangeI = selectSP->residue_serial_rangesN;
78
selectSP->residue_serial_start[rangeI] = n1;
79
selectSP->residue_serial_end[rangeI] = n2;
81
/** Increase and check the number of ranges: **/
82
selectSP->residue_serial_rangesN++;
83
if (selectSP->residue_serial_rangesN >= MAXFIELDS) break;
86
/* Return positive value on success: */
90
/*===========================================================================*/