diff options
Diffstat (limited to 'apps/plugins/zxbox/spconf.c')
-rw-r--r-- | apps/plugins/zxbox/spconf.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/apps/plugins/zxbox/spconf.c b/apps/plugins/zxbox/spconf.c new file mode 100644 index 0000000000..7c49269fa3 --- /dev/null +++ b/apps/plugins/zxbox/spconf.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1996-1998 Szeredi Miklos | ||
3 | * Email: mszeredi@inf.bme.hu | ||
4 | * | ||
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. | ||
9 | * | ||
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. | ||
14 | * | ||
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. | ||
18 | * | ||
19 | */ | ||
20 | #include "misc.h" | ||
21 | #include "spconf_p.h" | ||
22 | #include "spver.h" | ||
23 | #include "interf.h" | ||
24 | #include "spscr_p.h" | ||
25 | #include "spkey.h" | ||
26 | |||
27 | #include "snapshot.h" /* for SN_Z80 and SN_SNA */ | ||
28 | #include "tapefile.h" /* for TAP_TAP and TAP_TZX */ | ||
29 | #include "zxconfig.h" | ||
30 | #include "stdio.h" | ||
31 | #include "string.h" | ||
32 | /*#include <errno.h>*/ | ||
33 | #include "sys/types.h" | ||
34 | #include "helpers.h" | ||
35 | #include "ctype.h" | ||
36 | |||
37 | |||
38 | extern const char *spcf_keynames_ascii[]; | ||
39 | extern const char *spcf_keynames_misc[]; | ||
40 | |||
41 | char *spcf_init_snapshot = NULL; | ||
42 | int spcf_init_snapshot_type; | ||
43 | char *spcf_init_tapefile = NULL; | ||
44 | int spcf_init_tapefile_type; | ||
45 | #ifndef USE_GRAY | ||
46 | #define exit(i) rb->splash(HZ*1,true,"Exit: %d",i) | ||
47 | #else | ||
48 | #define exit(i) i=i | ||
49 | #endif | ||
50 | #define MAXLINELEN 512 | ||
51 | /*static int linectr; | ||
52 | static FILE *conffp; | ||
53 | static int conffd; | ||
54 | static const char *conffile; | ||
55 | */ | ||
56 | |||
57 | static int file_type = -1; | ||
58 | static int file_subtype; | ||
59 | |||
60 | struct ext_type { | ||
61 | const char *ext; | ||
62 | int type; | ||
63 | int subtype; | ||
64 | }; | ||
65 | |||
66 | static struct ext_type extensions[] = { | ||
67 | {"z80", FT_SNAPSHOT, SN_Z80}, | ||
68 | {"sna", FT_SNAPSHOT, SN_SNA}, | ||
69 | {"tzx", FT_TAPEFILE, TAP_TZX}, | ||
70 | {"tap", FT_TAPEFILE, TAP_TAP}, | ||
71 | |||
72 | {NULL, 0, 0} | ||
73 | }; | ||
74 | |||
75 | int spcf_find_file_type(char *filename, int *ftp, int *ftsubp) | ||
76 | { | ||
77 | int i; | ||
78 | int found; | ||
79 | |||
80 | if(*ftp >= 0 && *ftsubp >= 0) return 1; | ||
81 | |||
82 | found = 0; | ||
83 | |||
84 | for(i = 0; extensions[i].ext != NULL; i++) | ||
85 | if((*ftp < 0 || *ftp == extensions[i].type) && | ||
86 | (*ftsubp < 0 || *ftsubp == extensions[i].subtype) && | ||
87 | check_ext(filename, extensions[i].ext)) { | ||
88 | found = 1; | ||
89 | *ftp = extensions[i].type; | ||
90 | *ftsubp = extensions[i].subtype; | ||
91 | break; | ||
92 | } | ||
93 | |||
94 | if(!found) for(i = 0; extensions[i].ext != NULL; i++) | ||
95 | if((*ftp < 0 || *ftp == extensions[i].type) && | ||
96 | (*ftsubp < 0 || *ftsubp == extensions[i].subtype) && | ||
97 | try_extension(filename, extensions[i].ext)) { | ||
98 | found = 1; | ||
99 | *ftp = extensions[i].type; | ||
100 | *ftsubp = extensions[i].subtype; | ||
101 | break; | ||
102 | } | ||
103 | |||
104 | return found; | ||
105 | } | ||
106 | |||
107 | static int find_extension(const char *ext) | ||
108 | { | ||
109 | int i; | ||
110 | for(i = 0; extensions[i].ext != NULL; i++) | ||
111 | if(rb->strcasecmp(extensions[i].ext, ext) == 0) return i; | ||
112 | |||
113 | return -1; | ||
114 | } | ||
115 | |||
116 | |||
117 | /* now actually a snapshot/tape loader*/ | ||
118 | void spcf_read_command_line(void* parameter) | ||
119 | { | ||
120 | int ix; | ||
121 | |||
122 | ix = find_extension( parameter - 3 + rb->strlen (parameter) ); | ||
123 | |||
124 | file_type = extensions[ix].type; | ||
125 | file_subtype = extensions[ix].subtype; | ||
126 | rb->strncpy(filenamebuf, parameter, MAXFILENAME - 10); | ||
127 | filenamebuf[MAXFILENAME-10] = '\0'; | ||
128 | if(file_type < 0) file_subtype = -1; | ||
129 | if(!spcf_find_file_type(filenamebuf, &file_type, &file_subtype)) | ||
130 | return; | ||
131 | |||
132 | if(file_type == FT_SNAPSHOT) { | ||
133 | spcf_init_snapshot = make_string(spcf_init_snapshot, filenamebuf); | ||
134 | spcf_init_snapshot_type = file_subtype; | ||
135 | } | ||
136 | else if(file_type == FT_TAPEFILE) { | ||
137 | spcf_init_tapefile = make_string(spcf_init_tapefile, filenamebuf); | ||
138 | spcf_init_tapefile_type = file_subtype; | ||
139 | } | ||
140 | } | ||
141 | |||