Code beautification with uncrustify
[alexxy/gromacs.git] / src / gromacs / legacyheaders / string2.h
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  *                        VERSION 3.2.0
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.
14
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.
19  *
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.
26  *
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.
29  *
30  * For more info, check our website at http://www.gromacs.org
31  *
32  * And Hey:
33  * Gromacs Runs On Most of All Computer Systems
34  */
35 /*! \file
36  * \brief Generic string handling functions.
37  */
38 #ifndef _string2_h
39 #define _string2_h
40
41 /*
42  *
43  * string2.h
44  * David van der Spoel
45  *
46  */
47
48
49 #include <string.h>
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <ctype.h>
53 #include <time.h>
54 #include <errno.h>
55 #include "../utility/gmx_header_config.h"
56
57 #include "types/simple.h"
58
59 /* Suppress Cygwin compiler warnings from using newlib version of
60  * ctype.h */
61 #ifdef GMX_CYGWIN
62 #undef isdigit
63 #undef isstring
64 #undef isspace
65 #undef isalnum
66 #undef isalpha
67 #undef ispunct
68 #undef isxdigit
69 #undef isupper
70 #undef islower
71 #undef toupper
72 #undef tolower
73 #endif
74
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 #if 0
79 }
80 #endif
81
82 /** Continuation character. */
83 #define CONTINUE    '\\'
84 /** Comment sign to use. */
85 #define COMMENTSIGN ';'
86
87 /*! \brief
88  * Strip trailing spaces and if s ends with a ::CONTINUE remove that too.
89  *
90  * \returns TRUE if s ends with a CONTINUE, FALSE otherwise.
91  */
92 int continuing(char *s);
93
94 /*! \brief
95  * Reads a line from a stream.
96  *
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)
100  */
101 char *fgets2(char *s, int n, FILE *stream);
102
103 /** Remove portion of a line after a ::COMMENTSIGN.  */
104 void strip_comment(char *line);
105
106 /** Make a string uppercase. */
107 void upstring(char *str);
108
109 /** Remove leading whitespace from a string. */
110 void ltrim(char *str);
111
112 /** Remove trailing whitespace from a string. */
113 void rtrim(char *str);
114
115 /** Remove leading and trailing whitespace from a string. */
116 void trim(char *str);
117
118 /** Prints creation time stamp and user information into a file as comments. */
119 void nice_header(FILE *out, const char *fn);
120
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);
125
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);
130
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);
135
136 /*! \brief
137  * Pattern matching with wildcards.
138  *
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.
142  *
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 ?.
146  */
147 int gmx_wcmatch(const char *pattern, const char *str);
148
149 /** Magic hash initialization number from Dan J. Bernstein. */
150 extern const unsigned int
151     gmx_string_hash_init;
152
153 /*! \brief
154  * Return a hash of the string according to Dan J. Bernsteins algorithm.
155  *
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).
159  *
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.
166  */
167 unsigned int
168 gmx_string_hash_func(const char *s, unsigned int hash_init);
169
170 /** Return value for gmx_wcmatch() when there is no match. */
171 #define GMX_NO_WCMATCH 1
172
173 /** Our implementation of strsep, the thread-safe replacement for strtok. */
174 char *gmx_strsep(char **stringp, const char *delim);
175
176 /*! \brief
177  * Wraps lines, optionally indenting lines.
178  *
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.
184  */
185 char *wrap_lines(const char *buf, int line_width, int indent,
186                  gmx_bool bIndentFirst);
187
188 /** Implementation of the well-known Perl function split. */
189 char **split(char sep, const char *str);
190
191 /*! \brief
192  * Convert a string to gmx_large_int_t.
193  *
194  * This method works as the standard library function strtol(), except that it
195  * does not support different bases.
196  *
197  * \attention
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.
202  */
203 gmx_large_int_t str_to_large_int_t(const char *str, char **endptr);
204
205 #ifdef GMX_NATIVE_WINDOWS
206 #define snprintf _snprintf
207 #endif
208
209 #ifdef __cplusplus
210 }
211 #endif
212
213 #endif  /* _string2_h */