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:
+110
-93
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 oldcrtl.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 oldcrtl.c $NHDT-Date: 1431192780 2015/05/09 17:33:00 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
|
||||
/* NetHack 3.6 oldcrtl.c $Date: 2009/05/06 10:51:24 $ $Revision: 1.4 $ */
|
||||
/* SCCS Id: @(#)oldcrtl.c 3.5 1995/06/01 */
|
||||
/* Pat Rankin May'90 */
|
||||
@@ -24,169 +24,186 @@
|
||||
|
||||
/* void *memset(void *, int, size_t) -- fill chunk of memory.
|
||||
*/
|
||||
char *memset( dst, fil, cnt )
|
||||
char *
|
||||
memset(dst, fil, cnt)
|
||||
REG char *dst;
|
||||
REG char fil;
|
||||
REG int cnt;
|
||||
REG char fil;
|
||||
REG int cnt;
|
||||
{
|
||||
char *dst_p = dst;
|
||||
while ( --cnt >= 0 )
|
||||
*dst++ = fil;
|
||||
while (--cnt >= 0)
|
||||
*dst++ = fil;
|
||||
return dst_p;
|
||||
}
|
||||
|
||||
/* void *memcpy(void *, const void *, size_t) -- copy chunk of memory.
|
||||
*/
|
||||
char *memcpy( dst, src, cnt )
|
||||
REG char *dst;
|
||||
char *
|
||||
memcpy(dst, src, cnt)
|
||||
REG char *dst;
|
||||
REG const char *src;
|
||||
REG int cnt;
|
||||
REG int cnt;
|
||||
{
|
||||
char *dst_p = dst;
|
||||
while ( --cnt >= 0 )
|
||||
*dst++ = *src++;
|
||||
while (--cnt >= 0)
|
||||
*dst++ = *src++;
|
||||
return dst_p;
|
||||
}
|
||||
|
||||
/* void *memmove(void *, const void *, size_t) -- copy possibly overlapping mem.
|
||||
/* void *memmove(void *, const void *, size_t) -- copy possibly overlapping
|
||||
* mem.
|
||||
*/
|
||||
char *memmove( dst, src, cnt )
|
||||
REG char *dst;
|
||||
char *
|
||||
memmove(dst, src, cnt)
|
||||
REG char *dst;
|
||||
REG const char *src;
|
||||
REG int cnt;
|
||||
REG int cnt;
|
||||
{
|
||||
char *dst_p = dst;
|
||||
if ( src == dst || cnt <= 0 ) {
|
||||
; /* do nothing */
|
||||
} else if ( dst < src || dst >= src + cnt ) {
|
||||
while ( --cnt >= 0 )
|
||||
*dst++ = *src++;
|
||||
} else { /* work backwards */
|
||||
dst += cnt, src += cnt;
|
||||
while ( --cnt >= 0 )
|
||||
*--dst = *--src;
|
||||
if (src == dst || cnt <= 0) {
|
||||
; /* do nothing */
|
||||
} else if (dst < src || dst >= src + cnt) {
|
||||
while (--cnt >= 0)
|
||||
*dst++ = *src++;
|
||||
} else { /* work backwards */
|
||||
dst += cnt, src += cnt;
|
||||
while (--cnt >= 0)
|
||||
*--dst = *--src;
|
||||
}
|
||||
return dst_p;
|
||||
}
|
||||
|
||||
/* void *memchr(const void *, int, size_t) -- search for a byte.
|
||||
*/
|
||||
char *memchr( buf, byt, len )
|
||||
char *
|
||||
memchr(buf, byt, len)
|
||||
REG const char *buf;
|
||||
REG char byt;
|
||||
REG int len;
|
||||
REG char byt;
|
||||
REG int len;
|
||||
{
|
||||
while ( --len >= 0 )
|
||||
if ( *buf++ == byt ) /* found */
|
||||
return (char *)--buf;
|
||||
return (char *)0; /* not found */
|
||||
while (--len >= 0)
|
||||
if (*buf++ == byt) /* found */
|
||||
return (char *) --buf;
|
||||
return (char *) 0; /* not found */
|
||||
}
|
||||
|
||||
/* int memcmp(const void *, const void *, size_t) -- compare two chunks.
|
||||
*/
|
||||
int memcmp( buf1, buf2, len )
|
||||
int
|
||||
memcmp(buf1, buf2, len)
|
||||
REG const char *buf1;
|
||||
REG const char *buf2;
|
||||
REG int len;
|
||||
REG int len;
|
||||
{
|
||||
while ( --len >= 0 )
|
||||
if ( *buf1++ != *buf2++ )
|
||||
return (*--buf1 - *--buf2);
|
||||
return 0; /* buffers matched */
|
||||
while (--len >= 0)
|
||||
if (*buf1++ != *buf2++)
|
||||
return (*--buf1 - *--buf2);
|
||||
return 0; /* buffers matched */
|
||||
}
|
||||
#endif /*!SUPPRESS_MEM_FUNCS*/
|
||||
|
||||
|
||||
#ifndef SUPPRESS_ATEXIT
|
||||
/* int atexit(void (*)(void)) -- register an exit handler.
|
||||
*/
|
||||
#define MAX_EXIT_FUNCS 32 /* arbitrary (32 matches VAX C v3.x docs) */
|
||||
struct ex_hndlr { long reserved, (*routine)(), arg_count, *arg1_addr; };
|
||||
static int ex_cnt = 0; /* number of handlers registered so far */
|
||||
static struct { long dummy_arg; struct ex_hndlr handler; /*(black box)*/
|
||||
} ex_data[MAX_EXIT_FUNCS]; /* static handler data */
|
||||
#define MAX_EXIT_FUNCS 32 /* arbitrary (32 matches VAX C v3.x docs) */
|
||||
struct ex_hndlr {
|
||||
long reserved, (*routine)(), arg_count, *arg1_addr;
|
||||
};
|
||||
static int ex_cnt = 0; /* number of handlers registered so far */
|
||||
static struct {
|
||||
long dummy_arg;
|
||||
struct ex_hndlr handler; /*(black box)*/
|
||||
} ex_data[MAX_EXIT_FUNCS]; /* static handler data */
|
||||
extern unsigned long sys$dclexh();
|
||||
|
||||
int atexit( function )
|
||||
void (*function)(); /* note: actually gets called with 1 arg */
|
||||
int
|
||||
atexit(function)
|
||||
void (*function)(); /* note: actually gets called with 1 arg */
|
||||
{
|
||||
if ( ex_cnt < MAX_EXIT_FUNCS ) {
|
||||
ex_data[ex_cnt].dummy_arg = 0; /* ultimately receives exit reason */
|
||||
ex_data[ex_cnt].handler.reserved = 0;
|
||||
ex_data[ex_cnt].handler.routine = (long (*)()) function;
|
||||
ex_data[ex_cnt].handler.arg_count = 1; /*(required)*/
|
||||
ex_data[ex_cnt].handler.arg1_addr = &ex_data[ex_cnt].dummy_arg;
|
||||
(void)sys$dclexh(&ex_data[ex_cnt].handler); /* declare exit handler */
|
||||
return ++ex_cnt; /*(non-zero)*/
|
||||
if (ex_cnt < MAX_EXIT_FUNCS) {
|
||||
ex_data[ex_cnt].dummy_arg = 0; /* ultimately receives exit reason */
|
||||
ex_data[ex_cnt].handler.reserved = 0;
|
||||
ex_data[ex_cnt].handler.routine = (long (*) ()) function;
|
||||
ex_data[ex_cnt].handler.arg_count = 1; /*(required)*/
|
||||
ex_data[ex_cnt].handler.arg1_addr = &ex_data[ex_cnt].dummy_arg;
|
||||
(void) sys$dclexh(
|
||||
&ex_data[ex_cnt].handler); /* declare exit handler */
|
||||
return ++ex_cnt; /*(non-zero)*/
|
||||
} else
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
#endif /*!SUPPRESS_ATEXIT*/
|
||||
|
||||
|
||||
#ifndef SUPPRESS_RENAME
|
||||
/* int rename(const char *, const char *) -- rename a file (on same device).
|
||||
*/
|
||||
#ifndef EVMSERR
|
||||
#include <errno.h>
|
||||
#define C$$TRANSLATE(status) (errno = EVMSERR, vaxc$errno = (status))
|
||||
#define C$$TRANSLATE(status) (errno = EVMSERR, vaxc$errno = (status))
|
||||
#endif
|
||||
extern unsigned long lib$rename_file();
|
||||
|
||||
int rename( old_name, new_name )
|
||||
const char *old_name;
|
||||
const char *new_name;
|
||||
int
|
||||
rename(old_name, new_name)
|
||||
const char *old_name;
|
||||
const char *new_name;
|
||||
{
|
||||
struct dsc { unsigned short len, mbz; const char *adr; } old_dsc, new_dsc;
|
||||
struct dsc {
|
||||
unsigned short len, mbz;
|
||||
const char *adr;
|
||||
} old_dsc, new_dsc;
|
||||
unsigned long status;
|
||||
|
||||
/* put strings into descriptors and call run-time library routine */
|
||||
new_dsc.mbz = old_dsc.mbz = 0; /* type and class unspecified */
|
||||
old_dsc.len = strlen( old_dsc.adr = old_name );
|
||||
new_dsc.len = strlen( new_dsc.adr = new_name );
|
||||
status = lib$rename_file(&old_dsc, &new_dsc); /* omit optional args */
|
||||
if ( !(status & 1) ) { /* even => failure */
|
||||
C$$TRANSLATE(status);
|
||||
return -1;
|
||||
} else /* odd => success */
|
||||
return 0;
|
||||
new_dsc.mbz = old_dsc.mbz = 0; /* type and class unspecified */
|
||||
old_dsc.len = strlen(old_dsc.adr = old_name);
|
||||
new_dsc.len = strlen(new_dsc.adr = new_name);
|
||||
status = lib$rename_file(&old_dsc, &new_dsc); /* omit optional args */
|
||||
if (!(status & 1)) { /* even => failure */
|
||||
C$$TRANSLATE(status);
|
||||
return -1;
|
||||
} else /* odd => success */
|
||||
return 0;
|
||||
}
|
||||
#endif /*!SUPPRESS_RENAME*/
|
||||
|
||||
|
||||
#ifndef SUPPRESS_QSORT
|
||||
/* void qsort(void *, size_t, size_t, int (*)()) -- sort arbitrary collection.
|
||||
*/
|
||||
extern char *malloc(); /* assume no alloca() available */
|
||||
extern char *malloc(); /* assume no alloca() available */
|
||||
extern void free();
|
||||
|
||||
void qsort( base, count, size, compare )
|
||||
char *base;
|
||||
int count;
|
||||
REG int size;
|
||||
int (*compare)();
|
||||
void
|
||||
qsort(base, count, size, compare)
|
||||
char *base;
|
||||
int count;
|
||||
REG int size;
|
||||
int (*compare)();
|
||||
{
|
||||
REG int i, cmp;
|
||||
REG char *next, *prev, *tmp = 0;
|
||||
char wrk_buf[512];
|
||||
REG int i, cmp;
|
||||
REG char *next, *prev, *tmp = 0;
|
||||
char wrk_buf[512];
|
||||
|
||||
/* just use a shuffle sort (tradeoff between efficiency & simplicity) */
|
||||
/* [Optimal if already sorted; worst case when initially reversed.] */
|
||||
for ( next = base, i = 1; i < count; i++ ) {
|
||||
prev = next, next += size; /* increment front pointer */
|
||||
if ( (cmp = (*compare)( next, prev)) < 0 ) {
|
||||
/* found element out of order; move other(s) up then re-insert it */
|
||||
if ( !tmp ) tmp = size > (int)(sizeof wrk_buf) ? malloc(size) : wrk_buf;
|
||||
memcpy( tmp, next, size); /* save smaller element */
|
||||
while ( cmp < 0 ) {
|
||||
memcpy( prev + size, prev, size); /* move larger elem. up */
|
||||
prev -= size; /* decrement back pointer */
|
||||
cmp = (prev >= base ? (*compare)( tmp, prev) : 0);
|
||||
}
|
||||
memcpy( prev + size, tmp, size); /* restore small element */
|
||||
}
|
||||
for (next = base, i = 1; i < count; i++) {
|
||||
prev = next, next += size; /* increment front pointer */
|
||||
if ((cmp = (*compare)(next, prev)) < 0) {
|
||||
/* found element out of order; move other(s) up then re-insert it
|
||||
*/
|
||||
if (!tmp)
|
||||
tmp = size > (int) (sizeof wrk_buf) ? malloc(size) : wrk_buf;
|
||||
memcpy(tmp, next, size); /* save smaller element */
|
||||
while (cmp < 0) {
|
||||
memcpy(prev + size, prev, size); /* move larger elem. up */
|
||||
prev -= size; /* decrement back pointer */
|
||||
cmp = (prev >= base ? (*compare)(tmp, prev) : 0);
|
||||
}
|
||||
memcpy(prev + size, tmp, size); /* restore small element */
|
||||
}
|
||||
}
|
||||
if ( tmp != 0 && tmp != wrk_buf ) free(tmp);
|
||||
if (tmp != 0 && tmp != wrk_buf)
|
||||
free(tmp);
|
||||
return;
|
||||
}
|
||||
#endif /*!SUPPRESS_QSORT*/
|
||||
|
||||
Reference in New Issue
Block a user