1251881Speter/**
2251881Speter * @copyright
3251881Speter * ====================================================================
4251881Speter *    Licensed to the Apache Software Foundation (ASF) under one
5251881Speter *    or more contributor license agreements.  See the NOTICE file
6251881Speter *    distributed with this work for additional information
7251881Speter *    regarding copyright ownership.  The ASF licenses this file
8251881Speter *    to you under the Apache License, Version 2.0 (the
9251881Speter *    "License"); you may not use this file except in compliance
10251881Speter *    with the License.  You may obtain a copy of the License at
11251881Speter *
12251881Speter *      http://www.apache.org/licenses/LICENSE-2.0
13251881Speter *
14251881Speter *    Unless required by applicable law or agreed to in writing,
15251881Speter *    software distributed under the License is distributed on an
16251881Speter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17251881Speter *    KIND, either express or implied.  See the License for the
18251881Speter *    specific language governing permissions and limitations
19251881Speter *    under the License.
20251881Speter * ====================================================================
21251881Speter * @endcopyright
22251881Speter *
23251881Speter * @file svn_cmdline_private.h
24251881Speter * @brief Private functions for Subversion cmdline.
25251881Speter */
26251881Speter
27251881Speter#ifndef SVN_CMDLINE_PRIVATE_H
28251881Speter#define SVN_CMDLINE_PRIVATE_H
29251881Speter
30251881Speter#include <apr_pools.h>
31251881Speter#include <apr_hash.h>
32251881Speter
33251881Speter#include "svn_string.h"
34251881Speter#include "svn_error.h"
35251881Speter#include "svn_io.h"
36251881Speter
37251881Speter#ifdef __cplusplus
38251881Speterextern "C" {
39251881Speter#endif /* __cplusplus */
40251881Speter
41251881Speter/** Write a property as an XML element into @a *outstr.
42251881Speter *
43251881Speter * If @a outstr is NULL, allocate @a *outstr in @a pool; else append to
44251881Speter * @a *outstr, allocating in @a outstr's pool
45251881Speter *
46251881Speter * @a propname is the property name. @a propval is the property value, which
47251881Speter * will be encoded if it contains unsafe bytes.
48251881Speter *
49251881Speter * If @a inherited_prop is TRUE then @a propname is an inherited property,
50251881Speter * otherwise @a propname is an explicit property.
51251881Speter */
52251881Spetervoid
53251881Spetersvn_cmdline__print_xml_prop(svn_stringbuf_t **outstr,
54251881Speter                            const char *propname,
55251881Speter                            svn_string_t *propval,
56251881Speter                            svn_boolean_t inherited_prop,
57251881Speter                            apr_pool_t *pool);
58251881Speter
59251881Speter
60251881Speter/** An implementation of @c svn_auth_gnome_keyring_unlock_prompt_func_t that
61251881Speter * prompts the user for default GNOME Keyring password.
62251881Speter *
63251881Speter * Expects a @c svn_cmdline_prompt_baton2_t to be passed as @a baton.
64251881Speter *
65251881Speter * @since New in 1.6.
66251881Speter */
67251881Spetersvn_error_t *
68251881Spetersvn_cmdline__auth_gnome_keyring_unlock_prompt(char **keyring_password,
69251881Speter                                              const char *keyring_name,
70251881Speter                                              void *baton,
71251881Speter                                              apr_pool_t *pool);
72251881Speter
73251881Speter/** Container for config options parsed with svn_cmdline__parse_config_option
74251881Speter *
75251881Speter * @since New in 1.7.
76251881Speter */
77251881Spetertypedef struct svn_cmdline__config_argument_t
78251881Speter{
79251881Speter  const char *file;
80251881Speter  const char *section;
81251881Speter  const char *option;
82251881Speter  const char *value;
83251881Speter} svn_cmdline__config_argument_t;
84251881Speter
85251881Speter/** Parser for 'FILE:SECTION:OPTION=[VALUE]'-style option arguments.
86251881Speter *
87251881Speter * Parses @a opt_arg and places its value in @a config_options, an apr array
88251881Speter * containing svn_cmdline__config_argument_t* elements, allocating the option
89251881Speter * data in @a pool
90251881Speter *
91251881Speter * @since New in 1.7.
92251881Speter */
93251881Spetersvn_error_t *
94251881Spetersvn_cmdline__parse_config_option(apr_array_header_t *config_options,
95251881Speter                                 const char *opt_arg,
96251881Speter                                 apr_pool_t *pool);
97251881Speter
98251881Speter/** Sets the config options in @a config_options, an apr array containing
99251881Speter * @c svn_cmdline__config_argument_t* elements, to the configuration in @a cfg,
100251881Speter * a hash mapping of <tt>const char *</tt> configuration file names to
101251881Speter * @c svn_config_t *'s. Write warnings to stderr.
102251881Speter *
103251881Speter * Use @a prefix as prefix and @a argument_name in warning messages.
104251881Speter *
105251881Speter * @since New in 1.7.
106251881Speter */
107251881Spetersvn_error_t *
108251881Spetersvn_cmdline__apply_config_options(apr_hash_t *config,
109251881Speter                                  const apr_array_header_t *config_options,
110251881Speter                                  const char *prefix,
111251881Speter                                  const char *argument_name);
112251881Speter
113251881Speter/* Return a string allocated in POOL that is a copy of STR but with each
114251881Speter * line prefixed with INDENT. A line is all characters up to the first
115251881Speter * CR-LF, LF-CR, CR or LF, or the end of STR if sooner. */
116251881Speterconst char *
117251881Spetersvn_cmdline__indent_string(const char *str,
118251881Speter                           const char *indent,
119251881Speter                           apr_pool_t *pool);
120251881Speter
121251881Speter/* Print to stdout a hash PROP_HASH that maps property names (char *) to
122251881Speter   property values (svn_string_t *).  The names are assumed to be in UTF-8
123251881Speter   format; the values are either in UTF-8 (the special Subversion props) or
124251881Speter   plain binary values.
125251881Speter
126251881Speter   If OUT is not NULL, then write to it rather than stdout.
127251881Speter
128251881Speter   If NAMES_ONLY is true, print just names, else print names and
129251881Speter   values. */
130251881Spetersvn_error_t *
131251881Spetersvn_cmdline__print_prop_hash(svn_stream_t *out,
132251881Speter                             apr_hash_t *prop_hash,
133251881Speter                             svn_boolean_t names_only,
134251881Speter                             apr_pool_t *pool);
135251881Speter
136251881Speter/* Similar to svn_cmdline__print_prop_hash(), only output xml to *OUTSTR.
137251881Speter   If INHERITED_PROPS is true, then PROP_HASH contains inherited properties,
138251881Speter   otherwise PROP_HASH contains explicit properties.  If *OUTSTR is NULL,
139251881Speter   allocate it first from POOL, otherwise append to it. */
140251881Spetersvn_error_t *
141251881Spetersvn_cmdline__print_xml_prop_hash(svn_stringbuf_t **outstr,
142251881Speter                                 apr_hash_t *prop_hash,
143251881Speter                                 svn_boolean_t names_only,
144251881Speter                                 svn_boolean_t inherited_props,
145251881Speter                                 apr_pool_t *pool);
146251881Speter
147251881Speter
148251881Speter/* Search for a text editor command in standard environment variables,
149251881Speter   and invoke it to edit PATH.  Use POOL for all allocations.
150251881Speter
151251881Speter   If EDITOR_CMD is not NULL, it is the name of the external editor
152251881Speter   command to use, overriding anything else that might determine the
153251881Speter   editor.
154251881Speter
155251881Speter   CONFIG is a hash of svn_config_t * items keyed on a configuration
156251881Speter   category (SVN_CONFIG_CATEGORY_CONFIG et al), and may be NULL.  */
157251881Spetersvn_error_t *
158251881Spetersvn_cmdline__edit_file_externally(const char *path,
159251881Speter                                  const char *editor_cmd,
160251881Speter                                  apr_hash_t *config,
161251881Speter                                  apr_pool_t *pool);
162251881Speter
163251881Speter/* Search for a text editor command in standard environment variables,
164251881Speter   and invoke it to edit CONTENTS (using a temporary file created in
165251881Speter   directory BASE_DIR).  Return the new contents in *EDITED_CONTENTS,
166251881Speter   or set *EDITED_CONTENTS to NULL if no edit was performed.
167251881Speter
168251881Speter   If EDITOR_CMD is not NULL, it is the name of the external editor
169251881Speter   command to use, overriding anything else that might determine the
170251881Speter   editor.
171251881Speter
172251881Speter   If TMPFILE_LEFT is NULL, the temporary file will be destroyed.
173251881Speter   Else, the file will be left on disk, and its path returned in
174251881Speter   *TMPFILE_LEFT.
175251881Speter
176251881Speter   CONFIG is a hash of svn_config_t * items keyed on a configuration
177251881Speter   category (SVN_CONFIG_CATEGORY_CONFIG et al), and may be NULL.
178251881Speter
179251881Speter   If AS_TEXT is TRUE, recode CONTENTS and convert to native eol-style before
180251881Speter   editing and back again afterwards.  In this case, ENCODING determines the
181251881Speter   encoding used during editing.  If non-NULL, use the named encoding, else
182251881Speter   use the system encoding.  If AS_TEXT is FALSE, don't do any translation.
183251881Speter   In that case, ENCODING is ignored.
184251881Speter
185251881Speter   Use POOL for all allocations.  Use PREFIX as the prefix for the
186251881Speter   temporary file used by the editor.
187251881Speter
188251881Speter   If return error, *EDITED_CONTENTS is not touched. */
189251881Spetersvn_error_t *
190251881Spetersvn_cmdline__edit_string_externally(svn_string_t **edited_contents,
191251881Speter                                    const char **tmpfile_left,
192251881Speter                                    const char *editor_cmd,
193251881Speter                                    const char *base_dir,
194251881Speter                                    const svn_string_t *contents,
195251881Speter                                    const char *prefix,
196251881Speter                                    apr_hash_t *config,
197251881Speter                                    svn_boolean_t as_text,
198251881Speter                                    const char *encoding,
199251881Speter                                    apr_pool_t *pool);
200251881Speter
201251881Speter
202251881Speter/** Wrapper for apr_getopt_init(), which see.
203251881Speter *
204251881Speter * @since New in 1.4.
205251881Speter */
206251881Spetersvn_error_t *
207251881Spetersvn_cmdline__getopt_init(apr_getopt_t **os,
208251881Speter                         int argc,
209251881Speter                         const char *argv[],
210251881Speter                         apr_pool_t *pool);
211251881Speter
212251881Speter/* Determine whether interactive mode should be enabled, based on whether
213251881Speter * the user passed the --non-interactive or --force-interactive options.
214251881Speter * If neither option was passed, interactivity is enabled if standard
215251881Speter * input is connected to a terminal device.
216251881Speter *
217251881Speter * @since New in 1.8.
218251881Speter */
219251881Spetersvn_boolean_t
220251881Spetersvn_cmdline__be_interactive(svn_boolean_t non_interactive,
221251881Speter                            svn_boolean_t force_interactive);
222251881Speter
223251881Speter
224251881Speter#ifdef __cplusplus
225251881Speter}
226251881Speter#endif /* __cplusplus */
227251881Speter
228251881Speter#endif /* SVN_CMDLINE_PRIVATE_H */
229