~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/emu/fileio.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    TYPE DEFINITIONS
39
39
***************************************************************************/
40
40
 
 
41
typedef struct _path_iterator path_iterator;
 
42
struct _path_iterator
 
43
{
 
44
        const char *    base;
 
45
        const char *    cur;
 
46
        int                             index;
 
47
};
 
48
 
 
49
 
41
50
/* typedef struct _mame_file mame_file -- declared in fileio.h */
42
51
struct _mame_file
43
52
{
46
55
#endif
47
56
        astring *               filename;                                               /* full filename */
48
57
        core_file *             file;                                                   /* core file pointer */
 
58
        path_iterator   iterator;                                               /* iterator for paths */
49
59
        UINT32                  openflags;                                              /* flags we used for the open */
50
60
        char                    hash[HASH_BUF_SIZE];                    /* hash data for the file */
51
61
        zip_file *              zipfile;                                                /* ZIP file pointer */
54
64
};
55
65
 
56
66
 
57
 
typedef struct _path_iterator path_iterator;
58
 
struct _path_iterator
59
 
{
60
 
        const char *    base;
61
 
        const char *    cur;
62
 
        int                             index;
63
 
};
64
 
 
65
 
 
66
67
/* typedef struct _mame_path mame_path -- declared in fileio.h */
67
68
struct _mame_path
68
69
{
82
83
static void fileio_exit(running_machine *machine);
83
84
 
84
85
/* file open/close */
85
 
static file_error fopen_internal(core_options *opts, const char *searchpath, const char *filename, UINT32 crc, UINT32 flags, mame_file **file);
 
86
static file_error fopen_internal(core_options *opts, path_iterator *iterator, const char *filename, UINT32 crc, UINT32 flags, mame_file **file);
86
87
static file_error fopen_attempt_zipped(astring *fullname, UINT32 crc, UINT32 openflags, mame_file *file);
87
88
 
88
89
/* path iteration */
134
135
 
135
136
file_error mame_fopen(const char *searchpath, const char *filename, UINT32 openflags, mame_file **file)
136
137
{
137
 
        return fopen_internal(mame_options(), searchpath, filename, 0, openflags, file);
 
138
        path_iterator iterator;
 
139
        path_iterator_init(&iterator, mame_options(), searchpath);
 
140
        return fopen_internal(mame_options(), &iterator, filename, 0, openflags, file);
138
141
}
139
142
 
140
143
 
145
148
 
146
149
file_error mame_fopen_crc(const char *searchpath, const char *filename, UINT32 crc, UINT32 openflags, mame_file **file)
147
150
{
 
151
        path_iterator iterator;
 
152
        path_iterator_init(&iterator, mame_options(), searchpath);
148
153
        return mame_fopen_crc_options(mame_options(), searchpath, filename, crc, openflags, file);
149
154
}
150
155
 
156
161
 
157
162
file_error mame_fopen_options(core_options *opts, const char *searchpath, const char *filename, UINT32 openflags, mame_file **file)
158
163
{
159
 
        return fopen_internal(opts, searchpath, filename, 0, openflags, file);
 
164
        path_iterator iterator;
 
165
        path_iterator_init(&iterator, opts, searchpath);
 
166
        return fopen_internal(opts, &iterator, filename, 0, openflags, file);
160
167
}
161
168
 
162
169
 
167
174
 
168
175
file_error mame_fopen_crc_options(core_options *opts, const char *searchpath, const char *filename, UINT32 crc, UINT32 openflags, mame_file **file)
169
176
{
170
 
        return fopen_internal(opts, searchpath, filename, crc, openflags | OPEN_FLAG_HAS_CRC, file);
 
177
        path_iterator iterator;
 
178
        path_iterator_init(&iterator, opts, searchpath);
 
179
        return fopen_internal(opts, &iterator, filename, crc, openflags | OPEN_FLAG_HAS_CRC, file);
171
180
}
172
181
 
173
182
 
212
221
    fopen_internal - open a file
213
222
-------------------------------------------------*/
214
223
 
215
 
static file_error fopen_internal(core_options *opts, const char *searchpath, const char *filename, UINT32 crc, UINT32 openflags, mame_file **file)
 
224
static file_error fopen_internal(core_options *opts, path_iterator *iterator, const char *filename, UINT32 crc, UINT32 openflags, mame_file **file)
216
225
{
217
226
        file_error filerr = FILERR_NOT_FOUND;
218
 
        path_iterator iterator;
219
227
 
220
228
        /* can either have a hash or open for write, but not both */
221
229
        if ((openflags & OPEN_FLAG_HAS_CRC) && (openflags & OPEN_FLAG_WRITE))
233
241
        (*file)->debug_cookie = DEBUG_COOKIE;
234
242
#endif
235
243
 
236
 
        /* if the path is absolute, null out the search path */
237
 
        if (searchpath != NULL && osd_is_absolute_path(searchpath))
238
 
                searchpath = NULL;
239
 
 
240
 
        /* determine the maximum length of a composed filename, plus some extra space for .zip extensions */
241
 
        path_iterator_init(&iterator, opts, searchpath);
242
 
 
243
244
        /* loop over paths */
244
245
        (*file)->filename = astring_alloc();
245
 
        while (path_iterator_get_next(&iterator, (*file)->filename))
 
246
        while (path_iterator_get_next(iterator, (*file)->filename))
246
247
        {
247
248
                /* compute the full pathname */
248
249
                if (astring_len((*file)->filename) > 0)
263
264
                }
264
265
        }
265
266
 
 
267
        /* if we succeeded, save the iterator */
 
268
        if (filerr == FILERR_NONE)
 
269
                (*file)->iterator = *iterator;
 
270
 
266
271
        /* handle errors and return */
267
 
        if (filerr != FILERR_NONE)
 
272
        else
268
273
        {
269
274
                mame_fclose(*file);
270
275
                *file = NULL;
389
394
 
390
395
 
391
396
/*-------------------------------------------------
 
397
    mame_fclose_and_open_next - close an open
 
398
    file, and open the next entry in the original
 
399
    searchpath
 
400
-------------------------------------------------*/
 
401
 
 
402
file_error mame_fclose_and_open_next(mame_file **file, const char *filename, UINT32 openflags)
 
403
{
 
404
        path_iterator iterator = (*file)->iterator;
 
405
        mame_fclose(*file);
 
406
        *file = NULL;
 
407
        return fopen_internal(mame_options(), &iterator, filename, 0, openflags, file);
 
408
}
 
409
 
 
410
 
 
411
/*-------------------------------------------------
392
412
    mame_fcompress - enable/disable streaming file
393
413
    compression via zlib; level is 0 to disable
394
414
    compression, or up to 9 for max compression
803
823
{
804
824
        /* reset the structure */
805
825
        memset(iterator, 0, sizeof(*iterator));
806
 
        iterator->base = (searchpath != NULL) ? options_get_string(opts, searchpath) : "";
 
826
        iterator->base = (searchpath != NULL && !osd_is_absolute_path(searchpath)) ? options_get_string(opts, searchpath) : "";
807
827
        iterator->cur = iterator->base;
808
828
}
809
829