[srvx-commits] CVS: services/src checkdb.c,1.4,1.5
Brought to you by:
entrope
|
From: Adrian D. <sai...@us...> - 2002-07-08 01:36:42
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv7791
Modified Files:
checkdb.c
Log Message:
Make checkdb able to write out a copy of the db after checking it (good for reformatting old databases, and testing of recdb.c)
Index: checkdb.c
===================================================================
RCS file: /cvsroot/srvx/services/src/checkdb.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** checkdb.c 6 May 2002 23:33:13 -0000 1.4
--- checkdb.c 8 Jul 2002 01:36:09 -0000 1.5
***************
*** 2,5 ****
--- 2,6 ----
#include <stdarg.h>
#include <stdio.h>
+ #include <errno.h>
#include "log.h"
#include "recdb.h"
***************
*** 38,49 ****
{
dict_t db;
! if (argc < 2) {
! fprintf(stderr, "%s usage: %s <dbfile>\n", argv[0], argv[0]);
! return 1;
}
! if (!(db = parse_database(argv[1]))) return 2;
if (dict_foreach(db, check_record, 0)) return 3;
! if (!bad) fprintf(stdout, "Database checked okay.\n");
return 0;
}
--- 39,83 ----
{
dict_t db;
+ char *infile;
! if (argc < 2 || argc > 3) {
! fprintf(stderr, "%s usage: %s <dbfile> [outputfile]\n\n", argv[0], argv[0]);
! fprintf(stderr, "If [outputfile] is specified, dbfile is rewritten into outputfile after being\nparsed.\n\n");
! fprintf(stderr, "<dbfile> and/or [outputfile] may be given as '-' to use stdin and stdout,\nrespectively.\n");
! return 1;
! }
!
! if (!strcmp(argv[1], "-")) {
! infile = "/dev/stdin";
! } else {
! infile = argv[1];
}
! if (!(db = parse_database(infile))) return 2;
! fprintf(stdout, "Database read okay.\n");
! fflush(stdout);
if (dict_foreach(db, check_record, 0)) return 3;
! if (!bad) {
! fprintf(stdout, "Database checked okay.\n");
! fflush(stdout);
! }
!
! if (argc == 3) {
! FILE *f;
!
! if (!strcmp(argv[2], "-")) {
! f = stdout;
! } else {
! if (!(f = fopen(argv[2], "w"))) {
! fprintf(stderr, "fopen: %s\n", strerror(errno));
! return 4;
! }
! }
!
! write_database(f, db);
! fclose(f);
! fprintf(stdout, "Database written okay.\n");
! fflush(stdout);
! }
!
return 0;
}
|