Commit 8c8f4681 authored by Jack Jansen's avatar Jack Jansen

Patches by Jens B. Jorgensen with small mods by me:

- Converted the templates to use ANSI C prototypes (finally!)
- Use re in stead of deprecated regex
parent d06d120b
......@@ -4,9 +4,7 @@ static char $abbrev$_$method$__doc__[] =
;
static PyObject *
$abbrev$_$method$(self, args)
PyObject *self; /* Not used */
PyObject *args;
$abbrev$_$method$(PyObject *self /* Not used */, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
......
......@@ -4,9 +4,7 @@ static char $abbrev$_$method$__doc__[] =
;
static PyObject *
$abbrev$_$method$(self, args)
$abbrev$object *self;
PyObject *args;
$abbrev$_$method$($abbrev$object *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
......
......@@ -12,9 +12,7 @@ static struct memberlist $abbrev$_memberlist[] = {
};
static PyObject *
$abbrev$_getattr(self, name)
$abbrev$object *self;
char *name;
$abbrev$_getattr($abbrev$object *self, char *name)
{
PyObject *rv;
......@@ -28,10 +26,7 @@ $abbrev$_getattr(self, name)
static int
$abbrev$_setattr(self, name, v)
$abbrev$object *self;
char *name;
PyObject *v;
$abbrev$_setattr($abbrev$object *self, char *name, PyObject *v)
{
/* XXXX Add your own setattr code here */
if ( v == NULL ) {
......
......@@ -2,24 +2,19 @@
/* Code to access $name$ objects as mappings */
static int
$abbrev$_length(self)
$abbrev$object *self;
$abbrev$_length($abbrev$object *self)
{
/* XXXX Return the size of the mapping */
}
static PyObject *
$abbrev$_subscript(self, key)
$abbrev$object *self;
PyObject *key;
$abbrev$_subscript($abbrev$object *self, PyObject *key)
{
/* XXXX Return the item of self indexed by key */
}
static int
$abbrev$_ass_sub(self, v, w)
$abbrev$object *self;
PyObject *v, *w;
$abbrev$_ass_sub($abbrev$object *self, PyObject *v, PyObject *w)
{
/* XXXX Put w in self under key v */
return 0;
......
......@@ -2,177 +2,140 @@
/* Code to access $name$ objects as numbers */
static PyObject *
$abbrev$_add(v, w)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$_add($abbrev$object *v, $abbrev$object *w)
{
/* XXXX Add them */
}
static PyObject *
$abbrev$_sub(v, w)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$_sub($abbrev$object *v, $abbrev$object *w)
{
/* XXXX Subtract them */
}
static PyObject *
$abbrev$_mul(v, w)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$_mul($abbrev$object *v, $abbrev$object *w)
{
/* XXXX Multiply them */
}
static PyObject *
$abbrev$_div(x, y)
$abbrev$object *x;
$abbrev$object *y;
$abbrev$_div($abbrev$object *x, $abbrev$object *y)
{
/* XXXX Divide them */
}
static PyObject *
$abbrev$_mod(x, y)
$abbrev$object *x;
$abbrev$object *y;
$abbrev$_mod($abbrev$object *x, $abbrev$object *y)
{
/* XXXX Modulo them */
}
static PyObject *
$abbrev$_divmod(x, y)
$abbrev$object *x;
$abbrev$object *y;
$abbrev$_divmod($abbrev$object *x, $abbrev$object *y)
{
/* XXXX Return 2-tuple with div and mod */
}
static PyObject *
$abbrev$_pow(v, w, z)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$object *z;
$abbrev$_pow($abbrev$object *v, $abbrev$object *w, $abbrev$object *z)
{
/* XXXX */
}
static PyObject *
$abbrev$_neg(v)
$abbrev$object *v;
$abbrev$_neg($abbrev$object *v)
{
/* XXXX */
}
static PyObject *
$abbrev$_pos(v)
$abbrev$object *v;
$abbrev$_pos($abbrev$object *v)
{
/* XXXX */
}
static PyObject *
$abbrev$_abs(v)
$abbrev$object *v;
$abbrev$_abs($abbrev$object *v)
{
/* XXXX */
}
static int
$abbrev$_nonzero(v)
$abbrev$object *v;
$abbrev$_nonzero($abbrev$object *v)
{
/* XXXX Return 1 if non-zero */
}
static PyObject *
$abbrev$_invert(v)
$abbrev$object *v;
$abbrev$_invert($abbrev$object *v)
{
/* XXXX */
}
static PyObject *
$abbrev$_lshift(v, w)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$_lshift($abbrev$object *v, $abbrev$object *w)
{
/* XXXX */
}
static PyObject *
$abbrev$_rshift(v, w)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$_rshift($abbrev$object *v, $abbrev$object *w)
{
/* XXXX */
}
static PyObject *
$abbrev$_and(v, w)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$_and($abbrev$object *v, $abbrev$object *w)
{
/* XXXX */
}
static PyObject *
$abbrev$_xor(v, w)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$_xor($abbrev$object *v, $abbrev$object *w)
{
/* XXXX */
}
static PyObject *
$abbrev$_or(v, w)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$_or($abbrev$object *v, $abbrev$object *w)
{
/* XXXX */
}
static int
$abbrev$_coerce(pv, pw)
PyObject **pv;
PyObject **pw;
$abbrev$_coerce(PyObject **pv, PyObject **pw)
{
/* XXXX I haven't a clue... */
return 1;
}
static PyObject *
$abbrev$_int(v)
$abbrev$object *v;
$abbrev$_int($abbrev$object *v)
{
/* XXXX */
}
static PyObject *
$abbrev$_long(v)
$abbrev$object *v;
$abbrev$_long($abbrev$object *v)
{
/* XXXX */
}
static PyObject *
$abbrev$_float(v)
$abbrev$object *v;
$abbrev$_float($abbrev$object *v)
{
/* XXXX */
}
static PyObject *
$abbrev$_oct(v)
$abbrev$object *v;
$abbrev$_oct($abbrev$object *v)
{
/* XXXX Return object as octal stringobject */
}
static PyObject *
$abbrev$_hex(v)
$abbrev$object *v;
$abbrev$_hex($abbrev$object *v)
{
/* XXXX Return object as hex stringobject */
}
......
......@@ -2,59 +2,44 @@
/* Code to handle accessing $name$ objects as sequence objects */
static int
$abbrev$_length(self)
$abbrev$object *self;
$abbrev$_length($abbrev$object *self)
{
/* XXXX Return the size of the object */
}
static PyObject *
$abbrev$_concat(self, bb)
$abbrev$object *self;
PyObject *bb;
$abbrev$_concat($abbrev$object *self, PyObject *bb)
{
/* XXXX Return the concatenation of self and bb */
}
static PyObject *
$abbrev$_repeat(self, n)
$abbrev$object *self;
int n;
$abbrev$_repeat($abbrev$object *self, int n)
{
/* XXXX Return a new object that is n times self */
}
static PyObject *
$abbrev$_item(self, i)
$abbrev$object *self;
int i;
$abbrev$_item($abbrev$object *self, int i)
{
/* XXXX Return the i-th object of self */
}
static PyObject *
$abbrev$_slice(self, ilow, ihigh)
$abbrev$object *self;
int ilow, ihigh;
$abbrev$_slice($abbrev$object *self, int ilow, int ihigh)
{
/* XXXX Return the ilow..ihigh slice of self in a new object */
}
static int
$abbrev$_ass_item(self, i, v)
$abbrev$object *self;
int i;
PyObject *v;
$abbrev$_ass_item($abbrev$object *self, int i, PyObject *v)
{
/* XXXX Assign to the i-th element of self */
return 0;
}
static int
$abbrev$_ass_slice(self, ilow, ihigh, v)
PyListObject *self;
int ilow, ihigh;
PyObject *v;
$abbrev$_ass_slice(PyListObject *self, int ilow, int ihigh, PyObject *v)
{
/* XXXX Replace ilow..ihigh slice of self with v */
return 0;
......
static PyObject *
$abbrev$_call(self, args, kwargs)
$abbrev$object *self;
PyObject *args;
PyObject *kwargs;
$abbrev$_call($abbrev$object *self, PyObject *args, PyObject *kwargs)
{
/* XXXX Return the result of calling self with argument args */
}
......
static int
$abbrev$_compare(v, w)
$abbrev$object *v, *w;
$abbrev$_compare($abbrev$object *v, $abbrev$object *w)
{
/* XXXX Compare objects and return -1, 0 or 1 */
}
static void
$abbrev$_dealloc(self)
$abbrev$object *self;
$abbrev$_dealloc($abbrev$object *self)
{
/* XXXX Add your own cleanup code here */
PyMem_DEL(self);
......
static PyObject *
$abbrev$_getattr(self, name)
$abbrev$object *self;
char *name;
$abbrev$_getattr($abbrev$object *self, char *name)
{
/* XXXX Add your own getattr code here */
return Py_FindMethod($abbrev$_methods, (PyObject *)self, name);
......
static long
$abbrev$_hash(self)
$abbrev$object *self;
$abbrev$_hash($abbrev$object *self)
{
/* XXXX Return a hash of self (or -1) */
}
static int
$abbrev$_print(self, fp, flags)
$abbrev$object *self;
FILE *fp;
int flags;
$abbrev$_print($abbrev$object *self, FILE *fp, int flags)
{
/* XXXX Add code here to print self to fp */
return 0;
......
static PyObject *
$abbrev$_repr(self)
$abbrev$object *self;
$abbrev$_repr($abbrev$object *self)
{
PyObject *s;
......
static int
$abbrev$_setattr(self, name, v)
$abbrev$object *self;
char *name;
PyObject *v;
$abbrev$_setattr($abbrev$object *self, char *name, PyObject *v)
{
/* Set attribute 'name' to value 'v'. v==NULL means delete */
......
static PyObject *
$abbrev$_str(self)
$abbrev$object *self;
$abbrev$_str($abbrev$object *self)
{
PyObject *s;
......
......@@ -30,8 +30,8 @@ import string
oops = 'oops'
IDENTSTARTCHARS = string.ascii_letters + '_'
IDENTCHARS = string.ascii_letters + string.digits + '_'
IDENTSTARTCHARS = string.letters + '_'
IDENTCHARS = string.letters + string.digits + '_'
# Check that string is a legal C identifier
def checkid(str):
......
......@@ -2,37 +2,33 @@
# Variable substitution. Variables are $delimited$
#
import string
import regex
import regsub
import re
error = 'varsubst.error'
class Varsubst:
def __init__(self, dict):
self.dict = dict
self.prog = regex.compile('\$[a-zA-Z0-9_]*\$')
self.prog = re.compile('\$([a-zA-Z0-9_]*)\$')
self.do_useindent = 0
def useindent(self, onoff):
self.do_useindent = onoff
def subst(self, str):
def subst(self, s):
rv = ''
while 1:
pos = self.prog.search(str)
if pos < 0:
return rv + str
if pos:
rv = rv + str[:pos]
str = str[pos:]
len = self.prog.match(str)
if len == 2:
m = self.prog.search(s)
if not m:
return rv + s
rv = rv + s[:m.start()]
s = s[m.end():]
if m.end() - m.start() == 2:
# Escaped dollar
rv = rv + '$'
str = str[2:]
s = s[2:]
continue
name = str[1:len-1]
str = str[len:]
name = m.group(1)
if not self.dict.has_key(name):
raise error, 'No such variable: '+name
value = self.dict[name]
......@@ -44,7 +40,7 @@ class Varsubst:
lastnl = string.rfind(old, '\n', 0) + 1
lastnl = len(old) - lastnl
sub = '\n' + (' '*lastnl)
return regsub.gsub('\n', sub, value)
return re.sub('\n', sub, value)
def _test():
import sys
......
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