Ruby: fixes in debug output & file including

Originally committed to SVN as r917.
This commit is contained in:
pomyk 2007-01-31 17:52:12 +00:00
parent 66b91c41c3
commit 17088eb723
3 changed files with 30 additions and 197 deletions

View File

@ -122,8 +122,13 @@ namespace Automation4 {
rb_define_module_function(RubyScript::RubyAegisub, "progress_set",reinterpret_cast<RB_HOOK>(&RubyProgressSink::RubySetProgress), 1);
rb_define_module_function(RubyScript::RubyAegisub, "progress_task",reinterpret_cast<RB_HOOK>(&RubyProgressSink::RubySetTask), 1);
rb_define_module_function(RubyScript::RubyAegisub, "progress_title",reinterpret_cast<RB_HOOK>(&RubyProgressSink::RubySetTitle), 1);
rb_define_module_function(RubyScript::RubyAegisub, "debug_out",reinterpret_cast<RB_HOOK>(&RubyProgressSink::RubyDebugOut), 1);
rb_define_module_function(RubyScript::RubyAegisub, "debug_out",reinterpret_cast<RB_HOOK>(&RubyProgressSink::RubyDebugOut), -1);
rb_define_module_function(RubyScript::RubyAegisub, "get_cancelled",reinterpret_cast<RB_HOOK>(&RubyProgressSink::RubyGetCancelled), 0);
VALUE paths = rb_gv_get("$:");
for(int i = 0; i < include_path.GetCount(); i++)
{
rb_ary_push(paths, rb_str_new2(include_path[i].mb_str(wxConvISO8859_1)));
}
int status = 0;
wxCharBuffer buf = GetFilename().mb_str(wxConvISO8859_1);
@ -136,12 +141,16 @@ namespace Automation4 {
}
VALUE global_var = rb_gv_get("$script_name");
if(TYPE(global_var) == T_STRING)
name = wxString(StringValueCStr(global_var), wxConvUTF8);
global_var = rb_gv_get("$script_description");
if(TYPE(global_var) == T_STRING)
description = wxString(StringValueCStr(global_var), wxConvUTF8);
global_var = rb_gv_get("$script_author");
if(TYPE(global_var) == T_STRING)
author = wxString(StringValueCStr(global_var), wxConvUTF8);
global_var = rb_gv_get("$script_version");
if(TYPE(global_var) == T_STRING)
version = wxString(StringValueCStr(global_var), wxConvUTF8);
loaded = true;
}
@ -304,12 +313,12 @@ namespace Automation4 {
if(result != Qnil && result != Qfalse)
{
subsobj->RubyUpdateAssFile(result);
RubyProgressSink::inst->script_finished = true;
}
} catch (const char* e) {
wxString *err = new wxString(e, wxConvUTF8);
wxMessageBox(*err, _T("Error running macro"),wxICON_ERROR | wxOK);
}
RubyProgressSink::inst->script_finished = true;
}
@ -361,12 +370,12 @@ namespace Automation4 {
if(result != Qnil && result != Qfalse)
{
subsobj->RubyUpdateAssFile(result);
RubyProgressSink::inst->script_finished = true;
}
} catch (const char* e) {
wxString *err = new wxString(e, wxConvUTF8);
wxMessageBox(*err, _T("Error running filter"),wxICON_ERROR | wxOK);
}
RubyProgressSink::inst->script_finished = true;
}
ScriptConfigDialog* RubyFeatureFilter::GenerateConfigDialog(wxWindow *parent)
@ -442,9 +451,15 @@ namespace Automation4 {
return Qfalse;
}
VALUE RubyProgressSink::RubyDebugOut(VALUE self, VALUE msg)
VALUE RubyProgressSink::RubyDebugOut(int argc, VALUE *args, VALUE self)
{
wxString _m(StringValueCStr(msg), wxConvUTF8);
if(argc > 1 && TYPE(args[0]) == T_FIXNUM)
{
if(FIX2INT(args[0]) > RubyProgressSink::inst->trace_level)
return Qnil;
}
else args[1] = args[0];
wxString _m(StringValueCStr(args[1]), wxConvUTF8);
RubyProgressSink::inst->AddDebugOutput(_m);
RubyProgressSink::inst->DoUpdateDisplay();
wxSafeYield(RubyProgressSink::inst);
@ -519,38 +534,7 @@ namespace Automation4 {
{
recv = _recv;
};
typedef struct run_safely_arg {
VALUE (*func)(void);
void *arg;
} run_safely_arg_t;
static VALUE run_safely_0(void *arg)
{
run_safely_arg_t *rsarg = (run_safely_arg_t *) arg;
VALUE result;
result = (*rsarg->func)();
return result;
}
static int run_safely(VALUE (*func)(void), void *arg, VALUE *retval)
{
VALUE thread, ret;
run_safely_arg_t rsarg;
int state;
rsarg.func = func;
rsarg.arg = arg;
#if defined(HAVE_SETITIMER)
rb_thread_start_timer();
#endif
thread = rb_thread_create(reinterpret_cast<RB_HOOK>(&run_safely_0), &rsarg);
rb_thread_kill(thread);
#if defined(HAVE_SETITIMER)
rb_thread_stop_timer();
#endif
if (retval)
*retval = ret;
return state;
}
VALUE rbCallWrapper(VALUE arg)
{
RubyCallArguments &a = *reinterpret_cast<RubyCallArguments*>(arg);

View File

@ -66,7 +66,6 @@ namespace Automation4 {
bool can_modify;
bool can_set_undo;
//void CheckAllowModify(); // throws an error if modification is disallowed
// keep a cursor of last accessed item to avoid walking over the entire file on every access
std::list<AssEntry*>::iterator last_entry_ptr;
@ -75,7 +74,6 @@ namespace Automation4 {
static int RubyParseTagData();
static int RubyUnparseTagData();
static int RubyParseKaraokeData();
static int RubySetUndoPoint();
~RubyAssFile();
@ -104,7 +102,7 @@ namespace Automation4 {
static VALUE RubySetTask(VALUE self, VALUE task);
static VALUE RubySetTitle(VALUE self, VALUE title);
static VALUE RubyGetCancelled(VALUE self);
static VALUE RubyDebugOut(VALUE self, VALUE msg);
static VALUE RubyDebugOut(int argc, VALUE *args, VALUE self);
};

View File

@ -47,13 +47,6 @@ namespace Automation4 {
// LuaAssFile
/* void RubyAssFile::CheckAllowModify()
{
if (can_modify)
return;
rb_raise(rb_eRuntimeError, "Attempt to modify subtitles in read-only feature context.");
}
*/
VALUE RubyAssFile::AssEntryToRuby(AssEntry *e)
{
VALUE ass_entry;
@ -377,7 +370,7 @@ namespace Automation4 {
if(status == 0) ass->Line.push_back(new_entry);
else {
if(RubyProgressSink::inst)
RubyProgressSink::inst->RubyDebugOut(Qnil, ruby_errinfo);
RubyProgressSink::inst->RubyDebugOut(1, &ruby_errinfo, Qnil);
ruby_errinfo = Qnil; // clear the error
}
}
@ -396,153 +389,12 @@ namespace Automation4 {
return 1;
}
int RubyAssFile::RubyParseKaraokeData()
{
/* AssEntry *e = RubyToAssEntry(L);
if (e->GetType() != ENTRY_DIALOGUE) {
delete e;
lua_pushstring(L, "Attempt to create karaoke table from non-dialogue subtitle line");
lua_error(L);
return 0;
}
AssDialogue *dia = e->GetAsDialogue(e);
dia->ParseASSTags();
int kcount = 0;
int kdur = 0;
int ktime = 0;
wxString ktag = _T("");
wxString ktext = _T("");
wxString ktext_stripped = _T("");
lua_newtable(L);
for (int i = 0; i < (int)dia->Blocks.size(); i++) {
AssDialogueBlock *block = dia->Blocks[i];
switch (block->type) {
case BLOCK_BASE:
assert(block->type != BLOCK_BASE);
break;
case BLOCK_PLAIN:
ktext += block->text;
ktext_stripped += block->text;
break;
case BLOCK_DRAWING:
// a drawing is regarded as a kind of control code here, so it's just stripped away
ktext += block->text;
break;
case BLOCK_OVERRIDE: {
bool brackets_open = false;
AssDialogueBlockOverride *ovr = block->GetAsOverride(block);
for (int j = 0; j < (int)ovr->Tags.size(); j++) {
AssOverrideTag *tag = ovr->Tags[j];
if (tag->IsValid() && tag->Name.Mid(0,2).CmpNoCase(_T("\\k")) == 0) {
// karaoke tag
if (brackets_open) {
ktext += _T("}");
brackets_open = false;
}
// store to lua
lua_newtable(L);
lua_pushnumber(L, kdur);
lua_setfield(L, -2, "duration");
lua_pushnumber(L, ktime);
lua_setfield(L, -2, "start_time");
lua_pushnumber(L, ktime+kdur);
lua_setfield(L, -2, "end_time");
lua_pushstring(L, ktag.mb_str(wxConvUTF8));
lua_setfield(L, -2, "tag");
lua_pushstring(L, ktext.mb_str(wxConvUTF8));
lua_setfield(L, -2, "text");
lua_pushstring(L, ktext_stripped.mb_str(wxConvUTF8));
lua_setfield(L, -2, "text_stripped");
lua_rawseti(L, -2, kcount);
// prepare new syllable
kcount++;
ktag = tag->Name.Mid(1);
// check if it's a "set time" tag, special handling for that (depends on previous syllable duration)
if (ktag == _T("kt")) {
ktime = tag->Params[0]->AsInt() * 10;
kdur = 0;
} else {
ktime += kdur; // duration of previous syllable
kdur = tag->Params[0]->AsInt() * 10;
}
ktext.clear();
ktext_stripped.clear();
} else {
// not karaoke tag
if (!brackets_open) {
ktext += _T("{");
brackets_open = true;
}
ktext += tag->ToString();
}
}
if (brackets_open) {
ktext += _T("}");
brackets_open = false;
}
break;}
}
}
dia->ClearBlocks();
// store final syllable/block to lua
lua_newtable(L);
lua_pushnumber(L, kdur);
lua_setfield(L, -2, "duration");
lua_pushnumber(L, ktime);
lua_setfield(L, -2, "start_time");
lua_pushnumber(L, ktime+kdur);
lua_setfield(L, -2, "end_time");
lua_pushstring(L, ktag.mb_str(wxConvUTF8));
lua_setfield(L, -2, "tag");
lua_pushstring(L, ktext.mb_str(wxConvUTF8));
lua_setfield(L, -2, "text");
lua_pushstring(L, ktext_stripped.mb_str(wxConvUTF8));
lua_setfield(L, -2, "text_stripped");
lua_rawseti(L, -2, kcount);
delete dia;*/
return 1;
}
int RubyAssFile::RubySetUndoPoint()
{
/* RubyAssFile *laf = GetObjPointer(L, lua_upvalueindex(1));
if (!laf->can_set_undo) {
lua_pushstring(L, "Attempt to set an undo point in a context without undo-support.");
lua_error(L);
return 0;
}
wxString description;
if (lua_isstring(L, 1)) {
description = wxString(lua_tostring(L, 1), wxConvUTF8);
lua_pop(L, 1);
}
AssFile::top->FlagAsModified(); // TODO: make undo system support description of action undone
laf->ass = AssFile::top; // make sure we're still working on the most recent undo point
*/ return 0;
}
RubyAssFile::~RubyAssFile()
{
RubyObjects::Get()->Unregister(rbAssFile);
@ -568,15 +420,14 @@ namespace Automation4 {
if(status == 0) rb_ary_push(rbAssFile, res);
else {
if(RubyProgressSink::inst)
RubyProgressSink::inst->RubyDebugOut(Qnil, ruby_errinfo);
RubyProgressSink::inst->RubyDebugOut(1, &ruby_errinfo, Qnil);
ruby_errinfo = Qnil;
}
}
// TODO
rb_define_module_function(RubyScript::RubyAegisub, "parse_tag_data",reinterpret_cast<RB_HOOK>(&RubyParseTagData), 1);
rb_define_module_function(RubyScript::RubyAegisub, "unparse_tag_data",reinterpret_cast<RB_HOOK>(&RubyUnparseTagData), 1);
rb_define_module_function(RubyScript::RubyAegisub, "parse_karaoke_data",reinterpret_cast<RB_HOOK>(&RubyParseKaraokeData), 1);
//rb_define_module_function(RubyScript::RubyAegisub, "parse_tag_data",reinterpret_cast<RB_HOOK>(&RubyParseTagData), 1);
//rb_define_module_function(RubyScript::RubyAegisub, "unparse_tag_data",reinterpret_cast<RB_HOOK>(&RubyUnparseTagData), 1);
//rb_define_module_function(RubyScript::RubyAegisub, "set_undo_point",reinterpret_cast<RB_HOOK>(&RubySetUndoPoint), 1);
}