~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to prim/dio/libsrc/dclist.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1988-2009 European Southern Observatory (ESO)
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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, 
 
17
  MA 02139, USA.
 
18
 
 
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 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
29
.IDENT         cdlist.c
 
30
.LANGUAGE      C
 
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
 
36
 
 
37
 090706         last modif
 
38
------------------------------------------------------------------------*/
 
39
 
 
40
#define    MXLIST     64                /* max. no. of entries in list  */
 
41
 
 
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         */
 
46
               } list[MXLIST];
 
47
 
 
48
int  deflist(plist)
 
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 */
 
55
{
 
56
  char   c;
 
57
  int    l,ldig,n;
 
58
 
 
59
  lno = -1;
 
60
  for (n=0; n<MXLIST; n++) list[n].first = -1;  /* reset internal list  */
 
61
 
 
62
  if (*plist == '*') {                          /* check special cases  */
 
63
     if (*(++plist)) return -1;
 
64
     list[0].first = 1; list[0].last = 9999;
 
65
     lno = 0; return 0;
 
66
  }
 
67
 
 
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;
 
73
       l++;
 
74
       if (MXLIST<=l) { lno = 0; return 1; }
 
75
    }
 
76
    else if (c == '-' && ldig) list[l].first = n;
 
77
    else if (c == '.' && ldig) {
 
78
            if ((*plist++ != '.')) return -1;
 
79
            list[l].first = n;
 
80
    }
 
81
    else if (c<'0' || '9'<c) return -1;
 
82
 
 
83
    ldig = (('0' <= c) && (c <= '9')); 
 
84
    if (ldig)
 
85
       n = 10 * n + (c - '0');
 
86
    else 
 
87
       n = 0;
 
88
  }
 
89
  if (ldig) {
 
90
     if (list[l].first<0) list[l].first = n;
 
91
     list[l].last = (n<list[l].first) ? list[l].first : n;
 
92
   }
 
93
   else return -1;
 
94
 
 
95
  lno = 0;
 
96
  return 0;
 
97
}
 
98
 
 
99
int getlist(pno)
 
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 */
 
106
{
 
107
  if (lno<0) return 0;                   /* return if list empty        */
 
108
  if (list[lno].first<0) {
 
109
     lno = -1; return 0;
 
110
  }
 
111
 
 
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;
 
116
  }      
 
117
     
 
118
  return 1;
 
119
}