Indented with src/scripts/indent-emp.

This commit is contained in:
Markus Armbruster 2003-09-02 20:48:48 +00:00
parent 5f263a7753
commit 9b7adfbecc
437 changed files with 52211 additions and 51052 deletions

View file

@ -36,24 +36,25 @@
int
atoip(s_char **ptrptr)
{
register int num;
register s_char *cp;
register int neg;
register int num;
register s_char *cp;
register int neg;
if (ptrptr == 0 || *ptrptr == 0) return 0;
cp = *ptrptr;
num = 0;
neg = 0;
loop:
while (*cp == ' ' || *cp == '\t')
cp++;
if (*cp == '-') {
neg++;
cp++;
goto loop;
}
while (*cp >= '0' && *cp <= '9')
num = num * 10 + *cp++ - '0';
*ptrptr = cp;
return(neg ? -num : num);
if (ptrptr == 0 || *ptrptr == 0)
return 0;
cp = *ptrptr;
num = 0;
neg = 0;
loop:
while (*cp == ' ' || *cp == '\t')
cp++;
if (*cp == '-') {
neg++;
cp++;
goto loop;
}
while (*cp >= '0' && *cp <= '9')
num = num * 10 + *cp++ - '0';
*ptrptr = cp;
return (neg ? -num : num);
}

View file

@ -42,14 +42,14 @@
int
atopi(s_char *p)
{
register int r11;
register int r11;
if (p) {
r11 = atoi(p);
if (r11 < 0)
r11 = -r11;
return r11;
} else {
return (0);
}
if (p) {
r11 = atoi(p);
if (r11 < 0)
r11 = -r11;
return r11;
} else {
return (0);
}
}

View file

@ -33,23 +33,23 @@
#include "misc.h"
#include "bit.h"
#include "gen.h" /* getfdtablesize etc. */
#include "gen.h" /* getfdtablesize etc. */
static int bit_nbytes;
static int bit_nbytes;
bit_fdmask
bit_newfdmask(void)
{
bit_fdmask mask;
int nfile;
bit_fdmask mask;
int nfile;
if (bit_nbytes == 0) {
nfile = getfdtablesize();
bit_nbytes = (nfile + (BIT_BITSPERMASK-1)) / BIT_NBBY;
}
mask = (bit_fdmask) malloc(bit_nbytes);
(void) bit_zero(mask);
return mask;
if (bit_nbytes == 0) {
nfile = getfdtablesize();
bit_nbytes = (nfile + (BIT_BITSPERMASK - 1)) / BIT_NBBY;
}
mask = (bit_fdmask)malloc(bit_nbytes);
(void)bit_zero(mask);
return mask;
}
/*
@ -58,14 +58,14 @@ bit_newfdmask(void)
void
bit_zero(bit_fdmask bitp)
{
bit_mask *mask;
register int i;
register int nwords;
bit_mask *mask;
register int i;
register int nwords;
mask = bitp;
nwords = bit_nbytes / sizeof(*mask);
for (i=0; i<nwords; i++)
*mask++ = 0;
mask = bitp;
nwords = bit_nbytes / sizeof(*mask);
for (i = 0; i < nwords; i++)
*mask++ = 0;
}
/*
@ -74,14 +74,14 @@ bit_zero(bit_fdmask bitp)
void
bit_not(bit_fdmask bitp)
{
register bit_mask *mask;
register int i;
register int nwords;
register bit_mask *mask;
register int i;
register int nwords;
mask = bitp;
nwords = bit_nbytes / sizeof(*mask);
for (i=0; i<nwords; i++,mask++)
*mask = ~(*mask);
mask = bitp;
nwords = bit_nbytes / sizeof(*mask);
for (i = 0; i < nwords; i++, mask++)
*mask = ~(*mask);
}
/*
@ -90,16 +90,16 @@ bit_not(bit_fdmask bitp)
void
bit_copy(bit_fdmask bitsrc, bit_fdmask bitdst)
{
register bit_mask *src;
register bit_mask *dst;
register int i;
register int nwords;
register bit_mask *src;
register bit_mask *dst;
register int i;
register int nwords;
dst = bitdst;
src = bitsrc;
nwords = bit_nbytes / sizeof(*dst);
for (i=0; i<nwords; i++)
*dst++ = *src++;
dst = bitdst;
src = bitsrc;
nwords = bit_nbytes / sizeof(*dst);
for (i = 0; i < nwords; i++)
*dst++ = *src++;
}
/*
@ -108,16 +108,16 @@ bit_copy(bit_fdmask bitsrc, bit_fdmask bitdst)
void
bit_or(bit_fdmask bitsrc, bit_fdmask bitdst)
{
register bit_mask *src;
register bit_mask *dst;
register int i;
register int nwords;
register bit_mask *src;
register bit_mask *dst;
register int i;
register int nwords;
nwords = bit_nbytes / sizeof(*dst);
src = bitsrc;
dst = bitdst;
for (i=0; i<nwords; i++)
*dst++ |= *src++;
nwords = bit_nbytes / sizeof(*dst);
src = bitsrc;
dst = bitdst;
for (i = 0; i < nwords; i++)
*dst++ |= *src++;
}
/*
@ -126,18 +126,18 @@ bit_or(bit_fdmask bitsrc, bit_fdmask bitdst)
void
bit_or3(bit_fdmask bitsrc1, bit_fdmask bitsrc2, bit_fdmask bitdst)
{
register bit_mask *src1;
register bit_mask *src2;
register bit_mask *dst;
register int i;
register int nwords;
register bit_mask *src1;
register bit_mask *src2;
register bit_mask *dst;
register int i;
register int nwords;
src1 = bitsrc1;
src2 = bitsrc2;
dst = bitdst;
nwords = bit_nbytes / sizeof(*dst);
for (i=0; i<nwords; i++)
*dst++ = *src1++ | *src2++;
src1 = bitsrc1;
src2 = bitsrc2;
dst = bitdst;
nwords = bit_nbytes / sizeof(*dst);
for (i = 0; i < nwords; i++)
*dst++ = *src1++ | *src2++;
}
/*
@ -146,16 +146,16 @@ bit_or3(bit_fdmask bitsrc1, bit_fdmask bitsrc2, bit_fdmask bitdst)
void
bit_and(bit_fdmask bitsrc, bit_fdmask bitdst)
{
register bit_mask *src;
register bit_mask *dst;
register int i;
register int nwords;
register bit_mask *src;
register bit_mask *dst;
register int i;
register int nwords;
nwords = bit_nbytes / sizeof(*src);
src = bitsrc;
dst = bitdst;
for (i=0; i<nwords; i++)
*dst++ &= *src++;
nwords = bit_nbytes / sizeof(*src);
src = bitsrc;
dst = bitdst;
for (i = 0; i < nwords; i++)
*dst++ &= *src++;
}
/*
@ -164,18 +164,18 @@ bit_and(bit_fdmask bitsrc, bit_fdmask bitdst)
void
bit_and3(bit_fdmask bitsrc1, bit_fdmask bitsrc2, bit_fdmask bitdst)
{
register bit_mask *src1;
register bit_mask *src2;
register bit_mask *dst;
register int i;
register int nwords;
register bit_mask *src1;
register bit_mask *src2;
register bit_mask *dst;
register int i;
register int nwords;
src1 = bitsrc1;
src2 = bitsrc2;
dst = bitdst;
nwords = bit_nbytes / sizeof(*dst);
for (i=0; i<nwords; i++)
*dst++ = *src1++ & *src2++;
src1 = bitsrc1;
src2 = bitsrc2;
dst = bitdst;
nwords = bit_nbytes / sizeof(*dst);
for (i = 0; i < nwords; i++)
*dst++ = *src1++ & *src2++;
}
/*
@ -185,22 +185,22 @@ bit_and3(bit_fdmask bitsrc1, bit_fdmask bitsrc2, bit_fdmask bitdst)
int
bit_fd(bit_fdmask bitp)
{
register bit_mask *mask;
register unsigned int j;
register bit_mask m;
register int i;
int nwords;
register bit_mask *mask;
register unsigned int j;
register bit_mask m;
register int i;
int nwords;
mask = bitp;
nwords = bit_nbytes / sizeof(m);
for (i=0; i<nwords; i++,mask++) {
if ((m = *mask) == 0)
continue;
for (j=0; j<BIT_BITSPERMASK; j++) {
if (m & bit(j))
return i*BIT_BITSPERMASK + j;
}
/*NOTREACHED*/
mask = bitp;
nwords = bit_nbytes / sizeof(m);
for (i = 0; i < nwords; i++, mask++) {
if ((m = *mask) == 0)
continue;
for (j = 0; j < BIT_BITSPERMASK; j++) {
if (m & bit(j))
return i * BIT_BITSPERMASK + j;
}
return -1;
/*NOTREACHED*/
}
return -1;
}

View file

