svn_subst.h

Go to the documentation of this file.
00001 /**
00002  * @copyright
00003  * ====================================================================
00004  * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
00005  *
00006  * This software is licensed as described in the file COPYING, which
00007  * you should have received as part of this distribution.  The terms
00008  * are also available at http://subversion.tigris.org/license-1.html.
00009  * If newer versions of this license are posted there, you may use a
00010  * newer version instead, at your option.
00011  *
00012  * This software consists of voluntary contributions made by many
00013  * individuals.  For exact contribution history, see the revision
00014  * history and logs, available at http://subversion.tigris.org/.
00015  * ====================================================================
00016  * @endcopyright
00017  *
00018  * @file svn_subst.h
00019  * @brief Data substitution (keywords and EOL style)
00020  */
00021 
00022 
00023 
00024 #ifndef SVN_SUBST_H
00025 #define SVN_SUBST_H
00026 
00027 #include "svn_types.h"
00028 #include "svn_string.h"
00029 #include "svn_io.h"
00030 
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif /* __cplusplus */
00034 
00035 /* EOL conversion and keyword expansion. */
00036 
00037 /** Valid states for 'svn:eol-style' property.
00038  *
00039  * Property nonexistence is equivalent to 'none'.
00040  */
00041 typedef enum svn_subst_eol_style
00042 {
00043   /** An unrecognized style */
00044   svn_subst_eol_style_unknown,
00045 
00046   /** EOL translation is "off" or ignored value */
00047   svn_subst_eol_style_none,
00048 
00049   /** Translation is set to client's native eol */
00050   svn_subst_eol_style_native,
00051 
00052   /** Translation is set to one of LF, CR, CRLF */
00053   svn_subst_eol_style_fixed
00054 
00055 } svn_subst_eol_style_t;
00056 
00057 /** Set @a *style to the appropriate @c svn_subst_eol_style_t and @a *eol to
00058  * the appropriate cstring for a given svn:eol-style property value.
00059  *
00060  * Set @a *eol to
00061  *
00062  *    - @c NULL for @c svn_subst_eol_style_none, or
00063  *
00064  *    - a null-terminated C string containing the native eol marker
00065  *      for this platform, for @c svn_subst_eol_style_native, or
00066  *
00067  *    - a null-terminated C string containing the eol marker indicated
00068  *      by the property value, for @c svn_subst_eol_style_fixed.
00069  *
00070  * If @a *style is NULL, it is ignored.
00071  */
00072 void
00073 svn_subst_eol_style_from_value(svn_subst_eol_style_t *style,
00074                                const char **eol,
00075                                const char *value);
00076 
00077 /** Indicates whether the working copy and normalized versions of a file
00078  * with the given the parameters differ.  If @a force_eol_check is true,
00079  * the routine also accounts for all translations required due to repairing
00080  * fixed eol styles.
00081  *
00082  * @since New in 1.4
00083  *
00084  */
00085 svn_boolean_t
00086 svn_subst_translation_required(svn_subst_eol_style_t style,
00087                                const char *eol,
00088                                apr_hash_t *keywords,
00089                                svn_boolean_t special,
00090                                svn_boolean_t force_eol_check);
00091 
00092 
00093 /** Values used in keyword expansion.
00094  *
00095  * @deprecated Provided for backward compatibility with the 1.2 API.
00096  */
00097 typedef struct svn_subst_keywords_t
00098 {
00099   /**
00100    * @name svn_subst_keywords_t fields
00101    * String expansion of the like-named keyword, or NULL if the keyword
00102    * was not selected in the svn:keywords property.
00103    * @{
00104    */
00105   const svn_string_t *revision;
00106   const svn_string_t *date;
00107   const svn_string_t *author;
00108   const svn_string_t *url;
00109   const svn_string_t *id;
00110   /** @} */
00111 } svn_subst_keywords_t;
00112 
00113 
00114 /**
00115  * Set @a *kw to a new keywords hash filled with the appropriate contents
00116  * given a @a keywords_string (the contents of the svn:keywords
00117  * property for the file in question), the revision @a rev, the @a url, 
00118  * the @a date the file was committed on, and the @a author of the last 
00119  * commit.  Any of these can be @c NULL to indicate that the information is
00120  * not present, or @c 0 for @a date.
00121  *
00122  * Hash keys are of type <tt>const char *</tt>.
00123  * Hash values are of type <tt>svn_string_t *</tt>.
00124  * 
00125  * All memory is allocated out of @a pool.
00126  *
00127  * @since New in 1.3.
00128  */
00129 svn_error_t *
00130 svn_subst_build_keywords2(apr_hash_t **kw,
00131                           const char *keywords_string,
00132                           const char *rev,
00133                           const char *url,
00134                           apr_time_t date,
00135                           const char *author,
00136                           apr_pool_t *pool);
00137 
00138 /** Similar to svn_subst_build_keywords2() except that it populates
00139  * an existing structure @a *kw instead of creating a keywords hash.
00140  *
00141  * @deprecated Provided for backward compatibility with the 1.2 API.
00142  */
00143 svn_error_t *
00144 svn_subst_build_keywords(svn_subst_keywords_t *kw,
00145                          const char *keywords_string,
00146                          const char *rev,
00147                          const char *url,
00148                          apr_time_t date,
00149                          const char *author,
00150                          apr_pool_t *pool);
00151 
00152 
00153 /** Return @c TRUE if @a a and @a b do not hold the same keywords.
00154  *
00155  * @a a and @a b are hashes of the form produced by
00156  * svn_subst_build_keywords2().
00157  *
00158  * @since New in 1.3.
00159  *
00160  * If @a compare_values is @c TRUE, "same" means that the @a a and @a b 
00161  * contain exactly the same set of keywords, and the values of corresponding
00162  * keywords match as well.  Else if @a compare_values is @c FALSE, then
00163  * "same" merely means that @a a and @a b hold the same set of keywords,
00164  * although those keywords' values might differ.
00165  *
00166  * @a a and/or @a b may be @c NULL; for purposes of comparison, @c NULL is
00167  * equivalent to holding no keywords.
00168  */
00169 svn_boolean_t 
00170 svn_subst_keywords_differ2(apr_hash_t *a,
00171                            apr_hash_t *b,
00172                            svn_boolean_t compare_values,
00173                            apr_pool_t *pool);
00174 
00175 /** Similar to svn_subst_keywords_differ2() except that it compares
00176  * two @c svn_subst_keywords_t structs instead of keyword hashes.
00177  *
00178  * @deprecated Provided for backward compatibility with the 1.2 API.
00179  */
00180 svn_boolean_t 
00181 svn_subst_keywords_differ(const svn_subst_keywords_t *a,
00182                           const svn_subst_keywords_t *b,
00183                           svn_boolean_t compare_values);
00184 
00185 
00186 /** 
00187  * Copy and translate the data in stream @a src into stream @a dst.  It is
00188  * assumed that @a src is a readable stream and @a dst is a writable stream.
00189  *
00190  * @since New in 1.3.
00191  *
00192  * If @a eol_str is non-@c NULL, replace whatever bytestring @a src uses to
00193  * denote line endings with @a eol_str in the output.  If @a src has an
00194  * inconsistent line ending style, then: if @a repair is @c FALSE, return
00195  * @c SVN_ERR_IO_INCONSISTENT_EOL, else if @a repair is @c TRUE, convert any
00196  * line ending in @a src to @a eol_str in @a dst.  Recognized line endings are:
00197  * "\n", "\r", and "\r\n".
00198  *
00199  * Expand and contract keywords using the contents of @a keywords as the
00200  * new values.  If @a expand is @c TRUE, expand contracted keywords and
00201  * re-expand expanded keywords.  If @a expand is @c FALSE, contract expanded
00202  * keywords and ignore contracted ones.  Keywords not found in the hash are
00203  * ignored (not contracted or expanded).  If the @a keywords hash
00204  * itself is @c NULL, keyword substitution will be altogether ignored.
00205  *
00206  * Detect only keywords that are no longer than @c SVN_IO_MAX_KEYWORD_LEN
00207  * bytes, including the delimiters and the keyword itself.
00208  *
00209  * Note that a translation request is *required*:  one of @a eol_str or
00210  * @a keywords must be non-@c NULL.
00211  *
00212  * Recommendation: if @a expand is false, then you don't care about the
00213  * keyword values, so use empty strings as non-null signifiers when you
00214  * build the keywords hash.
00215  *
00216  * Notes: 
00217  *
00218  * See svn_wc__get_keywords() and svn_wc__get_eol_style() for a
00219  * convenient way to get @a eol_str and @a keywords if in libsvn_wc.
00220  */
00221 svn_error_t *
00222 svn_subst_translate_stream3(svn_stream_t *src,
00223                             svn_stream_t *dst,
00224                             const char *eol_str,
00225                             svn_boolean_t repair,
00226                             apr_hash_t *keywords,
00227                             svn_boolean_t expand,
00228                             apr_pool_t *pool);
00229 
00230 /** Return a stream which performs eol translation and keyword
00231  * expansion when read from or written to.  The stream @a stream
00232  * is used to read and write all data.  Make sure you call
00233  * svn_stream_close() on @a stream to make sure all data are flushed
00234  * and cleaned up.
00235  *
00236  * Read operations from and write operations to the stream
00237  * perform the same operation: if @a expand is @c FALSE, both
00238  * contract keywords.  One stream supports both read and write
00239  * operations.  Reads and writes may be mixed.
00240  *
00241  * The stream returned is allocated in @a pool.
00242  *
00243  * @since New in 1.4.
00244  */
00245 svn_stream_t *
00246 svn_subst_stream_translated(svn_stream_t *stream,
00247                             const char *eol_str,
00248                             svn_boolean_t repair,
00249                             apr_hash_t *keywords,
00250                             svn_boolean_t expand,
00251                             apr_pool_t *pool);
00252 
00253 /** Similar to svn_subst_translate_stream3() except relies upon a
00254  * @c svn_subst_keywords_t struct instead of a hash for the keywords.
00255  *
00256  * @deprecated Provided for backward compatibility with the 1.2 API.
00257  */
00258 svn_error_t *
00259 svn_subst_translate_stream2(svn_stream_t *src,
00260                             svn_stream_t *dst,
00261                             const char *eol_str,
00262                             svn_boolean_t repair,
00263                             const svn_subst_keywords_t *keywords,
00264                             svn_boolean_t expand,
00265                             apr_pool_t *pool);
00266 
00267 
00268 /**
00269  * Same as svn_subst_translate_stream2(), but does not take a @a pool
00270  * argument, instead creates a temporary subpool of the global pool, and
00271  * destroys it before returning.
00272  *
00273  * @deprecated Provided for backward compatibility with the 1.1 API.
00274  */
00275 svn_error_t *
00276 svn_subst_translate_stream(svn_stream_t *src,
00277                            svn_stream_t *dst,
00278                            const char *eol_str,
00279                            svn_boolean_t repair,
00280                            const svn_subst_keywords_t *keywords,
00281                            svn_boolean_t expand);
00282 
00283 
00284 /**
00285  * Translates the file at path @a src into a file at path @a dst.  The
00286  * parameters @a *eol_str, @a repair, @a *keywords and @a expand are
00287  * defined the same as in svn_subst_translate_stream3().
00288  *
00289  * In addition, it will create a special file from normal form or
00290  * translate one to normal form if @a special is @c TRUE.
00291  *
00292  * Copy the contents of file-path @a src to file-path @a dst atomically,
00293  * either creating @a dst (or overwriting @a dst if it exists), possibly
00294  * performing line ending and keyword translations.
00295  *
00296  * If anything goes wrong during the copy, attempt to delete @a dst (if
00297  * it exists).
00298  *
00299  * If @a eol_str and @a keywords are @c NULL, behavior is just a byte-for-byte
00300  * copy.
00301  *
00302  * @since New in 1.3.
00303  */
00304 svn_error_t *
00305 svn_subst_copy_and_translate3(const char *src,
00306                               const char *dst,
00307                               const char *eol_str,
00308                               svn_boolean_t repair,
00309                               apr_hash_t *keywords,
00310                               svn_boolean_t expand,
00311                               svn_boolean_t special,
00312                               apr_pool_t *pool);
00313 
00314 /**
00315  * Similar to svn_subst_copy_and_translate3() except that @a keywords is a
00316  * @c svn_subst_keywords_t struct instead of a keywords hash.
00317  *
00318  * @deprecated Provided for backward compatibility with the 1.2 API.
00319  * @since New in 1.1.
00320  */
00321 svn_error_t *
00322 svn_subst_copy_and_translate2(const char *src,
00323                               const char *dst,
00324                               const char *eol_str,
00325                               svn_boolean_t repair,
00326                               const svn_subst_keywords_t *keywords,
00327                               svn_boolean_t expand,
00328                               svn_boolean_t special,
00329                               apr_pool_t *pool);
00330 
00331 /**
00332  * Similar to svn_subst_copy_and_translate2() except that @a special is
00333  * always set to @c FALSE.
00334  *
00335  * @deprecated Provided for backward compatibility with the 1.0 API.
00336  */
00337 svn_error_t *
00338 svn_subst_copy_and_translate(const char *src,
00339                              const char *dst,
00340                              const char *eol_str,
00341                              svn_boolean_t repair,
00342                              const svn_subst_keywords_t *keywords,
00343                              svn_boolean_t expand,
00344                              apr_pool_t *pool);
00345 
00346 
00347 /**
00348  * Convenience routine: a variant of svn_subst_translate_stream3() which
00349  * operates on cstrings.
00350  *
00351  * @since New in 1.3.
00352  *
00353  * Return a new string in @a *dst, allocated in @a pool, by copying the
00354  * contents of string @a src, possibly performing line ending and keyword
00355  * translations.
00356  *
00357  * If @a eol_str and @a keywords are @c NULL, behavior is just a byte-for-byte
00358  * copy.
00359  */
00360 svn_error_t *
00361 svn_subst_translate_cstring2(const char *src,
00362                              const char **dst,
00363                              const char *eol_str,
00364                              svn_boolean_t repair,
00365                              apr_hash_t *keywords,
00366                              svn_boolean_t expand,
00367                              apr_pool_t *pool);
00368 
00369 /**
00370  * Similar to svn_subst_translate_cstring2() except that @a keywords is a
00371  * @c svn_subst_keywords_t struct instead of a keywords hash.
00372  *
00373  * @deprecated Provided for backward compatibility with the 1.2 API.
00374  */
00375 svn_error_t *
00376 svn_subst_translate_cstring(const char *src,
00377                             const char **dst,
00378                             const char *eol_str,
00379                             svn_boolean_t repair,
00380                             const svn_subst_keywords_t *keywords,
00381                             svn_boolean_t expand,
00382                             apr_pool_t *pool);
00383 
00384 /**
00385  * Translates a file @a src in working copy form to a file @a dst in
00386  * normal form.
00387  *
00388  * The values specified for @a eol_style, @a *eol_str, @a keywords and
00389  * @a special, should be the ones used to translate the file to its
00390  * working copy form.  Usually, these are the values specified by the
00391  * user in the files' properties.
00392  *
00393  * Inconsistent line endings in the file will be automatically repaired
00394  * (made consistent) for some eol styles.  For all others, an error is
00395  * returned.  By setting @a always_repair_eols to @c TRUE, eols will be
00396  * made consistent even for those styles which don't have it by default.
00397  *
00398  * @note To translate a file FROM normal form, use
00399  *       svn_subst_copy_and_translate3().
00400  *
00401  * @since New in 1.4
00402  *
00403  */
00404 svn_error_t *
00405 svn_subst_translate_to_normal_form(const char *src,
00406                                    const char *dst,
00407                                    svn_subst_eol_style_t eol_style,
00408                                    const char *eol_str,
00409                                    svn_boolean_t always_repair_eols,
00410                                    apr_hash_t *keywords,
00411                                    svn_boolean_t special,
00412                                    apr_pool_t *pool);
00413 
00414 /**
00415  * Set @a *stream_p to a stream that detranslates the file @a src from
00416  * working copy form to normal form, allocated in @a pool.
00417  *
00418  * The values specified for @a eol_style, @a *eol_str, @a keywords and
00419  * @a special, should be the ones used to translate the file to its
00420  * working copy form.  Usually, these are the values specified by the
00421  * user in the files' properties.
00422  *
00423  * Inconsistent line endings in the file will be automatically repaired
00424  * (made consistent) for some eol styles.  For all others, an error is
00425  * returned.  By setting @a always_repair_eols to @c TRUE, eols will be
00426  * made consistent even for those styles which don't have it by default.
00427  *
00428  * @since New in 1.4.
00429  *
00430  */
00431 svn_error_t *
00432 svn_subst_stream_detranslated(svn_stream_t **stream_p, 
00433                               const char *src,
00434                               svn_subst_eol_style_t eol_style,
00435                               const char *eol_str,
00436                               svn_boolean_t always_repair_eols,
00437                               apr_hash_t *keywords,
00438                               svn_boolean_t special,
00439                               apr_pool_t *pool);
00440 
00441 
00442 /* EOL conversion and character encodings */
00443 
00444 /** Translate the data in @a value (assumed to be in encoded in charset
00445  * @a encoding) to UTF8 and LF line-endings.  If @a encoding is @c NULL, 
00446  * then assume that @a value is in the system-default language encoding.
00447  * Return the translated data in @a *new_value, allocated in @a pool.  
00448  */
00449 svn_error_t *svn_subst_translate_string(svn_string_t **new_value,
00450                                         const svn_string_t *value,
00451                                         const char *encoding,
00452                                         apr_pool_t *pool);
00453 
00454 /** Translate the data in @a value from UTF8 and LF line-endings into
00455  * native locale and native line-endings, or to the output locale if
00456  * @a for_output is TRUE.  Return the translated data in @a
00457  * *new_value, allocated in @a pool.
00458  */
00459 svn_error_t *svn_subst_detranslate_string(svn_string_t **new_value,
00460                                           const svn_string_t *value,
00461                                           svn_boolean_t for_stdout,
00462                                           apr_pool_t *pool);
00463 
00464 
00465 
00466 #ifdef __cplusplus
00467 }
00468 #endif /* __cplusplus */
00469 
00470 #endif /* SVN_SUBST_H */

Generated on Sun Apr 1 22:54:12 2007 for Subversion by  doxygen 1.5.1