mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 20:41:20 +00:00
A better command-line interface for pak. NOTE: there has been a change in
how pak gets the filename for the archive. Instead of requiring an -f argument, it now takes the first non-option argument as the filename. If this is a problem, it can be changed back. Also, a manual page.
This commit is contained in:
parent
74990f48ef
commit
4ce4869143
4 changed files with 295 additions and 57 deletions
|
@ -6,8 +6,10 @@ PAK_INCS=@PAK_INCS@
|
||||||
|
|
||||||
INCLUDES= -I$(top_srcdir)/include $(PAK_INCS)
|
INCLUDES= -I$(top_srcdir)/include $(PAK_INCS)
|
||||||
|
|
||||||
bin_PROGRAMS= pak
|
bin_PROGRAMS= pak
|
||||||
|
|
||||||
pak_SOURCES= pak.c pakfile.c
|
man_MANS= pak.1
|
||||||
pak_LDADD= $(PAK_LIBS)
|
|
||||||
|
pak_SOURCES= pak.c pakfile.c
|
||||||
|
pak_LDADD= $(PAK_LIBS)
|
||||||
pak_DEPENDENCIES= $(PAK_DEPS)
|
pak_DEPENDENCIES= $(PAK_DEPS)
|
||||||
|
|
79
tools/pak/pak.1
Normal file
79
tools/pak/pak.1
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
.\" hey, Emacs: -*- nroff -*-
|
||||||
|
.\" pak is free software; you can redistribute it and/or modify
|
||||||
|
.\" it under the terms of the GNU General Public License as published by
|
||||||
|
.\" the Free Software Foundation; either version 2 of the License, or
|
||||||
|
.\" (at your option) any later version.
|
||||||
|
.\"
|
||||||
|
.\" This program is distributed in the hope that it will be useful,
|
||||||
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
.\"
|
||||||
|
.\" See the GNU General Public License for more details.
|
||||||
|
.\"
|
||||||
|
.\" You should have received a copy of the GNU General Public License
|
||||||
|
.\" along with this program; see the file COPYING. If not, write to:
|
||||||
|
.\"
|
||||||
|
.\" Free Software Foundation, Inc.
|
||||||
|
.\" 59 Temple Place, Suite 330
|
||||||
|
.\" Boston, MA 02111-1307, USA
|
||||||
|
.\"
|
||||||
|
.\" Some roff macros, for reference:
|
||||||
|
.\" .nh disable hyphenation
|
||||||
|
.\" .hy enable hyphenation
|
||||||
|
.\" .ad l left justify
|
||||||
|
.\" .ad b justify to both left and right margins (default)
|
||||||
|
.\" .nf disable filling
|
||||||
|
.\" .fi enable filling
|
||||||
|
.\" .br insert line break
|
||||||
|
.\" .sp <n> insert n+1 empty lines
|
||||||
|
.\" for manpage-specific macros, see man(7)
|
||||||
|
.\"
|
||||||
|
.TH PAK 1 "03 May, 2002" QuakeForge "QuakeForge User's Manual"
|
||||||
|
.\" Please update the above date whenever this man page is modified.
|
||||||
|
.SH NAME
|
||||||
|
pak \- The QuakeForge Packfile Tool
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B pak
|
||||||
|
<\fIcommand\fP> [\fIoption\fP]... \fIARCHIVE\fP \fIFILE\fP...
|
||||||
|
.SH DESCRIPTION
|
||||||
|
\fBpak\fP is a utility for managing pack (*.pak) archives. The format used is
|
||||||
|
compatible with Quake and Quake II. Pak archives are a convenient way to store
|
||||||
|
groups of related files. Some engines allow pak archives to be compressed
|
||||||
|
internally.
|
||||||
|
.SH COMMANDS
|
||||||
|
\fBpak\fP accepts the following arguments as a command. Only one command may be
|
||||||
|
used at a time.
|
||||||
|
.TP
|
||||||
|
.B \-c, \-\-create
|
||||||
|
Create an archive. Overwrites any contents.
|
||||||
|
.TP
|
||||||
|
.B \-t, \-\-test
|
||||||
|
Test an archive for valid formatting.
|
||||||
|
.TP
|
||||||
|
.B \-x, \-\-extract
|
||||||
|
Extract an archive. Overwrites any files in the current directory with the same
|
||||||
|
names as those inside the archive.
|
||||||
|
.TP
|
||||||
|
.B \-h, \-\-help
|
||||||
|
Show summary of options.
|
||||||
|
.TP
|
||||||
|
.B \-V, \-\-version
|
||||||
|
Show the version of pak.
|
||||||
|
.SH OPTIONS
|
||||||
|
\fBpak\fP takes the following arguments as options.
|
||||||
|
.TP
|
||||||
|
.B \-p, \-\-pad
|
||||||
|
Can be useful when creating an archive. File space is padded to a 4\-byte
|
||||||
|
boundary, assisting in the speed of loading files from the archive.
|
||||||
|
.TP
|
||||||
|
.B \-q, \-\-quiet
|
||||||
|
Inhibit some of pak's normal output.
|
||||||
|
.TP
|
||||||
|
.B \-v, \-\-verbose
|
||||||
|
Display more output than usual.
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
.BR quakeforge (1)
|
||||||
|
.SH AUTHORS
|
||||||
|
\fBpak\fP was written by Bill Currie <taniwha@quakeforge.net> for QuakeForge.
|
||||||
|
Jeff Teunissen <deek@quakeforge.net> has also work on it, mostly in the
|
||||||
|
interface.
|
210
tools/pak/pak.c
210
tools/pak/pak.c
|
@ -1,102 +1,204 @@
|
||||||
|
/*
|
||||||
|
pak.c
|
||||||
|
|
||||||
|
Pakfile tool
|
||||||
|
|
||||||
|
Copyright (C) 1996-1997 Id Software, Inc.
|
||||||
|
Copyright (C) 2002 Bill Currie <bill@taniwha.org>
|
||||||
|
Copyright (C) 2002 Jeff Teunissen <deek@quakeforge.net>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public
|
||||||
|
License along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <QF/qtypes.h>
|
||||||
|
|
||||||
#include "pakfile.h"
|
#include "pakfile.h"
|
||||||
|
#include "pak.h"
|
||||||
|
|
||||||
|
const char *this_program;
|
||||||
|
options_t options;
|
||||||
|
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
|
{"create", no_argument, 0, 'c'},
|
||||||
|
{"test", no_argument, 0, 't'},
|
||||||
|
{"extract", no_argument, 0, 'x'},
|
||||||
|
{"help", no_argument, 0, 'h'},
|
||||||
|
{"version", no_argument, 0, 'V'},
|
||||||
|
{"pad", no_argument, 0, 'p'},
|
||||||
|
{"quiet", no_argument, 0, 'q'},
|
||||||
|
{"verbose", no_argument, 0, 'v'},
|
||||||
{NULL, 0, NULL, 0},
|
{NULL, 0, NULL, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
static void
|
||||||
mo_none,
|
usage (int status)
|
||||||
mo_test,
|
{
|
||||||
mo_create,
|
printf ("%s - QuakeForge Packfile tool\n", this_program);
|
||||||
mo_extract,
|
printf ("Usage: %s <command> [options] ARCHIVE FILE [FILE ...]\n",
|
||||||
} mode_t;
|
this_program);
|
||||||
|
|
||||||
|
printf ("Commands:\n"
|
||||||
|
" -c, --create Create archive\n"
|
||||||
|
" -t, --test Test archive\n"
|
||||||
|
" -x, --extract Extract archive contents\n"
|
||||||
|
" -h, --help Display this help and exit\n"
|
||||||
|
" -V, --version Output version information and exit\n\n");
|
||||||
|
|
||||||
|
printf ("Options:\n"
|
||||||
|
" -p, --pad Pad file space to a 32-bit boundary\n"
|
||||||
|
" -q, --quiet Inhibit usual output\n"
|
||||||
|
" -v, --verbose Display more output than usual\n");
|
||||||
|
exit (status);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
decode_args (int argc, char **argv)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
|
||||||
|
options.mode = mo_none;
|
||||||
|
options.pad = false;
|
||||||
|
options.packfile = NULL;
|
||||||
|
options.verbosity = 1;
|
||||||
|
|
||||||
|
while ((c = getopt_long (argc, argv, "c" // create archive
|
||||||
|
"t" // test archive
|
||||||
|
"x" // extract archive contents
|
||||||
|
"h" // show help
|
||||||
|
"V" // show version
|
||||||
|
// "f:" // filename
|
||||||
|
"p" // pad
|
||||||
|
"q" // quiet
|
||||||
|
"v" // verbose
|
||||||
|
, long_options, (int *) 0)) != EOF) {
|
||||||
|
switch (c) {
|
||||||
|
case 'h': // help
|
||||||
|
usage (0);
|
||||||
|
break;
|
||||||
|
case 'V': // version
|
||||||
|
printf ("pak version %s\n", VERSION);
|
||||||
|
exit (0);
|
||||||
|
break;
|
||||||
|
case 'c': // create
|
||||||
|
options.mode = mo_create;
|
||||||
|
break;
|
||||||
|
case 't': // test
|
||||||
|
options.mode = mo_test;
|
||||||
|
break;
|
||||||
|
case 'x': // extract
|
||||||
|
options.mode = mo_extract;
|
||||||
|
break;
|
||||||
|
case 'q': // lower verbosity
|
||||||
|
options.verbosity--;
|
||||||
|
break;
|
||||||
|
case 'p': // pad
|
||||||
|
options.pad = true;
|
||||||
|
break;
|
||||||
|
case 'v': // increase verbosity
|
||||||
|
options.verbosity++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argv[optind] && *(argv[optind]))
|
||||||
|
options.packfile = strdup (argv[optind++]);
|
||||||
|
|
||||||
|
return optind;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
pack_t *pack;
|
pack_t *pack;
|
||||||
mode_t mode = mo_none;
|
int i;
|
||||||
int i;
|
|
||||||
int c;
|
|
||||||
const char *pack_file = 0;
|
|
||||||
int verbose = 0;
|
|
||||||
int pad = 0;
|
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, "cf:ptvx", long_options, 0)) != -1) {
|
this_program = argv[0];
|
||||||
switch (c) {
|
|
||||||
case 'f':
|
|
||||||
pack_file = optarg;
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
mode = mo_test;
|
|
||||||
break;
|
|
||||||
case 'c':
|
|
||||||
mode = mo_create;
|
|
||||||
break;
|
|
||||||
case 'x':
|
|
||||||
mode = mo_extract;
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
verbose = 1;
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
pad = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pack_file) {
|
decode_args (argc, argv);
|
||||||
fprintf (stderr, "no pak file specified\n");
|
|
||||||
|
if (!options.packfile) {
|
||||||
|
fprintf (stderr, "%s: no archive file specified, giving up.\n",
|
||||||
|
this_program);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (mode) {
|
switch (options.mode) {
|
||||||
case mo_extract:
|
case mo_extract:
|
||||||
pack = pack_open (pack_file);
|
if (!(pack = pack_open (options.packfile))) {
|
||||||
if (!pack) {
|
fprintf (stderr, "%s: error opening %s: %s\n", this_program,
|
||||||
fprintf (stderr, "error opening %s\n", pack_file);
|
options.packfile,
|
||||||
|
strerror (errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
for (i = 0; i < pack->numfiles; i++) {
|
for (i = 0; i < pack->numfiles; i++) {
|
||||||
if (verbose)
|
if (options.verbosity > 0)
|
||||||
printf ("%s\n", pack->files[i].name);
|
printf ("%s\n", pack->files[i].name);
|
||||||
pack_extract (pack, &pack->files[i]);
|
pack_extract (pack, &pack->files[i]);
|
||||||
}
|
}
|
||||||
pack_close (pack);
|
pack_close (pack);
|
||||||
break;
|
break;
|
||||||
case mo_test:
|
case mo_test:
|
||||||
pack = pack_open (pack_file);
|
if (!(pack = pack_open (options.packfile))) {
|
||||||
if (!pack) {
|
fprintf (stderr, "%s: error opening %s: %s\n", this_program,
|
||||||
fprintf (stderr, "error opening %s\n", pack_file);
|
options.packfile,
|
||||||
|
strerror (errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
for (i = 0; i < pack->numfiles; i++) {
|
for (i = 0; i < pack->numfiles; i++) {
|
||||||
if (verbose)
|
if (options.verbosity > 1)
|
||||||
printf ("%6d %s\n", pack->files[i].filelen,
|
printf ("%6d ", pack->files[i].filelen);
|
||||||
pack->files[i].name);
|
if (options.verbosity > 0)
|
||||||
else
|
|
||||||
printf ("%s\n", pack->files[i].name);
|
printf ("%s\n", pack->files[i].name);
|
||||||
}
|
}
|
||||||
pack_close (pack);
|
pack_close (pack);
|
||||||
break;
|
break;
|
||||||
case mo_create:
|
case mo_create:
|
||||||
pack = pack_create (pack_file);
|
pack = pack_create (options.packfile);
|
||||||
if (!pack) {
|
if (!pack) {
|
||||||
fprintf (stderr, "error creating %s\n", pack_file);
|
fprintf (stderr, "%s: error creating %s: %s\n", this_program,
|
||||||
|
options.packfile,
|
||||||
|
strerror (errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
pack->pad = pad;
|
pack->pad = options.pad;
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
if (verbose)
|
if (options.verbosity > 0)
|
||||||
printf ("%s\n", argv[optind]);
|
printf ("%s\n", argv[optind]);
|
||||||
pack_add (pack, argv[optind++]);
|
pack_add (pack, argv[optind++]);
|
||||||
}
|
}
|
||||||
pack_close (pack);
|
pack_close (pack);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf (stderr, "no operation specified\n");
|
fprintf (stderr, "%s: No command given, bailing out.\n",
|
||||||
|
this_program);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
55
tools/pak/pak.h
Normal file
55
tools/pak/pak.h
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
pak.h
|
||||||
|
|
||||||
|
Pakfile tool (definitions)
|
||||||
|
|
||||||
|
Copyright (C) 1996-1997 Id Software, Inc.
|
||||||
|
Copyright (C) 2002 Bill Currie <bill@taniwha.org>
|
||||||
|
Copyright (C) 2002 Jeff Teunissen <deek@quakeforge.net>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License as
|
||||||
|
published by the Free Software Foundation; either version 2 of
|
||||||
|
the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public
|
||||||
|
License along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __pak_h
|
||||||
|
#define __pak_h
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <QF/qtypes.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
mo_none,
|
||||||
|
mo_test,
|
||||||
|
mo_create,
|
||||||
|
mo_extract,
|
||||||
|
} pakmode_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
pakmode_t mode; // see above
|
||||||
|
int verbosity; // 0=silent
|
||||||
|
qboolean compress; // for the future
|
||||||
|
qboolean pad; // pad area of files to 4-byte boundary
|
||||||
|
char *packfile; // pak file to read/write/test
|
||||||
|
} options_t;
|
||||||
|
|
||||||
|
#endif // __pak_h
|
Loading…
Reference in a new issue