Remove unused function generate_excls and make clean_excls static
[gromacs.git] / src / gromacs / utility / cstringutil.h
blob859e9e0190e9269e6d916444b87d19a6ed24c344
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
37 /*! \file
38 * \brief Generic C string handling functions.
40 * \inpublicapi
41 * \ingroup module_utility
43 #ifndef GMX_UTILITY_CSTRINGUTIL_H
44 #define GMX_UTILITY_CSTRINGUTIL_H
46 #include <stdio.h>
48 #include "gromacs/utility/basedefinitions.h"
50 /** Continuation character. */
51 #define CONTINUE '\\'
52 /** Standard size for char* string buffers. */
53 #define STRLEN 4096
55 /*! \brief
56 * Strip trailing spaces and if s ends with a ::CONTINUE remove that too.
58 * \returns TRUE if s ends with a CONTINUE, FALSE otherwise.
60 int continuing(char *s);
62 /*! \brief
63 * Reads a line from a stream.
65 * This routine reads a string from stream of max length n, including
66 * \0 and zero terminated, without newlines. \p s should be long
67 * enough (>= \p n)
69 char *fgets2(char *s, int n, FILE *stream);
71 /** Remove portion of a line after a ';' comment sign. */
72 void strip_comment(char *line);
74 /** Make a string uppercase. */
75 void upstring(char *str);
77 /** Remove leading whitespace from a string. */
78 void ltrim(char *str);
80 /** Remove trailing whitespace from a string. */
81 void rtrim(char *str);
83 /** Remove leading and trailing whitespace from a string. */
84 void trim(char *str);
86 /** Version of gmx_strcasecmp() that also ignores '-' and '_'. */
87 int gmx_strcasecmp_min(const char *str1, const char *str2);
88 /** Version of gmx_strncasecmp() that also ignores '-' and '_'. */
89 int gmx_strncasecmp_min(const char *str1, const char *str2, int n);
91 /** Case-insensitive strcmp(). */
92 int gmx_strcasecmp(const char *str1, const char *str2);
93 /** Case-insensitive strncmp(). */
94 int gmx_strncasecmp(const char *str1, const char *str2, int n);
96 /** Creates a duplicate of \p src. */
97 char *gmx_strdup(const char *src);
98 /** Duplicates first \p n characters of \p src. */
99 char *gmx_strndup(const char *src, int n);
101 /*! \brief
102 * Pattern matching with wildcards.
104 * \param[in] pattern Pattern to match against.
105 * \param[in] str String to match.
106 * \returns 0 on match, GMX_NO_WCMATCH if there is no match.
108 * Matches \p str against \p pattern, which may contain * and ? wildcards.
109 * All other characters are matched literally.
110 * Currently, it is not possible to match literal * or ?.
112 int gmx_wcmatch(const char *pattern, const char *str);
114 /** Return value for gmx_wcmatch() when there is no match. */
115 #define GMX_NO_WCMATCH 1
117 /** Magic hash initialization number from Dan J. Bernstein. */
118 extern const unsigned int
119 gmx_string_hash_init;
121 /*! \brief
122 * Return a hash of the string according to Dan J. Bernsteins algorithm.
124 * \param[in] s String to calculate hash for.
125 * \param[in] hash_init Initial (or previous) hash value.
126 * \returns Updated hash value (hash_init combined with string hash).
128 * On the first invocation for a new string, use the constant
129 * gmx_string_hash_init for the second argument. If you want to create a hash
130 * corresponding to several concatenated strings, provide the returned hash
131 * value as hash_init for the second string, etc.
133 unsigned int
134 gmx_string_fullhash_func(const char *s, unsigned int hash_init);
136 /*! \brief
137 * Return a hash of the string according to Dan J. Bernsteins algorithm.
139 * \param[in] s String to calculate hash for.
140 * \param[in] hash_init Initial (or previous) hash value.
141 * \returns Updated hash value (hash_init combined with string hash).
143 * Identical to gmx_string_fullhash_func, except that
144 * this routine only uses characters for which isalnum(c) is true,
145 * and all characters are converted to upper case.
147 unsigned int
148 gmx_string_hash_func(const char *s, unsigned int hash_init);
150 /*! \brief
151 * Wraps lines, optionally indenting lines.
153 * Wraps lines at \p linewidth, indenting all following lines by \p indent
154 * spaces. A temp buffer is allocated and returned, which can be disposed of
155 * if no longer needed.
156 * If \p bIndentFirst is FALSE, then the first line will not be indented, only
157 * the lines that are created due to wapping.
159 char *wrap_lines(const char *buf, int line_width, int indent,
160 gmx_bool bIndentFirst);
162 /*! \brief
163 * Convert a string to int64_t.
165 * This method works as the standard library function strtol(), except that it
166 * does not support different bases.
168 int64_t str_to_int64_t(const char *str, char **endptr);
170 /** Minimum size of buffer to pass to gmx_step_str(). */
171 #define STEPSTRSIZE 22
173 /*! \brief
174 * Prints a int64_t value in buf and returns the pointer to buf.
176 * buf should be large enough to contain i: STEPSTRSIZE (22) chars.
177 * When multiple int64_t values are printed in the same printf call,
178 * be sure to call gmx_step_str with different buffers.
180 char *gmx_step_str(int64_t i, char *buf);
182 #endif