From: Adam Dickmeiss Date: Thu, 30 Nov 1995 08:34:27 +0000 (+0000) Subject: Started work on commit facility. X-Git-Tag: ZEBRA.1.0~642 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=e80772c51b80b8e5c9c3cfb037c988308a4014b9;p=idzebra-moved-to-github.git Started work on commit facility. Changed a few malloc/free to xmalloc/xfree. --- diff --git a/index/dirs.c b/index/dirs.c index 2e69cf8..f0a5687 100644 --- a/index/dirs.c +++ b/index/dirs.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dirs.c,v $ - * Revision 1.3 1995-11-20 16:59:45 adam + * Revision 1.4 1995-11-30 08:34:27 adam + * Started work on commit facility. + * Changed a few malloc/free to xmalloc/xfree. + * + * Revision 1.3 1995/11/20 16:59:45 adam * New update method: the 'old' keys are saved for each records. * * Revision 1.2 1995/11/20 11:56:23 adam @@ -77,22 +81,14 @@ struct dirs_info *dirs_open (Dict dict, const char *rep) int before = 0, after; logf (LOG_DEBUG, "dirs_open %s", rep); - if (!(p = malloc (sizeof (*p)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p = xmalloc (sizeof (*p)); p->dict = dict; strcpy (p->prefix, rep); p->prelen = strlen(p->prefix); strcpy (p->nextpath, rep); p->no_read = p->no_cur = 0; after = p->no_max = 400; - if (!(p->entries = malloc (sizeof(*p->entries) * (p->no_max)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p->entries = xmalloc (sizeof(*p->entries) * (p->no_max)); logf (LOG_DEBUG, "dirs_open first scan"); dict_scan (p->dict, p->nextpath, &before, &after, p, dirs_client_proc); return p; @@ -171,8 +167,8 @@ void dirs_free (struct dirs_info **pp) { struct dirs_info *p = *pp; - free (p->entries); - free (p); + xfree (p->entries); + xfree (p); *pp = NULL; } diff --git a/index/extract.c b/index/extract.c index d3a357d..23ba68e 100644 --- a/index/extract.c +++ b/index/extract.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: extract.c,v $ - * Revision 1.35 1995-11-28 14:26:21 adam + * Revision 1.36 1995-11-30 08:34:29 adam + * Started work on commit facility. + * Changed a few malloc/free to xmalloc/xfree. + * + * Revision 1.35 1995/11/28 14:26:21 adam * Bug fix: recordId with constant wasn't right. * Bug fix: recordId dictionary entry wasn't deleted when needed. * @@ -315,10 +319,10 @@ static void addRecordKey (const RecWord *p) { char *b; - b = malloc (reckeys.buf_max += 65000); + b = xmalloc (reckeys.buf_max += 65000); if (reckeys.buf_used > 0) memcpy (b, reckeys.buf, reckeys.buf_used); - free (reckeys.buf); + xfree (reckeys.buf); reckeys.buf = b; } dst = reckeys.buf + reckeys.buf_used; @@ -786,18 +790,18 @@ static int recordExtract (SYSNO *sysno, const char *fname, } } } - free (rec->info[recInfo_fileType]); + xfree (rec->info[recInfo_fileType]); rec->info[recInfo_fileType] = rec_strdup (rGroup->recordType, &rec->size[recInfo_fileType]); - free (rec->info[recInfo_filename]); + xfree (rec->info[recInfo_filename]); rec->info[recInfo_filename] = rec_strdup (fname, &rec->size[recInfo_filename]); - free (rec->info[recInfo_delKeys]); + xfree (rec->info[recInfo_delKeys]); if (reckeys.buf_used > 0 && rGroup->flagStoreKeys == 1) { - rec->info[recInfo_delKeys] = malloc (reckeys.buf_used); + rec->info[recInfo_delKeys] = xmalloc (reckeys.buf_used); rec->size[recInfo_delKeys] = reckeys.buf_used; memcpy (rec->info[recInfo_delKeys], reckeys.buf, rec->size[recInfo_delKeys]); @@ -808,11 +812,11 @@ static int recordExtract (SYSNO *sysno, const char *fname, rec->size[recInfo_delKeys] = 0; } - free (rec->info[recInfo_storeData]); + xfree (rec->info[recInfo_storeData]); if (rGroup->flagStoreData == 1) { rec->size[recInfo_storeData] = file_noread; - rec->info[recInfo_storeData] = malloc (file_noread); + rec->info[recInfo_storeData] = xmalloc (file_noread); if (file_noread < FILE_READ_BUFSIZE) memcpy (rec->info[recInfo_storeData], file_buf, file_noread); else @@ -836,7 +840,7 @@ static int recordExtract (SYSNO *sysno, const char *fname, rec->info[recInfo_storeData] = NULL; rec->size[recInfo_storeData] = 0; } - free (rec->info[recInfo_databaseName]); + xfree (rec->info[recInfo_databaseName]); rec->info[recInfo_databaseName] = rec_strdup (rGroup->databaseName, &rec->size[recInfo_databaseName]); diff --git a/index/main.c b/index/main.c index 140ef98..5ff01a4 100644 --- a/index/main.c +++ b/index/main.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: main.c,v $ - * Revision 1.22 1995-11-28 09:09:42 adam + * Revision 1.23 1995-11-30 08:34:31 adam + * Started work on commit facility. + * Changed a few malloc/free to xmalloc/xfree. + * + * Revision 1.22 1995/11/28 09:09:42 adam * Zebra config renamed. * Use setting 'recordId' to identify record now. * Bug fix in recindex.c: rec_release_blocks was invokeded even @@ -113,11 +117,21 @@ int main (int argc, char **argv) prog = *argv; if (argc < 2) { - fprintf (stderr, "index [-v log] [-m meg] [-c config] [-d base]" - " [-g group] [update|del dir] ...\n"); + fprintf (stderr, "zebraidx [options] command ...\n" + "Commands:\n" + " update Update index with files below .\n" + " If is empty filenames are read from stdin.\n" + " delete Delete index with files below .\n" + "Options:\n" + " -t Index files as (grs or text).\n" + " -c Read configuration file .\n" + " -g Index files according to group settings.\n" + " -d Records belong to Z39.50 database .\n" + " -m Use before flushing keys to disk.\n" + " -v Set logging to .\n"); exit (1); } - while ((ret = options ("t:c:g:v:m:d:", argv, argc, &arg)) != -2) + while ((ret = options ("t:c:g:d:m:v:l:", argv, argc, &arg)) != -2) { if (ret == 0) { @@ -184,6 +198,8 @@ int main (int argc, char **argv) configName = arg; else if (ret == 't') rGroupDef.recordType = arg; + else if (ret == 'l') + bf_cache (arg); else { logf (LOG_FATAL, "Unknown option '-%s'", arg); diff --git a/index/recindex.c b/index/recindex.c index 3bffe6b..90efa63 100644 --- a/index/recindex.c +++ b/index/recindex.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: recindex.c,v $ - * Revision 1.8 1995-11-28 14:26:21 adam + * Revision 1.9 1995-11-30 08:34:33 adam + * Started work on commit facility. + * Changed a few malloc/free to xmalloc/xfree. + * + * Revision 1.8 1995/11/28 14:26:21 adam * Bug fix: recordId with constant wasn't right. * Bug fix: recordId dictionary entry wasn't deleted when needed. * @@ -127,14 +131,9 @@ static void rec_tmp_expand (Records p, int size, int dst_type) if (p->tmp_size < size + 256 || p->tmp_size < p->head.block_size[dst_type]*2) { - free (p->tmp_buf); - p->tmp_size = size + p->head.block_size[dst_type]*2 + - 256; - if (!(p->tmp_buf = malloc (p->tmp_size))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + xfree (p->tmp_buf); + p->tmp_size = size + p->head.block_size[dst_type]*2 + 256; + p->tmp_buf = xmalloc (p->tmp_size); } } @@ -290,19 +289,10 @@ Records rec_open (int rw) Records p; int i, r; - if (!(p = malloc (sizeof(*p)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p = xmalloc (sizeof(*p)); p->rw = rw; p->tmp_size = 1024; - p->tmp_buf = malloc (p->tmp_size); - if (!p->tmp_buf) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p->tmp_buf = xmalloc (p->tmp_size); p->index_fname = "recindex"; p->index_BFile = bf_open (p->index_fname, 128, rw); if (p->index_BFile == NULL) @@ -347,7 +337,7 @@ Records rec_open (int rw) { char str[80]; sprintf (str, "recdata%c", i + 'A'); - p->data_fname[i] = malloc (strlen(str)+1); + p->data_fname[i] = xmalloc (strlen(str)+1); strcpy (p->data_fname[i], str); p->data_BFile[i] = NULL; } @@ -363,11 +353,7 @@ Records rec_open (int rw) } p->cache_max = 10; p->cache_cur = 0; - if (!(p->record_cache = malloc (sizeof(*p->record_cache)*p->cache_max))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p->record_cache = xmalloc (sizeof(*p->record_cache)*p->cache_max); return p; } @@ -434,7 +420,7 @@ void rec_close (Records *pp) assert (p); rec_cache_flush (p); - free (p->record_cache); + xfree (p->record_cache); if (p->rw) rec_write_head (p); @@ -446,10 +432,10 @@ void rec_close (Records *pp) { if (p->data_BFile[i]) bf_close (p->data_BFile[i]); - free (p->data_fname[i]); + xfree (p->data_fname[i]); } - free (p->tmp_buf); - free (p); + xfree (p->tmp_buf); + xfree (p); *pp = NULL; } @@ -476,11 +462,7 @@ Record rec_get (Records p, int sysno) assert (freeblock > 0); - if (!(rec = malloc (sizeof(*rec)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + rec = xmalloc (sizeof(*rec)); rec_tmp_expand (p, entry.u.used.size, dst_type); cptr = p->tmp_buf; @@ -507,7 +489,7 @@ Record rec_get (Records p, int sysno) nptr += sizeof(*rec->size); if (rec->size[i]) { - rec->info[i] = malloc (rec->size[i]); + rec->info[i] = xmalloc (rec->size[i]); memcpy (rec->info[i], nptr, rec->size[i]); nptr += rec->size[i]; } @@ -524,11 +506,7 @@ Record rec_new (Records p) Record rec; assert (p); - if (!(rec = malloc (sizeof(*rec)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + rec = xmalloc (sizeof(*rec)); if (p->head.index_free == 0) sysno = (p->head.index_last)++; else @@ -588,8 +566,8 @@ void rec_rm (Record *recpp) { int i; for (i = 0; i < REC_NO_INFO; i++) - free ((*recpp)->info[i]); - free (*recpp); + xfree ((*recpp)->info[i]); + xfree (*recpp); *recpp = NULL; } @@ -598,11 +576,7 @@ Record rec_cp (Record rec) Record n; int i; - if (!(n = malloc (sizeof(*n)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + n = xmalloc (sizeof(*n)); n->sysno = rec->sysno; for (i = 0; i < REC_NO_INFO; i++) if (!rec->info[i]) @@ -613,11 +587,7 @@ Record rec_cp (Record rec) else { n->size[i] = rec->size[i]; - if (!(n->info[i] = malloc (rec->size[i]))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc. rec_cp"); - exit (1); - } + n->info[i] = xmalloc (rec->size[i]); memcpy (n->info[i], rec->info[i], rec->size[i]); } return n; @@ -698,11 +668,7 @@ Records rec_open (int rw) Records p; int r; - if (!(p = malloc (sizeof(*p)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p = xmalloc (sizeof(*p)); p->rw = rw; p->tmp_buf = NULL; p->tmp_size = 0; @@ -754,11 +720,7 @@ Records rec_open (int rw) } p->cache_max = 10; p->cache_cur = 0; - if (!(p->record_cache = malloc (sizeof(*p->record_cache)*p->cache_max))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p->record_cache = xmalloc (sizeof(*p->record_cache)*p->cache_max)); return p; } @@ -829,13 +791,9 @@ static void rec_write_single (Records p, Record rec) } if (p->tmp_size < entry.u.used.size) { - free (p->tmp_buf); + xfree (p->tmp_buf); p->tmp_size = entry.u.used.size + 16384; - if (!(p->tmp_buf = malloc (p->tmp_size))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p->tmp_buf = xmalloc (p->tmp_size)); } cptr = p->tmp_buf; for (i = 0; i < REC_NO_INFO; i++) @@ -906,7 +864,7 @@ void rec_close (Records *p) assert (*p); rec_cache_flush (*p); - free ((*p)->record_cache); + xfree ((*p)->record_cache); if ((*p)->rw) rec_write_head (*p); @@ -917,9 +875,9 @@ void rec_close (Records *p) if ((*p)->data_fd != -1) close ((*p)->data_fd); - free ((*p)->tmp_buf); + xfree ((*p)->tmp_buf); - free (*p); + xfree (*p); *p = NULL; } @@ -939,11 +897,7 @@ Record rec_get (Records p, int sysno) read_indx (p, sysno, &entry, sizeof(entry)); - if (!(rec = malloc (sizeof(*rec)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + rec = xmalloc (sizeof(*rec)); if (lseek (p->data_fd, entry.u.used.offset, SEEK_SET) == -1) { logf (LOG_FATAL|LOG_ERRNO, "lseek in %s to pos %ld", @@ -952,13 +906,9 @@ Record rec_get (Records p, int sysno) } if (p->tmp_size < entry.u.used.size) { - free (p->tmp_buf); + xfree (p->tmp_buf); p->tmp_size = entry.u.used.size + 16384; - if (!(p->tmp_buf = malloc (p->tmp_size))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p->tmp_buf = xmalloc (p->tmp_size)); } for (got = 0; got < entry.u.used.size; got += r) { @@ -978,7 +928,7 @@ Record rec_get (Records p, int sysno) nptr += sizeof(*rec->size); if (rec->size[i]) { - rec->info[i] = malloc (rec->size[i]); + rec->info[i] = xmalloc (rec->size[i]); memcpy (rec->info[i], nptr, rec->size[i]); nptr += rec->size[i]; } @@ -995,11 +945,7 @@ Record rec_new (Records p) Record rec; assert (p); - if (!(rec = malloc (sizeof(*rec)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + rec = xmalloc (sizeof(*rec)); if (p->head.index_free == 0) sysno = (p->head.index_last)++; else @@ -1042,8 +988,8 @@ void rec_rm (Record *recpp) { int i; for (i = 0; i < REC_NO_INFO; i++) - free ((*recpp)->info[i]); - free (*recpp); + xfree ((*recpp)->info[i]); + xfree (*recpp); *recpp = NULL; } @@ -1052,11 +998,7 @@ Record rec_cp (Record rec) Record n; int i; - if (!(n = malloc (sizeof(*n)))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + n = xmalloc (sizeof(*n)); n->sysno = rec->sysno; for (i = 0; i < REC_NO_INFO; i++) if (!rec->info[i]) @@ -1067,11 +1009,7 @@ Record rec_cp (Record rec) else { n->size[i] = rec->size[i]; - if (!(n->info[i] = malloc (rec->size[i]))) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc. rec_cp"); - exit (1); - } + n->info[i] = xmalloc (rec->size[i]); memcpy (n->info[i], rec->info[i], rec->size[i]); } return n; @@ -1095,12 +1033,7 @@ char *rec_strdup (const char *s, size_t *len) return NULL; } *len = strlen(s)+1; - p = malloc (*len); - if (!p) - { - logf (LOG_FATAL|LOG_ERRNO, "malloc"); - exit (1); - } + p = xmalloc (*len); strcpy (p, s); return p; }