Consistent formatting of example code in the docs

This commit is contained in:
William S Fulton 2016-10-21 19:14:32 +01:00
commit 268b942865
25 changed files with 1705 additions and 1714 deletions

View file

@ -126,16 +126,16 @@ example:
<div class="code">
<pre>
List make_list(const char *s, ...) {
va_list ap;
List x;
...
va_start(ap, s);
while (s) {
x.append(s);
s = va_arg(ap, const char *);
}
va_end(ap);
return x;
va_list ap;
List x;
...
va_start(ap, s);
while (s) {
x.append(s);
s = va_arg(ap, const char *);
}
va_end(ap);
return x;
}
</pre>
</div>
@ -188,12 +188,12 @@ In contrast, suppose you attempted to make some kind of wrapper around
<div class="code">
<pre>
int wrap_printf(const char *fmt, ...) {
va_list ap;
va_start(ap,fmt);
...
printf(fmt,ap);
...
va_end(ap);
va_list ap;
va_start(ap,fmt);
...
printf(fmt,ap);
...
va_end(ap);
};
</pre>
</div>
@ -471,15 +471,15 @@ like this:
<div class="code">
<pre>
wrap_printf() {
char *arg1;
void *arg2;
int result;
char *arg1;
void *arg2;
int result;
arg1 = "%s";
arg2 = (void *) PyString_AsString(arg2obj);
...
result = printf(arg1,arg2);
...
arg1 = "%s";
arg2 = (void *) PyString_AsString(arg2obj);
...
result = printf(arg1,arg2);
...
}
</pre>
</div>
@ -525,16 +525,16 @@ like this:
%#if PY_VERSION_HEX&gt;=0x03000000
PyObject *pystr;
if (!PyUnicode_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string");
SWIG_fail;
PyErr_SetString(PyExc_ValueError, "Expected a string");
SWIG_fail;
}
pystr = PyUnicode_AsUTF8String(pyobj);
str = strdup(PyBytes_AsString(pystr));
Py_XDECREF(pystr);
%#else
if (!PyString_Check(pyobj)) {
PyErr_SetString(PyExc_ValueError, "Expected a string");
SWIG_fail;
PyErr_SetString(PyExc_ValueError, "Expected a string");
SWIG_fail;
}
str = PyString_AsString(pyobj);
%#endif
@ -626,23 +626,23 @@ example. For example:
of strings */
%typemap(in) (...) {
char **argv;
int argc;
int i;
char **argv;
int argc;
int i;
argc = PyTuple_Size(varargs);
argv = (char **) malloc(sizeof(char *)*(argc+1));
for (i = 0; i &lt; argc; i++) {
PyObject *o = PyTuple_GetItem(varargs,i);
if (!PyString_Check(o)) {
free(argv);
PyErr_SetString(PyExc_ValueError,"Expected a string");
SWIG_fail;
}
argv[i] = PyString_AsString(o);
}
argv[i] = NULL;
$1 = (void *) argv;
argc = PyTuple_Size(varargs);
argv = (char **) malloc(sizeof(char *)*(argc+1));
for (i = 0; i &lt; argc; i++) {
PyObject *o = PyTuple_GetItem(varargs,i);
if (!PyString_Check(o)) {
free(argv);
PyErr_SetString(PyExc_ValueError,"Expected a string");
SWIG_fail;
}
argv[i] = PyString_AsString(o);
}
argv[i] = NULL;
$1 = (void *) argv;
}
/* Rewrite the function call, using libffi */
@ -912,12 +912,12 @@ and it fully supports classes much like the <tt>%rename</tt> directive. For exa
class Foo {
public:
virtual void bar(char *arg, ...); // gets varargs above
virtual void bar(char *arg, ...); // gets varargs above
};
class Spam: public Foo {
public:
virtual void bar(char *arg, ...); // gets varargs above
virtual void bar(char *arg, ...); // gets varargs above
};
</pre>
</div>
@ -952,9 +952,9 @@ are placed in <tt>arg2</tt>, <tt>arg3</tt>, and so forth. For example:
<div class="code">
<pre>
%feature("action") Foo::bar {
...
result = arg1-&gt;bar(arg2, arg3, etc.);
...
...
result = arg1-&gt;bar(arg2, arg3, etc.);
...
}
</pre>
</div>
@ -987,10 +987,10 @@ you might structure your interface like this:
<div class="code">
<pre>
%typemap(const char *fmt, ...) {
...
...
}
%feature("action") traceprintf {
...
...
}
/* Include some header file with traceprintf in it */
@ -1011,7 +1011,7 @@ to control this:
<pre>
#ifdef USE_LIBFFI
%feature("action") printf {
...
...
}
#endif
#ifdef USE_OTHERFFI