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
79 /** Continuation character. */
81 /** Comment sign to use. */
82 #define COMMENTSIGN ';'
85 * Strip trailing spaces and if s ends with a ::CONTINUE remove that too.
87 * \returns TRUE if s ends with a CONTINUE, FALSE otherwise.
89 int continuing(char *s);
92 * Reads a line from a stream.
94 * This routine reads a string from stream of max length n
95 * and zero terminated, without newlines.
96 * \p s should be long enough (>= \p n)
98 char *fgets2(char *s, int n, FILE *stream);
100 /** Remove portion of a line after a ::COMMENTSIGN. */
101 void strip_comment(char *line);
103 /** Make a string uppercase. */
104 void upstring(char *str);
106 /** Remove leading whitespace from a string. */
107 void ltrim(char *str);
109 /** Remove trailing whitespace from a string. */
110 void rtrim(char *str);
112 /** Remove leading and trailing whitespace from a string. */
113 void trim(char *str);
115 /** Prints creation time stamp and user information into a file as comments. */
116 void nice_header(FILE *out, const char *fn);
118 /** Version of gmx_strcasecmp() that also ignores '-' and '_'. */
119 int gmx_strcasecmp_min(const char *str1, const char *str2);
120 /** Version of gmx_strncasecmp() that also ignores '-' and '_'. */
121 int gmx_strncasecmp_min(const char *str1, const char *str2, int n);
123 /** Case-insensitive strcmp(). */
124 int gmx_strcasecmp(const char *str1, const char *str2);
125 /** Case-insensitive strncmp(). */
126 int gmx_strncasecmp(const char *str1, const char *str2, int n);
128 /** Creates a duplicate of \p src. */
129 char *gmx_strdup(const char *src);
130 /** Duplicates first \p n characters of \p src. */
131 char *gmx_strndup(const char *src, int n);
134 * Pattern matcing with wildcards.
136 * \param[in] pattern Pattern to match against.
137 * \param[in] str String to match.
138 * \returns 0 on match, GMX_NO_WCMATCH if there is no match.
140 * Matches \p str against \p pattern, which may contain * and ? wildcards.
141 * All other characters are matched literally.
142 * Currently, it is not possible to match literal * or ?.
144 int gmx_wcmatch(const char *pattern, const char *str);
146 /** Return value for gmx_wcmatch() when there is no match. */
147 #define GMX_NO_WCMATCH 1
149 /** Our implementation of strsep, the thread-safe replacement for strtok. */
150 char *gmx_strsep(char **stringp, const char *delim);
153 * Wraps lines, optionally indenting lines.
155 * Wraps lines at \p linewidth, indenting all following lines by \p indent
156 * spaces. A temp buffer is allocated and returned, which can be disposed of
157 * if no longer needed.
158 * If \p bIndentFirst is FALSE, then the first line will not be indented, only
159 * the lines that are created due to wapping.
161 char *wrap_lines(const char *buf,int line_width, int indent,
162 gmx_bool bIndentFirst);
164 /** Implementation of the well-known Perl function split. */
165 char **split(char sep,const char *str);
168 * Convert a string to gmx_large_int_t.
170 * This method works as the standard library function strtol(), except that it
171 * does not support different bases.
174 * The following differences are present from the standard behavior:
175 * - \p endptr cannot be NULL.
176 * - If an overflow occurs, returns zero and \p *endptr will equal \p str.
177 * errno is still set to ERANGE.
179 gmx_large_int_t str_to_large_int_t(const char *str, char **endptr);
181 #ifdef GMX_NATIVE_WINDOWS
182 #define snprintf _snprintf
189 #endif /* _string2_h */