]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
now loads gamedir/*.pak instead of gamedir/pak#.pak, sorted by ASCII value (note...
authorlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 25 Mar 2002 22:51:57 +0000 (22:51 +0000)
committerlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 25 Mar 2002 22:51:57 +0000 (22:51 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@1676 d7cf8633-e32d-0410-b094-e92efae38249

common.c
common.h
filematch.c [new file with mode: 0644]
makefile

index 6eb69277d1b671126b422b1f7e4bf63f7ba9b776..36d2920ee3edd6a624aa76a4a70ff30d5088d0cc 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1728,10 +1728,11 @@ then loads and adds pak1.pak pak2.pak ...
 */
 void COM_AddGameDirectory (char *dir)
 {
 */
 void COM_AddGameDirectory (char *dir)
 {
-       int                             i;
-       searchpath_t    *search;
-       pack_t                  *pak;
-       char                    pakfile[MAX_OSPATH];
+       //int i;
+       stringlist_t *list, *current;
+       searchpath_t *search;
+       pack_t *pak;
+       char pakfile[MAX_OSPATH];
 
        strcpy (com_gamedir, dir);
 
 
        strcpy (com_gamedir, dir);
 
@@ -1743,6 +1744,28 @@ void COM_AddGameDirectory (char *dir)
        search->next = com_searchpaths;
        com_searchpaths = search;
 
        search->next = com_searchpaths;
        com_searchpaths = search;
 
+       // add any paks in the directory
+       list = listdirectory(dir);
+       for (current = list;current;current = current->next)
+       {
+               if (matchpattern(current->text, "*.pak"))
+               {
+                       sprintf (pakfile, "%s/%s", dir, current->text);
+                       pak = COM_LoadPackFile (pakfile);
+                       if (pak)
+                       {
+                               search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
+                               search->pack = pak;
+                               search->next = com_searchpaths;
+                               com_searchpaths = search;
+                       }
+                       else
+                               Con_Printf("unable to load pak \"%s\"\n", pakfile);
+               }
+       }
+       freedirectory(list);
+
+       /*
 //
 // add any pak files in the format pak0.pak pak1.pak, ...
 //
 //
 // add any pak files in the format pak0.pak pak1.pak, ...
 //
@@ -1757,6 +1780,7 @@ void COM_AddGameDirectory (char *dir)
                search->next = com_searchpaths;
                com_searchpaths = search;
        }
                search->next = com_searchpaths;
                com_searchpaths = search;
        }
+       */
 
 //
 // add the contents of the parms.txt file to the end of the command line
 
 //
 // add the contents of the parms.txt file to the end of the command line
index 9cb9b9b2b87e6cad78b2dd9133a4c1f05019ddee..b4fcbab93009d5efc6d87f121a0a5f683bc86ff8 100644 (file)
--- a/common.h
+++ b/common.h
@@ -199,3 +199,13 @@ extern char *gamename;
 // LordHavoc: useful...
 extern void COM_ToLowerString(char *in, char *out);
 extern void COM_ToUpperString(char *in, char *out);
 // LordHavoc: useful...
 extern void COM_ToLowerString(char *in, char *out);
 extern void COM_ToUpperString(char *in, char *out);
+
+typedef struct stringlist_s
+{
+       struct stringlist_s *next;
+       char *text;
+} stringlist_t;
+
+int matchpattern(char *in, char *pattern);
+stringlist_t *listdirectory(char *path);
+void freedirectory(stringlist_t *list);
diff --git a/filematch.c b/filematch.c
new file mode 100644 (file)
index 0000000..996753c
--- /dev/null
@@ -0,0 +1,166 @@
+
+#include "quakedef.h"
+
+// LordHavoc: some portable directory listing code I wrote for lmp2pcx, now used in darkplaces to load id1/*.pak and such...
+
+int matchpattern(char *in, char *pattern)
+{
+       while (*pattern)
+       {
+               switch (*pattern)
+               {
+               case '?': // match any single character
+                       if (!*in)
+                               return 0; // no match
+                       in++;
+                       pattern++;
+                       break;
+               case '*': // match anything until following string
+                       if (!*in)
+                               return 1; // match
+                       while (*pattern == '*')
+                               pattern++;
+                       if (*pattern == '?')
+                       {
+                               // *? (weird)
+                               break;
+                       }
+                       else if (*pattern)
+                       {
+                               // *text (typical)
+                               while (*in && *in != *pattern)
+                                       in++;
+                       }
+                       else
+                       {
+                               // *null (* at end of pattern)
+                               return 1;
+                       }
+                       break;
+               default:
+                       if (*in != *pattern)
+                               return 0; // no match
+                       in++;
+                       pattern++;
+                       break;
+               }
+       }
+       if (*in)
+               return 0; // reached end of pattern but not end of input
+       return 1; // success
+}
+
+// a little chained strings system
+stringlist_t *stringlistappend(stringlist_t *current, char *text)
+{
+       stringlist_t *newitem;
+       newitem = Z_Malloc(strlen(text) + 1 + sizeof(stringlist_t));
+       newitem->next = NULL;
+       newitem->text = (char *)(newitem + 1);
+       strcpy(newitem->text, text);
+       if (current)
+               current->next = newitem;
+       return newitem;
+}
+
+void stringlistfree(stringlist_t *current)
+{
+       stringlist_t *next;
+       while (current)
+       {
+               next = current->next;
+               Z_Free(current);
+               current = next;
+       }
+}
+
+stringlist_t *stringlistsort(stringlist_t *start)
+{
+       int notdone;
+       stringlist_t *current, *previous, *temp2, *temp3, *temp4;
+       notdone = 1;
+       while (notdone)
+       {
+               current = start;
+               notdone = 0;
+               previous = NULL;
+               while (current && current->next)
+               {
+                       if (strcmp(current->text, current->next->text) > 0)
+                       {
+                               // current is greater than next
+                               notdone = 1;
+                               temp2 = current->next;
+                               temp3 = current;
+                               temp4 = current->next->next;
+                               if (previous)
+                                       previous->next = temp2;
+                               else
+                                       start = temp2;
+                               temp2->next = temp3;
+                               temp3->next = temp4;
+                               break;
+                       }
+                       previous = current;
+                       current = current->next;
+               }
+       }
+       return start;
+}
+
+// operating system specific code
+#ifdef WIN32
+#include <io.h>
+stringlist_t *listdirectory(char *path)
+{
+       char pattern[4096];
+       struct _finddata_t n_file;
+    long hFile;
+       stringlist_t *start, *current;
+       strcpy(pattern, path);
+       strcat(pattern, "\\*");
+       // ask for the directory listing handle
+       hFile = _findfirst(pattern, &n_file);
+       if(hFile != -1)
+       {
+               // start a new chain with the the first name
+               start = current = stringlistappend(NULL, n_file.name);
+               // iterate through the directory
+               while (_findnext(hFile, &n_file) == 0)
+                       current = stringlistappend(current, n_file.name);
+               _findclose(hFile);
+               // sort the list alphanumerically
+               return stringlistsort(start);
+       }
+       else
+               return NULL;
+}
+#else
+#include <dirent.h>
+stringlist_t *listdirectory(char *path)
+{
+       DIR *dir;
+       struct dirent *ent;
+       stringlist_t *start, *current;
+       dir = opendir(path);
+       if (!dir)
+               return NULL;
+       ent = readdir(dir);
+       if (!ent)
+       {
+               closedir(dir);
+               return NULL;
+       }
+       start = current = stringlistappend(NULL, ent->d_name);
+       while((ent = readdir(dir)))
+               current = stringlistappend(current, ent->d_name);
+       closedir(dir);
+       // sort the list alphanumerically
+       return stringlistsort(start);
+}
+#endif
+
+void freedirectory(stringlist_t *list)
+{
+       stringlistfree(list);
+}
\ No newline at end of file
index 371fca22f6eead80b873293898a4cbc039622343..bd1a764a8d990a9bff2f436f7fef0f2ada1b9537 100644 (file)
--- a/makefile
+++ b/makefile
@@ -9,7 +9,7 @@ SOUNDLIB=-lasound
 #SND=snd_oss.o
 #SOUNDLIB=
 
 #SND=snd_oss.o
 #SOUNDLIB=
 
-OBJECTS= builddate.o cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o r_sky.o gl_rmain.o gl_rsurf.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_explosion.o sbar.o snd_dma.o snd_mem.o snd_mix.o $(SND) sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o sys_linux.o transform.o view.o wad.o world.o zone.o vid_shared.o palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o r_modules.o r_explosion.o r_lerpanim.o protocol.o quakeio.o r_clip.o ui.o portals.o sys_shared.o cl_light.o gl_backend.o cl_particles.o cl_screen.o cgamevm.o cgame.o
+OBJECTS= builddate.o cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o r_sky.o gl_rmain.o gl_rsurf.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_explosion.o sbar.o snd_dma.o snd_mem.o snd_mix.o $(SND) sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o sys_linux.o transform.o view.o wad.o world.o zone.o vid_shared.o palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o r_modules.o r_explosion.o r_lerpanim.o protocol.o quakeio.o r_clip.o ui.o portals.o sys_shared.o cl_light.o gl_backend.o cl_particles.o cl_screen.o cgamevm.o cgame.o filematch.o
 
 #K6/athlon optimizations
 CPUOPTIMIZATIONS=-march=k6
 
 #K6/athlon optimizations
 CPUOPTIMIZATIONS=-march=k6