2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.10 1995-11-21 15:01:16 adam
8 * New general match criteria implemented.
9 * New feature: document groups.
11 * Revision 1.9 1995/11/21 09:20:32 adam
12 * Yet more work on record match.
14 * Revision 1.8 1995/11/20 16:59:46 adam
15 * New update method: the 'old' keys are saved for each records.
17 * Revision 1.7 1995/11/20 11:56:28 adam
18 * Work on new traversal.
20 * Revision 1.6 1995/11/17 15:54:42 adam
21 * Started work on virtual directory structure.
23 * Revision 1.5 1995/10/17 18:02:09 adam
24 * New feature: databases. Implemented as prefix to words in dictionary.
26 * Revision 1.4 1995/09/28 09:19:46 adam
27 * xfree/xmalloc used everywhere.
28 * Extract/retrieve method seems to work for text records.
30 * Revision 1.3 1995/09/06 16:11:18 adam
31 * Option: only one word key per file.
33 * Revision 1.2 1995/09/04 12:33:43 adam
34 * Various cleanup. YAZ util used instead.
36 * Revision 1.1 1995/09/01 14:06:36 adam
37 * Split of work into more files.
45 #include <sys/types.h>
52 static int repComp (const char *a, const char *b, size_t len)
56 return memcmp (a, b, len);
59 static void repositoryExtractR (char *rep, struct recordGroup *rGroup)
63 size_t rep_len = strlen (rep);
68 if (rep[rep_len-1] != '/')
72 for (i=0; e[i].name; i++)
74 strcpy (rep +rep_len+1, e[i].name);
78 fileExtract (NULL, rep, rGroup, 0);
81 repositoryExtractR (rep, rGroup);
89 static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst,
90 const char *base, char *src,
91 struct recordGroup *rGroup)
93 struct dir_entry *e_src;
95 static char tmppath[256];
96 size_t src_len = strlen (src);
98 sprintf (tmppath, "%s%s", base, src);
99 e_src = dir_open (tmppath);
102 if (!dst || repComp (dst->path, src, src_len))
104 if (!dst || strcmp (dst->path, src))
109 if (src_len && src[src_len-1] == '/')
113 src[src_len+1] = '\0';
114 dirs_mkdir (di, src, 0);
119 /* delete tree dst */
124 if (src_len && src[src_len-1] == '/')
128 src[src_len+1] = '\0';
129 dst = dirs_read (di);
137 if (dst && !repComp (dst->path, src, src_len+1))
139 if (e_src[i_src].name)
141 logf (LOG_DEBUG, "dst=%s src=%s", dst->path + src_len+1,
143 sd = strcmp (dst->path + src_len+1, e_src[i_src].name);
148 else if (e_src[i_src].name)
152 logf (LOG_DEBUG, "trav sd=%d", sd);
155 strcpy (src + src_len+1, e_src[i_src].name);
156 sprintf (tmppath, "%s%s", base, src);
158 switch (e_src[i_src].kind)
161 if (e_src[i_src].ctime > dst->ctime)
163 if (fileExtract (&dst->sysno, tmppath, rGroup, 0))
164 dirs_add (di, src, dst->sysno, e_src[i_src].ctime);
166 dst = dirs_read (di);
169 repositoryUpdateR (di, dst, base, src, rGroup);
170 dst = dirs_last (di);
171 logf (LOG_DEBUG, "last is %s", dst ? dst->path : "null");
174 dst = dirs_read (di);
181 strcpy (src + src_len+1, e_src[i_src].name);
182 sprintf (tmppath, "%s%s", base, src);
184 switch (e_src[i_src].kind)
187 if (fileExtract (&sysno, tmppath, rGroup, 0))
188 dirs_add (di, src, sysno, e_src[i_src].ctime);
191 repositoryUpdateR (di, dst, base, src, rGroup);
193 dst = dirs_last (di);
206 void repositoryUpdate (struct recordGroup *rGroup)
208 struct dirs_info *di;
212 dict = dict_open ("repdict", 40, 1);
214 assert (rGroup->path);
215 di = dirs_open (dict, rGroup->path);
217 repositoryUpdateR (di, dirs_read (di), rGroup->path, src, rGroup);
223 void repositoryExtract (struct recordGroup *rGroup)
227 assert (rGroup->path);
228 strcpy (src, rGroup->path);
229 repositoryExtractR (src, rGroup);