python.cpp: Indentation consistency and misc formatting fixes

This commit is contained in:
gergely.erdelyi 2009-05-22 15:59:38 +00:00
parent 260c813f05
commit ef9921587b

View File

@ -147,16 +147,13 @@ static error_t idaapi idc_runpythonstatement(idc_value_t *argv, idc_value_t *res
return eOk;
}
/* QuickFix for the FILE* incompatibility problem */
int ExecFile(const char *FileName)
{
PyObject* PyFileObject = PyFile_FromString((char*)FileName, "r");
if (!PyFileObject)
{
return 0;
}
if (PyRun_SimpleFile(PyFile_AsFile(PyFileObject), FileName) == 0)
{
@ -203,9 +200,7 @@ void IDAPython_RunScript(char *script)
int i;
if (script)
{
scriptpath = script;
}
else
{
scriptpath = askfile_c(0, "*.py", "Python file to run");
@ -220,15 +215,10 @@ void IDAPython_RunScript(char *script)
for (i=0; scriptpath[i]; i++)
{
if (scriptpath[i] == '\\')
{
slashpath[i] = '/';
}
else
{
slashpath[i] = scriptpath[i];
}
}
slashpath[i] = '\0';
/* Add the script't path to sys.path */
@ -239,13 +229,10 @@ void IDAPython_RunScript(char *script)
/* Error handling */
if (PyErr_Occurred())
{
PyErr_Print();
}
}
/* Execute Python statement(s) from an editor window */
/* Default hotkey: Alt-8 */
void IDAPython_RunStatement(void)
@ -258,9 +245,7 @@ void IDAPython_RunStatement(void)
/* Fetch the previous statement */
if (history.supval(IDAPYTHON_DATA_STATEMENT, statement, sizeof(statement)) == -1)
{
statement[0] = '\0';
}
if (asktext(sizeof(statement), statement, statement, "Enter Python expressions"))
{
@ -311,10 +296,8 @@ void IDAPython_ScriptBox(void)
{
/* Print the exception info */
if (PyErr_Occurred())
{
PyErr_Print();
}
}
}
bool idaapi IDAPython_Menu_Callback(void *ud)
@ -345,10 +328,8 @@ static void handle_python_error(char *errbuf, size_t errbufsize)
Py_XDECREF(ptraceback);
}
else
{
PyErr_Print();
}
}
}
/* Convert return value from Python to IDC or report about an error */
@ -378,9 +359,7 @@ static bool return_python_result(idc_value_t *rv,
{
rv->str = (char *)qalloc(PyString_Size(result)+1);
if (!rv->str)
{
return false;
}
qstrncpy(rv->str, PyString_AsString(result), MAXSTR);
rv->vtype = VT_STR;
Py_XDECREF(result);
@ -425,7 +404,7 @@ bool idaapi IDAPython_extlang_compile(const char *name,
PyObject *func = PyFunction_New((PyObject *)code, globals);
if (func == NULL)
{
ERR:
ERR:
handle_python_error(errbuf, errbufsize);
Py_XDECREF(code);
return false;
@ -458,16 +437,13 @@ bool idaapi IDAPython_extlang_run(const char *name,
case VT_LONG:
pa = PyInt_FromLong(args[i].num);
break;
case VT_STR:
pa = PyString_FromString(args[i].str);
break;
case VT_FLOAT:
ieee_realcvt(&dresult, (ushort *)args[i].e, 013);
pa = PyFloat_FromDouble(dresult);
break;
default:
qsnprintf(errbuf, errbufsize, "arg#%d has wrong type %d", i, args[i].vtype);
return false;
@ -537,7 +513,7 @@ bool idaapi IDAPython_extlang_calcexpr(ea_t /*current_ea*/,
}
extlang_t extlang_python =
{
{
sizeof(extlang_t),
0,
"Python",
@ -546,7 +522,7 @@ extlang_t extlang_python =
IDAPython_extlang_calcexpr,
IDAPython_extlang_compile_file,
"py"
};
};
void enable_extlang_python(bool enable)
{
@ -569,7 +545,7 @@ bool idaapi IDAPython_cli_execute_line(const char *line)
}
cli_t cli_python =
{
{
sizeof(cli_t),
0,
"Python",
@ -578,19 +554,15 @@ cli_t cli_python =
IDAPython_cli_execute_line,
NULL,
NULL
};
};
/* Control the Python CLI status */
void enable_python_cli(bool enable)
{
if (enable)
{
install_command_interpreter(&cli_python);
}
else
{
remove_command_interpreter(&cli_python);
}
}
#endif
@ -604,9 +576,7 @@ bool IDAPython_Init(void)
/* Already initialized? */
if (initialized == 1)
{
return true;
}
/* Check for the presence of essential files */
initialized = 0;
@ -615,11 +585,8 @@ bool IDAPython_Init(void)
result &= CheckFile("init.py");
result &= CheckFile("idaapi.py");
result &= CheckFile("idautils.py");
if (!result)
{
return false;
}
#ifdef __LINUX__
/* Export symbols from libpython to resolve imported module deps */
@ -651,7 +618,6 @@ bool IDAPython_Init(void)
VER_PATCH,
VER_STATUS,
VER_SERIAL);
PyRun_SimpleString(tmp);
#if IDP_INTERFACE_VERSION >= 75
@ -676,11 +642,8 @@ bool IDAPython_Init(void)
/* Batch-mode operation: */
/* A script specified on the command line is run */
options = (char *)get_plugin_options("IDAPython");
if (options)
{
IDAPython_RunScript(options);
}
/* Add menu items for all the functions */
/* Different paths are used for the GUI version */
@ -689,31 +652,27 @@ bool IDAPython_Init(void)
(menu_item_callback_t *)IDAPython_Menu_Callback,
(void *)IDAPYTHON_RUNSTATEMENT);
/* Add Load Python file menu item*/
result = add_menu_item("File/Load file/IDC file...", "P~y~thon file...",
"Alt-9", SETMENU_APP,
(menu_item_callback_t *)IDAPython_Menu_Callback,
(void *)IDAPYTHON_RUNFILE);
if (!result)
{
add_menu_item("File/IDC command...", "P~y~thon file...",
"Alt-9", SETMENU_APP,
(menu_item_callback_t *)IDAPython_Menu_Callback,
(void *)IDAPYTHON_RUNFILE);
}
/* Add View Python Scripts menu item*/
result = add_menu_item("View/Open subviews/Show strings", "Python S~c~ripts",
"Alt-7", SETMENU_APP,
(menu_item_callback_t *)IDAPython_Menu_Callback,
(void *)IDAPYTHON_SCRIPTBOX);
if (!result)
{
add_menu_item("View/Open subviews/Problems", "Python S~c~ripts",
"Alt-7", SETMENU_APP,
(menu_item_callback_t *)IDAPython_Menu_Callback,
(void *)IDAPYTHON_SCRIPTBOX);
}
/* Register a RunPythonStatement() function for IDC */
set_idc_func("RunPythonStatement", idc_runpythonstatement, idc_runpythonstatement_args);
@ -821,22 +780,17 @@ char wanted_hotkey[] = "Alt-9";
extern "C"
{
plugin_t PLUGIN = {
plugin_t PLUGIN = {
IDP_INTERFACE_VERSION,
0, // plugin flags
init, // initialize
term, // terminate. this pointer may be NULL.
run, // invoke plugin
comment, // long comment about the plugin
// it could appear in the status line
// or as a hint
help, // multiline help about the plugin
wanted_name, // the preferred short name of the plugin
wanted_hotkey // the preferred hotkey to run the plugin
};
};
}