TORCS  1.3.9
The Open Racing Car Simulator
directory.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  directory.cpp -- directory management
3  -------------------
4  created : Fri Aug 13 21:58:55 CEST 1999
5  copyright : (C) 1999-2014 by Eric Espie, Bernhard Wymann
6  email : torcs@free.fr
7  version : $Id$
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
25 #include <stdlib.h>
26 #ifdef WIN32
27 #include <windows.h>
28 #endif
29 #include <tgf.h>
30 #include "os.h"
31 
32 void
33 gfDirInit(void)
34 {
35 }
36 
37 
43 tFList * GfDirGetList(const char *dir)
44 {
45  if (GfOs.dirGetList) {
46  return GfOs.dirGetList(dir);
47  } else {
48  return (tFList*)NULL;
49  }
50 }
51 
52 
59 tFList * GfDirGetListFiltered(const char *dir, const char *suffix)
60 {
62  return GfOs.dirGetListFiltered(dir, suffix);
63  } else {
64  return (tFList*)NULL;
65  }
66 }
67 
76 void GfDirFreeList(tFList *list, tfDirfreeUserData freeUserData, bool freename, bool freedispname)
77 {
78  if (list) {
79  // The list contains at least one element, checked above.
80  tFList *rl = list;
81  do {
82  tFList *tmp = rl;
83  rl = rl->next;
84  if ((freeUserData) && (tmp->userData)) {
85  freeUserData(tmp->userData);
86  }
87  if (freename && tmp->name != NULL) {
88  freez(tmp->name);
89  }
90  if (freedispname && tmp->dispName != NULL) {
91  freez(tmp->dispName);
92  }
93  free(tmp);
94  } while (rl != list);
95  }
96 }
97 
tFList * GfDirGetListFiltered(const char *dir, const char *suffix)
Get the list of files with matching suffix of a given directory.
Definition: directory.cpp:59
void * userData
User data.
Definition: tgf.h:235
tfDirGetList dirGetList
Definition: os.h:44
void gfDirInit(void)
Definition: directory.cpp:33
List of (DLL) files for a Directory.
Definition: tgf.h:229
struct FList * next
Next entry.
Definition: tgf.h:231
char * dispName
Name to display on screen.
Definition: tgf.h:234
void(* tfDirfreeUserData)(void *)
Function to call for releasing the user data associated with file entry.
Definition: tgf.h:240
The Gaming Framework API.
tGfOs GfOs
Definition: os.cpp:37
void GfDirFreeList(tFList *list, tfDirfreeUserData freeUserData, bool freename, bool freedispname)
Free a directory list.
Definition: directory.cpp:76
tfDirGetListFiltered dirGetListFiltered
Definition: os.h:45
char * name
File name.
Definition: tgf.h:233
tFList * GfDirGetList(const char *dir)
Get the list of files of a given directory.
Definition: directory.cpp:43
#define freez
Definition: tgf.h:67