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