Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
XCOMM $XConsortium: Imakefile /main/14 1996/05/08 09:27:35 drk $
#define CplusplusSource YES
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
EXTRA_LOAD_FLAGS = ExtraLoadFlags $(UNSHARED_CXXLIB)
#include <Threads.tmpl>
#include "../../tooltalk.tmpl"
DEFINES =
INCLUDES = -I. -I../../slib -I../../lib -I../../mini_isam
DEPLIBS = ../../slib/libstt.a TtClientDepLibs ../../mini_isam/libisam.a
LOCAL_LIBRARIES = ../../slib/libstt.a TtClientLibs ../../mini_isam/libisam.a
SYS_LIBRARIES =
#ifdef TtClientExtraLibs
EXTRA_LIBRARIES = TtClientExtraLibs
#endif
SRCS = binkey.C binkey_utils.C common.C \
options.C options_tt.C prop.C \
prop_utils.C spec.C spec_repair.C \
spec_utils.C ttdbck.C
OBJS = binkey.o binkey_utils.o common.o \
options.o options_tt.o prop.o \
prop_utils.o spec.o spec_repair.o \
spec_utils.o ttdbck.o
NormalCplusplusObjectRule()
ComplexCplusplusProgramTarget(ttdbck)
SpecialCplusplusObjectRule(options,options,$(TT_VERSION_DEFINE))

View File

@@ -0,0 +1,11 @@
XCOMM $XConsortium: admindefines /main/2 1996/05/07 19:15:52 drk $
#ifdef sun
/*
* Some tooltalk header files contain inline references to internal
* functions. Attempting to compile with -g fails because these
* inline references expand into unresolved symbols. Until tooltalk
* is fixed force use of -g0. See CDExc20311 for details.
*/
# define DebuggableCplusplusDebugFlags -g0
#endif

View File

@@ -0,0 +1,110 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: binkey.C /main/3 1995/10/20 16:24:54 rswiston $
/*
*
* binkey.cc
*
* Copyright (c) 1991 by Sun Microsystems, Inc.
*/
#include "util/tt_string.h"
#include "db/tt_db_key_utils.h"
#include "binkey.h"
#include <memory.h>
static unsigned char sixteen_zeroes[OID_KEY_LENGTH] = {
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0};
static unsigned char sixteen_foxes[OID_KEY_LENGTH] = {
255,255,255,255,
255,255,255,255,
255,255,255,255,
255,255,255,255};
Binkey Binkey::smallest(sixteen_zeroes);
Binkey Binkey::largest(sixteen_foxes);
static int binkey_compare(const unsigned char *a, const unsigned char *b);
Binkey::
Binkey()
{
memset((char *)_binkey, 0, sizeof(_binkey));
_key = (_Tt_db_key *)0;
}
Binkey::
Binkey(const unsigned char *k)
{
_Tt_string bks(k, sizeof(_binkey));
memcpy((char *)_binkey, k, sizeof(_binkey));
_key = new _Tt_db_key(bks);
}
Binkey & Binkey::
operator=(const Binkey &k)
{
memcpy((char *)_binkey, (char *)k._binkey, sizeof(_binkey));
_key = new _Tt_db_key(k);
return *this;
}
Binkey & Binkey::
operator=(const unsigned char *k)
{
_Tt_string bks(k, sizeof(_binkey));
memcpy((char *)_binkey, k, sizeof(_binkey));
_key = new _Tt_db_key(bks);
return *this;
}
int
operator==(const Binkey &a, const _Tt_db_key &b)
{
return b==*a._key;
}
int
operator==(const Binkey &a, const Binkey &b)
{
return binkey_compare(a._binkey,b._binkey)==0;
}
int
operator<(const Binkey &a, const Binkey &b)
{
return binkey_compare(a._binkey,b._binkey)<0;
}
int
operator>(const Binkey &a, const Binkey &b)
{
return binkey_compare(a._binkey,b._binkey)>0;
}
static int
binkey_compare(const unsigned char *pa, const unsigned char *pb)
{
// No libc routines seem to guarantee to handle unsigned chars!
int i = OID_KEY_LENGTH;
while (i--) {
if (*pa>*pb) return 1;
if (*pa++<*pb++) return -1;
}
return 0;
}
void Binkey::
print(FILE* f) const
{
if (_key.is_null()) {
fprintf(f,"(null key)");
} else {
_key->print(f);
}
}

View File

@@ -0,0 +1,59 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: binkey.h /main/3 1995/10/20 16:25:01 rswiston $ */
/*
*
* binkey.h
*
* Simple class for manipulating 16-byte keys.
* This class simply encapsulates the storage and (lexical) comparison
* of 16-byte binary keys. Generally, _Tt_db_key is the class to
* use to hold and manipulate keys; only code which depends on the
* lexical ordering of keys (which should only be the inspect-and-
* repair tools) should use this class.
*
* Copyright (c) 1991 by Sun Microsystems, Inc.
*/
#ifndef _BINKEY_H
#define _BINKEY_H
#include "tt_const.h"
#include "util/tt_object.h"
#include "util/tt_string.h"
#include "db/tt_db_key.h"
#include "db/tt_db_key_utils.h"
#include <stdio.h>
#include <memory.h>
class Binkey : public _Tt_object {
private:
unsigned char _binkey[OID_KEY_LENGTH];
_Tt_db_key_ptr _key;
public:
static Binkey smallest;
static Binkey largest;
Binkey();
Binkey(const unsigned char *);
~Binkey() {};
operator _Tt_string() const {return _key->string();};
operator char*() const {return (char *)_binkey;};
_Tt_db_key_ptr key() const {return _key;};
friend int operator==(const Binkey &a, const Binkey &b);
friend int operator!=(const Binkey &a, const Binkey &b) {
return !(a==b);};
friend int operator==(const Binkey &a, const _Tt_db_key &b);
friend int operator!=(const Binkey &a, const _Tt_db_key &b) {
return !(a==b);};
friend int operator<(const Binkey &a, const Binkey &b);
friend int operator>(const Binkey &a, const Binkey &b);
Binkey &operator=(const Binkey &k);
Binkey &operator=(const unsigned char *);
virtual void print(FILE *f = stdout) const;
};
declare_list_of(Binkey)
#endif /* _BINKEY_H */

View File

