/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
* Steve McClure, 1998
*/
+#include <config.h>
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
+#include "ioqueue.h"
#include "misc.h"
#include "queue.h"
-#include "ioqueue.h"
-static int ioqtobuf(register struct ioqueue *ioq, s_char *buf, int cc);
-static void enqueuecc(struct ioqueue *ioq, s_char *buf, int cc);
-static int dequeuecc(register struct ioqueue *ioq, register int cc);
+static int ioqtobuf(struct ioqueue *ioq, char *buf, int cc);
+static void enqueuecc(struct ioqueue *ioq, char *buf, int cc);
+static int dequeuecc(struct ioqueue *ioq, int cc);
-void insque(struct qelem *, struct qelem *);
-void remque(struct qelem *);
-void initque(struct qelem *p);
-struct qelem *makeqt(int nelem);
void
ioq_init(struct ioqueue *ioq, int bsize)
{
- extern s_char num_teles[];
-
initque(&ioq->queue);
ioq->cc = 0;
ioq->bsize = bsize;
- *num_teles = '\0';
}
/*
* number of bytes actually found.
*/
int
-ioq_peek(struct ioqueue *ioq, s_char *buf, int cc)
+ioq_peek(struct ioqueue *ioq, char *buf, int cc)
{
return ioqtobuf(ioq, buf, cc);
}
}
int
-ioq_read(struct ioqueue *ioq, s_char *buf, int cc)
+ioq_read(struct ioqueue *ioq, char *buf, int cc)
{
int n;
}
void
-ioq_write(struct ioqueue *ioq, s_char *buf, int cc)
+ioq_write(struct ioqueue *ioq, char *buf, int cc)
{
enqueuecc(ioq, buf, cc);
}
ioq->cc = 0;
}
-s_char *
-ioq_gets(struct ioqueue *ioq, s_char *buf, int cc)
+char *
+ioq_gets(struct ioqueue *ioq, char *buf, int cc, int *eol)
{
- register s_char *p;
- register s_char *end;
+ char *p;
+ char *end;
int nbytes;
+ *eol = 0;
+
+ cc--;
+
nbytes = ioqtobuf(ioq, buf, cc);
- if (nbytes < cc)
- cc = nbytes;
- end = &buf[cc];
+ end = &buf[nbytes];
for (p = buf; p < end && *p; p++) {
if (*p == '\n') {
- *p = '\0';
- dequeuecc(ioq, (p - buf) + 1);
+ *++p = '\0';
+ *eol = 1;
+ dequeuecc(ioq, p - buf);
return buf;
}
}
- return 0;
+ if (cc && (p - buf) == cc) {
+ dequeuecc(ioq, cc);
+ buf[cc] = '\0';
+ return buf;
+ }
+ return NULL;
}
/*
* left for a higher level.
*/
static int
-ioqtobuf(register struct ioqueue *ioq, s_char *buf, int cc)
+ioqtobuf(struct ioqueue *ioq, char *buf, int cc)
{
- register struct io *io;
+ struct io *io;
struct qelem *qp;
- s_char *offset;
+ char *offset;
int nbytes;
int nleft;
* append a buffer to the end of the ioq.
*/
static void
-enqueuecc(struct ioqueue *ioq, s_char *buf, int cc)
+enqueuecc(struct ioqueue *ioq, char *buf, int cc)
{
struct io *io;
- io = (struct io *)malloc(sizeof(*io));
+ io = malloc(sizeof(*io));
io->nbytes = cc;
io->offset = 0;
io->data = buf;
* which are no longer used.
*/
static int
-dequeuecc(register struct ioqueue *ioq, register int cc)
+dequeuecc(struct ioqueue *ioq, int cc)
{
- register struct io *io;
- register struct qelem *qp;
- register int nbytes;
- register int there;
+ struct io *io;
+ struct qelem *qp;
+ int nbytes;
+ int there;
nbytes = 0;
while ((qp = ioq->queue.q_forw) != &ioq->queue) {