~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to residue_ranges.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                            residue_ranges.c
 
6
 
 
7
Purpose:
 
8
        Extract residue ranges (serial numbers) from the list.
 
9
 
 
10
Input:
 
11
        (1) Pointer to SelectS structure, where data will be stored.
 
12
        (2) Pointer to the string with list of ranges.
 
13
 
 
14
Output:
 
15
        (1) Some data added to SelectS structure.
 
16
        (2) Return value.
 
17
 
 
18
Return value:
 
19
        (1) Positive on success.
 
20
        (2) Negative on failure.
 
21
 
 
22
========includes:============================================================*/
 
23
 
 
24
#include <stdio.h>
 
25
 
 
26
#include <string.h>
 
27
 
 
28
#include <X11/Xlib.h>
 
29
#include <X11/Xutil.h>
 
30
#include <X11/Xos.h>
 
31
#include <X11/Xatom.h>
 
32
 
 
33
#include "defines.h"
 
34
#include "typedefs.h"
 
35
 
 
36
/*======function prototypes:=================================================*/
 
37
 
 
38
char            *ExtractToken_ (char *, int, char *, char *);
 
39
int             ExtractSerials_ (int *, int *, char *);
 
40
 
 
41
/*======extract residue ranges:==============================================*/
 
42
 
 
43
int ExtractResidueRanges_ (SelectS *selectSP, char *stringP)
 
44
{
 
45
char            *remainderP;
 
46
char            tokenA[SHORTSTRINGSIZE];
 
47
int             max;
 
48
int             n1, n2;
 
49
int             rangeI;
 
50
 
 
51
/* Check the string length: */
 
52
if (strlen (stringP) == 0) return -1;
 
53
 
 
54
/* Initialize all_residue_serialF (1 = select all serial numbers): */
 
55
selectSP->all_residue_serialF = 0;
 
56
 
 
57
/* Initialize the number of ranges: */
 
58
selectSP->residue_serial_rangesN = 0;
 
59
 
 
60
/* If wildcard (asterisk) is present, set */
 
61
/* all_residue_serialF to one and return: */
 
62
if (strstr (stringP, "*"))
 
63
        {
 
64
        selectSP->all_residue_serialF = 1;
 
65
        return 1;
 
66
        }
 
67
 
 
68
/* Parse the list of ranges: */
 
69
remainderP = stringP;
 
70
max = SHORTSTRINGSIZE;
 
71
while ((remainderP = ExtractToken_ (tokenA, max, remainderP, " \t,;")) != NULL)
 
72
        {
 
73
        /** Extract serial numbers: **/
 
74
        if (ExtractSerials_ (&n1, &n2, tokenA) < 0) return -2;
 
75
 
 
76
        /** Copy serial numbers: **/
 
77
        rangeI = selectSP->residue_serial_rangesN;
 
78
        selectSP->residue_serial_start[rangeI] = n1;
 
79
        selectSP->residue_serial_end[rangeI]   = n2;
 
80
 
 
81
        /** Increase and check the number of ranges: **/
 
82
        selectSP->residue_serial_rangesN++;
 
83
        if (selectSP->residue_serial_rangesN >= MAXFIELDS) break;
 
84
        }
 
85
 
 
86
/* Return positive value on success: */
 
87
return 1;
 
88
}
 
89
 
 
90
/*===========================================================================*/
 
91
 
 
92