Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / apps / plugins / zxbox / spconf.c
blob0daabc7d77489b04cf3905db06304fc6ef0951f7
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 <stdio.h>
22 #include <string.h>
23 #include <ctype.h>
24 #include "zxmisc.h"
25 #include "spconf_p.h"
26 #include "interf.h"
27 #include "spscr_p.h"
28 #include "spkey.h"
30 #include "snapshot.h" /* for SN_Z80 and SN_SNA */
31 #include "tapefile.h" /* for TAP_TAP and TAP_TZX */
32 #include "zxconfig.h"
33 #include "helpers.h"
36 extern const char *spcf_keynames_ascii[];
37 extern const char *spcf_keynames_misc[];
39 char *spcf_init_snapshot = NULL;
40 int spcf_init_snapshot_type;
41 char *spcf_init_tapefile = NULL;
42 int spcf_init_tapefile_type;
45 static int file_type = -1;
46 static int file_subtype;
48 struct ext_type {
49 const char *ext;
50 int type;
51 int subtype;
54 static struct ext_type extensions[] = {
55 {"z80", FT_SNAPSHOT, SN_Z80},
56 {"sna", FT_SNAPSHOT, SN_SNA},
57 {"tzx", FT_TAPEFILE, TAP_TZX},
58 {"tap", FT_TAPEFILE, TAP_TAP},
60 {NULL, 0, 0}
63 int spcf_find_file_type(char *filename, int *ftp, int *ftsubp)
65 int i;
66 int found;
68 if(*ftp >= 0 && *ftsubp >= 0) return 1;
70 found = 0;
72 for(i = 0; extensions[i].ext != NULL; i++)
73 if((*ftp < 0 || *ftp == extensions[i].type) &&
74 (*ftsubp < 0 || *ftsubp == extensions[i].subtype) &&
75 check_ext(filename, extensions[i].ext)) {
76 found = 1;
77 *ftp = extensions[i].type;
78 *ftsubp = extensions[i].subtype;
79 break;
82 if(!found) for(i = 0; extensions[i].ext != NULL; i++)
83 if((*ftp < 0 || *ftp == extensions[i].type) &&
84 (*ftsubp < 0 || *ftsubp == extensions[i].subtype) &&
85 try_extension(filename, extensions[i].ext)) {
86 found = 1;
87 *ftp = extensions[i].type;
88 *ftsubp = extensions[i].subtype;
89 break;
92 return found;
95 static int find_extension(const char *ext)
97 int i;
98 for(i = 0; extensions[i].ext != NULL; i++)
99 if(rb->strcasecmp(extensions[i].ext, ext) == 0) return i;
101 return -1;
105 /* now actually a snapshot/tape loader*/
106 void spcf_read_command_line(const void* parameter)
108 int ix;
110 ix = find_extension( parameter - 3 + rb->strlen (parameter) );
112 file_type = extensions[ix].type;
113 file_subtype = extensions[ix].subtype;
114 rb->strlcpy(filenamebuf, parameter, MAXFILENAME - 10 + 1);
115 if(file_type < 0) file_subtype = -1;
116 if(!spcf_find_file_type(filenamebuf, &file_type, &file_subtype))
117 return;
119 if(file_type == FT_SNAPSHOT) {
120 spcf_init_snapshot = make_string(spcf_init_snapshot, filenamebuf);
121 spcf_init_snapshot_type = file_subtype;
123 else if(file_type == FT_TAPEFILE) {
124 spcf_init_tapefile = make_string(spcf_init_tapefile, filenamebuf);
125 spcf_init_tapefile_type = file_subtype;