2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.12 1995-11-24 11:31:37 adam
8 * Commands add & del read filenames from stdin if source directory is
10 * Match criteria supports 'constant' strings.
12 * Revision 1.11 1995/11/22 17:19:19 adam
13 * Record management uses the bfile system.
15 * Revision 1.10 1995/11/21 15:01:16 adam
16 * New general match criteria implemented.
17 * New feature: document groups.
19 * Revision 1.9 1995/11/21 09:20:32 adam
20 * Yet more work on record match.
22 * Revision 1.8 1995/11/20 16:59:46 adam
23 * New update method: the 'old' keys are saved for each records.
25 * Revision 1.7 1995/11/20 11:56:28 adam
26 * Work on new traversal.
28 * Revision 1.6 1995/11/17 15:54:42 adam
29 * Started work on virtual directory structure.
31 * Revision 1.5 1995/10/17 18:02:09 adam
32 * New feature: databases. Implemented as prefix to words in dictionary.
34 * Revision 1.4 1995/09/28 09:19:46 adam
35 * xfree/xmalloc used everywhere.
36 * Extract/retrieve method seems to work for text records.
38 * Revision 1.3 1995/09/06 16:11:18 adam
39 * Option: only one word key per file.
41 * Revision 1.2 1995/09/04 12:33:43 adam
42 * Various cleanup. YAZ util used instead.
44 * Revision 1.1 1995/09/01 14:06:36 adam
45 * Split of work into more files.
53 #include <sys/types.h>
60 static int repComp (const char *a, const char *b, size_t len)
64 return memcmp (a, b, len);
67 static void repositoryExtractR (int deleteFlag, char *rep,
68 struct recordGroup *rGroup)
72 size_t rep_len = strlen (rep);
77 if (rep[rep_len-1] != '/')
81 for (i=0; e[i].name; i++)
83 strcpy (rep +rep_len+1, e[i].name);
87 fileExtract (NULL, rep, rGroup, deleteFlag);
90 repositoryExtractR (deleteFlag, rep, rGroup);
98 static void stdinExtractR (int deleteFlag, struct recordGroup *rGroup)
102 while (scanf ("%s", tmppath) == 1)
103 fileExtract (NULL, tmppath, rGroup, deleteFlag);
106 static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst,
107 const char *base, char *src,
108 struct recordGroup *rGroup)
110 struct dir_entry *e_src;
112 static char tmppath[256];
113 size_t src_len = strlen (src);
115 sprintf (tmppath, "%s%s", base, src);
116 e_src = dir_open (tmppath);
119 if (!dst || repComp (dst->path, src, src_len))
121 if (!dst || strcmp (dst->path, src))
126 if (src_len && src[src_len-1] == '/')
130 src[src_len+1] = '\0';
131 dirs_mkdir (di, src, 0);
136 /* delete tree dst */
141 if (src_len && src[src_len-1] == '/')
145 src[src_len+1] = '\0';
146 dst = dirs_read (di);
154 if (dst && !repComp (dst->path, src, src_len+1))
156 if (e_src[i_src].name)
158 logf (LOG_DEBUG, "dst=%s src=%s", dst->path + src_len+1,
160 sd = strcmp (dst->path + src_len+1, e_src[i_src].name);
165 else if (e_src[i_src].name)
169 logf (LOG_DEBUG, "trav sd=%d", sd);
172 strcpy (src + src_len+1, e_src[i_src].name);
173 sprintf (tmppath, "%s%s", base, src);
175 switch (e_src[i_src].kind)
178 if (e_src[i_src].ctime > dst->ctime)
180 if (fileExtract (&dst->sysno, tmppath, rGroup, 0))
181 dirs_add (di, src, dst->sysno, e_src[i_src].ctime);
183 dst = dirs_read (di);
186 repositoryUpdateR (di, dst, base, src, rGroup);
187 dst = dirs_last (di);
188 logf (LOG_DEBUG, "last is %s", dst ? dst->path : "null");
191 dst = dirs_read (di);
198 strcpy (src + src_len+1, e_src[i_src].name);
199 sprintf (tmppath, "%s%s", base, src);
201 switch (e_src[i_src].kind)
204 if (fileExtract (&sysno, tmppath, rGroup, 0))
205 dirs_add (di, src, sysno, e_src[i_src].ctime);
208 repositoryUpdateR (di, dst, base, src, rGroup);
210 dst = dirs_last (di);
223 void repositoryUpdate (struct recordGroup *rGroup)
225 struct dirs_info *di;
229 dict = dict_open ("repdict", 40, 1);
231 assert (rGroup->path);
232 di = dirs_open (dict, rGroup->path);
234 repositoryUpdateR (di, dirs_read (di), rGroup->path, src, rGroup);
240 void repositoryDelete (struct recordGroup *rGroup)
244 assert (rGroup->path);
245 strcpy (src, rGroup->path);
247 stdinExtractR (1, rGroup);
249 repositoryExtractR (1, src, rGroup);
252 void repositoryAdd (struct recordGroup *rGroup)
256 assert (rGroup->path);
257 strcpy (src, rGroup->path);
259 stdinExtractR (0, rGroup);
261 repositoryExtractR (0, src, rGroup);