43 #include <yaz/snprintf.h>
80 WRBUF w = wrbuf_alloc();
81 for (i = 0; cstr[i]; i++)
83 if (cstr[i] <
' ' || cstr[i] > 126)
84 wrbuf_printf(w,
"\\%02X", cstr[i] & 0xff);
86 wrbuf_putc(w, cstr[i]);
101 yaz_log(YLOG_LOG,
"More than %d file log entries. Omitting rest",
127 const char *str,
int length);
151 const char **map = 0;
158 while (map && *map && **map == *
CHR_SPACE)
164 int first = i ? 0 : 1;
175 while (map && *map && **map != *
CHR_SPACE)
177 const char *cp = *map;
224 const char **map = 0;
225 const char *start = b;
226 const char *last = b;
236 while (map && *map && **map == *
CHR_SPACE)
250 start, last - start);
253 while (map && *map && **map != *
CHR_SPACE)
276 start, last - start);
287 const char *res_buf = 0;
290 const char *display_buf = 0;
291 size_t display_len = 0;
295 &display_buf, &display_len))
299 display_buf, display_len);
336 RecType rt,
void *recTypeClientData)
341 extractCtrl.
stream = stream;
353 extractCtrl.
handle = &info;
362 (*rt->
extract)(recTypeClientData, &extractCtrl);
367 const char *index_name,
368 const char **ws,
int ws_length)
374 for (i = 0; i<ws_length; i++)
398 seqno = key.
mem[key.
len-1];
400 if (key.
mem[0] == ch)
406 woff = seqno - startSeq;
407 if (woff >= 0 && woff < ws_length)
414 #define FILE_MATCH_BLANK "\t "
418 const char *fname,
const char *spec)
420 static char dstBuf[2048];
422 const char *s = spec;
433 char attset_str[64], attname_str[64];
439 for (i = 0; *s && *s !=
',' && *s !=
')' &&
441 if (i+1 <
sizeof(attset_str))
442 attset_str[i++] = *s;
443 attset_str[i] =
'\0';
448 strcpy(attname_str, attset_str);
453 for (i = 0; *s && *s !=
')' &&
455 if (i+1 <
sizeof(attname_str))
456 attname_str[i++] = *s;
457 attname_str[i] =
'\0';
461 yaz_log(YLOG_WARN,
"Missing ) in match criteria %s in group %s",
470 for (i = 0; i<32; i++)
475 yaz_log(YLOG_LOG,
"ws[%d] = %s", i, wrbuf_cstr(w));
481 for (i = 0; i<32; i++)
490 dst += strlen(ws[i]);
494 yaz_log(YLOG_WARN,
"Record didn't contain match"
495 " fields in (%s,%s)", attset_str, attname_str);
503 const char *spec_src = NULL;
504 const char *s1 = ++s;
509 if (spec_len >
sizeof(special)-1)
510 spec_len =
sizeof(special)-1;
511 memcpy(special, s, spec_len);
512 special[spec_len] =
'\0';
515 if (!strcmp(special,
"group"))
517 else if (!strcmp(special,
"database"))
519 else if (!strcmp(special,
"filename")) {
522 else if (!strcmp(special,
"type"))
528 strcpy(dst, spec_src);
529 dst += strlen(spec_src);
532 else if (*s ==
'\"' || *s ==
'\'')
534 int stopMarker = *s++;
538 while (*s && *s != stopMarker)
540 if (i+1 <
sizeof(tmpString))
541 tmpString[i++] = *s++;
546 strcpy(dst, tmpString);
547 dst += strlen(tmpString);
551 yaz_log(YLOG_WARN,
"Syntax error in match criteria %s in group %s",
559 yaz_log(YLOG_WARN,
"No match criteria for record %s in group %s",
568 yaz_log(YLOG_LOG,
"get_match_from_spec %s", wrbuf_cstr(w));
612 const char *recordType,
614 const char *match_criteria,
617 void *recTypeClientData);
628 const char *original_record_type = 0;
630 void *recTypeClientData;
638 sprintf(gprefix,
"%s.", zh->
m_group);
644 for (i = strlen(fname); --i >= 0; )
647 else if (fname[i] ==
'.')
649 strcpy(ext, fname+i+1);
656 sprintf(ext_res,
"%srecordType.%s", gprefix, ext);
664 yaz_log(YLOG_LOG,
"? %s", fname);
671 sprintf(ext_res,
"%srecordId.%s", gprefix, ext);
677 &recTypeClientData)))
679 yaz_log(YLOG_WARN,
"No such record type: %s", zh->
m_record_type);
688 yaz_log(YLOG_WARN,
"Bad filter version: %s", zh->
m_record_type);
698 if (zh->
path_reg && !yaz_is_abspath(fname))
701 strcat(full_rep,
"/");
702 strcat(full_rep, fname);
705 strcpy(full_rep, fname);
707 if ((fd = open(full_rep,
O_BINARY|O_RDONLY)) == -1)
709 yaz_log(YLOG_WARN|YLOG_ERRNO,
"open %s", full_rep);
722 recType, recTypeClientData);
737 const char *buf,
size_t buf_size,
739 const char *recordType,
741 const char *match_criteria,
749 if (recordType && *recordType)
752 "Record type explicitly specified: %s", recordType);
760 yaz_log(YLOG_WARN,
"No such record type defined");
772 yaz_log(YLOG_WARN,
"No such record type: %s", recordType);
784 recType, clientData);
792 const char *recordType,
794 const char *match_criteria,
797 void *recTypeClientData,
805 const char *matchStr = 0;
807 off_t start_offset = 0, end_offset = 0;
808 const char *pr_fname = fname;
815 pr_fname =
"<no file>";
829 off_t null_offset = 0;
832 start_offset = stream->
tellf(stream);
836 stream->
endf(stream, &null_offset);;
851 r = (*recType->
extract)(recTypeClientData, &extractCtrl);
855 action = extractCtrl.
action;
864 yaz_log(YLOG_WARN,
"extract error: generic");
868 yaz_log(YLOG_WARN,
"extract error: no such filter");
873 recordType, pr_fname, (
zint) start_offset);
876 end_offset = stream->
endf(stream, 0);
878 stream->
seekf(stream, end_offset);
884 yaz_log(YLOG_WARN,
"extract error: unknown error: %d", r);
887 end_offset = stream->
endf(stream, 0);
889 stream->
seekf(stream, end_offset);
891 end_offset = stream->
tellf(stream);
901 yaz_log(YLOG_LOG,
"test %s %s " ZINT_FORMAT, recordType,
902 pr_fname, (
zint) start_offset);
911 if (match_criteria && *match_criteria)
921 yaz_log(YLOG_LOG,
"error %s %s " ZINT_FORMAT, recordType,
922 pr_fname, (
zint) start_offset);
927 WRBUF w = wrbuf_alloc();
929 for (i = 0; i < strlen(matchStr); i++)
931 wrbuf_printf(w,
"%02X", matchStr[i] & 0xff);
933 yaz_log(YLOG_LOG,
"Got match %s", wrbuf_cstr(w));
953 assert(*rinfo ==
sizeof(*sysno));
954 memcpy(sysno, rinfo+1,
sizeof(*sysno));
964 yaz_log(YLOG_LOG,
"delete %s %s " ZINT_FORMAT, recordType,
965 pr_fname, (
zint) start_offset);
966 yaz_log(YLOG_WARN,
"cannot delete record above (seems new)");
972 yaz_log(YLOG_LOG,
"adelete %s %s " ZINT_FORMAT, recordType,
973 pr_fname, (
zint) start_offset);
978 yaz_log(YLOG_LOG,
"update %s %s " ZINT_FORMAT, recordType,
979 pr_fname, (
zint) start_offset);
980 yaz_log(YLOG_WARN,
"cannot update record above (seems new)");
984 yaz_log(YLOG_LOG,
"add %s %s " ZINT_FORMAT, recordType, pr_fname,
985 (
zint) start_offset);
1002 yaz_log(YLOG_WARN,
"Negative staticrank for record. Set to 0");
1010 sizeof(*sysno), sysno);
1019 extract_flush_record_keys(zh, *sysno, 1, zh->
reg->
keys,
1033 recordType, pr_fname, (
zint) start_offset);
1065 extract_flush_record_keys(zh, *sysno, 0, delkeys,
1077 yaz_log(YLOG_LOG,
"delete %s %s " ZINT_FORMAT, recordType,
1078 pr_fname, (
zint) start_offset);
1079 yaz_log(YLOG_WARN,
"cannot delete file above, "
1080 "storeKeys false (3)");
1085 yaz_log(YLOG_LOG,
"delete %s %s " ZINT_FORMAT, recordType,
1086 pr_fname, (
zint) start_offset);
1104 yaz_log(YLOG_LOG,
"update %s %s " ZINT_FORMAT, recordType,
1105 pr_fname, (
zint) start_offset);
1113 extract_flush_record_keys(zh, *sysno, 1,
1154 recordAttr->
recordSize = end_offset - start_offset;
1176 off_t cur_offset = stream->
tellf(stream);
1181 stream->
seekf(stream, start_offset);
1184 stream->
seekf(stream, cur_offset);
1220 const char *recordType,
1225 void *recTypeClientData)
1237 recType, recTypeClientData, &more);
1299 zh->
reg->
keys, 0, delkeys, 0);
1301 extract_flush_record_keys(zh, rec->
sysno, 0, delkeys, 0);
1302 extract_flush_record_keys(zh, rec->
sysno, 1, zh->
reg->
keys, 0);
1318 extract_flush_record_keys(zh, rec->
sysno, 1, zh->
reg->
keys, 0);
1336 const char *str,
size_t slen, NMEM nmem,
int level)
1341 const char *index_type;
1343 const char *string_index;
1351 for (i = 0; i < key->
len; i++)
1361 strcpy(dst_buf ,
"?");
1363 if (!strcmp(str,
""))
1364 strcpy(dst_buf,
"alwaysmatches");
1366 strcpy(dst_buf,
"firstinfield");
1368 strcpy(dst_buf,
"unknown");
1370 strcpy(dst_buf,
"space");
1372 for (i = 0; i<slen; i++)
1374 sprintf(dst_buf + strlen(dst_buf),
" %d", str[i] & 0xff);
1376 yaz_log(level,
"%s%s %s %s", keystr, index_type,
1377 string_index, dst_buf);
1381 yaz_log(level,
"%s%s %s \"%s\"", keystr, index_type,
1382 string_index, dst_term);
1394 NMEM nmem = nmem_create();
1412 struct ord_stat *next;
1426 for (p = ord_list; p ; p = p->next)
1434 p = xmalloc(
sizeof(*p));
1445 struct ord_stat *p1 = p;
1469 int mem = 1024*1024 * atoi(
res_get_def( zh->
res,
"memmax",
"8"));
1470 const char *key_tmp_dir =
res_get_def(zh->
res,
"keyTmpDir",
".");
1493 const char *del_str;
1494 struct it_key del_key_in;
1498 const char *ins_str;
1499 struct it_key ins_key_in;
1509 if (del && ins && ins_rank == del_rank
1511 && ins_slen == del_slen && !memcmp(del_str, ins_str, del_slen))
1522 &del_key_in, 0, del_str, del_slen,
1526 &ins_key_in, 1, ins_str, ins_slen,
1532 static void extract_flush_record_keys(
1544 sysno, cmd ?
"insert" :
"delete");
1551 const char *key_tmp_dir =
res_get_def(zh->
res,
"keyTmpDir",
".");
1558 yaz_log(YLOG_LOG,
"sysno=" ZINT_FORMAT " cmd=%d", sysno, cmd);
1569 &key_in, cmd, str, slen,
1580 NMEM nmem = nmem_create();
1591 const char *index_type;
1594 seqno = key.
mem[key.
len-1];
1612 yaz_log(YLOG_LOG,
"print_rec_keys");
1622 const char *index_type;
1629 seqno = key.
mem[key.
len-1];
1634 " term=%s", ord, seqno, dst_buf);
1640 const char *str,
int length)
1656 if (zh->m_segment_indexing)
1684 const char *str,
int length)
1689 if (length >
sizeof(valz)-1)
1690 length =
sizeof(valz)-1;
1692 memcpy(valz, str, length);
1693 valz[length] =
'\0';
1698 const char *
string,
int length)
1707 WRBUF w = wrbuf_alloc();
1709 wrbuf_write_escaped(w,
string, length);
1720 memcpy(&word, p,
sizeof(word));
1742 const char **map = 0;
1753 while (map && *map && **map == *
CHR_SPACE)
1764 while (map && *map && **map != *
CHR_SPACE)
1766 const char *cp = *map;
1806 const char *res_buf = 0;
1814 yaz_log(YLOG_LOG,
"Truncating long term %ld", (
long) res_len);
1864 void *buf,
size_t sz)
1898 yaz_log(YLOG_LOG,
"extract_flush_sort_keys cmd=%d sysno=" ZINT_FORMAT,
1910 NMEM nmem = nmem_create();
1911 struct sort_add_ent {
1914 struct sort_add_ent *next;
1919 struct sort_add_ent *sort_ent_list = 0;
1924 zint filter_sysno = key_in.
mem[1];
1925 zint section_id = key_in.
mem[2];
1927 struct sort_add_ent **e = &sort_ent_list;
1928 for (; *e; e = &(*e)->next)
1929 if ((*e)->ord == ord && section_id == (*e)->section_id)
1933 *e = nmem_malloc(nmem,
sizeof(**e));
1935 (*e)->wrbuf = wrbuf_alloc();
1938 (*e)->sysno = filter_sysno ? filter_sysno : sysno;
1939 (*e)->section_id = section_id;
1942 wrbuf_write((*e)->wrbuf, str, slen);
1943 wrbuf_putc((*e)->wrbuf,
'\0');
1947 zint last_sysno = 0;
1948 struct sort_add_ent *e = sort_ent_list;
1949 for (; e; e = e->next)
1951 if (last_sysno != e->sysno)
1954 last_sysno = e->sysno;
1961 wrbuf_destroy(e->wrbuf);