Commit ee2c4d48 authored by Peter Schneider-Kamp's avatar Peter Schneider-Kamp

ANSI-fication

parent c5b09a39
...@@ -40,8 +40,7 @@ typedef struct { ...@@ -40,8 +40,7 @@ typedef struct {
/* Regex object methods */ /* Regex object methods */
static void static void
reg_dealloc(re) reg_dealloc(regexobject *re)
regexobject *re;
{ {
if (re->re_patbuf.buffer) if (re->re_patbuf.buffer)
PyMem_DEL(re->re_patbuf.buffer); PyMem_DEL(re->re_patbuf.buffer);
...@@ -54,8 +53,7 @@ reg_dealloc(re) ...@@ -54,8 +53,7 @@ reg_dealloc(re)
} }
static PyObject * static PyObject *
makeresult(regs) makeresult(struct re_registers *regs)
struct re_registers *regs;
{ {
PyObject *v; PyObject *v;
int i; int i;
...@@ -89,9 +87,7 @@ makeresult(regs) ...@@ -89,9 +87,7 @@ makeresult(regs)
} }
static PyObject * static PyObject *
regobj_match(re, args) regobj_match(regexobject *re, PyObject *args)
regexobject *re;
PyObject *args;
{ {
PyObject *argstring; PyObject *argstring;
char *buffer; char *buffer;
...@@ -127,9 +123,7 @@ regobj_match(re, args) ...@@ -127,9 +123,7 @@ regobj_match(re, args)
} }
static PyObject * static PyObject *
regobj_search(re, args) regobj_search(regexobject *re, PyObject *args)
regexobject *re;
PyObject *args;
{ {
PyObject *argstring; PyObject *argstring;
char *buffer; char *buffer;
...@@ -174,9 +168,7 @@ regobj_search(re, args) ...@@ -174,9 +168,7 @@ regobj_search(re, args)
an integer index [0 .. 99] an integer index [0 .. 99]
*/ */
static PyObject* static PyObject*
group_from_index(re, index) group_from_index(regexobject *re, PyObject *index)
regexobject *re;
PyObject *index;
{ {
int i, a, b; int i, a, b;
char *v; char *v;
...@@ -218,9 +210,7 @@ group_from_index(re, index) ...@@ -218,9 +210,7 @@ group_from_index(re, index)
static PyObject * static PyObject *
regobj_group(re, args) regobj_group(regexobject *re, PyObject *args)
regexobject *re;
PyObject *args;
{ {
int n = PyTuple_Size(args); int n = PyTuple_Size(args);
int i; int i;
...@@ -281,9 +271,7 @@ static char* members[] = { ...@@ -281,9 +271,7 @@ static char* members[] = {
static PyObject * static PyObject *
regobj_getattr(re, name) regobj_getattr(regexobject *re, char *name)
regexobject *re;
char *name;
{ {
if (strcmp(name, "regs") == 0) { if (strcmp(name, "regs") == 0) {
if (re->re_lastok == NULL) { if (re->re_lastok == NULL) {
...@@ -380,11 +368,7 @@ static PyTypeObject Regextype = { ...@@ -380,11 +368,7 @@ static PyTypeObject Regextype = {
groupindex: transferred groupindex: transferred
*/ */
static PyObject * static PyObject *
newregexobject(pattern, translate, givenpat, groupindex) newregexobject(PyObject *pattern, PyObject *translate, PyObject *givenpat, PyObject *groupindex)
PyObject *pattern;
PyObject *translate;
PyObject *givenpat;
PyObject *groupindex;
{ {
regexobject *re; regexobject *re;
char *pat; char *pat;
...@@ -432,9 +416,7 @@ newregexobject(pattern, translate, givenpat, groupindex) ...@@ -432,9 +416,7 @@ newregexobject(pattern, translate, givenpat, groupindex)
} }
static PyObject * static PyObject *
regex_compile(self, args) regex_compile(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
PyObject *pat = NULL; PyObject *pat = NULL;
PyObject *tran = NULL; PyObject *tran = NULL;
...@@ -445,9 +427,7 @@ regex_compile(self, args) ...@@ -445,9 +427,7 @@ regex_compile(self, args)
} }
static PyObject * static PyObject *
symcomp(pattern, gdict) symcomp(PyObject *pattern, PyObject *gdict)
PyObject *pattern;
PyObject *gdict;
{ {
char *opat, *oend, *o, *n, *g, *v; char *opat, *oend, *o, *n, *g, *v;
int group_count = 0; int group_count = 0;
...@@ -554,9 +534,7 @@ symcomp(pattern, gdict) ...@@ -554,9 +534,7 @@ symcomp(pattern, gdict)
} }
static PyObject * static PyObject *
regex_symcomp(self, args) regex_symcomp(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
PyObject *pattern; PyObject *pattern;
PyObject *tran = NULL; PyObject *tran = NULL;
...@@ -583,8 +561,7 @@ static PyObject *cache_pat; ...@@ -583,8 +561,7 @@ static PyObject *cache_pat;
static PyObject *cache_prog; static PyObject *cache_prog;
static int static int
update_cache(pat) update_cache(PyObject *pat)
PyObject *pat;
{ {
PyObject *tuple = Py_BuildValue("(O)", pat); PyObject *tuple = Py_BuildValue("(O)", pat);
int status = 0; int status = 0;
...@@ -610,9 +587,7 @@ update_cache(pat) ...@@ -610,9 +587,7 @@ update_cache(pat)
} }
static PyObject * static PyObject *
regex_match(self, args) regex_match(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
PyObject *pat, *string; PyObject *pat, *string;
PyObject *tuple, *v; PyObject *tuple, *v;
...@@ -630,9 +605,7 @@ regex_match(self, args) ...@@ -630,9 +605,7 @@ regex_match(self, args)
} }
static PyObject * static PyObject *
regex_search(self, args) regex_search(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
PyObject *pat, *string; PyObject *pat, *string;
PyObject *tuple, *v; PyObject *tuple, *v;
...@@ -650,9 +623,7 @@ regex_search(self, args) ...@@ -650,9 +623,7 @@ regex_search(self, args)
} }
static PyObject * static PyObject *
regex_set_syntax(self, args) regex_set_syntax(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
int syntax; int syntax;
if (!PyArg_Parse(args, "i", &syntax)) if (!PyArg_Parse(args, "i", &syntax))
...@@ -667,9 +638,7 @@ regex_set_syntax(self, args) ...@@ -667,9 +638,7 @@ regex_set_syntax(self, args)
} }
static PyObject * static PyObject *
regex_get_syntax(self, args) regex_get_syntax(PyObject *self, PyObject *args)
PyObject *self;
PyObject *args;
{ {
if (!PyArg_Parse(args, "")) if (!PyArg_Parse(args, ""))
return NULL; return NULL;
......
...@@ -546,8 +546,7 @@ void re_compile_initialize() ...@@ -546,8 +546,7 @@ void re_compile_initialize()
regexp_ansi_sequences = (regexp_syntax & RE_ANSI_HEX) != 0; regexp_ansi_sequences = (regexp_syntax & RE_ANSI_HEX) != 0;
} }
int re_set_syntax(syntax) int re_set_syntax(int syntax)
int syntax;
{ {
int ret; int ret;
...@@ -558,8 +557,7 @@ int re_set_syntax(syntax) ...@@ -558,8 +557,7 @@ int re_set_syntax(syntax)
return ret; return ret;
} }
static int hex_char_to_decimal(ch) static int hex_char_to_decimal(int ch)
int ch;
{ {
if (ch >= '0' && ch <= '9') if (ch >= '0' && ch <= '9')
return ch - '0'; return ch - '0';
...@@ -570,16 +568,10 @@ static int hex_char_to_decimal(ch) ...@@ -570,16 +568,10 @@ static int hex_char_to_decimal(ch)
return 16; return 16;
} }
static void re_compile_fastmap_aux(code, static void re_compile_fastmap_aux(unsigned char *code, int pos,
pos, unsigned char *visited,
visited, unsigned char *can_be_null,
can_be_null, unsigned char *fastmap)
fastmap)
unsigned char *code;
int pos;
unsigned char *visited;
unsigned char *can_be_null;
unsigned char *fastmap;
{ {
int a; int a;
int b; int b;
...@@ -706,16 +698,9 @@ static void re_compile_fastmap_aux(code, ...@@ -706,16 +698,9 @@ static void re_compile_fastmap_aux(code,
} }
} }
static int re_do_compile_fastmap(buffer, static int re_do_compile_fastmap(unsigned char *buffer, int used, int pos,
used, unsigned char *can_be_null,
pos, unsigned char *fastmap)
can_be_null,
fastmap)
unsigned char *buffer;
int used;
int pos;
unsigned char *can_be_null;
unsigned char *fastmap;
{ {
unsigned char small_visited[512], *visited; unsigned char small_visited[512], *visited;
...@@ -736,8 +721,7 @@ static int re_do_compile_fastmap(buffer, ...@@ -736,8 +721,7 @@ static int re_do_compile_fastmap(buffer,
return 1; return 1;
} }
void re_compile_fastmap(bufp) void re_compile_fastmap(regexp_t bufp)
regexp_t bufp;
{ {
if (!bufp->fastmap || bufp->fastmap_accurate) if (!bufp->fastmap || bufp->fastmap_accurate)
return; return;
...@@ -782,9 +766,7 @@ void re_compile_fastmap(bufp) ...@@ -782,9 +766,7 @@ void re_compile_fastmap(bufp)
* *
*/ */
static int re_optimize_star_jump(bufp, code) static int re_optimize_star_jump(regexp_t bufp, unsigned char *code)
regexp_t bufp;
unsigned char *code;
{ {
unsigned char map[256]; unsigned char map[256];
unsigned char can_be_null; unsigned char can_be_null;
...@@ -945,8 +927,7 @@ static int re_optimize_star_jump(bufp, code) ...@@ -945,8 +927,7 @@ static int re_optimize_star_jump(bufp, code)
return 1; return 1;
} }
static int re_optimize(bufp) static int re_optimize(regexp_t bufp)
regexp_t bufp;
{ {
unsigned char *code; unsigned char *code;
...@@ -1147,10 +1128,7 @@ else \ ...@@ -1147,10 +1128,7 @@ else \
} \ } \
} }
char *re_compile_pattern(regex, size, bufp) char *re_compile_pattern(unsigned char *regex, int size, regexp_t bufp)
unsigned char *regex;
int size;
regexp_t bufp;
{ {
int a; int a;
int pos; int pos;
...@@ -1417,8 +1395,8 @@ char *re_compile_pattern(regex, size, bufp) ...@@ -1417,8 +1395,8 @@ char *re_compile_pattern(regex, size, bufp)
int prev; int prev;
int offset; int offset;
int range; int range;
int firstchar; int firstchar;
SET_LEVEL_START; SET_LEVEL_START;
ALLOC(1+256/8); ALLOC(1+256/8);
STORE(Cset); STORE(Cset);
...@@ -1586,16 +1564,8 @@ var = (unsigned char)*text++; \ ...@@ -1586,16 +1564,8 @@ var = (unsigned char)*text++; \
if (translate) \ if (translate) \
var = translate[var] var = translate[var]
int re_match(bufp, int re_match(regexp_t bufp, unsigned char *string, int size, int pos,
string, regexp_registers_t old_regs)
size,
pos,
old_regs)
regexp_t bufp;
unsigned char *string;
int size;
int pos;
regexp_registers_t old_regs;
{ {
unsigned char *code; unsigned char *code;
unsigned char *translate; unsigned char *translate;
...@@ -2021,18 +1991,8 @@ int re_match(bufp, ...@@ -2021,18 +1991,8 @@ int re_match(bufp,
#undef PREFETCH #undef PREFETCH
#undef NEXTCHAR #undef NEXTCHAR
int re_search(bufp, int re_search(regexp_t bufp, unsigned char *string, int size, int pos,
string, int range, regexp_registers_t regs)
size,
pos,
range,
regs)
regexp_t bufp;
unsigned char *string;
int size;
int pos;
int range;
regexp_registers_t regs;
{ {
unsigned char *fastmap; unsigned char *fastmap;
unsigned char *translate; unsigned char *translate;
......
...@@ -87,8 +87,7 @@ staticforward PyTypeObject Rotor_Type; ...@@ -87,8 +87,7 @@ staticforward PyTypeObject Rotor_Type;
/* This defines the necessary routines to manage rotor objects */ /* This defines the necessary routines to manage rotor objects */
static void static void
set_seed(r) set_seed(Rotorobj *r)
Rotorobj *r;
{ {
r->seed[0] = r->key[0]; r->seed[0] = r->key[0];
r->seed[1] = r->key[1]; r->seed[1] = r->key[1];
...@@ -98,8 +97,7 @@ set_seed(r) ...@@ -98,8 +97,7 @@ set_seed(r)
/* Return the next random number in the range [0.0 .. 1.0) */ /* Return the next random number in the range [0.0 .. 1.0) */
static double static double
r_random(r) r_random(Rotorobj *r)
Rotorobj *r;
{ {
int x, y, z; int x, y, z;
double val, term; double val, term;
...@@ -134,17 +132,13 @@ r_random(r) ...@@ -134,17 +132,13 @@ r_random(r)
} }
static short static short
r_rand(r, s) r_rand(Rotorobj *r, short s)
Rotorobj *r;
short s;
{ {
return (short)((short)(r_random(r) * (double)s) % s); return (short)((short)(r_random(r) * (double)s) % s);
} }
static void static void
set_key(r, key) set_key(Rotorobj *r, char *key)
Rotorobj *r;
char *key;
{ {
unsigned long k1=995, k2=576, k3=767, k4=671, k5=463; unsigned long k1=995, k2=576, k3=767, k4=671, k5=463;
size_t i; size_t i;
...@@ -172,9 +166,7 @@ set_key(r, key) ...@@ -172,9 +166,7 @@ set_key(r, key)
/* These define the interface to a rotor object */ /* These define the interface to a rotor object */
static Rotorobj * static Rotorobj *
rotorobj_new(num_rotors, key) rotorobj_new(int num_rotors, char *key)
int num_rotors;
char *key;
{ {
Rotorobj *xp; Rotorobj *xp;
...@@ -251,9 +243,7 @@ rotorobj_new(num_rotors, key) ...@@ -251,9 +243,7 @@ rotorobj_new(num_rotors, key)
/* Set ROTOR to the identity permutation */ /* Set ROTOR to the identity permutation */
static void static void
RTR_make_id_rotor(r, rtr) RTR_make_id_rotor(Rotorobj *r, unsigned char *rtr)
Rotorobj *r;
unsigned char *rtr;
{ {
register int j; register int j;
register int size = r->size; register int size = r->size;
...@@ -265,8 +255,7 @@ RTR_make_id_rotor(r, rtr) ...@@ -265,8 +255,7 @@ RTR_make_id_rotor(r, rtr)
/* The current set of encryption rotors */ /* The current set of encryption rotors */
static void static void
RTR_e_rotors(r) RTR_e_rotors(Rotorobj *r)
Rotorobj *r;
{ {
int i; int i;
for (i = 0; i < r->rotors; i++) { for (i = 0; i < r->rotors; i++) {
...@@ -276,8 +265,7 @@ RTR_e_rotors(r) ...@@ -276,8 +265,7 @@ RTR_e_rotors(r)
/* The current set of decryption rotors */ /* The current set of decryption rotors */
static void static void
RTR_d_rotors(r) RTR_d_rotors(Rotorobj *r)
Rotorobj *r;
{ {
register int i, j; register int i, j;
for (i = 0; i < r->rotors; i++) { for (i = 0; i < r->rotors; i++) {
...@@ -289,8 +277,7 @@ RTR_d_rotors(r) ...@@ -289,8 +277,7 @@ RTR_d_rotors(r)
/* The positions of the rotors at this time */ /* The positions of the rotors at this time */
static void static void
RTR_positions(r) RTR_positions(Rotorobj *r)
Rotorobj *r;
{ {
int i; int i;
for (i = 0; i < r->rotors; i++) { for (i = 0; i < r->rotors; i++) {
...@@ -300,8 +287,7 @@ RTR_positions(r) ...@@ -300,8 +287,7 @@ RTR_positions(r)
/* The number of positions to advance the rotors at a time */ /* The number of positions to advance the rotors at a time */
static void static void
RTR_advances(r) RTR_advances(Rotorobj *r)
Rotorobj *r;
{ {
int i; int i;
for (i = 0; i < r->rotors; i++) { for (i = 0; i < r->rotors; i++) {
...@@ -313,10 +299,7 @@ RTR_advances(r) ...@@ -313,10 +299,7 @@ RTR_advances(r)
* see Knuth for explanation of algorithm. * see Knuth for explanation of algorithm.
*/ */
static void static void
RTR_permute_rotor(r, e, d) RTR_permute_rotor(Rotorobj *r, unsigned char *e, unsigned char *d)
Rotorobj *r;
unsigned char *e;
unsigned char *d;
{ {
short i = r->size; short i = r->size;
short q; short q;
...@@ -338,8 +321,7 @@ RTR_permute_rotor(r, e, d) ...@@ -338,8 +321,7 @@ RTR_permute_rotor(r, e, d)
* Set the advancement, position, and permutation of the rotors * Set the advancement, position, and permutation of the rotors
*/ */
static void static void
RTR_init(r) RTR_init(Rotorobj *r)
Rotorobj *r;
{ {
int i; int i;
set_seed(r); set_seed(r);
...@@ -359,8 +341,7 @@ RTR_init(r) ...@@ -359,8 +341,7 @@ RTR_init(r)
/* Change the RTR-positions vector, using the RTR-advances vector */ /* Change the RTR-positions vector, using the RTR-advances vector */
static void static void
RTR_advance(r) RTR_advance(Rotorobj *r)
Rotorobj *r;
{ {
register int i=0, temp=0; register int i=0, temp=0;
if (r->size_mask) { if (r->size_mask) {
...@@ -386,9 +367,7 @@ RTR_advance(r) ...@@ -386,9 +367,7 @@ RTR_advance(r)
/* Encrypt the character P with the current rotor machine */ /* Encrypt the character P with the current rotor machine */
static unsigned char static unsigned char
RTR_e_char(r, p) RTR_e_char(Rotorobj *r, unsigned char p)
Rotorobj *r;
unsigned char p;
{ {
register int i=0; register int i=0;
register unsigned char tp=p; register unsigned char tp=p;
...@@ -413,9 +392,7 @@ RTR_e_char(r, p) ...@@ -413,9 +392,7 @@ RTR_e_char(r, p)
/* Decrypt the character C with the current rotor machine */ /* Decrypt the character C with the current rotor machine */
static unsigned char static unsigned char
RTR_d_char(r, c) RTR_d_char(Rotorobj *r, unsigned char c)
Rotorobj *r;
unsigned char c;
{ {
register int i = r->rotors - 1; register int i = r->rotors - 1;
register unsigned char tc = c; register unsigned char tc = c;
...@@ -440,11 +417,7 @@ RTR_d_char(r, c) ...@@ -440,11 +417,7 @@ RTR_d_char(r, c)
/* Perform a rotor encryption of the region from BEG to END by KEY */ /* Perform a rotor encryption of the region from BEG to END by KEY */
static void static void
RTR_e_region(r, beg, len, doinit) RTR_e_region(Rotorobj *r, unsigned char *beg, int len, int doinit)
Rotorobj *r;
unsigned char *beg;
int len;
int doinit;
{ {
register int i; register int i;
if (doinit || r->isinited == FALSE) if (doinit || r->isinited == FALSE)
...@@ -456,11 +429,7 @@ RTR_e_region(r, beg, len, doinit) ...@@ -456,11 +429,7 @@ RTR_e_region(r, beg, len, doinit)
/* Perform a rotor decryption of the region from BEG to END by KEY */ /* Perform a rotor decryption of the region from BEG to END by KEY */
static void static void
RTR_d_region(r, beg, len, doinit) RTR_d_region(Rotorobj *r, unsigned char *beg, int len, int doinit)
Rotorobj *r;
unsigned char *beg;
int len;
int doinit;
{ {
register int i; register int i;
if (doinit || r->isinited == FALSE) if (doinit || r->isinited == FALSE)
...@@ -474,8 +443,7 @@ RTR_d_region(r, beg, len, doinit) ...@@ -474,8 +443,7 @@ RTR_d_region(r, beg, len, doinit)
/* Rotor methods */ /* Rotor methods */
static void static void
rotor_dealloc(xp) rotor_dealloc(Rotorobj *xp)
Rotorobj *xp;
{ {
if (xp->e_rotor) if (xp->e_rotor)
PyMem_DEL(xp->e_rotor); PyMem_DEL(xp->e_rotor);
...@@ -489,9 +457,7 @@ rotor_dealloc(xp) ...@@ -489,9 +457,7 @@ rotor_dealloc(xp)
} }
static PyObject * static PyObject *
rotorobj_encrypt(self, args) rotorobj_encrypt(Rotorobj *self, PyObject *args)
Rotorobj *self;
PyObject * args;
{ {
char *string = NULL; char *string = NULL;
int len = 0; int len = 0;
...@@ -513,9 +479,7 @@ rotorobj_encrypt(self, args) ...@@ -513,9 +479,7 @@ rotorobj_encrypt(self, args)
} }
static PyObject * static PyObject *
rotorobj_encrypt_more(self, args) rotorobj_encrypt_more(Rotorobj *self, PyObject *args)
Rotorobj *self;
PyObject * args;
{ {
char *string = NULL; char *string = NULL;
int len = 0; int len = 0;
...@@ -537,9 +501,7 @@ rotorobj_encrypt_more(self, args) ...@@ -537,9 +501,7 @@ rotorobj_encrypt_more(self, args)
} }
static PyObject * static PyObject *
rotorobj_decrypt(self, args) rotorobj_decrypt(Rotorobj *self, PyObject *args)
Rotorobj *self;
PyObject * args;
{ {
char *string = NULL; char *string = NULL;
int len = 0; int len = 0;
...@@ -561,9 +523,7 @@ rotorobj_decrypt(self, args) ...@@ -561,9 +523,7 @@ rotorobj_decrypt(self, args)
} }
static PyObject * static PyObject *
rotorobj_decrypt_more(self, args) rotorobj_decrypt_more(Rotorobj *self, PyObject *args)
Rotorobj *self;
PyObject * args;
{ {
char *string = NULL; char *string = NULL;
int len = 0; int len = 0;
...@@ -585,9 +545,7 @@ rotorobj_decrypt_more(self, args) ...@@ -585,9 +545,7 @@ rotorobj_decrypt_more(self, args)
} }
static PyObject * static PyObject *
rotorobj_setkey(self, args) rotorobj_setkey(Rotorobj *self, PyObject *args)
Rotorobj *self;
PyObject * args;
{ {
char *key; char *key;
...@@ -612,9 +570,7 @@ rotorobj_methods[] = { ...@@ -612,9 +570,7 @@ rotorobj_methods[] = {
/* Return a rotor object's named attribute. */ /* Return a rotor object's named attribute. */
static PyObject * static PyObject *
rotorobj_getattr(s, name) rotorobj_getattr(Rotorobj *s, char *name)
Rotorobj *s;
char *name;
{ {
return Py_FindMethod(rotorobj_methods, (PyObject*)s, name); return Py_FindMethod(rotorobj_methods, (PyObject*)s, name);
} }
...@@ -638,9 +594,7 @@ statichere PyTypeObject Rotor_Type = { ...@@ -638,9 +594,7 @@ statichere PyTypeObject Rotor_Type = {
static PyObject * static PyObject *
rotor_rotor(self, args) rotor_rotor(PyObject *self, PyObject *args)
PyObject * self;
PyObject * args;
{ {
Rotorobj *r; Rotorobj *r;
char *string; char *string;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment