1 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
2 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
3 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
4 //%% (c) Copyright 1993, 1994 Novell, Inc.
5 //%% $XConsortium: tttar.C /main/4 1995/10/20 16:59:46 rswiston $
7 * tttar.cc - Link Service/ToolTalk object archive tool.
9 * Copyright (c) 1990 by Sun Microsystems, Inc.
16 #include <sys/param.h>
21 #if !defined(USL) && !defined(__uxp__)
28 #include "util/tt_port.h"
29 #include "util/copyright.h"
30 #include "tt_options.h"
33 #if defined(OPT_BUG_USL) || defined(OPT_BUG_UXP)
40 static char PatchID[] = "Patch Id: 100626_03.";
41 static int Patch_ID100626_03;
48 char our_process_name[80];
55 main(int argc, char **argv)
57 archiver *tttar = new archiver( argv[0] );
58 _Tt_string tttarfile_name;
60 bool_t tttar_worked = FALSE;
61 bool_t should_tttar = FALSE;
63 setlocale( LC_ALL, "" );
65 tttar->parse_args( argc, argv );
66 sprintf( our_process_name, "%s", (char *)tttar->process_name());
67 verbosity = tttar->verbosity();
69 if (tttar->should_tar()) {
72 * Create a temporary directory to which we can
73 * chdir() in order to create or extract the
74 * tttarfile for or from the tarfile.
76 tttardir = tempnam_result = tempnam(NULL, "tttardir");
78 if (mkdir( (char *)tttardir, S_IRWXU ) == 0) {
79 tttarfile_name = tttardir.cat( "/tttarfile" );
81 if ( (tttar->mode() == EXTRACT)
82 || (tttar->mode() == LIST))
84 tttar->do_tar( tttardir, FALSE );
86 * Extract the tttarfile silently
88 int old_verbosity = tttar->verbosity();
89 Archive_mode old_mode = tttar->mode();
90 tttar->verbosity_set( 0 );
91 tttar->mode_set( EXTRACT );
93 * If we're not extracting from stdin, we
94 * can invoke tar(1) again. Otherwise,
95 * do_tar() was smart enough to extract
96 * the tttarfile into the cwd the first
99 if (! tttar->only_1_look_at_tarfile()) {
100 tttar->do_tar( tttardir, TRUE );
101 } else if (tttar->mode() == EXTRACT) {
103 * The tttarfile was already
104 * extracted into cwd.
106 tttarfile_name = "tttarfile";
108 tttar->verbosity_set( old_verbosity );
109 tttar->mode_set( old_mode );
113 tttarfile_name = tttar->tarfile_arg();
118 tttar_worked = tttar->do_tttar( (char *)tttarfile_name,
119 tttar->should_tar() );
122 if (tttar->should_tar() && (tttar->mode() == CREATE)) {
123 tttar->do_tar( tttardir, tttar_worked );
126 if (tttar->should_tar()) {
128 * Remove any temporary tttarfile.
130 int status = unlink( (char *)tttarfile_name );
132 * We can't really expect an tttarfile in every tarfile,
133 * so don't complain if there isn't one to remove.
135 fprintf( stderr, "%s: %s: %s\n",
136 our_process_name, (char *)tttarfile_name,
140 status = rmdir( (char *)tttardir );
142 fprintf( stderr, "%s: %s: %s\n",
143 our_process_name, (char *)tttardir,