From: Dale Weiler Date: Sun, 14 Apr 2013 01:25:11 +0000 (+0000) Subject: Flatten more external functions X-Git-Tag: before-library~68 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=eb2a74f7e7968f99f6a9e01de838a900ebd6efe0;p=xonotic%2Fgmqcc.git Flatten more external functions --- diff --git a/fs.c b/fs.c index 6ff0e81..e39858a 100644 --- a/fs.c +++ b/fs.c @@ -298,7 +298,6 @@ int fs_file_getline(char **lineptr, size_t *n, FILE *stream) { #else # if !defined(__MINGW32__) # include /* mkdir */ -# include /* chdir */ int fs_dir_make(const char *path) { return mkdir(path, 0700); @@ -321,8 +320,4 @@ struct dirent *fs_dir_read(DIR *dir) { return readdir(dir); } -int fs_dir_change(const char *path) { - return chdir(path); -} - #endif /*! defined(_WIN32) && !defined(__MINGW32__) */ diff --git a/gmqcc.h b/gmqcc.h index 3539155..6d4d971 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -479,11 +479,10 @@ FILE *fs_file_open (const char *, const char *); int fs_file_getline(char **, size_t *, FILE *); /* directory handling */ +int fs_dir_make (const char *); DIR *fs_dir_open (const char *); int fs_dir_close (DIR *); struct dirent *fs_dir_read (DIR *); -int fs_dir_make (const char *); -int fs_dir_change (const char *); /*===================================================================*/ diff --git a/pak.c b/pak.c index fd80dea..a9ef112 100644 --- a/pak.c +++ b/pak.c @@ -259,9 +259,10 @@ bool pak_exists(pak_file_t *pak, const char *file, pak_directory_t **dir) { /* * Extraction abilities. These work as you expect them to. */ -bool pak_extract_one(pak_file_t *pak, const char *file) { - pak_directory_t *dir = NULL; - unsigned char *dat = NULL; +bool pak_extract_one(pak_file_t *pak, const char *file, const char *outdir) { + pak_directory_t *dir = NULL; + unsigned char *dat = NULL; + char *local = NULL; FILE *out; if (!pak_exists(pak, file, &dir)) { @@ -278,15 +279,20 @@ bool pak_extract_one(pak_file_t *pak, const char *file) { */ pak_tree_build(file); + /* TODO portable path seperators */ + util_asprintf(&local, "%s/%s", outdir, file); + /* * Now create the file, if this operation fails. Then abort * It shouldn't fail though. */ - if (!(out = fs_file_open(file, "wb"))) { + if (!(out = fs_file_open(local, "wb"))) { mem_d(dat); return false; } + /* free memory for directory string */ + mem_d(local); /* read */ fs_file_seek (pak->handle, dir->pos, SEEK_SET); @@ -310,11 +316,8 @@ bool pak_extract_all(pak_file_t *pak, const char *dir) { if (!fs_dir_make(dir)) return false; - if (fs_dir_change(dir)) - return false; - for (itr = 0; itr < vec_size(pak->directories); itr++) { - if (!pak_extract_one(pak, pak->directories[itr].name)) + if (!pak_extract_one(pak, pak->directories[itr].name, dir)) return false; } @@ -477,7 +480,6 @@ int main(int argc, char **argv) { bool extract = true; char *redirout = (char*)stdout; char *redirerr = (char*)stderr; - char *directory = NULL; char *file = NULL; char **files = NULL; pak_file_t *pak = NULL; @@ -498,8 +500,6 @@ int main(int argc, char **argv) { continue; if (parsecmd("redirerr", &argc, &argv, &redirerr, 1, false)) continue; - if (parsecmd("directory", &argc, &argv, &directory, 1, false)) - continue; if (parsecmd("file", &argc, &argv, &file, 1, false)) continue; @@ -542,7 +542,7 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - if (!pak_extract_all(pak, (directory) ? directory : "./")) { + if (!pak_extract_all(pak, "./")) { con_err("failed to extract PAK %s (files may be missing)\n", file); pak_close(pak); vec_free(files); @@ -562,13 +562,6 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - if (directory && !fs_dir_change(directory)) { - con_err("failed to change directory %s\n", directory); - pak_close(pak); - vec_free(files); - return EXIT_FAILURE; - } - for (iter = 0; iter < vec_size(files); iter++) { if (!(pak_insert_one(pak, files[iter]))) { con_err("failed inserting %s for PAK %s\n", files[iter], file);