~ubuntu-branches/ubuntu/wily/eso-midas/wily-proposed

« back to all changes in this revision

Viewing changes to system/ext/idtbl.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) 1995-2005 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
/*+++++++++  Remove ESO extensions to FORTRAN 77    ++++++++++++++++++++
 
29
.COPYRIGHT   (c) 1994-2005 European Southern Observatory
 
30
.LANGUAGE    C
 
31
.IDENT       idtbl.c
 
32
.AUTHOR      Preben J. Grosbol [ESO/IPG]
 
33
.KEYWORDS    identifier table, long names
 
34
.ENVIRONMENT UNIX
 
35
.COMMENT
 
36
.VERSION     1.0   12-Nov-1987: Creation,     PJG
 
37
.VERSION     1.1   14-Jan-1988: Add check for all id's,   PJG
 
38
.VERSION     1.2   08-Sep-1988: Standard error lists,   PJG
 
39
.VERSION     1.3   27-Apr-1994: Correct unique ID check,   PJG
 
40
 051012         last modif
 
41
 
 
42
------------------------------------------------------------------------*/
 
43
 
 
44
#include   <stdlib.h>
 
45
#include   <stdio.h>                        /* standard I/O functions   */
 
46
#include   <ctype.h>                        /* character types          */
 
47
#include   <string.h>                       /* string functions         */
 
48
#include   <f77ext.h>                       /* definition of constants  */
 
49
 
 
50
extern    int                   no_id;      /* no. of identifiers       */
 
51
extern    ID                  idtbl[];      /* table of identifiers     */
 
52
 
 
53
ID *add_id(id,size,type,group,err)        /* add new identifier to list */
 
54
char       *id;
 
55
int       size;
 
56
char      type;
 
57
char     group;
 
58
int       *err;
 
59
{
 
60
  int     n,i;
 
61
  char    c,*pid,*tid;
 
62
  ID      *pidtbl;
 
63
 
 
64
  if (size<=0) return (ID *) 0;          /* if zero length - return    */
 
65
  pidtbl = idtbl; *err = 0;
 
66
  for (n=0; n<no_id; n++) {              /* go through identifiers     */
 
67
    pid = id; tid = pidtbl->lname; i = size;
 
68
    while ((c = *tid++) == *pid++ && c != '\0') i--;
 
69
    if (!(c || i)) {                  /* identifier found, check it */
 
70
      return pidtbl;
 
71
    }
 
72
    pidtbl++;
 
73
  }
 
74
  if (MXID<=no_id) {
 
75
    fprintf(stderr,"Error: Too many identifiers\n");
 
76
    exit(1);
 
77
  }
 
78
 
 
79
  pidtbl->size = size;                  /* add new identifier to table */
 
80
  pidtbl->type = type;
 
81
  pidtbl->group = group;
 
82
  pidtbl->sname[0] = '\0';
 
83
  tid = pidtbl->lname;
 
84
  while (size--) *tid++ = *id++;        /* copy identifier over        */
 
85
  *tid = '\0';
 
86
  no_id++;
 
87
 
 
88
  return pidtbl;
 
89
}
 
90
 
 
91
void new_id(id,size,new)                     /* make short identifier      */
 
92
char       *id;
 
93
int       size;
 
94
char      *new;
 
95
{
 
96
  int     n,nomod;
 
97
  char    c,*pc;
 
98
 
 
99
  nomod = size < MXIDENT;               /* no modification for short  */
 
100
 
 
101
  n = 0; pc = new;
 
102
  while (size--) {                      /* construct short ident.     */
 
103
    c = *id++;
 
104
    if (c=='_') { nomod = 0; continue; }
 
105
    n++;
 
106
    if (n<MXIDENT-1 || !size) *new++ = c;
 
107
  }
 
108
  if (nomod) *pc = '\0'; else *new = '\0';
 
109
 
 
110
  return;
 
111
}
 
112
 
 
113
int chk_id()                         /* check if short id's are uniq */
 
114
{
 
115
  int      i,n,err;
 
116
  char     *sid,*ssd;
 
117
  ID       *pid;
 
118
 
 
119
  pid = idtbl; err = 0;
 
120
  for (n=0; n<no_id; n++, pid++) {
 
121
     if (*(sid = pid->sname)) {         /* check only new ident's     */
 
122
        for (i=0; i<no_id; i++)          /* compare with all short id  */
 
123
          if (i!=n && *(ssd=idtbl[i].sname))
 
124
            if (!strcmp(ssd,sid)) {
 
125
               err = 1;
 
126
               fprintf(stderr,"Error: Identifier >%s< - >%s< : >%s<\n",
 
127
                       pid->lname,idtbl[i].lname,sid);
 
128
               break;
 
129
             }
 
130
        for (i=0; i<no_id; i++)          /* compare with all long  id  */
 
131
          if (!strcmp(idtbl[i].lname,sid)) {
 
132
             err = 1;
 
133
             fprintf(stderr,"Error: Identifier error >%s< : >%s<\n",
 
134
                     idtbl[i].lname,sid);
 
135
             break;
 
136
           }
 
137
      }
 
138
   }
 
139
 
 
140
  return err;
 
141
}