Reformat all C files.
I'll push a formatting guide at some point. There may still be outstanding changes, but please feel free to resolve those as you arrive a them. To the best of my knowledge, there is no changes to the actual code content, but the formatter does have the occasional bug. If you run into an issue, please fix it!
This commit is contained in:
+115
-111
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 dgn_main.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 dgn_main.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
|
||||
/* NetHack 3.6 dgn_main.c $Date: 2009/05/06 10:54:27 $ $Revision: 1.7 $ */
|
||||
/* SCCS Id: @(#)dgn_main.c 3.5 1994/09/23 */
|
||||
/* Copyright (c) 1989 by Jean-Christophe Collet */
|
||||
@@ -15,41 +15,41 @@
|
||||
|
||||
/* Macintosh-specific code */
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
/* MacOS X has Unix-style files and processes */
|
||||
# undef MAC
|
||||
/* MacOS X has Unix-style files and processes */
|
||||
#undef MAC
|
||||
#endif
|
||||
#ifdef MAC
|
||||
# if defined(__SC__) || defined(__MRC__)
|
||||
# define MPWTOOL
|
||||
#if defined(__SC__) || defined(__MRC__)
|
||||
#define MPWTOOL
|
||||
#include <CursorCtl.h>
|
||||
# else
|
||||
/* put dungeon file in library location */
|
||||
# define PREFIX ":lib:"
|
||||
# endif
|
||||
#else
|
||||
/* put dungeon file in library location */
|
||||
#define PREFIX ":lib:"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MPWTOOL
|
||||
# define SpinCursor(x)
|
||||
#define SpinCursor(x)
|
||||
#endif
|
||||
|
||||
#define MAX_ERRORS 25
|
||||
#define MAX_ERRORS 25
|
||||
|
||||
extern int NDECL (yyparse);
|
||||
extern int NDECL(yyparse);
|
||||
extern int nh_line_number;
|
||||
const char *fname = "(stdin)";
|
||||
int fatal_error = 0;
|
||||
|
||||
int FDECL (main, (int,char **));
|
||||
void FDECL (yyerror, (const char *));
|
||||
void FDECL (yywarning, (const char *));
|
||||
int NDECL (yywrap);
|
||||
void FDECL (init_yyin, (FILE *));
|
||||
void FDECL (init_yyout, (FILE *));
|
||||
int FDECL(main, (int, char **));
|
||||
void FDECL(yyerror, (const char *));
|
||||
void FDECL(yywarning, (const char *));
|
||||
int NDECL(yywrap);
|
||||
void FDECL(init_yyin, (FILE *));
|
||||
void FDECL(init_yyout, (FILE *));
|
||||
|
||||
#ifdef AZTEC_36
|
||||
FILE *FDECL (freopen, (char *,char *,FILE *));
|
||||
FILE *FDECL(freopen, (char *, char *, FILE *));
|
||||
#endif
|
||||
#define Fprintf (void)fprintf
|
||||
#define Fprintf (void) fprintf
|
||||
|
||||
#if defined(__BORLANDC__) && !defined(_WIN32)
|
||||
extern unsigned _stklen = STKSIZ;
|
||||
@@ -59,99 +59,98 @@ main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
char infile[64], outfile[64], basename[64];
|
||||
FILE *fin, *fout;
|
||||
int i, len;
|
||||
boolean errors_encountered = FALSE;
|
||||
char infile[64], outfile[64], basename[64];
|
||||
FILE *fin, *fout;
|
||||
int i, len;
|
||||
boolean errors_encountered = FALSE;
|
||||
#if defined(MAC) && (defined(THINK_C) || defined(__MWERKS__))
|
||||
char *mark;
|
||||
static char *mac_argv[] = { "dgn_comp", /* dummy argv[0] */
|
||||
":dat:dungeon.pdf"
|
||||
};
|
||||
char *mark;
|
||||
static char *mac_argv[] = { "dgn_comp", /* dummy argv[0] */
|
||||
":dat:dungeon.pdf" };
|
||||
|
||||
argc = SIZE(mac_argv);
|
||||
argv = mac_argv;
|
||||
argc = SIZE(mac_argv);
|
||||
argv = mac_argv;
|
||||
#endif
|
||||
|
||||
Strcpy(infile, "(stdin)");
|
||||
fin = stdin;
|
||||
Strcpy(outfile, "(stdout)");
|
||||
fout = stdout;
|
||||
Strcpy(infile, "(stdin)");
|
||||
fin = stdin;
|
||||
Strcpy(outfile, "(stdout)");
|
||||
fout = stdout;
|
||||
|
||||
if (argc == 1) { /* Read standard input */
|
||||
init_yyin(fin);
|
||||
init_yyout(fout);
|
||||
(void) yyparse();
|
||||
if (fatal_error > 0)
|
||||
errors_encountered = TRUE;
|
||||
} else { /* Otherwise every argument is a filename */
|
||||
for(i=1; i<argc; i++) {
|
||||
fname = strcpy(infile, argv[i]);
|
||||
/* the input file had better be a .pdf file */
|
||||
len = strlen(fname) - 4; /* length excluding suffix */
|
||||
if (len < 0 || strncmp(".pdf", fname + len, 4)) {
|
||||
Fprintf(stderr,
|
||||
"Error - file name \"%s\" in wrong format.\n",
|
||||
fname);
|
||||
errors_encountered = TRUE;
|
||||
continue;
|
||||
}
|
||||
if (argc == 1) { /* Read standard input */
|
||||
init_yyin(fin);
|
||||
init_yyout(fout);
|
||||
(void) yyparse();
|
||||
if (fatal_error > 0)
|
||||
errors_encountered = TRUE;
|
||||
} else { /* Otherwise every argument is a filename */
|
||||
for (i = 1; i < argc; i++) {
|
||||
fname = strcpy(infile, argv[i]);
|
||||
/* the input file had better be a .pdf file */
|
||||
len = strlen(fname) - 4; /* length excluding suffix */
|
||||
if (len < 0 || strncmp(".pdf", fname + len, 4)) {
|
||||
Fprintf(stderr, "Error - file name \"%s\" in wrong format.\n",
|
||||
fname);
|
||||
errors_encountered = TRUE;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* build output file name */
|
||||
/* build output file name */
|
||||
#if defined(MAC) && (defined(THINK_C) || defined(__MWERKS__))
|
||||
/* extract basename from path to infile */
|
||||
mark = strrchr(infile, ':');
|
||||
strcpy(basename, mark ? mark+1 : infile);
|
||||
mark = strchr(basename, '.');
|
||||
if (mark) *mark = '\0';
|
||||
/* extract basename from path to infile */
|
||||
mark = strrchr(infile, ':');
|
||||
strcpy(basename, mark ? mark + 1 : infile);
|
||||
mark = strchr(basename, '.');
|
||||
if (mark)
|
||||
*mark = '\0';
|
||||
#else
|
||||
/* Use the whole name - strip off the last 3 or 4 chars. */
|
||||
/* Use the whole name - strip off the last 3 or 4 chars. */
|
||||
|
||||
#ifdef VMS /* avoid possible interaction with logical name */
|
||||
len++; /* retain "." as trailing punctuation */
|
||||
#ifdef VMS /* avoid possible interaction with logical name */
|
||||
len++; /* retain "." as trailing punctuation */
|
||||
#endif
|
||||
(void) strncpy(basename, infile, len);
|
||||
basename[len] = '\0';
|
||||
(void) strncpy(basename, infile, len);
|
||||
basename[len] = '\0';
|
||||
#endif
|
||||
|
||||
outfile[0] = '\0';
|
||||
outfile[0] = '\0';
|
||||
#ifdef PREFIX
|
||||
(void) strcat(outfile, PREFIX);
|
||||
(void) strcat(outfile, PREFIX);
|
||||
#endif
|
||||
(void) strcat(outfile, basename);
|
||||
(void) strcat(outfile, basename);
|
||||
|
||||
fin = freopen(infile, "r", stdin);
|
||||
if (!fin) {
|
||||
Fprintf(stderr, "Can't open %s for input.\n", infile);
|
||||
perror(infile);
|
||||
errors_encountered = TRUE;
|
||||
continue;
|
||||
}
|
||||
fout = freopen(outfile, WRBMODE, stdout);
|
||||
if (!fout) {
|
||||
Fprintf(stderr, "Can't open %s for output.\n", outfile);
|
||||
perror(outfile);
|
||||
errors_encountered = TRUE;
|
||||
continue;
|
||||
}
|
||||
init_yyin(fin);
|
||||
init_yyout(fout);
|
||||
(void) yyparse();
|
||||
nh_line_number = 1;
|
||||
if (fatal_error > 0) {
|
||||
errors_encountered = TRUE;
|
||||
fatal_error = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fout && fclose(fout) < 0) {
|
||||
Fprintf(stderr, "Can't finish output file.");
|
||||
perror(outfile);
|
||||
errors_encountered = TRUE;
|
||||
}
|
||||
exit(errors_encountered ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
fin = freopen(infile, "r", stdin);
|
||||
if (!fin) {
|
||||
Fprintf(stderr, "Can't open %s for input.\n", infile);
|
||||
perror(infile);
|
||||
errors_encountered = TRUE;
|
||||
continue;
|
||||
}
|
||||
fout = freopen(outfile, WRBMODE, stdout);
|
||||
if (!fout) {
|
||||
Fprintf(stderr, "Can't open %s for output.\n", outfile);
|
||||
perror(outfile);
|
||||
errors_encountered = TRUE;
|
||||
continue;
|
||||
}
|
||||
init_yyin(fin);
|
||||
init_yyout(fout);
|
||||
(void) yyparse();
|
||||
nh_line_number = 1;
|
||||
if (fatal_error > 0) {
|
||||
errors_encountered = TRUE;
|
||||
fatal_error = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fout && fclose(fout) < 0) {
|
||||
Fprintf(stderr, "Can't finish output file.");
|
||||
perror(outfile);
|
||||
errors_encountered = TRUE;
|
||||
}
|
||||
exit(errors_encountered ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -160,32 +159,37 @@ char **argv;
|
||||
* MAX_ERRORS wouldn't be reasonable.
|
||||
*/
|
||||
|
||||
void yyerror(s)
|
||||
void
|
||||
yyerror(s)
|
||||
const char *s;
|
||||
{
|
||||
(void) fprintf(stderr,"%s : line %d : %s\n",fname,nh_line_number, s);
|
||||
if (++fatal_error > MAX_ERRORS) {
|
||||
(void) fprintf(stderr,"Too many errors, good bye!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
(void) fprintf(stderr, "%s : line %d : %s\n", fname, nh_line_number, s);
|
||||
if (++fatal_error > MAX_ERRORS) {
|
||||
(void) fprintf(stderr, "Too many errors, good bye!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Just display a warning (that is : a non fatal error)
|
||||
*/
|
||||
|
||||
void yywarning(s)
|
||||
void
|
||||
yywarning(s)
|
||||
const char *s;
|
||||
{
|
||||
(void) fprintf(stderr,"%s : line %d : WARNING : %s\n",fname,nh_line_number,s);
|
||||
(void) fprintf(stderr, "%s : line %d : WARNING : %s\n", fname,
|
||||
nh_line_number, s);
|
||||
}
|
||||
|
||||
int yywrap()
|
||||
int
|
||||
yywrap()
|
||||
{
|
||||
SpinCursor(3); /* Don't know if this is a good place to put it ?
|
||||
Is it called for our grammar ? Often enough ?
|
||||
Too often ? -- h+ */
|
||||
return 1;
|
||||
SpinCursor(3); /* Don't know if this is a good place to put it ?
|
||||
Is it called for our grammar ?
|
||||
Often enough ?
|
||||
Too often ? -- h+ */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*dgn_main.c*/
|
||||
|
||||
+346
-340
@@ -1,9 +1,10 @@
|
||||
/* NetHack 3.6 dlb_main.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 dlb_main.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.9 $ */
|
||||
/* NetHack 3.6 dlb_main.c $Date: 2012/01/16 03:56:08 $ $Revision: 1.6 $ */
|
||||
/* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
/* data librarian; only useful if you are making the library version, DLBLIB */
|
||||
/* data librarian; only useful if you are making the library version, DLBLIB
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "dlb.h"
|
||||
@@ -14,26 +15,27 @@
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
static void FDECL(grow_ld, (libdir **,int *,int));
|
||||
static void FDECL(grow_ld, (libdir **, int *, int));
|
||||
static void FDECL(xexit, (int));
|
||||
|
||||
#ifdef DLB
|
||||
#ifdef DLBLIB
|
||||
|
||||
#define DLB_DIRECTORY "Directory" /* name of lib directory */
|
||||
#define LIBLISTFILE "dlb.lst" /* default list file */
|
||||
#define DLB_DIRECTORY "Directory" /* name of lib directory */
|
||||
#define LIBLISTFILE "dlb.lst" /* default list file */
|
||||
|
||||
/* library functions (from dlb.c) */
|
||||
extern boolean FDECL(open_library,(const char *,library *));
|
||||
extern void FDECL(close_library,(library *));
|
||||
extern boolean FDECL(open_library, (const char *, library *));
|
||||
extern void FDECL(close_library, (library *));
|
||||
|
||||
char *FDECL(eos, (char *)); /* also used by dlb.c */
|
||||
FILE *FDECL(fopen_datafile, (const char *,const char *));
|
||||
char *FDECL(eos, (char *)); /* also used by dlb.c */
|
||||
FILE *FDECL(fopen_datafile, (const char *, const char *));
|
||||
|
||||
static void FDECL(Write, (int,char *,long));
|
||||
static void FDECL(Write, (int, char *, long));
|
||||
static void NDECL(usage);
|
||||
static void NDECL(verbose_help);
|
||||
static void FDECL(write_dlb_directory, (int,int,libdir *,long,long,long));
|
||||
static void FDECL(write_dlb_directory,
|
||||
(int, int, libdir *, long, long, long));
|
||||
|
||||
static char default_progname[] = "dlb";
|
||||
static char *progname = default_progname;
|
||||
@@ -43,23 +45,22 @@ static const char *library_file = DLBFILE;
|
||||
static const char *list_file = LIBLISTFILE;
|
||||
|
||||
#ifdef AMIGA
|
||||
static char origdir[255]="";
|
||||
static char origdir[255] = "";
|
||||
#endif
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#define DLB_FILES_ALLOC 200 /* initial # of files we'll handle; can grow */
|
||||
#define DLB_VERS 1 /* version of dlb file we will write */
|
||||
#define DLB_FILES_ALLOC 200 /* initial # of files we'll handle; can grow */
|
||||
#define DLB_VERS 1 /* version of dlb file we will write */
|
||||
|
||||
/*
|
||||
* How the file is encoded within the library. Don't use a space
|
||||
* because (at least) the SunOS 4.1.3 C library will eat the white
|
||||
* space instead of preserving it like the man page says it should.
|
||||
*/
|
||||
#define ENC_NORMAL 'n' /* normal: not compressed in any way */
|
||||
|
||||
#define ENC_NORMAL 'n' /* normal: not compressed in any way */
|
||||
|
||||
/*
|
||||
* If you know tar, you have a small clue how to use this (note: - does
|
||||
@@ -90,63 +91,56 @@ static void
|
||||
verbose_help()
|
||||
{
|
||||
static const char *long_help[] = {
|
||||
"",
|
||||
"dlb COMMANDoptions args... files...",
|
||||
" commands:",
|
||||
" dlb ? print this text",
|
||||
" dlb h ditto",
|
||||
" dlb x extract all files",
|
||||
" dlb c create the archive",
|
||||
" dlb t list table of contents",
|
||||
" options:",
|
||||
" v verbose operation",
|
||||
" f file specify archive file name",
|
||||
" I file specify file for list of file names",
|
||||
" C dir change directory before processing any files",
|
||||
"",
|
||||
(char *)0
|
||||
"", "dlb COMMANDoptions args... files...", " commands:",
|
||||
" dlb ? print this text", " dlb h ditto",
|
||||
" dlb x extract all files", " dlb c create the archive",
|
||||
" dlb t list table of contents", " options:",
|
||||
" v verbose operation",
|
||||
" f file specify archive file name",
|
||||
" I file specify file for list of file names",
|
||||
" C dir change directory before processing any files", "",
|
||||
(char *) 0
|
||||
};
|
||||
const char **str;
|
||||
|
||||
for (str = long_help; *str; str++)
|
||||
(void) printf("%s\n", *str);
|
||||
(void) printf("%s\n", *str);
|
||||
usage();
|
||||
}
|
||||
|
||||
static void
|
||||
Write(out,buf,len)
|
||||
int out;
|
||||
char *buf;
|
||||
long len;
|
||||
Write(out, buf, len)
|
||||
int out;
|
||||
char *buf;
|
||||
long len;
|
||||
{
|
||||
#if defined(MSDOS) && !defined(__DJGPP__)
|
||||
unsigned short slen;
|
||||
|
||||
if (len > 65534) {
|
||||
printf("%d Length specified for write() too large for 16 bit env.",
|
||||
len);
|
||||
xexit(EXIT_FAILURE);
|
||||
printf("%d Length specified for write() too large for 16 bit env.",
|
||||
len);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
slen = (unsigned short)len;
|
||||
if (write(out,buf,slen) != slen) {
|
||||
slen = (unsigned short) len;
|
||||
if (write(out, buf, slen) != slen) {
|
||||
#else
|
||||
if (write(out,buf,len) != len) {
|
||||
if (write(out, buf, len) != len) {
|
||||
#endif
|
||||
printf("Write Error in '%s'\n",library_file);
|
||||
xexit(EXIT_FAILURE);
|
||||
printf("Write Error in '%s'\n", library_file);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
eos(s)
|
||||
char *s;
|
||||
char *s;
|
||||
{
|
||||
while (*s) s++;
|
||||
while (*s)
|
||||
s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/* open_library(dlb.c) needs this (which normally comes from src/files.c) */
|
||||
FILE *
|
||||
fopen_datafile(filename, mode)
|
||||
@@ -155,311 +149,322 @@ const char *filename, *mode;
|
||||
return fopen(filename, mode);
|
||||
}
|
||||
|
||||
#endif /* DLBLIB */
|
||||
#endif /* DLB */
|
||||
#endif /* DLBLIB */
|
||||
#endif /* DLB */
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
#ifdef DLB
|
||||
#ifdef DLBLIB
|
||||
int i, r;
|
||||
int ap=2; /* argument pointer */
|
||||
int cp; /* command pointer */
|
||||
int iseen=0, fseen=0, verbose=0; /* flags */
|
||||
char action=' ';
|
||||
int ap = 2; /* argument pointer */
|
||||
int cp; /* command pointer */
|
||||
int iseen = 0, fseen = 0, verbose = 0; /* flags */
|
||||
char action = ' ';
|
||||
library lib;
|
||||
|
||||
if (argc > 0 && argv[0] && *argv[0]) progname = argv[0];
|
||||
if (argc > 0 && argv[0] && *argv[0])
|
||||
progname = argv[0];
|
||||
#ifdef VMS
|
||||
progname = vms_basename(progname);
|
||||
#endif
|
||||
|
||||
if (argc<2) {
|
||||
usage();
|
||||
/* doesn't return */
|
||||
if (argc < 2) {
|
||||
usage();
|
||||
/* doesn't return */
|
||||
}
|
||||
|
||||
for(cp=0;argv[1][cp];cp++){
|
||||
switch(argv[1][cp]){
|
||||
default:
|
||||
usage(); /* doesn't return */
|
||||
case '-': /* silently ignore */
|
||||
break;
|
||||
case '?':
|
||||
case 'h':
|
||||
verbose_help();
|
||||
break;
|
||||
case 'I':
|
||||
if (ap == argc) usage();
|
||||
list_file=argv[ap++];
|
||||
if(iseen)
|
||||
printf("Warning: multiple I options. Previous ignored.\n");
|
||||
iseen=1;
|
||||
break;
|
||||
case 'f':
|
||||
if (ap == argc) usage();
|
||||
library_file=argv[ap++];
|
||||
if(fseen)
|
||||
printf("Warning: multiple f options. Previous ignored.\n");
|
||||
fseen=1;
|
||||
break;
|
||||
case 'C':
|
||||
if (ap == argc) usage();
|
||||
for (cp = 0; argv[1][cp]; cp++) {
|
||||
switch (argv[1][cp]) {
|
||||
default:
|
||||
usage(); /* doesn't return */
|
||||
case '-': /* silently ignore */
|
||||
break;
|
||||
case '?':
|
||||
case 'h':
|
||||
verbose_help();
|
||||
break;
|
||||
case 'I':
|
||||
if (ap == argc)
|
||||
usage();
|
||||
list_file = argv[ap++];
|
||||
if (iseen)
|
||||
printf("Warning: multiple I options. Previous ignored.\n");
|
||||
iseen = 1;
|
||||
break;
|
||||
case 'f':
|
||||
if (ap == argc)
|
||||
usage();
|
||||
library_file = argv[ap++];
|
||||
if (fseen)
|
||||
printf("Warning: multiple f options. Previous ignored.\n");
|
||||
fseen = 1;
|
||||
break;
|
||||
case 'C':
|
||||
if (ap == argc)
|
||||
usage();
|
||||
#ifdef AMIGA
|
||||
if(!getcwd(origdir,sizeof(origdir))){
|
||||
printf("Can't get current directory.\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
if (!getcwd(origdir, sizeof(origdir))) {
|
||||
printf("Can't get current directory.\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
if(chdir(argv[ap++])){
|
||||
printf("Can't chdir to %s\n",argv[--ap]);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
verbose=1;
|
||||
break;
|
||||
case 't':
|
||||
case 'c':
|
||||
case 'x':
|
||||
if(action != ' '){
|
||||
printf("Only one of t,x,c may be specified.\n");
|
||||
usage();
|
||||
}
|
||||
action=argv[1][cp];
|
||||
break;
|
||||
}
|
||||
if (chdir(argv[ap++])) {
|
||||
printf("Can't chdir to %s\n", argv[--ap]);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
case 't':
|
||||
case 'c':
|
||||
case 'x':
|
||||
if (action != ' ') {
|
||||
printf("Only one of t,x,c may be specified.\n");
|
||||
usage();
|
||||
}
|
||||
action = argv[1][cp];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(argv[ap] && iseen){
|
||||
printf("Too many arguments.\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
if (argv[ap] && iseen) {
|
||||
printf("Too many arguments.\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
switch(action){
|
||||
switch (action) {
|
||||
default:
|
||||
printf("Internal error - action.\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
break;
|
||||
case 't': /* list archive */
|
||||
if (!open_library(library_file, &lib)) {
|
||||
printf("Can't open dlb file\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
printf("Internal error - action.\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
break;
|
||||
case 't': /* list archive */
|
||||
if (!open_library(library_file, &lib)) {
|
||||
printf("Can't open dlb file\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (i = 0; i < lib.nentries; i++) {
|
||||
if (verbose)
|
||||
printf("%-14s %6ld %6ld\n",
|
||||
lib.dir[i].fname, lib.dir[i].foffset, lib.dir[i].fsize);
|
||||
else
|
||||
printf("%s\n", lib.dir[i].fname);
|
||||
}
|
||||
for (i = 0; i < lib.nentries; i++) {
|
||||
if (verbose)
|
||||
printf("%-14s %6ld %6ld\n", lib.dir[i].fname,
|
||||
lib.dir[i].foffset, lib.dir[i].fsize);
|
||||
else
|
||||
printf("%s\n", lib.dir[i].fname);
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
printf("Revision:%ld File count:%ld String size:%ld\n",
|
||||
lib.rev, lib.nentries, lib.strsize);
|
||||
if (verbose)
|
||||
printf("Revision:%ld File count:%ld String size:%ld\n", lib.rev,
|
||||
lib.nentries, lib.strsize);
|
||||
|
||||
close_library(&lib);
|
||||
xexit(EXIT_SUCCESS);
|
||||
close_library(&lib);
|
||||
xexit(EXIT_SUCCESS);
|
||||
|
||||
case 'x': { /* extract archive contents */
|
||||
int f, n;
|
||||
long remainder, total_read;
|
||||
char buf[BUFSIZ];
|
||||
case 'x': { /* extract archive contents */
|
||||
int f, n;
|
||||
long remainder, total_read;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
if (!open_library(library_file, &lib)) {
|
||||
printf("Can't open dlb file\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
if (!open_library(library_file, &lib)) {
|
||||
printf("Can't open dlb file\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (i = 0; i < lib.nentries; i++) {
|
||||
if (argv[ap]) {
|
||||
/* if files are listed, see if current is wanted */
|
||||
int c;
|
||||
for (c = ap; c < argc; c++)
|
||||
if (!FILENAME_CMP(lib.dir[i].fname, argv[c])) break;
|
||||
if (c == argc) continue; /* skip */
|
||||
} else if (!FILENAME_CMP(lib.dir[i].fname, DLB_DIRECTORY)) {
|
||||
/*
|
||||
* Don't extract the directory unless the user
|
||||
* specifically asks for it.
|
||||
*
|
||||
* Perhaps we should never extract the directory???
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
fseek(lib.fdata, lib.dir[i].foffset, SEEK_SET);
|
||||
for (i = 0; i < lib.nentries; i++) {
|
||||
if (argv[ap]) {
|
||||
/* if files are listed, see if current is wanted */
|
||||
int c;
|
||||
for (c = ap; c < argc; c++)
|
||||
if (!FILENAME_CMP(lib.dir[i].fname, argv[c]))
|
||||
break;
|
||||
if (c == argc)
|
||||
continue; /* skip */
|
||||
} else if (!FILENAME_CMP(lib.dir[i].fname, DLB_DIRECTORY)) {
|
||||
/*
|
||||
* Don't extract the directory unless the user
|
||||
* specifically asks for it.
|
||||
*
|
||||
* Perhaps we should never extract the directory???
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
fseek(lib.fdata, lib.dir[i].foffset, SEEK_SET);
|
||||
|
||||
f = open(lib.dir[i].fname, O_WRONLY|O_TRUNC|O_BINARY|O_CREAT, 0640);
|
||||
if (f < 0) {
|
||||
printf("Can't create '%s'\n", lib.dir[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
f = open(lib.dir[i].fname,
|
||||
O_WRONLY | O_TRUNC | O_BINARY | O_CREAT, 0640);
|
||||
if (f < 0) {
|
||||
printf("Can't create '%s'\n", lib.dir[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* read chunks from library and write them out */
|
||||
total_read = 0;
|
||||
do {
|
||||
remainder = lib.dir[i].fsize - total_read;
|
||||
if (remainder > (long) sizeof(buf))
|
||||
r = (int) sizeof(buf);
|
||||
else
|
||||
r = remainder;
|
||||
/* read chunks from library and write them out */
|
||||
total_read = 0;
|
||||
do {
|
||||
remainder = lib.dir[i].fsize - total_read;
|
||||
if (remainder > (long) sizeof(buf))
|
||||
r = (int) sizeof(buf);
|
||||
else
|
||||
r = remainder;
|
||||
|
||||
n = fread(buf, 1, r, lib.fdata);
|
||||
if (n != r) {
|
||||
printf("Read Error in '%s'\n", lib.dir[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
if (write(f, buf, n) != n) {
|
||||
printf("Write Error in '%s'\n", lib.dir[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
n = fread(buf, 1, r, lib.fdata);
|
||||
if (n != r) {
|
||||
printf("Read Error in '%s'\n", lib.dir[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
if (write(f, buf, n) != n) {
|
||||
printf("Write Error in '%s'\n", lib.dir[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
total_read += n;
|
||||
} while (total_read != lib.dir[i].fsize);
|
||||
total_read += n;
|
||||
} while (total_read != lib.dir[i].fsize);
|
||||
|
||||
(void) close(f);
|
||||
(void) close(f);
|
||||
|
||||
if (verbose) printf("x %s\n", lib.dir[i].fname);
|
||||
}
|
||||
if (verbose)
|
||||
printf("x %s\n", lib.dir[i].fname);
|
||||
}
|
||||
|
||||
close_library(&lib);
|
||||
xexit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
case 'c': /* create archive */
|
||||
{
|
||||
libdir *ld = 0;
|
||||
int ldlimit = 0;
|
||||
char buf[BUFSIZ];
|
||||
int fd, out, nfiles = 0;
|
||||
long dir_size, slen, flen, fsiz;
|
||||
boolean rewrite_directory = FALSE;
|
||||
|
||||
/*
|
||||
* Get names from either/both an argv list and a file
|
||||
* list. This does not do any duplicate checking
|
||||
*/
|
||||
|
||||
grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC);
|
||||
|
||||
/* get file name in argv list */
|
||||
if (argv[ap]) {
|
||||
for ( ; ap < argc; ap++, nfiles++) {
|
||||
if (nfiles == ldlimit)
|
||||
grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5);
|
||||
ld[nfiles].fname = (char *) alloc(strlen(argv[ap]) + 1);
|
||||
Strcpy(ld[nfiles].fname, argv[ap]);
|
||||
}
|
||||
}
|
||||
|
||||
if (iseen) {
|
||||
/* want to do a list file */
|
||||
FILE *list = fopen(list_file, "r");
|
||||
if (!list) {
|
||||
printf("Can't open %s\n",list_file);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* get file names, one per line */
|
||||
for ( ; fgets(buf, sizeof(buf), list); nfiles++) {
|
||||
if (nfiles == ldlimit)
|
||||
grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5);
|
||||
*(eos(buf)-1) = '\0'; /* strip newline */
|
||||
ld[nfiles].fname = (char *) alloc(strlen(buf) + 1);
|
||||
Strcpy(ld[nfiles].fname, buf);
|
||||
}
|
||||
fclose(list);
|
||||
}
|
||||
|
||||
if (nfiles == 0) {
|
||||
printf("No files to archive\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get file sizes and name string length. Don't include
|
||||
* the directory information yet.
|
||||
*/
|
||||
for (i = 0, slen = 0, flen = 0; i < nfiles; i++) {
|
||||
fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0);
|
||||
if (fd < 0) {
|
||||
printf("Can't open %s\n", ld[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
ld[i].fsize = lseek(fd, 0, SEEK_END);
|
||||
ld[i].foffset = flen;
|
||||
|
||||
slen += strlen(ld[i].fname); /* don't add null (yet) */
|
||||
flen += ld[i].fsize;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* open output file */
|
||||
out = open(library_file, O_RDWR|O_TRUNC|O_BINARY|O_CREAT, FCMASK);
|
||||
if (out < 0) {
|
||||
printf("Can't open %s for output\n", library_file);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* caculate directory size */
|
||||
dir_size = 40 /* header line (see below) */
|
||||
+ ((nfiles+1)*11) /* handling+file offset+SP+newline */
|
||||
+ slen+strlen(DLB_DIRECTORY); /* file names */
|
||||
|
||||
/* write directory */
|
||||
write_dlb_directory(out, nfiles, ld, slen, dir_size, flen);
|
||||
|
||||
flen = 0L;
|
||||
/* write each file */
|
||||
for (i = 0; i < nfiles; i++) {
|
||||
fd = open(ld[i].fname, O_RDONLY|O_BINARY, 0);
|
||||
if (fd < 0) {
|
||||
printf("Can't open input file '%s'\n", ld[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
if (verbose) printf("%s\n",ld[i].fname);
|
||||
|
||||
fsiz = 0L;
|
||||
while ((r = read(fd, buf, sizeof buf)) != 0) {
|
||||
if (r == -1) {
|
||||
printf("Read Error in '%s'\n", ld[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
if (write(out, buf, r) != r) {
|
||||
printf("Write Error in '%s'\n", ld[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
fsiz += r;
|
||||
}
|
||||
(void) close(fd);
|
||||
if (fsiz != ld[i].fsize) rewrite_directory = TRUE;
|
||||
/* in case directory rewrite is needed */
|
||||
ld[i].fsize = fsiz;
|
||||
ld[i].foffset = flen;
|
||||
flen += fsiz;
|
||||
}
|
||||
|
||||
if (rewrite_directory) {
|
||||
if (verbose) printf("(rewriting dlb directory info)\n");
|
||||
(void) lseek(out, 0, SEEK_SET); /* rewind */
|
||||
write_dlb_directory(out, nfiles, ld, slen, dir_size, flen);
|
||||
}
|
||||
|
||||
for (i = 0; i < nfiles; i++)
|
||||
free((genericptr_t) ld[i].fname), ld[i].fname = 0;
|
||||
free((genericptr_t)ld), ldlimit = 0;
|
||||
|
||||
(void) close(out);
|
||||
xexit(EXIT_SUCCESS);
|
||||
}
|
||||
close_library(&lib);
|
||||
xexit(EXIT_SUCCESS);
|
||||
}
|
||||
#endif /* DLBLIB */
|
||||
#endif /* DLB */
|
||||
|
||||
case 'c': /* create archive */
|
||||
{
|
||||
libdir *ld = 0;
|
||||
int ldlimit = 0;
|
||||
char buf[BUFSIZ];
|
||||
int fd, out, nfiles = 0;
|
||||
long dir_size, slen, flen, fsiz;
|
||||
boolean rewrite_directory = FALSE;
|
||||
|
||||
/*
|
||||
* Get names from either/both an argv list and a file
|
||||
* list. This does not do any duplicate checking
|
||||
*/
|
||||
|
||||
grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC);
|
||||
|
||||
/* get file name in argv list */
|
||||
if (argv[ap]) {
|
||||
for (; ap < argc; ap++, nfiles++) {
|
||||
if (nfiles == ldlimit)
|
||||
grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5);
|
||||
ld[nfiles].fname = (char *) alloc(strlen(argv[ap]) + 1);
|
||||
Strcpy(ld[nfiles].fname, argv[ap]);
|
||||
}
|
||||
}
|
||||
|
||||
if (iseen) {
|
||||
/* want to do a list file */
|
||||
FILE *list = fopen(list_file, "r");
|
||||
if (!list) {
|
||||
printf("Can't open %s\n", list_file);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* get file names, one per line */
|
||||
for (; fgets(buf, sizeof(buf), list); nfiles++) {
|
||||
if (nfiles == ldlimit)
|
||||
grow_ld(&ld, &ldlimit, DLB_FILES_ALLOC / 5);
|
||||
*(eos(buf) - 1) = '\0'; /* strip newline */
|
||||
ld[nfiles].fname = (char *) alloc(strlen(buf) + 1);
|
||||
Strcpy(ld[nfiles].fname, buf);
|
||||
}
|
||||
fclose(list);
|
||||
}
|
||||
|
||||
if (nfiles == 0) {
|
||||
printf("No files to archive\n");
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get file sizes and name string length. Don't include
|
||||
* the directory information yet.
|
||||
*/
|
||||
for (i = 0, slen = 0, flen = 0; i < nfiles; i++) {
|
||||
fd = open(ld[i].fname, O_RDONLY | O_BINARY, 0);
|
||||
if (fd < 0) {
|
||||
printf("Can't open %s\n", ld[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
ld[i].fsize = lseek(fd, 0, SEEK_END);
|
||||
ld[i].foffset = flen;
|
||||
|
||||
slen += strlen(ld[i].fname); /* don't add null (yet) */
|
||||
flen += ld[i].fsize;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* open output file */
|
||||
out =
|
||||
open(library_file, O_RDWR | O_TRUNC | O_BINARY | O_CREAT, FCMASK);
|
||||
if (out < 0) {
|
||||
printf("Can't open %s for output\n", library_file);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* caculate directory size */
|
||||
dir_size = 40 /* header line (see below) */
|
||||
+ ((nfiles + 1) * 11) /* handling+file offset+SP+newline */
|
||||
+ slen + strlen(DLB_DIRECTORY); /* file names */
|
||||
|
||||
/* write directory */
|
||||
write_dlb_directory(out, nfiles, ld, slen, dir_size, flen);
|
||||
|
||||
flen = 0L;
|
||||
/* write each file */
|
||||
for (i = 0; i < nfiles; i++) {
|
||||
fd = open(ld[i].fname, O_RDONLY | O_BINARY, 0);
|
||||
if (fd < 0) {
|
||||
printf("Can't open input file '%s'\n", ld[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
if (verbose)
|
||||
printf("%s\n", ld[i].fname);
|
||||
|
||||
fsiz = 0L;
|
||||
while ((r = read(fd, buf, sizeof buf)) != 0) {
|
||||
if (r == -1) {
|
||||
printf("Read Error in '%s'\n", ld[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
if (write(out, buf, r) != r) {
|
||||
printf("Write Error in '%s'\n", ld[i].fname);
|
||||
xexit(EXIT_FAILURE);
|
||||
}
|
||||
fsiz += r;
|
||||
}
|
||||
(void) close(fd);
|
||||
if (fsiz != ld[i].fsize)
|
||||
rewrite_directory = TRUE;
|
||||
/* in case directory rewrite is needed */
|
||||
ld[i].fsize = fsiz;
|
||||
ld[i].foffset = flen;
|
||||
flen += fsiz;
|
||||
}
|
||||
|
||||
if (rewrite_directory) {
|
||||
if (verbose)
|
||||
printf("(rewriting dlb directory info)\n");
|
||||
(void) lseek(out, 0, SEEK_SET); /* rewind */
|
||||
write_dlb_directory(out, nfiles, ld, slen, dir_size, flen);
|
||||
}
|
||||
|
||||
for (i = 0; i < nfiles; i++)
|
||||
free((genericptr_t) ld[i].fname), ld[i].fname = 0;
|
||||
free((genericptr_t) ld), ldlimit = 0;
|
||||
|
||||
(void) close(out);
|
||||
xexit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
#endif /* DLBLIB */
|
||||
#endif /* DLB */
|
||||
|
||||
xexit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
@@ -477,14 +482,16 @@ int alloc_incr;
|
||||
{
|
||||
static libdir zerolibdir;
|
||||
int i = 0, newlimit = *ldlimit_p + alloc_incr;
|
||||
libdir *newld = (libdir *)alloc(newlimit * sizeof *newld);
|
||||
libdir *newld = (libdir *) alloc(newlimit * sizeof *newld);
|
||||
|
||||
if (*ld_p) {
|
||||
for ( ; i < *ldlimit_p; ++i) newld[i] = (*ld_p)[i];
|
||||
free((genericptr_t)*ld_p);
|
||||
for (; i < *ldlimit_p; ++i)
|
||||
newld[i] = (*ld_p)[i];
|
||||
free((genericptr_t) *ld_p);
|
||||
}
|
||||
*ld_p = newld, *ldlimit_p = newlimit;
|
||||
for ( ; i < *ldlimit_p; ++i) (*ld_p)[i] = zerolibdir;
|
||||
*ld_p = newld, *ldlimit_p = newlimit;
|
||||
for (; i < *ldlimit_p; ++i)
|
||||
(*ld_p)[i] = zerolibdir;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -496,44 +503,43 @@ long slen, dir_size, flen;
|
||||
char buf[BUFSIZ];
|
||||
int i;
|
||||
|
||||
sprintf(buf,"%3ld %8ld %8ld %8ld %8ld\n",
|
||||
(long) DLB_VERS, /* version of dlb file */
|
||||
(long) nfiles+1, /* # of entries (includes directory) */
|
||||
/* string length + room for nulls */
|
||||
(long) slen+strlen(DLB_DIRECTORY)+nfiles+1,
|
||||
(long) dir_size, /* start of first file */
|
||||
(long) flen+dir_size); /* total file size */
|
||||
sprintf(buf, "%3ld %8ld %8ld %8ld %8ld\n",
|
||||
(long) DLB_VERS, /* version of dlb file */
|
||||
(long) nfiles + 1, /* # of entries (includes directory) */
|
||||
/* string length + room for nulls */
|
||||
(long) slen + strlen(DLB_DIRECTORY) + nfiles + 1,
|
||||
(long) dir_size, /* start of first file */
|
||||
(long) flen + dir_size); /* total file size */
|
||||
Write(out, buf, strlen(buf));
|
||||
|
||||
/* write each file entry */
|
||||
/* write each file entry */
|
||||
#define ENTRY_FORMAT "%c%s %8ld\n"
|
||||
sprintf(buf, ENTRY_FORMAT, ENC_NORMAL, DLB_DIRECTORY, (long) 0);
|
||||
Write(out, buf, strlen(buf));
|
||||
for (i = 0; i < nfiles; i++) {
|
||||
sprintf(buf, ENTRY_FORMAT,
|
||||
ENC_NORMAL, /* encoding */
|
||||
ld[i].fname, /* name */
|
||||
ld[i].foffset + dir_size); /* offset */
|
||||
Write(out, buf, strlen(buf));
|
||||
sprintf(buf, ENTRY_FORMAT, ENC_NORMAL, /* encoding */
|
||||
ld[i].fname, /* name */
|
||||
ld[i].foffset + dir_size); /* offset */
|
||||
Write(out, buf, strlen(buf));
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* DLBLIB */
|
||||
#endif /* DLB */
|
||||
#endif /* DLBLIB */
|
||||
#endif /* DLB */
|
||||
|
||||
static void
|
||||
xexit(retcd)
|
||||
int retcd;
|
||||
int retcd;
|
||||
{
|
||||
#ifdef DLB
|
||||
#ifdef AMIGA
|
||||
if (origdir[0]) chdir(origdir);
|
||||
if (origdir[0])
|
||||
chdir(origdir);
|
||||
#endif
|
||||
#endif
|
||||
exit(retcd);
|
||||
}
|
||||
|
||||
|
||||
#ifdef AMIGA
|
||||
#include "date.h"
|
||||
const char amiga_version_string[] = AMIGA_VERSION_STRING;
|
||||
|
||||
+881
-799
File diff suppressed because it is too large
Load Diff
+1829
-1714
File diff suppressed because it is too large
Load Diff
+22
-21
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 panic.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 panic.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
|
||||
/* NetHack 3.6 panic.c $Date: 2009/05/06 10:54:39 $ $Revision: 1.4 $ */
|
||||
/* SCCS Id: @(#)panic.c 3.5 1994/03/02 */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
@@ -21,30 +21,30 @@ extern void NDECL(vms_abort);
|
||||
|
||||
/*VARARGS1*/
|
||||
boolean panicking;
|
||||
void VDECL(panic, (char *,...));
|
||||
void VDECL(panic, (char *, ...));
|
||||
|
||||
void
|
||||
panic VA_DECL(char *,str)
|
||||
VA_START(str);
|
||||
VA_INIT(str, char *);
|
||||
if(panicking++)
|
||||
void panic
|
||||
VA_DECL(char *, str)
|
||||
VA_START(str);
|
||||
VA_INIT(str, char *);
|
||||
if (panicking++)
|
||||
#ifdef SYSV
|
||||
(void)
|
||||
(void)
|
||||
#endif
|
||||
abort(); /* avoid loops - this should never happen*/
|
||||
abort(); /* avoid loops - this should never happen*/
|
||||
|
||||
(void) fputs(" ERROR: ", stderr);
|
||||
Vfprintf(stderr, str, VA_ARGS);
|
||||
(void) fflush(stderr);
|
||||
(void) fputs(" ERROR: ", stderr);
|
||||
Vfprintf(stderr, str, VA_ARGS);
|
||||
(void) fflush(stderr);
|
||||
#if defined(UNIX) || defined(VMS)
|
||||
# ifdef SYSV
|
||||
(void)
|
||||
# endif
|
||||
abort(); /* generate core dump */
|
||||
#ifdef SYSV
|
||||
(void)
|
||||
#endif
|
||||
VA_END();
|
||||
exit(EXIT_FAILURE); /* redundant */
|
||||
return;
|
||||
abort(); /* generate core dump */
|
||||
#endif
|
||||
VA_END();
|
||||
exit(EXIT_FAILURE); /* redundant */
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef ALLOCA_HACK
|
||||
@@ -53,10 +53,11 @@ panic VA_DECL(char *,str)
|
||||
* have it then just use malloc() instead. This may not work on some
|
||||
* systems, but they should either use yacc or get a real alloca routine.
|
||||
*/
|
||||
long *alloca(cnt)
|
||||
long *
|
||||
alloca(cnt)
|
||||
unsigned cnt;
|
||||
{
|
||||
return cnt ? alloc(cnt) : (long *)0;
|
||||
return cnt ? alloc(cnt) : (long *) 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+276
-266
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 recover.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 recover.c $NHDT-Date: 1431192769 2015/05/09 17:32:49 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */
|
||||
/* NetHack 3.6 recover.c $Date: 2009/05/06 10:54:40 $ $Revision: 1.11 $ */
|
||||
/* SCCS Id: @(#)recover.c 3.5 1999/10/23 */
|
||||
/* Copyright (c) Janet Walz, 1992. */
|
||||
@@ -19,37 +19,37 @@
|
||||
#endif
|
||||
|
||||
#ifdef VMS
|
||||
extern int FDECL(vms_creat, (const char *,unsigned));
|
||||
extern int FDECL(vms_open, (const char *,int,unsigned));
|
||||
#endif /* VMS */
|
||||
extern int FDECL(vms_creat, (const char *, unsigned));
|
||||
extern int FDECL(vms_open, (const char *, int, unsigned));
|
||||
#endif /* VMS */
|
||||
|
||||
int FDECL(restore_savefile, (char *));
|
||||
void FDECL(set_levelfile_name, (int));
|
||||
int FDECL(open_levelfile, (int));
|
||||
int NDECL(create_savefile);
|
||||
void FDECL(copy_bytes, (int,int));
|
||||
void FDECL(copy_bytes, (int, int));
|
||||
|
||||
#ifndef WIN_CE
|
||||
#define Fprintf (void)fprintf
|
||||
#define Fprintf (void) fprintf
|
||||
#else
|
||||
#define Fprintf (void)nhce_message
|
||||
static void nhce_message(FILE*, const char*, ...);
|
||||
#define Fprintf (void) nhce_message
|
||||
static void nhce_message(FILE *, const char *, ...);
|
||||
#endif
|
||||
|
||||
#define Close (void)close
|
||||
#define Close (void) close
|
||||
|
||||
#ifdef UNIX
|
||||
#define SAVESIZE (PL_NSIZ + 13) /* save/99999player.e */
|
||||
#define SAVESIZE (PL_NSIZ + 13) /* save/99999player.e */
|
||||
#else
|
||||
# ifdef VMS
|
||||
#define SAVESIZE (PL_NSIZ + 22) /* [.save]<uid>player.e;1 */
|
||||
# else
|
||||
# ifdef WIN32
|
||||
#define SAVESIZE (PL_NSIZ + 40) /* username-player.NetHack-saved-game */
|
||||
# else
|
||||
#define SAVESIZE FILENAME /* from macconf.h or pcconf.h */
|
||||
# endif
|
||||
# endif
|
||||
#ifdef VMS
|
||||
#define SAVESIZE (PL_NSIZ + 22) /* [.save]<uid>player.e;1 */
|
||||
#else
|
||||
#ifdef WIN32
|
||||
#define SAVESIZE (PL_NSIZ + 40) /* username-player.NetHack-saved-game */
|
||||
#else
|
||||
#define SAVESIZE FILENAME /* from macconf.h or pcconf.h */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(EXEPATH)
|
||||
@@ -59,89 +59,96 @@ char *FDECL(exepath, (char *));
|
||||
#if defined(__BORLANDC__) && !defined(_WIN32)
|
||||
extern unsigned _stklen = STKSIZ;
|
||||
#endif
|
||||
char savename[SAVESIZE]; /* holds relative path of save file from playground */
|
||||
|
||||
char
|
||||
savename[SAVESIZE]; /* holds relative path of save file from playground */
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int argno;
|
||||
const char *dir = (char *)0;
|
||||
int argno;
|
||||
const char *dir = (char *) 0;
|
||||
#ifdef AMIGA
|
||||
char *startdir = (char *)0;
|
||||
char *startdir = (char *) 0;
|
||||
#endif
|
||||
|
||||
|
||||
if (!dir) dir = getenv("NETHACKDIR");
|
||||
if (!dir) dir = getenv("HACKDIR");
|
||||
if (!dir)
|
||||
dir = getenv("NETHACKDIR");
|
||||
if (!dir)
|
||||
dir = getenv("HACKDIR");
|
||||
#if defined(EXEPATH)
|
||||
if (!dir) dir = exepath(argv[0]);
|
||||
if (!dir)
|
||||
dir = exepath(argv[0]);
|
||||
#endif
|
||||
if (argc == 1 || (argc == 2 && !strcmp(argv[1], "-"))) {
|
||||
Fprintf(stderr,
|
||||
"Usage: %s [ -d directory ] base1 [ base2 ... ]\n", argv[0]);
|
||||
if (argc == 1 || (argc == 2 && !strcmp(argv[1], "-"))) {
|
||||
Fprintf(stderr, "Usage: %s [ -d directory ] base1 [ base2 ... ]\n",
|
||||
argv[0]);
|
||||
#if defined(WIN32) || defined(MSDOS)
|
||||
if (dir) {
|
||||
Fprintf(stderr, "\t(Unless you override it with -d, recover will look \n");
|
||||
Fprintf(stderr, "\t in the %s directory on your system)\n", dir);
|
||||
}
|
||||
if (dir) {
|
||||
Fprintf(
|
||||
stderr,
|
||||
"\t(Unless you override it with -d, recover will look \n");
|
||||
Fprintf(stderr, "\t in the %s directory on your system)\n", dir);
|
||||
}
|
||||
#endif
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
argno = 1;
|
||||
if (!strncmp(argv[argno], "-d", 2)) {
|
||||
dir = argv[argno]+2;
|
||||
if (*dir == '=' || *dir == ':') dir++;
|
||||
if (!*dir && argc > argno) {
|
||||
argno++;
|
||||
dir = argv[argno];
|
||||
}
|
||||
if (!*dir) {
|
||||
Fprintf(stderr,
|
||||
"%s: flag -d must be followed by a directory name.\n",
|
||||
argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
argno++;
|
||||
}
|
||||
argno = 1;
|
||||
if (!strncmp(argv[argno], "-d", 2)) {
|
||||
dir = argv[argno] + 2;
|
||||
if (*dir == '=' || *dir == ':')
|
||||
dir++;
|
||||
if (!*dir && argc > argno) {
|
||||
argno++;
|
||||
dir = argv[argno];
|
||||
}
|
||||
if (!*dir) {
|
||||
Fprintf(stderr,
|
||||
"%s: flag -d must be followed by a directory name.\n",
|
||||
argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
argno++;
|
||||
}
|
||||
#if defined(SECURE) && !defined(VMS)
|
||||
if (dir
|
||||
# ifdef HACKDIR
|
||||
&& strcmp(dir, HACKDIR)
|
||||
# endif
|
||||
) {
|
||||
(void) setgid(getgid());
|
||||
(void) setuid(getuid());
|
||||
}
|
||||
#endif /* SECURE && !VMS */
|
||||
if (dir
|
||||
#ifdef HACKDIR
|
||||
&& strcmp(dir, HACKDIR)
|
||||
#endif
|
||||
) {
|
||||
(void) setgid(getgid());
|
||||
(void) setuid(getuid());
|
||||
}
|
||||
#endif /* SECURE && !VMS */
|
||||
|
||||
#ifdef HACKDIR
|
||||
if (!dir) dir = HACKDIR;
|
||||
if (!dir)
|
||||
dir = HACKDIR;
|
||||
#endif
|
||||
|
||||
#ifdef AMIGA
|
||||
startdir = getcwd(0,255);
|
||||
startdir = getcwd(0, 255);
|
||||
#endif
|
||||
if (dir && chdir((char *) dir) < 0) {
|
||||
Fprintf(stderr, "%s: cannot chdir to %s.\n", argv[0], dir);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (dir && chdir((char *) dir) < 0) {
|
||||
Fprintf(stderr, "%s: cannot chdir to %s.\n", argv[0], dir);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (argc > argno) {
|
||||
if (restore_savefile(argv[argno]) == 0)
|
||||
Fprintf(stderr, "recovered \"%s\" to %s\n",
|
||||
argv[argno], savename);
|
||||
argno++;
|
||||
}
|
||||
while (argc > argno) {
|
||||
if (restore_savefile(argv[argno]) == 0)
|
||||
Fprintf(stderr, "recovered \"%s\" to %s\n", argv[argno],
|
||||
savename);
|
||||
argno++;
|
||||
}
|
||||
#ifdef AMIGA
|
||||
if (startdir) (void)chdir(startdir);
|
||||
if (startdir)
|
||||
(void) chdir(startdir);
|
||||
#endif
|
||||
exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char lock[256];
|
||||
@@ -150,13 +157,14 @@ void
|
||||
set_levelfile_name(lev)
|
||||
int lev;
|
||||
{
|
||||
char *tf;
|
||||
char *tf;
|
||||
|
||||
tf = rindex(lock, '.');
|
||||
if (!tf) tf = lock + strlen(lock);
|
||||
(void) sprintf(tf, ".%d", lev);
|
||||
tf = rindex(lock, '.');
|
||||
if (!tf)
|
||||
tf = lock + strlen(lock);
|
||||
(void) sprintf(tf, ".%d", lev);
|
||||
#ifdef VMS
|
||||
(void) strcat(tf, ";1");
|
||||
(void) strcat(tf, ";1");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -164,200 +172,197 @@ int
|
||||
open_levelfile(lev)
|
||||
int lev;
|
||||
{
|
||||
int fd;
|
||||
int fd;
|
||||
|
||||
set_levelfile_name(lev);
|
||||
set_levelfile_name(lev);
|
||||
#if defined(MICRO) || defined(WIN32) || defined(MSDOS)
|
||||
fd = open(lock, O_RDONLY | O_BINARY);
|
||||
fd = open(lock, O_RDONLY | O_BINARY);
|
||||
#else
|
||||
fd = open(lock, O_RDONLY, 0);
|
||||
fd = open(lock, O_RDONLY, 0);
|
||||
#endif
|
||||
return fd;
|
||||
return fd;
|
||||
}
|
||||
|
||||
int
|
||||
create_savefile()
|
||||
{
|
||||
int fd;
|
||||
int fd;
|
||||
|
||||
#if defined(MICRO) || defined(WIN32) || defined(MSDOS)
|
||||
fd = open(savename, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK);
|
||||
fd = open(savename, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, FCMASK);
|
||||
#else
|
||||
fd = creat(savename, FCMASK);
|
||||
fd = creat(savename, FCMASK);
|
||||
#endif
|
||||
return fd;
|
||||
return fd;
|
||||
}
|
||||
|
||||
void
|
||||
copy_bytes(ifd, ofd)
|
||||
int ifd, ofd;
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
int nfrom, nto;
|
||||
char buf[BUFSIZ];
|
||||
int nfrom, nto;
|
||||
|
||||
do {
|
||||
nfrom = read(ifd, buf, BUFSIZ);
|
||||
nto = write(ofd, buf, nfrom);
|
||||
if (nto != nfrom) {
|
||||
Fprintf(stderr, "file copy failed!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} while (nfrom == BUFSIZ);
|
||||
do {
|
||||
nfrom = read(ifd, buf, BUFSIZ);
|
||||
nto = write(ofd, buf, nfrom);
|
||||
if (nto != nfrom) {
|
||||
Fprintf(stderr, "file copy failed!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
} while (nfrom == BUFSIZ);
|
||||
}
|
||||
|
||||
int
|
||||
restore_savefile(basename)
|
||||
char *basename;
|
||||
{
|
||||
int gfd, lfd, sfd;
|
||||
int lev, savelev, hpid, pltmpsiz;
|
||||
xchar levc;
|
||||
struct version_info version_data;
|
||||
struct savefile_info sfi;
|
||||
char plbuf[PL_NSIZ];
|
||||
int gfd, lfd, sfd;
|
||||
int lev, savelev, hpid, pltmpsiz;
|
||||
xchar levc;
|
||||
struct version_info version_data;
|
||||
struct savefile_info sfi;
|
||||
char plbuf[PL_NSIZ];
|
||||
|
||||
/* level 0 file contains:
|
||||
* pid of creating process (ignored here)
|
||||
* level number for current level of save file
|
||||
* name of save file nethack would have created
|
||||
* savefile info
|
||||
* player name
|
||||
* and game state
|
||||
*/
|
||||
(void) strcpy(lock, basename);
|
||||
gfd = open_levelfile(0);
|
||||
if (gfd < 0) {
|
||||
/* level 0 file contains:
|
||||
* pid of creating process (ignored here)
|
||||
* level number for current level of save file
|
||||
* name of save file nethack would have created
|
||||
* savefile info
|
||||
* player name
|
||||
* and game state
|
||||
*/
|
||||
(void) strcpy(lock, basename);
|
||||
gfd = open_levelfile(0);
|
||||
if (gfd < 0) {
|
||||
#if defined(WIN32) && !defined(WIN_CE)
|
||||
if(errno == EACCES) {
|
||||
Fprintf(stderr,
|
||||
"\nThere are files from a game in progress under your name.");
|
||||
Fprintf(stderr,"\nThe files are locked or inaccessible.");
|
||||
Fprintf(stderr,"\nPerhaps the other game is still running?\n");
|
||||
} else
|
||||
Fprintf(stderr,
|
||||
"\nTrouble accessing level 0 (errno = %d).\n", errno);
|
||||
if (errno == EACCES) {
|
||||
Fprintf(
|
||||
stderr,
|
||||
"\nThere are files from a game in progress under your name.");
|
||||
Fprintf(stderr, "\nThe files are locked or inaccessible.");
|
||||
Fprintf(stderr, "\nPerhaps the other game is still running?\n");
|
||||
} else
|
||||
Fprintf(stderr, "\nTrouble accessing level 0 (errno = %d).\n",
|
||||
errno);
|
||||
#endif
|
||||
Fprintf(stderr, "Cannot open level 0 for %s.\n", basename);
|
||||
return(-1);
|
||||
}
|
||||
if (read(gfd, (genericptr_t) &hpid, sizeof hpid) != sizeof hpid) {
|
||||
Fprintf(stderr, "%s\n%s%s%s\n",
|
||||
"Checkpoint data incompletely written or subsequently clobbered;",
|
||||
"recovery for \"", basename, "\" impossible.");
|
||||
Close(gfd);
|
||||
return(-1);
|
||||
}
|
||||
if (read(gfd, (genericptr_t) &savelev, sizeof(savelev))
|
||||
!= sizeof(savelev)) {
|
||||
Fprintf(stderr,
|
||||
"Checkpointing was not in effect for %s -- recovery impossible.\n",
|
||||
basename);
|
||||
Close(gfd);
|
||||
return(-1);
|
||||
}
|
||||
if ((read(gfd, (genericptr_t) savename, sizeof savename)
|
||||
!= sizeof savename) ||
|
||||
(read(gfd, (genericptr_t) &version_data, sizeof version_data)
|
||||
!= sizeof version_data) ||
|
||||
(read(gfd, (genericptr_t) &sfi, sizeof sfi)
|
||||
!= sizeof sfi) ||
|
||||
(read(gfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz)
|
||||
!= sizeof pltmpsiz) || (pltmpsiz > PL_NSIZ) ||
|
||||
(read(gfd, (genericptr_t) &plbuf, pltmpsiz)
|
||||
!= pltmpsiz)) {
|
||||
Fprintf(stderr, "Error reading %s -- can't recover.\n", lock);
|
||||
Close(gfd);
|
||||
return(-1);
|
||||
}
|
||||
Fprintf(stderr, "Cannot open level 0 for %s.\n", basename);
|
||||
return (-1);
|
||||
}
|
||||
if (read(gfd, (genericptr_t) &hpid, sizeof hpid) != sizeof hpid) {
|
||||
Fprintf(
|
||||
stderr, "%s\n%s%s%s\n",
|
||||
"Checkpoint data incompletely written or subsequently clobbered;",
|
||||
"recovery for \"", basename, "\" impossible.");
|
||||
Close(gfd);
|
||||
return (-1);
|
||||
}
|
||||
if (read(gfd, (genericptr_t) &savelev, sizeof(savelev))
|
||||
!= sizeof(savelev)) {
|
||||
Fprintf(stderr, "Checkpointing was not in effect for %s -- recovery "
|
||||
"impossible.\n",
|
||||
basename);
|
||||
Close(gfd);
|
||||
return (-1);
|
||||
}
|
||||
if ((read(gfd, (genericptr_t) savename, sizeof savename)
|
||||
!= sizeof savename)
|
||||
|| (read(gfd, (genericptr_t) &version_data, sizeof version_data)
|
||||
!= sizeof version_data)
|
||||
|| (read(gfd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi)
|
||||
|| (read(gfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz)
|
||||
!= sizeof pltmpsiz) || (pltmpsiz > PL_NSIZ)
|
||||
|| (read(gfd, (genericptr_t) &plbuf, pltmpsiz) != pltmpsiz)) {
|
||||
Fprintf(stderr, "Error reading %s -- can't recover.\n", lock);
|
||||
Close(gfd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* save file should contain:
|
||||
* version info
|
||||
* savefile info
|
||||
* player name
|
||||
* current level (including pets)
|
||||
* (non-level-based) game state
|
||||
* other levels
|
||||
*/
|
||||
sfd = create_savefile();
|
||||
if (sfd < 0) {
|
||||
Fprintf(stderr, "Cannot create savefile %s.\n", savename);
|
||||
Close(gfd);
|
||||
return(-1);
|
||||
}
|
||||
/* save file should contain:
|
||||
* version info
|
||||
* savefile info
|
||||
* player name
|
||||
* current level (including pets)
|
||||
* (non-level-based) game state
|
||||
* other levels
|
||||
*/
|
||||
sfd = create_savefile();
|
||||
if (sfd < 0) {
|
||||
Fprintf(stderr, "Cannot create savefile %s.\n", savename);
|
||||
Close(gfd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
lfd = open_levelfile(savelev);
|
||||
if (lfd < 0) {
|
||||
Fprintf(stderr, "Cannot open level of save for %s.\n", basename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return(-1);
|
||||
}
|
||||
lfd = open_levelfile(savelev);
|
||||
if (lfd < 0) {
|
||||
Fprintf(stderr, "Cannot open level of save for %s.\n", basename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (write(sfd, (genericptr_t) &version_data, sizeof version_data)
|
||||
!= sizeof version_data) {
|
||||
Fprintf(stderr, "Error writing %s; recovery failed.\n", savename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return(-1);
|
||||
}
|
||||
if (write(sfd, (genericptr_t) &version_data, sizeof version_data)
|
||||
!= sizeof version_data) {
|
||||
Fprintf(stderr, "Error writing %s; recovery failed.\n", savename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (write(sfd, (genericptr_t) &sfi, sizeof sfi)
|
||||
!= sizeof sfi) {
|
||||
Fprintf(stderr,
|
||||
"Error writing %s; recovery failed (savefile_info).\n",
|
||||
savename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return(-1);
|
||||
}
|
||||
if (write(sfd, (genericptr_t) &sfi, sizeof sfi) != sizeof sfi) {
|
||||
Fprintf(stderr,
|
||||
"Error writing %s; recovery failed (savefile_info).\n",
|
||||
savename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (write(sfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz)
|
||||
!= sizeof pltmpsiz) {
|
||||
Fprintf(stderr,
|
||||
"Error writing %s; recovery failed (player name size).\n",
|
||||
savename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return(-1);
|
||||
}
|
||||
if (write(sfd, (genericptr_t) &pltmpsiz, sizeof pltmpsiz)
|
||||
!= sizeof pltmpsiz) {
|
||||
Fprintf(stderr,
|
||||
"Error writing %s; recovery failed (player name size).\n",
|
||||
savename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (write(sfd, (genericptr_t) &plbuf, pltmpsiz)
|
||||
!= pltmpsiz) {
|
||||
Fprintf(stderr,
|
||||
"Error writing %s; recovery failed (player name).\n",
|
||||
savename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return(-1);
|
||||
}
|
||||
if (write(sfd, (genericptr_t) &plbuf, pltmpsiz) != pltmpsiz) {
|
||||
Fprintf(stderr, "Error writing %s; recovery failed (player name).\n",
|
||||
savename);
|
||||
Close(gfd);
|
||||
Close(sfd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
copy_bytes(lfd, sfd);
|
||||
Close(lfd);
|
||||
(void) unlink(lock);
|
||||
copy_bytes(lfd, sfd);
|
||||
Close(lfd);
|
||||
(void) unlink(lock);
|
||||
|
||||
copy_bytes(gfd, sfd);
|
||||
Close(gfd);
|
||||
set_levelfile_name(0);
|
||||
(void) unlink(lock);
|
||||
copy_bytes(gfd, sfd);
|
||||
Close(gfd);
|
||||
set_levelfile_name(0);
|
||||
(void) unlink(lock);
|
||||
|
||||
for (lev = 1; lev < 256; lev++) {
|
||||
/* level numbers are kept in xchars in save.c, so the
|
||||
* maximum level number (for the endlevel) must be < 256
|
||||
*/
|
||||
if (lev != savelev) {
|
||||
lfd = open_levelfile(lev);
|
||||
if (lfd >= 0) {
|
||||
/* any or all of these may not exist */
|
||||
levc = (xchar) lev;
|
||||
write(sfd, (genericptr_t) &levc, sizeof(levc));
|
||||
copy_bytes(lfd, sfd);
|
||||
Close(lfd);
|
||||
(void) unlink(lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (lev = 1; lev < 256; lev++) {
|
||||
/* level numbers are kept in xchars in save.c, so the
|
||||
* maximum level number (for the endlevel) must be < 256
|
||||
*/
|
||||
if (lev != savelev) {
|
||||
lfd = open_levelfile(lev);
|
||||
if (lfd >= 0) {
|
||||
/* any or all of these may not exist */
|
||||
levc = (xchar) lev;
|
||||
write(sfd, (genericptr_t) &levc, sizeof(levc));
|
||||
copy_bytes(lfd, sfd);
|
||||
Close(lfd);
|
||||
(void) unlink(lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Close(sfd);
|
||||
Close(sfd);
|
||||
|
||||
#if 0 /* OBSOLETE, HackWB is no longer in use */
|
||||
#ifdef AMIGA
|
||||
@@ -379,44 +384,47 @@ char *basename;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef EXEPATH
|
||||
# ifdef __DJGPP__
|
||||
#ifdef __DJGPP__
|
||||
#define PATH_SEPARATOR '/'
|
||||
# else
|
||||
#else
|
||||
#define PATH_SEPARATOR '\\'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define EXEPATHBUFSZ 256
|
||||
char exepathbuf[EXEPATHBUFSZ];
|
||||
|
||||
char *exepath(str)
|
||||
char *
|
||||
exepath(str)
|
||||
char *str;
|
||||
{
|
||||
char *tmp, *tmp2;
|
||||
int bsize;
|
||||
char *tmp, *tmp2;
|
||||
int bsize;
|
||||
|
||||
if (!str) return (char *)0;
|
||||
bsize = EXEPATHBUFSZ;
|
||||
tmp = exepathbuf;
|
||||
if (!str)
|
||||
return (char *) 0;
|
||||
bsize = EXEPATHBUFSZ;
|
||||
tmp = exepathbuf;
|
||||
#if !defined(WIN32)
|
||||
strcpy (tmp, str);
|
||||
strcpy(tmp, str);
|
||||
#else
|
||||
# if defined(WIN_CE)
|
||||
{
|
||||
TCHAR wbuf[EXEPATHBUFSZ];
|
||||
GetModuleFileName((HANDLE)0, wbuf, EXEPATHBUFSZ);
|
||||
NH_W2A(wbuf, tmp, bsize);
|
||||
}
|
||||
# else
|
||||
*(tmp + GetModuleFileName((HANDLE)0, tmp, bsize)) = '\0';
|
||||
# endif
|
||||
#if defined(WIN_CE)
|
||||
{
|
||||
TCHAR wbuf[EXEPATHBUFSZ];
|
||||
GetModuleFileName((HANDLE) 0, wbuf, EXEPATHBUFSZ);
|
||||
NH_W2A(wbuf, tmp, bsize);
|
||||
}
|
||||
#else
|
||||
*(tmp + GetModuleFileName((HANDLE) 0, tmp, bsize)) = '\0';
|
||||
#endif
|
||||
tmp2 = strrchr(tmp, PATH_SEPARATOR);
|
||||
if (tmp2) *tmp2 = '\0';
|
||||
return tmp;
|
||||
#endif
|
||||
tmp2 = strrchr(tmp, PATH_SEPARATOR);
|
||||
if (tmp2)
|
||||
*tmp2 = '\0';
|
||||
return tmp;
|
||||
}
|
||||
#endif /* EXEPATH */
|
||||
|
||||
@@ -426,17 +434,19 @@ const char amiga_version_string[] = AMIGA_VERSION_STRING;
|
||||
#endif
|
||||
|
||||
#ifdef WIN_CE
|
||||
void nhce_message(FILE* f, const char* str, ...)
|
||||
void
|
||||
nhce_message(FILE *f, const char *str, ...)
|
||||
{
|
||||
va_list ap;
|
||||
TCHAR wbuf[NHSTR_BUFSIZE];
|
||||
char buf[NHSTR_BUFSIZE];
|
||||
TCHAR wbuf[NHSTR_BUFSIZE];
|
||||
char buf[NHSTR_BUFSIZE];
|
||||
|
||||
va_start(ap, str);
|
||||
vsprintf(buf, str, ap);
|
||||
vsprintf(buf, str, ap);
|
||||
va_end(ap);
|
||||
|
||||
MessageBox(NULL, NH_A2W(buf, wbuf, NHSTR_BUFSIZE), TEXT("Recover"), MB_OK);
|
||||
MessageBox(NULL, NH_A2W(buf, wbuf, NHSTR_BUFSIZE), TEXT("Recover"),
|
||||
MB_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user