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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
/****************************************************************
* *
* Copyright 2001, 2014 Fidelity Information Services, Inc *
* *
* This source code contains the intellectual property *
* of its copyright holder(s), and is made available *
* under a license. If you do not know the terms of *
* the license, please stop and do not read further. *
* *
****************************************************************/
#include "mdef.h"
#include "gtm_string.h"
#include "stringpool.h"
#include "stp_parms.h"
#include "gdsroot.h"
#include "gdskill.h"
#include "gdsblk.h"
#include "gtm_facility.h"
#include "fileinfo.h"
#include "gdsbt.h"
#include "gdsfhead.h"
#include "error.h"
#include "muextr.h"
#include "util.h"
#include "mupip_exit.h"
#include "mlkdef.h"
#include "zshow.h"
#include "file_input.h"
#include "load.h"
#include "mu_gvis.h"
#include "mupip_put_gvdata.h"
#include "mupip_put_gvn_fragment.h"
#include "str2gvkey.h"
#include "gtmmsg.h"
#include "gtm_utf8.h"
#include <rtnhdr.h>
#include "gv_trigger.h"
#include "mu_interactive.h"
GBLREF bool mupip_error_occurred;
GBLREF bool mu_ctrly_occurred;
GBLREF bool mu_ctrlc_occurred;
GBLREF spdesc stringpool;
GBLREF gv_key *gv_currkey;
GBLREF sgmnt_addrs *cs_addrs;
GBLREF int onerror;
error_def(ERR_LOADCTRLY);
error_def(ERR_LOADEOF);
error_def(ERR_LOADFILERR);
error_def(ERR_LOADINVCHSET);
error_def(ERR_MUNOFINISH);
error_def(ERR_TRIGDATAIGNORE);
error_def(ERR_RECLOAD);
#define GO_PUT_SUB 0
#define GO_PUT_DATA 1
#define GO_SET_EXTRACT 2
#define DEFAULT_MAX_REC_SIZE 3096
#define ISSUE_TRIGDATAIGNORE_IF_NEEDED(KEYLENGTH, PTR, HASHT_GBL) \
{ \
/* The ordering of the && below is important as the caller uses HASHT_GBL to be set to TRUE if the global pointed to \
* by PTR is ^#t. \
*/ \
if ((HASHT_GBL = IS_GVKEY_HASHT_FULL_GBLNAME(KEYLENGTH, PTR)) && !hasht_ignored) \
{ \
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_TRIGDATAIGNORE, 2, KEYLENGTH, PTR); \
hasht_ignored = TRUE; \
} \
}
void go_call_db(int routine, char *parm1, int parm2, int val_off1, int val_len1);
void go_load(uint4 begin, uint4 end)
{
char *ptr;
int len, fmt, keylength, keystate;
uint4 iter, max_data_len, max_subsc_len, key_count, max_rec_size;
mstr src, des;
unsigned char *rec_buff, ch;
boolean_t utf8_extract, format_error = FALSE, hasht_ignored = FALSE, hasht_gbl = FALSE;
char *val_off;
int val_len, val_off1, val_len1;
boolean_t is_setextract;
gvinit();
max_rec_size = DEFAULT_MAX_REC_SIZE;
rec_buff = (unsigned char *)malloc(max_rec_size);
fmt = MU_FMT_ZWR; /* by default, the extract format is ZWR (not GO) */
len = file_input_get(&ptr);
if (mupip_error_occurred)
{
free(rec_buff);
return;
}
if (len >= 0)
{
util_out_print("!AD", TRUE, len, ptr);
utf8_extract = ((len >= STR_LIT_LEN(UTF8_NAME)) &&
(0 == MEMCMP_LIT(ptr + len - STR_LIT_LEN("UTF-8"), "UTF-8"))) ? TRUE : FALSE;
if ((utf8_extract && !gtm_utf8_mode) || (!utf8_extract && gtm_utf8_mode))
{ /* extract CHSET doesn't match $ZCHSET */
if (utf8_extract)
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_LOADINVCHSET, 2, LEN_AND_LIT("UTF-8"));
else
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_LOADINVCHSET, 2, LEN_AND_LIT("M"));
mupip_error_occurred = TRUE;
free(rec_buff);
return;
}
} else
mupip_exit(ERR_LOADFILERR);
len = file_input_get(&ptr);
if (mupip_error_occurred)
{
free(rec_buff);
return;
}
if (len >= 0)
{
util_out_print("!AD", TRUE, len, ptr);
fmt = (0 == memcmp(ptr + len - STR_LIT_LEN("ZWR"), "ZWR", STR_LIT_LEN("ZWR"))) ? MU_FMT_ZWR : MU_FMT_GO;
} else
mupip_exit(ERR_LOADFILERR);
if (begin < 3)
begin = 3;
for (iter = 3; iter < begin; iter++)
{
len = file_input_get(&ptr);
if (len < 0) /* The IO device has signalled an end of file */
{
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_LOADEOF, 1, begin);
mupip_error_occurred = TRUE;
}
if (mupip_error_occurred)
{
util_out_print("Error reading record number: !UL\n", TRUE, iter);
free(rec_buff);
return;
}
}
assert(iter == begin);
util_out_print("Beginning LOAD at record number: !UL\n", TRUE, begin);
max_data_len = 0;
max_subsc_len = 0;
key_count = 0;
for (iter = begin - 1; ; )
{
if (++iter > end)
break;
if (mupip_error_occurred && ONERROR_STOP == onerror)
break;
if (mu_ctrly_occurred)
break;
if (mu_ctrlc_occurred)
{
util_out_print("!AD:!_ Key cnt: !UL max subsc len: !UL max data len: !UL", TRUE,
LEN_AND_LIT("LOAD TOTAL"), key_count, max_subsc_len, max_data_len);
util_out_print("Last LOAD record number: !UL", TRUE, key_count ? iter : 0);
mu_gvis();
util_out_print(0, TRUE);
mu_ctrlc_occurred = FALSE;
}
if (0 > (len = file_input_get(&ptr)))
break;
if (mupip_error_occurred)
{
mu_gvis();
break;
}
if ('\n' == *ptr)
{
if ('\n' == *(ptr+1))
break;
ptr++;
}
if (0 == len)
continue;
if (MU_FMT_GO != fmt)
{
/* Determine if the ZWR has $extract format */
if ('$' == *ptr)
{
keylength = zwrkeyvallen(ptr, len, &val_off, &val_len, &val_off1, &val_len1);
ptr = ptr + 4; /* Skip first 4 character '$','z','e','(' */
is_setextract = TRUE;
} else
{
/* Determine the ZWR key length. -1 (SIZEOF(=)) is needed since ZWR allows '^x(1,2)='*/
keylength = zwrkeyvallen(ptr, len, &val_off, &val_len, NULL, NULL);
is_setextract = FALSE;
}
ISSUE_TRIGDATAIGNORE_IF_NEEDED(keylength, ptr, hasht_gbl);
if (hasht_gbl)
{
hasht_gbl = FALSE;
continue;
}
go_call_db(GO_PUT_SUB, ptr, keylength, 0, 0);
if (mupip_error_occurred)
{
mu_gvis();
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_RECLOAD, 1, iter);
gv_target = NULL;
gv_currkey->base[0] = '\0';
ONERROR_PROCESS;
}
assert(keylength < len - 1);
if (max_subsc_len < (gv_currkey->end + 1))
max_subsc_len = gv_currkey->end + 1;
src.len = val_len;
src.addr = val_off;
des.len = 0;
if (src.len > max_rec_size)
{
max_rec_size = src.len;
free(rec_buff);
rec_buff = (unsigned char *)malloc(max_rec_size);
}
des.addr = (char *)rec_buff;
if (FALSE == zwr2format(&src, &des))
{
util_out_print("Format error in record number !8UL: !/!AD", TRUE, iter, src.len, src.addr);
format_error = TRUE;
continue;
}
if (max_data_len < des.len)
max_data_len = des.len;
(is_setextract) ? go_call_db(GO_SET_EXTRACT, des.addr, des.len, val_off1, val_len1)
: go_call_db(GO_PUT_DATA, (char *)rec_buff, des.len, 0, 0);
if (mupip_error_occurred)
{
mu_gvis();
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_RECLOAD, 1, iter);
ONERROR_PROCESS;
}
key_count++;
} else
{
ISSUE_TRIGDATAIGNORE_IF_NEEDED(len, ptr, hasht_gbl);
if (hasht_gbl)
{
if (0 > (len = file_input_get(&ptr)))
break;
iter++;
hasht_gbl = FALSE;
continue;
}
go_call_db(GO_PUT_SUB, ptr, len, 0, 0);
if (mupip_error_occurred)
{
mu_gvis();
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_RECLOAD, 1, iter);
gv_target = NULL;
gv_currkey->base[0] = '\0';
ONERROR_PROCESS;
}
if (max_subsc_len < (gv_currkey->end + 1))
max_subsc_len = gv_currkey->end + 1;
if (++iter > end)
{
iter--; /* Decrement as didn't load key */
break;
}
if ((len = file_input_get(&ptr)) < 0)
break;
if (mupip_error_occurred)
{
mu_gvis();
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_RECLOAD, 1, iter);
break;
}
stringpool.free = stringpool.base;
if (max_data_len < len)
max_data_len = len;
go_call_db(GO_PUT_DATA, ptr, len, 0, 0);
if (mupip_error_occurred)
{
mu_gvis();
gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_RECLOAD, 1, iter);
ONERROR_PROCESS;
}
key_count++;
}
}
free(rec_buff);
file_input_close();
if (mu_ctrly_occurred)
{
gtm_putmsg_csa(CSA_ARG(cs_addrs) VARLSTCNT(1) ERR_LOADCTRLY);
mupip_exit(ERR_MUNOFINISH);
}
util_out_print("LOAD TOTAL!_!_Key Cnt: !UL Max Subsc Len: !UL Max Data Len: !UL",TRUE,key_count,max_subsc_len,
max_data_len);
util_out_print("Last LOAD record number: !UL\n", TRUE, key_count ? (iter - 1) : 0);
if (format_error)
mupip_exit(ERR_LOADFILERR);
}
void go_call_db(int routine, char *parm1, int parm2, int val_off1, int val_len1)
{
/* In order to duplicate the VMS functionality, which is to trap all errors in mupip_load_ch
* and continue in go_load after they occur, it is necessary to call these routines from a
* subroutine due to the limitations of condition handlers and unwinding on UNIX.
*/
ESTABLISH(mupip_load_ch);
switch(routine)
{ case GO_PUT_SUB:
gv_currkey->end = 0;
str2gvkey_gvfunc(parm1, parm2);
break;
case GO_PUT_DATA:
mupip_put_gvdata(parm1, parm2);
break;
case GO_SET_EXTRACT:
mupip_put_gvn_fragment(parm1, parm2, val_off1, val_len1);
break;
}
REVERT;
}
|