@ -37,36 +37,36 @@
void
srandom(unsigned int n)
{
extern void srand48();
extern void srand48();
srand48(n);
srand48(n);
}
long
random(void)
{
extern long lrand48();
extern long lrand48();
return (lrand48()); /* 5/28/91 by bailey@mcs.kent.edu */
return (lrand48()); /* 5/28/91 by bailey@mcs.kent.edu */
}
#endif
int
chance(double d)
{
double roll;
double roll;
roll = (random() & 0x7fff);
roll = (random() & 0x7fff);
if (d > roll/32768.0)
return 1;
return 0;
if (d > roll / 32768.0)
return 1;
return 0;
}
int
roll(int n)
{
return (random() % n) + 1;
return (random() % n) + 1;
}
/*
@ -76,12 +76,12 @@ roll(int n)
int
roundavg(double val)
{
int flr;
int flr;
flr = (int) val;
if (val < 0)
flr -= chance(flr - val);
else
flr += chance(val - flr);
return flr;
flr = (int)val;
if (val < 0)
flr -= chance(flr - val);
else
flr += chance(val - flr);
return flr;
}

View file

@ -40,9 +40,8 @@
s_char *
copy(register s_char *s1, register s_char *s2)
{
while ((*s2++ = *s1++) != 0)
;
return s2 - 1;
while ((*s2++ = *s1++) != 0) ;
return s2 - 1;
}
#ifdef hpux
@ -51,13 +50,13 @@ copy(register s_char *s1, register s_char *s2)
void
bzero(s_char *ptr, int len)
{
memset(ptr, 0, len);
memset(ptr, 0, len);
}
void
bcopy(s_char *src, s_char *dst, int len)
{
memcpy(dst, src, len);
memcpy(dst, src, len);
}
#endif
@ -68,16 +67,16 @@ bcopy(s_char *src, s_char *dst, int len)
void
blankfill(s_char *ptr, register struct range *range, int size)
{
register s_char *p;
register int row;
register int col;
register s_char *p;
register int row;
register int col;
for (row=0; row<range->height; row++) {
col = (range->width + 1) * (size + 1) / 2 - 1;
p = ptr;
while (--col >= 0)
*p++ = ' ';
*p++ = 0;
ptr += MAPWIDTH(size);
}
for (row = 0; row < range->height; row++) {
col = (range->width + 1) * (size + 1) / 2 - 1;
p = ptr;
while (--col >= 0)
*p++ = ' ';
*p++ = 0;
ptr += MAPWIDTH(size);
}
}

View file

@ -41,7 +41,7 @@
#include <sys/types.h>
#if !defined(_WIN32)
#include <sys/ioctl.h>
#include <unistd.h> /* fork close dup2 */
#include <unistd.h> /* fork close dup2 */
#endif
#include <fcntl.h>
#include "gen.h"
@ -50,23 +50,23 @@ void
disassoc(void)
{
#if !defined(_WIN32)
int i;
int i;
if (fork() != 0)
exit(0);
for (i = 0; i < 10; i++)
(void) close(i);
(void) open("/", O_RDONLY, 0);
(void) dup2(0, 1);
(void) dup2(0, 2);
if (fork() != 0)
exit(0);
for (i = 0; i < 10; i++)
(void)close(i);
(void)open("/", O_RDONLY, 0);
(void)dup2(0, 1);
(void)dup2(0, 2);
#if defined hpux || defined Rel4
setsid();
setsid();
#else
i = open("/dev/tty", O_RDWR, 0);
if (i > 0) {
(void) ioctl(i, TIOCNOTTY, 0);
(void) close(i);
}
i = open("/dev/tty", O_RDWR, 0);
if (i > 0) {
(void)ioctl(i, TIOCNOTTY, 0);
(void)close(i);
}
#endif
#endif
}

View file

@ -32,7 +32,7 @@
*/
#if !defined(_WIN32)
#include <unistd.h> /* getdtablesize */
#include <unistd.h> /* getdtablesize */
#endif
#include "gen.h"
@ -41,14 +41,14 @@ void
setfdtablesize(int min, int start)
{
#ifdef sequent
extern int errno;
extern int errno;
while (start >= min) {
if (setdtablesize(start) > 0)
break;
start -= 16;
}
errno = 0;
while (start >= min) {
if (setdtablesize(start) > 0)
break;
start -= 16;
}
errno = 0;
#endif
}
@ -56,10 +56,10 @@ int
getfdtablesize(void)
{
#if defined(_WIN32)
return (_NFILE);
return (_NFILE);
#elif defined(hpux)
return (int)sysconf(_SC_OPEN_MAX);
return (int)sysconf(_SC_OPEN_MAX);
#else
return getdtablesize();
return getdtablesize();
#endif
}

File diff suppressed because it is too large Load diff

View file

@ -37,14 +37,14 @@
s_char *
getstarg(s_char *input, s_char *prompt, s_char *buf)
{
extern s_char *getstring(s_char *prompt, s_char *buf);
extern s_char *getstring(s_char *prompt, s_char *buf);
*buf = '\0';
if (input == 0 || *input == 0) {
if (getstring(prompt, buf) == 0)
return 0;
} else {
strcpy(buf, input);
}
return buf;
*buf = '\0';
if (input == 0 || *input == 0) {
if (getstring(prompt, buf) == 0)
return 0;
} else {
strcpy(buf, input);
}
return buf;
}

View file

@ -38,8 +38,8 @@
s_char *
getstring(s_char *prompt, s_char *buf)
{
*buf = '\0';
if (prmptrd(prompt, buf, 1024) < 0)
return 0;
return buf;
*buf = '\0';
if (prmptrd(prompt, buf, 1024) < 0)
return 0;
return buf;
}

View file

@ -37,54 +37,54 @@
#include <stdio.h>
setbuffer(fp, buf, size)
FILE *fp;
s_char *buf;
int size;
FILE *fp;
s_char *buf;
int size;
{
if (size > BUFSIZ)
setbuf(fp, buf);
/* XXX else report error */
if (size > BUFSIZ)
setbuf(fp, buf);
/* XXX else report error */
}
s_char *
rindex(sp, c)
register s_char *sp;
register int c;
register s_char *sp;
register int c;
{
register s_char *r;
register s_char *r;
r = NULL;
do {
if (*sp == c)
r = sp;
} while (*sp++);
return r;
r = NULL;
do {
if (*sp == c)
r = sp;
} while (*sp++);
return r;
}
s_char *
index(sp, c)
register s_char *sp;
register int c;
register s_char *sp;
register int c;
{
do {
if (*sp == c)
return (sp);
} while (*sp++);
return NULL;
do {
if (*sp == c)
return (sp);
} while (*sp++);
return NULL;
}
int
ffs(marg)
register unsigned marg;
register unsigned marg;
{
register unsigned bval;
register int i;
register unsigned bval;
register int i;
if (marg == 0)
return 0;
for (bval=1, i=1; i <= 32; i++, bval <<= 1)
if (marg & bval)
return i;
if (marg == 0)
return 0;
for (bval = 1, i = 1; i <= 32; i++, bval <<= 1)
if (marg & bval)
return i;
return 0;
}
#endif

View file

@ -36,17 +36,17 @@
int
iceil(double arg)
{
register int i;
register int i;
i = arg;
return(i >= arg ? i : i + 1);
i = arg;
return (i >= arg ? i : i + 1);
}
int
ifloor(double arg)
{
register int i;
register int i;
i = arg;
return(i <= arg ? i : i - 1);
i = arg;
return (i <= arg ? i : i - 1);
}

View file

