Include Gromacs files with double quotes in C++ code.
[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
79 /** Continuation character. */
80 #define CONTINUE    '\\'
81 /** Comment sign to use. */
82 #define COMMENTSIGN ';'
83
84 /*! \brief
85  * Strip trailing spaces and if s ends with a ::CONTINUE remove that too.
86  *
87  * \returns TRUE if s ends with a CONTINUE, FALSE otherwise.
88  */
89 int continuing(char *s);
90
91 /*! \brief
92  * Reads a line from a stream.
93  *
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)
97  */
98 char *fgets2(char *s, int n, FILE *stream);
99
100 /** Remove portion of a line after a ::COMMENTSIGN.  */
101 void strip_comment(char *line);
102
103 /** Make a string uppercase. */
104 void upstring(char *str);
105
106 /** Remove leading whitespace from a string. */
107 void ltrim(char *str);
108
109 /** Remove trailing whitespace from a string. */
110 void rtrim(char *str);
111
112 /** Remove leading and trailing whitespace from a string. */
113 void trim(char *str);
114
115 /** Prints creation time stamp and user information into a file as comments. */
116 void nice_header(FILE *out, const char *fn);
117
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);
122
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);
127
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);
132
133 /*! \brief
134  * Pattern matcing with wildcards.
135  *
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.
139  *
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 ?.
143  */
144 int gmx_wcmatch(const char *pattern, const char *str);
145
146 /** Return value for gmx_wcmatch() when there is no match. */
147 #define GMX_NO_WCMATCH 1
148
149 /** Our implementation of strsep, the thread-safe replacement for strtok. */
150 char *gmx_strsep(char **stringp, const char *delim);
151
152 /*! \brief
153  * Wraps lines, optionally indenting lines.
154  *
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.
160  */
161 char *wrap_lines(const char *buf,int line_width, int indent,
162                  gmx_bool bIndentFirst);
163
164 /** Implementation of the well-known Perl function split. */
165 char **split(char sep,const char *str);
166
167 /*! \brief
168  * Convert a string to gmx_large_int_t.
169  *
170  * This method works as the standard library function strtol(), except that it
171  * does not support different bases.
172  *
173  * \attention
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.
178  */
179 gmx_large_int_t str_to_large_int_t(const char *str, char **endptr);
180
181 #ifdef GMX_NATIVE_WINDOWS
182 #define snprintf _snprintf
183 #endif
184
185 #ifdef __cplusplus
186 }
187 #endif
188
189 #endif  /* _string2_h */