2 * Copyright (C) 1996-1998 Szeredi Miklos
3 * Email: mszeredi@inf.bme.hu
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. See the file COPYING.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define DIR_SEP_CHAR '/'
31 char *get_base_name(char *fname
)
37 for(; p
>= fname
&& *p
!= DIR_SEP_CHAR
; p
--);
42 int check_ext(const char *filename
, const char *ext
)
47 flen
= (int) rb
->strlen(filename
);
48 elen
= (int) rb
->strlen(ext
);
50 if(flen
<= elen
+ 1) return 0;
52 if(filename
[flen
-elen
-1] != '.') return 0;
53 for(i
= 0; i
< elen
; i
++) if(filename
[flen
-elen
+i
] != toupper(ext
[i
])) break;
54 if(i
== elen
) return 1;
55 for(i
= 0; i
< elen
; i
++) if(filename
[flen
-elen
+i
] != tolower(ext
[i
])) break;
56 if(i
== elen
) return 1;
60 void add_extension(char *filename
, const char *ext
)
65 i
= (int) rb
->strlen(filename
);
66 if(filename
[i
] > 64 && filename
[i
] < 96) upper
= 1;
71 for(; *ext
; i
++, ext
++) filename
[i
] = toupper(*ext
);
73 for(; *ext
; i
++, ext
++) filename
[i
] = tolower(*ext
);
76 int file_exist(const char *filename
)
81 fd
= rb
->open(filename
, O_RDONLY
);
87 /* if(errno == ENOENT) return 0;
91 int try_extension(char *filename
, const char *ext
)
95 tend
= (int) rb
->strlen(filename
);
96 add_extension(filename
, ext
);
97 if(file_exist(filename
)) return 1;
99 filename
[tend
] = '\0';
103 void *malloc_err(size_t size
)
107 p
= (char *) my_malloc(size
);
109 // fprintf(stderr, "Out of memory!\n");
115 char *make_string(char *ostr
, const char *nstr
)
117 if(ostr
!= NULL
) /*free(ostr)*/ostr
=0;
118 ostr
= malloc_err(rb
->strlen(nstr
) + 1);
119 rb
->strcpy(ostr
, nstr
);
123 void free_string(char *ostr
)
125 if(ostr
!= NULL
) /*free(ostr)*/ostr
=0;
128 int mis_strcasecmp(const char *s1
, const char *s2
)
136 if(!c1
|| c1
!= c2
) break;