@ -35,7 +35,7 @@
#if !defined(_WIN32)
#include <netinet/in.h>
#endif
#include <stdio.h> /* sprintf */
#include <stdio.h> /* sprintf */
#include "misc.h"
#include "gen.h"
@ -43,11 +43,11 @@
s_char *
inet_ntoa(struct in_addr addr)
{
static s_char str[18];
register u_char *p;
static s_char str[18];
register u_char *p;
p = (u_char *)&addr;
sprintf(str, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
return str;
p = (u_char *)&addr;
sprintf(str, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
return str;
}
#endif /* NeXT */

View file

@ -44,12 +44,12 @@
#if !defined(_WIN32)
#include <sys/uio.h>
#include <sys/file.h>
#include <unistd.h> /* close read shutdown select */
#include <unistd.h> /* close read shutdown select */
#include <sys/socket.h>
#endif
#include <time.h>
#include <fcntl.h>
#include <stdlib.h> /* malloc calloc free */
#include <stdlib.h> /* malloc calloc free */
#if defined(_WIN32)
#include <winsock.h>
@ -61,475 +61,463 @@
#include "ioqueue.h"
#include "io_mask.h"
#include "empio.h"
#include "gen.h" /* getfdtablesize */
#include "gen.h" /* getfdtablesize */
#include "empthread.h"
extern struct player *player; /* XXX */
static struct iop **io_list;
static struct io_mask *iom;
static bit_fdmask newoutput;
static struct iop **io_list;
static struct io_mask *iom;
static bit_fdmask newoutput;
struct iop {
int fd;
struct ioqueue *input;
struct ioqueue *output;
int flags;
s_char *assoc;
int bufsize;
int (*notify)();
int fd;
struct ioqueue *input;
struct ioqueue *output;
int flags;
s_char *assoc;
int bufsize;
int (*notify) ();
};
extern int errno;
extern int errno;
void
io_init(void)
{
iom = iom_create(IO_READ|IO_WRITE);
io_list = (struct iop **) calloc(getfdtablesize(), sizeof(*io_list));
newoutput = bit_newfdmask();
iom = iom_create(IO_READ | IO_WRITE);
io_list = (struct iop **)calloc(getfdtablesize(), sizeof(*io_list));
newoutput = bit_newfdmask();
}
struct iop *
io_open(int fd, int flags, int bufsize, int (*notify) (void), s_char *assoc)
io_open(int fd, int flags, int bufsize, int (*notify) (void),
s_char *assoc)
{
struct iop *iop;
struct iop *iop;
if (io_list[fd] != 0) {
/* already exists */
return 0;
}
flags = flags & (IO_READ|IO_WRITE|IO_NBLOCK|IO_NEWSOCK);
if ((flags & (IO_READ|IO_WRITE)) == 0)
return 0;
iop = (struct iop *) malloc(sizeof(struct iop));
iop->fd = fd;
iop->input = 0;
iop->output = 0;
iop->flags = 0;
iop->bufsize = bufsize;
if ((flags & IO_READ) && (flags & IO_NEWSOCK) == 0)
iop->input = ioq_create(bufsize);
if ((flags & IO_WRITE) && (flags & IO_NEWSOCK) == 0)
iop->output = ioq_create(bufsize);
if (flags & IO_NBLOCK)
io_noblocking(iop, 1);
iop->flags = flags;
iop->assoc = assoc;
iop->notify = notify;
io_list[fd] = iop;
iom_set(iom, flags, fd);
return iop;
if (io_list[fd] != 0) {
/* already exists */
return 0;
}
flags = flags & (IO_READ | IO_WRITE | IO_NBLOCK | IO_NEWSOCK);
if ((flags & (IO_READ | IO_WRITE)) == 0)
return 0;
iop = (struct iop *)malloc(sizeof(struct iop));
iop->fd = fd;
iop->input = 0;
iop->output = 0;
iop->flags = 0;
iop->bufsize = bufsize;
if ((flags & IO_READ) && (flags & IO_NEWSOCK) == 0)
iop->input = ioq_create(bufsize);
if ((flags & IO_WRITE) && (flags & IO_NEWSOCK) == 0)
iop->output = ioq_create(bufsize);
if (flags & IO_NBLOCK)
io_noblocking(iop, 1);
iop->flags = flags;
iop->assoc = assoc;
iop->notify = notify;
io_list[fd] = iop;
iom_set(iom, flags, fd);
return iop;
}
void
io_close(struct iop *iop)
{
if (iop->input != 0)
ioq_destroy(iop->input);
if (iop->output != 0)
ioq_destroy(iop->output);
iom_clear(iom, iop->flags, iop->fd);
BIT_CLRB(iop->fd, newoutput);
io_list[iop->fd] = 0;
if (iop->input != 0)
ioq_destroy(iop->input);
if (iop->output != 0)
ioq_destroy(iop->output);
iom_clear(iom, iop->flags, iop->fd);
BIT_CLRB(iop->fd, newoutput);
io_list[iop->fd] = 0;
#if !defined(_WIN32)
(void) close(iop->fd);
(void)close(iop->fd);
#else
closesocket(iop->fd);
#endif
free((s_char *)iop);
free((s_char *)iop);
}
int
io_input(struct iop *iop, int waitforinput)
{
s_char buf[IO_BUFSIZE];
int cc;
s_char buf[IO_BUFSIZE];
int cc;
/* Not a read IOP */
if ((iop->flags & IO_READ) == 0)
return -1;
if ((iop->flags & IO_READ) == 0)
return -1;
/* IOP is markes as in error. */
if (iop->flags & IO_ERROR)
return -1;
if (iop->flags & IO_ERROR)
return -1;
/* Wait for the file to have input. */
if (waitforinput) {
empth_select(iop->fd, EMPTH_FD_READ);
}
if (waitforinput) {
empth_select(iop->fd, EMPTH_FD_READ);
}
#if !defined(_WIN32)
/* Do the actual read. */
cc = read(iop->fd, buf, sizeof(buf));
if (cc < 0) {
/* would block, so nothing to read. */
if (errno == EWOULDBLOCK)
return 0;
cc = read(iop->fd, buf, sizeof(buf));
if (cc < 0) {
/* would block, so nothing to read. */
if (errno == EWOULDBLOCK)
return 0;
/* Some form of file error occurred... */
iop->flags |= IO_ERROR;
iom_clear(iom, IO_READ, iop->fd);
return -1;
}
/* Some form of file error occurred... */
iop->flags |= IO_ERROR;
iom_clear(iom, IO_READ, iop->fd);
return -1;
}
#else
cc = recv(iop->fd, buf, sizeof(buf), 0);
if (cc == SOCKET_ERROR) {
int err = WSAGetLastError();
/* Hmm, it would block. file is opened noblock, soooooo.. */
if (err == WSAEWOULDBLOCK)
return 0;
int err = WSAGetLastError();
/* Hmm, it would block. file is opened noblock, soooooo.. */
if (err == WSAEWOULDBLOCK)
return 0;
/* Some form of file error occurred... */
iop->flags |= IO_ERROR;
iom_clear(iom, IO_READ, iop->fd);
return -1;
/* Some form of file error occurred... */
iop->flags |= IO_ERROR;
iom_clear(iom, IO_READ, iop->fd);
return -1;
}
#endif
/* We eof'd */
if (cc == 0) {
iop->flags |= IO_EOF;
return 0;
}
if (cc == 0) {
iop->flags |= IO_EOF;
return 0;
}
/* Append the input to the IOQ. */
ioq_append(iop->input, buf, cc);
return cc;
ioq_append(iop->input, buf, cc);
return cc;
}
int
io_inputwaiting(struct iop *iop)
{
return ioq_qsize(iop->input);
return ioq_qsize(iop->input);
}
int
io_outputwaiting(struct iop *iop)
{
return ioq_qsize(iop->output);
return ioq_qsize(iop->output);
}
int
io_output(struct iop *iop, int waitforoutput)
{
#if !defined(_WIN32)
struct iovec iov[16];
struct iovec iov[16];
#else
s_char buf[IO_BUFSIZE];
s_char buf[IO_BUFSIZE];
#endif
int cc;
int n;
int remain;
int cc;
int n;
int remain;
/* If there is no output waiting. */
if (!io_outputwaiting(iop))
return 0;
if (!io_outputwaiting(iop))
return 0;
/* bit clear */
BIT_CLRB(iop->fd, newoutput);
BIT_CLRB(iop->fd, newoutput);
/* If the iop is not write enabled. */
if ((iop->flags & IO_WRITE) == 0)
return -1;
if ((iop->flags & IO_WRITE) == 0)
return -1;
/* If the io is marked as in error... */
if (iop->flags & IO_ERROR)
return -1;
if (iop->flags & IO_ERROR)
return -1;
/* This is the same test as io_outputwaiting.... */
if (ioq_qsize(iop->output) == 0)
return 0;
if (ioq_qsize(iop->output) == 0)
return 0;
#if !defined(_WIN32)
/* make the iov point to the data in the queue. */
/* I.E., each of the elements in the queue. */
/* returns the number of elements in the iov. */
n = ioq_makeiov(iop->output, iov, IO_BUFSIZE);
n = ioq_makeiov(iop->output, iov, IO_BUFSIZE);
#else
/* Make a buffer containing the output to write. */
n = ioq_makebuf(iop->output, buf, sizeof(buf));
n = ioq_makebuf(iop->output, buf, sizeof(buf));
#endif
if (n <= 0) {
/* If we got no elements, we have no output.... */
iom_clear(iom, IO_WRITE, iop->fd);
return 0;
}
if (n <= 0) {
/* If we got no elements, we have no output.... */
iom_clear(iom, IO_WRITE, iop->fd);
return 0;
}
/* wait for the file to be output ready. */
if (waitforoutput != IO_NOWAIT) {
/* This waits for the file to be ready for writing, */
/* and lets other threads run. */
empth_select(iop->fd, EMPTH_FD_WRITE);
}
if (waitforoutput != IO_NOWAIT) {
/* This waits for the file to be ready for writing, */
/* and lets other threads run. */
empth_select(iop->fd, EMPTH_FD_WRITE);
}
/* Do the actual write. */
#if !defined(_WIN32)
cc = writev(iop->fd, iov, n);
cc = writev(iop->fd, iov, n);
/* if it failed.... */
if (cc < 0) {
/* Hmm, it would block. file is opened noblock, soooooo.. */
if (errno == EWOULDBLOCK) {
/* If there are remaining bytes, set the IO as remaining.. */
remain = ioq_qsize(iop->output);
if (remain > 0)
iom_set(iom, IO_WRITE, iop->fd);
return remain;
}
iop->flags |= IO_ERROR;
iom_clear(iom, IO_WRITE, iop->fd);
return -1;
if (cc < 0) {
/* Hmm, it would block. file is opened noblock, soooooo.. */
if (errno == EWOULDBLOCK) {
/* If there are remaining bytes, set the IO as remaining.. */
remain = ioq_qsize(iop->output);
if (remain > 0)
iom_set(iom, IO_WRITE, iop->fd);
return remain;
}
iop->flags |= IO_ERROR;
iom_clear(iom, IO_WRITE, iop->fd);
return -1;
}
#else
cc = send(iop->fd, buf, n, 0);
cc = send(iop->fd, buf, n, 0);
/* if it failed.... */
if (cc == SOCKET_ERROR) {
int err = WSAGetLastError();
/* Hmm, it would block. file is opened noblock, soooooo.. */
if (err == WSAEWOULDBLOCK) {
/* If there are remaining bytes, set the IO as remaining.. */
remain = ioq_qsize(iop->output);
if (remain > 0)
iom_set(iom, IO_WRITE, iop->fd);
return remain;
}
iop->flags |= IO_ERROR;
iom_clear(iom, IO_WRITE, iop->fd);
return -1;
if (cc == SOCKET_ERROR) {
int err = WSAGetLastError();
/* Hmm, it would block. file is opened noblock, soooooo.. */
if (err == WSAEWOULDBLOCK) {
/* If there are remaining bytes, set the IO as remaining.. */
remain = ioq_qsize(iop->output);
if (remain > 0)
iom_set(iom, IO_WRITE, iop->fd);
return remain;
}
iop->flags |= IO_ERROR;
iom_clear(iom, IO_WRITE, iop->fd);
return -1;
}
#endif
/* If no bytes were written, something happened.. Like an EOF. */
#ifndef hpux
if (cc == 0) {
iop->flags |= IO_EOF;
return 0;
}
if (cc == 0) {
iop->flags |= IO_EOF;
return 0;
}
#else
if (cc == 0) {
remain = ioq_qsize(iop->output);
if (remain > 0)
iom_set(iom, IO_WRITE, iop->fd);
return remain;
}
#endif /* hpux */
if (cc == 0) {
remain = ioq_qsize(iop->output);
if (remain > 0)
iom_set(iom, IO_WRITE, iop->fd);
return remain;
}
#endif /* hpux */
/* Remove the number of written bytes from the queue. */
ioq_dequeue(iop->output, cc);
ioq_dequeue(iop->output, cc);
/* If the queue has stuff remaining, set it still needing output. */
remain = ioq_qsize(iop->output);
if (remain == 0) {
iom_clear(iom, IO_WRITE, iop->fd);
} else {
iom_set(iom, IO_WRITE, iop->fd);
}
return cc;
remain = ioq_qsize(iop->output);
if (remain == 0) {
iom_clear(iom, IO_WRITE, iop->fd);
} else {
iom_set(iom, IO_WRITE, iop->fd);
}
return cc;
}
int
io_select(struct timeval *tv)
{
bit_fdmask readmask;
bit_fdmask writemask;
int n;
int nfds;
int fd;
struct iop *iop;
bit_fdmask readmask;
bit_fdmask writemask;
int n;
int nfds;
int fd;
struct iop *iop;
iom_getmask(iom, &nfds, &readmask, &writemask);
n = select(nfds + 1, (fd_set *)readmask, (fd_set *)writemask, 0, tv);
if (n <= 0) {
if (errno == EINTR)
return 0;
return -1;
}
while ((fd = bit_fd(readmask)) >= 0) {
iop = io_list[fd];
if ((iop->flags & IO_NEWSOCK) == 0)
(void) io_input(iop, IO_NOWAIT);
if (iop->notify != 0)
iop->notify(iop, IO_READ, iop->assoc);
BIT_CLRB(fd, readmask);
}
while ((fd = bit_fd(writemask)) >= 0) {
iop = io_list[fd];
if (io_output(iop, IO_NOWAIT) < 0 && iop->notify != 0)
iop->notify(iop, IO_WRITE, iop->assoc);
BIT_CLRB(fd, writemask);
}
return n;
iom_getmask(iom, &nfds, &readmask, &writemask);
n = select(nfds + 1, (fd_set *) readmask, (fd_set *) writemask, 0, tv);
if (n <= 0) {
if (errno == EINTR)
return 0;
return -1;
}
while ((fd = bit_fd(readmask)) >= 0) {
iop = io_list[fd];
if ((iop->flags & IO_NEWSOCK) == 0)
(void)io_input(iop, IO_NOWAIT);
if (iop->notify != 0)
iop->notify(iop, IO_READ, iop->assoc);
BIT_CLRB(fd, readmask);
}
while ((fd = bit_fd(writemask)) >= 0) {
iop = io_list[fd];
if (io_output(iop, IO_NOWAIT) < 0 && iop->notify != 0)
iop->notify(iop, IO_WRITE, iop->assoc);
BIT_CLRB(fd, writemask);
}
return n;
}
void
io_flush(int doWait)
{
int fd;
struct iop *iop;
int fd;
struct iop *iop;
while ((fd = bit_fd(newoutput)) >= 0) {
iop = io_list[fd];
if (io_output(iop, doWait) < 0 && iop->notify != 0)
iop->notify(iop, IO_WRITE, iop->assoc);
}
while ((fd = bit_fd(newoutput)) >= 0) {
iop = io_list[fd];
if (io_output(iop, doWait) < 0 && iop->notify != 0)
iop->notify(iop, IO_WRITE, iop->assoc);
}
}
int
io_peek(struct iop *iop, s_char *buf, int nbytes)
{
if ((iop->flags & IO_READ) == 0)
return -1;
return ioq_peek(iop->input, buf, nbytes);
if ((iop->flags & IO_READ) == 0)
return -1;
return ioq_peek(iop->input, buf, nbytes);
}
int
io_read(struct iop *iop, s_char *buf, int nbytes)
{
int cc;
int cc;
if ((iop->flags & IO_READ) == 0)
return -1;
cc = ioq_peek(iop->input, buf, nbytes);
if (cc > 0)
ioq_dequeue(iop->input, cc);
return cc;
if ((iop->flags & IO_READ) == 0)
return -1;
cc = ioq_peek(iop->input, buf, nbytes);
if (cc > 0)
ioq_dequeue(iop->input, cc);
return cc;
}
int
io_write(struct iop *iop, s_char *buf, int nbytes, int doWait)
{
int len;
int len;
if ((iop->flags & IO_WRITE) == 0)
return -1;
ioq_append(iop->output, buf, nbytes);
BIT_SETB(iop->fd, newoutput);
len = ioq_qsize(iop->output);
if (len > iop->bufsize) {
if (doWait) {
io_output_all(iop);
} else {
/* only try a write every BUFSIZE characters */
if (((len-nbytes) % iop->bufsize) <
(len % iop->bufsize))
io_output(iop, 0);
}
if ((iop->flags & IO_WRITE) == 0)
return -1;
ioq_append(iop->output, buf, nbytes);
BIT_SETB(iop->fd, newoutput);
len = ioq_qsize(iop->output);
if (len > iop->bufsize) {
if (doWait) {
io_output_all(iop);
} else {
/* only try a write every BUFSIZE characters */
if (((len - nbytes) % iop->bufsize) < (len % iop->bufsize))
io_output(iop, 0);
}
return nbytes;
}
return nbytes;
}
int
io_output_all(struct iop *iop)
{
int n;
int n;
while ((n = io_output(iop, IO_NOWAIT)) > 0) {
empth_select(iop->fd, EMPTH_FD_WRITE);
}
return n;
while ((n = io_output(iop, IO_NOWAIT)) > 0) {
empth_select(iop->fd, EMPTH_FD_WRITE);
}
return n;
}
int
io_gets(struct iop *iop, s_char *buf, int nbytes)
{
if ((iop->flags & IO_READ) == 0)
return -1;
return ioq_gets(iop->input, buf, nbytes);
if ((iop->flags & IO_READ) == 0)
return -1;
return ioq_gets(iop->input, buf, nbytes);
}
int
io_puts(struct iop *iop, s_char *buf)
{
if ((iop->flags & IO_WRITE) == 0)
return -1;
BIT_SETB(iop->fd, newoutput);
return ioq_puts(iop->output, buf);
if ((iop->flags & IO_WRITE) == 0)
return -1;
BIT_SETB(iop->fd, newoutput);
return ioq_puts(iop->output, buf);
}
int
io_shutdown(struct iop *iop, int flags)
{
flags &= (IO_READ|IO_WRITE);
if ((iop->flags & flags) != flags)
return -1;
if (flags & IO_READ) {
shutdown(iop->fd, 0);
ioq_drain(iop->input);
}
if (flags & IO_WRITE) {
shutdown(iop->fd, 1);
ioq_drain(iop->output);
}
return 0;
flags &= (IO_READ | IO_WRITE);
if ((iop->flags & flags) != flags)
return -1;
if (flags & IO_READ) {
shutdown(iop->fd, 0);
ioq_drain(iop->input);
}
if (flags & IO_WRITE) {
shutdown(iop->fd, 1);
ioq_drain(iop->output);
}
return 0;
}
int
io_noblocking(struct iop *iop, int value)
{
#if !defined(_WIN32)
int flags;
int flags;
flags = fcntl(iop->fd, F_GETFL, 0);
if (flags < 0)
return -1;
if (value == 0)
flags &= ~FNDELAY;
else
flags |= FNDELAY;
if (fcntl(iop->fd, F_SETFL, flags) < 0)
return -1;
flags = fcntl(iop->fd, F_GETFL, 0);
if (flags < 0)
return -1;
if (value == 0)
flags &= ~FNDELAY;
else
flags |= FNDELAY;
if (fcntl(iop->fd, F_SETFL, flags) < 0)
return -1;
#else
u_long arg = value;
ioctlsocket(iop->fd, FIONBIO, &arg);
#endif
if (value == 0)
iop->flags &= ~IO_NBLOCK;
else
iop->flags |= IO_NBLOCK;
return 0;
if (value == 0)
iop->flags &= ~IO_NBLOCK;
else
iop->flags |= IO_NBLOCK;
return 0;
}
int
io_conn(struct iop *iop)
{
return (iop->flags & IO_CONN);
return (iop->flags & IO_CONN);
}
int
io_error(struct iop *iop)
{
return (iop->flags & IO_ERROR);
return (iop->flags & IO_ERROR);
}
int
io_eof(struct iop *iop)
{
return (iop->flags & IO_EOF);
return (iop->flags & IO_EOF);
}
int
io_fileno(struct iop *iop)
{
return iop->fd;
return iop->fd;
}
struct iop *
io_iopfromfd(int fd)
{
return io_list[fd];
return io_list[fd];
}

View file

@ -31,83 +31,84 @@
*
*/
#include <stdlib.h> /* malloc */
#include <stdlib.h> /* malloc */
#include <errno.h>
#include "misc.h"
#include "bit.h"
#include "empio.h"
#include "io_mask.h"
extern int errno;
extern int errno;
struct io_mask *
iom_create(int what)
{
struct io_mask *imp;
struct io_mask *imp;
imp = (struct io_mask *) malloc(sizeof(*imp));
if (what & IO_READ) {
imp->readmask = bit_newfdmask();
imp->user_readmask = bit_newfdmask();
} else {
imp->readmask = 0;
imp->user_readmask = 0;
}
if (what & IO_WRITE) {
imp->writemask = bit_newfdmask();
imp->user_writemask = bit_newfdmask();
} else {
imp->writemask = 0;
imp->user_writemask = 0;
}
imp->what = what;
imp->maxfd = 0;
return imp;
imp = (struct io_mask *)malloc(sizeof(*imp));
if (what & IO_READ) {
imp->readmask = bit_newfdmask();
imp->user_readmask = bit_newfdmask();
} else {
imp->readmask = 0;
imp->user_readmask = 0;
}
if (what & IO_WRITE) {
imp->writemask = bit_newfdmask();
imp->user_writemask = bit_newfdmask();
} else {
imp->writemask = 0;
imp->user_writemask = 0;
}
imp->what = what;
imp->maxfd = 0;
return imp;
}
void
iom_getmask(struct io_mask *mask, int *nfdp, bit_fdmask *readp, bit_fdmask *writep)
iom_getmask(struct io_mask *mask, int *nfdp, bit_fdmask *readp,
bit_fdmask *writep)
{
if (mask->what & IO_READ)
bit_copy(mask->readmask, mask->user_readmask);
if (mask->what & IO_WRITE)
bit_copy(mask->writemask, mask->user_writemask);
*readp = mask->user_readmask;
*writep = mask->user_writemask;
*nfdp = mask->maxfd;
if (mask->what & IO_READ)
bit_copy(mask->readmask, mask->user_readmask);
if (mask->what & IO_WRITE)
bit_copy(mask->writemask, mask->user_writemask);
*readp = mask->user_readmask;
*writep = mask->user_writemask;
*nfdp = mask->maxfd;
}
void
iom_set(struct io_mask *mask, int what, int fd)
{
if ((mask->what & what) == 0)
return;
if (what & IO_READ)
BIT_SETB(fd, mask->readmask);
if (what & IO_WRITE)
BIT_SETB(fd, mask->writemask);
if (fd > mask->maxfd)
mask->maxfd = fd;
if ((mask->what & what) == 0)
return;
if (what & IO_READ)
BIT_SETB(fd, mask->readmask);
if (what & IO_WRITE)
BIT_SETB(fd, mask->writemask);
if (fd > mask->maxfd)
mask->maxfd = fd;
}
void
iom_clear(struct io_mask *mask, int what, int fd)
{
if ((mask->what & what) == 0)
return;
if (what & IO_READ)
BIT_CLRB(fd, mask->readmask);
if (what & IO_WRITE)
BIT_CLRB(fd, mask->writemask);
if ((mask->what & what) == 0)
return;
if (what & IO_READ)
BIT_CLRB(fd, mask->readmask);
if (what & IO_WRITE)
BIT_CLRB(fd, mask->writemask);
}
void
iom_zero(struct io_mask *mask, int what)
{
if ((mask->what & what) == 0)
return;
if (what & IO_READ)
bit_zero(mask->readmask);
if (what & IO_WRITE)
bit_zero(mask->writemask);
if ((mask->what & what) == 0)
return;
if (what & IO_READ)
bit_zero(mask->readmask);
if (what & IO_WRITE)
bit_zero(mask->writemask);
}

View file

@ -38,7 +38,7 @@
*/
#include <stdio.h>
#include <stdlib.h> /* malloc free */
#include <stdlib.h> /* malloc free */
#include <sys/types.h>
#if !defined(_WIN32)
#include <sys/uio.h>
@ -47,9 +47,11 @@
#include "queue.h"
#include "ioqueue.h"
static int ioqtocbuf(struct ioqueue *ioq, s_char *buf, int cc, register int stopc);
static int ioqtocbuf(struct ioqueue *ioq, s_char *buf, int cc,
register int stopc);
#if !defined(_WIN32)
static int ioqtoiov(struct ioqueue *ioq, struct iovec *iov, register int max);
static int ioqtoiov(struct ioqueue *ioq, struct iovec *iov,
register int max);
#endif
static int ioqtobuf(struct ioqueue *ioq, s_char *buf, int cc);
static int appendcc(struct ioqueue *ioq, s_char *buf, int cc);
@ -62,43 +64,43 @@ static void loc_StripDels(char *pBuf);
struct ioqueue *
ioq_create(int size)
{
struct ioqueue *ioq;
struct ioqueue *ioq;
ioq = (struct ioqueue *) malloc(sizeof(struct ioqueue));
emp_initque(&ioq->list.queue);
ioq->list.nbytes = 0;
ioq->list.offset = 0;
ioq->list.size = 0;
ioq->list.data = 0;
ioq->bufsize = size;
ioq->cc = 0;
return ioq;
ioq = (struct ioqueue *)malloc(sizeof(struct ioqueue));
emp_initque(&ioq->list.queue);
ioq->list.nbytes = 0;
ioq->list.offset = 0;
ioq->list.size = 0;
ioq->list.data = 0;
ioq->bufsize = size;
ioq->cc = 0;
return ioq;
}
void
ioq_destroy(struct ioqueue *ioq)
{
#if !defined(aix) && !defined(NeXT)
#if !defined(aix) && !defined(NeXT)
/* ioq_drain doesn't work under aix or NeXT... dunno why --ts */
ioq_drain(ioq);
ioq_drain(ioq);
#endif /* aix */
free((s_char *)ioq);
free((s_char *)ioq);
}
void
ioq_drain(struct ioqueue *ioq)
{
struct emp_qelem *qp;
struct io *io;
struct emp_qelem *qp;
struct io *io;
while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue){
io = (struct io *) qp;
(void) emp_remque(&io->queue);
(void) free((s_char *)io->data);
(void) free((s_char *)io);
}
ioq->cc = 0;
while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue) {
io = (struct io *)qp;
(void)emp_remque(&io->queue);
(void)free((s_char *)io->data);
(void)free((s_char *)io);
}
ioq->cc = 0;
}
/*
@ -110,9 +112,9 @@ ioq_drain(struct ioqueue *ioq)
int
ioq_makeiov(struct ioqueue *ioq, struct iovec *iov, int cc)
{
if (ioq->cc <= 0)
return 0;
return ioqtoiov(ioq, iov, cc);
if (ioq->cc <= 0)
return 0;
return ioqtoiov(ioq, iov, cc);
}
#endif
@ -124,25 +126,25 @@ ioq_makeiov(struct ioqueue *ioq, struct iovec *iov, int cc)
int
ioq_peek(struct ioqueue *ioq, s_char *buf, int cc)
{
return ioqtobuf(ioq, buf, cc);
return ioqtobuf(ioq, buf, cc);
}
int
ioq_dequeue(struct ioqueue *ioq, int cc)
{
return removecc(ioq, cc);
return removecc(ioq, cc);
}
void
ioq_append(struct ioqueue *ioq, s_char *buf, int cc)
{
appendcc(ioq, buf, cc);
appendcc(ioq, buf, cc);
}
int
ioq_qsize(struct ioqueue *ioq)
{
return ioq->cc;
return ioq->cc;
}
/*
@ -153,28 +155,28 @@ ioq_qsize(struct ioqueue *ioq)
int
ioq_gets(struct ioqueue *ioq, s_char *buf, int cc)
{
int nbytes;
int actual;
int nbytes;
int actual;
nbytes = ioqtocbuf(ioq, buf, cc - 1, '\n');
if (nbytes >= 0) {
actual = nbytes;
if (actual > cc - 1)
actual = cc - 1;
buf[actual] = '\0';
/* remove the newline too */
removecc(ioq, nbytes + 1);
nbytes = ioqtocbuf(ioq, buf, cc - 1, '\n');
if (nbytes >= 0) {
actual = nbytes;
if (actual > cc - 1)
actual = cc - 1;
buf[actual] = '\0';
/* remove the newline too */
removecc(ioq, nbytes + 1);
#if defined(_WIN32)
loc_StripDels(buf);
loc_StripDels(buf);
#endif
}
return nbytes;
}
return nbytes;
}
int
ioq_puts(struct ioqueue *ioq, s_char *buf)
{
return appendcc(ioq, buf, strlen(buf));
return appendcc(ioq, buf, strlen(buf));
}
/*
@ -188,34 +190,34 @@ ioq_puts(struct ioqueue *ioq, s_char *buf)
* left for a higher level.
*/
static
int
int
ioqtobuf(struct ioqueue *ioq, s_char *buf, int cc)
{
struct io *io;
struct emp_qelem *qp;
struct emp_qelem *head;
register int nbytes;
register int nleft;
register s_char *offset;
struct io *io;
struct emp_qelem *qp;
struct emp_qelem *head;
register int nbytes;
register int nleft;
register s_char *offset;
nleft = cc;
offset = buf;
head = &ioq->list.queue;
for (qp = head->q_forw; qp != head && nleft > 0; qp = qp->q_forw) {
io = (struct io *) qp;
if ((nbytes = io->nbytes - io->offset) < 0) {
/* XXX log something here */
continue;
}
if (nbytes > 0) {
if (nleft < nbytes)
nbytes = nleft;
bcopy(io->data + io->offset, offset, nbytes);
offset += nbytes;
nleft -= nbytes;
}
nleft = cc;
offset = buf;
head = &ioq->list.queue;
for (qp = head->q_forw; qp != head && nleft > 0; qp = qp->q_forw) {
io = (struct io *)qp;
if ((nbytes = io->nbytes - io->offset) < 0) {
/* XXX log something here */
continue;
}
return offset - buf;
if (nbytes > 0) {
if (nleft < nbytes)
nbytes = nleft;
bcopy(io->data + io->offset, offset, nbytes);
offset += nbytes;
nleft -= nbytes;
}
}
return offset - buf;
}
/*
@ -223,38 +225,37 @@ ioqtobuf(struct ioqueue *ioq, s_char *buf, int cc)
* terminating on the stop character.
*/
static
int
int
ioqtocbuf(struct ioqueue *ioq, s_char *buf, int cc, register int stopc)
{
register int nbytes;
register s_char *p;
register int n;
struct io *io;
struct emp_qelem *qp;
struct emp_qelem *head;
int total;
int found;
register int nbytes;
register s_char *p;
register int n;
struct io *io;
struct emp_qelem *qp;
struct emp_qelem *head;
int total;
int found;
head = &ioq->list.queue;
found = 0;
total = 0;
for (qp = head->q_forw; qp != head; qp = qp->q_forw) {
io = (struct io *) qp;
if ((nbytes = io->nbytes - io->offset) <= 0)
continue;
p = io->data + io->offset;
for (n=0; n < nbytes && p[n] != stopc; n++)
;
total += n;
if (n < nbytes) {
found++;
break;
}
head = &ioq->list.queue;
found = 0;
total = 0;
for (qp = head->q_forw; qp != head; qp = qp->q_forw) {
io = (struct io *)qp;
if ((nbytes = io->nbytes - io->offset) <= 0)
continue;
p = io->data + io->offset;
for (n = 0; n < nbytes && p[n] != stopc; n++) ;
total += n;
if (n < nbytes) {
found++;
break;
}
if (found == 0)
return -1;
ioqtobuf(ioq, buf, cc < total ? cc : total);
return total;
}
if (found == 0)
return -1;
ioqtobuf(ioq, buf, cc < total ? cc : total);
return total;
}
/*
@ -263,33 +264,33 @@ ioqtocbuf(struct ioqueue *ioq, s_char *buf, int cc, register int stopc)
*/
#if !defined(_WIN32)
static
int
int
ioqtoiov(struct ioqueue *ioq, struct iovec *iov, register int max)
{
struct io *io;
register int cc;
register int niov;
register int len;
struct emp_qelem *qp;
struct io *io;
register int cc;
register int niov;
register int len;
struct emp_qelem *qp;
cc = max;
niov = 0;
qp = ioq->list.queue.q_forw;
while (qp != &ioq->list.queue && cc > 0) {
io = (struct io *) qp;
len = io->nbytes - io->offset;
if (len > cc)
len = cc;
iov->iov_base = io->data + io->offset;
iov->iov_len = len;
cc -= len;
niov++;
iov++;
qp = qp->q_forw;
if (niov >= 16)
break;
}
return niov;
cc = max;
niov = 0;
qp = ioq->list.queue.q_forw;
while (qp != &ioq->list.queue && cc > 0) {
io = (struct io *)qp;
len = io->nbytes - io->offset;
if (len > cc)
len = cc;
iov->iov_base = io->data + io->offset;
iov->iov_len = len;
cc -= len;
niov++;
iov++;
qp = qp->q_forw;
if (niov >= 16)
break;
}
return niov;
}
#endif
@ -297,39 +298,39 @@ ioqtoiov(struct ioqueue *ioq, struct iovec *iov, register int max)
* append a buffer to the end of the ioq.
*/
static
int
int
appendcc(struct ioqueue *ioq, s_char *buf, int cc)
{
struct io *io;
int len;
s_char *ptr;
int avail;
struct io *io;
int len;
s_char *ptr;
int avail;
/* determine if any space is left */
io = (struct io *)ioq->list.queue.q_back;
avail = io->size - io->nbytes;
if (avail > 0) {
/* append to existing buffer */
len = cc > avail ? avail : cc;
bcopy(buf, io->data + io->nbytes, len);
io->nbytes += len;
ioq->cc += len;
if (avail < cc)
appendcc(ioq, buf + len, cc - len);
} else {
/* create a new buffer, minimum bufsize bytes */
len = cc > ioq->bufsize ? cc : ioq->bufsize;
ptr = malloc(len);
bcopy(buf, ptr, cc);
io = (struct io *) malloc(sizeof(struct io));
io->nbytes = cc;
io->size = len;
io->offset = 0;
io->data = ptr;
emp_insque(&io->queue, ioq->list.queue.q_back);
ioq->cc += cc;
}
return cc;
/* determine if any space is left */
io = (struct io *)ioq->list.queue.q_back;
avail = io->size - io->nbytes;
if (avail > 0) {
/* append to existing buffer */
len = cc > avail ? avail : cc;
bcopy(buf, io->data + io->nbytes, len);
io->nbytes += len;
ioq->cc += len;
if (avail < cc)
appendcc(ioq, buf + len, cc - len);
} else {
/* create a new buffer, minimum bufsize bytes */
len = cc > ioq->bufsize ? cc : ioq->bufsize;
ptr = malloc(len);
bcopy(buf, ptr, cc);
io = (struct io *)malloc(sizeof(struct io));
io->nbytes = cc;
io->size = len;
io->offset = 0;
io->data = ptr;
emp_insque(&io->queue, ioq->list.queue.q_back);
ioq->cc += cc;
}
return cc;
}
/*
@ -338,45 +339,46 @@ appendcc(struct ioqueue *ioq, s_char *buf, int cc)
* which are no longer used.
*/
static
int
int
removecc(struct ioqueue *ioq, register int cc)
{
struct io *io;
struct emp_qelem *qp;
register int nbytes;
register int there;
register int remain;
struct io *io;
struct emp_qelem *qp;
register int nbytes;
register int there;
register int remain;
nbytes = 0;
remain = cc;
while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue) {
io = (struct io *) qp;
there = io->nbytes - io->offset;
if (there < 0) {
/* error */
(void) emp_remque(&io->queue);
(void) free((s_char *)io);
continue;
}
if (remain >= there) {
/* not enough or exact; free entry */
nbytes += there;
remain -= there;
(void) emp_remque(&io->queue);
(void) free(io->data);
(void) free((s_char *)io);
} else {
/* too much; increment offset */
io->offset += remain;
nbytes += remain;
remain = 0;
}
if (remain <= 0)
break;
nbytes = 0;
remain = cc;
while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue) {
io = (struct io *)qp;
there = io->nbytes - io->offset;
if (there < 0) {
/* error */
(void)emp_remque(&io->queue);
(void)free((s_char *)io);
continue;
}
ioq->cc -= nbytes;
return nbytes;
if (remain >= there) {
/* not enough or exact; free entry */
nbytes += there;
remain -= there;
(void)emp_remque(&io->queue);
(void)free(io->data);
(void)free((s_char *)io);
} else {
/* too much; increment offset */
io->offset += remain;
nbytes += remain;
remain = 0;
}
if (remain <= 0)
break;
}
ioq->cc -= nbytes;
return nbytes;
}
#if defined(_WIN32)
/*
* Make an (output) buffer up to the
@ -387,39 +389,37 @@ removecc(struct ioqueue *ioq, register int cc)
int
ioq_makebuf(struct ioqueue *ioq, char *pBuf, int nBufLen)
{
struct io *io;
struct emp_qelem *qp;
struct emp_qelem *head;
int nbytes;
int nleft;
struct io *io;
struct emp_qelem *qp;
struct emp_qelem *head;
int nbytes;
int nleft;
int ncopied;
s_char *offset;
s_char *offset;
ncopied = 0;
nleft = nBufLen;
offset = pBuf;
head = &ioq->list.queue;
nleft = nBufLen;
offset = pBuf;
head = &ioq->list.queue;
for (qp = head->q_forw;
(qp != head) && (nleft > 0);
qp = qp->q_forw) {
io = (struct io *) qp;
nbytes = io->nbytes - io->offset;
if (nbytes < 0) {
/* Paranoid check for bad buffer. */
continue;
}
/* too many bytes, wait till next time. */
if (nbytes > nleft)
break;
bcopy(io->data + io->offset, offset, nbytes);
offset += nbytes;
nleft -= nbytes;
ncopied += nbytes;
for (qp = head->q_forw; (qp != head) && (nleft > 0); qp = qp->q_forw) {
io = (struct io *)qp;
nbytes = io->nbytes - io->offset;
if (nbytes < 0) {
/* Paranoid check for bad buffer. */
continue;
}
return ncopied;
/* too many bytes, wait till next time. */
if (nbytes > nleft)
break;
bcopy(io->data + io->offset, offset, nbytes);
offset += nbytes;
nleft -= nbytes;
ncopied += nbytes;
}
return ncopied;
}
#endif /* _WIN32 */
@ -438,19 +438,18 @@ loc_StripDels(char *pBuf)
char *sp;
for (cp = pBuf; *cp;) {
/* Remove Backspace and DEL */
if (*cp == '\b' || *cp == '\x8F') {
if (cp == pBuf)
dp = cp;
else
dp = cp - 1;
sp = cp + 1;
while (*sp)
*dp++ = *sp++;
*dp = 0;
} else
cp++;
/* Remove Backspace and DEL */
if (*cp == '\b' || *cp == '\x8F') {
if (cp == pBuf)
dp = cp;
else
dp = cp - 1;
sp = cp + 1;
while (*sp)
*dp++ = *sp++;
*dp = 0;
} else
cp++;
}
}
#endif