@@ -0,0 +1,15 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: binkey_utils.C /main/3 1995/10/20 16:25:10 rswiston $
/*
*
* binkey_utils.cc
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include "binkey.h"
implement_list_of(Binkey)

View File

@@ -0,0 +1,50 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: common.C /main/3 1995/10/20 16:25:17 rswiston $
/*
*
* common.cc
*
* Some utility routines common to all inspect-and-repair tools (but
* not part of any class.)
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include "dbck.h"
static int
do_a_directory(_Tt_string path, int (*fn)(_Tt_string))
{
_Tt_string suffix("TT_DB/");
if (path.right(1)!="/") {
path = path.cat("/");
}
if (path.right(suffix.len())!=suffix) {
path = path.cat(suffix);
}
return (*fn)(path);
}
int
do_directories(const _Tt_string_list_ptr &dirs, int (*fn)(_Tt_string))
{
int failcount = 0;
_Tt_string_list_cursor c(dirs);
if (dirs->is_empty()) {
failcount = !do_a_directory(".",fn);
} else {
while(c.next()) {
failcount += !do_a_directory(*c,fn);
}
}
return failcount;
}

View File

@@ -0,0 +1,30 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: dbck.h /main/3 1995/10/20 16:25:24 rswiston $ */
/* -*-C++-*-
*
* dbck.h
*
* standard/global defines common to all inspect and repair tools
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#ifndef _DBCK_H
#define _DBCK_H
#include "options.h"
extern char *progname; // from argv[0]
extern FILE *tstream; // for calling print() methods in dbx
extern int do_directories(const _Tt_string_list_ptr &dirs,
int (*fn)(_Tt_string));
#if !defined(_TT_NODEBUG)
#define DBCK_DEBUG(n) (opts->debug_level()>=(n))
#else
#define DBCK_DEBUG(n) 0
#endif
#endif /* _DBCK_H */

View File

@@ -0,0 +1,183 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $TOG: options.C /main/4 1998/03/20 14:26:44 mgreess $
/*
*
* options.cc
*
* Common option handling routines
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include <stdio.h>
#include <stdlib.h>
#include "util/copyright.h"
#if defined(linux) || defined(sgi)
#include <getopt.h>
#endif
#include "dbck.h"
#include "options.h"
#include "util/tt_iostream.h"
#include "util/tt_gettext.h"
Dbck_options::
Dbck_options()
{
_dbdirectories = new _Tt_string_list;
_sel_filename_p = 0;
_sel_filename = (char *) 0;
_sel_objid_p = 0;
_sel_objid_key = (_Tt_db_key *) 0;
_sel_type_p = 0;
_sel_type = (char *) 0;
_diag_badform_p = 0;
_diag_exist_p = 0;
_disp_id_p = 0;
_disp_mand_p = 0;
_disp_prop_p = 0;
_repair_netisam_p = 0;
_repair_type_p = 0;
_repair_type = (char *) 0;
_repair_delete_p = 0;
_debug_level = 0;
}
int Dbck_options::
set_opts(int argc, char **argv)
{
int c;
char *opts = optstring();
while (-1 != (c = getopt(argc,(char **)argv,opts))) {
if (!set_option(c, optarg)) {
//print help
return 0;
}
}
_dbdirectories = new _Tt_string_list;
for (; optind<argc; ++optind) {
_Tt_string s(argv[optind]);
_dbdirectories->append(s);
}
return 1;
}
int Dbck_options::
set_common_option(int optchar, const char *optval)
{
switch (optchar) {
case '?':
case 'h': // treat h as illegal, forces Usage: msg
return 0;
case 'v':
_TT_PRINT_VERSIONS(progname)
exit(0);
case 'd':
_debug_level = atoi(optval);
break;
case 'f':
_sel_filename_p = 1;
_sel_filename = optval;
break;
case 'k':
_sel_objid_p = 1;
_sel_objid_key = new _Tt_db_key(_Tt_string(optval));
break;
case 't':
_sel_type_p = 1;
_sel_type = optval;
break;
case 'b':
_diag_badform_p = 1;
break;
case 'x':
_diag_exist_p = 1;
break;
case 'i':
_disp_id_p = 1;
break;
case 'm':
_disp_mand_p = 1;
break;
case 'p':
_disp_prop_p = 1;
break;
case 'I':
_repair_netisam_p = 1;
break;
case 'T':
_repair_type_p = 1;
_repair_type = optval;
break;
case 'Z':
_repair_delete_p = 1;
break;
default:
return 0;
}
return 1;
}
void Dbck_options::
print(FILE *f) const
{
fprintf(f,"%s <\n",type_string());
fprintf(f,"\nDirectories:\n");
dbdirectories()->print(_tt_string_print,f);
fprintf(f,"\n");
if (_sel_filename_p) {
fprintf(f,catgets(_ttcatd, 6, 7, "Select by filename: %s\n"),
(char *)_sel_filename);
}
if (_sel_objid_p) {
fprintf(f,catgets(_ttcatd, 6, 8, "Select by objid key:"));
_sel_objid_key->print(f);
fprintf(f,"\n");
}
if (_sel_type_p) {
fprintf(f,catgets(_ttcatd, 6, 9, "Select by type: %s\n"),
(char *)_sel_type);
}
if (_diag_badform_p) {
fprintf(f,catgets(_ttcatd, 6, 10,
"Diagnose badly formed entities\n"));
}
if (_diag_exist_p) {
fprintf(f,catgets(_ttcatd, 6, 11, "Diagnose references to "
"non-existent entities\n"));
}
if (_disp_id_p) {
fprintf(f,catgets(_ttcatd, 6, 12, "Display ids\n"));
}
if (_disp_mand_p) {
fprintf(f,catgets(_ttcatd, 6, 13, "Display mandatory data\n"));
}
if (_disp_prop_p) {
fprintf(f,catgets(_ttcatd, 6, 14,
"Display properties and values data\n"));
}
if (_repair_netisam_p) {
fprintf(f,catgets(_ttcatd, 6, 15,
"Invoke NetISAM isrepair() function before "
"inspecting\n"));
}
if (_repair_type_p) {
fprintf(f,catgets(_ttcatd, 6, 16,
"Repair by setting to type: %s\n"),
(char *)_repair_type);
}
if (_repair_delete_p) {
fprintf(f,catgets(_ttcatd, 6, 17, "Repair by deleting\n"));
}
fprintf(f,catgets(_ttcatd, 6, 18, "Debugging printout level %d\n"),
_debug_level);
}

View File

@@ -0,0 +1,118 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: options.h /main/3 1995/10/20 16:25:40 rswiston $ */
/* -*-C++-*-
*
* options.h
*
* Class definitions for classes to parse and hold options from
* the command lines.
*
* Part of the ToolTalk/Link Service data base inspect and repair tool.
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#ifndef _OPTIONS_H
#define _OPTIONS_H
#include "util/tt_string.h"
#include "binkey.h"
// Options common to both ttdbck and lsdbck
class Dbck_options : public _Tt_object {
public:
Dbck_options();
int set_opts(int argc, char **argv);
const _Tt_string_list_ptr &dbdirectories() const {
return _dbdirectories;};
// Selection options
virtual int selecting_p() const{
return _sel_filename_p | _sel_objid_p | _sel_type_p;
}
int sel_filename_p()const{return _sel_filename_p;};
const _Tt_string &sel_filename() const{return _sel_filename;};
int sel_objid_p() const{return _sel_objid_p;};
_Tt_db_key_ptr sel_objid_key() const{return _sel_objid_key;};
int sel_type_p() const{return _sel_type_p;};
const _Tt_string &sel_type() const{return _sel_type;};
// Diagnosis options
virtual int diagnosing_p() const{
return _diag_badform_p | _diag_exist_p;
};
int diag_badform_p()const{return _diag_badform_p;};
int diag_exist_p() {return _diag_exist_p;};
// Display options
virtual int displaying_p() const{
return _disp_id_p | _disp_mand_p | _disp_prop_p;
};
int disp_id_p() const{return _disp_id_p;};
int disp_mand_p() const{return _disp_mand_p;};
int disp_prop_p() const{return _disp_prop_p;};
// Repair options
// Note repair_netisam_p is not included in repairing_p since
// netisam repair occurs *before* inspection, instead of after.
virtual int repairing_p() const{
return _repair_type_p | _repair_delete_p;
};
int repair_netisam_p() const{return _repair_netisam_p;};
int repair_type_p() const{return _repair_type_p;};
const _Tt_string &repair_type() const{return _repair_type;};
int repair_delete_p() const{return _repair_delete_p;};
int debug_level() const{return _debug_level;};
virtual char * type_string() const {
return "Dbck_options";
};
virtual void print(FILE *f = stdout) const;
protected:
_Tt_string_list_ptr _dbdirectories;
// Selection options
int _sel_filename_p;
_Tt_string _sel_filename; // shell wildcard pattern
int _sel_objid_p;
_Tt_db_key_ptr _sel_objid_key;
int _sel_type_p;
_Tt_string _sel_type; // shell wildcard pattern
// Diagnosis options
int _diag_badform_p;
int _diag_exist_p;
// Display options
int _disp_id_p;
int _disp_mand_p;
int _disp_prop_p;
// Repair options
int _repair_netisam_p;
int _repair_type_p;
_Tt_string _repair_type;
int _repair_delete_p;
int _debug_level;
virtual char * optstring()=0;
virtual int set_option(int optchar, const char *optval)=0;
int set_common_option(int optchar,
const char *optval);
};
#endif

View File

@@ -0,0 +1,66 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: options_tt.C /main/3 1995/10/20 16:25:48 rswiston $
/*
*
* options_tt.cc
*
* ttdbck option handling routines
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include <stdio.h>
#include <stdlib.h>
#include "dbck.h"
#include "options_tt.h"
#include "util/tt_gettext.h"
Dbck_specoptions::
Dbck_specoptions()
{
_repair_filename_p = 0;
_repair_filename = (char *)0;
}
/*
* Return the getopt valid-options string
*/
char * Dbck_specoptions::
optstring()
{
return "vhf:k:t:bximpaIF:T:Zd:";
}
int Dbck_specoptions::
set_option(int optchar, const char *optval)
{
switch (optchar) {
case 'a':
_disp_id_p = _disp_mand_p = _disp_prop_p = 1;
break;
case 'F':
_repair_filename_p = 1;
_repair_filename = optval;
break;
default:
return set_common_option(optchar, optval);
}
return 1;
}
void Dbck_specoptions::
print(FILE *f) const
{
Dbck_options::print(f);
if (_repair_filename_p) {
fprintf(f,catgets(_ttcatd, 6, 19,
"Repair by setting to file: %s\n"),
(char *)_repair_filename);
}
fprintf(f,">\n");
}

