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.
28 #define DIR_SEP_CHAR '/'
30 char *get_base_name(char *fname
)
36 for(; p
>= fname
&& *p
!= DIR_SEP_CHAR
; p
--);
41 int check_ext(const char *filename
, const char *ext
)
46 flen
= (int) rb
->strlen(filename
);
47 elen
= (int) rb
->strlen(ext
);
49 if(flen
<= elen
+ 1) return 0;
51 if(filename
[flen
-elen
-1] != '.') return 0;
52 for(i
= 0; i
< elen
; i
++) if(filename
[flen
-elen
+i
] != toupper(ext
[i
])) break;
53 if(i
== elen
) return 1;
54 for(i
= 0; i
< elen
; i
++) if(filename
[flen
-elen
+i
] != tolower(ext
[i
])) break;
55 if(i
== elen
) return 1;
59 void add_extension(char *filename
, const char *ext
)
64 i
= (int) rb
->strlen(filename
);
65 if(filename
[i
] > 64 && filename
[i
] < 96) upper
= 1;
70 for(; *ext
; i
++, ext
++) filename
[i
] = toupper(*ext
);
72 for(; *ext
; i
++, ext
++) filename
[i
] = tolower(*ext
);
75 int file_exist(const char *filename
)
80 fd
= rb
->open(filename
, O_RDONLY
);
86 /* if(errno == ENOENT) return 0;
90 int try_extension(char *filename
, const char *ext
)
94 tend
= (int) rb
->strlen(filename
);
95 add_extension(filename
, ext
);
96 if(file_exist(filename
)) return 1;
98 filename
[tend
] = '\0';
102 void *malloc_err(size_t size
)
106 p
= (char *) my_malloc(size
);
108 // fprintf(stderr, "Out of memory!\n");
114 char *make_string(char *ostr
, const char *nstr
)
116 if(ostr
!= NULL
) /*free(ostr)*/ostr
=0;
117 ostr
= malloc_err(rb
->strlen(nstr
) + 1);
118 rb
->strcpy(ostr
, nstr
);
122 void free_string(char *ostr
)
124 if(ostr
!= NULL
) /*free(ostr)*/ostr
=0;
127 int mis_strcasecmp(const char *s1
, const char *s2
)
135 if(!c1
|| c1
!= c2
) break;