+struct scan_info {
+ struct scan_entry *list;
+ ODR odr;
+ int before, after;
+ ISAM isam;
+ char prefix[20];
+};
+
+static int scan_handle (Dict_char *name, const char *info, int pos,
+ void *client)
+{
+ int len_prefix, idx;
+ ISAM_P isam_p;
+ RSET rset;
+ struct scan_info *scan_info = client;
+
+ rset_isam_parms parms;
+
+ len_prefix = strlen(scan_info->prefix);
+ if (memcmp (name, scan_info->prefix, len_prefix))
+ return 1;
+ if (pos > 0)
+ idx = scan_info->after - pos + scan_info->before;
+ else
+ idx = - pos - 1;
+ scan_info->list[idx].term = odr_malloc (scan_info->odr,
+ strlen(name + len_prefix)+1);
+ strcpy (scan_info->list[idx].term, name + len_prefix);
+ assert (*info == sizeof(isam_p));
+ memcpy (&isam_p, info+1, sizeof(isam_p));
+ parms.is = scan_info->isam;
+ parms.pos = isam_p;
+#if 1
+ rset = rset_create (rset_kind_isam, &parms);
+ count_set (rset, &scan_info->list[idx].occurrences);
+ rset_delete (rset);
+#else
+ scan_info->list[idx].occurrences = 1;
+#endif
+ logf (LOG_DEBUG, "pos=%3d idx=%3d name=%s", pos, idx, name);
+ return 0;
+}
+
+int rpn_scan (ZServerInfo *zi, ODR odr, Z_AttributesPlusTerm *zapt,
+ int *position, int *num_entries, struct scan_entry **list,
+ int *status)
+{
+ int i, j, sizez;
+ int pos = *position;
+ int num = *num_entries;
+ int before;
+ int after;
+ char termz[IT_MAX_WORD+20];
+ AttrType use;
+ int use_value;
+ Z_Term *term = zapt->term;
+ struct scan_info scan_info;
+
+ logf (LOG_DEBUG, "scan, position = %d, num = %d", pos, num);
+ scan_info.before = before = pos-1;
+ scan_info.after = after = 1+num-pos;
+ scan_info.odr = odr;
+
+ logf (LOG_DEBUG, "scan, before = %d, after = %d", before, after);
+
+ scan_info.isam = zi->wordIsam;
+ scan_info.list = odr_malloc (odr, (before+after)*sizeof(*scan_info.list));
+ for (j = 0; j<before+after; j++)
+ scan_info.list[j].term = NULL;
+ attr_init (&use, zapt, 1);
+ use_value = attr_find (&use, NULL);
+ logf (LOG_DEBUG, "use value %d", use_value);
+
+ if (use_value == -1)
+ use_value = 1016;
+ i = index_word_prefix (termz, 1, use_value);
+ strcpy (scan_info.prefix, termz);
+ sizez = term->u.general->len;
+ if (sizez > IT_MAX_WORD)
+ sizez = IT_MAX_WORD;
+ for (j = 0; j<sizez; j++)
+ termz[j+i] = index_char_cvt (term->u.general->buf[j]);
+ termz[j+i] = '\0';
+
+ dict_scan (zi->wordDict, termz, &before, &after, &scan_info, scan_handle);
+
+ *status = BEND_SCAN_SUCCESS;
+
+ for (i = 0; i<scan_info.after; i++)
+ if (scan_info.list[scan_info.before+scan_info.after-i-1].term)
+ break;
+ *num_entries -= i;
+ if (i)
+ *status = BEND_SCAN_PARTIAL;
+
+ for (i = 0; i<scan_info.before; i++)
+ if (scan_info.list[i].term)
+ break;
+ if (i)
+ *status = BEND_SCAN_PARTIAL;
+ *position -= i;
+ *num_entries -= i;
+
+ *list = scan_info.list+i; /* list is set to first 'real' entry */
+
+ if (*num_entries == 0) /* signal 'unsupported use-attribute' */
+ zi->errCode = 114; /* if no entries was found */
+ logf (LOG_DEBUG, "position = %d, num_entries = %d",
+ *position, *num_entries);
+ if (zi->errCode)
+ logf (LOG_DEBUG, "scan error: %d", zi->errCode);
+ return 0;
+}
+
+
+