1
/*===========================================================================
2
Copyright (C) 1988-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
.AUTHOR Preben Grosbol, ESO/IPG
32
.KEYWORDS decoding, list of numbers
33
.COMMENT Routines for decoding and accessing list of numbers
34
given as a MIDAS 'list'.
35
.VERSION 1.0 1988-Oct-11 : Creation, PJG
38
------------------------------------------------------------------------*/
40
#define MXLIST 64 /* max. no. of entries in list */
42
static int lno = -1; /* no. to current list range */
43
static struct { /* structure with list of no's */
44
int first; /* first no. in range */
45
int last; /* last no. of in range */
49
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
50
.PURPOSE decode string with MIDAS 'list' specification and initiate
51
internal list structure.
52
.RETURN status, 0: OK, -1:invalid list, 1: list too long
53
------------------------------------------------------------------------*/
54
char *plist; /* pointer to list specification */
60
for (n=0; n<MXLIST; n++) list[n].first = -1; /* reset internal list */
62
if (*plist == '*') { /* check special cases */
63
if (*(++plist)) return -1;
64
list[0].first = 1; list[0].last = 9999;
68
n = 0; l = 0; ldig = 0;
69
while ((c = *plist++) && c!=' ') { /* go through list */
70
if (c == ',' && ldig) {
71
if (list[l].first<0) list[l].first = n;
72
list[l].last = (n<list[l].first) ? list[l].first : n;
74
if (MXLIST<=l) { lno = 0; return 1; }
76
else if (c == '-' && ldig) list[l].first = n;
77
else if (c == '.' && ldig) {
78
if ((*plist++ != '.')) return -1;
81
else if (c<'0' || '9'<c) return -1;
83
ldig = (('0' <= c) && (c <= '9'));
85
n = 10 * n + (c - '0');
90
if (list[l].first<0) list[l].first = n;
91
list[l].last = (n<list[l].first) ? list[l].first : n;
100
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
101
.PURPOSE get next no. in list previously defined. The no. is
102
return through the parameter.
103
.RETURN status, 1:valid no., 0:no number return
104
------------------------------------------------------------------------*/
105
int *pno; /* pointer to var. with next no. in list */
107
if (lno<0) return 0; /* return if list empty */
108
if (list[lno].first<0) {
112
*pno = list[lno].first++; /* get next no. in list */
113
if (list[lno].last<list[lno].first) { /* check if range finished */
114
list[lno++].first = -1;
115
if (MXLIST<=lno) lno = -1;