2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $XConsortium: tttar.C /main/4 1995/10/20 16:59:46 rswiston $
29 * tttar.cc - Link Service/ToolTalk object archive tool.
31 * Copyright (c) 1990 by Sun Microsystems, Inc.
38 #include <sys/param.h>
40 #if defined(__osf__) || defined(linux) || defined(sun) || defined(CSRG_BASED)
43 #if !defined(USL) && !defined(sun)
50 #include "util/tt_port.h"
51 #include "util/copyright.h"
52 #include "tt_options.h"
55 #if defined(OPT_BUG_USL)
62 static char PatchID[] = "Patch Id: 100626_03.";
63 static int Patch_ID100626_03;
70 char our_process_name[80];
77 main(int argc, char **argv)
79 archiver *tttar = new archiver( argv[0] );
80 _Tt_string tttarfile_name;
82 bool_t tttar_worked = FALSE;
83 bool_t should_tttar = FALSE;
85 setlocale( LC_ALL, "" );
87 tttar->parse_args( argc, argv );
88 sprintf( our_process_name, "%s", (char *)tttar->process_name());
89 verbosity = tttar->verbosity();
91 if (tttar->should_tar()) {
94 * Create a temporary directory to which we can
95 * chdir() in order to create or extract the
96 * tttarfile for or from the tarfile.
98 tttardir = tempnam_result = tempnam(NULL, "tttardir");
100 if (mkdir( (char *)tttardir, S_IRWXU ) == 0) {
101 tttarfile_name = tttardir.cat( "/tttarfile" );
103 if ( (tttar->mode() == EXTRACT)
104 || (tttar->mode() == LIST))
106 tttar->do_tar( tttardir, FALSE );
108 * Extract the tttarfile silently
110 int old_verbosity = tttar->verbosity();
111 Archive_mode old_mode = tttar->mode();
112 tttar->verbosity_set( 0 );
113 tttar->mode_set( EXTRACT );
115 * If we're not extracting from stdin, we
116 * can invoke tar(1) again. Otherwise,
117 * do_tar() was smart enough to extract
118 * the tttarfile into the cwd the first
121 if (! tttar->only_1_look_at_tarfile()) {
122 tttar->do_tar( tttardir, TRUE );
123 } else if (tttar->mode() == EXTRACT) {
125 * The tttarfile was already
126 * extracted into cwd.
128 tttarfile_name = "tttarfile";
130 tttar->verbosity_set( old_verbosity );
131 tttar->mode_set( old_mode );
135 tttarfile_name = tttar->tarfile_arg();
140 tttar_worked = tttar->do_tttar( (char *)tttarfile_name,
141 tttar->should_tar() );
144 if (tttar->should_tar() && (tttar->mode() == CREATE)) {
145 tttar->do_tar( tttardir, tttar_worked );
148 if (tttar->should_tar()) {
150 * Remove any temporary tttarfile.
152 int status = unlink( (char *)tttarfile_name );
154 * We can't really expect an tttarfile in every tarfile,
155 * so don't complain if there isn't one to remove.
157 fprintf( stderr, "%s: %s: %s\n",
158 our_process_name, (char *)tttarfile_name,
162 status = rmdir( (char *)tttardir );
164 fprintf( stderr, "%s: %s: %s\n",
165 our_process_name, (char *)tttardir,