| 1 | /* ---------------------------------------------------------------- EASYCI.C */ |
|---|
| 2 | |
|---|
| 3 | /* ///////////////////////////////////////////////////////////////////////// |
|---|
| 4 | |
|---|
| 5 | [ Version 1.0 ] |
|---|
| 6 | 28.Oct.1998 - Cisis facilities. |
|---|
| 7 | |
|---|
| 8 | [ Version 1.1 ] |
|---|
| 9 | 02.Feb.1999 - "eci_field_DO": delete field occurrence. |
|---|
| 10 | |
|---|
| 11 | ///////////////////////////////////////////////////////////////////////// */ |
|---|
| 12 | |
|---|
| 13 | /* ---------------------------------------------------------- C HEADER FILES */ |
|---|
| 14 | #include <string.h> |
|---|
| 15 | #include <ctype.h> |
|---|
| 16 | /* #include <mem.h> */ |
|---|
| 17 | /* ------------------------------------------------------------ HEADER FILES */ |
|---|
| 18 | #include "../cisis.h" |
|---|
| 19 | #include "easyfc.h" |
|---|
| 20 | #include "easyci.h" |
|---|
| 21 | /* --------------------------------------------------------------- externals */ |
|---|
| 22 | extern RECSTRU *vrecp[]; /* cirun.h */ |
|---|
| 23 | extern TRMSTRU *vtrmp[]; /* cirun.h */ |
|---|
| 24 | extern int dbxsleep; /* cidbx.c */ |
|---|
| 25 | |
|---|
| 26 | /* ============================================================= eci_rec_new */ |
|---|
| 27 | long eci_rec_new(EFC_ERROR *err, /* error structure */ |
|---|
| 28 | long mfrl) /* master file record lenght */ |
|---|
| 29 | { |
|---|
| 30 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 31 | 1. Find last unused record index, if unavailable: return error |
|---|
| 32 | 2. Allocate found record index |
|---|
| 33 | 3. Return record index |
|---|
| 34 | |
|---|
| 35 | 1.0 - 28.Oct.1998 |
|---|
| 36 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 37 | long idx; /* auxiliary find index */ |
|---|
| 38 | |
|---|
| 39 | /* 1 */ |
|---|
| 40 | for (idx = maxnrec-1; vrecp[idx]; idx--) |
|---|
| 41 | if (!idx) { |
|---|
| 42 | efc_error(err,ECI_ERROR_MAXNREC,NULL); |
|---|
| 43 | return -1L; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | /* 2 */ |
|---|
| 47 | |
|---|
| 48 | recallok(idx,mfrl); |
|---|
| 49 | |
|---|
| 50 | /* 3 */ |
|---|
| 51 | return idx; |
|---|
| 52 | } |
|---|
| 53 | /* ========================================================== eci_rec_active */ |
|---|
| 54 | long eci_rec_active(long idx) /* record index */ |
|---|
| 55 | { |
|---|
| 56 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 57 | 1. Set active and normal flags |
|---|
| 58 | 2. Return record index |
|---|
| 59 | |
|---|
| 60 | 1.0 - 28.Oct.1998 |
|---|
| 61 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 62 | |
|---|
| 63 | /* 1 */ |
|---|
| 64 | VMFRstatus(idx) = ACTIVE; |
|---|
| 65 | VRECrc(idx) = RCNORMAL; |
|---|
| 66 | VMFRmfn(idx) = 1L; |
|---|
| 67 | VRECtype(idx) = TYPEMFR; |
|---|
| 68 | VMFRmfrl(idx) = VMFRbase(idx) = LEADER; |
|---|
| 69 | |
|---|
| 70 | /* 2 */ |
|---|
| 71 | return idx; |
|---|
| 72 | } |
|---|
| 73 | /* ============================================================ eci_rec_copy */ |
|---|
| 74 | void eci_rec_copy(long to, /* target record index */ |
|---|
| 75 | long from) /* source record index */ |
|---|
| 76 | { |
|---|
| 77 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 78 | 1. Copy record index content |
|---|
| 79 | |
|---|
| 80 | 1.0 - 28.Oct.1998 |
|---|
| 81 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 82 | |
|---|
| 83 | /* 1 */ |
|---|
| 84 | VRECrc(to) = VRECrc(from); |
|---|
| 85 | memcpy(VMFX(to),VMFX(from),VMFRmfrl(from)); |
|---|
| 86 | } |
|---|
| 87 | /* ============================================================ eci_rec_free */ |
|---|
| 88 | void eci_rec_free(long idx) /* record index */ |
|---|
| 89 | { |
|---|
| 90 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 91 | 1. Free record structure |
|---|
| 92 | 2. Decrease record index count |
|---|
| 93 | |
|---|
| 94 | 1.0 - 28.Oct.1998 |
|---|
| 95 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 96 | |
|---|
| 97 | /* 1 */ |
|---|
| 98 | if (!vrecp[idx]) return; |
|---|
| 99 | vrecp[idx] = efc_free(vrecp[idx]); |
|---|
| 100 | |
|---|
| 101 | /* 2 */ |
|---|
| 102 | nrecs--; |
|---|
| 103 | } |
|---|
| 104 | /* ============================================================= eci_trm_new */ |
|---|
| 105 | long eci_trm_new(EFC_ERROR *err) /* error structure */ |
|---|
| 106 | { |
|---|
| 107 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 108 | 1. Find last unused term index, if unavailable: return error |
|---|
| 109 | 2. Return term index |
|---|
| 110 | |
|---|
| 111 | 1.0 - 05.Nov.1998 |
|---|
| 112 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 113 | long idx; /* auxiliary find index */ |
|---|
| 114 | |
|---|
| 115 | /* 1 */ |
|---|
| 116 | for (idx = maxntrm-1; vtrmp[idx]; idx--) |
|---|
| 117 | if (!idx) { |
|---|
| 118 | efc_error(err,ECI_ERROR_MAXNTRM,NULL); |
|---|
| 119 | return -1L; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | /* 2 */ |
|---|
| 123 | return idx; |
|---|
| 124 | } |
|---|
| 125 | /* ============================================================ eci_trm_free */ |
|---|
| 126 | void eci_trm_free(long idx) /* term index */ |
|---|
| 127 | { |
|---|
| 128 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 129 | 1. Free term structure |
|---|
| 130 | 2. Decrease term index count |
|---|
| 131 | |
|---|
| 132 | 1.0 - 05.Nov.1998 |
|---|
| 133 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 134 | |
|---|
| 135 | /* 1 */ |
|---|
| 136 | if (!vtrmp[idx]) return; |
|---|
| 137 | vtrmp[idx] = efc_free(vtrmp[idx]); |
|---|
| 138 | |
|---|
| 139 | /* 2 */ |
|---|
| 140 | ntrms--; |
|---|
| 141 | } |
|---|
| 142 | /* ============================================================ eci_last_mfn */ |
|---|
| 143 | long eci_last_mfn(EFC_ERROR *err, /* error structure */ |
|---|
| 144 | char *db) /* data base name */ |
|---|
| 145 | { |
|---|
| 146 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 147 | 1. Allocate a control record |
|---|
| 148 | 2. Access the control record, and the last MFN |
|---|
| 149 | 3. Garbage collector |
|---|
| 150 | 4. Return the last MFN |
|---|
| 151 | |
|---|
| 152 | 1.0 - 04.Nov.1998 |
|---|
| 153 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 154 | long idx; /* control record index */ |
|---|
| 155 | long last_mfn; /* last MFN */ |
|---|
| 156 | |
|---|
| 157 | /* 1 */ |
|---|
| 158 | idx = eci_rec_new(err,sizeof(M0STRU)); |
|---|
| 159 | if (idx < 0L) return idx; |
|---|
| 160 | |
|---|
| 161 | /* 2 */ |
|---|
| 162 | record(idx,db,0L); |
|---|
| 163 | last_mfn = VMF0nxtmfn(idx)-1L; |
|---|
| 164 | |
|---|
| 165 | /* 3 */ |
|---|
| 166 | eci_rec_free(idx); |
|---|
| 167 | |
|---|
| 168 | /* 4 */ |
|---|
| 169 | return last_mfn; |
|---|
| 170 | } |
|---|
| 171 | /* =============================================================== eci_field */ |
|---|
| 172 | char *eci_field(long idx, /* record index */ |
|---|
| 173 | int tag, |
|---|
| 174 | int occ, |
|---|
| 175 | char *buff) /* field update instructions */ |
|---|
| 176 | { |
|---|
| 177 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 178 | 1. Get field directory index |
|---|
| 179 | 2. Copy field data to the buffer |
|---|
| 180 | 3. Return buffer pointer |
|---|
| 181 | |
|---|
| 182 | 1.0 - 30.Oct.1998 |
|---|
| 183 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 184 | int i; |
|---|
| 185 | |
|---|
| 186 | /* 1 */ |
|---|
| 187 | if ((i = fieldx(idx,tag,occ)) < 0) return NULL; |
|---|
| 188 | |
|---|
| 189 | /* 2 */ |
|---|
| 190 | strncpy(buff,VFIELDP(idx,i),VDIRlen(idx,i)); |
|---|
| 191 | *(buff+VDIRlen(idx,i)) = '\0'; |
|---|
| 192 | |
|---|
| 193 | /* 3 */ |
|---|
| 194 | return buff; |
|---|
| 195 | } |
|---|
| 196 | /* =========================================================== eci_sub_field */ |
|---|
| 197 | char *eci_sub_field(char subfld_char, /* subfield character */ |
|---|
| 198 | char *buff) /* field buffer */ |
|---|
| 199 | { |
|---|
| 200 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 201 | 1. |
|---|
| 202 | |
|---|
| 203 | 1.0 - 10.Nov.1998 |
|---|
| 204 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 205 | char upper_subfld_char; |
|---|
| 206 | char *p; |
|---|
| 207 | char *q; |
|---|
| 208 | |
|---|
| 209 | /* 1 */ |
|---|
| 210 | if (!buff) return NULL; |
|---|
| 211 | upper_subfld_char = toupper(subfld_char); |
|---|
| 212 | |
|---|
| 213 | /* 2 */ |
|---|
| 214 | for (p = buff; *p; p++) { |
|---|
| 215 | if (*p != '^') continue; |
|---|
| 216 | if (*(p+1) == subfld_char || *(p+1) == upper_subfld_char) break; |
|---|
| 217 | } |
|---|
| 218 | if (!*p) return NULL; |
|---|
| 219 | p++; p++; |
|---|
| 220 | |
|---|
| 221 | /* 3 */ |
|---|
| 222 | for (q = buff; *p; p++) { |
|---|
| 223 | if (*p == '^') break; |
|---|
| 224 | *q++ = *p; |
|---|
| 225 | } |
|---|
| 226 | *q = '\0'; |
|---|
| 227 | |
|---|
| 228 | /* 4 */ |
|---|
| 229 | return buff; |
|---|
| 230 | } |
|---|
| 231 | /* ======================================================== eci_field_update */ |
|---|
| 232 | ECI_ERROR eci_field_update(EFC_ERROR *err,/* error structure */ |
|---|
| 233 | long idx, /* record index */ |
|---|
| 234 | char *buff) /* field update instructions */ |
|---|
| 235 | { |
|---|
| 236 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 237 | 1. Field update |
|---|
| 238 | |
|---|
| 239 | 1.0 - 28.Oct.1998 |
|---|
| 240 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 241 | char *error_p; /* error pointer */ |
|---|
| 242 | |
|---|
| 243 | /* 1 */ |
|---|
| 244 | error_p = fldupdat(idx,buff); |
|---|
| 245 | return error_p ? efc_error(err,ECI_ERROR_FLDUPD,error_p) : ECI_ERROR_OK; |
|---|
| 246 | } |
|---|
| 247 | /* ============================================================= eci_field_D */ |
|---|
| 248 | ECI_ERROR eci_field_D(EFC_ERROR *err, /* error structure */ |
|---|
| 249 | long idx, /* record index */ |
|---|
| 250 | int tag) /* field tag */ |
|---|
| 251 | { |
|---|
| 252 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 253 | 1. Fill the buffer with delete field instruction |
|---|
| 254 | 2. Field update |
|---|
| 255 | |
|---|
| 256 | 1.0 - 28.Oct.1998 |
|---|
| 257 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 258 | char buff[ECI_FIELD_UPDATE_SIZE+1]; /* auxiliary field update buffer */ |
|---|
| 259 | |
|---|
| 260 | /* 1 */ |
|---|
| 261 | if (tag) sprintf(buff,"D%d",tag); |
|---|
| 262 | else sprintf(buff,"D*"); |
|---|
| 263 | |
|---|
| 264 | /* 2 */ |
|---|
| 265 | return eci_field_update(err,idx,buff); |
|---|
| 266 | } |
|---|
| 267 | /* ============================================================ eci_field_DO */ |
|---|
| 268 | ECI_ERROR eci_field_DO(EFC_ERROR *err, /* error structure */ |
|---|
| 269 | long idx, /* record index */ |
|---|
| 270 | int tag, /* field tag */ |
|---|
| 271 | int occ) /* field ocurrence */ |
|---|
| 272 | { |
|---|
| 273 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 274 | 1. Fill the buffer with delete field instruction |
|---|
| 275 | 2. Field update |
|---|
| 276 | |
|---|
| 277 | 1.1 - 08.Feb.1999 |
|---|
| 278 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 279 | char buff[ECI_FIELD_UPDATE_SIZE+1]; /* auxiliary field update buffer */ |
|---|
| 280 | |
|---|
| 281 | /* 1 */ |
|---|
| 282 | if (tag) |
|---|
| 283 | if (occ) sprintf(buff,"D%d/%d",tag,occ); |
|---|
| 284 | else sprintf(buff,"D%d",tag,occ); |
|---|
| 285 | else sprintf(buff,"D*"); |
|---|
| 286 | |
|---|
| 287 | /* 2 */ |
|---|
| 288 | return eci_field_update(err,idx,buff); |
|---|
| 289 | } |
|---|
| 290 | /* ============================================================ eci_field_AN */ |
|---|
| 291 | ECI_ERROR eci_field_AN(EFC_ERROR *err, /* error structure */ |
|---|
| 292 | long idx, /* record index */ |
|---|
| 293 | int tag, /* field tag */ |
|---|
| 294 | long num) /* field value */ |
|---|
| 295 | { |
|---|
| 296 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 297 | 1. Fill the buffer with add field instruction |
|---|
| 298 | 2. Field update |
|---|
| 299 | |
|---|
| 300 | 1.0 - 28.Oct.1998 |
|---|
| 301 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 302 | char buff[ECI_FIELD_UPDATE_SIZE+1]; /* auxiliary field update buffer */ |
|---|
| 303 | |
|---|
| 304 | /* 1 */ |
|---|
| 305 | sprintf(buff,"A%d|%ld|",tag,num); |
|---|
| 306 | |
|---|
| 307 | /* 2 */ |
|---|
| 308 | return eci_field_update(err,idx,buff); |
|---|
| 309 | } |
|---|
| 310 | /* ============================================================ eci_field_MN */ |
|---|
| 311 | ECI_ERROR eci_field_MN(EFC_ERROR *err, /* error structure */ |
|---|
| 312 | long idx, /* record index */ |
|---|
| 313 | int tag, /* field tag */ |
|---|
| 314 | long num) /* field value */ |
|---|
| 315 | { |
|---|
| 316 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 317 | 1. Field delete, field add |
|---|
| 318 | |
|---|
| 319 | 1.0 - 28.Oct.1998 |
|---|
| 320 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 321 | ECI_ERROR error_code; /* error code */ |
|---|
| 322 | |
|---|
| 323 | /* 1 */ |
|---|
| 324 | error_code = eci_field_D(err,idx,tag); |
|---|
| 325 | if (!error_code) error_code = eci_field_AN(err,idx,tag,num); |
|---|
| 326 | return error_code; |
|---|
| 327 | } |
|---|
| 328 | /* ============================================================ eci_field_AT */ |
|---|
| 329 | ECI_ERROR eci_field_AT(EFC_ERROR *err, /* error structure */ |
|---|
| 330 | long idx, /* record index */ |
|---|
| 331 | int tag, /* field tag */ |
|---|
| 332 | char *text) /* field content */ |
|---|
| 333 | { |
|---|
| 334 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 335 | 1. Allocate space for field update |
|---|
| 336 | 2. Fill the buffer with add field instruction |
|---|
| 337 | 3. Field update |
|---|
| 338 | 4. Garbage collector |
|---|
| 339 | 5. Return error code |
|---|
| 340 | |
|---|
| 341 | 1.0 - 28.Oct.1998 |
|---|
| 342 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 343 | char *buff; /* auxiliary string buffer pointer */ |
|---|
| 344 | long buff_size; /* string buffer size needed */ |
|---|
| 345 | ECI_ERROR error_code; /* error code */ |
|---|
| 346 | |
|---|
| 347 | /* 1 */ |
|---|
| 348 | buff_size = strlen(text); |
|---|
| 349 | buff = efc_new(ECI_FIELD_UPDATE_SIZE+buff_size+1); |
|---|
| 350 | if (!buff) return efc_error(err,ECI_ERROR_ALLOC,text); |
|---|
| 351 | |
|---|
| 352 | /* 2 */ |
|---|
| 353 | sprintf(buff,"H %d %ld %s",tag,buff_size,text); |
|---|
| 354 | |
|---|
| 355 | /* 3 */ |
|---|
| 356 | error_code = eci_field_update(err,idx,buff); |
|---|
| 357 | |
|---|
| 358 | /* 4 */ |
|---|
| 359 | efc_free(buff); |
|---|
| 360 | |
|---|
| 361 | /* 5 */ |
|---|
| 362 | return error_code; |
|---|
| 363 | } |
|---|
| 364 | /* ============================================================ eci_field_MT */ |
|---|
| 365 | ECI_ERROR eci_field_MT(EFC_ERROR *err, /* error structure */ |
|---|
| 366 | long idx, /* record index */ |
|---|
| 367 | int tag, /* field tag */ |
|---|
| 368 | char *text) /* field content */ |
|---|
| 369 | { |
|---|
| 370 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 371 | 1. Field delete, field add |
|---|
| 372 | |
|---|
| 373 | 1.0 - 28.Oct.1998 |
|---|
| 374 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 375 | ECI_ERROR error_code; /* error code */ |
|---|
| 376 | |
|---|
| 377 | /* 1 */ |
|---|
| 378 | error_code = eci_field_D(err,idx,tag); |
|---|
| 379 | if (!error_code) error_code = eci_field_AT(err,idx,tag,text); |
|---|
| 380 | return error_code; |
|---|
| 381 | } |
|---|
| 382 | /* ============================================================ eci_field_ML */ |
|---|
| 383 | ECI_ERROR eci_field_ML(EFC_ERROR *err, /* error structure */ |
|---|
| 384 | long idx, /* record index */ |
|---|
| 385 | int tag, /* field tag */ |
|---|
| 386 | char *list) /* field list content */ |
|---|
| 387 | { |
|---|
| 388 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 389 | 1. Delete field |
|---|
| 390 | 2. Split each line as a new field occurrence |
|---|
| 391 | 3. Skip end of line characters |
|---|
| 392 | 4. Find next end of line position |
|---|
| 393 | 5. Keep end of line character, field update, restore end of line character |
|---|
| 394 | 6. Return error code |
|---|
| 395 | |
|---|
| 396 | 1.0 - 28.Oct.1998 |
|---|
| 397 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 398 | char *p; /* auxiliary string buffer pointer */ |
|---|
| 399 | char *q; /* auxiliary string buffer pointer */ |
|---|
| 400 | char back_char; /* backup line end character */ |
|---|
| 401 | ECI_ERROR error_code; /* error code */ |
|---|
| 402 | |
|---|
| 403 | /* 1 */ |
|---|
| 404 | error_code = eci_field_D(err,idx,tag); |
|---|
| 405 | if (error_code) return error_code; |
|---|
| 406 | |
|---|
| 407 | /* 2 */ |
|---|
| 408 | for (p = list; *p; p++) { |
|---|
| 409 | |
|---|
| 410 | /* 3 */ |
|---|
| 411 | if (*p == '\r' || *p == '\n') continue; |
|---|
| 412 | |
|---|
| 413 | /* 4 */ |
|---|
| 414 | for (q = p; *p && *p != '\r' && *p != '\n'; p++); |
|---|
| 415 | |
|---|
| 416 | /* 5 */ |
|---|
| 417 | back_char = *p; |
|---|
| 418 | *p = '\0'; |
|---|
| 419 | error_code = eci_field_AT(err,idx,tag,q); |
|---|
| 420 | *p = back_char; |
|---|
| 421 | if (error_code || !*p) break; |
|---|
| 422 | |
|---|
| 423 | } /* for */ |
|---|
| 424 | |
|---|
| 425 | /* 6 */ |
|---|
| 426 | return error_code; |
|---|
| 427 | } |
|---|
| 428 | /* ========================================================== eci_field_copy */ |
|---|
| 429 | ECI_ERROR eci_field_copy(EFC_ERROR *err, /* error structure */ |
|---|
| 430 | BOOLEAN del, /* delete previous value */ |
|---|
| 431 | long to_idx, /* source record index */ |
|---|
| 432 | int to_tag, /* source field tag */ |
|---|
| 433 | long from_idx, /* target record index */ |
|---|
| 434 | int from_tag) /* target field tag */ |
|---|
| 435 | { |
|---|
| 436 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 437 | 0. Check invalid copy: cannot be copied onto itself |
|---|
| 438 | 1. Delete target field |
|---|
| 439 | 2. Loop all source field occurrences |
|---|
| 440 | 3. Get field directory index, check end of occurrences |
|---|
| 441 | 4. Allocate work buffer |
|---|
| 442 | 5. Copy source field to buffer |
|---|
| 443 | 6. Field add buffer to target field |
|---|
| 444 | 7. Return error code |
|---|
| 445 | |
|---|
| 446 | 1.0 - 05.Nov.1998 |
|---|
| 447 | 1.1 - 25.Feb.1999 |
|---|
| 448 | 1. delete flag |
|---|
| 449 | 1.2 - 17.Jun.1999 |
|---|
| 450 | 1. copy check |
|---|
| 451 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 452 | int occ; /* auxiliary occurrence index */ |
|---|
| 453 | int i; /* auxiliary field directory index */ |
|---|
| 454 | char *buff; /* auxiliary string buffer pointer */ |
|---|
| 455 | ECI_ERROR error_code = ECI_ERROR_OK; /* error code */ |
|---|
| 456 | |
|---|
| 457 | /* 0 */ |
|---|
| 458 | if (to_idx == from_idx && to_tag == from_tag) { |
|---|
| 459 | return efc_error(err,ECI_ERROR_FLDUPD,"cannot be copied onto itself"); |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | /* 1 */ |
|---|
| 463 | if (del) { |
|---|
| 464 | error_code = eci_field_D(err,to_idx,to_tag); |
|---|
| 465 | if (error_code) return error_code; |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | /* 2 */ |
|---|
| 469 | for (occ = 1; ; occ++) { |
|---|
| 470 | |
|---|
| 471 | /* 3 */ |
|---|
| 472 | i = fieldx(from_idx,from_tag,occ); |
|---|
| 473 | if (i < 0) break; |
|---|
| 474 | |
|---|
| 475 | /* 4 */ |
|---|
| 476 | buff = efc_new(VDIRlen(from_idx,i)+1); |
|---|
| 477 | if (!buff) return efc_error(err,ECI_ERROR_ALLOC,NULL); |
|---|
| 478 | |
|---|
| 479 | /* 5 */ |
|---|
| 480 | strncpy(buff,VFIELDP(from_idx,i),VDIRlen(from_idx,i)); |
|---|
| 481 | *(buff+VDIRlen(from_idx,i)) = '\0'; |
|---|
| 482 | |
|---|
| 483 | /* 6 */ |
|---|
| 484 | error_code = eci_field_AT(err,to_idx,to_tag,buff); |
|---|
| 485 | efc_free(buff); |
|---|
| 486 | if (error_code) break; |
|---|
| 487 | |
|---|
| 488 | } /* for */ |
|---|
| 489 | |
|---|
| 490 | /* 7 */ |
|---|
| 491 | return error_code; |
|---|
| 492 | } |
|---|
| 493 | /* ========================================================== eci_set_uctab */ |
|---|
| 494 | ECI_ERROR eci_set_uctab(EFC_ERROR *err,/* error structure */ |
|---|
| 495 | unsigned char *p) /* upper case string buffer pointer */ |
|---|
| 496 | { |
|---|
| 497 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 498 | 1.0 - 28.Oct.1998 |
|---|
| 499 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 500 | int i; /* auxiliary table index */ |
|---|
| 501 | int conv_code; /* convertion code */ |
|---|
| 502 | |
|---|
| 503 | /* [1.0] set alphabetic char table */ |
|---|
| 504 | for (i = 0; *p; p++) { |
|---|
| 505 | |
|---|
| 506 | /* [1.0] skip non numeric characters */ |
|---|
| 507 | if (!isdigit(*p)) continue; |
|---|
| 508 | |
|---|
| 509 | /* [1.0] check table limit */ |
|---|
| 510 | conv_code = atoi(p); |
|---|
| 511 | if (conv_code < 0 || conv_code > 255) |
|---|
| 512 | return efc_error(err,ECI_ERROR_UCTAB,p); |
|---|
| 513 | |
|---|
| 514 | /* [1.0] set word case table */ |
|---|
| 515 | isisuctab[i++] = (unsigned char)conv_code; |
|---|
| 516 | if (i > 255) break; |
|---|
| 517 | |
|---|
| 518 | /* [1.0] skip numeric characters */ |
|---|
| 519 | while (isdigit(*p)) p++; |
|---|
| 520 | |
|---|
| 521 | } /* for */ |
|---|
| 522 | |
|---|
| 523 | /* [1.0] no error */ |
|---|
| 524 | return ECI_ERROR_OK; |
|---|
| 525 | } |
|---|
| 526 | /* ========================================================== eci_set_actab */ |
|---|
| 527 | ECI_ERROR eci_set_actab(EFC_ERROR *err,/* error structure */ |
|---|
| 528 | char *p) /* alphabetic character string buffer pointer */ |
|---|
| 529 | { |
|---|
| 530 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 531 | 1.0 - 28.Oct.1998 |
|---|
| 532 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 533 | int i; /* auxiliary table index */ |
|---|
| 534 | |
|---|
| 535 | /* [1.0] no table entry */ |
|---|
| 536 | if (!*p) return ECI_ERROR_OK; |
|---|
| 537 | |
|---|
| 538 | /* [1.0] reset alphabetic char table */ |
|---|
| 539 | memset(isiswctab,0x00,256); |
|---|
| 540 | |
|---|
| 541 | /* [1.0] set alphabetic char table */ |
|---|
| 542 | for (isiswctot = 0; *p; p++) { |
|---|
| 543 | |
|---|
| 544 | /* [1.0] skip non numeric characters */ |
|---|
| 545 | if (!isdigit(*p)) continue; |
|---|
| 546 | |
|---|
| 547 | /* [1.0] check table limit */ |
|---|
| 548 | i = atoi(p); |
|---|
| 549 | if (i < 0 || i > 255) return efc_error(err,ECI_ERROR_ACTAB,p); |
|---|
| 550 | |
|---|
| 551 | /* [1.0] set word case table */ |
|---|
| 552 | if (!isiswctab[i]) isiswctot++; |
|---|
| 553 | isiswctab[i] = 1; |
|---|
| 554 | |
|---|
| 555 | /* [1.0] skip numeric characters */ |
|---|
| 556 | while (isdigit(*p)) p++; |
|---|
| 557 | |
|---|
| 558 | } /* for */ |
|---|
| 559 | |
|---|
| 560 | /* [1.0] no error */ |
|---|
| 561 | return ECI_ERROR_OK; |
|---|
| 562 | } |
|---|
| 563 | /* =============================================================== eci_uctab */ |
|---|
| 564 | char *eci_uctab(char *buff) /* string buffer pointer */ |
|---|
| 565 | { |
|---|
| 566 | /* 03.Jul.2000 |
|---|
| 567 | WARNING: it has to be unsigned char |
|---|
| 568 | */ |
|---|
| 569 | unsigned char *p; /* auxiliary string buffer pointer */ |
|---|
| 570 | |
|---|
| 571 | /* [1.0] convert all characters according the upper case table */ |
|---|
| 572 | if (buff) |
|---|
| 573 | for (p = buff; *p; p++) *p = isisuctab[*p]; |
|---|
| 574 | |
|---|
| 575 | /* [1.0] return original buffer pointer */ |
|---|
| 576 | return buff; |
|---|
| 577 | } |
|---|
| 578 | /* ============================================================= eci_fmt_all */ |
|---|
| 579 | ECI_ERROR eci_fmt_all(long idx, /* record index */ |
|---|
| 580 | char *buff) /* output buffer */ |
|---|
| 581 | { |
|---|
| 582 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 583 | 1.0 - 28.Oct.1998 |
|---|
| 584 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 585 | |
|---|
| 586 | /* 1 */ |
|---|
| 587 | /* [1.0] fill a buffer with all record fields */ |
|---|
| 588 | char *p = buff; /* auxiliary buffer */ |
|---|
| 589 | int flddir; /* field directory index */ |
|---|
| 590 | char *fld; |
|---|
| 591 | |
|---|
| 592 | /* [1.0] fill the buffer with the MFN */ |
|---|
| 593 | sprintf(p,"mfn=%ld<BR>\n",VMFRmfn(idx)); |
|---|
| 594 | p += strlen(p); |
|---|
| 595 | |
|---|
| 596 | /* [1.0] loop for all fields */ |
|---|
| 597 | for (flddir = 0; flddir < VMFRnvf(idx); flddir++) { |
|---|
| 598 | sprintf(p,"%5u %c",VDIRtag(idx,flddir),OPENFCHR); |
|---|
| 599 | p += strlen(p); |
|---|
| 600 | |
|---|
| 601 | sprintf(p,"%-.*s%c<BR>\n",VDIRlen(idx,flddir),VFIELDP(idx,flddir),CLOSFCHR); |
|---|
| 602 | p += strlen(p); |
|---|
| 603 | } /* for */ |
|---|
| 604 | |
|---|
| 605 | /* [1.0] set string terminator character */ |
|---|
| 606 | *p = '\0'; |
|---|
| 607 | |
|---|
| 608 | /* [1.0] return OK */ |
|---|
| 609 | return ECI_ERROR_OK; |
|---|
| 610 | } |
|---|
| 611 | /* ------------------------------------------------------ eci_export_iso2709 */ |
|---|
| 612 | #define ISO_LEADER_LENGHT 24 |
|---|
| 613 | #define ISO_TAG_LENGHT 3 |
|---|
| 614 | #define ISO_FLDLEN_LENGHT 4 |
|---|
| 615 | #define ISO_FLDLOC_LENGHT 5 |
|---|
| 616 | #define ISO_DIRECTORY_LENGHT (ISO_TAG_LENGHT + ISO_FLDLEN_LENGHT + ISO_FLDLOC_LENGHT) |
|---|
| 617 | #define ISO_FLDSEP '#' |
|---|
| 618 | #define ISO_MARCFLDSEP 30 |
|---|
| 619 | #define ISO_FLDSEP_LENGHT 1 |
|---|
| 620 | #define ISO_RECSEP '#' |
|---|
| 621 | #define ISO_MARCRECSEP 29 |
|---|
| 622 | #define ISO_RECSEP_LENGHT 1 |
|---|
| 623 | #define ISO_LINE_LENGHT 80 |
|---|
| 624 | #define ISO_MARC_TAG 3000 |
|---|
| 625 | |
|---|
| 626 | char ldrtag(long idx, |
|---|
| 627 | int tag) { |
|---|
| 628 | char *p = "0"; |
|---|
| 629 | int flddir = 0; |
|---|
| 630 | int nvf = VMFRnvf(idx); |
|---|
| 631 | |
|---|
| 632 | for (flddir = 0; flddir < nvf; flddir++) { |
|---|
| 633 | if (tag == VDIRtag(idx,flddir)) { |
|---|
| 634 | if (VDIRlen(idx,flddir) > 0) { |
|---|
| 635 | p = VFIELDP(idx,flddir); |
|---|
| 636 | } |
|---|
| 637 | break; |
|---|
| 638 | } |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | return *p; |
|---|
| 642 | } |
|---|
| 643 | |
|---|
| 644 | BOOLEAN eci_export_iso2709_marc(FILE *export_fp, /* export file pointer */ |
|---|
| 645 | long idx) /* record index */ |
|---|
| 646 | |
|---|
| 647 | { |
|---|
| 648 | char *buff; /* iso formed record buffer */ |
|---|
| 649 | char *p; /* auxiliary pointer */ |
|---|
| 650 | long total_dir; /* directory quantity of bytes */ |
|---|
| 651 | long base_address; /* base address quantity of bytes */ |
|---|
| 652 | long total_data; /* data quantity of bytes */ |
|---|
| 653 | long total_record; /* record quantity of bytes */ |
|---|
| 654 | long location_offset; /* location offset from the first data */ |
|---|
| 655 | int tag; /* field number */ |
|---|
| 656 | int flddir; /* field directory index */ |
|---|
| 657 | int skip_bytes; /* auxiliary print quantity of bytes */ |
|---|
| 658 | int nvf; /* number of variable fields */ |
|---|
| 659 | |
|---|
| 660 | char status[1]; /* Estado del registro */ |
|---|
| 661 | char icodes[4]; /* 0=Tipo de registro; 1=Nivel bibliogr�co; 2=Tipo de control; 3=unused */ |
|---|
| 662 | char forusr[3]; /* 0=Nivel de codificaci�1=Forma de catalogaci�2=Linked requirement */ |
|---|
| 663 | |
|---|
| 664 | /* .......................................... calculate quantity of bytes */ |
|---|
| 665 | for (flddir = 0,nvf=0,total_data = 0L; flddir < VMFRnvf(idx); flddir++) { |
|---|
| 666 | tag = VDIRtag(idx,flddir); |
|---|
| 667 | if (tag >= ISO_MARC_TAG) if (tag <= ISO_MARC_TAG+ISOHSIZE) continue; |
|---|
| 668 | total_data += VDIRlen(idx,flddir) + ISO_FLDSEP_LENGHT; |
|---|
| 669 | nvf++; |
|---|
| 670 | } |
|---|
| 671 | total_dir = nvf * ISO_DIRECTORY_LENGHT; |
|---|
| 672 | base_address = ISO_LEADER_LENGHT + total_dir + ISO_FLDSEP_LENGHT; |
|---|
| 673 | total_record = base_address + total_data + ISO_RECSEP_LENGHT; |
|---|
| 674 | |
|---|
| 675 | /* ................................................ allocate buffer space */ |
|---|
| 676 | buff = (char *)ALLOC((ALLOPARM)(total_record+1)); |
|---|
| 677 | if (!buff) return FALSE; |
|---|
| 678 | |
|---|
| 679 | /* ............................................................... leader */ |
|---|
| 680 | status[0] = ldrtag(idx, ISO_MARC_TAG + 5); |
|---|
| 681 | icodes[0] = ldrtag(idx, ISO_MARC_TAG + 6); |
|---|
| 682 | icodes[1] = ldrtag(idx, ISO_MARC_TAG + 7); |
|---|
| 683 | icodes[2] = ldrtag(idx, ISO_MARC_TAG + 8); |
|---|
| 684 | forusr[0] = ldrtag(idx, ISO_MARC_TAG + 17); |
|---|
| 685 | forusr[1] = ldrtag(idx, ISO_MARC_TAG + 18); |
|---|
| 686 | forusr[2] = ldrtag(idx, ISO_MARC_TAG + 19); |
|---|
| 687 | |
|---|
| 688 | p = buff; |
|---|
| 689 | |
|---|
| 690 | sprintf(p,"%05ld%c%c%c%c000%05ld%c%c%c%d%d00",total_record,status[0], |
|---|
| 691 | icodes[0],icodes[1],icodes[2], base_address, |
|---|
| 692 | forusr[0],forusr[1],forusr[2], |
|---|
| 693 | ISO_FLDLEN_LENGHT,ISO_FLDLOC_LENGHT); |
|---|
| 694 | |
|---|
| 695 | p += ISO_LEADER_LENGHT; |
|---|
| 696 | |
|---|
| 697 | /* ............................................................ directory */ |
|---|
| 698 | for (flddir = 0,location_offset = 0L; flddir < VMFRnvf(idx); flddir++) { |
|---|
| 699 | tag = VDIRtag(idx,flddir); |
|---|
| 700 | if (tag >= ISO_MARC_TAG) if (tag <= ISO_MARC_TAG+ISOHSIZE) continue; |
|---|
| 701 | if (tag == 1000) tag = 1; |
|---|
| 702 | if (tag > 999) tag = tag % 1000; |
|---|
| 703 | sprintf(p,"%-03.3u%04u%05lu",tag,VDIRlen(idx,flddir)+ISO_FLDSEP_LENGHT, |
|---|
| 704 | location_offset); |
|---|
| 705 | p += ISO_DIRECTORY_LENGHT; |
|---|
| 706 | location_offset += VDIRlen(idx,flddir) + ISO_FLDSEP_LENGHT; |
|---|
| 707 | } /* for */ |
|---|
| 708 | |
|---|
| 709 | /* .......................................................... data fields */ |
|---|
| 710 | *p++ = ISO_MARCFLDSEP; |
|---|
| 711 | for (flddir = 0; flddir < VMFRnvf(idx); flddir++) { |
|---|
| 712 | tag = VDIRtag(idx,flddir); |
|---|
| 713 | if (tag >= ISO_MARC_TAG) if (tag <= ISO_MARC_TAG+ISOHSIZE) continue; |
|---|
| 714 | memcpy(p,VFIELDP(idx,flddir),VDIRlen(idx,flddir)); |
|---|
| 715 | p += VDIRlen(idx,flddir); |
|---|
| 716 | *p++ = ISO_MARCFLDSEP; |
|---|
| 717 | } /* for */ |
|---|
| 718 | |
|---|
| 719 | /* ..................................................... record separator */ |
|---|
| 720 | *p++ = ISO_MARCRECSEP; |
|---|
| 721 | *p = '\0'; |
|---|
| 722 | |
|---|
| 723 | /* .......................................................... show buffer */ |
|---|
| 724 | fprintf(export_fp,"%s", buff); |
|---|
| 725 | |
|---|
| 726 | /* ......................................................... free buffers */ |
|---|
| 727 | efc_free(buff); |
|---|
| 728 | |
|---|
| 729 | return TRUE; |
|---|
| 730 | } |
|---|
| 731 | |
|---|
| 732 | /* ====================================================== eci_export_iso2709 */ |
|---|
| 733 | BOOLEAN eci_export_iso2709(FILE *export_fp, /* export file pointer */ |
|---|
| 734 | long idx, /* record index */ |
|---|
| 735 | BOOLEAN writeCR) /* force ASCII structure */ |
|---|
| 736 | { |
|---|
| 737 | char *buff; /* iso formed record buffer */ |
|---|
| 738 | char *p; /* auxiliary pointer */ |
|---|
| 739 | long total_dir; /* directory quantity of bytes */ |
|---|
| 740 | long base_address; /* base address quantity of bytes */ |
|---|
| 741 | long total_data; /* data quantity of bytes */ |
|---|
| 742 | long total_record; /* record quantity of bytes */ |
|---|
| 743 | long location_offset; /* location offset from the first data */ |
|---|
| 744 | int tag; /* field number */ |
|---|
| 745 | int flddir; /* field directory index */ |
|---|
| 746 | int skip_bytes; /* auxiliary print quantity of bytes */ |
|---|
| 747 | |
|---|
| 748 | /* .......................................... calculate quantity of bytes */ |
|---|
| 749 | total_dir = VMFRnvf(idx) * ISO_DIRECTORY_LENGHT; |
|---|
| 750 | base_address = ISO_LEADER_LENGHT + total_dir + ISO_FLDSEP_LENGHT; |
|---|
| 751 | for (flddir = 0,total_data = 0L; flddir < VMFRnvf(idx); flddir++) |
|---|
| 752 | total_data += VDIRlen(idx,flddir) + ISO_FLDSEP_LENGHT; |
|---|
| 753 | total_record = base_address + total_data + ISO_RECSEP_LENGHT; |
|---|
| 754 | |
|---|
| 755 | /* ................................................ allocate buffer space */ |
|---|
| 756 | buff = (char *)ALLOC((ALLOPARM)(total_record+1)); |
|---|
| 757 | if (!buff) return FALSE; |
|---|
| 758 | |
|---|
| 759 | /* ............................................................... leader */ |
|---|
| 760 | p = buff; |
|---|
| 761 | sprintf(p,"%05ld0000000%05ld000%d%d00",total_record,base_address, |
|---|
| 762 | ISO_FLDLEN_LENGHT,ISO_FLDLOC_LENGHT); |
|---|
| 763 | p += ISO_LEADER_LENGHT; |
|---|
| 764 | |
|---|
| 765 | /* ............................................................ directory */ |
|---|
| 766 | for (flddir = 0,location_offset = 0L; flddir < VMFRnvf(idx); flddir++) { |
|---|
| 767 | tag = VDIRtag(idx,flddir); |
|---|
| 768 | if (tag == 1000) tag = 1; |
|---|
| 769 | if (tag > 999) tag = tag % 1000; |
|---|
| 770 | sprintf(p,"%-03.3u%04u%05lu",tag,VDIRlen(idx,flddir)+ISO_FLDSEP_LENGHT, |
|---|
| 771 | location_offset); |
|---|
| 772 | p += ISO_DIRECTORY_LENGHT; |
|---|
| 773 | location_offset += VDIRlen(idx,flddir) + ISO_FLDSEP_LENGHT; |
|---|
| 774 | } /* for */ |
|---|
| 775 | |
|---|
| 776 | /* .......................................................... data fields */ |
|---|
| 777 | *p++ = ISO_FLDSEP; |
|---|
| 778 | for (flddir = 0; flddir < VMFRnvf(idx); flddir++) { |
|---|
| 779 | memcpy(p,VFIELDP(idx,flddir),VDIRlen(idx,flddir)); |
|---|
| 780 | p += VDIRlen(idx,flddir); |
|---|
| 781 | *p++ = ISO_FLDSEP; |
|---|
| 782 | } /* for */ |
|---|
| 783 | |
|---|
| 784 | /* ..................................................... record separator */ |
|---|
| 785 | *p++ = ISO_RECSEP; |
|---|
| 786 | *p = '\0'; |
|---|
| 787 | |
|---|
| 788 | /* .......................................................... show buffer */ |
|---|
| 789 | for (p = buff; *p; p += skip_bytes) { |
|---|
| 790 | skip_bytes = fprintf(export_fp,"%-.*s",ISO_LINE_LENGHT,p); |
|---|
| 791 | #if !PC |
|---|
| 792 | if (writeCR) fprintf(export_fp,"\r"); |
|---|
| 793 | #endif |
|---|
| 794 | fprintf(export_fp,"\n"); |
|---|
| 795 | } |
|---|
| 796 | |
|---|
| 797 | /* ......................................................... free buffers */ |
|---|
| 798 | efc_free(buff); |
|---|
| 799 | |
|---|
| 800 | return TRUE; |
|---|
| 801 | } |
|---|
| 802 | /* ======================================================== eci_export_hline */ |
|---|
| 803 | BOOLEAN eci_export_hline(FILE *export_fp, /* export file pointer */ |
|---|
| 804 | long idx) /* current record index */ |
|---|
| 805 | { |
|---|
| 806 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 807 | 1. Write MFN mark |
|---|
| 808 | 2. Loop all fields, write field number mark |
|---|
| 809 | 3. Loop all field characters, write characters, ended by a NEWLINE |
|---|
| 810 | 4. Write end of record mark |
|---|
| 811 | 5. Return no error |
|---|
| 812 | |
|---|
| 813 | 1.0 - 12.Nov.1998 |
|---|
| 814 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 815 | char *p; /* auxiliary string buffer pointer */ |
|---|
| 816 | int loop1; /* loop all fields */ |
|---|
| 817 | FFI loop2; /* loop all field characters */ |
|---|
| 818 | int xdir; /* field directory entry */ |
|---|
| 819 | |
|---|
| 820 | /* 1 */ |
|---|
| 821 | fprintf(export_fp,"!mfn=%ld!\n",VMFRmfn(idx)); |
|---|
| 822 | |
|---|
| 823 | /* 2 */ |
|---|
| 824 | for (xdir=0, loop1=VMFRnvf(idx); loop1--; xdir++) { |
|---|
| 825 | fprintf(export_fp,"H %d %d ",VDIRtag(idx,xdir),VDIRlen(idx,xdir)); |
|---|
| 826 | /* 3 */ |
|---|
| 827 | for (p=VFIELDP(idx,xdir), loop2=VDIRlen(idx,xdir); loop2--; p++) |
|---|
| 828 | fprintf(export_fp,"%c",*p); |
|---|
| 829 | fprintf(export_fp,"\n"); |
|---|
| 830 | } |
|---|
| 831 | |
|---|
| 832 | /* 4 */ |
|---|
| 833 | fprintf(export_fp,"!eor!\n"); |
|---|
| 834 | |
|---|
| 835 | /* 5 */ |
|---|
| 836 | return TRUE; |
|---|
| 837 | } |
|---|
| 838 | /* ======================================================== eci_export_vline */ |
|---|
| 839 | BOOLEAN eci_export_vline(FILE *export_fp, /* export file pointer */ |
|---|
| 840 | long idx) /* current record index */ |
|---|
| 841 | { |
|---|
| 842 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 843 | 1. Write MFN mark |
|---|
| 844 | 2. Loop all fields, write field number mark |
|---|
| 845 | 3. Loop all field characters, write characters, ended by a NEWLINE |
|---|
| 846 | 4. Write end of record mark |
|---|
| 847 | 5. Return no error |
|---|
| 848 | |
|---|
| 849 | 1.0 - 12.Nov.1998 |
|---|
| 850 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 851 | char *p; /* auxiliary string buffer pointer */ |
|---|
| 852 | int loop1; /* loop all fields */ |
|---|
| 853 | FFI loop2; /* loop all field characters */ |
|---|
| 854 | int xdir; /* field directory entry */ |
|---|
| 855 | |
|---|
| 856 | /* 1 */ |
|---|
| 857 | fprintf(export_fp,"!mfn=%ld!\n",VMFRmfn(idx)); |
|---|
| 858 | |
|---|
| 859 | /* 2 */ |
|---|
| 860 | for (xdir=0, loop1=VMFRnvf(idx); loop1--; xdir++) { |
|---|
| 861 | fprintf(export_fp,"!v%05u!",VDIRtag(idx,xdir)); |
|---|
| 862 | /* 3 */ |
|---|
| 863 | for (p=VFIELDP(idx,xdir), loop2=VDIRlen(idx,xdir); loop2--; p++) |
|---|
| 864 | fprintf(export_fp,"%c",*p); |
|---|
| 865 | fprintf(export_fp,"\n"); |
|---|
| 866 | } |
|---|
| 867 | |
|---|
| 868 | /* 4 */ |
|---|
| 869 | fprintf(export_fp,"!eor!\n"); |
|---|
| 870 | |
|---|
| 871 | /* 5 */ |
|---|
| 872 | return TRUE; |
|---|
| 873 | } |
|---|
| 874 | /* ------------------------------------------------------ eci_import_iso2709 */ |
|---|
| 875 | #define ISO_BASEADD_OFFSET 12 |
|---|
| 876 | #define ISO_FLDLEN_OFFSET 20 |
|---|
| 877 | #define ISO_FLDLOC_OFFSET 21 |
|---|
| 878 | |
|---|
| 879 | ECI_ERROR eci_import_iso2709_marc(EFC_ERROR *err, |
|---|
| 880 | FILE *import_fp, /* import file pointer */ |
|---|
| 881 | long idx, |
|---|
| 882 | char *buff) |
|---|
| 883 | { |
|---|
| 884 | char *line; /* line pointer */ |
|---|
| 885 | char *p; /* auxiliary string buffer pointer */ |
|---|
| 886 | char *fldupd; /* field update area string buffer pointer */ |
|---|
| 887 | long linesize; /* line size */ |
|---|
| 888 | long total_record; /* record quantity of bytes */ |
|---|
| 889 | long base_address; /* base address quantity of bytes */ |
|---|
| 890 | int fldlen; /* field lenght */ |
|---|
| 891 | int fldloc; /* field location */ |
|---|
| 892 | long qtt_read; /* quantity of bytes read */ |
|---|
| 893 | int tag; /* tag to be added */ |
|---|
| 894 | |
|---|
| 895 | char status[1]; /* Estado del registro */ |
|---|
| 896 | char icodes[4]; /* 0=Tipo de registro; 1=Nivel bibliogr�co; 2=Tipo de control; 3=unused */ |
|---|
| 897 | char forusr[3]; /* 0=Nivel de codificaci�1=Forma de catalogaci�2=Linked requirement */ |
|---|
| 898 | |
|---|
| 899 | /* ............................................................ read line */ |
|---|
| 900 | line = fgets(buff,MAXMFRL,import_fp); |
|---|
| 901 | if (!line) return ECI_ERROR_EOF; |
|---|
| 902 | |
|---|
| 903 | /* ......................................................... clear record */ |
|---|
| 904 | VRECrc(idx) = RCNORMAL; |
|---|
| 905 | VMFRstatus(idx) = ACTIVE; |
|---|
| 906 | VRECtype(idx) = TYPEMFR; |
|---|
| 907 | if (eci_field_D(err,idx,0)) return err->code; |
|---|
| 908 | |
|---|
| 909 | /* ............................................... get leader information */ |
|---|
| 910 | sscanf(line,"%05ld",&total_record); |
|---|
| 911 | if (total_record < ISO_BASEADD_OFFSET) return efc_error(err,ECI_ERROR_IMPORT,line); |
|---|
| 912 | |
|---|
| 913 | sscanf(line+5,"%c",&status); |
|---|
| 914 | |
|---|
| 915 | p = (char *)&icodes; |
|---|
| 916 | sscanf(line+6,"%c", p++); |
|---|
| 917 | sscanf(line+7,"%c", p++); |
|---|
| 918 | sscanf(line+8,"%c", p++); |
|---|
| 919 | sscanf(line+9,"%c", p++); |
|---|
| 920 | |
|---|
| 921 | sscanf(line+ISO_BASEADD_OFFSET,"%05ld",&base_address); |
|---|
| 922 | |
|---|
| 923 | p = (char *)&forusr; |
|---|
| 924 | sscanf(line+17,"%c", p++); |
|---|
| 925 | sscanf(line+18,"%c", p++); |
|---|
| 926 | sscanf(line+19,"%c", p); |
|---|
| 927 | |
|---|
| 928 | qtt_read = 0L; |
|---|
| 929 | |
|---|
| 930 | /* ............................................ loop for all record lines */ |
|---|
| 931 | while (line) { |
|---|
| 932 | |
|---|
| 933 | /* ............................................ get line with no CR/LF */ |
|---|
| 934 | linesize = strlen(line); |
|---|
| 935 | for (p = line+linesize-1; (*p == '\n' || *p == '\r') && linesize; p--,linesize--) |
|---|
| 936 | *p = '\0'; |
|---|
| 937 | |
|---|
| 938 | /* ............................................... check end of record */ |
|---|
| 939 | qtt_read += linesize; |
|---|
| 940 | if (qtt_read >= total_record) break; |
|---|
| 941 | line += linesize; |
|---|
| 942 | |
|---|
| 943 | /* ..................................................... get next line */ |
|---|
| 944 | line = fgets(line,MAXMFRL,import_fp); |
|---|
| 945 | if (!line) return efc_error(err,ECI_ERROR_IMPORT,buff); |
|---|
| 946 | |
|---|
| 947 | } /* while */ |
|---|
| 948 | |
|---|
| 949 | /* use the lasting buffer for field update */ |
|---|
| 950 | fldupd = p+2; |
|---|
| 951 | |
|---|
| 952 | /* ....................................... update marc fields */ |
|---|
| 953 | sprintf(fldupd,"H %d 1 %c", ISO_MARC_TAG + 5, status[0]); |
|---|
| 954 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 955 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 956 | |
|---|
| 957 | sprintf(fldupd,"H %d 1 %c", ISO_MARC_TAG + 6, icodes[0]); |
|---|
| 958 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 959 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 960 | |
|---|
| 961 | sprintf(fldupd,"H %d 1 %c", ISO_MARC_TAG + 7, icodes[1]); |
|---|
| 962 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 963 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 964 | |
|---|
| 965 | sprintf(fldupd,"H %d 1 %c", ISO_MARC_TAG + 8, icodes[2]); |
|---|
| 966 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 967 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 968 | |
|---|
| 969 | /* sprintf(fldupd,"H %d 1 %c", ISO_MARC_TAG + 9, icodes[3]); |
|---|
| 970 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 971 | efc_error(err,ECI_ERROR_IMPORT,NULL); */ |
|---|
| 972 | |
|---|
| 973 | sprintf(fldupd,"H %d 1 %c", ISO_MARC_TAG + 17, forusr[0]); |
|---|
| 974 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 975 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 976 | |
|---|
| 977 | sprintf(fldupd,"H %d 1 %c", ISO_MARC_TAG + 18, forusr[1]); |
|---|
| 978 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 979 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 980 | |
|---|
| 981 | sprintf(fldupd,"H %d 1 %c", ISO_MARC_TAG + 19, forusr[2]); |
|---|
| 982 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 983 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 984 | |
|---|
| 985 | /* use the lasting buffer for field update */ |
|---|
| 986 | fldupd = p+2; |
|---|
| 987 | |
|---|
| 988 | /* ....................................... loop for all directory entries */ |
|---|
| 989 | for (qtt_read = ISO_LEADER_LENGHT; qtt_read+1 < base_address; qtt_read += ISO_DIRECTORY_LENGHT) { |
|---|
| 990 | |
|---|
| 991 | /* ................................................... directory entry */ |
|---|
| 992 | p = buff + qtt_read; |
|---|
| 993 | sscanf(p,"%03d%04d%05d",&tag,&fldlen,&fldloc); |
|---|
| 994 | fldlen--; |
|---|
| 995 | |
|---|
| 996 | /* ................................................. field update data */ |
|---|
| 997 | sprintf(fldupd,"H %u %lu %-.*s",tag,fldlen,fldlen,buff+(base_address+fldloc)); |
|---|
| 998 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 999 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 1000 | |
|---|
| 1001 | } /* for */ |
|---|
| 1002 | |
|---|
| 1003 | /* ..................................................... return exit code */ |
|---|
| 1004 | return ECI_ERROR_OK; |
|---|
| 1005 | } |
|---|
| 1006 | |
|---|
| 1007 | /* ------------------------------------------------------- eci_import_iso2709 */ |
|---|
| 1008 | ECI_ERROR eci_import_iso2709(EFC_ERROR *err, |
|---|
| 1009 | FILE *import_fp, /* import file pointer */ |
|---|
| 1010 | long idx, |
|---|
| 1011 | char *buff) |
|---|
| 1012 | { |
|---|
| 1013 | char *line; /* line pointer */ |
|---|
| 1014 | char *p; /* auxiliary string buffer pointer */ |
|---|
| 1015 | char *fldupd; /* field update area string buffer pointer */ |
|---|
| 1016 | long linesize; /* line size */ |
|---|
| 1017 | long total_record; /* record quantity of bytes */ |
|---|
| 1018 | long base_address; /* base address quantity of bytes */ |
|---|
| 1019 | int fldlen; /* field lenght */ |
|---|
| 1020 | int fldloc; /* field location */ |
|---|
| 1021 | long qtt_read; /* quantity of bytes read */ |
|---|
| 1022 | int tag; /* tag to be added */ |
|---|
| 1023 | |
|---|
| 1024 | /* ............................................................ read line */ |
|---|
| 1025 | line = fgets(buff,MAXMFRL,import_fp); |
|---|
| 1026 | if (!line) return ECI_ERROR_EOF; |
|---|
| 1027 | |
|---|
| 1028 | /* ......................................................... clear record */ |
|---|
| 1029 | VRECrc(idx) = RCNORMAL; |
|---|
| 1030 | VMFRstatus(idx) = ACTIVE; |
|---|
| 1031 | VRECtype(idx) = TYPEMFR; |
|---|
| 1032 | if (eci_field_D(err,idx,0)) return err->code; |
|---|
| 1033 | |
|---|
| 1034 | /* ............................................... get leader information */ |
|---|
| 1035 | sscanf(line,"%05ld",&total_record); |
|---|
| 1036 | if (total_record < ISO_BASEADD_OFFSET) return efc_error(err,ECI_ERROR_IMPORT,line); |
|---|
| 1037 | sscanf(line+ISO_BASEADD_OFFSET,"%05ld",&base_address); |
|---|
| 1038 | qtt_read = 0L; |
|---|
| 1039 | |
|---|
| 1040 | /* ............................................ loop for all record lines */ |
|---|
| 1041 | while (line) { |
|---|
| 1042 | |
|---|
| 1043 | /* ............................................ get line with no CR/LF */ |
|---|
| 1044 | linesize = strlen(line); |
|---|
| 1045 | for (p = line+linesize-1; (*p == '\n' || *p == '\r') && linesize; p--,linesize--) |
|---|
| 1046 | *p = '\0'; |
|---|
| 1047 | |
|---|
| 1048 | /* ............................................... check end of record */ |
|---|
| 1049 | qtt_read += linesize; |
|---|
| 1050 | if (qtt_read >= total_record) break; |
|---|
| 1051 | line += linesize; |
|---|
| 1052 | |
|---|
| 1053 | /* ..................................................... get next line */ |
|---|
| 1054 | line = fgets(line,MAXMFRL,import_fp); |
|---|
| 1055 | if (!line) return efc_error(err,ECI_ERROR_IMPORT,buff); |
|---|
| 1056 | |
|---|
| 1057 | } /* while */ |
|---|
| 1058 | |
|---|
| 1059 | /* use the lasting buffer for field update */ |
|---|
| 1060 | fldupd = p+2; |
|---|
| 1061 | |
|---|
| 1062 | /* ....................................... loop for all directory entries */ |
|---|
| 1063 | for (qtt_read = ISO_LEADER_LENGHT; qtt_read+1 < base_address; qtt_read += ISO_DIRECTORY_LENGHT) { |
|---|
| 1064 | |
|---|
| 1065 | /* ................................................... directory entry */ |
|---|
| 1066 | p = buff + qtt_read; |
|---|
| 1067 | sscanf(p,"%03d%04d%05d",&tag,&fldlen,&fldloc); |
|---|
| 1068 | fldlen--; |
|---|
| 1069 | |
|---|
| 1070 | /* ................................................. field update data */ |
|---|
| 1071 | sprintf(fldupd,"H %u %lu %-.*s",tag,fldlen,fldlen,buff+(base_address+fldloc)); |
|---|
| 1072 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 1073 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 1074 | |
|---|
| 1075 | } /* for */ |
|---|
| 1076 | |
|---|
| 1077 | /* ..................................................... return exit code */ |
|---|
| 1078 | return ECI_ERROR_OK; |
|---|
| 1079 | } |
|---|
| 1080 | /* ------------------------------------------------------- eci_import_hvline */ |
|---|
| 1081 | ECI_ERROR eci_import_hvline(EFC_ERROR *err, |
|---|
| 1082 | FILE *import_fp, /* import file pointer */ |
|---|
| 1083 | long idx, |
|---|
| 1084 | char *buff) |
|---|
| 1085 | { |
|---|
| 1086 | char *line; /* line pointer */ |
|---|
| 1087 | char *p; /* auxiliary string buffer pointer */ |
|---|
| 1088 | char *fldupd; /* field update area string buffer pointer */ |
|---|
| 1089 | long linesize; /* line size */ |
|---|
| 1090 | long mfn; /* MFN */ |
|---|
| 1091 | int tag; /* tag to be added */ |
|---|
| 1092 | |
|---|
| 1093 | /* ......................................................... clear record */ |
|---|
| 1094 | VRECrc(idx) = RCNORMAL; |
|---|
| 1095 | VMFRstatus(idx) = ACTIVE; |
|---|
| 1096 | VRECtype(idx) = TYPEMFR; |
|---|
| 1097 | if (eci_field_D(err,idx,0)) return err->code; |
|---|
| 1098 | |
|---|
| 1099 | /* ............................................ loop for all record lines */ |
|---|
| 1100 | do { |
|---|
| 1101 | |
|---|
| 1102 | /* ............................................ get line with no CR/LF */ |
|---|
| 1103 | line = fgets(buff,MAXMFRL,import_fp); |
|---|
| 1104 | if (!line) return ECI_ERROR_EOF; |
|---|
| 1105 | |
|---|
| 1106 | linesize = strlen(line); |
|---|
| 1107 | for (p = line+linesize-1; (*p == '\n' || *p == '\r') && linesize; p--,linesize--) |
|---|
| 1108 | *p = '\0'; |
|---|
| 1109 | |
|---|
| 1110 | /* use the lasting buffer for field update */ |
|---|
| 1111 | fldupd = p+2; |
|---|
| 1112 | |
|---|
| 1113 | /* ............................................... check end of record */ |
|---|
| 1114 | if (strncmp(line,"!eor!",5) == 0) break; |
|---|
| 1115 | |
|---|
| 1116 | /* ................................................. get record number */ |
|---|
| 1117 | if (strncmp(line,"!mfn=",5) == 0) { |
|---|
| 1118 | mfn = atol(line+5); |
|---|
| 1119 | if (mfn < 1L) efc_error(err,ECI_ERROR_IMPORT,line); |
|---|
| 1120 | VMFRmfn(idx) = mfn; |
|---|
| 1121 | continue; |
|---|
| 1122 | } |
|---|
| 1123 | |
|---|
| 1124 | /* ........................................ get field data vline style */ |
|---|
| 1125 | if (strncmp(line,"!v",2) == 0) { |
|---|
| 1126 | |
|---|
| 1127 | /* ............................................... get field number */ |
|---|
| 1128 | line++; line++; linesize--; linesize--; |
|---|
| 1129 | tag = atoi(line); |
|---|
| 1130 | while (*line++ != '!') linesize--; |
|---|
| 1131 | |
|---|
| 1132 | /* .............................................. field update data */ |
|---|
| 1133 | sprintf(fldupd,"H %u %lu %s",tag,--linesize,line); |
|---|
| 1134 | if (eci_field_update(err,idx,fldupd)) |
|---|
| 1135 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 1136 | |
|---|
| 1137 | continue; |
|---|
| 1138 | } |
|---|
| 1139 | |
|---|
| 1140 | /* ............................................ field data Hline style */ |
|---|
| 1141 | if (strncmp(line,"H ",2) == 0) { |
|---|
| 1142 | if (eci_field_update(err,idx,line)) |
|---|
| 1143 | efc_error(err,ECI_ERROR_IMPORT,NULL); |
|---|
| 1144 | continue; |
|---|
| 1145 | } |
|---|
| 1146 | |
|---|
| 1147 | /* ................................................ invalid data found */ |
|---|
| 1148 | efc_error(err,ECI_ERROR_IMPORT,line); |
|---|
| 1149 | break; |
|---|
| 1150 | |
|---|
| 1151 | } while (line); |
|---|
| 1152 | |
|---|
| 1153 | /* ..................................................... return exit code */ |
|---|
| 1154 | return ECI_ERROR_OK; |
|---|
| 1155 | } |
|---|
| 1156 | /* -------------------------------------------------------- eci_import_rline */ |
|---|
| 1157 | ECI_ERROR eci_import_rline(EFC_ERROR *err, |
|---|
| 1158 | FILE *import_fp, /* import file pointer */ |
|---|
| 1159 | char delimiter, |
|---|
| 1160 | long idx, |
|---|
| 1161 | char *buff) |
|---|
| 1162 | { |
|---|
| 1163 | char *fmt = "H %06d %06ld"; |
|---|
| 1164 | int fmt_size = 16; |
|---|
| 1165 | char *line; /* line pointer */ |
|---|
| 1166 | char *text; /* text data pointer */ |
|---|
| 1167 | char *p; /* auxiliary string buffer pointer */ |
|---|
| 1168 | int tag; /* tag to be added */ |
|---|
| 1169 | long textSize; |
|---|
| 1170 | |
|---|
| 1171 | /* ......................................................... clear record */ |
|---|
| 1172 | VRECrc(idx) = RCNORMAL; |
|---|
| 1173 | VMFRstatus(idx) = ACTIVE; |
|---|
| 1174 | VRECtype(idx) = TYPEMFR; |
|---|
| 1175 | if (eci_field_D(err,idx,0)) return err->code; |
|---|
| 1176 | |
|---|
| 1177 | /* ............................................ get line with no CR/LF */ |
|---|
| 1178 | line = fgets(buff+fmt_size,MAXMFRL,import_fp); |
|---|
| 1179 | if (!line) return ECI_ERROR_EOF; |
|---|
| 1180 | |
|---|
| 1181 | for (p = text = line,textSize = 0L,tag = 0; *p; p++) { |
|---|
| 1182 | |
|---|
| 1183 | if (*p != delimiter && *p != '\n' && *p != '\r') { |
|---|
| 1184 | textSize++; |
|---|
| 1185 | continue; |
|---|
| 1186 | } |
|---|
| 1187 | |
|---|
| 1188 | tag++; |
|---|
| 1189 | |
|---|
| 1190 | if (textSize) { |
|---|
| 1191 | |
|---|
| 1192 | *p = '\0'; |
|---|
| 1193 | sprintf(text-fmt_size,fmt,tag,textSize); |
|---|
| 1194 | *(text-1) = ' '; |
|---|
| 1195 | |
|---|
| 1196 | if (eci_field_update(err,idx,text-fmt_size)) |
|---|
| 1197 | efc_error(err,ECI_ERROR_IMPORT,text-fmt_size); |
|---|
| 1198 | |
|---|
| 1199 | } |
|---|
| 1200 | |
|---|
| 1201 | text = p+1; |
|---|
| 1202 | textSize = 0; |
|---|
| 1203 | } |
|---|
| 1204 | |
|---|
| 1205 | /* ..................................................... return exit code */ |
|---|
| 1206 | return ECI_ERROR_OK; |
|---|
| 1207 | } |
|---|
| 1208 | /* ========================================================== eci_lock_netws */ |
|---|
| 1209 | void eci_lock_netws(long idx, /* record index */ |
|---|
| 1210 | char *db) /* database name */ |
|---|
| 1211 | { |
|---|
| 1212 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 1213 | 1. Set database structure |
|---|
| 1214 | 2. Set lock flags |
|---|
| 1215 | |
|---|
| 1216 | 1.0 - 08.Dec.1998 |
|---|
| 1217 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 1218 | |
|---|
| 1219 | /* 1 */ |
|---|
| 1220 | if (!VRECdbxp(idx)) VRECdbxp(idx) = dbxstorp(db); |
|---|
| 1221 | |
|---|
| 1222 | /* 2 */ |
|---|
| 1223 | #if MULTI |
|---|
| 1224 | VRDBnetws(idx) = FULLNETS; |
|---|
| 1225 | dbxewlrc = 1; |
|---|
| 1226 | dbxfloop = ECI_LOCK_RETRIES; |
|---|
| 1227 | dbxwloop = ECI_LOCK_RETRIES; |
|---|
| 1228 | dbxiloop = ECI_LOCK_RETRIES; |
|---|
| 1229 | dbxsleep = 0; |
|---|
| 1230 | #endif /* MULTI */ |
|---|
| 1231 | } |
|---|
| 1232 | /* ================================================================ eci_lock */ |
|---|
| 1233 | BOOLEAN eci_lock(long idx, /* record index */ |
|---|
| 1234 | char *db, /* database name */ |
|---|
| 1235 | long mfn, /* MFN */ |
|---|
| 1236 | int lock_type) /* lock type */ |
|---|
| 1237 | { |
|---|
| 1238 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 1239 | 1. Net work operation cisis status |
|---|
| 1240 | 2. Get record with lock flag |
|---|
| 1241 | 3. Restore normal flags |
|---|
| 1242 | 4. Get record |
|---|
| 1243 | 5, Return TRUE if it was locked, otherwise FALSE |
|---|
| 1244 | |
|---|
| 1245 | 1.0 - 08.Dec.1998 |
|---|
| 1246 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 1247 | |
|---|
| 1248 | /* 1 */ |
|---|
| 1249 | eci_lock_netws(idx,db); |
|---|
| 1250 | |
|---|
| 1251 | #if MULTI |
|---|
| 1252 | /* 2 */ |
|---|
| 1253 | VREClock(idx) = lock_type; |
|---|
| 1254 | record(idx,db,mfn); |
|---|
| 1255 | |
|---|
| 1256 | /* 3 */ |
|---|
| 1257 | VREClock(idx) = NOLOCK; |
|---|
| 1258 | if (lock_type == EWLOCK) VRDBnetws(idx) = MONONETS; |
|---|
| 1259 | #else /* !MULTI */ |
|---|
| 1260 | /* 4 */ |
|---|
| 1261 | record(idx,db,mfn); |
|---|
| 1262 | #endif /* MULTI */ |
|---|
| 1263 | |
|---|
| 1264 | /* 5 */ |
|---|
| 1265 | return (BOOLEAN)(VRECrc(idx) == RCLOCK); |
|---|
| 1266 | } |
|---|
| 1267 | /* ============================================================== eci_unlock */ |
|---|
| 1268 | ECI_ERROR eci_unlock(long idx, /* record index */ |
|---|
| 1269 | long mfn, /* MFN */ |
|---|
| 1270 | int lock_type) /* lock type */ |
|---|
| 1271 | { |
|---|
| 1272 | /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
|---|
| 1273 | 1. Net work operation cisis status |
|---|
| 1274 | 2. Restore locked flags |
|---|
| 1275 | 3. Unlock record |
|---|
| 1276 | 4. Return no error |
|---|
| 1277 | |
|---|
| 1278 | 1.0 - 08.Dec.1998 |
|---|
| 1279 | >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ |
|---|
| 1280 | |
|---|
| 1281 | /* 1 */ |
|---|
| 1282 | eci_lock_netws(idx,VRDBname(idx)); |
|---|
| 1283 | |
|---|
| 1284 | #if MULTI |
|---|
| 1285 | /* 2 */ |
|---|
| 1286 | if (mfn > 0L) { |
|---|
| 1287 | VRECgdbl(idx) = (FFI)0-VMFRmfrl(idx); |
|---|
| 1288 | VRECgdbw(idx) = (FFI)0-VMFRmfrl(idx); |
|---|
| 1289 | } |
|---|
| 1290 | |
|---|
| 1291 | /* 3 */ |
|---|
| 1292 | if (recunlck(idx,lock_type)) return ECI_ERROR_UNLOCK; |
|---|
| 1293 | #endif /* MULTI */ |
|---|
| 1294 | |
|---|
| 1295 | /* 4 */ |
|---|
| 1296 | return ECI_ERROR_OK; |
|---|
| 1297 | } |
|---|