00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031
00032
00033
00034
00035
00036
00037
00038 struct vfsref;
00039 struct vfsent;
00040
00044 struct vfslist {
00048 struct vfsref *first;
00052 struct vfsref *last;
00056 unsigned int items;
00057 };
00058
00063 struct vfsmodule {
00067 int (*match)(struct vfsent *ve, int isdir);
00071 int (*populate)(struct vfsent *ve);
00075 FILE *(*open)(struct vfsent *ve);
00076
00080 char pseudo;
00081
00085 unsigned char sortorder;
00086
00090 char marking;
00091 };
00092
00099 struct vfsent {
00103 char *name;
00107 char *filename;
00108
00113 int refcount;
00114
00118 struct vfsmodule *vmod;
00122 struct vfslist population;
00126 int recurse;
00127 };
00128
00132 struct vfsref {
00136 struct vfsent *ent;
00140 struct vfsref *next;
00144 struct vfsref *prev;
00149 int marked;
00150 };
00151
00155 struct vfsmatch {
00159 regex_t regex;
00163 char *string;
00164 };
00165
00169 #define VFSLIST_INITIALIZER { NULL, NULL, 0 }
00170
00174 static inline void
00175 vfs_list_init(struct vfslist *vl)
00176 {
00177 vl->first = vl->last = NULL;
00178 vl->items = 0;
00179 }
00180
00184 static inline void
00185 vfs_list_move(struct vfslist *vdst, const struct vfslist *vsrc)
00186 {
00187 memcpy(vdst, vsrc, sizeof(struct vfslist));
00188 }
00189
00193 static inline struct vfsref *
00194 vfs_list_first(const struct vfslist *vl)
00195 {
00196 return (vl->first);
00197 }
00198
00202 static inline struct vfsref *
00203 vfs_list_last(const struct vfslist *vl)
00204 {
00205 return (vl->last);
00206 }
00207
00211 static inline int
00212 vfs_list_empty(const struct vfslist *vl)
00213 {
00214 return (vl->first == NULL);
00215 }
00216
00220 static inline unsigned int
00221 vfs_list_items(const struct vfslist *vl)
00222 {
00223 return (vl->items);
00224 }
00225
00229 static inline struct vfsref *
00230 vfs_list_next(const struct vfsref *vr)
00231 {
00232 return (vr->next);
00233 }
00234
00238 static inline struct vfsref *
00239 vfs_list_prev(const struct vfsref *vr)
00240 {
00241 return (vr->prev);
00242 }
00243
00247 #define VFS_LIST_FOREACH(vl, vr) \
00248 for (vr = vfs_list_first(vl); vr != NULL; vr = vfs_list_next(vr))
00249
00252 #define VFS_LIST_FOREACH_REVERSE(vl, vr) \
00253 for (vr = vfs_list_last(vl); vr != NULL; vr = vfs_list_prev(vr))
00254
00258 static inline void
00259 vfs_list_remove(struct vfslist *vl, struct vfsref *vr)
00260 {
00261 if (vr->next == NULL) {
00262
00263 g_assert(vl->last == vr);
00264 vl->last = vr->prev;
00265 } else {
00266
00267 vr->next->prev = vr->prev;
00268 }
00269 if (vr->prev == NULL) {
00270
00271 g_assert(vl->first == vr);
00272 vl->first = vr->next;
00273 } else {
00274
00275 vr->prev->next = vr->next;
00276 }
00277 vl->items--;
00278 }
00279
00283 static inline void
00284 vfs_list_insert_head(struct vfslist *vl, struct vfsref *vr)
00285 {
00286 vr->prev = NULL;
00287 vr->next = vl->first;
00288 vl->first = vr;
00289 if (vr->next != NULL) {
00290
00291 vr->next->prev = vr;
00292 } else {
00293
00294 vl->last = vr;
00295 }
00296 vl->items++;
00297 }
00298
00302 static inline void
00303 vfs_list_insert_tail(struct vfslist *vl, struct vfsref *vr)
00304 {
00305 vr->prev = vl->last;
00306 vr->next = NULL;
00307 vl->last = vr;
00308 if (vr->prev != NULL) {
00309
00310 vr->prev->next = vr;
00311 } else {
00312
00313 vl->first = vr;
00314 }
00315 vl->items++;
00316 }
00317
00321 static inline void
00322 vfs_list_insert_before(struct vfslist *vl, struct vfsref *nvr,
00323 struct vfsref *lvr)
00324 {
00325 nvr->prev = lvr->prev;
00326 nvr->next = lvr;
00327 lvr->prev = nvr;
00328 if (nvr->prev != NULL) {
00329
00330 nvr->prev->next = nvr;
00331 } else {
00332
00333 vl->first = nvr;
00334 }
00335 vl->items++;
00336 }
00337
00341 static inline void
00342 vfs_list_insert_after(struct vfslist *vl, struct vfsref *nvr,
00343 struct vfsref *lvr)
00344 {
00345 nvr->prev = lvr;
00346 nvr->next = lvr->next;
00347 lvr->next = nvr;
00348 if (nvr->next != NULL) {
00349
00350 nvr->next->prev = nvr;
00351 } else {
00352
00353 vl->last = nvr;
00354 }
00355 vl->items++;
00356 }
00357
00362 const char *vfs_lockup(void);
00363
00373 struct vfsref *vfs_lookup(const char *filename, const char *name,
00374 const char *basepath, int strict);
00378 struct vfsref *vfs_dup(const struct vfsref *vr);
00384 void vfs_close(struct vfsref *vr);
00388 int vfs_populate(const struct vfsref *vr);
00393 void vfs_unfold(struct vfslist *vl, const struct vfsref *vr);
00399 void vfs_locate(struct vfslist *vl, const struct vfsref *vr,
00400 const struct vfsmatch *vm);
00404 struct vfsref *vfs_write_playlist(const struct vfslist *vl,
00405 const struct vfsref *vr, const char *filename);
00409 int vfs_delete(const char *filename);
00413 FILE *vfs_fopen(const char *filename, const char *mode);
00417 int vfs_fgets(char *str, size_t size, FILE *fp);
00418
00422 static inline const char *
00423 vfs_name(const struct vfsref *vr)
00424 {
00425 return (vr->ent->name);
00426 }
00427
00431 static inline const char *
00432 vfs_filename(const struct vfsref *vr)
00433 {
00434 return (vr->ent->filename);
00435 }
00436
00440 static inline int
00441 vfs_playable(const struct vfsref *vr)
00442 {
00443 return (vr->ent->vmod->open != NULL);
00444 }
00445
00449 static inline FILE *
00450 vfs_open(const struct vfsref *vr)
00451 {
00452 return vr->ent->vmod->open(vr->ent);
00453 }
00454
00458 static inline int
00459 vfs_populatable(const struct vfsref *vr)
00460 {
00461 return (vr->ent->vmod->populate != NULL);
00462 }
00463
00468 static inline char
00469 vfs_marking(const struct vfsref *vr)
00470 {
00471 return (vr->ent->vmod->marking);
00472 }
00473
00477 static inline const struct vfslist *
00478 vfs_population(const struct vfsref *vr)
00479 {
00480 return (&vr->ent->population);
00481 }
00482
00486 static inline int
00487 vfs_marked(const struct vfsref *vr)
00488 {
00489 return (vr->marked != 0);
00490 }
00491
00495 static inline void
00496 vfs_mark(struct vfsref *vr)
00497 {
00498 vr->marked = 1;
00499 }
00500
00504 static inline void
00505 vfs_unmark(struct vfsref *vr)
00506 {
00507 vr->marked = 0;
00508 }
00509
00513 struct vfsmatch *vfs_match_new(const char *str);
00517 void vfs_match_free(struct vfsmatch *vm);
00518
00522 static inline int
00523 vfs_match_compare(const struct vfsmatch *vm, const char *name)
00524 {
00525 return (regexec(&vm->regex, name, 0, NULL, 0) == 0);
00526 }
00527
00531 static inline const char *
00532 vfs_match_value(const struct vfsmatch *vm)
00533 {
00534 return (vm->string);
00535 }