ANSI-fication

This commit is contained in:
Peter Schneider-Kamp 2000-07-10 12:29:26 +00:00
parent 416d413527
commit 41c36ffe83
4 changed files with 70 additions and 213 deletions

View File

@ -58,8 +58,7 @@ typedef struct {
} pylist; } pylist;
static void static void
reap_obj(fd2obj) reap_obj(pylist fd2obj[FD_SETSIZE + 3])
pylist fd2obj[FD_SETSIZE + 3];
{ {
int i; int i;
for (i = 0; i < FD_SETSIZE + 3 && fd2obj[i].sentinel >= 0; i++) { for (i = 0; i < FD_SETSIZE + 3 && fd2obj[i].sentinel >= 0; i++) {
@ -74,10 +73,7 @@ reap_obj(fd2obj)
returns a number >= 0 returns a number >= 0
*/ */
static int static int
list2set(list, set, fd2obj) list2set(PyObject *list, fd_set *set, pylist fd2obj[FD_SETSIZE + 3])
PyObject *list;
fd_set *set;
pylist fd2obj[FD_SETSIZE + 3];
{ {
int i; int i;
int max = -1; int max = -1;
@ -155,9 +151,7 @@ list2set(list, set, fd2obj)
/* returns NULL and sets the Python exception if an error occurred */ /* returns NULL and sets the Python exception if an error occurred */
static PyObject * static PyObject *
set2list(set, fd2obj) set2list(fd_set *set, pylist fd2obj[FD_SETSIZE + 3])
fd_set *set;
pylist fd2obj[FD_SETSIZE + 3];
{ {
int i, j, count=0; int i, j, count=0;
PyObject *list, *o; PyObject *list, *o;
@ -199,9 +193,7 @@ set2list(set, fd2obj)
static PyObject * static PyObject *
select_select(self, args) select_select(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
/* This would be an awful lot of stack space on Windows! */ /* This would be an awful lot of stack space on Windows! */

View File

@ -18,9 +18,7 @@ redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#include <fcntl.h> #include <fcntl.h>
static PyObject * static PyObject *
sgi_nap(self, args) sgi_nap(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
long ticks; long ticks;
if (!PyArg_Parse(args, "l", &ticks)) if (!PyArg_Parse(args, "l", &ticks))
@ -35,9 +33,7 @@ sgi_nap(self, args)
extern char *_getpty(int *, int, mode_t, int); extern char *_getpty(int *, int, mode_t, int);
static PyObject * static PyObject *
sgi__getpty(self, args) sgi__getpty(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
int oflag; int oflag;
int mode; int mode;

View File

@ -84,9 +84,7 @@ typedef struct { char c; void *x; } s_void_p;
if it isn't one */ if it isn't one */
static int static int
get_long(v, p) get_long(PyObject *v, long *p)
PyObject *v;
long *p;
{ {
long x = PyInt_AsLong(v); long x = PyInt_AsLong(v);
if (x == -1 && PyErr_Occurred()) { if (x == -1 && PyErr_Occurred()) {
@ -103,9 +101,7 @@ get_long(v, p)
/* Same, but handling unsigned long */ /* Same, but handling unsigned long */
static int static int
get_ulong(v, p) get_ulong(PyObject *v, unsigned long *p)
PyObject *v;
unsigned long *p;
{ {
if (PyLong_Check(v)) { if (PyLong_Check(v)) {
unsigned long x = PyLong_AsUnsignedLong(v); unsigned long x = PyLong_AsUnsignedLong(v);
@ -129,10 +125,9 @@ get_ulong(v, p)
/* XXX Inf/NaN are not handled quite right (but underflow is!) */ /* XXX Inf/NaN are not handled quite right (but underflow is!) */
static int static int
pack_float(x, p, incr) pack_float(double x, /* The number to pack */
double x; /* The number to pack */ char *p, /* Where to pack the high order byte */
char *p; /* Where to pack the high order byte */ int incr) /* 1 for big-endian; -1 for little-endian */
int incr; /* 1 for big-endian; -1 for little-endian */
{ {
int s; int s;
int e; int e;
@ -201,10 +196,9 @@ pack_float(x, p, incr)
} }
static int static int
pack_double(x, p, incr) pack_double(double x, /* The number to pack */
double x; /* The number to pack */ char *p, /* Where to pack the high order byte */
char *p; /* Where to pack the high order byte */ int incr) /* 1 for big-endian; -1 for little-endian */
int incr; /* 1 for big-endian; -1 for little-endian */
{ {
int s; int s;
int e; int e;
@ -294,9 +288,8 @@ pack_double(x, p, incr)
} }
static PyObject * static PyObject *
unpack_float(p, incr) unpack_float(const char *p, /* Where the high order byte is */
char *p; /* Where the high order byte is */ int incr) /* 1 for big-endian; -1 for little-endian */
int incr; /* 1 for big-endian; -1 for little-endian */
{ {
int s; int s;
int e; int e;
@ -338,9 +331,8 @@ unpack_float(p, incr)
} }
static PyObject * static PyObject *
unpack_double(p, incr) unpack_double(const char *p, /* Where the high order byte is */
char *p; /* Where the high order byte is */ int incr) /* 1 for big-endian; -1 for little-endian */
int incr; /* 1 for big-endian; -1 for little-endian */
{ {
int s; int s;
int e; int e;
@ -413,82 +405,62 @@ typedef struct _formatdef {
} formatdef; } formatdef;
static PyObject * static PyObject *
nu_char(p, f) nu_char(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return PyString_FromStringAndSize(p, 1); return PyString_FromStringAndSize(p, 1);
} }
static PyObject * static PyObject *
nu_byte(p, f) nu_byte(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return PyInt_FromLong((long) *(signed char *)p); return PyInt_FromLong((long) *(signed char *)p);
} }
static PyObject * static PyObject *
nu_ubyte(p, f) nu_ubyte(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return PyInt_FromLong((long) *(unsigned char *)p); return PyInt_FromLong((long) *(unsigned char *)p);
} }
static PyObject * static PyObject *
nu_short(p, f) nu_short(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return PyInt_FromLong((long) *(short *)p); return PyInt_FromLong((long) *(short *)p);
} }
static PyObject * static PyObject *
nu_ushort(p, f) nu_ushort(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return PyInt_FromLong((long) *(unsigned short *)p); return PyInt_FromLong((long) *(unsigned short *)p);
} }
static PyObject * static PyObject *
nu_int(p, f) nu_int(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return PyInt_FromLong((long) *(int *)p); return PyInt_FromLong((long) *(int *)p);
} }
static PyObject * static PyObject *
nu_uint(p, f) nu_uint(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
unsigned int x = *(unsigned int *)p; unsigned int x = *(unsigned int *)p;
return PyLong_FromUnsignedLong((unsigned long)x); return PyLong_FromUnsignedLong((unsigned long)x);
} }
static PyObject * static PyObject *
nu_long(p, f) nu_long(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return PyInt_FromLong(*(long *)p); return PyInt_FromLong(*(long *)p);
} }
static PyObject * static PyObject *
nu_ulong(p, f) nu_ulong(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return PyLong_FromUnsignedLong(*(unsigned long *)p); return PyLong_FromUnsignedLong(*(unsigned long *)p);
} }
static PyObject * static PyObject *
nu_float(p, f) nu_float(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
float x; float x;
memcpy((char *)&x, p, sizeof(float)); memcpy((char *)&x, p, sizeof(float));
@ -496,9 +468,7 @@ nu_float(p, f)
} }
static PyObject * static PyObject *
nu_double(p, f) nu_double(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
double x; double x;
memcpy((char *)&x, p, sizeof(double)); memcpy((char *)&x, p, sizeof(double));
@ -506,18 +476,13 @@ nu_double(p, f)
} }
static PyObject * static PyObject *
nu_void_p(p, f) nu_void_p(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return PyLong_FromVoidPtr(*(void **)p); return PyLong_FromVoidPtr(*(void **)p);
} }
static int static int
np_byte(p, v, f) np_byte(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
long x; long x;
if (get_long(v, &x) < 0) if (get_long(v, &x) < 0)
@ -527,10 +492,7 @@ np_byte(p, v, f)
} }
static int static int
np_char(p, v, f) np_char(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
if (!PyString_Check(v) || PyString_Size(v) != 1) { if (!PyString_Check(v) || PyString_Size(v) != 1) {
PyErr_SetString(StructError, PyErr_SetString(StructError,
@ -542,10 +504,7 @@ np_char(p, v, f)
} }
static int static int
np_short(p, v, f) np_short(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
long x; long x;
if (get_long(v, &x) < 0) if (get_long(v, &x) < 0)
@ -555,10 +514,7 @@ np_short(p, v, f)
} }
static int static int
np_int(p, v, f) np_int(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
long x; long x;
if (get_long(v, &x) < 0) if (get_long(v, &x) < 0)
@ -568,10 +524,7 @@ np_int(p, v, f)
} }
static int static int
np_uint(p, v, f) np_uint(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
unsigned long x; unsigned long x;
if (get_ulong(v, &x) < 0) if (get_ulong(v, &x) < 0)
@ -581,10 +534,7 @@ np_uint(p, v, f)
} }
static int static int
np_long(p, v, f) np_long(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
long x; long x;
if (get_long(v, &x) < 0) if (get_long(v, &x) < 0)
@ -594,10 +544,7 @@ np_long(p, v, f)
} }
static int static int
np_ulong(p, v, f) np_ulong(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
unsigned long x; unsigned long x;
if (get_ulong(v, &x) < 0) if (get_ulong(v, &x) < 0)
@ -607,10 +554,7 @@ np_ulong(p, v, f)
} }
static int static int
np_float(p, v, f) np_float(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
float x = (float)PyFloat_AsDouble(v); float x = (float)PyFloat_AsDouble(v);
if (x == -1 && PyErr_Occurred()) { if (x == -1 && PyErr_Occurred()) {
@ -623,10 +567,7 @@ np_float(p, v, f)
} }
static int static int
np_double(p, v, f) np_double(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
double x = PyFloat_AsDouble(v); double x = PyFloat_AsDouble(v);
if (x == -1 && PyErr_Occurred()) { if (x == -1 && PyErr_Occurred()) {
@ -639,10 +580,7 @@ np_double(p, v, f)
} }
static int static int
np_void_p(p, v, f) np_void_p(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
void *x = PyLong_AsVoidPtr(v); void *x = PyLong_AsVoidPtr(v);
if (x == NULL && PyErr_Occurred()) { if (x == NULL && PyErr_Occurred()) {
@ -676,9 +614,7 @@ static formatdef native_table[] = {
}; };
static PyObject * static PyObject *
bu_int(p, f) bu_int(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
long x = 0; long x = 0;
int i = f->size; int i = f->size;
@ -694,9 +630,7 @@ bu_int(p, f)
} }
static PyObject * static PyObject *
bu_uint(p, f) bu_uint(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
unsigned long x = 0; unsigned long x = 0;
int i = f->size; int i = f->size;
@ -710,26 +644,19 @@ bu_uint(p, f)
} }
static PyObject * static PyObject *
bu_float(p, f) bu_float(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return unpack_float(p, 1); return unpack_float(p, 1);
} }
static PyObject * static PyObject *
bu_double(p, f) bu_double(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return unpack_double(p, 1); return unpack_double(p, 1);
} }
static int static int
bp_int(p, v, f) bp_int(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
long x; long x;
int i; int i;
@ -744,10 +671,7 @@ bp_int(p, v, f)
} }
static int static int
bp_uint(p, v, f) bp_uint(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
unsigned long x; unsigned long x;
int i; int i;
@ -762,10 +686,7 @@ bp_uint(p, v, f)
} }
static int static int
bp_float(p, v, f) bp_float(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
double x = PyFloat_AsDouble(v); double x = PyFloat_AsDouble(v);
if (x == -1 && PyErr_Occurred()) { if (x == -1 && PyErr_Occurred()) {
@ -777,10 +698,7 @@ bp_float(p, v, f)
} }
static int static int
bp_double(p, v, f) bp_double(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
double x = PyFloat_AsDouble(v); double x = PyFloat_AsDouble(v);
if (x == -1 && PyErr_Occurred()) { if (x == -1 && PyErr_Occurred()) {
@ -810,9 +728,7 @@ static formatdef bigendian_table[] = {
}; };
static PyObject * static PyObject *
lu_int(p, f) lu_int(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
long x = 0; long x = 0;
int i = f->size; int i = f->size;
@ -828,9 +744,7 @@ lu_int(p, f)
} }
static PyObject * static PyObject *
lu_uint(p, f) lu_uint(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
unsigned long x = 0; unsigned long x = 0;
int i = f->size; int i = f->size;
@ -844,26 +758,19 @@ lu_uint(p, f)
} }
static PyObject * static PyObject *
lu_float(p, f) lu_float(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return unpack_float(p+3, -1); return unpack_float(p+3, -1);
} }
static PyObject * static PyObject *
lu_double(p, f) lu_double(const char *p, const formatdef *f)
const char *p;
const formatdef *f;
{ {
return unpack_double(p+7, -1); return unpack_double(p+7, -1);
} }
static int static int
lp_int(p, v, f) lp_int(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
long x; long x;
int i; int i;
@ -878,10 +785,7 @@ lp_int(p, v, f)
} }
static int static int
lp_uint(p, v, f) lp_uint(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
unsigned long x; unsigned long x;
int i; int i;
@ -896,10 +800,7 @@ lp_uint(p, v, f)
} }
static int static int
lp_float(p, v, f) lp_float(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
double x = PyFloat_AsDouble(v); double x = PyFloat_AsDouble(v);
if (x == -1 && PyErr_Occurred()) { if (x == -1 && PyErr_Occurred()) {
@ -911,10 +812,7 @@ lp_float(p, v, f)
} }
static int static int
lp_double(p, v, f) lp_double(char *p, PyObject *v, const formatdef *f)
char *p;
PyObject *v;
const formatdef *f;
{ {
double x = PyFloat_AsDouble(v); double x = PyFloat_AsDouble(v);
if (x == -1 && PyErr_Occurred()) { if (x == -1 && PyErr_Occurred()) {
@ -945,8 +843,7 @@ static formatdef lilendian_table[] = {
static const formatdef * static const formatdef *
whichtable(pfmt) whichtable(char **pfmt)
const char **pfmt;
{ {
const char *fmt = (*pfmt)++; /* May be backed out of later */ const char *fmt = (*pfmt)++; /* May be backed out of later */
switch (*fmt) { switch (*fmt) {
@ -975,9 +872,7 @@ whichtable(pfmt)
/* Get the table entry for a format code */ /* Get the table entry for a format code */
static const formatdef * static const formatdef *
getentry(c, f) getentry(int c, const formatdef *f)
int c;
const formatdef *f;
{ {
for (; f->format != '\0'; f++) { for (; f->format != '\0'; f++) {
if (f->format == c) { if (f->format == c) {
@ -992,10 +887,7 @@ getentry(c, f)
/* Align a size according to a format code */ /* Align a size according to a format code */
static int static int
align(size, c, e) align(int size, int c, const formatdef *e)
int size;
int c;
const formatdef *e;
{ {
if (e->format == c) { if (e->format == c) {
if (e->alignment) { if (e->alignment) {
@ -1011,9 +903,7 @@ align(size, c, e)
/* calculate the size of a format string */ /* calculate the size of a format string */
static int static int
calcsize(fmt, f) calcsize(const char *fmt, const formatdef *f)
const char *fmt;
const formatdef *f;
{ {
const formatdef *e; const formatdef *e;
const char *s; const char *s;
@ -1067,9 +957,7 @@ Return size of C struct described by format string fmt.\n\
See struct.__doc__ for more on format strings."; See struct.__doc__ for more on format strings.";
static PyObject * static PyObject *
struct_calcsize(self, args) struct_calcsize(PyObject *self, PyObject *args)
PyObject *self; /* Not used */
PyObject *args;
{ {
char *fmt; char *fmt;
const formatdef *f; const formatdef *f;
@ -1091,9 +979,7 @@ Return string containing values v1, v2, ... packed according to fmt.\n\
See struct.__doc__ for more on format strings."; See struct.__doc__ for more on format strings.";
static PyObject * static PyObject *
struct_pack(self, args) struct_pack(PyObject *self, PyObject *args)
PyObject *self; /* Not used */
PyObject *args;
{ {
const formatdef *f, *e; const formatdef *f, *e;
PyObject *format, *result, *v; PyObject *format, *result, *v;
@ -1231,9 +1117,7 @@ to fmt. Requires len(string)==calcsize(fmt).\n\
See struct.__doc__ for more on format strings."; See struct.__doc__ for more on format strings.";
static PyObject * static PyObject *
struct_unpack(self, args) struct_unpack(PyObject *self, PyObject *args)
PyObject *self; /* Not used */
PyObject *args;
{ {
const formatdef *f, *e; const formatdef *f, *e;
char *str, *start, *fmt, *s; char *str, *start, *fmt, *s;

View File

@ -53,9 +53,7 @@ static PyObject *S_ident_o = NULL; /* identifier, held by openlog() */
static PyObject * static PyObject *
syslog_openlog(self, args) syslog_openlog(PyObject * self, PyObject * args)
PyObject * self;
PyObject * args;
{ {
long logopt = 0; long logopt = 0;
long facility = LOG_USER; long facility = LOG_USER;
@ -80,9 +78,7 @@ syslog_openlog(self, args)
static PyObject * static PyObject *
syslog_syslog(self, args) syslog_syslog(PyObject * self, PyObject * args)
PyObject * self;
PyObject * args;
{ {
char *message; char *message;
int priority = LOG_INFO; int priority = LOG_INFO;
@ -101,9 +97,7 @@ syslog_syslog(self, args)
} }
static PyObject * static PyObject *
syslog_closelog(self, args) syslog_closelog(PyObject *self, PyObject *args)
PyObject * self;
PyObject * args;
{ {
if (!PyArg_ParseTuple(args, ":closelog")) if (!PyArg_ParseTuple(args, ":closelog"))
return NULL; return NULL;
@ -115,9 +109,7 @@ syslog_closelog(self, args)
} }
static PyObject * static PyObject *
syslog_setlogmask(self, args) syslog_setlogmask(PyObject *self, PyObject *args)
PyObject * self;
PyObject * args;
{ {
long maskpri, omaskpri; long maskpri, omaskpri;
@ -128,9 +120,7 @@ syslog_setlogmask(self, args)
} }
static PyObject * static PyObject *
syslog_log_mask(self, args) syslog_log_mask(PyObject *self, PyObject *args)
PyObject * self;
PyObject * args;
{ {
long mask; long mask;
long pri; long pri;
@ -141,9 +131,7 @@ syslog_log_mask(self, args)
} }
static PyObject * static PyObject *
syslog_log_upto(self, args) syslog_log_upto(PyObject *self, PyObject *args)
PyObject * self;
PyObject * args;
{ {
long mask; long mask;
long pri; long pri;
@ -168,10 +156,7 @@ static PyMethodDef syslog_methods[] = {
/* helper function for initialization function */ /* helper function for initialization function */
static void static void
ins(d, s, x) ins(PyObject *d, char *s, long x)
PyObject *d;
char *s;
long x;
{ {
PyObject *v = PyInt_FromLong(x); PyObject *v = PyInt_FromLong(x);
if (v) { if (v) {