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 /** Prints creation time stamp and user information into a file as comments. */
119 void nice_header(FILE *out, const char *fn);
121 /** Version of gmx_strcasecmp() that also ignores '-' and '_'. */
122 int gmx_strcasecmp_min(const char *str1, const char *str2);
123 /** Version of gmx_strncasecmp() that also ignores '-' and '_'. */
124 int gmx_strncasecmp_min(const char *str1, const char *str2, int n);
126 /** Case-insensitive strcmp(). */
127 int gmx_strcasecmp(const char *str1, const char *str2);
128 /** Case-insensitive strncmp(). */
129 int gmx_strncasecmp(const char *str1, const char *str2, int n);
131 /** Creates a duplicate of \p src. */
132 char *gmx_strdup(const char *src);
133 /** Duplicates first \p n characters of \p src. */
134 char *gmx_strndup(const char *src, int n);
137 * Pattern matching with wildcards.
139 * \param[in] pattern Pattern to match against.
140 * \param[in] str String to match.
141 * \returns 0 on match, GMX_NO_WCMATCH if there is no match.
143 * Matches \p str against \p pattern, which may contain * and ? wildcards.
144 * All other characters are matched literally.
145 * Currently, it is not possible to match literal * or ?.
147 int gmx_wcmatch(const char *pattern, const char *str);
149 /** Magic hash initialization number from Dan J. Bernstein. */
150 extern const unsigned int
151 gmx_string_hash_init;
154 * Return a hash of the string according to Dan J. Bernsteins algorithm.
156 * \param[in] s String to calculate hash for.
157 * \param[in] hash_init Initial (or previous) hash value.
158 * \returns Updated hash value (hash_init combined with string hash).
160 * This routine only uses characters for which isalnum(c) is true,
161 * and all characters are converted to upper case.
162 * On the first invocation for a new string, use the constant
163 * gmx_string_hash_init for the second argument. If you want to create a hash
164 * corresponding to several concatenated strings, provide the returned hash
165 * value as hash_init for the second string, etc.
168 gmx_string_hash_func(const char *s, unsigned int hash_init);
170 /** Return value for gmx_wcmatch() when there is no match. */
171 #define GMX_NO_WCMATCH 1
173 /** Our implementation of strsep, the thread-safe replacement for strtok. */
174 char *gmx_strsep(char **stringp, const char *delim);
177 * Wraps lines, optionally indenting lines.
179 * Wraps lines at \p linewidth, indenting all following lines by \p indent
180 * spaces. A temp buffer is allocated and returned, which can be disposed of
181 * if no longer needed.
182 * If \p bIndentFirst is FALSE, then the first line will not be indented, only
183 * the lines that are created due to wapping.
185 char *wrap_lines(const char *buf, int line_width, int indent,
186 gmx_bool bIndentFirst);
188 /** Implementation of the well-known Perl function split. */
189 char **split(char sep, const char *str);
192 * Convert a string to gmx_large_int_t.
194 * This method works as the standard library function strtol(), except that it
195 * does not support different bases.
198 * The following differences are present from the standard behavior:
199 * - \p endptr cannot be NULL.
200 * - If an overflow occurs, returns zero and \p *endptr will equal \p str.
201 * errno is still set to ERANGE.
203 gmx_large_int_t str_to_large_int_t(const char *str, char **endptr);
205 #ifdef GMX_NATIVE_WINDOWS
206 #define snprintf _snprintf
213 #endif /* _string2_h */