View File

@@ -0,0 +1,59 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: options_tt.h /main/3 1995/10/20 16:25:55 rswiston $ */
/* -*-C++-*-
*
* options_tt.h
*
* Class definitions for classes to parse and hold options from
* the command lines.
*
* Part of the ToolTalk/Link Service data base inspect and repair tool.
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#ifndef _OPTIONS_TT_H
#define _OPTIONS_TT_H
#include "util/tt_string.h"
#include "options.h"
// options unique to ttdbck
class Dbck_specoptions : public Dbck_options {
public:
Dbck_specoptions();
// Repair options
virtual int repairing_p() const{
return Dbck_options::repairing_p() |
_repair_filename_p;
};
int repair_filename_p() const{
return _repair_filename_p;
};
const _Tt_string &repair_filename() const{
return _repair_filename;
};
virtual char * type_string() const{
return "Dbck_specoptions";
};
virtual void print(FILE *f = stdout) const;
protected:
// Repair options
int _repair_filename_p;
_Tt_string _repair_filename;
virtual char * optstring();
virtual int set_option(int optchar, const char *optval);
};
#endif

View File

@@ -0,0 +1,47 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: prop.C /main/3 1995/10/20 16:26:03 rswiston $
/*
*
* prop.cc
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include <stddef.h>
#include <stdio.h>
#include <errno.h>
#if defined(ultrix)
#include <sys/types.h>
#endif
#include <sys/stat.h>
#include "prop.h"
#include "ttdbck.h"
// A Prop just holds the name and its list of values.
// We probably have 600 classes that do this by now.
Prop::
Prop(_Tt_string propname)
{
_name = propname;
_values = new _Tt_string_list();
}
void Prop::
print(FILE *f) const
{
fprintf(f,"Prop<");
_name->print(f);
fprintf(f,"=<");
_values->print(_tt_string_print,f);
fprintf(f,">>\n");
}
_Tt_string
_tt_prop_name(_Tt_object_ptr &o)
{
return(((Prop *)o.c_pointer())->name());
}

View File

@@ -0,0 +1,47 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: prop.h /main/3 1995/10/20 16:26:11 rswiston $ */
/*
*
* prop.h
*
* Part of the inspect&repair tools.
*
* accumulates, prints, rewrites(?) data for a spec or link.
* This is for the sole use of dbck, so much less information
* hiding is done than the usual TT class definition style:
* in particular, data members are simply made public,
* instead of defining access functions.
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#ifndef _PROP_H
#define _PROP_H
#include "util/tt_object.h"
#include "util/tt_list.h"
#include "util/tt_table.h"
#include "util/tt_string.h"
declare_list_of(Prop)
declare_table_of(Prop)
class Prop : public _Tt_object {
public:
Prop(){};
Prop(_Tt_string propname);
~Prop() {};
virtual void print(FILE * f) const;
_Tt_string &name() { /* key access for table package */
return _name;
}
_Tt_string _name;
_Tt_string_list_ptr _values;
};
_Tt_string _tt_prop_name(_Tt_object_ptr &o);
#endif /* _SPEC_H */

