2008-01-16 19:29:29 +01:00
|
|
|
// Copyright (c) 2008, Simone Cociancich
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// AEGISUB
|
|
|
|
//
|
|
|
|
// Website: http://aegisub.cellosoft.com
|
|
|
|
// Contact: mailto:jiifurusu@gmail.com
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2008-01-16 19:29:29 +01:00
|
|
|
#ifdef WITH_PERL
|
|
|
|
|
|
|
|
|
|
|
|
#include "auto4_perl.h"
|
|
|
|
#include "version.h"
|
|
|
|
#include "standard_paths.h"
|
2008-01-16 20:36:17 +01:00
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/utils.h>
|
2008-01-16 19:29:29 +01:00
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
|
2008-01-20 23:38:07 +01:00
|
|
|
#ifdef __VISUALC__
|
|
|
|
#pragma warning(disable: 4800)
|
2008-03-13 20:12:55 +01:00
|
|
|
#pragma warning(disable: 4706)
|
2008-01-20 23:38:07 +01:00
|
|
|
#endif
|
2008-01-16 19:29:29 +01:00
|
|
|
|
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
namespace Automation4 {
|
2008-01-16 19:29:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
// PerlScript class
|
|
|
|
//
|
|
|
|
PerlScript *PerlScript::active = NULL;
|
|
|
|
|
|
|
|
PerlScript::PerlScript(const wxString &filename):
|
|
|
|
Script(filename)
|
|
|
|
{
|
|
|
|
// Create a package name for the script
|
|
|
|
package.Printf(_T("Aegisub::Script::p%lx"), this);
|
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
// local @INC; # lol
|
2008-01-16 19:29:29 +01:00
|
|
|
inc_saved = newAV();
|
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
// Buggy
|
2008-01-16 19:29:29 +01:00
|
|
|
reload = false;
|
|
|
|
mtime = 0;
|
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
// Load the script
|
2008-01-16 19:29:29 +01:00
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
|
|
|
PerlScript::~PerlScript()
|
|
|
|
{
|
|
|
|
unload();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerlScript::Reload()
|
|
|
|
{
|
|
|
|
unload();
|
|
|
|
reload = false;
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerlScript::load()
|
|
|
|
{
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_METH(load);
|
|
|
|
wxLogTrace(wxTRACE_AutoPerl, _T("filename = '%s', package = '%s'"), GetFilename().c_str(), package.c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
|
|
|
|
// Feed some defaults into the script info
|
|
|
|
name = GetPrettyFilename().BeforeLast(_T('.'));
|
|
|
|
description = _("Perl script");
|
2008-01-16 20:36:17 +01:00
|
|
|
author = wxGetUserId();
|
2008-01-16 19:29:29 +01:00
|
|
|
version = GetAegisubShortVersionString();
|
|
|
|
|
2008-01-16 20:36:17 +01:00
|
|
|
wxFileName fn(GetFilename());
|
|
|
|
wxDateTime mod;
|
|
|
|
fn.GetTimes(NULL,&mod,NULL);
|
|
|
|
mtime = mod.GetTicks();
|
2008-01-16 19:29:29 +01:00
|
|
|
|
|
|
|
// Create the script's package
|
|
|
|
gv_stashpv(package.mb_str(wx2pl), 1);
|
|
|
|
// Set this script as active
|
|
|
|
activate(this);
|
|
|
|
|
|
|
|
// 'Enclose' the script into its package
|
|
|
|
wxString _script = _T("package ") + package + _T(";\n")
|
2008-01-26 02:24:52 +01:00
|
|
|
_T("require Aegisub; require Aegisub::Script; require Aegisub::Progress;") // Core modules
|
2008-01-16 19:29:29 +01:00
|
|
|
_T("our ($_script_reload, $_script_path, $_script_package);\n") // Internal vars
|
|
|
|
_T("our ($script_name, $script_description, $script_author, $script_version);\n") // Package info
|
|
|
|
_T("open SCRIPT, $_script_path;\n") // Open the script file
|
|
|
|
_T("local @_source = <SCRIPT>;\n") // read the source
|
|
|
|
_T("close SCRIPT;\n") // close the file
|
|
|
|
_T("eval \"@{_source}\n1;\" || die $@;"); // eval the source
|
|
|
|
|
|
|
|
// Let's eval the 'boxed' script
|
|
|
|
eval_pv(_script.mb_str(wx2pl), 0);
|
2008-01-26 02:24:52 +01:00
|
|
|
SV *_err = newSVsv(ERRSV); // We need this later
|
|
|
|
// Done running
|
|
|
|
deactivate();
|
2008-01-24 18:20:47 +01:00
|
|
|
// and check on errors
|
2008-01-26 02:24:52 +01:00
|
|
|
if(SvTRUE(_err)) {
|
|
|
|
description = wxString(SvPV_nolen(_err), pl2wx);
|
2008-01-16 19:29:29 +01:00
|
|
|
loaded = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
loaded = true;
|
|
|
|
}
|
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_RET(load);
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerlScript::unload() {
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_METH(unload);
|
|
|
|
wxLogTrace(wxTRACE_AutoPerl, _T("name = '%s' package = '%s'"), name.c_str(), package.c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
|
|
|
|
// Deinstantiate(?) all features and clear the vector
|
|
|
|
for(; !features.empty(); features.pop_back()) {
|
|
|
|
delete (Feature*) features.back();
|
|
|
|
}
|
|
|
|
features.clear();
|
|
|
|
|
|
|
|
// Dismiss the package's stash
|
|
|
|
hv_undef((HV*)gv_stashpv(package.mb_str(wx2pl), 0));
|
|
|
|
|
|
|
|
// Officially finished with unloading
|
2008-01-24 18:20:47 +01:00
|
|
|
wxLogDebug(_T("'%s' (%s) unloaded"), name.c_str(), package.c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
loaded = false;
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_RET(unload);
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerlScript::activate(PerlScript *script)
|
|
|
|
{
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_FUNC(PerlScript::activate);
|
|
|
|
wxLogTrace(wxTRACE_AutoPerl, _T("name = '%s', package = '%s'"), script->GetName().c_str(), script->GetPackage().c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
|
|
|
|
// Hooking $SIG{__WARN__}
|
2008-01-24 18:20:47 +01:00
|
|
|
wxLogTrace(wxTRACE_AutoPerl, _T("$SIG{__WARN__} = \\&Aegisub::warn"));
|
2008-01-16 19:29:29 +01:00
|
|
|
eval_pv("$SIG{__WARN__} = \\&Aegisub::warn", 1);
|
|
|
|
|
|
|
|
// Add the script's includes to @INC
|
|
|
|
AV *inc_av = get_av("main::INC", 0);
|
|
|
|
if(inc_av) {
|
|
|
|
dAV;
|
|
|
|
|
|
|
|
// Save the previous includes
|
|
|
|
AV_COPY(inc_av, script->inc_saved);
|
|
|
|
|
|
|
|
// Make room in @INC
|
|
|
|
I32 inc_count = script->include_path.GetCount();
|
|
|
|
av_unshift(inc_av, inc_count);
|
2008-01-24 18:20:47 +01:00
|
|
|
// Add the automation include paths
|
2008-01-16 19:29:29 +01:00
|
|
|
for(I32 i = 0; i < inc_count; i++) {
|
2008-01-24 18:20:47 +01:00
|
|
|
wxLogTrace(wxTRACE_AutoPerl, _T("$INC[%d] = '%s'"), i, script->include_path.Item(i).c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
AV_TOUCH(inc_av, i)
|
|
|
|
AV_STORE(newSVpv(script->include_path.Item(i).mb_str(wx2pl), 0));
|
|
|
|
}
|
2008-01-24 18:20:47 +01:00
|
|
|
wxLogDebug(_T("@INC = ( %s )"), wxString(SvPV_nolen(eval_pv("\"@INC\"", 1)), pl2wx).c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
|
|
|
else {
|
2008-01-24 18:20:47 +01:00
|
|
|
PerlLogWarning(_("Unable to add the automation include path(s) to @INC: the script's code may not compile or execute properly."));
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the values of script vars
|
|
|
|
script->WriteVars();
|
2008-01-24 18:20:47 +01:00
|
|
|
|
2008-01-16 19:29:29 +01:00
|
|
|
active = script;
|
2008-01-24 18:20:47 +01:00
|
|
|
wxLogDebug(_T("'%s' (%p) activated"), active->GetName().c_str(), active);
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerlScript::deactivate()
|
|
|
|
{
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_FUNC(PerlScript::deactivate);
|
|
|
|
wxLogTrace(wxTRACE_AutoPerl, _T("name = '%s', package = '%s'"), active->GetName().c_str(), active->GetPackage().c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
|
|
|
|
// Revert @INC to its value before the script activation
|
|
|
|
AV *inc_av = get_av("main::INC", 0);
|
|
|
|
if(inc_av) {
|
|
|
|
dAV;
|
|
|
|
|
|
|
|
// Reset @INC
|
|
|
|
if(av_len(active->inc_saved) >= 0) {
|
|
|
|
// If there's a saved one
|
|
|
|
AV_COPY(active->inc_saved, inc_av);
|
2008-01-24 18:20:47 +01:00
|
|
|
wxLogDebug(_T("@INC = ( %s )"), wxString(SvPV_nolen(eval_pv("\"@INC\"", 1)), pl2wx).c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
av_clear(active->inc_saved);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the values of script vars
|
|
|
|
active->ReadVars();
|
|
|
|
|
2008-02-03 20:21:02 +01:00
|
|
|
// If reload flag is set...
|
|
|
|
/* STILL BROKEN :< */
|
|
|
|
if(active->reload) {
|
|
|
|
// check if the source file on disk changed
|
|
|
|
wxFileName fn(active->GetFilename());
|
|
|
|
wxDateTime mod;
|
|
|
|
fn.GetTimes(NULL,&mod,NULL);
|
|
|
|
if(active->mtime != mod.GetTicks()) {
|
|
|
|
// and reload the script
|
|
|
|
PerlLogVerbose(wxString::Format(_("Reloading %s because the file on disk (%s) changed."), active->GetName().c_str(), active->GetFilename().c_str()));
|
|
|
|
active->Reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
// Unhooking $SIG{__WARN__}
|
|
|
|
wxLogTrace(wxTRACE_AutoPerl, _T("undef $SIG{__WARN__}"));
|
2008-01-16 19:29:29 +01:00
|
|
|
eval_pv("undef $SIG{__WARN__}", 1);
|
|
|
|
|
2008-01-16 19:41:59 +01:00
|
|
|
wxLogDebug(_T("%s(%p) deactivated"), active->GetName().c_str(), active);
|
2008-01-16 19:29:29 +01:00
|
|
|
active = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerlScript::AddFeature(Feature *feature)
|
|
|
|
{
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_METH(AddFeature);
|
2008-01-16 19:29:29 +01:00
|
|
|
features.push_back(feature);
|
2008-01-24 18:20:47 +01:00
|
|
|
wxLogDebug(_T("Added '%s' to '%s'(%s)'s features"), feature->GetName().c_str(), name.c_str(), package.c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerlScript::DeleteFeature(Feature *feature)
|
|
|
|
{
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_METH(DeleteFeature);
|
2008-01-16 19:29:29 +01:00
|
|
|
for(std::vector<Feature*>::iterator it = features.begin(); it != features.end(); it++)
|
|
|
|
if(*it == feature) {
|
|
|
|
delete feature;
|
2008-01-24 18:20:47 +01:00
|
|
|
wxLogDebug(_T("Deleted '%s' from '%s'(%s)'s features"), feature->GetName().c_str(), name.c_str(), package.c_str());
|
2008-01-16 19:29:29 +01:00
|
|
|
features.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerlScript::ReadVars()
|
|
|
|
{
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_METH(ReadVars);
|
2008-01-16 19:29:29 +01:00
|
|
|
// This will get anything inside it °_°
|
|
|
|
SV *whore = NULL;
|
|
|
|
// All the vars' names will stick to it #_#
|
|
|
|
wxString bitch;
|
|
|
|
|
|
|
|
bitch = package + _T("::script_name");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 0);
|
|
|
|
if(whore) name = wxString(SvPV_nolen(whore), pl2wx);
|
|
|
|
|
|
|
|
bitch = package + _T("::script_description");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 0);
|
|
|
|
if(whore) description = wxString(SvPV_nolen(whore), pl2wx);
|
|
|
|
|
|
|
|
bitch = package + _T("::script_author");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 0);
|
|
|
|
if(whore) author = wxString(SvPV_nolen(whore), pl2wx);
|
|
|
|
|
|
|
|
bitch = package + _T("::script_version");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 0);
|
|
|
|
if(whore) version = wxString(SvPV_nolen(whore), pl2wx);
|
|
|
|
|
2008-02-03 20:21:02 +01:00
|
|
|
//bitch = package + _T("::_script_reload");
|
|
|
|
//whore = get_sv(bitch.mb_str(wx2pl), 0);
|
|
|
|
//if(whore) reload = SvTRUE(whore);
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerlScript::WriteVars() const
|
|
|
|
{
|
2008-01-24 18:20:47 +01:00
|
|
|
wxTRACE_METH(WriteVars);
|
2008-01-16 19:29:29 +01:00
|
|
|
// Somewhat as above
|
|
|
|
SV *whore = NULL;
|
|
|
|
wxString bitch;
|
|
|
|
|
|
|
|
bitch = package + _T("::_script_package");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 1);
|
|
|
|
sv_setpv(whore, package.mb_str(wx2pl));
|
|
|
|
|
|
|
|
bitch = package + _T("::_script_path");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 1);
|
|
|
|
sv_setpv(whore, GetFilename().mb_str(wx2pl));
|
|
|
|
|
|
|
|
bitch = package + _T("::_script_reload");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 1);
|
|
|
|
sv_setiv(whore, int(reload));
|
|
|
|
|
|
|
|
bitch = package + _T("::script_name");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 1);
|
|
|
|
sv_setpv(whore, name.mb_str(wx2pl));
|
|
|
|
|
|
|
|
bitch = package + _T("::script_description");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 1);
|
|
|
|
sv_setpv(whore, description.mb_str(wx2pl));
|
|
|
|
|
|
|
|
bitch = package + _T("::script_author");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 1);
|
|
|
|
sv_setpv(whore, author.mb_str(wx2pl));
|
|
|
|
|
|
|
|
bitch = package + _T("::script_version");
|
|
|
|
whore = get_sv(bitch.mb_str(wx2pl), 1);
|
|
|
|
sv_setpv(whore, version.mb_str(wx2pl));
|
|
|
|
}
|
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
// PerlFeatureMacro
|
|
|
|
//
|
|
|
|
|
|
|
|
PerlFeatureMacro::PerlFeatureMacro(const wxString &name, const wxString &description, PerlScript *own_script, SV *proc_sub, SV *val_sub):
|
|
|
|
Feature(SCRIPTFEATURE_MACRO, name),
|
|
|
|
FeatureMacro(name, description)
|
2008-01-16 19:29:29 +01:00
|
|
|
{
|
2008-01-24 18:20:47 +01:00
|
|
|
// We know what script we belong to ^_^
|
|
|
|
script = own_script;
|
|
|
|
|
|
|
|
// And not surprisingly we have some callbacks too
|
|
|
|
processing_sub = newSVsv(proc_sub);
|
|
|
|
validation_sub = newSVsv(val_sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
PerlFeatureMacro::~PerlFeatureMacro() {
|
|
|
|
// The macro subroutines get undefined
|
|
|
|
CV *cv = Nullcv;
|
|
|
|
HV *hv = NULL;
|
|
|
|
GV *gv = NULL;
|
|
|
|
if(processing_sub) {
|
|
|
|
cv = sv_2cv(processing_sub, &hv, &gv, 1);
|
|
|
|
cv_undef(cv);
|
|
|
|
if(hv) hv_undef(hv);
|
|
|
|
}
|
|
|
|
if(validation_sub) {
|
|
|
|
cv = sv_2cv(validation_sub, &hv, &gv, 1);
|
|
|
|
cv_undef(cv);
|
|
|
|
if(hv) hv_undef(hv);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool PerlFeatureMacro::Validate(AssFile *subs, const std::vector<int> &selected, int active)
|
|
|
|
{
|
|
|
|
// If there's no validation subroutine defined simply return true
|
|
|
|
if(!validation_sub) return true;
|
|
|
|
// otherwise...
|
|
|
|
|
|
|
|
// Sub lines
|
|
|
|
AV *lines = PerlAss::MakeHasshLines(NULL, subs);
|
|
|
|
// Selection array
|
|
|
|
AV *selected_av = newAV();
|
|
|
|
VECTOR_AV(selected, selected_av, int, iv);
|
|
|
|
|
|
|
|
// Activate the owner script
|
|
|
|
script->Activate();
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
int c = 0;
|
2008-01-16 19:29:29 +01:00
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
// Prepare the stack
|
|
|
|
dSP;
|
|
|
|
|
|
|
|
ENTER;
|
|
|
|
SAVETMPS;
|
|
|
|
|
|
|
|
// Push the parameters on the stack
|
|
|
|
PUSHMARK(SP);
|
|
|
|
XPUSHs(sv_2mortal(newRV_noinc((SV*)lines)));
|
|
|
|
XPUSHs(sv_2mortal(newRV_noinc((SV*)selected_av)));
|
|
|
|
XPUSHs(sv_2mortal(newSViv(active)));
|
|
|
|
PUTBACK;
|
|
|
|
|
|
|
|
// Call back the callback
|
|
|
|
c = call_sv(validation_sub, G_EVAL | G_SCALAR);
|
|
|
|
SPAGAIN;
|
|
|
|
|
|
|
|
if(SvTRUE(ERRSV)) {
|
|
|
|
wxLogVerbose(wxString(SvPV_nolen(ERRSV), pl2wx));
|
|
|
|
ret = false;
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
2008-01-24 18:20:47 +01:00
|
|
|
else {
|
|
|
|
SV *wtf = sv_mortalcopy(POPs);
|
|
|
|
ret = SvTRUE(wtf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tidy up everything
|
|
|
|
PUTBACK;
|
|
|
|
FREETMPS;
|
|
|
|
LEAVE;
|
|
|
|
|
|
|
|
// Deactivate the script
|
|
|
|
script->Deactivate();
|
|
|
|
|
|
|
|
return ret;
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
|
|
|
|
2008-01-24 18:20:47 +01:00
|
|
|
void PerlFeatureMacro::Process(AssFile *subs, std::vector<int> &selected, int active, wxWindow * const progress_parent)
|
2008-01-16 19:29:29 +01:00
|
|
|
{
|
2008-01-27 02:22:01 +01:00
|
|
|
/* TODO: extend the progress window 'coverage' */
|
2008-01-24 18:20:47 +01:00
|
|
|
// Convert the AssFile::Line to perl stuff
|
|
|
|
AV *lines = PerlAss::MakeHasshLines(NULL, subs);
|
|
|
|
// Same with the selection array
|
|
|
|
AV *selected_av = newAV();
|
|
|
|
VECTOR_AV(selected, selected_av, int, iv);
|
|
|
|
|
|
|
|
// Prepare the stack
|
|
|
|
dSP;
|
|
|
|
ENTER;
|
|
|
|
SAVETMPS;
|
|
|
|
|
2008-02-03 20:21:02 +01:00
|
|
|
// Push the arguments onto the stack
|
2008-01-24 18:20:47 +01:00
|
|
|
PUSHMARK(SP);
|
2008-02-03 20:21:02 +01:00
|
|
|
SV* lines_ref = sv_2mortal(newRV_noinc((SV*)lines));
|
|
|
|
XPUSHs(lines_ref);
|
|
|
|
SV* selected_ref = sv_2mortal(newRV_noinc((SV*)selected_av));
|
|
|
|
XPUSHs(selected_ref);
|
2008-01-24 18:20:47 +01:00
|
|
|
XPUSHs(sv_2mortal(newSViv(active)));
|
|
|
|
PUTBACK;
|
|
|
|
|
|
|
|
// Create a progress window
|
|
|
|
PerlProgressSink *ps = new PerlProgressSink(progress_parent, GetName());
|
|
|
|
// Start the callback thread
|
2008-02-03 20:21:02 +01:00
|
|
|
script->Activate();
|
2008-01-24 18:20:47 +01:00
|
|
|
PerlThread call(processing_sub, G_EVAL | G_VOID);
|
2008-02-03 20:21:02 +01:00
|
|
|
// Show the progress window until it is dismissed
|
2008-01-24 18:20:47 +01:00
|
|
|
ps->ShowModal();
|
|
|
|
// Now wait the thread to return
|
|
|
|
call.Wait();
|
2008-02-03 20:21:02 +01:00
|
|
|
script->Deactivate();
|
2008-01-24 18:20:47 +01:00
|
|
|
|
|
|
|
if(!SvTRUE(ERRSV)) {
|
2008-02-03 20:21:02 +01:00
|
|
|
// Show progress sink again
|
|
|
|
ps->Show(true);
|
|
|
|
ps->SetTask(_("Saving changes"));
|
|
|
|
|
|
|
|
// Recreate the ass :S
|
2008-01-24 18:20:47 +01:00
|
|
|
subs->FlagAsModified(GetName());
|
2008-02-03 20:21:02 +01:00
|
|
|
PerlAss::MakeAssLines(subs, (AV*)SvRV(lines_ref));
|
2008-01-24 18:20:47 +01:00
|
|
|
// And reset selection vector
|
|
|
|
selected.clear();
|
2008-02-03 20:21:02 +01:00
|
|
|
AV_VECTOR((AV*)SvRV(selected_ref), selected, IV);
|
2008-01-24 18:20:47 +01:00
|
|
|
CHOP_SELECTED(subs, selected);
|
2008-02-03 20:21:02 +01:00
|
|
|
|
|
|
|
ps->Hide();
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
2008-02-03 20:21:02 +01:00
|
|
|
// Delete the progress sink
|
|
|
|
ps->Destroy();
|
2008-01-24 18:20:47 +01:00
|
|
|
|
2008-02-03 20:21:02 +01:00
|
|
|
// Clean the call stack
|
2008-01-24 18:20:47 +01:00
|
|
|
FREETMPS;
|
|
|
|
LEAVE;
|
2008-01-16 19:29:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //WITH_PERL
|