Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
45
cde/lib/tt/bin/tttar/Imakefile
Normal file
45
cde/lib/tt/bin/tttar/Imakefile
Normal file
@@ -0,0 +1,45 @@
|
||||
XCOMM $XConsortium: Imakefile /main/11 1996/05/08 09:28:48 drk $
|
||||
|
||||
#define CplusplusSource YES
|
||||
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
|
||||
EXTRA_LOAD_FLAGS = ExtraLoadFlags $(UNSHARED_CXXLIB)
|
||||
|
||||
#include <Threads.tmpl>
|
||||
|
||||
#include "../../tooltalk.tmpl"
|
||||
|
||||
DEFINES =
|
||||
INCLUDES = -I. -I../../lib
|
||||
|
||||
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 = \
|
||||
tttar.C \
|
||||
archiver.C \
|
||||
tttar_utils.C \
|
||||
tttar_api.C \
|
||||
tttar_spec.C \
|
||||
tttar_file_utils.C \
|
||||
tttar_string_map.C
|
||||
|
||||
OBJS = \
|
||||
tttar.o \
|
||||
archiver.o \
|
||||
tttar_utils.o \
|
||||
tttar_api.o \
|
||||
tttar_spec.o \
|
||||
tttar_file_utils.o \
|
||||
tttar_string_map.o
|
||||
|
||||
NormalCplusplusObjectRule()
|
||||
|
||||
ComplexCplusplusProgramTarget(tttar)
|
||||
|
||||
SpecialCplusplusObjectRule(archiver,archiver,$(TT_VERSION_DEFINE))
|
||||
11
cde/lib/tt/bin/tttar/admindefines
Normal file
11
cde/lib/tt/bin/tttar/admindefines
Normal file
@@ -0,0 +1,11 @@
|
||||
XCOMM $XConsortium: admindefines /main/2 1996/05/07 19:18:56 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
|
||||
548
cde/lib/tt/bin/tttar/archiver.C
Normal file
548
cde/lib/tt/bin/tttar/archiver.C
Normal file
@@ -0,0 +1,548 @@
|
||||
//%% (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: archiver.C /main/3 1995/10/20 16:59:21 rswiston $
|
||||
/* @(#)archiver.C 1.17 93/07/30
|
||||
* archiver.cc - ToolTalk wrapper for tar(1).
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tt_options.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "api/c/tt_c.h"
|
||||
#include "util/copyright.h"
|
||||
#include "util/tt_gettext.h"
|
||||
#include "tttar_utils.h"
|
||||
#include "tttar_file_utils.h"
|
||||
#include "tttar_api.h"
|
||||
#include "archiver.h"
|
||||
|
||||
/*
|
||||
* External variables
|
||||
*/
|
||||
|
||||
/*
|
||||
* archiver::archiver()
|
||||
*/
|
||||
archiver::
|
||||
archiver( char *arg0 )
|
||||
{
|
||||
if (arg0 != NULL) {
|
||||
char *base = strrchr( arg0, '/' );
|
||||
if (base == NULL) {
|
||||
base = arg0;
|
||||
} else {
|
||||
base++;
|
||||
}
|
||||
_prog_name = base;
|
||||
_process_name = _prog_name;
|
||||
} else {
|
||||
_process_name = "(No process name)";
|
||||
_prog_name = "(No program name)";
|
||||
}
|
||||
_mode = NO_MODE;
|
||||
_verbosity = 0;
|
||||
_follow_symlinks = FALSE;
|
||||
_recurse = TRUE;
|
||||
_archive_links = TRUE;
|
||||
_archive_external_links = TRUE;
|
||||
_preserve_modes = FALSE;
|
||||
_preserve__props = TRUE;
|
||||
_should_tar = TRUE;
|
||||
_only_1_look_at_tarfile = FALSE;
|
||||
_io_stream = NULL;
|
||||
_paths2tar = new _Tt_string_list;
|
||||
_renamings = new Lstar_string_map_list;
|
||||
}
|
||||
|
||||
archiver::
|
||||
~archiver()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* archiver::do_tar() - Invoke tar(1) using system()
|
||||
* If _mode is CREATE, do_tttarfile means "also archive tttarfile".
|
||||
* If _mode is EXTRACT, do_tttarfile means "only extract tttarfile".
|
||||
*/
|
||||
int archiver::
|
||||
do_tar( _Tt_string tttardir, bool_t do_tttarfile )
|
||||
{
|
||||
char _curdir[ MAXPATHLEN+1 ];
|
||||
_Tt_string curdir;
|
||||
int status2return;
|
||||
_Tt_string cmd( "tar " );
|
||||
_Tt_string exclude_file;
|
||||
|
||||
/*
|
||||
* Further down, we use the X option to exclude the tttarfile when
|
||||
* extracting so we can extract it into a different place.
|
||||
* Unfortunately AIX and HPUX don\'t have the X option, so
|
||||
* their users will just have to suffer with having the extra
|
||||
* tttarfile appear when doing extracting, and we hope we
|
||||
* have permission to do so..
|
||||
*/
|
||||
|
||||
#if !defined(OPT_TAR_HAS_EXCLUDE_OPTION)
|
||||
_only_1_look_at_tarfile = TRUE;
|
||||
#endif
|
||||
/*
|
||||
* If we're extracting just the tttarfile, chdir() to
|
||||
* a place where we can extract it with permission and
|
||||
* without collisions.
|
||||
*/
|
||||
if (do_tttarfile && (_mode == EXTRACT)) {
|
||||
#if !defined(OPT_BUG_SUNOS_4)
|
||||
curdir = getcwd( _curdir, MAXPATHLEN );
|
||||
#else
|
||||
curdir = getwd( _curdir );
|
||||
#endif
|
||||
int status = chdir( (char *)tttardir );
|
||||
if (status != 0) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
switch (_mode) {
|
||||
case CREATE:
|
||||
cmd = cmd.cat( "c" );
|
||||
break;
|
||||
case EXTRACT:
|
||||
cmd = cmd.cat( "x" );
|
||||
break;
|
||||
case LIST:
|
||||
cmd = cmd.cat( "t" );
|
||||
break;
|
||||
case NO_MODE:
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
for (int n = 0; n < _verbosity; n++) {
|
||||
cmd = cmd.cat( "v" );
|
||||
}
|
||||
if (_follow_symlinks) {
|
||||
cmd = cmd.cat( "h" );
|
||||
}
|
||||
if (_preserve_modes) {
|
||||
cmd = cmd.cat( "p" );
|
||||
}
|
||||
if (_tarfile_arg.len() != 0) {
|
||||
cmd = cmd.cat( "f" );
|
||||
}
|
||||
/*
|
||||
* If we're extracting and we don't want the tttarfile, we
|
||||
* need to pass the X option to exclude the tttarfile.
|
||||
* But if we're extracting from stdin, we only get one chance
|
||||
* to read the input, so in that case we can't exclude the
|
||||
* tttarfile from being extracted.
|
||||
*/
|
||||
|
||||
if ((_mode == EXTRACT) && (! do_tttarfile) && (!_only_1_look_at_tarfile))
|
||||
{
|
||||
cmd = cmd.cat( "X" );
|
||||
}
|
||||
if (_tarfile_arg.len() != 0) {
|
||||
cmd = cmd.cat( " " );
|
||||
/*
|
||||
* If we've chdir()'d to our temp dir to extract the
|
||||
* tttarfile, then be sure to prepend the old cwd
|
||||
* to the tarfile's name if it's relative.
|
||||
*/
|
||||
if ( do_tttarfile
|
||||
&& (_mode == EXTRACT)
|
||||
&& (_tarfile_arg[0] != '/'))
|
||||
{
|
||||
cmd = cmd.cat( curdir ).cat( "/" );
|
||||
}
|
||||
cmd = cmd.cat( _tarfile_arg );
|
||||
}
|
||||
_Tt_string_list_cursor pathc( _paths2tar );
|
||||
switch (_mode) {
|
||||
case CREATE:
|
||||
while (pathc.next()) {
|
||||
cmd = cmd.cat( " " ).cat( *pathc );
|
||||
}
|
||||
/*
|
||||
* Have tar dip into our temporary directory and
|
||||
* pick up the tttarfile.
|
||||
*/
|
||||
if (do_tttarfile) {
|
||||
cmd = cmd.cat( " -C " ).cat( tttardir ).
|
||||
cat( " tttarfile" );
|
||||
}
|
||||
break;
|
||||
case EXTRACT:
|
||||
if (do_tttarfile) {
|
||||
/*
|
||||
* Only extract the tttarfile.
|
||||
*/
|
||||
cmd = cmd.cat( " tttarfile" );
|
||||
} else {
|
||||
if (_only_1_look_at_tarfile) {
|
||||
/*
|
||||
* If we're extracting from stdin, we
|
||||
* can only invoke tar(1) once, so
|
||||
* hope we have write permission
|
||||
* on the current directory, 'cuz that's
|
||||
* where we've got to put the tttarfile.
|
||||
* Only explicitly ask for the tttarfile
|
||||
* if we are being picky in what we extract.
|
||||
*/
|
||||
if (_paths2tar->count() > 0) {
|
||||
cmd = cmd.cat( " tttarfile" );
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Extract everything _but_ the tttarfile.
|
||||
*/
|
||||
exclude_file = tttardir.cat( "/tar.exclude" );
|
||||
FILE *fp = fopen( (char *)exclude_file, "w" );
|
||||
if (fp == NULL) {
|
||||
cmd = cmd.cat( " /dev/null" );
|
||||
} else {
|
||||
fprintf( fp, "tttarfile\n" );
|
||||
fclose( fp );
|
||||
cmd = cmd.cat( " " ).cat( exclude_file );
|
||||
}
|
||||
}
|
||||
while (pathc.next()) {
|
||||
cmd = cmd.cat( " " ).cat( *pathc );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIST:
|
||||
break;
|
||||
case NO_MODE:
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
//printf( "Invoking: %s\n", (char *)cmd );
|
||||
int sys_status = system( (char *)cmd );
|
||||
if (WIFEXITED(sys_status)) {
|
||||
status2return = WEXITSTATUS(sys_status);
|
||||
} else {
|
||||
fprintf( stderr,
|
||||
"%s: system(\"%s\"): %d\n",
|
||||
(char *)_process_name, (char *)cmd, sys_status );
|
||||
status2return = 1;
|
||||
}
|
||||
if (_mode == EXTRACT) {
|
||||
int status;
|
||||
if (do_tttarfile) {
|
||||
status = chdir( (char *)curdir );
|
||||
if (status != 0) {
|
||||
fprintf( stderr, "%s: chdir(\"%s\"): %s\n",
|
||||
(char *)_process_name,
|
||||
(char *)curdir, strerror(errno) );
|
||||
exit( status );
|
||||
}
|
||||
} else if (exclude_file.len() > 0) {
|
||||
status = unlink( (char *)exclude_file );
|
||||
if (status != 0) {
|
||||
perror( (char *)exclude_file );
|
||||
}
|
||||
}
|
||||
}
|
||||
return status2return;
|
||||
|
||||
} /* archiver::do_tar() */
|
||||
|
||||
/*
|
||||
* archiver::do_tttar() - Perform just the LS/TT part of tttar
|
||||
*/
|
||||
bool_t archiver::
|
||||
do_tttar( char *tttarfile_name, bool_t silent )
|
||||
{
|
||||
char *process_id;
|
||||
int first_ttmalloc;
|
||||
XDR xdrs;
|
||||
bool_t val2return = TRUE;
|
||||
char _curdir[ MAXPATHLEN+1 ];
|
||||
_Tt_string curdir;
|
||||
|
||||
_io_stream = this->_open_io_stream( tttarfile_name, silent );
|
||||
if (_io_stream == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
switch (_mode) {
|
||||
case CREATE:
|
||||
xdrstdio_create( &xdrs, _io_stream, XDR_ENCODE );
|
||||
break;
|
||||
case LIST:
|
||||
case EXTRACT:
|
||||
xdrstdio_create( &xdrs, _io_stream, XDR_DECODE );
|
||||
break;
|
||||
case NO_MODE:
|
||||
default:
|
||||
fprintf( stderr, "%s: Archive_mode: %d\n",
|
||||
(char *)_process_name, (int)_mode );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tooltalk setup
|
||||
*/
|
||||
first_ttmalloc = tt_mark();
|
||||
note_ptr_err( tt_open() );
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
return FALSE;
|
||||
}
|
||||
process_id = ptr_returned;
|
||||
|
||||
switch (_mode) {
|
||||
case CREATE:
|
||||
val2return = pathlist_lstt_archive(
|
||||
_paths2tar, _recurse, _follow_symlinks,
|
||||
_verbosity, &xdrs );
|
||||
break;
|
||||
case LIST:
|
||||
val2return = pathlist_lstt_archive_list(_paths2tar, _verbosity,
|
||||
&xdrs);
|
||||
break;
|
||||
case EXTRACT:
|
||||
#if !defined(OPT_BUG_SUNOS_4)
|
||||
curdir = getcwd( _curdir, MAXPATHLEN );
|
||||
#else
|
||||
curdir = getwd( _curdir );
|
||||
#endif
|
||||
val2return = pathlist_lstt_dearchive( _paths2tar, _renamings,
|
||||
curdir, _preserve__props,
|
||||
_verbosity, &xdrs);
|
||||
break;
|
||||
case NO_MODE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tooltalk teardown
|
||||
*/
|
||||
note_err( tt_close() );
|
||||
my_tt_release( first_ttmalloc );
|
||||
|
||||
xdr_destroy( &xdrs );
|
||||
if ((_io_stream != stdin) && (_io_stream != stdout)) {
|
||||
fclose( _io_stream );
|
||||
}
|
||||
return val2return;
|
||||
}
|
||||
|
||||
/*
|
||||
* archiver::parse_args()
|
||||
*/
|
||||
void archiver::
|
||||
parse_args( int argc, char **argv )
|
||||
{
|
||||
bool_t next_arg_is_tarfile = FALSE;
|
||||
|
||||
for ( int argnum = 1; argnum < argc; argnum++ ) {
|
||||
char *cp = argv[argnum];
|
||||
_Tt_string arg( cp );
|
||||
if (argnum == 1) {
|
||||
/*
|
||||
* Process mode setting and other flags.
|
||||
*/
|
||||
while (*cp != '\0') {
|
||||
switch (*cp) {
|
||||
case 'c':
|
||||
case 't':
|
||||
case 'x':
|
||||
if (_mode == NO_MODE) {
|
||||
switch (*cp) {
|
||||
case 'c':
|
||||
_mode = CREATE;
|
||||
break;
|
||||
case 't':
|
||||
_mode = LIST;
|
||||
break;
|
||||
case 'x':
|
||||
_mode = EXTRACT;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
this->usage();
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
cp++;
|
||||
switch (*cp) {
|
||||
case 'v':
|
||||
_TT_PRINT_VERSIONS
|
||||
((char *)_prog_name)
|
||||
exit(0);
|
||||
break;
|
||||
case 'h':
|
||||
this->usage();
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
this->usage();
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
next_arg_is_tarfile = TRUE;
|
||||
break;
|
||||
case 'R':
|
||||
_recurse = FALSE;
|
||||
break;
|
||||
case 'h':
|
||||
_follow_symlinks = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
_preserve_modes = TRUE;
|
||||
break;
|
||||
case 'P':
|
||||
_preserve__props = FALSE;
|
||||
break;
|
||||
case 'S':
|
||||
_archive_links = FALSE;
|
||||
break;
|
||||
case 'E':
|
||||
_archive_external_links = FALSE;
|
||||
break;
|
||||
case 'L':
|
||||
_should_tar = FALSE;
|
||||
break;
|
||||
case 'v':
|
||||
_verbosity++;
|
||||
break;
|
||||
default:
|
||||
this->usage();
|
||||
exit(1);
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
} else if (next_arg_is_tarfile) {
|
||||
_tarfile_arg = cp;
|
||||
next_arg_is_tarfile = FALSE;
|
||||
} else if (arg == "-rename") {
|
||||
Lstar_string_map_ptr m = new Lstar_string_map;
|
||||
|
||||
if (++argnum >= argc) {
|
||||
this->usage();
|
||||
exit(1);
|
||||
} else {
|
||||
m->old_string_set( argv[argnum] );
|
||||
if (++argnum >= argc) {
|
||||
this->usage();
|
||||
exit(1);
|
||||
} else {
|
||||
m->new_string_set( argv[argnum] );
|
||||
_renamings->append( m );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Add this pathname to the list.
|
||||
*/
|
||||
_Tt_string path = cp;
|
||||
_paths2tar->append( path );
|
||||
}
|
||||
}
|
||||
if ( ((_tarfile_arg.len() == 0) && (! _should_tar))
|
||||
|| (_mode == NO_MODE)
|
||||
|| (_should_tar && (! _recurse)))
|
||||
{
|
||||
this->usage();
|
||||
exit(1);
|
||||
}
|
||||
_only_1_look_at_tarfile =
|
||||
(_tarfile_arg.len() == 0) || (_tarfile_arg == "-");
|
||||
/*
|
||||
* Renaming as you dearchive is not a tar(1) option.
|
||||
*/
|
||||
if ( (_renamings->count() > 0)
|
||||
&& (_should_tar || (_mode != EXTRACT)))
|
||||
{
|
||||
this->usage();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* archiver::_open_io_stream() - Returns an file pointer opened according
|
||||
* to _mode. Uses stdin/stdout if filename is NULL or "-".
|
||||
* Exits with an error message if the _mode is not set,
|
||||
* or if the named file cannot be opened.
|
||||
*/
|
||||
FILE * archiver::
|
||||
_open_io_stream(char *filename, bool_t silent)
|
||||
{
|
||||
bool_t in_pipe;
|
||||
FILE *fp = NULL;
|
||||
|
||||
in_pipe = ( (filename == NULL)
|
||||
|| (strcmp( filename, "-" ) == 0));
|
||||
switch (_mode) {
|
||||
case CREATE:
|
||||
if (in_pipe) {
|
||||
return stdout;
|
||||
} else {
|
||||
fp = fopen( filename, "w" );
|
||||
}
|
||||
break;
|
||||
case EXTRACT:
|
||||
case LIST:
|
||||
if (in_pipe) {
|
||||
return stdin;
|
||||
} else {
|
||||
fp = fopen( filename, "r" );
|
||||
}
|
||||
break;
|
||||
case NO_MODE:
|
||||
default:
|
||||
fprintf( stderr, "%s: Archive_mode: %d\n",
|
||||
(char *)_process_name, (int)_mode );
|
||||
}
|
||||
if ((fp == NULL) && (! silent)) {
|
||||
fprintf( stderr, "%s: %s: %s\n",
|
||||
(char *)_process_name, filename, strerror(errno) );
|
||||
}
|
||||
return fp;
|
||||
|
||||
} /* archiver::_open_io_stream() */
|
||||
|
||||
/*
|
||||
* archiver::usage()
|
||||
*/
|
||||
void archiver::
|
||||
usage( FILE *fs ) const
|
||||
{
|
||||
fprintf( fs,
|
||||
catgets(_ttcatd, 7, 2,
|
||||
"Usage: %s {ctx}[fhpPv[v]] [tarfile] pathname ...\n"
|
||||
" %s {ctx}fL[hpPRv[v]] tttarfile pathname ...\n"
|
||||
" %s -v\n"
|
||||
" %s -h\n"),
|
||||
(char *)_prog_name, (char *)_prog_name, (char *)_prog_name,
|
||||
(char *)_prog_name );
|
||||
fprintf( fs,
|
||||
catgets(_ttcatd, 7, 3,
|
||||
"\tc create an archive\n"
|
||||
"\tt list an archive's contents\n"
|
||||
"\tx extract from an archive\n"
|
||||
"\tf use next arg <tarfile> as archive\n"
|
||||
"\th follow symbolic links\n"
|
||||
"\tL do not invoke tar(1)\n"
|
||||
"\tp preserve file modes\n"
|
||||
"\tP (root) do not preserve objects' "
|
||||
"owner, mod time, etc.\n"
|
||||
"\tR do not recurse into directories\n"
|
||||
"\tv be verbose\n"
|
||||
"\tvv be very verbose\n"
|
||||
"\t-v print the version number and quit\n"
|
||||
"\t-h[elp] print this message\n"));
|
||||
}
|
||||
73
cde/lib/tt/bin/tttar/archiver.h
Normal file
73
cde/lib/tt/bin/tttar/archiver.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*%% (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: archiver.h /main/3 1995/10/20 16:59:30 rswiston $ */
|
||||
/*
|
||||
* archiver.h - Interface to archiver, an LS/TT-aware tar(1).
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ARCHIVER_H
|
||||
#define _ARCHIVER_H
|
||||
|
||||
#include <api/c/tt_c.h>
|
||||
#include <util/tt_string.h>
|
||||
#include "tttar_string_map.h"
|
||||
|
||||
/*
|
||||
* Type definitions
|
||||
*/
|
||||
|
||||
typedef enum archive_mode {
|
||||
NO_MODE,
|
||||
CREATE,
|
||||
LIST,
|
||||
EXTRACT} Archive_mode;
|
||||
|
||||
class archiver : public _Tt_object {
|
||||
public:
|
||||
archiver( char *arg0 );
|
||||
virtual ~archiver();
|
||||
|
||||
int do_tar( _Tt_string tttardir,
|
||||
bool_t only_tttarfile );
|
||||
bool_t do_tttar( char *tttarfile_name,
|
||||
bool_t silent );
|
||||
void parse_args( int argc, char **argv );
|
||||
void usage( FILE *fs = stderr ) const;
|
||||
_Tt_string process_name() { return _process_name; }
|
||||
Archive_mode mode() { return _mode; }
|
||||
void mode_set( Archive_mode m ) { _mode = m; }
|
||||
bool_t verbosity() { return _verbosity; }
|
||||
void verbosity_set( int v ) { _verbosity = v; }
|
||||
bool_t should_tar() { return _should_tar; }
|
||||
bool_t only_1_look_at_tarfile()
|
||||
{ return _only_1_look_at_tarfile; }
|
||||
_Tt_string tarfile_arg() { return _tarfile_arg; }
|
||||
|
||||
private:
|
||||
FILE *_open_io_stream( char *filename,
|
||||
bool_t complain );
|
||||
|
||||
_Tt_string _process_name;
|
||||
_Tt_string _prog_name;
|
||||
Archive_mode _mode;
|
||||
int _verbosity;
|
||||
bool_t _follow_symlinks;
|
||||
bool_t _recurse;
|
||||
bool_t _archive_links;
|
||||
bool_t _archive_external_links;
|
||||
bool_t _preserve_modes;
|
||||
bool_t _preserve__props;
|
||||
bool_t _should_tar;
|
||||
bool_t _only_1_look_at_tarfile;
|
||||
FILE *_io_stream;
|
||||
_Tt_string _tarfile_arg;
|
||||
_Tt_string_list_ptr _paths2tar;
|
||||
Lstar_string_map_list_ptr _renamings;
|
||||
};
|
||||
|
||||
#endif /* _ARCHIVER_H */
|
||||
150
cde/lib/tt/bin/tttar/tttar.C
Normal file
150
cde/lib/tt/bin/tttar/tttar.C
Normal file
@@ -0,0 +1,150 @@
|
||||
//%% (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: tttar.C /main/4 1995/10/20 16:59:46 rswiston $
|
||||
/*
|
||||
* tttar.cc - Link Service/ToolTalk object archive tool.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#if defined(__osf__)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#if !defined(USL) && !defined(__uxp__)
|
||||
#include <osfcn.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <netdb.h>
|
||||
#include <locale.h>
|
||||
#include <errno.h>
|
||||
#include "util/tt_port.h"
|
||||
#include "util/copyright.h"
|
||||
#include "tt_options.h"
|
||||
#include "archiver.h"
|
||||
|
||||
#if defined(OPT_BUG_USL) || defined(OPT_BUG_UXP)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
TT_INSERT_COPYRIGHT
|
||||
|
||||
#ifdef OPT_PATCH
|
||||
static char PatchID[] = "Patch Id: 100626_03.";
|
||||
static int Patch_ID100626_03;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Global variables
|
||||
*/
|
||||
|
||||
char our_process_name[80];
|
||||
int verbosity = 0;
|
||||
|
||||
/*
|
||||
* main()
|
||||
*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
archiver *tttar = new archiver( argv[0] );
|
||||
_Tt_string tttarfile_name;
|
||||
_Tt_string tttardir;
|
||||
bool_t tttar_worked = FALSE;
|
||||
bool_t should_tttar = FALSE;
|
||||
|
||||
setlocale( LC_ALL, "" );
|
||||
|
||||
tttar->parse_args( argc, argv );
|
||||
sprintf( our_process_name, "%s", (char *)tttar->process_name());
|
||||
verbosity = tttar->verbosity();
|
||||
|
||||
if (tttar->should_tar()) {
|
||||
char *tempnam_result;
|
||||
/*
|
||||
* Create a temporary directory to which we can
|
||||
* chdir() in order to create or extract the
|
||||
* tttarfile for or from the tarfile.
|
||||
*/
|
||||
tttardir = tempnam_result = tempnam(NULL, "tttardir");
|
||||
free(tempnam_result);
|
||||
if (mkdir( (char *)tttardir, S_IRWXU ) == 0) {
|
||||
tttarfile_name = tttardir.cat( "/tttarfile" );
|
||||
should_tttar = TRUE;
|
||||
if ( (tttar->mode() == EXTRACT)
|
||||
|| (tttar->mode() == LIST))
|
||||
{
|
||||
tttar->do_tar( tttardir, FALSE );
|
||||
/*
|
||||
* Extract the tttarfile silently
|
||||
*/
|
||||
int old_verbosity = tttar->verbosity();
|
||||
Archive_mode old_mode = tttar->mode();
|
||||
tttar->verbosity_set( 0 );
|
||||
tttar->mode_set( EXTRACT );
|
||||
/*
|
||||
* If we're not extracting from stdin, we
|
||||
* can invoke tar(1) again. Otherwise,
|
||||
* do_tar() was smart enough to extract
|
||||
* the tttarfile into the cwd the first
|
||||
* time we called it.
|
||||
*/
|
||||
if (! tttar->only_1_look_at_tarfile()) {
|
||||
tttar->do_tar( tttardir, TRUE );
|
||||
} else if (tttar->mode() == EXTRACT) {
|
||||
/*
|
||||
* The tttarfile was already
|
||||
* extracted into cwd.
|
||||
*/
|
||||
tttarfile_name = "tttarfile";
|
||||
}
|
||||
tttar->verbosity_set( old_verbosity );
|
||||
tttar->mode_set( old_mode );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tttarfile_name = tttar->tarfile_arg();
|
||||
should_tttar = TRUE;
|
||||
}
|
||||
|
||||
if (should_tttar) {
|
||||
tttar_worked = tttar->do_tttar( (char *)tttarfile_name,
|
||||
tttar->should_tar() );
|
||||
}
|
||||
|
||||
if (tttar->should_tar() && (tttar->mode() == CREATE)) {
|
||||
tttar->do_tar( tttardir, tttar_worked );
|
||||
}
|
||||
|
||||
if (tttar->should_tar()) {
|
||||
/*
|
||||
* Remove any temporary tttarfile.
|
||||
*/
|
||||
int status = unlink( (char *)tttarfile_name );
|
||||
/*
|
||||
* We can't really expect an tttarfile in every tarfile,
|
||||
* so don't complain if there isn't one to remove.
|
||||
if (status != 0) {
|
||||
fprintf( stderr, "%s: %s: %s\n",
|
||||
our_process_name, (char *)tttarfile_name,
|
||||
strerror(errno));
|
||||
}
|
||||
*/
|
||||
status = rmdir( (char *)tttardir );
|
||||
if (status != 0) {
|
||||
fprintf( stderr, "%s: %s: %s\n",
|
||||
our_process_name, (char *)tttardir,
|
||||
strerror(errno));
|
||||
exit(status);
|
||||
}
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
549
cde/lib/tt/bin/tttar/tttar_api.C
Normal file
549
cde/lib/tt/bin/tttar/tttar_api.C
Normal file
@@ -0,0 +1,549 @@
|
||||
//%% (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: tttar_api.C /main/4 1995/10/20 16:59:54 rswiston $
|
||||
/*
|
||||
* tttar_api.cc - ToolTalk object archiving interface functions.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#if defined(__osf__)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#ifndef USL
|
||||
#include <osfcn.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <sys/param.h>
|
||||
#include "api/c/api_api.h"
|
||||
#include "api/c/tt_c.h"
|
||||
#include "util/tt_path.h"
|
||||
#include "util/tt_gettext.h"
|
||||
#include "tttar_utils.h"
|
||||
#include "tttar_file_utils.h"
|
||||
#include "tttar_spec.h"
|
||||
#include "tttar_api.h"
|
||||
|
||||
/*
|
||||
* Type definitions
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
|
||||
// Number of buckets in a hash table of interesting specs in an archive.
|
||||
#define SPEC_MAP_SIZE 1000
|
||||
|
||||
/*
|
||||
* Private functions
|
||||
*/
|
||||
static bool_t path_lstt_archive(
|
||||
_Tt_string path,
|
||||
int verbosity,
|
||||
XDR *xdrs );
|
||||
bool_t dearchive_this_path(
|
||||
char *path, void *ppaths_to_extract );
|
||||
static Tt_filter_action gather_specs( const char *spec_id, void *,
|
||||
void *specs);
|
||||
|
||||
/*
|
||||
* pathlist_lstt_archive() - Archive the LS/TT objects in the given paths.
|
||||
*/
|
||||
bool_t
|
||||
pathlist_lstt_archive(
|
||||
_Tt_string_list_ptr paths,
|
||||
bool_t recurse,
|
||||
bool_t follow_symlinks,
|
||||
int verbosity,
|
||||
XDR *xdrs )
|
||||
{
|
||||
_Tt_string_list_ptr realpaths2tar;
|
||||
Object_kind obj_kind;
|
||||
_Tt_string_list_ptr paths_copy(new _Tt_string_list);
|
||||
_Tt_string_list_cursor path_cursor( paths );
|
||||
while (path_cursor.next()) {
|
||||
paths_copy->append( *path_cursor );
|
||||
}
|
||||
|
||||
bool_t need_preliminary_pass = follow_symlinks && recurse;
|
||||
realpaths2tar = realtrees( paths_copy, need_preliminary_pass );
|
||||
|
||||
obj_kind = VERSION_NUM;
|
||||
int version = CURRENT_ARCHIVE_VERSION;
|
||||
if ( (! xdr_enum( xdrs, (enum_t *)&obj_kind ))
|
||||
|| (! xdr_int( xdrs, &version )))
|
||||
{
|
||||
fprintf( stderr, "%s: ! xdr_enum() || ! xdr_int()\n",
|
||||
(char *)our_process_name );
|
||||
return FALSE;
|
||||
}
|
||||
while (! paths_copy->is_empty()) {
|
||||
_Tt_string_list_ptr children;
|
||||
_Tt_string path( paths_copy->top() );
|
||||
|
||||
paths_copy->pop();
|
||||
if (! path_lstt_archive( path, verbosity, xdrs ))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (recurse) {
|
||||
children = _tt_dir_entries( path, follow_symlinks );
|
||||
children->append_destructive( paths_copy );
|
||||
paths_copy = children;
|
||||
}
|
||||
}
|
||||
obj_kind = ARCHIVE_END;
|
||||
if (! xdr_enum( xdrs, (enum_t *)&obj_kind )) {
|
||||
fprintf( stderr, "%s: ! xdr_enum()\n",
|
||||
(char *)our_process_name );
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
} /* pathlist_lstt_archive() */
|
||||
|
||||
/*
|
||||
* pathlist_lstt_dearchive() - Extract the LS/TT objects of the given paths.
|
||||
* If no paths are given, extract everything in the archive.
|
||||
*/
|
||||
bool_t
|
||||
pathlist_lstt_dearchive(
|
||||
_Tt_string_list_ptr paths_to_extract,
|
||||
Lstar_string_map_list_ptr renamings,
|
||||
_Tt_string where_to_dearchive,
|
||||
bool_t preserve__props,
|
||||
int verbosity,
|
||||
XDR *xdrs )
|
||||
{
|
||||
_Tt_string last_path;
|
||||
char *this_path = NULL;
|
||||
int num_specs = 0;
|
||||
int num_links = 0;
|
||||
bool_t last_path_valid = FALSE;
|
||||
Object_kind obj_kind = NO_KIND;
|
||||
Lstar_string_map_table_ptr spec_map;
|
||||
int mem_mark = tt_mark();
|
||||
|
||||
spec_map = new Lstar_string_map_table(Lstar_string_map_old_string,
|
||||
SPEC_MAP_SIZE );
|
||||
do {
|
||||
bool_t just_dearchived_spec = FALSE;
|
||||
bool_t just_dearchived_link = FALSE;
|
||||
|
||||
if (! xdr_enum( xdrs, (enum_t *)&obj_kind )) {
|
||||
fprintf( stderr,
|
||||
catgets(_ttcatd, 7, 4,
|
||||
"%s: Could not read object kind "
|
||||
"from archive stream.\n"),
|
||||
(char *)our_process_name );
|
||||
return FALSE;
|
||||
}
|
||||
switch (obj_kind) {
|
||||
case VERSION_NUM:
|
||||
int version;
|
||||
if (! xdr_int( xdrs, &version)) {
|
||||
fprintf( stderr,
|
||||
catgets(_ttcatd, 7, 5,
|
||||
"%s: Could not read archive ver"
|
||||
"sion from archive stream.\n"),
|
||||
(char *)our_process_name );
|
||||
return FALSE;
|
||||
}
|
||||
if (version != CURRENT_ARCHIVE_VERSION) {
|
||||
fprintf( stderr,
|
||||
catgets(_ttcatd, 7, 6,
|
||||
"%s: Found archive version %d, "
|
||||
"but expected version %d.\n"),
|
||||
(char *)our_process_name, version,
|
||||
CURRENT_ARCHIVE_VERSION );
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
case SPEC:
|
||||
char *old_spec_id;
|
||||
char *new_spec_id;
|
||||
Tt_status err;
|
||||
|
||||
old_spec_id = NULL;
|
||||
new_spec_id = NULL;
|
||||
err = TT_OK;
|
||||
|
||||
if (! spec_dearchive( &old_spec_id, &new_spec_id,
|
||||
&this_path, renamings,
|
||||
(char *)where_to_dearchive,
|
||||
preserve__props,
|
||||
dearchive_this_path,
|
||||
(void *)&paths_to_extract,
|
||||
verbosity,
|
||||
xdrs, &err ))
|
||||
{
|
||||
my_tt_release( mem_mark );
|
||||
return FALSE;
|
||||
}
|
||||
if (new_spec_id != NULL) {
|
||||
Lstar_string_map_ptr m = new Lstar_string_map;
|
||||
|
||||
m->old_string_set( old_spec_id );
|
||||
m->new_string_set( new_spec_id );
|
||||
m->extra_set( this_path );
|
||||
spec_map->insert( m );
|
||||
num_specs++;
|
||||
just_dearchived_spec = TRUE;
|
||||
}
|
||||
break;
|
||||
case ARCHIVE_END:
|
||||
break;
|
||||
case NO_KIND:
|
||||
default:
|
||||
fprintf( stderr,
|
||||
catgets(_ttcatd, 7, 7,
|
||||
"%s: found object of unknown kind "
|
||||
"%d in archive.\n"),
|
||||
(char *)our_process_name, (int)obj_kind );
|
||||
return FALSE;
|
||||
}
|
||||
if (verbosity && ( (last_path != this_path)
|
||||
|| (obj_kind == ARCHIVE_END)))
|
||||
{
|
||||
if (last_path_valid) {
|
||||
if (just_dearchived_spec) {
|
||||
num_specs--;
|
||||
} else if (just_dearchived_link) {
|
||||
num_links--;
|
||||
}
|
||||
if (verbosity > 1) {
|
||||
fprintf( stderr, "\n" );
|
||||
}
|
||||
if ( (num_specs > 0) || (num_links > 0)) {
|
||||
fprintf( stderr, "x %s %d %s\n",
|
||||
(char *)last_path, num_specs,
|
||||
( num_specs == 1
|
||||
? "spec" : "specs" ));
|
||||
}
|
||||
num_specs = 0;
|
||||
num_links = 0;
|
||||
if (just_dearchived_spec) {
|
||||
num_specs = 1;
|
||||
} else if (just_dearchived_link) {
|
||||
num_links = 1;
|
||||
}
|
||||
}
|
||||
last_path = this_path;
|
||||
if (! last_path_valid) {
|
||||
last_path_valid = TRUE;
|
||||
}
|
||||
}
|
||||
} while (obj_kind != ARCHIVE_END);
|
||||
my_tt_release( mem_mark );
|
||||
return TRUE;
|
||||
|
||||
} /* pathlist_lstt_dearchive() */
|
||||
|
||||
/*
|
||||
* pathlist_lstt_archive_list() - List the LS/TT objects of the given paths.
|
||||
* If no paths are given, list everything in the archive.
|
||||
*/
|
||||
bool_t
|
||||
pathlist_lstt_archive_list(
|
||||
_Tt_string_list_ptr paths_to_list,
|
||||
int verbosity,
|
||||
XDR *xdrs )
|
||||
{
|
||||
_Tt_string last_path;
|
||||
_Tt_string this_path;
|
||||
int num_specs = 0;
|
||||
int num_links = 0;
|
||||
bool_t last_path_valid = FALSE;
|
||||
Object_kind obj_kind = NO_KIND;
|
||||
Lstar_string_map_table_ptr spec_map;
|
||||
int mem_mark = tt_mark();
|
||||
|
||||
spec_map = new Lstar_string_map_table(Lstar_string_map_old_string,
|
||||
SPEC_MAP_SIZE );
|
||||
do {
|
||||
Lstar_spec spec;
|
||||
|
||||
if (! xdr_enum( xdrs, (enum_t *)&obj_kind )) {
|
||||
fprintf( stderr,
|
||||
catgets(_ttcatd, 7, 8,
|
||||
"%s: Could not read object kind "
|
||||
"from archive stream.\n"),
|
||||
(char *)our_process_name );
|
||||
return FALSE;
|
||||
}
|
||||
switch (obj_kind) {
|
||||
case VERSION_NUM:
|
||||
int version;
|
||||
if (! xdr_int( xdrs, &version)) {
|
||||
fprintf( stderr,
|
||||
catgets(_ttcatd, 7, 9,
|
||||
"%s: Could not read archive ver"
|
||||
"sion from archive stream.\n"),
|
||||
(char *)our_process_name );
|
||||
return FALSE;
|
||||
}
|
||||
if (version != CURRENT_ARCHIVE_VERSION) {
|
||||
fprintf( stderr,
|
||||
catgets(_ttcatd, 7, 10,
|
||||
"%s: Found archive version %d, "
|
||||
"but expected version %d.\n"),
|
||||
(char *)our_process_name, version,
|
||||
CURRENT_ARCHIVE_VERSION );
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
case SPEC:
|
||||
if (! spec.xdr(xdrs)) {
|
||||
my_tt_release( mem_mark );
|
||||
return FALSE;
|
||||
}
|
||||
if (dearchive_this_path( (char *)spec.path(),
|
||||
&paths_to_list ))
|
||||
{
|
||||
Lstar_string_map_ptr m = new Lstar_string_map;
|
||||
|
||||
/*
|
||||
* Insert it into this "map" just so that
|
||||
* we can use the map to figure out if
|
||||
* a given link counts under paths_to_list.
|
||||
*/
|
||||
m->old_string_set( spec.id() );
|
||||
m->extra_set( spec.path() );
|
||||
spec_map->insert( m );
|
||||
this_path = spec.path();
|
||||
num_specs++;
|
||||
if (verbosity > 1) {
|
||||
spec.print( stdout );
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ARCHIVE_END:
|
||||
break;
|
||||
case NO_KIND:
|
||||
default:
|
||||
fprintf( stderr,
|
||||
catgets(_ttcatd, 7, 11,
|
||||
"%s: found object of unknown kind "
|
||||
"%d in archive.\n"),
|
||||
(char *)our_process_name, (int)obj_kind );
|
||||
return FALSE;
|
||||
}
|
||||
if ( (last_path != this_path)
|
||||
|| (obj_kind == ARCHIVE_END))
|
||||
{
|
||||
if (last_path_valid) {
|
||||
if (obj_kind == SPEC) {
|
||||
num_specs--;
|
||||
} else if (obj_kind == SUN_LINK) {
|
||||
num_links--;
|
||||
}
|
||||
printf( "%s %d %s\n",
|
||||
(char *)last_path, num_specs,
|
||||
(num_specs == 1 ? "spec" : "specs" ));
|
||||
num_specs = 0;
|
||||
num_links = 0;
|
||||
if (obj_kind == SPEC) {
|
||||
num_specs = 1;
|
||||
} else if (obj_kind == SUN_LINK) {
|
||||
num_links = 1;
|
||||
}
|
||||
}
|
||||
last_path = this_path;
|
||||
if (! last_path_valid) {
|
||||
last_path_valid = TRUE;
|
||||
}
|
||||
}
|
||||
} while (obj_kind != ARCHIVE_END);
|
||||
my_tt_release( mem_mark );
|
||||
return TRUE;
|
||||
|
||||
} /* pathlist_lstt_archive_list() */
|
||||
|
||||
/*
|
||||
* path_lstt_archive() - Archive the specs on the given path.
|
||||
*/
|
||||
static bool_t
|
||||
path_lstt_archive(
|
||||
_Tt_string path,
|
||||
int verbosity,
|
||||
XDR *xdrs )
|
||||
{
|
||||
_Tt_string_list *specs;
|
||||
Object_kind obj_kind;
|
||||
int num_specs_archived = 0;
|
||||
int num_links_archived = 0;
|
||||
bool_t val2return = TRUE;
|
||||
|
||||
specs = new _Tt_string_list;
|
||||
note_err( tt_file_objects_query( (char *)path, gather_specs, NULL, specs ));
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
delete specs;
|
||||
return TRUE;
|
||||
}
|
||||
while (! specs->is_empty()) {
|
||||
_Tt_string spec = specs->top();
|
||||
Tt_status tt_err;
|
||||
|
||||
obj_kind = SPEC;
|
||||
specs->pop();
|
||||
if (! xdr_enum( xdrs, (enum_t *)&obj_kind )) {
|
||||
fprintf( stderr, "%s: ! xdr_enum()\n",
|
||||
(char *)our_process_name );
|
||||
val2return = FALSE;
|
||||
break;
|
||||
}
|
||||
if (! spec_archive( (char *)spec, (char *)path, verbosity,
|
||||
xdrs, &tt_err ))
|
||||
{
|
||||
val2return = FALSE;
|
||||
break;
|
||||
}
|
||||
num_specs_archived++;
|
||||
}
|
||||
if ((verbosity && num_specs_archived > 0 ) || (verbosity > 1)) {
|
||||
if (verbosity > 1) {
|
||||
fprintf( stderr, "\n" );
|
||||
}
|
||||
fprintf( stderr, "a %s: %d %s\n", (char *)path,
|
||||
num_specs_archived,
|
||||
((num_specs_archived == 1) ? "spec" : "specs" ));
|
||||
}
|
||||
delete specs;
|
||||
return val2return;
|
||||
|
||||
} /* path_lstt_archive() */
|
||||
|
||||
|
||||
/*
|
||||
* spec_archive() - Archive a spec onto the given XDR stream.
|
||||
*/
|
||||
bool_t
|
||||
spec_archive( char *id, char *path, int verbosity, XDR *xdrs, Tt_status *err )
|
||||
{
|
||||
_Tt_string _path( path );
|
||||
_Tt_string _id( id );
|
||||
|
||||
*err = TT_OK;
|
||||
if (xdrs->x_op == XDR_ENCODE) {
|
||||
Lstar_spec spec( _id, _path );
|
||||
|
||||
*err = spec.read_self();
|
||||
if (IS_TT_ERR(*err)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (! spec.xdr(xdrs)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (verbosity > 1) {
|
||||
spec.print( stderr );
|
||||
}
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
} /* spec_archive() */
|
||||
|
||||
/*
|
||||
* spec_dearchive() - Recreate a spec that was archived on this XDR stream.
|
||||
*/
|
||||
bool_t
|
||||
spec_dearchive(
|
||||
char **old_spec_id_ptr,
|
||||
char **new_spec_id_ptr,
|
||||
char **path_as_archived,
|
||||
Lstar_string_map_list_ptr renamings,
|
||||
char *where_to_create,
|
||||
bool_t preserve__props,
|
||||
bool_t (*dearchive_this_path)(char *, void *),
|
||||
void *context,
|
||||
int verbosity,
|
||||
XDR *xdrs,
|
||||
Tt_status *err )
|
||||
{
|
||||
_Tt_string where( where_to_create );
|
||||
|
||||
*err = TT_OK;
|
||||
*old_spec_id_ptr = NULL;
|
||||
*new_spec_id_ptr = NULL;
|
||||
*path_as_archived = NULL;
|
||||
if (xdrs->x_op == XDR_ENCODE) {
|
||||
return FALSE;
|
||||
} else if (xdrs->x_op == XDR_DECODE) {
|
||||
Lstar_spec spec;
|
||||
_Tt_string path;
|
||||
|
||||
if (! spec.xdr(xdrs)) {
|
||||
return FALSE;
|
||||
}
|
||||
*old_spec_id_ptr = _tt_strdup( spec.id() );
|
||||
*path_as_archived = _tt_strdup( spec.path() );
|
||||
path = spec.path();
|
||||
if ( (dearchive_this_path == NULL)
|
||||
|| (dearchive_this_path( (char *)path, context )))
|
||||
{
|
||||
_Tt_string _new_name = new_name( spec.path(),
|
||||
renamings );
|
||||
if (_new_name.len() > 0) {
|
||||
if (verbosity > 2) {
|
||||
fprintf( stderr, "%s => ",
|
||||
(char *)spec.path() );
|
||||
}
|
||||
spec.path_set( _new_name );
|
||||
if (verbosity > 2) {
|
||||
fprintf( stderr, "%s\n",
|
||||
(char *)spec.path() );
|
||||
}
|
||||
}
|
||||
*new_spec_id_ptr =
|
||||
spec.write_self( where, preserve__props, err );
|
||||
if (! IS_TT_ERR(*err) && (verbosity > 1)) {
|
||||
spec.print( stdout );
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
} /* spec_dearchive() */
|
||||
|
||||
|
||||
/*
|
||||
* dearchive_this_path() - Should we extract this <path> from its archive?
|
||||
*
|
||||
* Returns true if *ppaths_to_extract is an empty list.
|
||||
*/
|
||||
bool_t
|
||||
dearchive_this_path( char *path, void *ppaths_to_extract )
|
||||
{
|
||||
_Tt_string_list_ptr paths;
|
||||
_Tt_string _path( path );
|
||||
|
||||
if (ppaths_to_extract == NULL) {
|
||||
return TRUE;
|
||||
}
|
||||
paths = *(_Tt_string_list_ptr *)ppaths_to_extract;
|
||||
if (paths->count() <= 0) {
|
||||
return TRUE;
|
||||
}
|
||||
return is_child_in( _path, paths );
|
||||
|
||||
} /* dearchive_this_path() */
|
||||
|
||||
/*
|
||||
* gather_specs()
|
||||
*/
|
||||
static Tt_filter_action
|
||||
gather_specs( const char *spec_id, void *, void *specs )
|
||||
{
|
||||
_Tt_string id = spec_id;
|
||||
((_Tt_string_list *)specs)->push( id );
|
||||
return TT_FILTER_CONTINUE;
|
||||
}
|
||||
66
cde/lib/tt/bin/tttar/tttar_api.h
Normal file
66
cde/lib/tt/bin/tttar/tttar_api.h
Normal 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: tttar_api.h /main/3 1995/10/20 17:00:02 rswiston $ */
|
||||
/*
|
||||
* tttar_api.h - Link Service/ToolTalk object archiving interface functions.
|
||||
*
|
||||
* If LS/TT object archiving were ever to go into the LS/TT API,
|
||||
* some variation on these would be the functions to put in.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _TTTAR_API_H
|
||||
#define _TTTAR_API_H
|
||||
|
||||
#include "tttar_string_map.h"
|
||||
|
||||
#define CURRENT_ARCHIVE_VERSION 1
|
||||
|
||||
typedef enum object_kind {
|
||||
NO_KIND,
|
||||
VERSION_NUM,
|
||||
SPEC,
|
||||
ARCHIVE_END,
|
||||
SUN_LINK } Object_kind;
|
||||
|
||||
bool_t pathlist_lstt_archive(
|
||||
_Tt_string_list_ptr paths,
|
||||
bool_t recurse,
|
||||
bool_t follow_symlinks,
|
||||
int verbosity,
|
||||
XDR *xdrs );
|
||||
bool_t pathlist_lstt_dearchive(
|
||||
_Tt_string_list_ptr paths_to_extract,
|
||||
Lstar_string_map_list_ptr renamings,
|
||||
_Tt_string where_to_dearchive,
|
||||
bool_t preserve__props,
|
||||
int verbosity,
|
||||
XDR *xdrs );
|
||||
bool_t pathlist_lstt_archive_list(
|
||||
_Tt_string_list_ptr paths_to_extract,
|
||||
int verbosity,
|
||||
XDR *xdrs );
|
||||
bool_t spec_archive(
|
||||
char *id,
|
||||
char *path,
|
||||
int verbosity,
|
||||
XDR *xdrs,
|
||||
Tt_status *err );
|
||||
bool_t spec_dearchive(
|
||||
char **old_spec_id_ptr,
|
||||
char **new_spec_id_ptr,
|
||||
char **path_as_archived,
|
||||
Lstar_string_map_list_ptr renamings,
|
||||
char *where_to_create,
|
||||
bool_t preserve__props,
|
||||
bool_t (*dearchive_this_path)(char *, void *),
|
||||
void *context,
|
||||
int verbosity,
|
||||
XDR *xdrs,
|
||||
Tt_status *err );
|
||||
|
||||
#endif /* _TTTAR_API_H */
|
||||
61
cde/lib/tt/bin/tttar/tttar_file.C
Normal file
61
cde/lib/tt/bin/tttar/tttar_file.C
Normal file
@@ -0,0 +1,61 @@
|
||||
//%% (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: tttar_file.C /main/3 1995/10/20 17:00:10 rswiston $
|
||||
/*
|
||||
* tttar_file.cc - Implements hash table of files for the Link Service archive
|
||||
* tool.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tttar_file.h"
|
||||
|
||||
implement_list_of(tttar_file)
|
||||
implement_table_of(tttar_file,path,_Tt_string)
|
||||
|
||||
/*
|
||||
* tttar_file::tttar_file
|
||||
*/
|
||||
tttar_file::
|
||||
tttar_file()
|
||||
{
|
||||
_path = (char *)NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* tttar_file::tttar_file()
|
||||
*/
|
||||
tttar_file::
|
||||
tttar_file( _Tt_string path )
|
||||
{
|
||||
_path = path;
|
||||
}
|
||||
|
||||
/*
|
||||
* tttar_file::~tttar_file()
|
||||
*/
|
||||
tttar_file::
|
||||
~tttar_file()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* tttar_file::path()
|
||||
*/
|
||||
_Tt_string tttar_file::
|
||||
path()
|
||||
{
|
||||
return(_path);
|
||||
}
|
||||
|
||||
/*
|
||||
* tttar_file::print()
|
||||
*/
|
||||
void tttar_file::
|
||||
print( FILE *fs ) const
|
||||
{
|
||||
this->_path->print(fs);
|
||||
}
|
||||
37
cde/lib/tt/bin/tttar/tttar_file.h
Normal file
37
cde/lib/tt/bin/tttar/tttar_file.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*%% (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: tttar_file.h /main/3 1995/10/20 17:00:17 rswiston $ */
|
||||
/*
|
||||
* tttar_file.h - Interface to hash table of files for the Link Service archive
|
||||
* tool.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _LSTAR_FILE_H
|
||||
#define _LSTAR_FILE_H
|
||||
|
||||
#include <util/tt_object.h>
|
||||
#include <util/tt_list.h>
|
||||
#include <util/tt_string.h>
|
||||
#include <util/tt_table.h>
|
||||
|
||||
class tttar_file : public _Tt_object {
|
||||
public:
|
||||
tttar_file();
|
||||
tttar_file( _Tt_string path );
|
||||
~tttar_file();
|
||||
|
||||
_Tt_string path();
|
||||
void print(FILE *fs = stdout) const;
|
||||
private:
|
||||
_Tt_string _path;
|
||||
};
|
||||
|
||||
declare_list_of(tttar_file)
|
||||
declare_table_of(tttar_file,path,_Tt_string)
|
||||
|
||||
#endif /* _LSTAR_FILE_H */
|
||||
377
cde/lib/tt/bin/tttar/tttar_file_utils.C
Normal file
377
cde/lib/tt/bin/tttar/tttar_file_utils.C
Normal file
@@ -0,0 +1,377 @@
|
||||
//%% (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: tttar_file_utils.C /main/3 1995/10/20 17:00:26 rswiston $
|
||||
/*
|
||||
* tttar_file_utils.cc - File utilities for the ToolTalk archive tool.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#if defined(ultrix)
|
||||
#include <sys/inode.h>
|
||||
#define S_ISLNK(m) (((m)&IFMT) == IFLNK)
|
||||
#endif
|
||||
#include <dirent.h>
|
||||
#include "tttar_utils.h"
|
||||
#include "tttar_file_utils.h"
|
||||
#if defined(OPT_BUG_USL) || defined(OPT_BUG_UXP)
|
||||
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
|
||||
#endif
|
||||
|
||||
extern char *_tt_get_realpath(char *, char *);
|
||||
|
||||
/*
|
||||
* is_child_in() - Is <path> a node in any of the path trees listed?
|
||||
*
|
||||
* Returns true if, for any string <pathtree> in <paths>,
|
||||
* a) "<path>" == "<pathtree>", or
|
||||
* b) "<pathtree>/" is a prefix of "<path>".
|
||||
*
|
||||
*/
|
||||
bool_t
|
||||
is_child_in( _Tt_string path, _Tt_string_list_ptr paths )
|
||||
{
|
||||
_Tt_string_list_cursor path_cursor( paths );
|
||||
while (path_cursor.next()) {
|
||||
if (is_child_of( path, (*path_cursor))) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* is_child_of() - Is <path> in the path tree given?
|
||||
*
|
||||
* Returns true if
|
||||
* a) "<path>" == "<pathtree>", or
|
||||
* b) "<pathtree>/" is a prefix of "<path>".
|
||||
*
|
||||
*/
|
||||
bool_t
|
||||
is_child_of( _Tt_string path, _Tt_string pathtree )
|
||||
{
|
||||
if (pathtree == path) {
|
||||
return TRUE;
|
||||
}
|
||||
_Tt_string prefix = pathtree.cat( "/" );
|
||||
if ( prefix == path.left( prefix.len())) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* new_name() - Return the most specific renaming, or an empty string.
|
||||
*/
|
||||
_Tt_string
|
||||
new_name( _Tt_string old_name, Lstar_string_map_list_ptr renamings )
|
||||
{
|
||||
_Tt_string _new_name;
|
||||
Lstar_string_map_ptr best_renaming(new Lstar_string_map);
|
||||
Lstar_string_map_list_cursor renaming_cursor( renamings );
|
||||
|
||||
while (renaming_cursor.next()) {
|
||||
_Tt_string rename_pattern = (*renaming_cursor)->old_string();
|
||||
if (is_child_of( old_name, rename_pattern )) {
|
||||
if ( rename_pattern.len()
|
||||
> best_renaming->old_string().len())
|
||||
{
|
||||
best_renaming = *renaming_cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* If a renaming was found...
|
||||
*/
|
||||
if ( best_renaming->old_string().len() > 0) {
|
||||
/*
|
||||
* ... the new name will have as its prefix the
|
||||
* replacement part of the mapping.
|
||||
*/
|
||||
_new_name = best_renaming->new_string();
|
||||
/*
|
||||
* If it was not a perfect match...
|
||||
*/
|
||||
if (old_name != best_renaming->old_string()) {
|
||||
/*
|
||||
* ... we need to tack on whatever is
|
||||
* unique about old_string.
|
||||
*/
|
||||
_new_name =
|
||||
_new_name.cat(
|
||||
old_name.right(
|
||||
old_name.len()
|
||||
- best_renaming->old_string().len()));
|
||||
}
|
||||
}
|
||||
return _new_name;
|
||||
}
|
||||
|
||||
/*
|
||||
* dir_entries() - Return a new list of paths, with one entry for each
|
||||
* entry in the directory <path>, each entry consisting of
|
||||
* <path> appended by a slash and the name of the entry.
|
||||
* Returns an empty list if <path> is not a directory.
|
||||
* If !follow_symlinks, returns an empty list if <path> is a symlink.
|
||||
*/
|
||||
_Tt_string_list_ptr
|
||||
dir_entries( _Tt_string path, bool_t follow_symlinks )
|
||||
{
|
||||
DIR *dirp;
|
||||
_Tt_string_list_ptr entries(new _Tt_string_list);
|
||||
|
||||
if (! follow_symlinks) {
|
||||
struct stat lstat_buf;
|
||||
int lstat_status;
|
||||
|
||||
lstat_status = lstat( (char *)path, &lstat_buf );
|
||||
if (( lstat_status == 0) && S_ISLNK(lstat_buf.st_mode)) {
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
dirp = opendir( (char *)path );
|
||||
if (dirp == NULL) {
|
||||
return entries;
|
||||
}
|
||||
while (TRUE) {
|
||||
struct dirent *entry;
|
||||
_Tt_string epath;
|
||||
_Tt_string epath_slash;
|
||||
_Tt_string ename;
|
||||
|
||||
entry = readdir( dirp );
|
||||
if (entry == NULL) {
|
||||
break;
|
||||
}
|
||||
ename = entry->d_name;
|
||||
if ((ename == ".") || (ename == "..")) {
|
||||
continue;
|
||||
}
|
||||
epath_slash = path.cat( "/" );
|
||||
epath = epath_slash.cat( entry->d_name );
|
||||
entries->push( epath );
|
||||
}
|
||||
if (closedir( dirp ) != 0) {
|
||||
fprintf( stderr, "%s: closedir(\"%s\"): %s\n",
|
||||
our_process_name, (char *)path, strerror(errno) );
|
||||
}
|
||||
return entries;
|
||||
|
||||
} /* dir_entries() */
|
||||
|
||||
/*
|
||||
* realtrees() - Return a new absolutized list of the paths given.
|
||||
* If follow_symlinks, then recurse on any directories listed and
|
||||
* put the realpath of the other end of the symlink onto the list.
|
||||
*/
|
||||
_Tt_string_list_ptr
|
||||
realtrees( _Tt_string_list_ptr paths, bool_t follow_symlinks )
|
||||
{
|
||||
_Tt_string_list_ptr realpaths(new _Tt_string_list);
|
||||
_Tt_string_list_cursor path_cursor( paths );
|
||||
|
||||
while (path_cursor.next()) {
|
||||
char resolved_path_buf[ MAXPATHLEN+1 ];
|
||||
char *resolved_path;
|
||||
_Tt_string abs_path;
|
||||
_Tt_string path;
|
||||
struct stat lstat_buf;
|
||||
int lstat_status;
|
||||
|
||||
path = (*path_cursor);
|
||||
lstat_status = lstat( (char *)path, &lstat_buf );
|
||||
if ( lstat_status != 0) {
|
||||
/*
|
||||
* ToolTalk objects can be associated
|
||||
* with paths that don't exist.
|
||||
*/
|
||||
if (errno != ENOENT) {
|
||||
fprintf( stderr,
|
||||
"%s: lstat(\"%s\"): %s\n",
|
||||
our_process_name,
|
||||
(char *)path, strerror(errno) );
|
||||
continue;
|
||||
} else {
|
||||
resolved_path =
|
||||
_tt_get_realpath( (char *)path,
|
||||
resolved_path_buf );
|
||||
}
|
||||
} else if (S_ISLNK(lstat_buf.st_mode)) {
|
||||
if (follow_symlinks) {
|
||||
resolved_path = _tt_get_realpath( (char *)path,
|
||||
resolved_path_buf );
|
||||
} else {
|
||||
/*
|
||||
* Use the absolute path of the
|
||||
* symlink instead of the path of the
|
||||
* linked file.
|
||||
*/
|
||||
char *dir = dirname( (char *)path );
|
||||
char *base = basename( (char *)path );
|
||||
resolved_path = _tt_get_realpath( dir,
|
||||
resolved_path_buf );
|
||||
if (resolved_path != NULL) {
|
||||
strcat( resolved_path_buf, "/" );
|
||||
int len = strlen( resolved_path_buf );
|
||||
strncat( resolved_path_buf,
|
||||
base, MAXPATHLEN - len );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resolved_path = _tt_get_realpath( (char *)path,
|
||||
resolved_path_buf );
|
||||
}
|
||||
if (resolved_path != NULL) {
|
||||
abs_path = resolved_path;
|
||||
} else {
|
||||
if (errno == ENOENT) {
|
||||
/*
|
||||
* XXX: We need to figure out here what the
|
||||
* realpath would be if the file existed.
|
||||
*/
|
||||
}
|
||||
fprintf( stderr, "%s: %s: %s\n",
|
||||
our_process_name,
|
||||
(char *)path, strerror(errno) );
|
||||
continue;
|
||||
}
|
||||
realpaths->push( abs_path );
|
||||
if (follow_symlinks) {
|
||||
append_real_subtrees( realpaths, abs_path );
|
||||
}
|
||||
}
|
||||
return realpaths;
|
||||
|
||||
} /* realtrees() */
|
||||
|
||||
/*
|
||||
* append_real_subtrees() - If <path> is a directory, add to <realtrees>
|
||||
* any directories it contains links to, and recurse on both
|
||||
* these and any other real directories in <path>.
|
||||
*/
|
||||
void
|
||||
append_real_subtrees( _Tt_string_list_ptr realtrees, _Tt_string path )
|
||||
{
|
||||
struct stat stat_buf;
|
||||
DIR *dirp;
|
||||
|
||||
if (stat( (char *)path, &stat_buf ) != 0) {
|
||||
fprintf( stderr, "%s: stat(\"%s\"): %s\n",
|
||||
our_process_name, (char *)path, strerror(errno) );
|
||||
return;
|
||||
}
|
||||
if (! S_ISDIR(stat_buf.st_mode)) {
|
||||
return;
|
||||
}
|
||||
dirp = opendir( (char *)path );
|
||||
if (dirp == NULL) {
|
||||
fprintf( stderr, "%s: realpath(\"%s\"): %s\n",
|
||||
our_process_name, (char *)path, strerror(errno) );
|
||||
perror( NULL );
|
||||
return;
|
||||
}
|
||||
while (TRUE) {
|
||||
struct dirent *entry;
|
||||
struct stat lstat_buf;
|
||||
_Tt_string epath;
|
||||
_Tt_string epath_slash;
|
||||
_Tt_string ename;
|
||||
|
||||
entry = readdir( dirp );
|
||||
if (entry == NULL) {
|
||||
break;
|
||||
}
|
||||
ename = entry->d_name;
|
||||
if ((ename == ".") || (ename == "..")) {
|
||||
continue;
|
||||
}
|
||||
epath_slash = path.cat( "/" );
|
||||
epath = epath_slash.cat( entry->d_name );
|
||||
if (lstat( (char *)epath, &lstat_buf ) != 0) {
|
||||
fprintf( stderr, "%s: lstat(\"%s\"): %s\n",
|
||||
our_process_name, (char *)epath,
|
||||
strerror(errno) );
|
||||
perror( NULL );
|
||||
continue;
|
||||
}
|
||||
if (stat( (char *)epath, &stat_buf ) != 0) {
|
||||
fprintf( stderr, "%s: stat(\"%s\"): %s\n",
|
||||
our_process_name, (char *)epath,
|
||||
strerror(errno) );
|
||||
perror( NULL );
|
||||
continue;
|
||||
}
|
||||
if (S_ISDIR(stat_buf.st_mode)) {
|
||||
if (S_ISLNK(lstat_buf.st_mode)) {
|
||||
char rpath_buf[ MAXPATHLEN+1 ];
|
||||
char *rpath;
|
||||
|
||||
rpath = _tt_get_realpath( (char *)epath, rpath_buf );
|
||||
if (rpath == NULL) {
|
||||
fprintf( stderr,
|
||||
"%s: realpath(\"%s\"): %s\n",
|
||||
our_process_name,(char *)epath,
|
||||
strerror(errno) );
|
||||
} else {
|
||||
_Tt_string rp( rpath );
|
||||
realtrees->push( rp );
|
||||
}
|
||||
}
|
||||
append_real_subtrees( realtrees, epath );
|
||||
}
|
||||
}
|
||||
if (closedir( dirp ) != 0) {
|
||||
fprintf( stderr, "%s: closedir(\"%s\"): %s\n",
|
||||
our_process_name, (char *)path, strerror(errno) );
|
||||
}
|
||||
|
||||
} /* append_real_subtrees() */
|
||||
|
||||
/*
|
||||
* basename() - Return the last component of a pathname.
|
||||
*/
|
||||
char *basename( char *pathname ) {
|
||||
char *the_basename;
|
||||
|
||||
the_basename = strrchr( pathname, '/' );
|
||||
if (the_basename == NULL) {
|
||||
the_basename = pathname;
|
||||
} else {
|
||||
the_basename++; // Don't want the '/'
|
||||
}
|
||||
return the_basename;
|
||||
}
|
||||
|
||||
/*
|
||||
* dirname() - Return the pathname minus the basename, or "." if the
|
||||
* basename is all there is. Caller is responsible for free()ing
|
||||
* the storage returned.
|
||||
*/
|
||||
char *dirname( char *pathname ) {
|
||||
char *the_basename;
|
||||
char *the_dirname;
|
||||
|
||||
the_basename = strrchr( pathname, '/' );
|
||||
if (the_basename == NULL) {
|
||||
the_dirname = (char *)malloc((size_t)(2 * sizeof(char)));
|
||||
the_dirname[0] = '.';
|
||||
the_dirname[1] = '\0';
|
||||
} else {
|
||||
int len = the_basename - pathname;
|
||||
the_dirname = (char *)
|
||||
malloc((size_t)( sizeof(char) * (len + 1)));
|
||||
strncpy( the_dirname, pathname, len );
|
||||
the_dirname[ len ] = '\0';
|
||||
}
|
||||
return the_dirname;
|
||||
}
|
||||
33
cde/lib/tt/bin/tttar/tttar_file_utils.h
Normal file
33
cde/lib/tt/bin/tttar/tttar_file_utils.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*%% (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: tttar_file_utils.h /main/3 1995/10/20 17:00:34 rswiston $ */
|
||||
/*
|
||||
* tttar_file_utils.h - File utilities for the LS/TT archive tool.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _LSTAR_FILE_UTILS_H
|
||||
#define _LSTAR_FILE_UTILS_H
|
||||
|
||||
#include "tttar_string_map.h"
|
||||
|
||||
/*
|
||||
* Procedure declarations
|
||||
*/
|
||||
|
||||
bool_t is_child_in( _Tt_string path, _Tt_string_list_ptr paths );
|
||||
bool_t is_child_of( _Tt_string path, _Tt_string pathtree );
|
||||
_Tt_string new_name( _Tt_string old_name,
|
||||
Lstar_string_map_list_ptr renamings );
|
||||
_Tt_string_list_ptr dir_entries( _Tt_string path, bool_t follow_symlinks );
|
||||
_Tt_string_list_ptr realtrees( _Tt_string_list_ptr paths,
|
||||
bool_t follow_symlinks );
|
||||
void append_real_subtrees( _Tt_string_list_ptr realtrees,
|
||||
_Tt_string path );
|
||||
char *basename( char *pathname );
|
||||
char *dirname( char *pathname );
|
||||
|
||||
#endif /* _LSTAR_FILE_UTILS_H */
|
||||
337
cde/lib/tt/bin/tttar/tttar_spec.C
Normal file
337
cde/lib/tt/bin/tttar/tttar_spec.C
Normal file
@@ -0,0 +1,337 @@
|
||||
//%% (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: tttar_spec.C /main/3 1995/10/20 17:00:42 rswiston $
|
||||
/*
|
||||
* tttar_spec.cc - Implementation of specs for Link Service/ToolTalk archiving
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(__osf__)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#if defined (USL) || defined(__uxp__)
|
||||
#include "tt_options.h"
|
||||
#if defined(OPT_BUG_USL) || defined(OPT_BUG_UXP)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <osfcn.h>
|
||||
#endif /* if defined(OPT_BUG_USL) || defined(OPT_BUG_UXP) */
|
||||
#else
|
||||
#include <osfcn.h>
|
||||
#endif
|
||||
#endif /* __osf__ */
|
||||
#include "api/c/tt_c.h"
|
||||
#include "util/tt_iostream.h"
|
||||
#include "tttar_utils.h"
|
||||
#include "tttar_spec.h"
|
||||
|
||||
/*
|
||||
* Lstar_spec::Lstar_spec()
|
||||
*/
|
||||
Lstar_spec::
|
||||
Lstar_spec()
|
||||
{
|
||||
_props = new Lstar_spec_prop_list();
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec::Lstar_spec() -
|
||||
*/
|
||||
Lstar_spec::
|
||||
Lstar_spec( _Tt_string id, _Tt_string path )
|
||||
{
|
||||
_id = id;
|
||||
_path = path;
|
||||
_props = new Lstar_spec_prop_list();
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec::~Lstar_spec()
|
||||
*/
|
||||
Lstar_spec::
|
||||
~Lstar_spec()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec::xdr()
|
||||
*/
|
||||
bool_t Lstar_spec::
|
||||
xdr( XDR *xdrs )
|
||||
{
|
||||
if (! this->_id.xdr(xdrs)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (! this->_path.xdr(xdrs)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (! this->_type.xdr(xdrs)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (! this->_props.xdr(xdrs)) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec::read_self() - Read from ToolTalk everything we need to know
|
||||
* about ourselves in order to archive ourself.
|
||||
*/
|
||||
Tt_status Lstar_spec::
|
||||
read_self()
|
||||
{
|
||||
/*
|
||||
* Get the spec's type.
|
||||
*/
|
||||
note_ptr_err( tt_spec_type( (char *)_id ));
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
return err_noted;
|
||||
}
|
||||
_type = ptr_returned;
|
||||
/*
|
||||
* Get how many properties are on the spec.
|
||||
*/
|
||||
note_int_err( tt_spec_propnames_count( (char *)_id ));
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
return err_noted;
|
||||
}
|
||||
int num_props = int_returned;
|
||||
/*
|
||||
* Push the spec's properties onto our list in reverse order,
|
||||
* to preserve the admittedly meaningless order they had.
|
||||
*/
|
||||
for (int n = num_props - 1; n >= 0; n--) {
|
||||
note_ptr_err( tt_spec_propname( (char *)_id, n ));
|
||||
switch (err_noted) {
|
||||
case TT_ERR_OBJID:
|
||||
case TT_ERR_DBAVAIL:
|
||||
return err_noted;
|
||||
case TT_ERR_NUM:
|
||||
continue;
|
||||
case TT_ERR_DBEXIST:
|
||||
default:
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
return err_noted;
|
||||
}
|
||||
}
|
||||
_Tt_string propname = ptr_returned;
|
||||
Lstar_spec_prop_ptr prop_ptr;
|
||||
|
||||
prop_ptr = new Lstar_spec_prop( _id, propname );
|
||||
this->_props->push( prop_ptr );
|
||||
}
|
||||
return err_noted;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec::write_self() - Recreate a spec like the one we are, returning
|
||||
* the id of the spec created. The string returned must be freed
|
||||
* using tt_free().
|
||||
*/
|
||||
char * Lstar_spec::
|
||||
write_self( _Tt_string where, bool_t preserve__props, Tt_status *err )
|
||||
{
|
||||
char *spec_created = NULL;
|
||||
_Tt_string path;
|
||||
|
||||
if (this->_path.len() <= 0) {
|
||||
*err = TT_ERR_PATH;
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
* TO_DO: tt_spec_create() won't convert /./ to / in a path
|
||||
* if the path doesn't exist.
|
||||
*/
|
||||
if (this->_path.left(2) == "./") {
|
||||
this->_path = this->_path.right( _path.len() - 2 );
|
||||
}
|
||||
/*
|
||||
* If the archived path is absolute, ignore <where>.
|
||||
*/
|
||||
if (this->_path[0] == '/') {
|
||||
path = this->_path;
|
||||
} else {
|
||||
path = where.cat( "/" ).cat( this->_path );
|
||||
}
|
||||
note_ptr_err( tt_spec_create( (char *)path ));
|
||||
*err = err_noted;
|
||||
spec_created = ptr_returned;
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
return spec_created;
|
||||
}
|
||||
note_err( tt_spec_type_set( spec_created, (char *)this->_type ));
|
||||
*err = err_noted;
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
return spec_created;
|
||||
}
|
||||
Lstar_spec_prop_list_cursor prop_cursor( this->_props );
|
||||
while (prop_cursor.next()) {
|
||||
*err = prop_cursor->write_self( spec_created, preserve__props );
|
||||
}
|
||||
note_err( tt_spec_write( spec_created ));
|
||||
*err = err_noted;
|
||||
return spec_created;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec::print()
|
||||
*/
|
||||
void Lstar_spec::
|
||||
print( FILE *fs ) const
|
||||
{
|
||||
fprintf( fs, "spec id: " );
|
||||
this->_id.print( fs );
|
||||
fprintf( fs, "\nspec type: " );
|
||||
this->_type.print( fs );
|
||||
fprintf( fs, "\nspec path: " );
|
||||
this->_path.print( fs );
|
||||
fprintf( fs, "\n" );
|
||||
this->_props->print(Lstar_spec::do_print, fs );
|
||||
fprintf( fs, "\n" );
|
||||
}
|
||||
|
||||
implement_list_of(Lstar_spec_prop)
|
||||
|
||||
/*
|
||||
* Lstar_spec_prop::Lstar_spec_prop()
|
||||
*/
|
||||
Lstar_spec_prop::
|
||||
Lstar_spec_prop()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec_prop::Lstar_spec_prop()
|
||||
*/
|
||||
Lstar_spec_prop::
|
||||
Lstar_spec_prop( _Tt_string id, _Tt_string propname )
|
||||
{
|
||||
_propname = propname;
|
||||
_values = new _Tt_string_list();
|
||||
/*
|
||||
* Get how many values are in the spec's property.
|
||||
*/
|
||||
note_int_err( tt_spec_prop_count( (char *)id, (char *)propname ));
|
||||
switch (err_noted) {
|
||||
case TT_ERR_PROPNAME:
|
||||
case TT_ERR_OBJID:
|
||||
case TT_ERR_DBAVAIL:
|
||||
return;
|
||||
case TT_ERR_DBEXIST:
|
||||
default:
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
int num_values = int_returned;
|
||||
/*
|
||||
* Push the property's values onto our list in reverse order,
|
||||
* to preserve the order they had.
|
||||
*/
|
||||
for (int n = num_values - 1; n >= 0; n--) {
|
||||
int len;
|
||||
unsigned char *value;
|
||||
|
||||
note_err( tt_spec_bprop( (char *)id, (char *)propname, n, &value, &len ));
|
||||
switch (err_noted) {
|
||||
case TT_ERR_PROPNAME:
|
||||
case TT_ERR_OBJID:
|
||||
case TT_ERR_DBAVAIL:
|
||||
return;
|
||||
case TT_ERR_NUM:
|
||||
continue;
|
||||
case TT_ERR_DBEXIST:
|
||||
default:
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
_Tt_string val( value, len );
|
||||
this->_values->push( val );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec_prop::~Lstar_spec_prop()
|
||||
*/
|
||||
Lstar_spec_prop::
|
||||
~Lstar_spec_prop()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec_prop::xdr()
|
||||
*/
|
||||
bool_t Lstar_spec_prop::
|
||||
xdr( XDR *xdrs )
|
||||
{
|
||||
if (! this->_propname.xdr(xdrs)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (! this->_values.xdr(xdrs)) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec_prop::write_self() - Write this prop onto the given spec.
|
||||
*/
|
||||
Tt_status Lstar_spec_prop::
|
||||
write_self( char *spec_id, bool_t preserve__props )
|
||||
{
|
||||
/*
|
||||
* If we're not root and this is a blessed property,
|
||||
* do not attempt to write it.
|
||||
* Insert link here to policy statement about prop names in tt_c.h.
|
||||
*/
|
||||
if ( (_propname[0] == '_')
|
||||
&& ( (! preserve__props)
|
||||
|| (getuid() != 0)))
|
||||
{
|
||||
return TT_OK;
|
||||
}
|
||||
_Tt_string_list_cursor value_cursor( this->_values );
|
||||
char *val;
|
||||
int len;
|
||||
while (value_cursor.next()) {
|
||||
val = (char *)(*value_cursor);
|
||||
len = (*value_cursor).len();
|
||||
note_err( tt_spec_bprop_add( spec_id, (char *)_propname,
|
||||
(unsigned char *)val, len));
|
||||
if (IS_TT_ERR(err_noted)) {
|
||||
return err_noted;
|
||||
}
|
||||
}
|
||||
return err_noted;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec_prop::print()
|
||||
*/
|
||||
void Lstar_spec_prop::
|
||||
print( FILE *fs ) const
|
||||
{
|
||||
this->_propname.print( fs );
|
||||
fprintf( fs, ": " );
|
||||
this->_values->print(_tt_string_print,fs);
|
||||
fprintf( fs, "\n" );
|
||||
}
|
||||
|
||||
void Lstar_spec::
|
||||
do_print(const _Tt_ostream &os, const _Tt_object *obj)
|
||||
{
|
||||
((Lstar_spec *)obj)->print(os.theFILE());
|
||||
}
|
||||
|
||||
void Lstar_spec_prop::
|
||||
do_print(FILE *fs, const _Tt_object *obj)
|
||||
{
|
||||
((Lstar_spec_prop *)obj)->print(fs);
|
||||
}
|
||||
|
||||
60
cde/lib/tt/bin/tttar/tttar_spec.h
Normal file
60
cde/lib/tt/bin/tttar/tttar_spec.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*%% (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: tttar_spec.h /main/3 1995/10/20 17:00:53 rswiston $ */
|
||||
/*
|
||||
* tttar_spec.h - Interface to specs for the Link Service/ToolTalk archive tool
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _LSTAR_SPEC_H
|
||||
#define _LSTAR_SPEC_H
|
||||
|
||||
declare_list_of(Lstar_spec_prop)
|
||||
|
||||
class Lstar_spec : public _Tt_object {
|
||||
public:
|
||||
Lstar_spec();
|
||||
Lstar_spec( _Tt_string id, _Tt_string path );
|
||||
~Lstar_spec();
|
||||
|
||||
_Tt_string id() {return _id;}
|
||||
_Tt_string path() {return _path;}
|
||||
void path_set( _Tt_string p ) {_path = p;}
|
||||
bool_t xdr( XDR *xdrs );
|
||||
Tt_status read_self();
|
||||
char *write_self( _Tt_string where,
|
||||
bool_t preserve__props,
|
||||
Tt_status *err );
|
||||
void print(FILE *fs = stdout) const;
|
||||
|
||||
static void do_print(const _Tt_ostream &os,
|
||||
const _Tt_object *obj);
|
||||
private:
|
||||
_Tt_string _id;
|
||||
_Tt_string _type;
|
||||
_Tt_string _path;
|
||||
Lstar_spec_prop_list_ptr _props;
|
||||
};
|
||||
|
||||
class Lstar_spec_prop : public _Tt_object {
|
||||
public:
|
||||
Lstar_spec_prop();
|
||||
Lstar_spec_prop( _Tt_string spec_id, _Tt_string propname );
|
||||
~Lstar_spec_prop();
|
||||
|
||||
bool_t xdr( XDR *xdrs );
|
||||
Tt_status write_self( char *spec_id,
|
||||
bool_t preserve__props);
|
||||
void print(FILE *fs = stdout) const;
|
||||
static void do_print(FILE *fs, const _Tt_object *obj);
|
||||
|
||||
private:
|
||||
_Tt_string _propname;
|
||||
_Tt_string_list_ptr _values;
|
||||
};
|
||||
|
||||
#endif /* _LSTAR_SPEC_H */
|
||||
45
cde/lib/tt/bin/tttar/tttar_spec_map.C
Normal file
45
cde/lib/tt/bin/tttar/tttar_spec_map.C
Normal file
@@ -0,0 +1,45 @@
|
||||
//%% (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: tttar_spec_map.C /main/3 1995/10/20 17:01:06 rswiston $
|
||||
/*
|
||||
* tttar_spec_map.cc - Implements mappings of old specs to new specs.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tttar_spec_map.h"
|
||||
|
||||
implement_list_of(Lstar_spec_map)
|
||||
implement_table_of(Lstar_spec_map,old_id,_Tt_string)
|
||||
|
||||
/*
|
||||
* Lstar_spec_map::Lstar_spec_map
|
||||
*/
|
||||
Lstar_spec_map::
|
||||
Lstar_spec_map()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec_map::~Lstar_spec_map()
|
||||
*/
|
||||
Lstar_spec_map::
|
||||
~Lstar_spec_map()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_spec_map::print()
|
||||
*/
|
||||
void Lstar_spec_map::
|
||||
print( FILE *fs ) const
|
||||
{
|
||||
this->_old_id->print(fs);
|
||||
fprintf( fs, " (" );
|
||||
this->_path->print(fs);
|
||||
fprintf( fs, " ) -> " );
|
||||
this->_new_id->print(fs);
|
||||
}
|
||||
51
cde/lib/tt/bin/tttar/tttar_spec_map.h
Normal file
51
cde/lib/tt/bin/tttar/tttar_spec_map.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*%% (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: tttar_spec_map.h /main/3 1995/10/20 17:01:17 rswiston $ */
|
||||
/*
|
||||
* tttar_spec_map.h - Interface to spec maps for the LS/TT archive tool
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _LSTAR_SPEC_MAP_H
|
||||
#define _LSTAR_SPEC_MAP_H
|
||||
|
||||
#include <util/tt_object.h>
|
||||
#include <util/tt_list.h>
|
||||
#include <util/tt_string.h>
|
||||
#include <util/tt_table.h>
|
||||
|
||||
/*
|
||||
* SET() - Set a private member to the formal parameter of its set method.
|
||||
*/
|
||||
#define SET(identifier) \
|
||||
{ \
|
||||
name2(_,identifier) = identifier; \
|
||||
}
|
||||
|
||||
class Lstar_spec_map : public _Tt_object {
|
||||
public:
|
||||
Lstar_spec_map();
|
||||
~Lstar_spec_map();
|
||||
|
||||
_Tt_string old_id() {return _old_id;};
|
||||
_Tt_string new_id() {return _new_id;};
|
||||
_Tt_string path() {return _path;};
|
||||
void old_id_set( _Tt_string old_id ) SET(old_id);
|
||||
void new_id_set( _Tt_string new_id ) SET(new_id);
|
||||
void path_set( _Tt_string path ) SET(path);
|
||||
void print(FILE *fs = stdout) const;
|
||||
|
||||
private:
|
||||
_Tt_string _old_id;
|
||||
_Tt_string _new_id;
|
||||
_Tt_string _path;
|
||||
};
|
||||
|
||||
declare_list_of(Lstar_spec_map)
|
||||
declare_table_of(Lstar_spec_map,old_id,_Tt_string)
|
||||
|
||||
#endif /* _LSTAR_SPEC_MAP_H */
|
||||
52
cde/lib/tt/bin/tttar/tttar_string_map.C
Normal file
52
cde/lib/tt/bin/tttar/tttar_string_map.C
Normal file
@@ -0,0 +1,52 @@
|
||||
//%% (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: tttar_string_map.C /main/3 1995/10/20 17:01:27 rswiston $
|
||||
/*
|
||||
* tttar_string_map.cc - Implements mappings of old specs to new specs.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tttar_string_map.h"
|
||||
#include "util/tt_iostream.h"
|
||||
|
||||
implement_list_of(Lstar_string_map)
|
||||
implement_table_of(Lstar_string_map)
|
||||
|
||||
_Tt_string
|
||||
Lstar_string_map_old_string(_Tt_object_ptr &o)
|
||||
{
|
||||
return(((Lstar_string_map *)o.c_pointer())->old_string());
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_string_map::Lstar_string_map
|
||||
*/
|
||||
Lstar_string_map::
|
||||
Lstar_string_map()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_string_map::~Lstar_string_map()
|
||||
*/
|
||||
Lstar_string_map::
|
||||
~Lstar_string_map()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Lstar_string_map::print()
|
||||
*/
|
||||
void Lstar_string_map::
|
||||
print( FILE *fs ) const
|
||||
{
|
||||
this->_old_string->print(fs);
|
||||
fprintf( fs, " (" );
|
||||
this->_extra->print(fs);
|
||||
fprintf( fs, " ) -> " );
|
||||
this->_new_string->print(fs);
|
||||
}
|
||||
51
cde/lib/tt/bin/tttar/tttar_string_map.h
Normal file
51
cde/lib/tt/bin/tttar/tttar_string_map.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*%% (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: tttar_string_map.h /main/3 1995/10/20 17:01:35 rswiston $ */
|
||||
/*
|
||||
* tttar_string_map.h - Interface to spec maps for the LS/TT archive tool
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _LSTAR_STRING_MAP_H
|
||||
#define _LSTAR_STRING_MAP_H
|
||||
|
||||
#include <util/tt_object.h>
|
||||
#include <util/tt_list.h>
|
||||
#include <util/tt_string.h>
|
||||
#include <util/tt_table.h>
|
||||
|
||||
/*
|
||||
* SET() - Set a private member to the formal parameter of its set method.
|
||||
*/
|
||||
#define SET(identifier) \
|
||||
{ \
|
||||
name2(_,identifier) = identifier; \
|
||||
}
|
||||
|
||||
class Lstar_string_map : public _Tt_object {
|
||||
public:
|
||||
Lstar_string_map();
|
||||
~Lstar_string_map();
|
||||
|
||||
_Tt_string &old_string() {return _old_string;};
|
||||
_Tt_string new_string() {return _new_string;};
|
||||
_Tt_string extra() {return _extra;};
|
||||
void old_string_set( _Tt_string old_string ) SET(old_string);
|
||||
void new_string_set( _Tt_string new_string ) SET(new_string);
|
||||
void extra_set( _Tt_string extra ) SET(extra);
|
||||
void print(FILE *fs = stdout) const;
|
||||
|
||||
private:
|
||||
_Tt_string _old_string;
|
||||
_Tt_string _new_string;
|
||||
_Tt_string _extra;
|
||||
};
|
||||
|
||||
declare_list_of(Lstar_string_map)
|
||||
declare_table_of(Lstar_string_map)
|
||||
_Tt_string Lstar_string_map_old_string(_Tt_object_ptr &o);
|
||||
#endif /* _LSTAR_STRING_MAP_H */
|
||||
95
cde/lib/tt/bin/tttar/tttar_utils.C
Normal file
95
cde/lib/tt/bin/tttar/tttar_utils.C
Normal file
@@ -0,0 +1,95 @@
|
||||
//%% (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: tttar_utils.C /main/3 1995/10/20 17:01:44 rswiston $
|
||||
/*
|
||||
* tttar_utils.cc - Utilities for the Link Service archive tool.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <api/c/tt_c.h>
|
||||
#include <util/tt_enumname.h>
|
||||
#include "tttar_utils.h"
|
||||
|
||||
/*
|
||||
* External Variables
|
||||
*/
|
||||
extern int verbosity;
|
||||
|
||||
/*
|
||||
* Global Variables
|
||||
*/
|
||||
Tt_status err_noted; // Used by note_err() macro.
|
||||
char *ptr_returned; // Used by note_ptr_err() macro.
|
||||
void *voidptr_returned; // Used by note_voidptr_err() macro.
|
||||
Tt_message msg_returned; // Used by note_msg_err() macro.
|
||||
int int_returned; // Used by note_int_err() macro.
|
||||
|
||||
#define make_printable_on_1_line( cp ) \
|
||||
while (*cp != '\0') { \
|
||||
if ( (*cp == '\n') \
|
||||
|| (*cp == '\r') \
|
||||
|| (! isprint((unsigned char)*cp))) \
|
||||
{ \
|
||||
*cp = '_'; \
|
||||
} \
|
||||
cp++; \
|
||||
}
|
||||
|
||||
/*
|
||||
* note_error() - Note a failed ToolTalk call on stderr.
|
||||
*/
|
||||
Tt_status
|
||||
note_error( Tt_status error, char *expression, char *file, int line ) {
|
||||
if (! IS_TT_ERR(error)) {
|
||||
return error;
|
||||
}
|
||||
if (verbosity >= 1) {
|
||||
(void) fprintf( stderr,
|
||||
"%s: %s:%d:%s => %s %s\n",
|
||||
our_process_name, file, line, expression,
|
||||
_tt_enumname((Tt_status)error),
|
||||
tt_status_message(error)
|
||||
);
|
||||
} else {
|
||||
(void) fprintf( stderr, "%s: %s\n", our_process_name,
|
||||
tt_status_message(error) );
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* my_tt_free() - Wrap tt_free().
|
||||
*/
|
||||
void
|
||||
my_tt_free( caddr_t p ) {
|
||||
tt_free(p);
|
||||
}
|
||||
|
||||
/*
|
||||
* my_tt_release() - Wrap tt_release().
|
||||
*/
|
||||
void
|
||||
my_tt_release( int mark ) {
|
||||
tt_release(mark);
|
||||
}
|
||||
|
||||
/*
|
||||
* in_list() - Is this string in this list?
|
||||
*/
|
||||
bool_t
|
||||
in_list( _Tt_string s, _Tt_string_list_ptr list )
|
||||
{
|
||||
_Tt_string_list_cursor sc( list );
|
||||
while (sc.next()) {
|
||||
if ((*sc) == s) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
133
cde/lib/tt/bin/tttar/tttar_utils.h
Normal file
133
cde/lib/tt/bin/tttar/tttar_utils.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/*%% (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: tttar_utils.h /main/3 1995/10/20 17:01:53 rswiston $ */
|
||||
/*
|
||||
* tttar_utils.h - Utilities for the ToolTalk archive tool.
|
||||
*
|
||||
* Copyright (c) 1990 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
#ifndef _LSTAR_UTILS_H
|
||||
#define _LSTAR_UTILS_H
|
||||
|
||||
#include <api/c/tt_c.h>
|
||||
#include <util/tt_string.h>
|
||||
|
||||
|
||||
/*
|
||||
* External Variables
|
||||
*/
|
||||
|
||||
extern Tt_status err_noted; // Used by note_err() macro.
|
||||
extern char *ptr_returned; // Used by note_ptr_err() macro.
|
||||
extern void *voidptr_returned; // Used by note_voidptr_err() macro.
|
||||
extern Tt_message msg_returned; // Used by note_msg_err() macro.
|
||||
extern int int_returned; // Used by note_int_err() macro.
|
||||
extern char our_process_name[];
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
|
||||
/*
|
||||
* STRING_EQUAL() - Check 2 strings for equality.
|
||||
*/
|
||||
#define STRING_EQUAL(s1,s2) ( strcmp( s1, s2 ) == 0 )
|
||||
|
||||
/*
|
||||
* NULL_OR_EMPTY() - Is this string ptr NULL or empty?
|
||||
*/
|
||||
#define NULL_OR_EMPTY(p) (( (char *)p == NULL ) || ( *(char *)p == '\0' ))
|
||||
|
||||
/*
|
||||
* IS_TT_ERR() - Is this Tt_status neither TT_OK nor a TT_WARN?
|
||||
*/
|
||||
#define IS_TT_ERR(err) ( err > TT_WRN_LAST )
|
||||
|
||||
/*
|
||||
* stringify() - Turn a macro argument into a string.
|
||||
* gross Reiserism, use # in ANSI C
|
||||
*/
|
||||
#if defined(__STDC__)
|
||||
#define stringify(s) #s
|
||||
#else
|
||||
/* gross Reiserism, use # in ANSI C */
|
||||
#define stringify(s) "s"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* note_err() - Note any error corresponding to this Tt_status
|
||||
* expression, returning the error code
|
||||
*/
|
||||
#define note_err(expression) \
|
||||
( ( TT_OK == ( err_noted = expression)) \
|
||||
? TT_OK \
|
||||
: note_error( err_noted, stringify(expression), \
|
||||
__FILE__, __LINE__ ))
|
||||
|
||||
|
||||
/*
|
||||
* note_ptr_err() - Assign the (char *) expression to ptr_returned,
|
||||
* noting any error on stderr if error isn't TT_OK, and
|
||||
* return the error code
|
||||
*/
|
||||
#define note_ptr_err(expression) \
|
||||
( ( TT_OK \
|
||||
== ( err_noted = \
|
||||
tt_pointer_error(ptr_returned = expression))) \
|
||||
? TT_OK \
|
||||
: note_error( err_noted, stringify(expression), \
|
||||
__FILE__, __LINE__ ))
|
||||
|
||||
/*
|
||||
* note_int_err() - Assign the (int) expression to int_returned,
|
||||
* noting any error on stderr if error isn't TT_OK, and
|
||||
* return the error code
|
||||
*/
|
||||
#define note_int_err(expression) \
|
||||
( ( TT_OK \
|
||||
== ( err_noted = \
|
||||
tt_int_error(int_returned = expression))) \
|
||||
? TT_OK \
|
||||
: note_error( err_noted, stringify(expression), \
|
||||
__FILE__, __LINE__ ))
|
||||
|
||||
/*
|
||||
* note_msg_err() - Assign the expression to msg_returned,
|
||||
* noting any error on stderr if error isn't TT_OK, and
|
||||
* return the error code
|
||||
*/
|
||||
#define note_msg_err(expression) \
|
||||
( ( TT_OK \
|
||||
== ( err_noted = \
|
||||
tt_pointer_error(msg_returned = expression))) \
|
||||
? TT_OK \
|
||||
: note_error( err_noted, stringify(expression), \
|
||||
__FILE__, __LINE__ ))
|
||||
|
||||
/*
|
||||
* note_voidptr_err() - Assign the expression to voidptr_returned,
|
||||
* noting any error on stderr if error isn't TT_OK, and
|
||||
* return the error code
|
||||
*/
|
||||
#define note_voidptr_err(expression) \
|
||||
( ( TT_OK \
|
||||
== ( err_noted = \
|
||||
tt_pointer_error(voidptr_returned = expression))) \
|
||||
? TT_OK \
|
||||
: note_error( err_noted, stringify(expression), \
|
||||
__FILE__, __LINE__ ))
|
||||
|
||||
/*
|
||||
* Procedure declarations
|
||||
*/
|
||||
|
||||
Tt_status note_error( Tt_status error, char *expression,
|
||||
char *file, int line );
|
||||
void my_tt_free( caddr_t p );
|
||||
void my_tt_release( int mark );
|
||||
bool_t in_list( _Tt_string s, _Tt_string_list_ptr list );
|
||||
|
||||
#endif /* _LSTAR_UTILS_H */
|
||||
Reference in New Issue
Block a user