+/*
+====================
+FS_AddFileToPack
+
+Add a file to the list of files contained into a package
+====================
+*/
+static packfile_t* FS_AddFileToPack (const char* name, pack_t* pack,
+ fs_offset_t offset, fs_offset_t packsize,
+ fs_offset_t realsize, int flags)
+{
+ int (*strcmp_funct) (const char* str1, const char* str2);
+ int left, right, middle;
+ packfile_t *pfile;
+
+ strcmp_funct = pack->ignorecase ? strcasecmp : strcmp;
+
+ // Look for the slot we should put that file into (binary search)
+ left = 0;
+ right = pack->numfiles - 1;
+ while (left <= right)
+ {
+ int diff;
+
+ middle = (left + right) / 2;
+ diff = strcmp_funct (pack->files[middle].name, name);
+
+ // If we found the file, there's a problem
+ if (!diff)
+ Con_Printf ("Package %s contains the file %s several times\n", pack->filename, name);
+
+ // If we're too far in the list
+ if (diff > 0)
+ right = middle - 1;
+ else
+ left = middle + 1;
+ }
+
+ // We have to move the right of the list by one slot to free the one we need
+ pfile = &pack->files[left];
+ memmove (pfile + 1, pfile, (pack->numfiles - left) * sizeof (*pfile));
+ pack->numfiles++;
+
+ strlcpy (pfile->name, name, sizeof (pfile->name));
+ pfile->offset = offset;
+ pfile->packsize = packsize;
+ pfile->realsize = realsize;
+ pfile->flags = flags;
+
+ return pfile;
+}
+
+