Fixing copyright issues and code contributors
[alexxy/gromacs.git] / include / string2.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  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012,2013, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * 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 string handling functions.
40  */
41 #ifndef _string2_h
42 #define _string2_h
43
44 /*
45  *
46  * string2.h
47  * David van der Spoel
48  *
49  */
50
51 #include <string.h>
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <ctype.h>
55 #include <time.h>
56 #include <errno.h>
57 #include "visibility.h"
58 #include "gmx_header_config.h"
59
60 /*#include "typedefs.h"*/
61 #include "types/simple.h"
62
63 /* Suppress Cygwin compiler warnings from using newlib version of
64  * ctype.h */
65 #ifdef GMX_CYGWIN
66 #undef isdigit
67 #undef isstring
68 #undef isspace
69 #undef isalnum
70 #undef isalpha
71 #undef ispunct
72 #undef isxdigit
73 #undef isupper
74 #undef islower
75 #undef toupper
76 #undef tolower
77 #endif
78
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 #if 0
83 }
84 #endif
85
86 #define CONTINUE    '\\'
87 #define COMMENTSIGN ';'
88
89 GMX_LIBGMX_EXPORT
90 int continuing(char *s);
91
92 GMX_LIBGMX_EXPORT
93 char *fgets2(char *s, int n, FILE *stream);
94
95 GMX_LIBGMX_EXPORT
96 void strip_comment (char *line);
97
98 int break_line (char *line,
99                        char *variable,
100                        char *value);
101
102 GMX_LIBGMX_EXPORT
103 void upstring (char *str);
104
105 GMX_LIBGMX_EXPORT
106 void ltrim (char *str);
107
108 GMX_LIBGMX_EXPORT
109 void rtrim (char *str);
110
111 GMX_LIBGMX_EXPORT
112 void trim (char *str);
113
114 GMX_LIBGMX_EXPORT
115 void nice_header (FILE *out,const char *fn);
116
117 GMX_LIBGMX_EXPORT
118 int gmx_strcasecmp_min(const char *str1, const char *str2);
119 GMX_LIBGMX_EXPORT
120 int gmx_strncasecmp_min(const char *str1, const char *str2, int n);
121 /* This funny version of strcasecmp, is not only case-insensitive,
122  * but also ignores '-' and '_'.
123  */
124
125 GMX_LIBGMX_EXPORT
126 int gmx_strcasecmp(const char *str1, const char *str2);
127 GMX_LIBGMX_EXPORT
128 int gmx_strncasecmp(const char *str1, const char *str2, int n);
129
130 GMX_LIBGMX_EXPORT
131 char *gmx_strdup(const char *src);
132 char *gmx_strndup(const char *src, int n);
133
134 /* Magic hash initialization number from Dan J. Bernstein. */
135 extern const unsigned int
136 gmx_string_hash_init;
137
138 /* Return a hash of the string according to Dan J. Bernsteins algorithm.
139  * This routine only uses characters for which isalnum(c) is true,
140  * and all characters are converted to upper case.
141  * On the first invocation for a new string, use the constant
142  * gmx_string_hash_init for the second argument. If you want to create a hash
143  * corresponding to several concatenated strings, provide the returned hash
144  * value as hash_init for the second string, etc.
145  */
146 unsigned int
147 gmx_string_hash_func(const char *s, unsigned int hash_init);
148     
149 /** Pattern matcing with wildcards. */
150 GMX_LIBGMX_EXPORT
151 int gmx_wcmatch(const char *pattern, const char *src);
152
153 /** Return value for gmx_wcmatch() when there is no match. */
154 #define GMX_NO_WCMATCH 1
155
156
157 /* this is our implementation of strsep, the thread-safe replacement for
158    strtok */
159 GMX_LIBGMX_EXPORT
160 char *gmx_strsep(char **stringp, const char *delim);
161
162
163 GMX_LIBGMX_EXPORT
164 char *wrap_lines(const char *buf,int line_width, int indent,
165                         gmx_bool bIndentFirst);
166 /* wraps lines at 'linewidth', indenting all following
167  * lines by 'indent' spaces. A temp buffer is allocated and returned,
168  * which can be disposed of if no longer needed.
169  * If !bIndentFirst, then the first line will not be indented, only 
170  * the lines that are created due to wapping.
171  */
172
173
174 char **split(char sep,char *str);
175 /* Implementation of the well-known Perl function split */
176
177 gmx_large_int_t str_to_large_int_t(const char *str, char **endptr);
178     
179 #ifdef GMX_NATIVE_WINDOWS
180 #define snprintf _snprintf
181 #endif
182
183 #ifdef __cplusplus
184 }
185 #endif
186
187 #endif  /* _string2_h */