Rearange menu of mpegplayer. Add new menu with "settings" and "quit", and remove...
[kugel-rb.git] / apps / plugins / zxbox / zxmisc.c
blobc4dbf888e5ad43e996140d7ba080a02275094ac3
1 /*
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.
21 #include "zxmisc.h"
22 #include "zxconfig.h"
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <ctype.h>
27 #include "helpers.h"
28 #include "zxconfig.h"
29 #define DIR_SEP_CHAR '/'
31 char *get_base_name(char *fname)
33 char *p;
35 p = fname;
36 for(; *p; p++);
37 for(; p >= fname && *p != DIR_SEP_CHAR; p--);
38 return ++p;
42 int check_ext(const char *filename, const char *ext)
44 int flen, elen;
45 int i;
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;
57 return 0;
60 void add_extension(char *filename, const char *ext)
62 int i;
63 int upper;
65 i = (int) rb->strlen(filename);
66 if(filename[i] > 64 && filename[i] < 96) upper = 1;
67 else upper = 0;
69 filename[i++] = '.';
70 if(upper)
71 for(; *ext; i++, ext++) filename[i] = toupper(*ext);
72 else
73 for(; *ext; i++, ext++) filename[i] = tolower(*ext);
76 int file_exist(const char *filename)
78 /*FILE *fp;*/
79 int fd;
81 fd = rb->open(filename, O_RDONLY);
82 if(fd >= 0) {
83 rb->close(fd);
84 return 1;
86 else return 0;
87 /* if(errno == ENOENT) return 0;
88 return 1;*/
91 int try_extension(char *filename, const char *ext)
93 int tend;
95 tend = (int) rb->strlen(filename);
96 add_extension(filename, ext);
97 if(file_exist(filename)) return 1;
99 filename[tend] = '\0';
100 return 0;
103 void *malloc_err(size_t size)
105 char *p;
107 p = (char *) my_malloc(size);
108 if(p == NULL) {
109 // fprintf(stderr, "Out of memory!\n");
110 /*exit(1);*/
112 return (void *) p;
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);
120 return ostr;
123 void free_string(char *ostr)
125 if(ostr != NULL) /*free(ostr)*/ostr=0;
128 int mis_strcasecmp(const char *s1, const char *s2)
130 int c1, c2;
132 for(;; s1++, s2++) {
133 c1 = tolower(*s1);
134 c2 = tolower(*s2);
136 if(!c1 || c1 != c2) break;
138 return c1-c2;