3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gromacs Runs On Most of All Computer Systems
36 * \brief Generic string handling functions.
55 #include "../utility/gmx_header_config.h"
57 #include "types/simple.h"
59 /* Suppress Cygwin compiler warnings from using newlib version of
82 /** Continuation character. */
84 /** Comment sign to use. */
85 #define COMMENTSIGN ';'
88 * Strip trailing spaces and if s ends with a ::CONTINUE remove that too.
90 * \returns TRUE if s ends with a CONTINUE, FALSE otherwise.
92 int continuing(char *s);
95 * Reads a line from a stream.
97 * This routine reads a string from stream of max length n
98 * and zero terminated, without newlines.
99 * \p s should be long enough (>= \p n)
101 char *fgets2(char *s, int n, FILE *stream);
103 /** Remove portion of a line after a ::COMMENTSIGN. */
104 void strip_comment(char *line);
106 /** Make a string uppercase. */
107 void upstring(char *str);
109 /** Remove leading whitespace from a string. */
110 void ltrim(char *str);
112 /** Remove trailing whitespace from a string. */
113 void rtrim(char *str);
115 /** Remove leading and trailing whitespace from a string. */
116 void trim(char *str);
118 /** Portable version of ctime_r. */
119 char *gmx_ctime_r(const time_t *clock, char *buf, int n);
121 /** Prints creation time stamp and user information into a file as comments. */
122 void nice_header(FILE *out, const char *fn);
124 /** Version of gmx_strcasecmp() that also ignores '-' and '_'. */
125 int gmx_strcasecmp_min(const char *str1, const char *str2);
126 /** Version of gmx_strncasecmp() that also ignores '-' and '_'. */
127 int gmx_strncasecmp_min(const char *str1, const char *str2, int n);
129 /** Case-insensitive strcmp(). */
130 int gmx_strcasecmp(const char *str1, const char *str2);
131 /** Case-insensitive strncmp(). */
132 int gmx_strncasecmp(const char *str1, const char *str2, int n);
134 /** Creates a duplicate of \p src. */
135 char *gmx_strdup(const char *src);
136 /** Duplicates first \p n characters of \p src. */
137 char *gmx_strndup(const char *src, int n);
140 * Pattern matching with wildcards.
142 * \param[in] pattern Pattern to match against.
143 * \param[in] str String to match.
144 * \returns 0 on match, GMX_NO_WCMATCH if there is no match.
146 * Matches \p str against \p pattern, which may contain * and ? wildcards.
147 * All other characters are matched literally.
148 * Currently, it is not possible to match literal * or ?.
150 int gmx_wcmatch(const char *pattern, const char *str);
152 /** Magic hash initialization number from Dan J. Bernstein. */
153 extern const unsigned int
154 gmx_string_hash_init;
157 * Return a hash of the string according to Dan J. Bernsteins algorithm.
159 * \param[in] s String to calculate hash for.
160 * \param[in] hash_init Initial (or previous) hash value.
161 * \returns Updated hash value (hash_init combined with string hash).
163 * This routine only uses characters for which isalnum(c) is true,
164 * and all characters are converted to upper case.
165 * On the first invocation for a new string, use the constant
166 * gmx_string_hash_init for the second argument. If you want to create a hash
167 * corresponding to several concatenated strings, provide the returned hash
168 * value as hash_init for the second string, etc.
171 gmx_string_hash_func(const char *s, unsigned int hash_init);
173 /** Return value for gmx_wcmatch() when there is no match. */
174 #define GMX_NO_WCMATCH 1
176 /** Our implementation of strsep, the thread-safe replacement for strtok. */
177 char *gmx_strsep(char **stringp, const char *delim);
180 * Wraps lines, optionally indenting lines.
182 * Wraps lines at \p linewidth, indenting all following lines by \p indent
183 * spaces. A temp buffer is allocated and returned, which can be disposed of
184 * if no longer needed.
185 * If \p bIndentFirst is FALSE, then the first line will not be indented, only
186 * the lines that are created due to wapping.
188 char *wrap_lines(const char *buf, int line_width, int indent,
189 gmx_bool bIndentFirst);
191 /** Implementation of the well-known Perl function split. */
192 char **split(char sep, const char *str);
195 * Convert a string to gmx_large_int_t.
197 * This method works as the standard library function strtol(), except that it
198 * does not support different bases.
201 * The following differences are present from the standard behavior:
202 * - \p endptr cannot be NULL.
203 * - If an overflow occurs, returns zero and \p *endptr will equal \p str.
204 * errno is still set to ERANGE.
206 gmx_large_int_t str_to_large_int_t(const char *str, char **endptr);
208 #ifdef GMX_NATIVE_WINDOWS
209 #define snprintf _snprintf
216 #endif /* _string2_h */