8 #include "io_lib_header.h"
9 #include "util_lib_header.h"
10 #include "define_header.h"
18 void fatal(char *,...);
19 void error(char *,...);
20 void warning(char *,...);
22 char *blank_to_(char *); /* DES change blanks to _ */
25 void getstr(char *,char *);
26 double getreal(char *,double,double,double);
27 int getint(char *,int,int,int);
29 Boolean linetype(char *,char *);
30 Boolean blankline(char *);
31 void get_path(char *,char *);
36 * Tries to allocate "bytes" bytes of memory. Exits program if failed.
38 * Generic pointer to the newly allocated memory.
41 void *ckalloc(size_t bytes)
44 extern void *vcalloc (size_t nelem, size_t elsize);
46 if( (ret = vcalloc(bytes, sizeof(char))) == NULL)
48 if( (ret = vmalloc(bytes)) == NULL)
50 fatal("Out of memory\n");
59 * Tries to vreallocate "bytes" bytes of memory. Exits program if failed.
61 * Generic pointer to the re-allocated memory.
64 void *ckvrealloc(void *ptr, size_t bytes)
67 extern void *vrealloc (void *ptr, size_t size);
69 if( (ret = vrealloc(ptr, bytes)) == NULL)
70 fatal("Out of memory\n");
79 * Tries to free memory allocated by ckalloc.
84 void ckfree(void *ptr)
93 * Prints error msg to stderr and exits.
94 * Variadic parameter list can be passed.
100 void fatal( char *msg,...)
105 fprintf(stderr,"\n\nFATAL ERROR: ");
106 vfprintf(stderr,msg,ap);
107 fprintf(stderr,"\n\n");
109 myexit(EXIT_FAILURE);
115 * Prints error msg to stderr.
116 * Variadic parameter list can be passed.
122 void error( char *msg,...)
127 fprintf(stderr,"\n\nERROR: ");
128 vfprintf(stderr,msg,ap);
129 fprintf(stderr,"\n\n");
136 * Prints warning msg to stderr.
137 * Variadic parameter list can be passed.
143 void warning( char *msg,...)
148 fprintf(stderr,"\n\nWARNING: ");
149 vfprintf(stderr,msg,ap);
150 fprintf(stderr,"\n\n");
158 * Removes trailing blanks from a string
161 * Pointer to the processed string
164 char * rtrim(char *str)
170 while ( isspace(str[p]) )
182 * Replace blanks in a string with underscores
184 * Also replaces , ; : ( or ) with _
187 * Pointer to the processed string
190 char * blank_to_(char *str)
198 if( strrchr(";,():",str[i]))str[i]='_';
199 else if (isspace(str[i]));
208 * Converts string str to uppercase.
210 * Pointer to the converted string.
213 char * upstr(char *str)
215 register char *s = str;
217 while( (*s = toupper(*s)) )
226 * Converts string str to lower case.
228 * Pointer to the converted string.
231 char * lowstr(char *str)
233 register char *s = str;
235 while( (*s = tolower(*s)) )
241 void getstr(char *instr,char *outstr)
243 fprintf(stdout,"%s: ",instr);
244 fgets(outstr, 100, stdin);
247 double getreal(char *instr,double minx,double maxx,double def)
254 fprintf(stdout,"%s (%.1lf-%.1lf) [%.1lf]: ",instr,minx,maxx,def);
255 fgets(line, MAXLINE, stdin);
256 status=sscanf(line,"%lf",&ret);
257 if(status == EOF) return def;
259 fprintf(stderr,"ERROR: Max. value=%.1lf\n\n",maxx);
263 fprintf(stderr,"ERROR: Min. value=%.1lf\n\n",minx);
272 int getint(char *instr,int minx,int maxx, int def)
278 fprintf(stdout,"%s (%d..%d) [%d]: ",
279 instr,(pint)minx,(pint)maxx,(pint)def);
280 fgets(line, MAXLINE, stdin);
281 status=sscanf(line,"%d",&ret);
282 if(status == EOF) return def;
284 fprintf(stderr,"ERROR: Max. value=%d\n\n",(pint)maxx);
288 fprintf(stderr,"ERROR: Min. value=%d\n\n",(pint)minx);
300 getstr("\n\nEnter system command",line);
303 fprintf(stdout,"\n\n");
307 Boolean linetype(char *line,char *code)
309 return( strncmp(line,code,strlen(code)) == 0 );
312 Boolean blankline(char *line)
316 for(i=0;line[i]!='\n' && line[i]!=EOS;i++) {
317 if( isdigit(line[i]) ||
329 void get_path(char *str,char *path)
334 for(i=strlen(path)-1;i>-1;--i) {
335 if(str[i]==DIRDELIM) {
339 if(str[i]=='.') break;
346 /*********************************COPYRIGHT NOTICE**********************************/
347 /*© Centro de Regulacio Genomica */
349 /*Cedric Notredame */
350 /*Tue Oct 27 10:12:26 WEST 2009. */
351 /*All rights reserved.*/
352 /*This file is part of T-COFFEE.*/
354 /* T-COFFEE is free software; you can redistribute it and/or modify*/
355 /* it under the terms of the GNU General Public License as published by*/
356 /* the Free Software Foundation; either version 2 of the License, or*/
357 /* (at your option) any later version.*/
359 /* T-COFFEE is distributed in the hope that it will be useful,*/
360 /* but WITHOUT ANY WARRANTY; without even the implied warranty of*/
361 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the*/
362 /* GNU General Public License for more details.*/
364 /* You should have received a copy of the GNU General Public License*/
365 /* along with Foobar; if not, write to the Free Software*/
366 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
367 /*............................................... |*/
368 /* If you need some more information*/
369 /* cedric.notredame@europe.com*/
370 /*............................................... |*/
374 /*********************************COPYRIGHT NOTICE**********************************/