From 7cff10cf5bdaa5fc399e9ada5a55c638f4d163c4 Mon Sep 17 00:00:00 2001
From: shb <shb@none>
Date: Sat, 26 Jan 2008 01:24:52 +0000
Subject: [PATCH] Fixed bugs in autoperl: entry's class recognition misreading
 comments as key:value; crash if core modules are not found; description not
 set after script loading failure.

Originally committed to SVN as r1841.
---
 aegisub/auto4_perl.cpp        |  8 ++++----
 aegisub/auto4_perl_ass.cpp    | 16 +++++++---------
 aegisub/auto4_perl_script.cpp | 17 +++++++++--------
 3 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/aegisub/auto4_perl.cpp b/aegisub/auto4_perl.cpp
index d35cdfa35..f7b6d6bc3 100644
--- a/aegisub/auto4_perl.cpp
+++ b/aegisub/auto4_perl.cpp
@@ -57,8 +57,8 @@ namespace Automation4 {
 // Perl -> C++ interface (XSUBS)
 //
 
-  /* Aegisub */
-  XS(perl_log)  // Aegisub::log()
+  /* package Aegisub */
+  XS(perl_log)
   {
 	wxTRACE_FUNC(Aegisub::log);
 	dXSARGS;
@@ -74,7 +74,7 @@ namespace Automation4 {
 	PerlLog(level, msg);
   }
 
-  XS(perl_warning)  // Aegisub::warn()
+  XS(perl_warning)
   {
 	wxTRACE_FUNC(Aegisub::warn);
 	dXSARGS;
@@ -87,7 +87,7 @@ namespace Automation4 {
   }
 
 
-  XS(perl_text_extents)  // Aegisub::text_extents
+  XS(perl_text_extents)
   {
 	wxTRACE_FUNC(Aegisub::text_extents);
 	dXSARGS;
diff --git a/aegisub/auto4_perl_ass.cpp b/aegisub/auto4_perl_ass.cpp
index 009e3aab0..3e1c6d252 100644
--- a/aegisub/auto4_perl_ass.cpp
+++ b/aegisub/auto4_perl_ass.cpp
@@ -84,16 +84,14 @@ namespace Automation4 {
 	case ENTRY_ATTACHMENT: return _T("attachment");
 	default:
 	case ENTRY_BASE:
-	  wxString data(entry->GetEntryData());
-	  if(entry->group == _T("[Script Info]") && data.Matches(_T("*:*"))) return _T("info"); 
-		
-	  if(data == entry->group) return _T("head");
-	  
-	  if(data.StartsWith(_T("Format:"))) return _T("format");
-	  
-	  if(data.IsEmpty()) return _T("clear");
-	  
+	  wxString data(entry->GetEntryData());	  
 	  if(data.Trim(left).StartsWith(_T(";"))) return _T("comment");
+	  else {
+		if(entry->group == _T("[Script Info]") && data.Matches(_T("*:*"))) return _T("info");
+		if(data == entry->group) return _T("head");
+		if(data.StartsWith(_T("Format:"))) return _T("format");
+		if(data.IsEmpty()) return _T("clear");
+	  }
 	}
 
 	// Fallback
diff --git a/aegisub/auto4_perl_script.cpp b/aegisub/auto4_perl_script.cpp
index 96ed302a2..d87f0eeba 100644
--- a/aegisub/auto4_perl_script.cpp
+++ b/aegisub/auto4_perl_script.cpp
@@ -109,6 +109,7 @@ namespace Automation4 {
 
 	// 'Enclose' the script into its package
 	wxString _script = _T("package ") + package + _T(";\n")
+	  _T("require Aegisub; require Aegisub::Script; require Aegisub::Progress;") // Core modules
 	  _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
@@ -118,19 +119,19 @@ namespace Automation4 {
 
 	// Let's eval the 'boxed' script
 	eval_pv(_script.mb_str(wx2pl), 0);
+	SV *_err = newSVsv(ERRSV);  // We need this later
+	// Done running
+	deactivate();
 	// and check on errors
-	if(SvTRUE(ERRSV)) {
-	  description = wxString(SvPV_nolen(ERRSV), pl2wx);
-	  wxLogError(description); // Remove?
+	if(SvTRUE(_err)) {
+	  description = wxString(SvPV_nolen(_err), pl2wx);
+	  //wxLogError(description);  // Remove?
 	  loaded = false;
 	}
 	else {
 	  loaded = true;
 	}
 
-	// The script has done loading (running)
-	deactivate();
-
 	wxTRACE_RET(load);
   }
   
@@ -200,8 +201,8 @@ namespace Automation4 {
 	}
 
 	// Require the core modules
-	load_module(PERL_LOADMOD_NOIMPORT, newSVpvn("Aegisub", 7), NULL);
-	load_module(PERL_LOADMOD_NOIMPORT, newSVpvn("Aegisub::Progress", 17), NULL);
+	//load_module(PERL_LOADMOD_NOIMPORT, newSVpvn("Aegisub", 7), NULL);
+	//load_module(PERL_LOADMOD_NOIMPORT, newSVpvn("Aegisub::Progress", 17), NULL);
 	//load_module(PERL_LOADMOD_NOIMPORT, newSVpvn("Aegisub::Script", 15), NULL);
 
 	// Set the values of script vars
-- 
GitLab