minor code style modification

This commit is contained in:
elias.bachaalany 2010-03-22 14:22:17 +00:00
parent ab81000187
commit 0c11d8f170
3 changed files with 48 additions and 44 deletions

View File

@ -1,3 +1,7 @@
# -----------------------------------------------------------------------
# This is an example illustrating how to use the graphing functionality in Python
# (c) Hex-Rays
#
from idaapi import GraphViewer from idaapi import GraphViewer
class MyGraph(GraphViewer): class MyGraph(GraphViewer):

View File

@ -100,19 +100,19 @@ public:
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
loader_input_t(PyObject *pycobject = NULL): li(NULL), own(OWN_NONE), __idc_cvt_id__(PY_ICID_OPAQUE) loader_input_t(PyObject *pycobject = NULL): li(NULL), own(OWN_NONE), __idc_cvt_id__(PY_ICID_OPAQUE)
{ {
if (pycobject != NULL && PyCObject_Check(pycobject)) if ( pycobject != NULL && PyCObject_Check(pycobject) )
_from_cobject(pycobject); _from_cobject(pycobject);
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
void close() void close()
{ {
if (li == NULL) if ( li == NULL )
return; return;
if (own == OWN_CREATE) if ( own == OWN_CREATE )
close_linput(li); close_linput(li);
else if (own == OWN_FROM_FP) else if ( own == OWN_FROM_FP )
unmake_linput(li); unmake_linput(li);
li = NULL; li = NULL;
@ -130,7 +130,7 @@ public:
{ {
close(); close();
li = open_linput(filename, remote); li = open_linput(filename, remote);
if (li == NULL) if ( li == NULL )
Py_RETURN_FALSE; Py_RETURN_FALSE;
// Save file name // Save file name
@ -160,7 +160,7 @@ public:
// This method can be used to pass a linput_t* from C code // This method can be used to pass a linput_t* from C code
static loader_input_t *from_cobject(PyObject *pycobject) static loader_input_t *from_cobject(PyObject *pycobject)
{ {
if (!PyCObject_Check(pycobject)) if ( !PyCObject_Check(pycobject) )
return NULL; return NULL;
loader_input_t *l = new loader_input_t(); loader_input_t *l = new loader_input_t();
l->_from_cobject(pycobject); l->_from_cobject(pycobject);
@ -171,7 +171,7 @@ public:
static loader_input_t *from_fp(FILE *fp) static loader_input_t *from_fp(FILE *fp)
{ {
linput_t *fp_li = make_linput(fp); linput_t *fp_li = make_linput(fp);
if (fp_li == NULL) if ( fp_li == NULL )
return NULL; return NULL;
loader_input_t *l = new loader_input_t(); loader_input_t *l = new loader_input_t();
@ -191,7 +191,7 @@ public:
PyObject *open_memory(ea_t start, asize_t size = 0) PyObject *open_memory(ea_t start, asize_t size = 0)
{ {
linput_t *l = create_memory_linput(start, size); linput_t *l = create_memory_linput(start, size);
if (l == NULL) if ( l == NULL )
Py_RETURN_FALSE; Py_RETURN_FALSE;
close(); close();
li = l; li = l;
@ -218,13 +218,13 @@ public:
do do
{ {
char *buf = (char *) malloc(sz + 5); char *buf = (char *) malloc(sz + 5);
if (buf == NULL) if ( buf == NULL )
break; break;
qlgetz(li, fpos, buf, sz); qlgetz(li, fpos, buf, sz);
PyObject *ret = PyString_FromString(buf); PyObject *ret = PyString_FromString(buf);
free(buf); free(buf);
return ret; return ret;
} while (false); } while ( false );
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -234,9 +234,9 @@ public:
do do
{ {
char *buf = (char *) malloc(len + 5); char *buf = (char *) malloc(len + 5);
if (buf == NULL) if ( buf == NULL )
break; break;
if (qlgets(buf, len, li) == NULL) if ( qlgets(buf, len, li) == NULL )
{ {
free(buf); free(buf);
break; break;
@ -244,7 +244,7 @@ public:
PyObject *ret = PyString_FromString(buf); PyObject *ret = PyString_FromString(buf);
free(buf); free(buf);
return ret; return ret;
} while (false); } while ( false );
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -254,10 +254,10 @@ public:
do do
{ {
char *buf = (char *) malloc(size + 5); char *buf = (char *) malloc(size + 5);
if (buf == NULL) if ( buf == NULL )
break; break;
ssize_t r = qlread(li, buf, size); ssize_t r = qlread(li, buf, size);
if (r == -1) if ( r == -1 )
{ {
free(buf); free(buf);
break; break;
@ -265,7 +265,7 @@ public:
PyObject *ret = PyString_FromStringAndSize(buf, r); PyObject *ret = PyString_FromStringAndSize(buf, r);
free(buf); free(buf);
return ret; return ret;
} while (false); } while ( false );
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -281,10 +281,10 @@ public:
do do
{ {
char *buf = (char *) malloc(size + 5); char *buf = (char *) malloc(size + 5);
if (buf == NULL) if ( buf == NULL )
break; break;
int r = lreadbytes(li, buf, size, big_endian); int r = lreadbytes(li, buf, size, big_endian);
if (r == -1) if ( r == -1 )
{ {
free(buf); free(buf);
break; break;
@ -292,7 +292,7 @@ public:
PyObject *ret = PyString_FromStringAndSize(buf, r); PyObject *ret = PyString_FromStringAndSize(buf, r);
free(buf); free(buf);
return ret; return ret;
} while (false); } while ( false );
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -318,7 +318,7 @@ public:
PyObject *get_char() PyObject *get_char()
{ {
int ch = qlgetc(li); int ch = qlgetc(li);
if (ch == EOF) if ( ch == EOF )
Py_RETURN_NONE; Py_RETURN_NONE;
return Py_BuildValue("c", ch); return Py_BuildValue("c", ch);
} }
@ -330,17 +330,17 @@ PyObject *py_enumerate_files(PyObject *path, PyObject *fname, PyObject *callback
{ {
do do
{ {
if (!PyString_Check(path) || !PyString_Check(fname) || !PyCallable_Check(callback)) if ( !PyString_Check(path) || !PyString_Check(fname) || !PyCallable_Check(callback) )
break; break;
const char *_path = PyString_AsString(path); const char *_path = PyString_AsString(path);
const char *_fname = PyString_AsString(fname); const char *_fname = PyString_AsString(fname);
if (_path == NULL || _fname == NULL) if ( _path == NULL || _fname == NULL )
break; break;
char answer[MAXSTR]; char answer[MAXSTR];
answer[0] = '\0'; answer[0] = '\0';
int r = enumerate_files(answer, sizeof(answer), _path, _fname, py_enumerate_files_cb, callback); int r = enumerate_files(answer, sizeof(answer), _path, _fname, py_enumerate_files_cb, callback);
return Py_BuildValue("(is)", r, answer); return Py_BuildValue("(is)", r, answer);
} while (false); } while ( false );
Py_RETURN_NONE; Py_RETURN_NONE;
} }
//</inline(py_diskio)> //</inline(py_diskio)>

View File

@ -17,7 +17,7 @@ private:
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
bool _from_fp(FILE *fp) bool _from_fp(FILE *fp)
{ {
if (fp == NULL) if ( fp == NULL )
return false; return false;
own = false; own = false;
fn.sprnt("<FILE * %p>", fp); fn.sprnt("<FILE * %p>", fp);
@ -43,7 +43,7 @@ public:
own = true; own = true;
fn.qclear(); fn.qclear();
__idc_cvt_id__ = PY_ICID_OPAQUE; __idc_cvt_id__ = PY_ICID_OPAQUE;
if (pycobject != NULL && PyCObject_Check(pycobject)) if ( pycobject != NULL && PyCObject_Check(pycobject) )
_from_cobject(pycobject); _from_cobject(pycobject);
} }
@ -56,9 +56,9 @@ public:
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
void close() void close()
{ {
if (fp == NULL) if ( fp == NULL )
return; return;
if (own) if ( own )
qfclose(fp); qfclose(fp);
fp = NULL; fp = NULL;
own = true; own = true;
@ -75,7 +75,7 @@ public:
{ {
close(); close();
fp = qfopen(filename, mode); fp = qfopen(filename, mode);
if (fp == NULL) if ( fp == NULL )
Py_RETURN_FALSE; Py_RETURN_FALSE;
// Save file name // Save file name
fn = filename; fn = filename;
@ -86,7 +86,7 @@ public:
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
static qfile_t *from_fp(FILE *fp) static qfile_t *from_fp(FILE *fp)
{ {
if (fp == NULL) if ( fp == NULL )
return NULL; return NULL;
qfile_t *qf = new qfile_t(); qfile_t *qf = new qfile_t();
qf->own = false; qf->own = false;
@ -132,10 +132,10 @@ public:
do do
{ {
char *buf = (char *) malloc(size + 5); char *buf = (char *) malloc(size + 5);
if (buf == NULL) if ( buf == NULL )
break; break;
int r = freadbytes(fp, buf, size, big_endian); int r = freadbytes(fp, buf, size, big_endian);
if (r != 0) if ( r != 0 )
{ {
free(buf); free(buf);
break; break;
@ -143,7 +143,7 @@ public:
PyObject *ret = PyString_FromStringAndSize(buf, r); PyObject *ret = PyString_FromStringAndSize(buf, r);
free(buf); free(buf);
return ret; return ret;
} while (false); } while ( false );
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -153,10 +153,10 @@ public:
do do
{ {
char *buf = (char *) malloc(size + 5); char *buf = (char *) malloc(size + 5);
if (buf == NULL) if ( buf == NULL )
break; break;
int r = qfread(fp, buf, size); int r = qfread(fp, buf, size);
if (r <= 0) if ( r <= 0 )
{ {
free(buf); free(buf);
break; break;
@ -164,7 +164,7 @@ public:
PyObject *ret = PyString_FromStringAndSize(buf, r); PyObject *ret = PyString_FromStringAndSize(buf, r);
free(buf); free(buf);
return ret; return ret;
} while (false); } while ( false );
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -174,9 +174,9 @@ public:
do do
{ {
char *buf = (char *) malloc(size + 5); char *buf = (char *) malloc(size + 5);
if (buf == NULL) if ( buf == NULL )
break; break;
if (qfgets(buf, size, fp) == NULL) if ( qfgets(buf, size, fp) == NULL )
{ {
free(buf); free(buf);
break; break;
@ -184,7 +184,7 @@ public:
PyObject *ret = PyString_FromString(buf); PyObject *ret = PyString_FromString(buf);
free(buf); free(buf);
return ret; return ret;
} while (false); } while ( false );
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -199,7 +199,7 @@ public:
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
int write(PyObject *py_buf) int write(PyObject *py_buf)
{ {
if (!PyString_Check(py_buf)) if ( !PyString_Check(py_buf) )
return 0; return 0;
return qfwrite(fp, (void *)PyString_AS_STRING(py_buf), PyString_GET_SIZE(py_buf)); return qfwrite(fp, (void *)PyString_AS_STRING(py_buf), PyString_GET_SIZE(py_buf));
} }
@ -235,7 +235,7 @@ public:
PyObject *get_char() PyObject *get_char()
{ {
int ch = qfgetc(fp); int ch = qfgetc(fp);
if (ch == EOF) if ( ch == EOF )
Py_RETURN_NONE; Py_RETURN_NONE;
return Py_BuildValue("c", ch); return Py_BuildValue("c", ch);
} }