2 * cat-cmd.c -- Print the content of a file or URL.
4 * ====================================================================
5 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 /* ==================================================================== */
25 #include "svn_pools.h"
26 #include "svn_client.h"
27 #include "svn_error.h"
33 /* This implements the `svn_opt_subcommand_t' interface. */
35 svn_cl__cat(apr_getopt_t
*os
,
39 svn_cl__opt_state_t
*opt_state
= ((svn_cl__cmd_baton_t
*) baton
)->opt_state
;
40 svn_client_ctx_t
*ctx
= ((svn_cl__cmd_baton_t
*) baton
)->ctx
;
41 apr_array_header_t
*targets
;
44 apr_pool_t
*subpool
= svn_pool_create(pool
);
46 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets
, os
,
50 /* Cat cannot operate on an implicit '.' so a filename is required */
52 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS
, 0, NULL
);
54 SVN_ERR(svn_stream_for_stdout(&out
, pool
));
56 for (i
= 0; i
< targets
->nelts
; i
++)
58 const char *target
= APR_ARRAY_IDX(targets
, i
, const char *);
60 svn_opt_revision_t peg_revision
;
62 svn_pool_clear(subpool
);
63 SVN_ERR(svn_cl__check_cancel(ctx
->cancel_baton
));
65 /* Get peg revisions. */
66 SVN_ERR(svn_opt_parse_path(&peg_revision
, &truepath
, target
,
69 SVN_ERR(svn_cl__try(svn_client_cat2(out
, truepath
, &peg_revision
,
70 &(opt_state
->start_revision
),
72 NULL
, opt_state
->quiet
,
73 SVN_ERR_UNVERSIONED_RESOURCE
,
74 SVN_ERR_ENTRY_NOT_FOUND
,
75 SVN_ERR_CLIENT_IS_DIRECTORY
,
78 svn_pool_destroy(subpool
);