Subversion 1.6.16

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 <apr_pools.h>
00028 #include <apr_hash.h>
00029 #include <apr_time.h>
00030 
00031 #include "svn_types.h"
00032 #include "svn_string.h"
00033 #include "svn_io.h"
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif /* __cplusplus */
00038 
00039 /* EOL conversion and keyword expansion. */
00040 
00041 /** The EOL used in the Repository for "native" files */
00042 #define SVN_SUBST_NATIVE_EOL_STR "\n"
00043 
00044 /** Valid states for 'svn:eol-style' property.
00045  *
00046  * Property nonexistence is equivalent to 'none'.
00047  */
00048 typedef enum svn_subst_eol_style
00049 {
00050   /** An unrecognized style */
00051   svn_subst_eol_style_unknown,
00052 
00053   /** EOL translation is "off" or ignored value */
00054   svn_subst_eol_style_none,
00055 
00056   /** Translation is set to client's native eol */
00057   svn_subst_eol_style_native,
00058 
00059   /** Translation is set to one of LF, CR, CRLF */
00060   svn_subst_eol_style_fixed
00061 
00062 } svn_subst_eol_style_t;
00063 
00064 /** Set @a *style to the appropriate @c svn_subst_eol_style_t and @a *eol to
00065  * the appropriate cstring for a given svn:eol-style property value.
00066  *
00067  * Set @a *eol to
00068  *
00069  *    - @c NULL for @c svn_subst_eol_style_none, or
00070  *
00071  *    - a NULL-terminated C string containing the native eol marker
00072  *      for this platform, for @c svn_subst_eol_style_native, or
00073  *
00074  *    - a NULL-terminated C string containing the eol marker indicated
00075  *      by the property value, for @c svn_subst_eol_style_fixed.
00076  *
00077  * If @a *style is NULL, it is ignored.
00078  */
00079 void
00080 svn_subst_eol_style_from_value(svn_subst_eol_style_t *style,
00081                                const char **eol,
00082                                const char *value);
00083 
00084 /** Indicates whether the working copy and normalized versions of a file
00085  * with the given the parameters differ.  If @a force_eol_check is TRUE,
00086  * the routine also accounts for all translations required due to repairing
00087  * fixed eol styles.
00088  *
00089  * @since New in 1.4
00090  *
00091  */
00092 svn_boolean_t
00093 svn_subst_translation_required(svn_subst_eol_style_t style,
00094                                const char *eol,
00095                                apr_hash_t *keywords,
00096                                svn_boolean_t special,
00097                                svn_boolean_t force_eol_check);
00098 
00099 
00100 /** Values used in keyword expansion.
00101  *
00102  * @deprecated Provided for backward compatibility with the 1.2 API.
00103  */
00104 typedef struct svn_subst_keywords_t
00105 {
00106   /**
00107    * @name svn_subst_keywords_t fields
00108    * String expansion of the like-named keyword, or NULL if the keyword
00109    * was not selected in the svn:keywords property.
00110    * @{
00111    */
00112   const svn_string_t *revision;
00113   const svn_string_t *date;
00114   const svn_string_t *author;
00115   const svn_string_t *url;
00116   const svn_string_t *id;
00117   /** @} */
00118 } svn_subst_keywords_t;
00119 
00120 
00121 /**
00122  * Set @a *kw to a new keywords hash filled with the appropriate contents
00123  * given a @a keywords_string (the contents of the svn:keywords
00124  * property for the file in question), the revision @a rev, the @a url,
00125  * the @a date the file was committed on, and the @a author of the last
00126  * commit.  Any of these can be @c NULL to indicate that the information is
00127  * not present, or @c 0 for @a date.
00128  *
00129  * Hash keys are of type <tt>const char *</tt>.
00130  * Hash values are of type <tt>svn_string_t *</tt>.
00131  *
00132  * All memory is allocated out of @a pool.
00133  *
00134  * @since New in 1.3.
00135  */
00136 svn_error_t *
00137 svn_subst_build_keywords2(apr_hash_t **kw,
00138                           const char *keywords_string,
00139                           const char *rev,
00140                           const char *url,
00141                           apr_time_t date,
00142                           const char *author,
00143                           apr_pool_t *pool);
00144 
00145 /** Similar to svn_subst_build_keywords2() except that it populates
00146  * an existing structure @a *kw instead of creating a keywords hash.
00147  *
00148  * @deprecated Provided for backward compatibility with the 1.2 API.
00149  */
00150 SVN_DEPRECATED
00151 svn_error_t *
00152 svn_subst_build_keywords(svn_subst_keywords_t *kw,
00153                          const char *keywords_string,
00154                          const char *rev,
00155                          const char *url,
00156                          apr_time_t date,
00157                          const char *author,
00158                          apr_pool_t *pool);
00159 
00160 
00161 /** Return @c TRUE if @a a and @a b do not hold the same keywords.
00162  *
00163  * @a a and @a b are hashes of the form produced by
00164  * svn_subst_build_keywords2().
00165  *
00166  * @since New in 1.3.
00167  *
00168  * If @a compare_values is @c TRUE, "same" means that the @a a and @a b
00169  * contain exactly the same set of keywords, and the values of corresponding
00170  * keywords match as well.  Else if @a compare_values is @c FALSE, then
00171  * "same" merely means that @a a and @a b hold the same set of keywords,
00172  * although those keywords' values might differ.
00173  *
00174  * @a a and/or @a b may be @c NULL; for purposes of comparison, @c NULL is
00175  * equivalent to holding no keywords.
00176  */
00177 svn_boolean_t
00178 svn_subst_keywords_differ2(apr_hash_t *a,
00179                            apr_hash_t *b,
00180                            svn_boolean_t compare_values,
00181                            apr_pool_t *pool);
00182 
00183 /** Similar to svn_subst_keywords_differ2() except that it compares
00184  * two @c svn_subst_keywords_t structs instead of keyword hashes.
00185  *
00186  * @deprecated Provided for backward compatibility with the 1.2 API.
00187  */
00188 SVN_DEPRECATED
00189 svn_boolean_t
00190 svn_subst_keywords_differ(const svn_subst_keywords_t *a,
00191                           const svn_subst_keywords_t *b,
00192                           svn_boolean_t compare_values);
00193 
00194 
00195 /**
00196  * Copy and translate the data in stream @a src into stream @a dst.  It is
00197  * assumed that @a src is a readable stream and @a dst is a writable stream.
00198  *
00199  * If @a eol_str is non-@c NULL, replace whatever bytestring @a src uses to
00200  * denote line endings with @a eol_str in the output.  If @a src has an
00201  * inconsistent line ending style, then: if @a repair is @c FALSE, return
00202  * @c SVN_ERR_IO_INCONSISTENT_EOL, else if @a repair is @c TRUE, convert any
00203  * line ending in @a src to @a eol_str in @a dst.  Recognized line endings are:
00204  * "\n", "\r", and "\r\n".
00205  *
00206  * Expand and contract keywords using the contents of @a keywords as the
00207  * new values.  If @a expand is @c TRUE, expand contracted keywords and
00208  * re-expand expanded keywords.  If @a expand is @c FALSE, contract expanded
00209  * keywords and ignore contracted ones.  Keywords not found in the hash are
00210  * ignored (not contracted or expanded).  If the @a keywords hash
00211  * itself is @c NULL, keyword substitution will be altogether ignored.
00212  *
00213  * Detect only keywords that are no longer than @c SVN_KEYWORD_MAX_LEN
00214  * bytes, including the delimiters and the keyword itself.
00215  *
00216  * Note that a translation request is *required*:  one of @a eol_str or
00217  * @a keywords must be non-@c NULL.
00218  *
00219  * Recommendation: if @a expand is FALSE, then you don't care about the
00220  * keyword values, so use empty strings as non-NULL signifiers when you
00221  * build the keywords hash.
00222  *
00223  * Notes:
00224  *
00225  * See svn_wc__get_keywords() and svn_wc__get_eol_style() for a
00226  * convenient way to get @a eol_str and @a keywords if in libsvn_wc.
00227  *
00228  * @since New in 1.3.
00229  *
00230  * @deprecated Provided for backward compatibility with the 1.5 API.
00231  *   Callers should use svn_subst_stream_translated() instead.
00232  */
00233 SVN_DEPRECATED
00234 svn_error_t *
00235 svn_subst_translate_stream3(svn_stream_t *src_stream,
00236                             svn_stream_t *dst_stream,
00237                             const char *eol_str,
00238                             svn_boolean_t repair,
00239                             apr_hash_t *keywords,
00240                             svn_boolean_t expand,
00241                             apr_pool_t *scratch_pool);
00242 
00243 
00244 /** Similar to svn_subst_translate_stream3() except relies upon a
00245  * @c svn_subst_keywords_t struct instead of a hash for the keywords.
00246  *
00247  * @deprecated Provided for backward compatibility with the 1.2 API.
00248  */
00249 SVN_DEPRECATED
00250 svn_error_t *
00251 svn_subst_translate_stream2(svn_stream_t *src_stream,
00252                             svn_stream_t *dst_stream,
00253                             const char *eol_str,
00254                             svn_boolean_t repair,
00255                             const svn_subst_keywords_t *keywords,
00256                             svn_boolean_t expand,
00257                             apr_pool_t *scratch_pool);
00258 
00259 
00260 /**
00261  * Same as svn_subst_translate_stream2(), but does not take a @a pool
00262  * argument, instead creates a temporary subpool of the global pool, and
00263  * destroys it before returning.
00264  *
00265  * @deprecated Provided for backward compatibility with the 1.1 API.
00266  */
00267 SVN_DEPRECATED
00268 svn_error_t *
00269 svn_subst_translate_stream(svn_stream_t *src_stream,
00270                            svn_stream_t *dst_stream,
00271                            const char *eol_str,
00272                            svn_boolean_t repair,
00273                            const svn_subst_keywords_t *keywords,
00274                            svn_boolean_t expand);
00275 
00276 
00277 /** Return a stream which performs eol translation and keyword
00278  * expansion when read from or written to.  The stream @a stream
00279  * is used to read and write all data.
00280  *
00281  * Make sure you call svn_stream_close() on the returned stream to
00282  * ensure all data is flushed and cleaned up (this will also close
00283  * the provided @a stream).
00284  *
00285  * Read operations from and write operations to the stream
00286  * perform the same operation: if @a expand is @c FALSE, both
00287  * contract keywords.  One stream supports both read and write
00288  * operations.  Reads and writes may be mixed.
00289  *
00290  * The stream returned is allocated in @a pool.
00291  *
00292  * @since New in 1.4.
00293  */
00294 svn_stream_t *
00295 svn_subst_stream_translated(svn_stream_t *stream,
00296                             const char *eol_str,
00297                             svn_boolean_t repair,
00298                             apr_hash_t *keywords,
00299                             svn_boolean_t expand,
00300                             apr_pool_t *pool);
00301 
00302 
00303 /** Return a stream which performs eol translation and keyword
00304  * expansion when read from or written to.  The stream @a stream
00305  * is used to read and write all data.  Make sure you call
00306  * svn_stream_close() on @a stream to make sure all data are flushed
00307  * and cleaned up.
00308  *
00309  * When @a stream is closed, then @a source will be closed.
00310  *
00311  * Read and write operations perform the same transformation:
00312  * all data is translated to normal form.
00313  *
00314  * @see svn_subst_translate_to_normal_form()
00315  *
00316  * @since New in 1.5.
00317  * @deprecated Provided for backward compatibility with the 1.5 API.
00318  */
00319 SVN_DEPRECATED
00320 svn_error_t *
00321 svn_subst_stream_translated_to_normal_form(svn_stream_t **stream,
00322                                            svn_stream_t *source,
00323                                            svn_subst_eol_style_t eol_style,
00324                                            const char *eol_str,
00325                                            svn_boolean_t always_repair_eols,
00326                                            apr_hash_t *keywords,
00327                                            apr_pool_t *pool);
00328 
00329 
00330 /** Returns a readable stream in @a *stream containing the "normal form"
00331  * of the special file located at @a path. The stream will be allocated
00332  * in @a result_pool, and any temporary allocations will be made in
00333  * @a scratch_pool.
00334  *
00335  * @since New in 1.6.
00336  */
00337 svn_error_t *
00338 svn_subst_read_specialfile(svn_stream_t **stream,
00339                            const char *path,
00340                            apr_pool_t *result_pool,
00341                            apr_pool_t *scratch_pool);
00342 
00343 
00344 /** Returns a writeable stream in @a *stream that accepts content in
00345  * the "normal form" for a special file, to be located at @a path, and
00346  * will create that file when the stream is closed. The stream will be
00347  * allocated in @a result_pool, and any temporary allocations will be
00348  * made in @a scratch_pool.
00349  *
00350  * @since New in 1.6.
00351  */
00352 svn_error_t *
00353 svn_subst_create_specialfile(svn_stream_t **stream,
00354                              const char *path,
00355                              apr_pool_t *result_pool,
00356                              apr_pool_t *scratch_pool);
00357 
00358 
00359 /** Returns a stream which translates the special file at @a path to
00360  * the internal representation for special files when read from.  When
00361  * written to, it does the reverse: creating a special file when the
00362  * stream is closed.
00363  *
00364  * @since New in 1.5.
00365  *
00366  * @deprecated Provided for backward compatibility with the 1.5 API.
00367  *   Callers should use svn_subst_read_specialfile or
00368  *   svn_subst_create_specialfile as appropriate.
00369  */
00370 SVN_DEPRECATED
00371 svn_error_t *
00372 svn_subst_stream_from_specialfile(svn_stream_t **stream,
00373                                   const char *path,
00374                                   apr_pool_t *pool);
00375 
00376 
00377 /**
00378  * Translates the file at path @a src into a file at path @a dst.  The
00379  * parameters @a *eol_str, @a repair, @a *keywords and @a expand are
00380  * defined the same as in svn_subst_translate_stream3().
00381  *
00382  * In addition, it will create a special file from normal form or
00383  * translate one to normal form if @a special is @c TRUE.
00384  *
00385  * Copy the contents of file-path @a src to file-path @a dst atomically,
00386  * either creating @a dst (or overwriting @a dst if it exists), possibly
00387  * performing line ending and keyword translations.
00388  *
00389  * If anything goes wrong during the copy, attempt to delete @a dst (if
00390  * it exists).
00391  *
00392  * If @a eol_str and @a keywords are @c NULL, behavior is just a byte-for-byte
00393  * copy.
00394  *
00395  * @since New in 1.3.
00396  */
00397 svn_error_t *
00398 svn_subst_copy_and_translate3(const char *src,
00399                               const char *dst,
00400                               const char *eol_str,
00401                               svn_boolean_t repair,
00402                               apr_hash_t *keywords,
00403                               svn_boolean_t expand,
00404                               svn_boolean_t special,
00405                               apr_pool_t *pool);
00406 
00407 /**
00408  * Similar to svn_subst_copy_and_translate3() except that @a keywords is a
00409  * @c svn_subst_keywords_t struct instead of a keywords hash.
00410  *
00411  * @deprecated Provided for backward compatibility with the 1.2 API.
00412  * @since New in 1.1.
00413  */
00414 SVN_DEPRECATED
00415 svn_error_t *
00416 svn_subst_copy_and_translate2(const char *src,
00417                               const char *dst,
00418                               const char *eol_str,
00419                               svn_boolean_t repair,
00420                               const svn_subst_keywords_t *keywords,
00421                               svn_boolean_t expand,
00422                               svn_boolean_t special,
00423                               apr_pool_t *pool);
00424 
00425 /**
00426  * Similar to svn_subst_copy_and_translate2() except that @a special is
00427  * always set to @c FALSE.
00428  *
00429  * @deprecated Provided for backward compatibility with the 1.0 API.
00430  */
00431 SVN_DEPRECATED
00432 svn_error_t *
00433 svn_subst_copy_and_translate(const char *src,
00434                              const char *dst,
00435                              const char *eol_str,
00436                              svn_boolean_t repair,
00437                              const svn_subst_keywords_t *keywords,
00438                              svn_boolean_t expand,
00439                              apr_pool_t *pool);
00440 
00441 
00442 /**
00443  * Convenience routine: a variant of svn_subst_translate_stream3() which
00444  * operates on cstrings.
00445  *
00446  * @since New in 1.3.
00447  *
00448  * Return a new string in @a *dst, allocated in @a pool, by copying the
00449  * contents of string @a src, possibly performing line ending and keyword
00450  * translations.
00451  *
00452  * If @a eol_str and @a keywords are @c NULL, behavior is just a byte-for-byte
00453  * copy.
00454  */
00455 svn_error_t *
00456 svn_subst_translate_cstring2(const char *src,
00457                              const char **dst,
00458                              const char *eol_str,
00459                              svn_boolean_t repair,
00460                              apr_hash_t *keywords,
00461                              svn_boolean_t expand,
00462                              apr_pool_t *pool);
00463 
00464 /**
00465  * Similar to svn_subst_translate_cstring2() except that @a keywords is a
00466  * @c svn_subst_keywords_t struct instead of a keywords hash.
00467  *
00468  * @deprecated Provided for backward compatibility with the 1.2 API.
00469  */
00470 SVN_DEPRECATED
00471 svn_error_t *
00472 svn_subst_translate_cstring(const char *src,
00473                             const char **dst,
00474                             const char *eol_str,
00475                             svn_boolean_t repair,
00476                             const svn_subst_keywords_t *keywords,
00477                             svn_boolean_t expand,
00478                             apr_pool_t *pool);
00479 
00480 /**
00481  * Translates a file @a src in working copy form to a file @a dst in
00482  * normal form.
00483  *
00484  * The values specified for @a eol_style, @a *eol_str, @a keywords and
00485  * @a special, should be the ones used to translate the file to its
00486  * working copy form.  Usually, these are the values specified by the
00487  * user in the files' properties.
00488  *
00489  * Inconsistent line endings in the file will be automatically repaired
00490  * (made consistent) for some eol styles.  For all others, an error is
00491  * returned.  By setting @a always_repair_eols to @c TRUE, eols will be
00492  * made consistent even for those styles which don't have it by default.
00493  *
00494  * @note To translate a file FROM normal form, use
00495  *       svn_subst_copy_and_translate3().
00496  *
00497  * @since New in 1.4
00498  * @deprecated Provided for backward compatibility with the 1.5 API
00499  */
00500 SVN_DEPRECATED
00501 svn_error_t *
00502 svn_subst_translate_to_normal_form(const char *src,
00503                                    const char *dst,
00504                                    svn_subst_eol_style_t eol_style,
00505                                    const char *eol_str,
00506                                    svn_boolean_t always_repair_eols,
00507                                    apr_hash_t *keywords,
00508                                    svn_boolean_t special,
00509                                    apr_pool_t *pool);
00510 
00511 /**
00512  * Set @a *stream_p to a stream that detranslates the file @a src from
00513  * working copy form to normal form, allocated in @a pool.
00514  *
00515  * The values specified for @a eol_style, @a *eol_str, @a keywords and
00516  * @a special, should be the ones used to translate the file to its
00517  * working copy form.  Usually, these are the values specified by the
00518  * user in the files' properties.
00519  *
00520  * Inconsistent line endings in the file will be automatically repaired
00521  * (made consistent) for some eol styles.  For all others, an error is
00522  * returned.  By setting @a always_repair_eols to @c TRUE, eols will be
00523  * made consistent even for those styles which don't have it by default.
00524  *
00525  * @since New in 1.4.
00526  *
00527  * @deprecated Provided for backward compatibility with the 1.5 API.
00528  *   Use svn_subst_stream_from_specialfile if the source is special;
00529  *   otherwise, use svn_subst_stream_translated_to_normal_form.
00530  */
00531 SVN_DEPRECATED
00532 svn_error_t *
00533 svn_subst_stream_detranslated(svn_stream_t **stream_p,
00534                               const char *src,
00535                               svn_subst_eol_style_t eol_style,
00536                               const char *eol_str,
00537                               svn_boolean_t always_repair_eols,
00538                               apr_hash_t *keywords,
00539                               svn_boolean_t special,
00540                               apr_pool_t *pool);
00541 
00542 
00543 /* EOL conversion and character encodings */
00544 
00545 /** Translate the data in @a value (assumed to be in encoded in charset
00546  * @a encoding) to UTF8 and LF line-endings.  If @a encoding is @c NULL,
00547  * then assume that @a value is in the system-default language encoding.
00548  * Return the translated data in @a *new_value, allocated in @a pool.
00549  */
00550 svn_error_t *svn_subst_translate_string(svn_string_t **new_value,
00551                                         const svn_string_t *value,
00552                                         const char *encoding,
00553                                         apr_pool_t *pool);
00554 
00555 /** Translate the data in @a value from UTF8 and LF line-endings into
00556  * native locale and native line-endings, or to the output locale if
00557  * @a for_output is TRUE.  Return the translated data in @a
00558  * *new_value, allocated in @a pool.
00559  */
00560 svn_error_t *svn_subst_detranslate_string(svn_string_t **new_value,
00561                                           const svn_string_t *value,
00562                                           svn_boolean_t for_output,
00563                                           apr_pool_t *pool);
00564 
00565 
00566 #ifdef __cplusplus
00567 }
00568 #endif /* __cplusplus */
00569 
00570 #endif /* SVN_SUBST_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines