77 |
N_("filename: Perl script (file) to load\n" |
N_("filename: Perl script (file) to load\n" |
78 |
"Without argument, /perl command lists all loaded Perl scripts."), |
"Without argument, /perl command lists all loaded Perl scripts."), |
79 |
0, 2, weechat_cmd_perl, NULL }, |
0, 2, weechat_cmd_perl, NULL }, |
80 |
|
{ "python", N_("list/load/unload Python scripts"), |
81 |
|
N_("[load filename] | [autoload] | [unload]"), |
82 |
|
N_("filename: Python script (file) to load\n" |
83 |
|
"Without argument, /python command lists all loaded Python scripts."), |
84 |
|
0, 2, weechat_cmd_python, NULL }, |
85 |
{ "server", N_("list, add or remove servers"), |
{ "server", N_("list, add or remove servers"), |
86 |
N_("[servername] | " |
N_("[servername] | " |
87 |
"[servername hostname port [-auto | -noauto] [-pwd password] [-nicks nick1 " |
"[servername hostname port [-auto | -noauto] [-pwd password] [-nicks nick1 " |
1291 |
int |
int |
1292 |
weechat_cmd_perl (int argc, char **argv) |
weechat_cmd_perl (int argc, char **argv) |
1293 |
{ |
{ |
1294 |
#ifdef PLUGINS |
#ifdef PLUGIN_PERL |
1295 |
t_plugin_script *ptr_plugin_script; |
t_plugin_script *ptr_plugin_script; |
1296 |
t_plugin_handler *ptr_plugin_handler; |
t_plugin_handler *ptr_plugin_handler; |
1297 |
int handler_found, path_length; |
int handler_found, path_length; |
1298 |
char *path_script; |
char *path_script; |
1299 |
|
|
|
#ifdef PLUGIN_PERL |
|
1300 |
switch (argc) |
switch (argc) |
1301 |
{ |
{ |
1302 |
case 0: |
case 0: |
1422 |
(void) argv; |
(void) argv; |
1423 |
#endif /* PLUGIN_PERL */ |
#endif /* PLUGIN_PERL */ |
1424 |
|
|
1425 |
|
return 0; |
1426 |
|
} |
1427 |
|
|
1428 |
|
/* |
1429 |
|
* weechat_cmd_python: list/load/unload Python scripts |
1430 |
|
*/ |
1431 |
|
|
1432 |
|
int |
1433 |
|
weechat_cmd_python (int argc, char **argv) |
1434 |
|
{ |
1435 |
|
#ifdef PLUGIN_PYTHON |
1436 |
|
t_plugin_script *ptr_plugin_script; |
1437 |
|
t_plugin_handler *ptr_plugin_handler; |
1438 |
|
int handler_found, path_length; |
1439 |
|
char *path_script; |
1440 |
|
|
1441 |
|
switch (argc) |
1442 |
|
{ |
1443 |
|
case 0: |
1444 |
|
/* list registered Python scripts */ |
1445 |
|
gui_printf (NULL, "\n"); |
1446 |
|
gui_printf (NULL, _("Registered Python scripts:\n")); |
1447 |
|
if (python_scripts) |
1448 |
|
{ |
1449 |
|
for (ptr_plugin_script = python_scripts; ptr_plugin_script; |
1450 |
|
ptr_plugin_script = ptr_plugin_script->next_script) |
1451 |
|
{ |
1452 |
|
irc_display_prefix (NULL, PREFIX_PLUGIN); |
1453 |
|
gui_printf (NULL, " %s v%s%s%s\n", |
1454 |
|
ptr_plugin_script->name, |
1455 |
|
ptr_plugin_script->version, |
1456 |
|
(ptr_plugin_script->description[0]) ? " - " : "", |
1457 |
|
ptr_plugin_script->description); |
1458 |
|
} |
1459 |
|
} |
1460 |
|
else |
1461 |
|
{ |
1462 |
|
irc_display_prefix (NULL, PREFIX_PLUGIN); |
1463 |
|
gui_printf (NULL, _(" (none)\n")); |
1464 |
|
} |
1465 |
|
|
1466 |
|
/* list Python message handlers */ |
1467 |
|
gui_printf (NULL, "\n"); |
1468 |
|
gui_printf (NULL, _("Python message handlers:\n")); |
1469 |
|
handler_found = 0; |
1470 |
|
for (ptr_plugin_handler = plugin_msg_handlers; ptr_plugin_handler; |
1471 |
|
ptr_plugin_handler = ptr_plugin_handler->next_handler) |
1472 |
|
{ |
1473 |
|
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON) |
1474 |
|
{ |
1475 |
|
handler_found = 1; |
1476 |
|
irc_display_prefix (NULL, PREFIX_PLUGIN); |
1477 |
|
gui_printf (NULL, _(" IRC(%s) => Python(%s)\n"), |
1478 |
|
ptr_plugin_handler->name, |
1479 |
|
ptr_plugin_handler->function_name); |
1480 |
|
} |
1481 |
|
} |
1482 |
|
if (!handler_found) |
1483 |
|
{ |
1484 |
|
irc_display_prefix (NULL, PREFIX_PLUGIN); |
1485 |
|
gui_printf (NULL, _(" (none)\n")); |
1486 |
|
} |
1487 |
|
|
1488 |
|
/* list Python command handlers */ |
1489 |
|
gui_printf (NULL, "\n"); |
1490 |
|
gui_printf (NULL, _("Python command handlers:\n")); |
1491 |
|
handler_found = 0; |
1492 |
|
for (ptr_plugin_handler = plugin_cmd_handlers; ptr_plugin_handler; |
1493 |
|
ptr_plugin_handler = ptr_plugin_handler->next_handler) |
1494 |
|
{ |
1495 |
|
if (ptr_plugin_handler->plugin_type == PLUGIN_TYPE_PYTHON) |
1496 |
|
{ |
1497 |
|
handler_found = 1; |
1498 |
|
irc_display_prefix (NULL, PREFIX_PLUGIN); |
1499 |
|
gui_printf (NULL, _(" Command /%s => Python(%s)\n"), |
1500 |
|
ptr_plugin_handler->name, |
1501 |
|
ptr_plugin_handler->function_name); |
1502 |
|
} |
1503 |
|
} |
1504 |
|
if (!handler_found) |
1505 |
|
{ |
1506 |
|
irc_display_prefix (NULL, PREFIX_PLUGIN); |
1507 |
|
gui_printf (NULL, _(" (none)\n")); |
1508 |
|
} |
1509 |
|
|
1510 |
|
break; |
1511 |
|
case 1: |
1512 |
|
if (strcasecmp (argv[0], "autoload") == 0) |
1513 |
|
plugin_auto_load (PLUGIN_TYPE_PYTHON, "python/autoload"); |
1514 |
|
if (strcasecmp (argv[0], "unload") == 0) |
1515 |
|
{ |
1516 |
|
/* unload all Python scripts */ |
1517 |
|
plugin_unload (PLUGIN_TYPE_PYTHON, NULL); |
1518 |
|
irc_display_prefix (NULL, PREFIX_PLUGIN); |
1519 |
|
gui_printf (NULL, _("Python scripts unloaded\n")); |
1520 |
|
} |
1521 |
|
break; |
1522 |
|
case 2: |
1523 |
|
if (strcasecmp (argv[0], "load") == 0) |
1524 |
|
{ |
1525 |
|
/* load Python script */ |
1526 |
|
if (strstr(argv[1], DIR_SEPARATOR)) |
1527 |
|
path_script = NULL; |
1528 |
|
else |
1529 |
|
{ |
1530 |
|
path_length = strlen (weechat_home) + strlen (argv[1]) + 7; |
1531 |
|
path_script = (char *) malloc (path_length * sizeof (char)); |
1532 |
|
snprintf (path_script, path_length, "%s%s%s%s%s", |
1533 |
|
weechat_home, DIR_SEPARATOR, "python", |
1534 |
|
DIR_SEPARATOR, argv[1]); |
1535 |
|
} |
1536 |
|
plugin_load (PLUGIN_TYPE_PYTHON, |
1537 |
|
(path_script) ? path_script : argv[1]); |
1538 |
|
if (path_script) |
1539 |
|
free (path_script); |
1540 |
|
} |
1541 |
|
else |
1542 |
|
{ |
1543 |
|
irc_display_prefix (NULL, PREFIX_ERROR); |
1544 |
|
gui_printf (NULL, |
1545 |
|
_("%s unknown option for \"%s\" command\n"), |
1546 |
|
WEECHAT_ERROR, "python"); |
1547 |
|
} |
1548 |
|
break; |
1549 |
|
default: |
1550 |
|
irc_display_prefix (NULL, PREFIX_ERROR); |
1551 |
|
gui_printf (NULL, |
1552 |
|
_("%s wrong argument count for \"%s\" command\n"), |
1553 |
|
WEECHAT_ERROR, "python"); |
1554 |
|
} |
1555 |
#else |
#else |
1556 |
|
irc_display_prefix (NULL, PREFIX_ERROR); |
1557 |
|
gui_printf (NULL, |
1558 |
|
_("WeeChat was build without Python support.\n" |
1559 |
|
"Please rebuild WeeChat with " |
1560 |
|
"\"--enable-python\" option for ./configure script\n")); |
1561 |
/* make gcc happy */ |
/* make gcc happy */ |
1562 |
(void) argc; |
(void) argc; |
1563 |
(void) argv; |
(void) argv; |
1564 |
#endif /* PLUGINS */ |
#endif /* PLUGIN_PYTHON */ |
1565 |
|
|
1566 |
return 0; |
return 0; |
1567 |
} |
} |