View file

@ -58,20 +58,20 @@ int
file_lock(int fd)
{
if (_locking(fd, _LK_LOCK, 0) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
return 1;
}
int
file_unlock(int fd)
{
if (_locking(fd, _LK_UNLCK, 0) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
return 1;
}
#else
@ -83,21 +83,21 @@ int flock();
int
file_lock(int fd)
{
if (flock(fd, LOCK_EX) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
if (flock(fd, LOCK_EX) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
}
int
file_unlock(int fd)
{
if (flock(fd, LOCK_UN) < 0) {
logerror("file unlock (fd %d) failed", fd);
return 0;
}
return 1;
if (flock(fd, LOCK_UN) < 0) {
logerror("file unlock (fd %d) failed", fd);
return 0;
}
return 1;
}
#else
@ -105,35 +105,35 @@ file_unlock(int fd)
int
file_lock(int fd)
{
struct flock lock;
struct flock lock;
lock.l_type = F_WRLCK;
lock.l_whence = L_SET;
lock.l_start = 0;
lock.l_len = 0;
lock.l_pid = 0;
if (fcntl(fd, F_SETLKW, &lock) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
lock.l_type = F_WRLCK;
lock.l_whence = L_SET;
lock.l_start = 0;
lock.l_len = 0;
lock.l_pid = 0;
if (fcntl(fd, F_SETLKW, &lock) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
}
int
file_unlock(int fd)
{
struct flock lock;
struct flock lock;
lock.l_type = F_UNLCK;
lock.l_whence = L_SET;
lock.l_start = 0;
lock.l_len = 0;
lock.l_pid = 0;
if (fcntl(fd, F_SETLKW, &lock) < 0) {
logerror("file unlock (fd %d) failed", fd);
return 0;
}
return 1;
lock.l_type = F_UNLCK;
lock.l_whence = L_SET;
lock.l_start = 0;
lock.l_len = 0;
lock.l_pid = 0;
if (fcntl(fd, F_SETLKW, &lock) < 0) {
logerror("file unlock (fd %d) failed", fd);
return 0;
}
return 1;
}
#endif

View file

@ -43,76 +43,76 @@
int
diffx(int x1, int x2)
{
int dx;
int dx;
dx = x1 - x2;
dx = dx % WORLD_X;
if (dx > WORLD_X/2)
dx = dx - WORLD_X;
if (dx < -WORLD_X/2)
dx = dx + WORLD_X;
return dx;
dx = x1 - x2;
dx = dx % WORLD_X;
if (dx > WORLD_X / 2)
dx = dx - WORLD_X;
if (dx < -WORLD_X / 2)
dx = dx + WORLD_X;
return dx;
}
int
diffy(int y1, int y2)
{
int dy;
int dy;
dy = y1 - y2;
dy = dy % WORLD_Y;
if (dy > WORLD_Y/2)
dy = dy - WORLD_Y;
if (dy < -WORLD_Y/2)
dy = dy + WORLD_Y;
return dy;
dy = y1 - y2;
dy = dy % WORLD_Y;
if (dy > WORLD_Y / 2)
dy = dy - WORLD_Y;
if (dy < -WORLD_Y / 2)
dy = dy + WORLD_Y;
return dy;
}
int
deltax(int x1, int x2)
{
int dx;
int dx;
dx = abs(x1 - x2);
dx = dx % WORLD_X;
if (dx > WORLD_X/2)
dx = WORLD_X - dx;
return dx;
dx = abs(x1 - x2);
dx = dx % WORLD_X;
if (dx > WORLD_X / 2)
dx = WORLD_X - dx;
return dx;
}
int
deltay(int y1, int y2)
{
int dy;
int dy;
dy = abs(y1 - y2);
dy = dy % WORLD_Y;
if (dy > WORLD_Y/2)
dy = WORLD_Y - dy;
return dy;
dy = abs(y1 - y2);
dy = dy % WORLD_Y;
if (dy > WORLD_Y / 2)
dy = WORLD_Y - dy;
return dy;
}
int
mapdist(int x1, int y1, int x2, int y2)
{
int dx, dy;
int dx, dy;
x1 = x1 % WORLD_X;
y1 = y1 % WORLD_Y;
x2 = x2 % WORLD_X;
y2 = y2 % WORLD_Y;
dx = deltax(x1, x2);
dy = deltay(y1, y2);
if (dx > dy)
return (dx - dy) / 2 + dy;
return dy;
x1 = x1 % WORLD_X;
y1 = y1 % WORLD_Y;
x2 = x2 % WORLD_X;
y2 = y2 % WORLD_Y;
dx = deltax(x1, x2);
dy = deltay(y1, y2);
if (dx > dy)
return (dx - dy) / 2 + dy;
return dy;
}
int
mapdsq(int x1, int y1, int x2, int y2)
{
int sq;
int sq;
sq = mapdist(x1, y1, x2, y2);
return sq * sq;
sq = mapdist(x1, y1, x2, y2);
return sq * sq;
}

View file

@ -37,35 +37,35 @@
double
dmax(double n1, double n2)
{
if (n1 > n2)
return n1;
return n2;
if (n1 > n2)
return n1;
return n2;
}
double
dmin(double n1, double n2)
{
if (n1 < n2)
return n1;
return n2;
if (n1 < n2)
return n1;
return n2;
}
#if !defined(_WIN32)
int
max(int n1, int n2)
{
if (n1 > n2)
return n1;
return n2;
if (n1 > n2)
return n1;
return n2;
}
int
min(int n1, int n2)
{
if (n1 < n2)
return n1;
return n2;
if (n1 < n2)
return n1;
return n2;
}
#endif

View file

@ -40,35 +40,35 @@
s_char *
numstr(s_char *buf, int n)
{
extern s_char *numnames[];
extern s_char *tennames[];
extern s_char *numnames[];
extern s_char *tennames[];
if (n > 100) {
(void) strcpy(buf, "several");
} else if (n < 0) {
(void) strcpy(buf, "a negative number of");
if (n > 100) {
(void)strcpy(buf, "several");
} else if (n < 0) {
(void)strcpy(buf, "a negative number of");
} else {
if (n >= 20) {
(void)strcpy(buf, tennames[n / 10]);
if (n % 10) {
(void)strcat(buf, "-");
(void)strcat(buf, numnames[n % 10]);
}
} else {
if (n >= 20) {
(void) strcpy(buf, tennames[n / 10]);
if (n % 10) {
(void) strcat(buf, "-");
(void) strcat(buf, numnames[n % 10]);
}
} else {
(void) strcpy(buf, numnames[n % 20]);
}
(void)strcpy(buf, numnames[n % 20]);
}
return buf;
}
return buf;
}
s_char *
effadv(int n)
{
extern s_char *effadv_list[];
extern s_char *effadv_list[];
if (n < 0)
n = 0;
if (n >= 100)
n = 99;
return effadv_list[n/25];
if (n < 0)
n = 0;
if (n >= 100)
n = 99;
return effadv_list[n / 25];
}

View file

@ -37,16 +37,16 @@
int
onearg(s_char *arg, s_char *prompt)
{
extern s_char *getstring(s_char *prompt, s_char *buf);
int n;
s_char buf[1024];
extern s_char *getstring(s_char *prompt, s_char *buf);
int n;
s_char buf[1024];
if (arg == 0 || *arg == 0) {
if ((arg = getstring(prompt, buf)) == 0)
return -1;
}
n = atoi(arg);
if (n < 0)
return -1;
return n;
if (arg == 0 || *arg == 0) {
if ((arg = getstring(prompt, buf)) == 0)
return -1;
}
n = atoi(arg);
if (n < 0)
return -1;
return n;
}

View file

@ -44,53 +44,54 @@
#include "gen.h"
int
parse(register s_char *buf, s_char **argpp, s_char **condp, s_char *space, s_char **redir)
parse(register s_char *buf, s_char **argpp, s_char **condp, s_char *space,
s_char **redir)
{
register s_char *bp2;
register s_char *bp1 = space;
register s_char **arg = argpp;
int fs;
int quoted;
int argnum;
register s_char *bp2;
register s_char *bp1 = space;
register s_char **arg = argpp;
int fs;
int quoted;
int argnum;
if (space == 0)
return -1;
if (redir)
*redir = 0;
if (condp != 0)
*condp = 0;
for (argnum=0; *buf && argnum < 100; ) {
arg[argnum] = bp1;
argnum++;
while (isspace(*buf))
buf++;
if (redir && (*buf == '>' || *buf == '|')) {
*redir = buf;
argnum--;
arg[argnum] = 0;
break;
}
quoted = 0;
for (bp2 = bp1; *buf; ) {
if (!quoted && isspace(*buf)) {
buf++;
break;
}
if (*buf == '"'){
quoted = !quoted;
buf++;
} else {
*bp1++ = *buf++;
}
}
*bp1++ = 0;
if (*bp2 == '?' && condp != 0) {
*condp = bp2 + 1;
argnum--;
}
if (space == 0)
return -1;
if (redir)
*redir = 0;
if (condp != 0)
*condp = 0;
for (argnum = 0; *buf && argnum < 100;) {
arg[argnum] = bp1;
argnum++;
while (isspace(*buf))
buf++;
if (redir && (*buf == '>' || *buf == '|')) {
*redir = buf;
argnum--;
arg[argnum] = 0;
break;
}
arg[argnum] = 0;
for (fs = argnum + 1; fs < 16; fs++)
arg[fs] = 0;
return argnum;
quoted = 0;
for (bp2 = bp1; *buf;) {
if (!quoted && isspace(*buf)) {
buf++;
break;
}
if (*buf == '"') {
quoted = !quoted;
buf++;
} else {
*bp1++ = *buf++;
}
}
*bp1++ = 0;
if (*bp2 == '?' && condp != 0) {
*condp = bp2 + 1;
argnum--;
}
}
arg[argnum] = 0;
for (fs = argnum + 1; fs < 16; fs++)
arg[fs] = 0;
return argnum;
}

View file

@ -37,23 +37,23 @@
s_char *
plur(int n, s_char *no, s_char *yes)
{
return (n == 1 ? no : yes);
return (n == 1 ? no : yes);
}
s_char *
splur(int n)
{
return (n == 1 ? "" : "s");
return (n == 1 ? "" : "s");
}
s_char *
esplur(int n)
{
return (n == 1 ? "" : "es");
return (n == 1 ? "" : "es");
}
s_char *
iesplur(int n)
{
return (n == 1 ? "y" : "ies");
return (n == 1 ? "y" : "ies");
}

View file

@ -36,30 +36,29 @@
void
emp_insque(struct emp_qelem *elem, struct emp_qelem *queue)
{
struct emp_qelem *next;
struct emp_qelem *next;
next = queue->q_forw;
queue->q_forw = elem;
elem->q_forw = next;
elem->q_back = queue;
next->q_back = elem;
next = queue->q_forw;
queue->q_forw = elem;
elem->q_forw = next;
elem->q_back = queue;
next->q_back = elem;
}
void
emp_remque(struct emp_qelem *elem)
{
if (elem == (struct emp_qelem *)0)
return;
if (elem->q_forw != (struct emp_qelem *)0)
elem->q_forw->q_back = elem->q_back;
if (elem->q_back != (struct emp_qelem *)0)
elem->q_back->q_forw = elem->q_forw;
if (elem == (struct emp_qelem *)0)
return;
if (elem->q_forw != (struct emp_qelem *)0)
elem->q_forw->q_back = elem->q_back;
if (elem->q_back != (struct emp_qelem *)0)
elem->q_back->q_forw = elem->q_forw;
}
void
emp_initque(struct emp_qelem *elem)
{
elem->q_forw = elem;
elem->q_back = elem;
elem->q_forw = elem;
elem->q_back = elem;
}

View file

@ -36,17 +36,17 @@
int
roundintby(int n, int m)
{
register int r11;
register int r11;
r11 = (m >> 1) + n;
return (r11 / m * m);
r11 = (m >> 1) + n;
return (r11 / m * m);
}
int
ldround(double a4, int ac)
{
int f4;
int f4;
f4 = ac / 2.0 + a4;
return (f4 / ac * ac);
f4 = ac / 2.0 + a4;
return (f4 / ac * ac);
}

View file

@ -37,9 +37,9 @@
int
same(register s_char *s1, register s_char *s2)
{
while (*s1 == *s2++) {
if (*s1++ == 0)
return 1;
}
return 0;
while (*s1 == *s2++) {
if (*s1++ == 0)
return 1;
}
return 0;
}

View file

@ -36,9 +36,9 @@
int
scthash(register int x, register int y, int tsize)
{
if (x < 0)
x = -x;
if (y < 0)
y = -y;
return ((x*10 + y) % tsize);
if (x < 0)
x = -x;
if (y < 0)
y = -y;
return ((x * 10 + y) % tsize);
}

View file

@ -36,13 +36,13 @@
#include "gen.h"
#include <signal.h>
u_int mask;
u_int mask;
void
blocksig(void)
{
#if !defined(_WIN32)
mask = sigsetmask(0xffffffff);
mask = sigsetmask(0xffffffff);
#endif
}
@ -50,43 +50,43 @@ void
unblocksig(void)
{
#if !defined(_WIN32)
sigsetmask(mask);
sigsetmask(mask);
#endif
}
#ifdef sys5
const s_char *sys_siglist[] = {
"no signal",
"interrupt",
"quit",
"illegal instruction",
"trace trap",
"IOT instruction",
"system crash imminent",
"floating point exception",
"kill",
"bus error",
"segmentation violation",
"bad argument to system call",
"write on a pipe with no one to read it",
"alarm clock",
"software termination",
"user defined signal 1",
"user defined signal 2",
"death of a child",
"power-fail restart",
"asychronous i/o",
"PTY read/write",
"I/O intervention required",
"monitor mode granted",
"monitor mode retracted",
"sound ack",
"data pending",
"no signal",
"interrupt",
"quit",
"illegal instruction",
"trace trap",
"IOT instruction",
"system crash imminent",
"floating point exception",
"kill",
"bus error",
"segmentation violation",
"bad argument to system call",
"write on a pipe with no one to read it",
"alarm clock",
"software termination",
"user defined signal 1",
"user defined signal 2",
"death of a child",
"power-fail restart",
"asychronous i/o",
"PTY read/write",
"I/O intervention required",
"monitor mode granted",
"monitor mode retracted",
"sound ack",
"data pending",
};
#else
#if (!defined __ppc__) && (!defined linux) && (!defined FBSD) && (!defined __linux__)
/* linux and osx declare sys_siglist in signal.h */
extern s_char *sys_siglist[];
extern s_char *sys_siglist[];
#endif /* linux */
#endif /* sys5 */
@ -94,12 +94,12 @@ const s_char *
signame(int sig)
{
#ifdef POSIX_SIGNALS
if (sig <= 0 || sig > _sys_nsig)
return "bad signal";
return _sys_siglist[sig];
#else /* POSIX_SIGNALS */
if (sig <= 0 || sig > NSIG)
return "bad signal";
return sys_siglist[sig];
if (sig <= 0 || sig > _sys_nsig)
return "bad signal";
return _sys_siglist[sig];
#else /* POSIX_SIGNALS */
if (sig <= 0 || sig > NSIG)
return "bad signal";
return sys_siglist[sig];
#endif /* POSIX_SIGNALS */
}

View file

@ -36,13 +36,13 @@
#include "gen.h"
#ifdef NOSTRDUP
char *strdup(char *x)
char *
strdup(char *x)
{
char *y;
char *y;
y=(char *)malloc((sizeof(char)*strlen(x))+1);
strcpy(y,x);
return y;
y = (char *)malloc((sizeof(char) * strlen(x)) + 1);
strcpy(y, x);
return y;
}
#endif /* NOSTRDUP */

View file

@ -40,18 +40,18 @@
int
strscan(s_char *target, s_char *string)
{
int i,n,delta;
int i, n, delta;
if ((string == NULL) || (target == NULL))
return(1);
n = strlen(target);
delta = strlen(string);
if (delta < n)
return(1);
delta -= n;
for (i = 0; i <= delta; i++) {
if (!strncmp(target,&(string[i]),n))
return(0);
}
return(1);
if ((string == NULL) || (target == NULL))
return (1);
n = strlen(target);
delta = strlen(string);
if (delta < n)
return (1);
delta -= n;
for (i = 0; i <= delta; i++) {
if (!strncmp(target, &(string[i]), n))
return (0);
}
return (1);
}

View file

@ -45,7 +45,7 @@
#include "misc.h"
#include "gen.h"
#ifdef OSK /* os9/68k can take advantage of both */
#ifdef OSK /* os9/68k can take advantage of both */
#define LONGINT
#define INTSPRINTF
#endif
@ -72,7 +72,8 @@ typedef void *pointer;
typedef int *intp;
int vsprintf(dest, format, args)
int
vsprintf(dest, format, args)
s_char *dest;
register s_char *format;
va_list args;
@ -86,96 +87,98 @@ va_list args;
#endif
tempfmt[0] = '%';
while(c = *format++) {
if(c=='%') {
while (c = *format++) {
if (c == '%') {
tp = &tempfmt[1];
#ifndef LONGINT
longflag = 0;
#endif
continue_format:
switch(c = *format++) {
case 's':
*tp++ = c;
*tp = '\0';
dp += Sprintf(dp, tempfmt, va_arg(args, s_char *));
break;
case 'u':
case 'x':
case 'o':
case 'X':
continue_format:
switch (c = *format++) {
case 's':
*tp++ = c;
*tp = '\0';
dp += Sprintf(dp, tempfmt, va_arg(args, s_char *));
break;
case 'u':
case 'x':
case 'o':
case 'X':
#ifdef UNSIGNEDSPECIAL
*tp++ = c;
*tp = '\0';
*tp++ = c;
*tp = '\0';
#ifndef LONGINT
if(longflag)
dp += Sprintf(dp, tempfmt, va_arg(args, unsigned long));
else
if (longflag)
dp +=
Sprintf(dp, tempfmt, va_arg(args, unsigned long));
else
#endif
dp += Sprintf(dp, tempfmt, va_arg(args, unsigned));
break;
dp += Sprintf(dp, tempfmt, va_arg(args, unsigned));
break;
#endif
case 'd':
case 'c':
case 'i':
*tp++ = c;
*tp = '\0';
case 'd':
case 'c':
case 'i':
*tp++ = c;
*tp = '\0';
#ifndef LONGINT
if(longflag)
dp += Sprintf(dp, tempfmt, va_arg(args, long));
else
if (longflag)
dp += Sprintf(dp, tempfmt, va_arg(args, long));
else
#endif
dp += Sprintf(dp, tempfmt, va_arg(args, int));
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
*tp++ = c;
*tp = '\0';
dp += Sprintf(dp, tempfmt, va_arg(args, double));
break;
case 'p':
*tp++ = c;
*tp = '\0';
dp += Sprintf(dp, tempfmt, va_arg(args, pointer));
break;
case '-':
case '+':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
case ' ':
case '#':
case 'h':
*tp++ = c;
goto continue_format;
case 'l':
dp += Sprintf(dp, tempfmt, va_arg(args, int));
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
*tp++ = c;
*tp = '\0';
dp += Sprintf(dp, tempfmt, va_arg(args, double));
break;
case 'p':
*tp++ = c;
*tp = '\0';
dp += Sprintf(dp, tempfmt, va_arg(args, pointer));
break;
case '-':
case '+':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
case ' ':
case '#':
case 'h':
*tp++ = c;
goto continue_format;
case 'l':
#ifndef LONGINT
longflag = 1;
*tp++ = c;
longflag = 1;
*tp++ = c;
#endif
goto continue_format;
case '*':
tp += Sprintf(tp, "%d", va_arg(args, int));
goto continue_format;
case 'n':
*va_arg(args, intp) = dp - dest;
break;
case '%':
default:
*dp++ = c;
break;
goto continue_format;
case '*':
tp += Sprintf(tp, "%d", va_arg(args, int));
goto continue_format;
case 'n':
*va_arg(args, intp) = dp - dest;
break;
case '%':
default:
*dp++ = c;
break;
}
} else *dp++ = c;
} else
*dp++ = c;
}
*dp = '\0';
return dp - dest;