4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Green Red Orange Magenta Azure Cyan Skyblue
29 static char *SRCID_string2_c
= "$Id$";
34 #include <sys/types.h>
46 int continuing(char *s
)
47 /* strip trailing spaces and if s ends with a CONTINUE remove that too.
48 * returns TRUE if s ends with a CONTINUE, FALSE otherwise.
55 if ((sl
> 0) && (s
[sl
-1] == CONTINUE
)) {
63 char *fgets2(char *line
, int n
, FILE *stream
)
64 /* This routine reads a string from stream of max length n
65 * and zero terminated, without newlines
66 * line should be long enough (>= n)
70 if (fgets(line
,n
,stream
)==NULL
) return NULL
;
71 if ((c
=strchr(line
,'\n'))!=NULL
) *c
=0;
75 void strip_comment (char *line
)
82 /* search for a comment mark and replace it by a zero */
83 if ((c
= strchr(line
,COMMENTSIGN
)) != NULL
)
87 void upstring (char *str
)
91 for (i
=0; (i
< (int)strlen(str
)); i
++)
92 str
[i
] = toupper(str
[i
]);
95 void ltrim (char *str
)
105 while ((tr
[c
] == ' ') || (tr
[c
] == '\t'))
112 void rtrim (char *str
)
120 while ((nul
> 0) && ((str
[nul
] == ' ') || (str
[nul
] == '\t')) ) {
126 void trim (char *str
)
132 void nice_header (FILE *out
,char *fn
)
140 /* Print a nice header above the file */
142 fprintf (out
,"%c\n",COMMENTSIGN
);
145 if ((pw
= getpwuid(uid
)) != NULL
)
146 fprintf (out
,"%c\tUser %s (%d)\n",COMMENTSIGN
,pw
->pw_name
,(int) uid
);
148 fprintf (out
,"%c\tUser %d not in password file\n",COMMENTSIGN
,(int) uid
);
150 fprintf (out
,"%c\t%s",COMMENTSIGN
,ctime(&clock
));
151 fprintf (out
,"%c\t%s\n",COMMENTSIGN
,fn
);
152 fprintf (out
,"%c\n",COMMENTSIGN
);
155 int gmx_strcasecmp(const char *str1
, const char *str2
)
162 ch1
=toupper(*(str1
++));
163 while ((ch1
=='-') || (ch1
=='_'));
165 ch2
=toupper(*(str2
++));
166 while ((ch2
=='-') || (ch2
=='_'));
167 if (ch1
!=ch2
) return (ch1
-ch2
);
173 char *gmx_strdup(const char *src
)
177 snew(dest
,strlen(src
)+1);
183 char *wrap_lines(char *buf
,int line_width
, int indent
)
186 int i
,i0
,i2
,j
,b2len
,lspace
=0,l2space
=0;
187 bool bFirst
,bFitsOnLine
;
189 /* characters are copied from buf to b2 with possible spaces changed
190 * into newlines and extra space added for indentation.
191 * i indexes buf (source buffer) and i2 indexes b2 (destination buffer)
192 * i0 points to the beginning of the current line (in buf, source)
193 * lspace and l2space point to the last space on the current line
194 * bFirst is set to prevent indentation of first line
195 * bFitsOnLine says if the first space occurred before line_width, if
196 * that is not the case, we have a word longer than line_width which
197 * will also not fit on the next line, so we might as well keep it on
198 * the current line (where it also won't fit, but looks better)
209 /* find the last space before end of line */
210 for(i
=i0
; ((i
-i0
< line_width
) || (l2space
==-1)) && (buf
[i
]); i
++) {
212 /* remember the position of a space */
217 /* if we have a newline before the line is full, reset counters */
218 if (buf
[i
]=='\n' && buf
[i
+1]) {
222 /* add indentation after the newline */
223 for(j
=0; (j
<indent
); j
++)
227 /* check if one word does not fit on the line */
228 bFitsOnLine
= (i
-i0
<= line_width
);
229 /* if we're not at the end of the string */
231 /* reset line counters to just after the space */
234 /* if the words fit on the line, and we're beyond the indentation part */
235 if ( (bFitsOnLine
) && (l2space
>= indent
) ) {
236 /* start a new line */
238 /* and add indentation */
246 for(j
=0; (j
<indent
); j
++)
248 /* no extra spaces after indent; */