-
Notifications
You must be signed in to change notification settings - Fork 1
/
dat1_init.c
151 lines (123 loc) · 7.16 KB
/
dat1_init.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <errno.h>
#include "ems.h" /* EMS error reporting routines */
#include "ems_par.h" /* EMS public constants */
#include "hds1.h" /* Global definitions for HDS */
#include "rec.h" /* Public rec_ definitions */
#include "dat1.h" /* Internal dat_ definitions */
#include "dat_err.h" /* DAT__ error code definitions */
int dat1_init( void )
{
/*+ */
/* Name: */
/* dat1_init */
/* Purpose: */
/* Initialise HDS. */
/* Language: */
/* ANSI C */
/* Invocation: */
/* dat1_init( ) */
/* Description: */
/* This routine should be called to initialise HDS prior to making calls */
/* to other internal HDS routines which make use of locators or global */
/* tuning parameters. It ensures that HDS is active by initialising */
/* global tuning parameters, setting up the working/free locator queues, */
/* allocating space for the latter, initialising the global native data */
/* representation information and establishing an "exit handler" to */
/* clean up when the program terminates. */
/* Parameters: */
/* void */
/* Returned Value: */
/* int dat1_init */
/* The global status value current on exit. */
/* Copyright: */
/* Copyright (C) 1991, 1992 Science & Engineering Research Council */
/* Copyright (C) 2007 Science and Technology Facilities Council */
/* All Rights Reserved */
/* Licence: */
/* This program is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License as */
/* published by the Free Software Foundation; either version 2 of */
/* the License, or (at your option) any later version. */
/* This program is distributed in the hope that it will be */
/* useful, but WITHOUT ANY WARRANTY; without even the implied */
/* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR */
/* PURPOSE. See the GNU General Public License for more details. */
/* You should have received a copy of the GNU General Public */
/* License along with this program; if not, write to the Free */
/* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, */
/* MA 02110-1301, USA */
/* Authors: */
/* RFWS: R.F. Warren-Smith (STARLINK) */
/* {@enter_new_authors_here@} */
/* History: */
/* 4-APR-1991 (RFWS): */
/* Added prologue and made portable. */
/* 24-FEB-1992 (RFWS): */
/* Converted into an internal routine to be called automatically. */
/* 26-FEB-1992 (RFWS): */
/* Separated out the initialisation of tuning parameters. */
/* 7-SEP-1992 (RFWS): */
/* Installed initialisation of the global native data representation */
/* information. */
/* 20-JUN-2007 (TIMJ): */
/* Add HDS_DISABLE_CLEANUP (useful for debugging) to disable */
/* the exit handler. */
/* {@enter_further_changes_here@} */
/* Bugs: */
/* {@note_any_bugs_here@} */
/*- */
/* Local Variables: */
static int first = 1; /* First invocation of this routine? */
/*. */
/* Check the inherited global status. */
if ( !_ok( hds_gl_status ) ) return hds_gl_status;
/* Check if HDS is already active. There is nothing to do if it is. */
if ( !hds_gl_active )
{
/* Initialise HDS tuning parameters. */
dat1_intune( &hds_gl_status );
/* Start up the rec_ facility. */
rec_start( );
/* Initialise the Working and Free Locator Queues. Then fill the free queue */
/* with a cluster of virgin Locator Control Packets. */
dat_ga_wlq = NULL;
dat_ga_flq = NULL;
dau_refill_flq( );
/* Initialise the global native data representation information. */
dat1_init_ndr( &hds_gl_status );
/* Note if HDS is now active. */
if ( _ok( hds_gl_status ) )
{
hds_gl_active = 1;
/* On the first (successful) invocation of this routine, declare hds1_exit */
/* as an exit handler. (if we want it) */
if ( first )
{
/* see if we want an exit handler */
if (!getenv( "HDS_DISABLE_CLEANUP")) {
if ( !atexit( hds1_exit ) )
{
first = 0;
}
/* If an error occurred, then report it. */
else
{
hds_gl_status = DAT__FATAL;
emsSyser( "MESSAGE", errno );
emsRep( "DAT1_INIT_1",
"Error establishing an exit handler for HDS - ^MESSAGE",
&hds_gl_status );
}
} else {
first = 0;
}
}
}
}
/* Exit the routine, returning the current global status value. */
return hds_gl_status;
}