View File

@@ -0,0 +1,18 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: prop_utils.C /main/3 1995/10/20 16:26:19 rswiston $
/*
*
* prop_utils.cc
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include "prop.h"
implement_list_of(Prop)
implement_table_of(Prop)

297
cde/lib/tt/bin/dbck/spec.C Normal file
View File

@@ -0,0 +1,297 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: spec.C /main/3 1995/10/20 16:26:34 rswiston $
/*
*
* spec.cc
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include <string.h>
#include <stddef.h>
#include <stdio.h>
#include <errno.h>
#if defined(ultrix)
#include <sys/types.h>
#endif
#include <sys/stat.h>
#include "spec.h"
#include "options_tt.h"
#include "util/tt_gettext.h"
#include "ttdbck.h"
#include "tt_db_server_consts.h"
#if !defined(OPT_STRERROR)
// No strerror(), fake it
char *
strerror(int e)
{
return ((e<sys_nerr) ? sys_errlist[e] : "unknown");
}
#endif
Spec::
Spec()
{
key = (Binkey *) 0;
filename = "";
type = "";
is_filespec = 0;
props = new Prop_table(_tt_prop_name);
propnames = new _Tt_string_list;
}
void Spec::
add_prop_and_value(_Tt_string propname, _Tt_string value)
{
// the reason we need to keep the list of names in
// propnames is that we want to preserve the order in
// which they were encountered, so that adding them
// back in goes smoothly. A tt_table method that
// returned a sorted list of keys would be nice, but
// right now I don't have time... RFM 1/10/91
Prop_ptr sp = props->lookup(propname);
if (sp.is_null()) {
sp = new Prop(propname);
props->insert(sp);
propnames->append(propname);
}
sp->_values->append(value);
}
void Spec::
print(FILE *f) const
{
print_key(f);
print_mand(f);
print_props(f);
}
void Spec::
print_key(FILE *f) const
{
fprintf(f,
"-----------\n"
"objkey: ");
key->print(f);
fprintf(f, "\n");
}
void Spec::
print_mand(FILE *f) const
{
if (is_filespec) {
fprintf(f, "file: %s\n", (char *)filename);
} else {
fprintf(f,
"type: %s\nfile: %s\n",
(char *)type, (char *)filename);
}
}
void Spec::
print_props(FILE *f) const
{
_Tt_string_list_cursor c;
Prop_ptr sp;
_Tt_string_list_cursor v;
int i;
c.reset(propnames);
while(c.next()) {
sp = props->lookup(*c);
v.reset(sp->_values);
i = 0;
while(v.next()) {
fprintf(f,
"prop %32s[%2d] = ",
(char *)sp->_name, i++);
v->print(f);
fprintf(f,"\n");
}
}
}
//
// Called when all info for a spec has been accumulated; see if the
// spec is selected under the current selection options, diagnose
// according to diagnostic options, print according to printing
// options.
//
void Spec::
process_spec()
{
// Possible things to go wrong. Done as a bitmap not so much
// to save space, but to make the determination whether any
// bad things were found easy, by seeing if bad_flags is nonzero.
int bad_flags = 0;
const int BAD_NOFILE = 1;
const int BAD_NOTYPE = 2;
const int BAD_MULTITYPE = 4;
const int BAD_FILE_STAT = 8;
const int BAD_TYPE = 0x10;
const int BAD_TYPED_FILESPEC = 0x20;
int save_errno = 0;
Prop_ptr sp;
_Tt_otype_ptr ot;
_Tt_string_list_ptr type_list;
// All the props have been accumulated, now we can pick out
// the type if it's there.
sp = props->lookup(_Tt_string(TT_DB_OBJECT_TYPE_PROPERTY));
if (!sp.is_null()) {
type_list = sp->_values;
} else {
type_list = new _Tt_string_list;
}
if (type_list->count()==1) {
type = type_list->top();
} else {
type = "";
}
_Tt_string filehostname, filelocalpath;
filelocalpath = filename.split(':',filehostname);
if (opts->selecting_p()) {
if (opts->sel_filename_p()) {
if (!filelocalpath.sh_match(opts->sel_filename())) {
return;
}
}
if (opts->sel_type_p()) {
if (!type.sh_match(opts->sel_type())) {
return;
}
}
if (opts->sel_objid_p()) {
if (*key != *opts->sel_objid_key()) {
return;
}
}
}
if (opts->diagnosing_p()) {
if (opts->diag_badform_p()) {
if (filename=="") {
bad_flags |= BAD_NOFILE;
}
switch (type_list->count()) {
case 0:
// It's OK if docoids have no type.
if (!is_filespec) {
bad_flags |= BAD_NOTYPE;
}
break;
case 1:
ot = (*tdb_ptr)->otable->lookup(type);
if (ot.is_null()) {
bad_flags |= BAD_TYPE;
} else if (is_filespec) {
// docoids should not have a type,
// it's an error if they do, even
// if it's a valid type
bad_flags |= BAD_TYPED_FILESPEC;
}
break;
default:
bad_flags |= BAD_MULTITYPE;
}
}
if (opts->diag_exist_p() && filename!="") {
struct stat statbuf;
// HACK: ought to check that filehostname is
// same as localhost, but that's expensive
// due to aliases, possibly domain-qualified
// names, etc.
if (-1==stat((char *)filelocalpath,&statbuf)) {
save_errno = errno;
bad_flags |= BAD_FILE_STAT;
}
}
}
// If the spec has a forward pointer, then it's OK for
// it to be missing information...
sp = props->lookup(_Tt_string(TT_DB_FORWARD_POINTER_PROPERTY));
if (!sp.is_null()) {
bad_flags = 0;
}
// a spec is eligible for display or repair only if it passes all
// selection options (if not, we returned earlier) and if either the
// spec is bad somehow, or we aren't diagnosing in which case we
// always display or repair all selected specs.
if (bad_flags || !opts->diagnosing_p()) {
if (opts->displaying_p() || bad_flags) {
print_key(stdout);
}
if (opts->disp_mand_p()) {
print_mand(stdout);
}
if (opts->disp_prop_p()) {
print_props(stdout);
}
// if we are diagnosing, now is the time to print the
// diagnostics. Note that bad_flags will be zero if
// we aren't diagnosing, but we still must fall all
// way through and put the spec on the repair list.
if ((bad_flags & BAD_NOFILE)!=0) {
printf(catgets(_ttcatd, 6, 20,
"Error: no file for spec.\n"));
}
if ((bad_flags & BAD_NOTYPE)!=0) {
printf(catgets(_ttcatd, 6, 21,
"Error: no type for spec.\n"));
}
if ((bad_flags & BAD_TYPE)!=0) {
printf(catgets(_ttcatd, 6, 22,"Error: \"%s\" is not "
"an installed otype.\n"),
type.operator const char *());
}
if ((bad_flags & BAD_MULTITYPE)!=0) {
printf(catgets(_ttcatd, 6, 23,"Error: spec has multiple "
"values for type property.\n"));
}
if ((bad_flags & BAD_FILE_STAT)!=0) {
printf(catgets(_ttcatd, 6, 24,"Error: "));
printf("%s: %s", (char *)filename, strerror(save_errno));
}
if ((bad_flags & BAD_TYPED_FILESPEC)!=0) {
printf(catgets(_ttcatd, 6, 26,"Error: "));
printf("%s: internal spec for file has an otype.\n",
(char *)filename);
}
// put the spec on the list for later processing, unless
// it is a filespec, which cannot be repaired (hope we
// never get a bad filespec!)
if (!is_filespec && opts->repairing_p()) {
specs_to_repair->append(this);
}
}
}

View File

@@ -0,0 +1,53 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: spec.h /main/3 1995/10/20 16:26:43 rswiston $ */
/*
*
* spec.h
*
* Part of the spec inspect&repair tool.
*
* accumulates, prints, rewrites(?) data for a spec.
* This is for the sole use of ttdbck, so much less information
* hiding is done than the usual TT class definition style:
* in particular, data members are simply made public,
* instead of defining access functions.
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#ifndef _SPEC_H
#define _SPEC_H
#include "util/tt_object.h"
#include "util/tt_list.h"
#include "util/tt_string.h"
#include "binkey.h"
#include "prop.h"
declare_list_of(Spec)
class Spec : public _Tt_object {
public:
Spec();
~Spec() {};
Binkey_ptr key;
_Tt_string type;
_Tt_string filename;
int is_filespec;
virtual void print(FILE * f) const;
void process_spec();
void print_key(FILE * f) const;
void print_mand(FILE * f) const;
void print_props(FILE * f) const;
void add_prop_and_value(_Tt_string propname,
_Tt_string value);
void repair_spec();
private:
Prop_table_ptr props;
_Tt_string_list_ptr propnames;
};
#endif /* _SPEC_H */

View File

@@ -0,0 +1,225 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: spec_repair.C /main/3 1995/10/20 16:26:51 rswiston $
/*
*
* spec_repair.cc
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include <stddef.h>
#include <stdio.h>
#include <errno.h>
#if defined(ultrix)
#include <sys/types.h>
#endif
#if defined(_AIX)
#include <time.h>
#endif
#include <sys/stat.h>
#include "spec.h"
#include "options_tt.h"
#include "ttdbck.h"
#include "db/tt_db_object.h"
#include "db/tt_db_object_utils.h"
#include "db/tt_db_key.h"
#include "db/tt_db_object.h"
#include "db/tt_db_results.h"
#include "db/tt_db_access.h"
#include "tt_db_server_consts.h"
#define MKERR(msg, err) fprintf(stderr, \
"ttdbck: error %s spec: %s\n", \
msg, \
tt_status_message(err))
const char* MP_TYPE_PROP = "_NODE_TYPE";
void Spec::
repair_spec()
{
// by this point all the information about the spec is collected
// in the Spec instance. We make any requested changes to
// the Spec instance, then completely replace the
// info on disk with the info from the Spec instance.
if (opts->repair_type_p()) {
type = opts->repair_type();
}
if (opts->repair_filename_p()) {
filename = opts->repair_filename();
}
_Tt_db_object_ptr oldobj = new _Tt_db_object();
switch(oldobj->getDBResults()) {
case TT_DB_OK:
break;
default:
MKERR("creating", TT_ERR_INTERNAL);
return;
}
_Tt_string objid = oldobj->create(filename, key->key()->string());
switch(oldobj->getDBResults()) {
case TT_DB_OK:
break;
default:
MKERR("creating", TT_ERR_INTERNAL);
return;
}
_Tt_db_access_ptr access = oldobj->getAccess();
switch(oldobj->getDBResults()) {
case TT_DB_OK:
break;
default:
MKERR("creating", TT_ERR_INTERNAL);
return;
}
switch(oldobj->remove()) {
case TT_DB_OK:
case TT_DB_ERR_NO_SUCH_OBJECT:
case TT_DB_ERR_NO_SUCH_PROPERTY:
case TT_DB_WRN_FORWARD_POINTER:
break;
case TT_DB_ERR_ACCESS_DENIED:
MKERR("destroying", TT_ERR_ACCESS);
return;
default:
MKERR("destroying", TT_ERR_DBAVAIL);
return;
}
if (opts->repair_delete_p()) {
// don't recreate the spec.
} else {
// Should ensure we are running under a particular namespace
// for this? Like an override namespace to force into the
// db under repair?
_Tt_db_object_ptr newobj = new _Tt_db_object();
switch(newobj->getDBResults()) {
case TT_DB_OK:
break;
default:
MKERR("creating", TT_ERR_INTERNAL);
return;
}
_Tt_string newobjid = newobj->create(filename,
key->key()->string());
switch(newobj->getDBResults()) {
case TT_DB_OK:
break;
default:
MKERR("creating", TT_ERR_INTERNAL);
return;
}
newobj->setType(type);
newobj->setAccess(access);
// Re-create the properties
_Tt_string_list_cursor c;
Prop_ptr sp;
_Tt_string_list_cursor v;
_Tt_db_property_ptr dbprop = new _Tt_db_property();
uid_t euid;
gid_t group;
mode_t mode;
int owner_written = 0;
int group_written = 0;
int mode_written = 0;
c.reset(propnames);
while(c.next()) {
sp = props->lookup(*c);
v.reset(sp->_values);
if (!v.next()) {
// No values for the property. This is
// theoretically impossible -- delete the
// property.
} else if (sp->_name == TT_DB_OBJECT_TYPE_PROPERTY) {
// this is the special prop that holds the
// type name. Don't try to set it by that name.
} else {
if (sp->_name ==
TT_OBJECT_OWNER_PROPERTY) {
// This is the special user field
// Note that the access info is
// already written out above.
// Re-write it here anyway, in
// case it was corrupt in the
// old DB.
memcpy((char *)&euid,
(char *)(*v), sizeof(uid_t));
owner_written = 1;
}
else if (sp->_name ==
TT_OBJECT_GROUP_PROPERTY) {
// This is the special group field
// See note for owner field above
memcpy((char *)&group,
(char *)(*v), sizeof(gid_t));
group_written = 1;
}
else if (sp->_name ==
TT_OBJECT_MODE_PROPERTY) {
// This is the special mode field
// See note for owner field above
memcpy((char *)&mode,
(char *)(*v), sizeof(mode_t));
mode_written = 1;
}
else {
// Ordinary property -- create
// a new _Tt_db_property record
dbprop->name = sp->_name;
dbprop->values->push(*v);
while(v.next()) {
// Add any remaining values
dbprop->values->push(*v);
}
}
}
newobj->addProperty(dbprop);
}
if (owner_written && group_written && mode_written) {
// We have complete access info from the old prop
// list, so we may as well use it.
access->user = euid;
access->group = group;
access->mode = mode;
newobj->setAccess(access);
}
// There\'s not much we can do if this call doesn\'t work
newobj->write();
}
}

View File

@@ -0,0 +1,15 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: spec_utils.C /main/3 1995/10/20 16:27:00 rswiston $
/*
*
* spec_utils.cc
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include "spec.h"
implement_list_of(Spec)

View File

@@ -0,0 +1,615 @@
//%% (c) Copyright 1993, 1994 Hewlett-Packard Company
//%% (c) Copyright 1993, 1994 International Business Machines Corp.
//%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
//%% (c) Copyright 1993, 1994 Novell, Inc.
//%% $XConsortium: ttdbck.C /main/3 1995/10/20 16:34:00 rswiston $
/*
*
* ttdbck.cc
* @(#)ttdbck.C 1.31 93/09/07
*
* ToolTalk 1.0 spec data base inspect and repair tool
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <isam.h>
#include <locale.h>
#include <memory.h>
#include "util/tt_port.h"
#include "util/tt_gettext.h"
#include "util/tt_global_env.h"
#include "ttdbck.h"
#include "dbck.h"
#include "options_tt.h"
#include "binkey.h"
#include "spec.h"
#include "util/copyright.h"
#include "dm/dm_recfmts.h"
#include "mp/mp_mp.h"
#include "mp_s_mp.h"
#include "tt_db_server_consts.h"
#include "tt_isstrerror.h"
TT_INSERT_COPYRIGHT
#ifdef OPT_PATCH
static char PatchID[] = "Patch Id: 100626_03.";
static int Patch_ID100626_03;
#endif
char *progname; // from argv[0]
Dbck_specoptions *opts;
_Tt_typedb_ptr *tdb_ptr;
FILE *tstream; // for calling print() methods in dbx
// Global variables controlling state of main merge loop.
Table_oid_prop oid_prop_record;
Table_oid_access oid_access_record;
Table_oid_container oid_container_record;
Table_docoid_path docoid_path_record;
struct keydesc docoid_path_keydesc;
int oid_prop_fd, oid_access_fd, oid_container_fd, docoid_path_fd;
Binkey this_min_key;
Binkey oid_prop_key;
Binkey oid_access_key;
Binkey oid_container_key;
Binkey last_min_key;
int oid_access_inspected;
int oid_container_inspected;
_Tt_string oid_prop_value;
_Tt_string oid_prop_name;
_Tt_string oid_prop_rootname;
_Tt_string oid_access_rootname;
_Tt_string oid_container_rootname;
_Tt_string docoid_path_rootname;
Spec_list_ptr specs_to_repair;
// TOC
int main(int argc, char **argv);
int process_directory(_Tt_string dirname);
void process_spec(Spec_ptr s);
void advance_oid_prop();
void advance_oid_container();
void advance_oid_access();
void closeall();
Binkey compute_min_key(Binkey a, Binkey b, Binkey c);
void inspect_docoid_path(Spec_ptr p);
void pisamerr(const char *func, const char *name);
void check_if_file(Spec_ptr p);
// isam.h does not include function headers at all!!
extern "C" {
int isaddindex(int, struct keydesc*);
int isbuild(char*, int, struct keydesc*, int);
int isclose(int);
int iscntl(int, int, char*);
int isdelrec(int, long);
int iserase(char*);
int isopen(char*, int);
int isread(int, char*, int);
int isrepair(const char *, int);
int isrewrec(int, int, char*);
int isstart(int, struct keydesc*, int, char*, int);
int iswrite(int, char*);
}
int
main(int argc, char **argv)
{
int status;
tstream = stderr;
opts = new Dbck_specoptions;
progname = argv[0];
setlocale( LC_ALL, "" );
if (!opts->set_opts(argc, argv))
{
fprintf(stderr, catgets(_ttcatd, 6, 2,
"Usage:\n"
"ttdbck [-f file] [-k objkey] [-t type] [-bx] \n"
"[-impa] [-IZ] [-F newfilename] [-T newtype] [mountpoints]\n"));
exit (1);
}
if (DBCK_DEBUG(1)) {
opts->print(stderr);
}
if (opts->repairing_p() &&
!opts->selecting_p() &&
!opts->diagnosing_p()) {
fprintf(stderr,
catgets(_ttcatd, 6, 3,
"ttdbck: you must specify a selection "
"[-fkt] option or a diagnosis [-bx] option\n"
"if a repair [-FTZ] option is specified\n"));
exit (1);
}
if (opts->diag_badform_p()) {
// We have to initialize just enough of the ttsession
// server state to make the _Tt_typedb class work.
// XXX: really the _Tt_typedb class should be independent
// of the server.
_tt_global = new _Tt_global;
_tt_s_mp = new _Tt_s_mp;
_tt_mp = (_Tt_mp *)new _Tt_s_mp;
tdb_ptr = new _Tt_typedb_ptr;
(*tdb_ptr) = new _Tt_typedb;
Tt_status err;
// Load the xdr types database
err = (*tdb_ptr)->init_xdr();
if (err == TT_ERR_NO_MATCH) {
fprintf(stderr, "ttdbck: %s\n",
catgets(_ttcatd, 6, 4,
"Version mismatch in compiled types"));
exit (1);
} else if (err != TT_OK) {
fprintf(stderr, "ttdbck: %s\n",
catgets(_ttcatd, 6, 5,
"Cannot read types in database"));
exit (1);
}
}
status = do_directories(opts->dbdirectories(),process_directory);
// Normally UNIX programs don't make noise if nothing is wrong, but
// in the case of ttdbck it's unlikely the admin running it is
// familiar with it, and it's only being run if the database is
// suspected of damage already. So we print a reassuring message
// if there are no errors. If there are errors, there has
// already been output.
if (status==0) {
fprintf(stderr,
catgets(_ttcatd, 6, 25,
"ttdbck: no errors found.\n"));
}
exit(status);
return status;
}
/*
* Main guts of ttdbck. Called once for each directory named on the
* command line. Returns 1 if the directory was processed without
* detecting any errors, else 0.
*/
int
process_directory(_Tt_string dirname)
{
struct keydesc oid_prop_keydesc;
struct keydesc oid_access_keydesc;
struct keydesc oid_container_keydesc;
Spec_ptr this_spec;
// Initialize for main loop.
specs_to_repair = new Spec_list;
oid_prop_rootname = dirname.cat(TT_DB_PROPERTY_TABLE_FILE);
oid_prop_keydesc.k_flags = ISDUPS;
oid_prop_keydesc.k_nparts = 2;
oid_prop_keydesc.k_part[0].kp_start =
offsetof(Table_oid_prop,objkey);
oid_prop_keydesc.k_part[0].kp_leng =
sizeof(oid_prop_record.objkey);
oid_prop_keydesc.k_part[0].kp_type = BINTYPE;
oid_prop_keydesc.k_part[1].kp_start =
offsetof(Table_oid_prop,propname);
oid_prop_keydesc.k_part[1].kp_leng =
sizeof(oid_prop_record.propname);
oid_prop_keydesc.k_part[1].kp_type = CHARTYPE;
oid_access_rootname = dirname.cat(TT_DB_ACCESS_TABLE_FILE);
oid_access_keydesc.k_flags = ISNODUPS;
oid_access_keydesc.k_nparts = 1;
oid_access_keydesc.k_part[0].kp_start =
offsetof(Table_oid_access,objkey);
oid_access_keydesc.k_part[0].kp_leng =
sizeof(oid_access_record.objkey);
oid_access_keydesc.k_part[0].kp_type = BINTYPE;
oid_container_rootname = dirname.cat(TT_DB_FILE_OBJECT_MAP_FILE);
oid_container_keydesc.k_flags = ISNODUPS;
oid_container_keydesc.k_nparts = 1;
oid_container_keydesc.k_part[0].kp_start =
offsetof(Table_oid_container,objkey);
oid_container_keydesc.k_part[0].kp_leng =
sizeof(oid_container_record.objkey);
oid_container_keydesc.k_part[0].kp_type = BINTYPE;
docoid_path_rootname = dirname.cat(TT_DB_FILE_TABLE_FILE);
docoid_path_keydesc.k_flags = ISNODUPS;
docoid_path_keydesc.k_nparts = 1;
docoid_path_keydesc.k_part[0].kp_start =
offsetof(Table_docoid_path, dockey);
docoid_path_keydesc.k_part[0].kp_leng =
sizeof(docoid_path_record.dockey);
docoid_path_keydesc.k_part[0].kp_type = BINTYPE;
last_min_key = Binkey::smallest;
oid_prop_fd = -1;
oid_access_fd = -1;
oid_container_fd = -1;
docoid_path_fd = -1;
if (opts->repair_netisam_p()) {
if (-1==isrepair(oid_prop_rootname, 1)) {
pisamerr("isrepair", oid_prop_rootname);
return 0;
}
if (-1==isrepair(oid_access_rootname, 1)) {
pisamerr("isrepair", oid_access_rootname);
return 0;
}
if (-1==isrepair(oid_container_rootname, 1)) {
pisamerr("isrepair", oid_container_rootname);
return 0;
}
if (-1==isrepair(docoid_path_rootname, 1)) {
pisamerr("isrepair", docoid_path_rootname);
return 0;
}
}
oid_prop_fd = isopen(oid_prop_rootname, ISVARLEN+ISINPUT+ISMANULOCK);
if (oid_prop_fd==-1) {
pisamerr("isopen",oid_prop_rootname);
closeall();
return 0;
}
oid_access_fd = isopen(oid_access_rootname,
ISVARLEN+ISINPUT+ISMANULOCK);
if (oid_access_fd==-1) {
pisamerr("isopen",oid_access_rootname);
closeall();
return 0;
}
oid_container_fd = isopen(oid_container_rootname,
ISVARLEN+ISINPUT+ISMANULOCK);
if (oid_container_fd==-1) {
pisamerr("isopen",oid_container_rootname);
closeall();
return 0;
}
docoid_path_fd = isopen(docoid_path_rootname,
ISVARLEN+ISINPUT+ISMANULOCK);
if (docoid_path_fd==-1) {
pisamerr("isopen",docoid_path_rootname);
closeall();
return 0;
}
if (-1==isstart(oid_prop_fd, &oid_prop_keydesc,
0,
(char *)&oid_prop_record,
ISFIRST)) {
pisamerr("isstart",oid_prop_rootname);
closeall();
return 0;
}
if (-1==isstart(oid_access_fd, &oid_access_keydesc,
0,
(char *)&oid_access_record,
ISFIRST)) {
pisamerr("isstart", oid_access_rootname);
closeall();
return 0;
}
if (-1==isstart(oid_container_fd, &oid_container_keydesc,
0,
(char *)&oid_container_record,
ISFIRST)){
pisamerr("isstart", oid_container_rootname);
closeall();
return 0;
}
if (-1==isstart(docoid_path_fd, &docoid_path_keydesc,
0,
(char *)&docoid_path_record,
ISFIRST)){
pisamerr("isstart", docoid_path_rootname);
closeall();
return 0;
}
advance_oid_prop();
advance_oid_access();
advance_oid_container();
this_min_key = compute_min_key(oid_prop_key,
oid_access_key,
oid_container_key);
while (this_min_key<Binkey::largest) {
if (last_min_key<this_min_key) {
// At this point, we have read all
// information about the previous spec.
// Analyze it, list it if called for,
// queue it for later repair if called
// for.
process_spec(this_spec);
// Complain about any missing required props
// in previous spec, and reset the required property
// list.
// start accumulating a new spec
this_spec = new Spec;
this_spec->key =
new Binkey((unsigned char *)(char *)this_min_key);
check_if_file(this_spec);
if (oid_access_key>this_min_key) {
// mark spec as no access rec
}
if (oid_container_key>this_min_key) {
// mark spec as no container rec
}
}
if (!oid_container_inspected &&
oid_container_key==this_min_key) {
oid_container_inspected = 1;
inspect_docoid_path(this_spec);
}
if (oid_prop_key==this_min_key) {
// Accumulate property
this_spec->add_prop_and_value(oid_prop_name,
oid_prop_value);
}
// Advance to next records.
if (oid_prop_key==this_min_key) {
advance_oid_prop();
} else {
if (oid_container_key==this_min_key) {
advance_oid_container();
}
if (oid_access_key==this_min_key) {
advance_oid_access();
}
}
last_min_key = this_min_key;
this_min_key = compute_min_key(oid_prop_key,
oid_access_key,
oid_container_key);
}
// And remember to process the last spec.
process_spec(this_spec);
closeall();
if (opts->repairing_p()) {
Spec_list_cursor c(specs_to_repair);
while(c.next()) {
c->repair_spec();
}
}
return 1;
}
// the advance_*() routines try to read the next record in the table;
// when eof is hit, they set the record key to the largest possible
// key. This makes all the merge comparisons work right.
void
advance_oid_prop()
{
if (-1==isread(oid_prop_fd, (char *)&oid_prop_record, ISNEXT)) {
switch (iserrno) {
case EENDFILE:
break;
default:
pisamerr("isread", oid_prop_rootname);
break;
}
oid_prop_key = Binkey::largest;
} else {
int l;
oid_prop_key = oid_prop_record.objkey;
l = sizeof(oid_prop_record.propname);
if (oid_prop_record.propname[l-1]==NULL_CHAR) {
// strip nulls
l = strlen(oid_prop_record.propname);
}
oid_prop_name.set((unsigned char *)oid_prop_record.propname,l);
oid_prop_value.set((unsigned char *)oid_prop_record.propval,
isreclen-offsetof(Table_oid_prop,propval));
}
}
void
advance_oid_access()
{
if (-1==isread(oid_access_fd, (char *)&oid_access_record, ISNEXT)) {
switch (iserrno) {
case EENDFILE:
break;
default:
pisamerr("isread", oid_access_rootname);
break;
}
oid_access_key = Binkey::largest;
} else {
oid_access_key = oid_access_record.objkey;
}
oid_access_inspected = 0;
}
void
advance_oid_container()
{
if (-1==isread(oid_container_fd,
(char *)&oid_container_record, ISNEXT)) {
switch (iserrno) {
case EENDFILE:
break;
default:
pisamerr("isread", oid_container_rootname);
break;
}
oid_container_key = Binkey::largest;
} else {
oid_container_key = oid_container_record.objkey;
}
oid_container_inspected = 0;
}
void
closeall()
{
if (oid_container_fd!=-1) isclose(oid_container_fd);
if (oid_access_fd!=-1) isclose(oid_access_fd);
if (oid_prop_fd!=-1) isclose(oid_prop_fd);
if (docoid_path_fd!=-1) isclose(docoid_path_fd);
}
// compute_min_key finds the least key
Binkey
compute_min_key(Binkey a, Binkey b, Binkey c)
{
Binkey result = a;
if (b<result) result = b;
if (c<result) result = c;
return result;
}
// process spec is called when the next key is encountered, or at
// end of file. The spec data accumulated in spec s is inspected,
// printed, and/or queued for later repair.
void
process_spec(Spec_ptr s)
{
// The first time through the loop there is no accumulated spec
// so s will be null.
if (!s.is_null()) {
s->process_spec();
}
}
// inspect_docoid_path retrieves the docoid_path record for the current
// spec and fills the file name into this_spec.
void
inspect_docoid_path(Spec_ptr this_spec)
{
memset((char *)&docoid_path_record, 0, sizeof(docoid_path_record));
memcpy(docoid_path_record.dockey, oid_container_record.dockey,
sizeof(docoid_path_record.dockey));
if (-1==isread(docoid_path_fd, (char *)&docoid_path_record, ISEQUAL)) {
switch (iserrno) {
case ENOREC:
// oid doesn't have a file!
this_spec->filename = "";
return;
default:
pisamerr("isread", oid_container_rootname);
break;
}
}
if (docoid_path_record.filepath[MAX_KEY_LEN-1] == '\0') {
// strip padding.
this_spec->filename = (char *)docoid_path_record.filepath;
} else {
this_spec->filename.set((unsigned char *)
docoid_path_record.filepath,
isreclen-offsetof(Table_docoid_path,
filepath));
}
}
/*
* Print ISAM error message. Some error codes (well, one)
* are special cased to give more "helpful" messages.
*/
void
pisamerr(const char *func, const char *name)
{
const char *msg = _tt_isstrerror(iserrno);
if (msg) {
fprintf(stderr,"ttdbck: %s(\"%s\"): %s\n", func, name,
msg);
} else {
fprintf(stderr,"ttdbck: %s(\"%s\"): %d\n", func, name,
iserrno);
}
switch (iserrno) {
case EBADFILE:
fprintf(stderr,
catgets(_ttcatd, 6, 6,
"ttdbck: try 'ttdbck -I'.\n"));
break;
default:
break;
}
}
void
check_if_file(Spec_ptr this_spec)
{
memset((char *)&docoid_path_record, '\0', sizeof(docoid_path_record));
memcpy((char *)docoid_path_record.dockey,
(char *)(*this_spec->key), OID_KEY_LENGTH);
if (-1==isread(docoid_path_fd, (char *)&docoid_path_record, ISEQUAL)) {
switch (iserrno) {
case ENOREC:
break;
default:
pisamerr("isread", oid_container_rootname);
break;
}
this_spec->is_filespec = 0;
return;
}
// This is the docoid for a file. Set the filename in the spec
// so the -f option will select the docoid for the file as well.
this_spec->is_filespec = 1;
if (docoid_path_record.filepath[MAX_KEY_LEN-1] == '\0') {
// strip padding.
this_spec->filename = (char *)docoid_path_record.filepath;
} else {
this_spec->filename.set((unsigned char *)
docoid_path_record.filepath,
isreclen-offsetof(Table_docoid_path,
filepath));
}
}

View File

@@ -0,0 +1,27 @@
/*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
/*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
/*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
/*%% (c) Copyright 1993, 1994 Novell, Inc. */
/*%% $XConsortium: ttdbck.h /main/3 1995/10/20 16:34:12 rswiston $ */
/*
*
* ttdbck.h
*
* ToolTalk 1.0 spec data base inspect and repair tool global declarations
*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
#ifndef _TTDBCK_H
#define _TTDBCK_H
#include "spec.h"
#include "options_tt.h"
#include "mp_typedb.h"
extern char *progname; // from argv[0]
extern Spec_list_ptr specs_to_repair;
extern _Tt_typedb_ptr *tdb_ptr;
extern Dbck_specoptions *opts;
#endif /* _TTDBCK_H */