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