-
Notifications
You must be signed in to change notification settings - Fork 1
/
dat1_import_loc.c
184 lines (157 loc) · 8.39 KB
/
dat1_import_loc.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <ctype.h>
#include "ems.h" /* EMS error reporting routines */
#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_import_loc( const struct LOC * loc,
struct LCP **lcp )
{
/*+ */
/* Name: */
/* dat1_import_loc */
/* Purpose: */
/* Validate a locator and find its Locator Control Packet. */
/* Invocation: */
/* dat1_import_loc( loc, lcp ) */
/* Description: */
/* This routine validates a locator, as supplied by a caller of HDS, and */
/* identifies the Locator Control Packet associated with it. */
/* Parameters: */
/* struct LOC *loc */
/* Pointer to the locator. */
/* struct LCP **lcp */
/* Pointer to a pointer which will be set to point at the Locator */
/* Control Packet associated with the locator supplied (if valid). If */
/* the locator is not valid, or if any other error occurs, then a */
/* null pointer will be returned in *lcp. */
/* Returned Value: */
/* int dat1_import_loc */
/* The global status value current on exit. */
/* Copyright: */
/* Copyright (C) 1992 Science & Engineering Research Council */
/* Copyright (C) 2005 Particle Physics and Astronomy Research Council */
/* Authors: */
/* RFWS: R.F. Warren-Smith (STARLINK) */
/* BKM: B.K. McIlwrath (STARLINK) */
/* TIMJ: T. Jenness (JAC, Hawaii) */
/* {@enter_new_authors_here@} */
/* History: */
/* 25-SEP-1992 (RFWS): */
/* Converted from an earlier version. Explicit locator length */
/* argument added instead of passing pointer and length in a combined */
/* structure. */
/* 11-MAY-2004 (BKM): */
/* Change HDS 32/64-bit flag appropriately for locator */
/* 15-NOV-2005 (TIMJ): */
/* Change API to use the struct LOC explcitly */
/* 30-NOV-2005 (TIMJ): */
/* Try to be a bit cleverer when printing a bad locator */
/* 01-DEC-2005 (TIMJ): */
/* Abandon any attempt to print the contents of the struct */
/* 14-JUL-2006 (BKM) */
/* Produce a more informative message if the file record has been */
/* erased. */
/* {@enter_further_changes_here@} */
/* Bugs: */
/* {@note_any_bugs_here@} */
/*- */
/* Local Variables: */
int valid; /* Locator valid? */
struct RCL rcl; /* Record Control Label */
char strpntr[20]; /* Pointer location of bad loc */
/*. */
/* Check the inherited global status. */
if ( _ok( hds_gl_status ) )
{
/* See if HDS has been initialised. The locator cannot be valid if it has */
/* not, as no locators will have been issued. */
valid = hds_gl_active;
/* Validate the locator NULL-ness. */
if ( valid )
{
valid = ( loc != NULL );
}
/* Validate the locator check field. */
if ( valid )
{
valid = ( loc->check == DAT__LOCCHECK );
}
/* If OK, then identify the associated LCP and check that the locator */
/* sequence number tallies with the LCP sequence number. */
if ( valid )
{
*lcp = loc->lcp;
valid = ( loc->seqno == (*lcp)->seqno );
}
/* If OK, then check that the associated LCP is valid. */
if ( valid )
{
valid = (*lcp)->data.valid;
}
/* Check if we know that something has called 'rec_delete_record' on the */
/* target of the LCP. */
if ( valid )
{
if ( (*lcp)->data.erased )
{
hds_gl_status = DAT__LOCER;
emsSetnc( "NAME", (*lcp)->data.name, DAT__SZNAM );
emsRep( "DAT1_IMPORT_LOC_1",
"Locator target for \'^NAME\' has been \
erased - only annuling this locator is allowed).",
&hds_gl_status );
}
}
/* If still OK, then read the associated Record Control Label and check */
/* that the Record ID of the record's parent, as stored in the LCP, matches */
/* the RID stored in the actual record. */
if ( valid )
{
rec_get_rcl( &(*lcp)->data.han, &rcl );
if ( _ok( hds_gl_status ) )
{
/* If the RIDs do not match, then report an error. */
if ( ( rcl.parent.bloc != (*lcp)->data.parent.bloc ) ||
( rcl.parent.chip != (*lcp)->data.parent.chip ) )
{
hds_gl_status = DAT__INCHK;
emsSetnc( "NAME", (*lcp)->data.name, DAT__SZNAM );
emsRep( "DAT1_IMPORT_LOC_2",
"Locator refers to an object \'^NAME\' which no \
longer exists (possible programming error or corrupted HDS container file).",
&hds_gl_status );
}
}
}
/* If the locator is not valid, but no other error has occurred, then */
/* report an error. */
if ( !valid && _ok( hds_gl_status ) )
{
hds_gl_status = DAT__LOCIN;
/* Store the pointer */
sprintf(strpntr, "%p", loc );
emsSetc( "PNTR", strpntr );
emsRep( "DAT1_IMPORT_LOC_3",
"HDS locator invalid for import: value==^PNTR (possible programming error).",
&hds_gl_status );
}
}
/* If an error has occurred, then return a null pointer. */
if ( !_ok( hds_gl_status ) )
{
*lcp = NULL;
}
/* otherwise set the HDS 64-bit mode according to the "extended" bit in the */
/* RCL. */
else
{
hds_gl_64bit = rcl.extended;
}
/* Exit the routine. */
return hds_gl_status;
}