Index: src/af/util/xp/ut_PerlBindings.cpp =================================================================== --- src/af/util/xp/ut_PerlBindings.cpp (revision 23327) +++ src/af/util/xp/ut_PerlBindings.cpp (working copy) @@ -1,423 +0,0 @@ -// If PERL_OBJECT is defined, perl guts are C++ functions, and thus we should -// not use extern "C". -#ifndef PERL_OBJECT -# define is_cplusplus -#endif - -#include "ut_PerlBindings.h" -#include "ut_string_class.h" -#include "xap_App.h" -#include "xap_Frame.h" -#include "xav_View.h" -#include "ut_debugmsg.h" -#include "ev_EditMethod.h" -#include "ev_Menu.h" -#include "ev_Menu_Actions.h" - -// for scandir - TODO: make me less unixy -//win32 #include -//win32 #include - -// HACK to not collide with perl DEBUG -#ifdef DEBUG -# define ABI_DEBUG -# undef DEBUG -#endif - -#include -#include // printf - -#ifdef is_cplusplus -extern "C" { -#endif - -// perl has its own 'bool' datatype that clashes with C++'s -// builtin bool. perl will define bool as an enum, int, or char -// if you'd don't define this. this hack allows our perl bindings -// to compile on *BSD -#define HAS_BOOL 1 - -// perl uses some wacky define's for the SvTRUE macro's and the like which -// gcc (read: ISO C++) does not allow. Defining PERL_GCC_BRACE_GROUPS_FORBIDDEN -// forces 'perl' not these defines and to use another macro definition. See sv.h -// for more information. -#define PERL_GCC_BRACE_GROUPS_FORBIDDEN 1 - -#include -#include - -#ifdef is_cplusplus -} -#endif - -#ifdef PERL_OBJECT -# define NO_XSLOCKS -# include -# include "win32iop.h" -# include -# include -#endif - -#ifdef DEBUG -# define PERL_DEBUG -# undef DEBUG -#endif - -#ifdef ABI_DEBUG -# define DEBUG -#endif - -extern "C" { - -#ifdef NOT_PERL_5_8 - void boot_DynaLoader(CV* cv); - void xs_init () -#else - void boot_DynaLoader(PerlInterpreter *pi, CV* cv); - void xs_init(PerlInterpreter * my_perl) -#endif - { - newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, __FILE__); - /* we want to link to the module code, but until it's stable - it's better to have it dynamically loaded... - newXS("abi::boot_AbiWord", boot_AbiWord, file);*/ - } -} - -////////////////////////////////////////////////// -// Impl -////////////////////////////////////////////////// -struct UT_PerlBindings::Impl -{ -public: - PerlInterpreter* pPerlInt; - UT_String errmsg; -}; - -#ifdef PERL_DEBUG -#define DEBUG -#endif - -extern "C" { - - // return > 0 for perl directory entries -#if defined (__APPLE__) || defined (__FreeBSD__) || defined (__OpenBSD__) \ - || defined(_AIX) - static int perl_only (struct dirent *d) -#else - static int perl_only (const struct dirent *d) -#endif - { - const char * name = d->d_name; - - if ( name ) - { - int len = strlen (name); - - if (len >= 3) - { - if(!strcmp(name+(len-3), ".pl") || !strcmp(name+(len-3), ".pm")) - return 1; - } - } - return 0; - } -} // extern "C" block - -UT_PerlBindings::UT_PerlBindings() - : impl_(new UT_PerlBindings::Impl) -{ - char *argv[] = { "", "-MAbiWord", "-e", "0" }; - - impl_->pPerlInt = perl_alloc(); - - // how can I signal that there is not enough memory without throwing an exception? - if (impl_->pPerlInt == 0) { - UT_DEBUGMSG(("Not enough memory to start a perl interpreter!\n")); - UT_ASSERT_NOT_REACHED(); - DELETEP(impl_); - return; - } - - perl_construct(impl_->pPerlInt); - int exitstatus = perl_parse(impl_->pPerlInt, xs_init, sizeof(argv) / sizeof(char*), argv, 0); - - if (exitstatus != 0) - { - UT_DEBUGMSG(("perl_parse failed with error nb: %d", exitstatus)); - UT_ASSERT_NOT_REACHED(); - DELETEP(impl_); - return; - } - - exitstatus = perl_run(impl_->pPerlInt); - - if (exitstatus != 0) - { - UT_DEBUGMSG(("perl_run failed with error nb: %d", exitstatus)); - UT_ASSERT_NOT_REACHED(); - DELETEP(impl_); - return; - } - - // interpreter loaded, now to auto-load plugins... TODO: make this less unix-ish - { - struct dirent **namelist; - int n = 0; - - UT_String scriptList[2]; - - // global script dir - UT_String scriptDir = XAP_App::getApp()->getAbiSuiteAppDir(); - scriptDir += "/scripts/"; - scriptList[0] = scriptDir; - - // the user-local script directory - scriptDir = XAP_App::getApp()->getUserPrivateDirectory (); - scriptDir += "/AbiWord/scripts/"; - scriptList[1] = scriptDir; - - for(UT_uint32 i = 0; i < (sizeof(scriptList)/sizeof(scriptList[0])); i++) - { - scriptDir = scriptList[i]; - - n = scandir(scriptDir.c_str(), &namelist, perl_only, alphasort); - UT_DEBUGMSG(("DOM: found %d PERL scripts in %s\n", n, scriptDir.c_str())); - - if (n > 0) - { - while(n--) - { - UT_String script (scriptDir + namelist[n]->d_name); - - UT_DEBUGMSG(("DOM: loading PERL script %s\n", script.c_str())); - - evalFile ( script ) ; - - g_free(namelist[n]); - } - } - g_free (namelist); - } - } -} - -UT_PerlBindings::~UT_PerlBindings() -{ - if (impl_) - { - perl_destruct(impl_->pPerlInt); - perl_free(impl_->pPerlInt); - delete impl_; - } -} - -UT_PerlBindings& -UT_PerlBindings::getInstance() -{ - static UT_PerlBindings instance; - return instance; -} - -const UT_String& -UT_PerlBindings::errmsg() const -{ - static const UT_String& empty(""); - return impl_ ? impl_->errmsg : empty; -} - -bool -UT_PerlBindings::evalFile(const UT_String& filename) -{ - if (0 == impl_) - return false; - -#ifndef NOT_PERL_5_8 - PerlInterpreter * my_perl = impl_->pPerlInt; -#endif - - UT_String code("require \""); - - for (size_t i = 0; i < filename.size(); ++i) - { - if (filename[i] != '\\') - code += filename[i]; - else - code += "\\\\"; - } - - code += "\""; - - SV* retval = perl_eval_pv(code.c_str(), FALSE); - - if (!SvOK(retval)) - { - if (SvTRUE(ERRSV)) - { - UT_DEBUGMSG(("Error compiling perl script.\n")); - - if (impl_) - { - impl_->errmsg = "Error compiling perl script:\n"; - impl_->errmsg += SvPV_nolen(ERRSV); - warpString(impl_->errmsg, 50); - } - } - - return false; - } - else - { - if (!SvTRUE(retval)) - { - UT_DEBUGMSG(("Error running perl script.\n")); - - if (impl_) - impl_->errmsg = "Error running perl script.\n"; - - return false; - } - } - - code = "delete $INC{\""; - - for (size_t i = 0; i < filename.size(); ++i) - { - if (filename[i] != '\\') - code += filename[i]; - else - code += "\\\\"; - } - - code += "\"}"; - - perl_eval_pv(code.c_str(), FALSE); - - return true; -} - -bool -UT_PerlBindings::runCallback(const char* method) -{ -#ifndef NOT_PERL_5_8 - PerlInterpreter * my_perl = impl_->pPerlInt; -#endif - - dSP; - PUSHMARK(SP); - -#ifdef NOT_PERL_5_8 - Perl_call_pv(method, - G_VOID | G_DISCARD | G_NOARGS /* | G_EVAL */ ); -#else - Perl_call_pv(my_perl, method, - G_VOID | G_DISCARD | G_NOARGS /* | G_EVAL */ ); -#endif - - if (SvTRUE(ERRSV)) - { - if (impl_) - { - impl_->errmsg = "Error executing perl script:\n"; - impl_->errmsg += SvPV_nolen(ERRSV); - warpString(impl_->errmsg, 50); - } - - return false; - } - - return true; -} - -void -UT_PerlBindings::registerCallback(const char* pszFunctionName, - const char* pszMenuPath, - const char* pszDescription, - bool bRaisesDialog) -{ - XAP_App* app = XAP_App::getApp(); - XAP_Menu_Id id = 0; - UT_ASSERT(app); - UT_ASSERT(pszFunctionName); - UT_ASSERT(pszMenuPath); - UT_ASSERT(pszDescription); - - UT_uint32 nb_frames = app->getFrameCount(); - for (UT_uint32 i = 0; i < nb_frames; ++i) - { - XAP_Frame* frame = app->getFrame(i); - UT_ASSERT(frame); - EV_Menu* menu = frame->getMainMenu(); - UT_ASSERT(menu); - id = menu->addMenuItem(pszMenuPath, pszDescription); - } - - app->getMenuActionSet()->addAction(new EV_Menu_Action(id, false, bRaisesDialog, false, false, "executeScript", 0, 0, pszFunctionName)); -} - -/***************************************************************************/ -/***************************************************************************/ - -UT_PerlScriptSniffer::UT_PerlScriptSniffer () -{ -} - -UT_PerlScriptSniffer::~UT_PerlScriptSniffer () -{ -} - -bool UT_PerlScriptSniffer::recognizeContents (const char * szBuf, - UT_uint32 iNumbytes) const -{ - // this can obviously get better - if (NULL == strstr(szBuf, "perl")) - return false; - - return true; -} - -bool UT_PerlScriptSniffer::recognizeSuffix (const char * szSuffix) const -{ - if ( !g_ascii_strcasecmp ( szSuffix, ".perl" ) || !g_ascii_strcasecmp (szSuffix, ".pl" ) ) - return true; - - return false; -} - -bool UT_PerlScriptSniffer::getDlgLabels (const char ** szDesc, - const char ** szSuffixList, - UT_ScriptIdType * ft) const -{ - *szDesc = "Perl Scripts (.perl, .pl)"; - *szSuffixList = "*.perl; *.pl"; - *ft = getType(); - return true; -} - -UT_Error UT_PerlScriptSniffer::constructScript(UT_Script** ppscript) const -{ - *ppscript = new UT_PerlScript(); - return UT_OK; -} - -/***************************************************************************/ -/***************************************************************************/ - -UT_PerlScript::UT_PerlScript() -{ -} - -UT_PerlScript::~UT_PerlScript() -{ -} - -UT_Error UT_PerlScript::execute(const char * fileName) -{ - UT_PerlBindings& instance = UT_PerlBindings::getInstance(); - UT_String file(fileName); - - if (instance.evalFile(file)) - return UT_OK; - - return UT_ERROR; -} Index: src/af/util/xp/ut_PerlBindings.h =================================================================== --- src/af/util/xp/ut_PerlBindings.h (revision 23327) +++ src/af/util/xp/ut_PerlBindings.h (working copy) @@ -1,63 +0,0 @@ -#ifndef UT_PERLBINDINGS_H -#define UT_PERLBINDINGS_H - -/* pre-emptive dismissal; ut_types.h is needed by just about everything, - * so even if it's commented out in-file that's still a lot of work for - * the preprocessor to do... - */ -#ifndef UT_TYPES_H -#include "ut_types.h" -#endif -#include "ut_Script.h" - -class UT_String; - -class ABI_EXPORT UT_PerlBindings -{ -public: - static UT_PerlBindings& getInstance(); - bool evalFile(const UT_String& filename); - const UT_String& errmsg() const; - bool runCallback(const char* method); - void registerCallback(const char* pszFunctionName, - const char* pszMenuPath, - const char* pszDescription, - bool bRaisesDialog); - - ~UT_PerlBindings(); - -private: - UT_PerlBindings(); - UT_PerlBindings(const UT_PerlBindings&); - UT_PerlBindings& operator= (const UT_PerlBindings&); - - struct Impl; - Impl* impl_; -}; - -class ABI_EXPORT UT_PerlScriptSniffer : public UT_ScriptSniffer -{ -public: - UT_PerlScriptSniffer(); - virtual ~UT_PerlScriptSniffer(); - - virtual bool recognizeContents (const char* szBuf, - UT_uint32 iNumbytes) const; - virtual bool recognizeSuffix (const char* szSuffix) const; - virtual bool getDlgLabels(const char** szDesc, - const char** szSuffixList, - UT_ScriptIdType* ft) const; - virtual UT_Error constructScript (UT_Script** ppscript) const; -}; - -class ABI_EXPORT UT_PerlScript : public UT_Script -{ -public: - UT_PerlScript(); - virtual ~UT_PerlScript(); - - virtual UT_Error execute(const char* scriptName); - virtual const UT_String& errmsg() const { return UT_PerlBindings::getInstance().errmsg(); } -}; - -#endif // UT_PERLBINDINGS_H Index: src/af/util/xp/Makefile.am =================================================================== --- src/af/util/xp/Makefile.am (revision 23327) +++ src/af/util/xp/Makefile.am (working copy) @@ -6,14 +6,7 @@ libxp_la_CPPFLAGS = \ $(AF_CPPFLAGS) -if SCRIPT -script_sources = \ - ut_PerlBindings.cpp \ - ut_PerlBindings.h -endif - libxp_la_SOURCES = \ - $(script_sources) \ ut_AdobeEncoding.cpp \ ut_AdobeEncoding.h \ ut_allocator.cpp \ Index: src/wp/ap/cocoa/ap_CocoaApp.cpp =================================================================== --- src/wp/ap/cocoa/ap_CocoaApp.cpp (revision 23327) +++ src/wp/ap/cocoa/ap_CocoaApp.cpp (working copy) @@ -45,7 +45,6 @@ #include "ut_misc.h" #include "ut_png.h" -#include "ut_PerlBindings.h" #include "ut_Script.h" #include "ev_CocoaMenuBar.h" @@ -412,14 +411,7 @@ XAP_CocoaAppController * pController = (XAP_CocoaAppController *) [NSApp delegate]; [pController setAutoLoadPluginsAfterLaunch:YES]; } - ////////////////////////////////////////////////////////////////// -#ifdef ABI_OPT_PERL - // hack to keep the perl bindings working on unix - UT_ScriptLibrary& instance = UT_ScriptLibrary::instance(); - instance.registerScript ( new UT_PerlScriptSniffer () ); -#endif - return true; } Index: src/wp/ap/gtk/ap_UnixApp.cpp =================================================================== --- src/wp/ap/gtk/ap_UnixApp.cpp (revision 23328) +++ src/wp/ap/gtk/ap_UnixApp.cpp (working copy) @@ -43,10 +43,6 @@ #include "ut_string.h" #include "ut_misc.h" #include "ut_locale.h" -#ifdef ABI_OPT_PERL - #include "ut_PerlBindings.h" - #include "ut_Script.h" -#endif #include "ut_sleep.h" #include "xap_Args.h" @@ -392,14 +388,6 @@ if(bLoadPlugins || !bFound) loadAllPlugins(); - ////////////////////////////////////////////////////////////////// - -#ifdef ABI_OPT_PERL - // hack to keep the perl bindings working on unix - UT_ScriptLibrary * instance = UT_ScriptLibrary::instance(); - instance->registerScript ( new UT_PerlScriptSniffer () ); -#endif - return true; } Index: src/wp/ap/xp/ap_Args.h =================================================================== --- src/wp/ap/xp/ap_Args.h (revision 23327) +++ src/wp/ap/xp/ap_Args.h (working copy) @@ -50,10 +50,6 @@ AP_App* getApp() const { return m_pApp; } bool doWindowlessArgs(bool & bSuccessful); - -#ifdef ABI_OPT_PERL - static const char * m_sScript; -#endif #ifdef DEBUG static int m_iDumpstrings; #endif Index: src/wp/ap/xp/ap_Args.cpp =================================================================== --- src/wp/ap/xp/ap_Args.cpp (revision 23327) +++ src/wp/ap/xp/ap_Args.cpp (working copy) @@ -32,14 +32,7 @@ #include "ut_string.h" #include "ut_misc.h" -#ifdef ABI_OPT_PERL -#include "ut_PerlBindings.h" -#endif - // Static initializations: -#ifdef ABI_OPT_PERL -const char * AP_Args::m_sScript = NULL; -#endif #ifdef DEBUG int AP_Args::m_iDumpstrings = 0; #endif @@ -80,9 +73,6 @@ #ifdef DEBUG {"dumpstrings", 'd', 0, G_OPTION_ARG_NONE, &AP_Args::m_iDumpstrings, "Dump strings to file", NULL}, #endif -#ifdef ABI_OPT_PERL - {"script", 's', 0, G_OPTION_ARG_STRING, &AP_Args::m_sScript, "Execute FILE as script", "FILE"}, -#endif {NULL } }; @@ -164,15 +154,6 @@ } #endif -#ifdef ABI_OPT_PERL - if (m_sScript) - { - UT_PerlBindings& pb(UT_PerlBindings::getInstance()); - if (!pb.evalFile(m_sScript)) - printf("%s\n", pb.errmsg().c_str()); - } -#endif - if (m_iVersion) { printf("%s\n", PACKAGE_VERSION); Index: src/bindings/perl/typemap =================================================================== --- src/bindings/perl/typemap (revision 23327) +++ src/bindings/perl/typemap (working copy) @@ -1,27 +0,0 @@ -TYPEMAP -const char * T_PV -FV_View * O_OBJECT -XAP_Frame * O_OBJECT_FRAME - -OUTPUT -O_OBJECT - sv_setref_pv( $arg, "AbiWord::FV_View", (void*)$var ); - -O_OBJECT_FRAME - sv_setref_pv( $arg, "AbiWord::XAP_Frame", (void*)$var ); - -INPUT -O_OBJECT - if (sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG)) - $var = ($type)SvIV((SV*)SvRV( $arg )); - else { - warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" ); XSRETURN_UNDEF; - } - -O_OBJECT_FRAME - if (sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG)) - $var = ($type)SvIV((SV*)SvRV( $arg )); - else { - warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" ); XSRETURN_UNDEF; - } - Index: src/bindings/perl/AbiWord.xs =================================================================== --- src/bindings/perl/AbiWord.xs (revision 23327) +++ src/bindings/perl/AbiWord.xs (working copy) @@ -1,373 +0,0 @@ -#include -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" - -/* perl sux */ -#undef ref -#undef list - -#include "../../af/xap/xp/xap_App.h" -#include "../../af/xap/xp/xap_Frame.h" -#include "../../af/xap/xp/xad_Document.h" -#include "../../text/ptbl/xp/pd_Document.h" -#include "../../text/fmt/xp/fv_View.h" -#include "../../text/fmt/xp/fp_PageSize.h" -#include "../../af/util/xp/ut_string.h" -#include "../../af/util/xp/ut_units.h" -#include "../../af/util/xp/ut_PerlBindings.h" -#include "../../af/ev/xp/ev_EditMethod.h" - -MODULE = AbiWord PACKAGE = AbiWord::FV_View - -void -moveCursorAbs(pView, target, where) - FV_View *pView - const char *target - int where - ALIAS: - AbiWord::FV_View::moveCursorAbs = 0 - AbiWord::FV_View::moveCursorRel = 1 - CODE: - UT_UCSChar *tmp; - static char szWhere[16]; - const char * format = ix ? "%+d" : "%d"; - sprintf(szWhere, format, where); - assert(target && target[0]); - // printf("moveCursorAbs\n"); - - switch (target[0]) - { - case 'p': /* page */ - if (UT_UCS4_cloneString_char(&tmp, szWhere)) - { - pView->gotoTarget(AP_JUMPTARGET_PAGE, tmp); - g_free(tmp); - } - break; - case 'l': /* line */ - if (UT_UCS4_cloneString_char(&tmp, szWhere)) - { - pView->gotoTarget(AP_JUMPTARGET_LINE, tmp); - g_free(tmp); - } - break; - } - -void -cut(pView) - FV_View* pView - CODE: - pView->cmdCut(); - -void -copy(pView) - FV_View* pView - CODE: - pView->cmdCopy(); - -void -paste(pView) - FV_View* pView - CODE: - pView->cmdPaste(); - -void -setPaperColor(pView, color) - FV_View* pView - const char* color - CODE: - pView->setPaperColor((gchar*) color); - -bool -setCharFormat (pView, ...) - FV_View *pView - ALIAS: - AbiWord::FV_View::setCharFormat = 0 - AbiWord::FV_View::setSectionFormat = 1 - AbiWord::FV_View::setBlockFormat = 2 - CODE: - { - gchar **properties = new gchar* [items]; - // printf("setCharFormat\n"); - - for (int i = 1; i < items; ++i) - properties[i - 1] = SvPV(ST(i), PL_na); - - properties[items - 1] = NULL; - - switch (ix) { - case 0: - pView->setCharFormat((const gchar **) properties); - break; - case 1: - pView->setSectionFormat((const gchar **) properties); - break; - case 2: - pView->setBlockFormat((const gchar **) properties); - break; - } - - delete[] properties; - RETVAL = true; - } - OUTPUT: - RETVAL - -void -changeNumColumns (pView, ncolumns) - FV_View *pView - unsigned int ncolumns - CODE: - /* this is not actually implemented, though it's in the header - pView->changeNumColumns (ncolumns);*/ - -void -cmdCharDelete (pView, forward, count) - FV_View *pView - bool forward - unsigned int count - CODE: - pView->cmdCharDelete (forward, count); - -unsigned int -getCurrentPageNumber (pView) - FV_View *pView - CODE: - RETVAL = pView->getCurrentPageNumber(); - OUTPUT: - RETVAL - -bool -saveAs(pView, filename, left, cpy) - FV_View *pView - const char * filename - int left - bool cpy - CODE: - // printf("saveAs\n"); - pView->cmdSaveAs(filename, left, cpy); - RETVAL = true; - OUTPUT: - RETVAL - -bool -write(pView, pszText) - FV_View *pView - const char *pszText - CODE: - UT_UCSChar *text = NULL; - // printf("write\n"); - UT_UCS4_cloneString_char(&text, pszText); - pView->cmdCharInsert(text, strlen(pszText)); - g_free(text); - RETVAL = true; - OUTPUT: - RETVAL - -bool -write_OneAtTime(pView, pszText) - FV_View *pView - const char *pszText - CODE: - // THIS METHOD IS ONLY USEFUL FOR SPEED TESTS!! - static UT_UCSChar text[2] = { 0, 0 }; - while ((text[0] = *pszText++) != '\0') - pView->cmdCharInsert(text, 1); - RETVAL = true; - OUTPUT: - RETVAL - -void -editHeader(pView) - FV_View *pView - CODE: - pView->cmdEditHeader(); - -void -editFooter(pView) - FV_View *pView - CODE: - pView->cmdEditFooter(); - -void -editBody(pView) - FV_View *pView - CODE: - pView->clearHdrFtrEdit(); - pView->warpInsPtToXY(0, 0, false); - -unsigned int -getPoint(pView) - FV_View *pView - CODE: - RETVAL = pView->getPoint(); - OUTPUT: - RETVAL - -bool -find(pView, pszText, matchCase) - FV_View* pView - const char* pszText - bool matchCase - CODE: - UT_UCSChar *text = NULL; - UT_UCS4_cloneString_char(&text, pszText); - bool bTmp; - pView->findSetMatchCase(matchCase); - RETVAL = pView->findNext(text, bTmp); - g_free(text); - OUTPUT: - RETVAL - -bool -replace(pView, pszTextToFind, pszReplacement, matchCase) - FV_View* pView - const char* pszTextToFind - const char* pszReplacement - bool matchCase - CODE: - UT_UCSChar *textToFind = NULL; - UT_UCS4_cloneString_char(&textToFind, pszTextToFind); - UT_UCSChar *replacement = NULL; - UT_UCS4_cloneString_char(&replacement, pszReplacement); - bool bTmp; - pView->findSetMatchCase(matchCase); - pView->findSetFindString(textToFind); - pView->findSetReplaceString(replacement); - RETVAL = pView->findReplace(bTmp); - g_free(textToFind); - g_free(replacement); - OUTPUT: - RETVAL - -char* -getSelectionText(pView) - FV_View* pView - CODE: - if (!pView->isSelectionEmpty()) - { - UT_UCSChar* text; - pView->getSelectionText(text); - UT_uint32 size = UT_UCS4_strlen(text); - RETVAL = (char*) g_try_malloc(size); - UT_UCS4_strcpy_to_char(RETVAL, text); - } - else - { - RETVAL = (char*) g_try_malloc(1); - *RETVAL = '\0'; - } - - OUTPUT: - RETVAL - -void -print(pView) - FV_View* pView - ALIAS: - AbiWord::FV_View::showPrintDialog = 0 - AbiWord::FV_View::print = 1 - CODE: - EV_EditMethodContainer* pEMC = XAP_App::getApp()->getEditMethodContainer(); - EV_EditMethod* pEM = 0; - - if (ix == 0) - pEM = pEMC->findEditMethodByName("print"); - else - pEM = pEMC->findEditMethodByName("printTB"); - - pEM->Fn(pView, 0); - -MODULE = AbiWord PACKAGE = AbiWord::XAP_Frame - -XAP_Frame * -getLastFocussed() - CODE: - // printf("getLastFocussed\n"); - RETVAL = XAP_App::getApp()->getLastFocussedFrame(); - OUTPUT: - RETVAL - -XAP_Frame * -openFile(pszFilename) - const char* pszFilename - CODE: - XAP_App* app = XAP_App::getApp(); - // printf("openFile\n"); - RETVAL = app->newFrame(); - RETVAL->loadDocument(pszFilename, 0, true); - OUTPUT: - RETVAL - -FV_View * -getCurrentView(pFrame) - XAP_Frame* pFrame - CODE: - // printf("getCurrentView\n"); - RETVAL = (FV_View *) pFrame->getCurrentView(); - OUTPUT: - RETVAL - -void -setPageSize(pFrame, iWidth, iHeight) - XAP_Frame* pFrame - double iWidth - double iHeight - CODE: - // THIS METHOD DOESN'T WORK - AD_Document* ad_doc = pFrame->getCurrentDoc(); - PD_Document* doc = dynamic_cast (ad_doc); - if (doc) - { - fp_PageSize ps(iWidth, iHeight, DIM_MM); -// doc->setPageSize(ps); - } - -void -setPageSizeByName(pFrame, pszName) - XAP_Frame* pFrame - const char* pszName - CODE: - // THIS METHOD DOESN'T WORKS - AD_Document* ad_doc = pFrame->getCurrentDoc(); - PD_Document* doc = dynamic_cast (ad_doc); - if (doc) -// doc->setPageSize(fp_PageSize(pszName)); - ; - -void -close(pFrame) - XAP_Frame *pFrame - CODE: - XAP_App * pApp = XAP_App::getApp(); - - if (pFrame == pApp->getLastFocussedFrame()) - pApp->clearLastFocussedFrame(); - - if (pApp->getFrameCount() <= 1) - { - // Delete all the open modeless dialogs - pApp->closeModelessDlgs(); - pApp->reallyExit(); - } - - pApp->forgetFrame(pFrame); - pFrame->close(); - delete pFrame; - -void -register(pszFunctionName, pszMenuPath, pszDescription, bRaisesDialog) - const char *pszFunctionName - const char *pszMenuPath - const char *pszDescription - bool bRaisesDialog - CODE: - UT_PerlBindings::getInstance().registerCallback( - pszFunctionName, pszMenuPath, pszDescription, bRaisesDialog); - -void -exit() - CODE: - XAP_App::getApp()->reallyExit(); - Index: src/bindings/perl/AbiWord.pm =================================================================== --- src/bindings/perl/AbiWord.pm (revision 23327) +++ src/bindings/perl/AbiWord.pm (working copy) @@ -1,378 +0,0 @@ -package AbiWord; - -use strict; - -require Exporter; -require DynaLoader; - -@AbiWord::ISA = qw(Exporter DynaLoader); - -# Items to export into callers namespace by default. Note: do not export -# names by default without a very good reason. Use EXPORT_OK instead. -# Do not simply export all your public functions/methods/constants. - -# This allows declaration use AbiWord ':all'; -# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK -# will save memory. -%AbiWord::EXPORT_TAGS = ( 'all' => [ qw( - -) ] ); - -@AbiWord::EXPORT_OK = ( @{ $AbiWord::EXPORT_TAGS{'all'} } ); - -@AbiWord::EXPORT = qw( - -); -$AbiWord::VERSION = '0.01'; - -bootstrap AbiWord $AbiWord::VERSION; - -# Preloaded methods go here. - -1; -__END__ -# Below is stub documentation for your module. You better edit it! - -=head1 NAME - -AbiWord - Perl extension for AbiWord - -=head1 SYNOPSIS - - $frame = AbiWord::XAP_Frame::getLastFocussed; - $view = $frame->getCurrentView; - $view->write("Hello world!"); - 1; - -=head1 DESCRIPTION - -Perl bindings for AbiWord. - -=head2 INTRODUCTION - -Now, we're going to write out first script. I'm tired of "Hello -World!", so we will just write a nice "X" into the current AbiWord document. - -Write the perl script: - -my $frame = AbiWord::XAP_Frame::getLastFocussed; -my $view = $frame->getCurrentView; -$view->write("X"); -1; - -Save it as "test_x.pl", execute abiword, and click on the -Tools->Script menubar item (or in the blue arrow in the "extra" -toolbar). Doing that will open a dialog box, select test_x.pl (and -click "ok" ;) - -You should see now a sexy X in your current cursor position. - -If you don't see it, take a break, make sure that you're using the -perl script enabled version of abiword, and if everything seems ok, -but it's still not working send me (e98cuenc@yahoo.com) an email with -a description of your problem. - -Now, how does this script write an X in your document? -Let's analyse it. - -The first line: - my $frame = AbiWord::XAP_Frame::getLastFocussed; - -creates a new local ("my") variable ($frame), and gives it the value -of the last focussed frame that AbiWord knows about (ie, the frame in -which you're working right now). - -Now you should get a "view" from this "frame" to be able to write -something (if you find it awkward to "write" something in a "view" -instead of writting in a "controller", then you're right). - -The second line does just that: - my $view = $frame->getCurrentView; - -It gets the view associated with the frame that you're using, and -stores it in the local variable "$view". - -Now, we will write something in our new view: - $view->write("X"); - -No comments. - -The trailing "1;" is important. It's the return value of your script. -If you forget about it, you will burn in hell, etc. - -Here we've just used 3 functions of the abiword's perl bindings, but -with only these function we can already do plenty of cool things, for -instance... - -=head2 ADVANCED EXAMPLE - -Now, we can pass to the interesting stuff (well, I'm not saying that -inserting a X in your document is not interesting, but...) - -Let's study a script that will write in the current abiword -document a serie of cards, with the following format: - -POBOX -NAME -STREET -POSTAL_CODE CITY (REGION) -COUNTRY - -The data that will be used to fill each card will be extracted from -the default GnomeCard file. - -Here is the script: - -############################## -my $CARD; -my $home = $ENV{'HOME'} || $ENV{'LOGDIR'} || (getpwuid($<))[7] || die "You're homeless!\n"; -open CARD, "< $home/.gnome/GnomeCard.gcrd" or die "Sorry, could not open default card file: $!"; - -while () { - read_card($CARD) if (/^BEGIN:VCARD/); -} - -1; - -sub read_card { - my $CARD = shift; - my ($name, $pobox, $extended, $street, $city, $region, $postalcode, $country); - while () { - if (/^END:VCARD/) { - chomp($name); - chomp($country); - my $frame = AbiWord::XAP_Frame::getLastFocussed; - my $view = $frame->getCurrentView; - $view->write("$pobox\n") unless ($pobox eq ""); - $view->write("$name\n"); - $view->write("$street\n"); - $view->write("$postalcode $city ($region)\n"); - $view->write("$country\n"); - return 0; - } - else { - my ($type, $data) = split /:/; - $name = $data if ($type eq "FN"); - if ($type =~ /^ADR/) { - ($pobox, $extended, $street, $city, $region, $postalcode, $country) = split(/;/, $data); - } - } - } -} -############################## - -ok, now that's a lot of code... but the abiword stuff is the same that we used -in the last example. We get the current frame, the associated view, -and then we write something. The key is in the "something". After that we parse -the file generated by GnomeCard (just open GnomeCard, and fill some -cards), and we write the contents of GnomeCard (formatting them a bit -in the way). - -To understand how it works, take a navigator, go to google and search -for "perl tutorial". This script is not rocket science, I'm sure that -you can understand it without a glitch (if it's not the case, you can -ask me whatever you want). - -Now, you can do more things than just write something in a view! You -can do weird things, as saving documents, editing headers, etc. - -Here's a list of all the methods that you can use (you can always read -the AbiWord.xs file, but I think that the whole point of this -mini-tutorial is to show how to use the abiword perl bindings -*without* having to take a look at the code): - -#################### -$view->moveCursorAbs(target, where) -$view->moveCursorRel(target, where) - -ex.: - $view->moveCursorAbs("page", 3); - $view->moveCursorAbs("line", 6); - - It will move your cursor to the page 3, line 6. - -ex.: - $view->moveCursorRel("page", -2); - $view->moveCursorRel("line", 4); - - It will advance your cursor 2 pages up, and 4 lines down. - -#################### -$view->setCharFormat(format) - -ex.: - $view->setCharFormat("font-weight" => "normal", - "font-style" => "normal", - "font-family" => "Times New Roman", - "font-size" => "12pt", - "text-decoration" => "normal"); - - It will change the current character format (if you write - something after this call, it will show up in the selected - format). - - The formats availables are: - TODO - -#################### -$view->setSectionFormat(format) - -ex.: - $view->setSectionFormat("font-weight" => "normal", - "font-style" => "normal", - "font-family" => "Times New Roman", - "font-size" => "12pt", - "text-decoration" => "normal"); - - It will change the current character format (if you write - something after this call, it will show up in the selected - format). - - The formats availables are: - TODO - -#################### -$view->setBlockFormat(format) - -ex.: - $view->setBlockFormat("font-weight" => "normal", - "font-style" => "normal", - "font-family" => "Times New Roman", - "font-size" => "12pt", - "text-decoration" => "normal"); - - It will change the current character format (if you write - something after this call, it will show up in the selected - format). - - The formats availables are: - TODO - -#################### -$view->changeNumColumns(ncols) - -ex.: - $view->changeNumColumns(3); - - It will... well, you can guess it :) - -#################### -$view->cmdCharDelete(forward, count) - -ex.: - $view->cmdCharDelete(false, 3); - - It will delete backwards 3 characters - -#################### -$page_nb = $view->getCurrentPageNumber - - It returns the current page number - -#################### -$view->saveAs(filename, ieft, cpy) - - It saves the doc being edited in $view as "filename". - It will be saved in the format specified by ieft, using the - following table: - - 1 -> AbiWord - 2 -> AbiWord gzipped - 4 -> HTML - 5 -> RTF - 6 -> Text - 7 -> UTF8 - 8 -> LaTeX - 9 -> PalmDoc - 10 -> RTF attic (somebody can explain me what's that?) - 11 -> WML - 12 -> XHTML - 13 -> DocBook - 16 -> Psion TextEd - 17 -> Psion Word - 19 -> Applix - 21 -> XSL FO - - The last argument, cpy, says if the save will be "seen" by the - user or if it will be "invisible". - - For instance, if you save a document named "blah.abw" as - "foo.abw" and cpy is true (1), then the user will see as the - filename of the document that (s)he is editing change from - "blah.abw" to "foo.abw", and the '*' that marks the document - as dirty will disappear. - - If you save the document and cpy is false (0), then the user - will not see any visible change (besides the fact that there - will be a new file in his hard disk). - -#################### -$view->editHeader - - It changes the insertion point to the header. Next "write"'s - will write in the header, and not in the body. - -#################### -$view->editFooter - - It changes the insertion point to the footer. Next "write"'s - will write in the footer, and not in the body. - -#################### -$view->editBody - - It changes the insertion point to the body of the document. - Useful after an edit{Header,Footer}. ** NOTE: It doesn't work - right now. - -#################### -$pos = $view->getPoint - - It returns the position of the insertion point. - -#################### -$frame->getCurrentView - - It returns the view that is being used in the frame. - -#################### -$frame->close - - It closes the frame. - -#################### -$frame # openFile(filename) - - It opens a new frame, using the document "filename". - -#################### -$frame # getLastFocussed - - It returns the last focused frame. - -#################### -exit - - Quits the app - -=head2 FUTURE - -Now that we can dynamically add menu items to abiword, it should be a -piece of cake to package some scripts with abiword, and bind them to -new menu bar item's (a la gimp). - -So, if you write a script and you think that it may be of public -interest, send us a copy and we will package it with abiword (once we -enable the perl build by default). - -And that's all folks! - -=head1 AUTHOR - -J. Cuenca Abela, e98cuenc@yahoo.com - -=head1 SEE ALSO - -perl(1). - -=cut Index: src/bindings/perl/MANIFEST =================================================================== --- src/bindings/perl/MANIFEST (revision 23327) +++ src/bindings/perl/MANIFEST (working copy) @@ -1,6 +0,0 @@ -Changes -MANIFEST -Makefile.PL -AbiWord.pm -AbiWord.xs -test.pl Index: src/bindings/perl/Makefile.PL =================================================================== --- src/bindings/perl/Makefile.PL (revision 23327) +++ src/bindings/perl/Makefile.PL (working copy) @@ -1,22 +0,0 @@ -use ExtUtils::MakeMaker; -# See lib/ExtUtils/MakeMaker.pm for details of how to influence -# the contents of the Makefile that is written. - -#abi-js/src/bindings/perl -$abidir = "../.."; - -WriteMakefile( - 'NAME' => 'AbiWord', - 'XSOPT' => '-C++', - 'CC' => 'g++', - 'LD' => 'g++', - #SKIP => [qw(dynamic dynamic_lib dynamic_bs)], - #LINKTYPE => 'static', - 'VERSION_FROM' => 'AbiWord.pm', # finds $VERSION - 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 - 'LIBS' => [''], # e.g., '-lm' - 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' - 'INC' => join(' ', map {"-I$abidir/$_"} - qw(af/ev/xp af/xap/xp af/util/xp af/util/unix ../../expat/lib - text/fmt/xp text/ptbl/xp af/gr/xp wp/impexp/xp wp/ap/xp)), -); Index: src/bindings/perl/Changes =================================================================== --- src/bindings/perl/Changes (revision 23327) +++ src/bindings/perl/Changes (working copy) @@ -1,6 +0,0 @@ -Revision history for Perl extension abi. - -0.01 Sat Apr 7 01:04:55 2001 - - original version; created by Joaquin Cuenca Abela & Paolo Molaro - - Index: src/bindings/perl/test.pl =================================================================== --- src/bindings/perl/test.pl (revision 23327) +++ src/bindings/perl/test.pl (working copy) @@ -1,20 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl test.pl' - -######################### We start with some black magic to print on failure. - -# Change 1..1 below to 1..last_test_to_print . -# (It may become useful if the test is moved to ./t subdirectory.) - -BEGIN { $| = 1; print "1..1\n"; } -END {print "not ok 1\n" unless $loaded;} -use AbiWord; -$loaded = 1; -print "ok 1\n"; - -######################### End of black magic. - -# Insert your test code below (better if it prints "ok 13" -# (correspondingly "not ok 13") depending on the success of chunk 13 -# of the test code): - Index: src/bindings/perl/examples/dynamic_menu.pl =================================================================== --- src/bindings/perl/examples/dynamic_menu.pl (revision 23327) +++ src/bindings/perl/examples/dynamic_menu.pl (working copy) @@ -1,15 +0,0 @@ -sub toto { - my $frame = AbiWord::XAP_Frame::getLastFocussed; - my $view = $frame->getCurrentView; - $view->write("Body 1\n"); - $view->editHeader; - $view->write("Header"); - $view->editFooter; - $view->write("Footer"); - $view->editBody; - $view->write("Body 2\n"); -} - -AbiWord::XAP_Frame::register("toto", "&Edit/Toto", "Description toto", false); - -1; Index: src/bindings/perl/examples/print.pl =================================================================== --- src/bindings/perl/examples/print.pl (revision 23327) +++ src/bindings/perl/examples/print.pl (working copy) @@ -1,16 +0,0 @@ -sub PrintNonInteractive { - my $frame = AbiWord::XAP_Frame::getLastFocussed; - my $view = $frame->getCurrentView; - $view->print; -} - -sub PrintInteractive { - my $frame = AbiWord::XAP_Frame::getLastFocussed; - my $view = $frame->getCurrentView; - $view->showPrintDialog; -} - -AbiWord::XAP_Frame::register("PrintNonInteractive", "&File/PerlPrint", "Another item for print the document", false); -AbiWord::XAP_Frame::register("PrintInteractive", "&File/PerlPrint Interactive", "And another one", true); - -1; Index: src/bindings/perl/examples/test_random_words.pl =================================================================== --- src/bindings/perl/examples/test_random_words.pl (revision 23327) +++ src/bindings/perl/examples/test_random_words.pl (working copy) @@ -1,82 +0,0 @@ -open(TEXT, "/home/cuenca/cvs/abiword/abi/COPYING") or die "eccck. Do you have a \"/home/cuenca/cvs/abiword/abi/COPYING\" ?? :-) : $!"; - -my $frame = AbiWord::XAP_Frame::getLastFocussed; -my $view = $frame->getCurrentView; -my @words; -# most probable choices are the most repeated ones -my @seps = (" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", - " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", - "\t", "\n", "\n\n", ""); - -while () { - push(@words, split(/\s+/)); -} - -my $init_time = time; -my $def_style = 1; -my $i; - -for ($i = 0; $i < 3001; ++$i) { - if (($i % 100) == 0) { - my $current_time = time; - my $delta = $current_time - $init_time; - printf("$i $delta\n"); - $init_time = $current_time; - } - - $def_style = &maybeChangeStyle($view, $def_style); - my $word = &pickoneof(@words); - $view->write($word) unless ($word eq ""); - my $tmp = &pickoneof(@seps); - $view->write($tmp) unless ($tmp eq ""); -} - -close TEXT; -1; - -sub pickoneof -{ - return $_[int(rand(scalar(@_) -1))]; -} - -sub maybeChangeStyle -{ - my $view = shift; - my $defst = shift; - my @ftts = ({"font-weight" => "bold"}, - {"font-weight" => "bold"}, - {"font-weight" => "bold"}, - {"font-style" => "italic"}, - {"font-style" => "italic"}, - {"font-weight" => "bold", - "font-size" => "24pt"}, - {"font-family" => "Courier New", - "font-size" => "11pt"}, - {"font-style" => "normal", - "text-decoration" => "underline"}); - if ($defst == 1) { - if (rand(100) > 95) { - my $char_prop = &pickoneof(@ftts); - $view->setCharFormat(%{$char_prop}); - return 0; - } - } - else { - my $tmp = rand(100); - if ($tmp > 75) { - $view->setCharFormat("font-weight" => "normal", - "font-style" => "normal", - "font-family" => "Times New Roman", - "font-size" => "12pt", - "text-decoration" => "normal"); - return 1; - } - elsif ($tmp > 70) { - my $char_prop = &pickoneof(@ftts); - $view->setCharFormat(%{$char_prop}); - return 0; - } - } - - return 0; -} Index: src/bindings/perl/examples/test_scroll.pl =================================================================== --- src/bindings/perl/examples/test_scroll.pl (revision 23327) +++ src/bindings/perl/examples/test_scroll.pl (working copy) @@ -1,13 +0,0 @@ -# open an empty document -$frame = abi::XAP_Frame::getLastFocussed; -$view = $frame->getCurrentView; -$view->write("1\n"); -$view->write("5\n"); -$view->moveCursorRel("line", -1); -$view->write("3\n"); -$view->moveCursorRel("line", -1); -$view->write("2\n"); -$view->moveCursorRel("line", 1); -$view->write("4\n"); - -1; Index: src/bindings/perl/examples/fax.pl =================================================================== --- src/bindings/perl/examples/fax.pl (revision 23327) +++ src/bindings/perl/examples/fax.pl (working copy) @@ -1,64 +0,0 @@ -# test script for abiword -use strict; -use Gnome; -use Gtk; - -my $false = 0; -my $true = 1; - -Gnome->init("abiword", "0.7.14"); - -my $w = new Gnome::Dialog("Fax Document Composer", "Button_Ok", "Button_Cancel"); -my $table = new Gtk::Table(3, 3, $false); -my $label = new Gtk::Label("Fax Number:"); -my $fax_number = new Gtk::Entry; -my $company_name = new Gtk::Entry; -my $logo = new Gnome::PixmapEntry(0, "Select a logo", $true); -my $frame = new Gtk::Frame("Preview (FIXME!)"); - -$table->attach_defaults($label, 0, 1, 0, 1); -$label = new Gtk::Label("Company Name"); -$table->attach_defaults($label, 0, 1, 1, 2); -$label = new Gtk::Label("Company Logo"); -$table->attach_defaults($label, 0, 1, 2, 3); - -$table->attach_defaults($fax_number, 1, 2, 0, 1); -$table->attach_defaults($company_name, 1, 2, 1, 2); -$table->attach_defaults($logo, 1, 2, 2, 3); - -$table->attach_defaults($frame, 2, 3, 0, 3); - -$table->set_row_spacings(2); -$table->set_col_spacings(8); - -# we add the table to the dialog... -$w->vbox->add($table); - -$w->signal_connect('clicked', \&clicked_cb, $fax_number, $company_name, $logo); -$w->show_all; - -# return a true value -1; - -sub clicked_cb { - my ($dialog, $fax_number, $company_name, $logo, $button_nb) = @_; - - if ($button_nb == 0) { - my $frame = AbiWord::XAP_Frame::getLastFocussed(); - my $view = $frame->getCurrentView(); - - $view->setCharFormat("font-weight" => "bold", "font-size" => "24pt"); - $view->write("FAX Document.\t" . $fax_number->get_text . "\n\n"); - $view->setCharFormat("font-size" => "12pt"); - $view->write("From: "); - $view->setCharFormat("font-weight" => "normal"); - $view->write("TODO (" . $company_name->get_text . ")\n"); - $view->setCharFormat("font-weight" => "bold"); - $view->write("To: "); - $view->setCharFormat("font-weight" => "normal"); - $view->write("TODO\n"); - } - - $dialog->close(); -} - Index: src/bindings/perl/examples/duplicate_selection.pl =================================================================== --- src/bindings/perl/examples/duplicate_selection.pl (revision 23327) +++ src/bindings/perl/examples/duplicate_selection.pl (working copy) @@ -1,7 +0,0 @@ -my $frame = abi::XAP_Frame::getLastFocussed; -my $view = $frame->getCurrentView; -$text = $view->getSelectionText; -# I need a "clearSelection", or something... -$view->moveCursorRel("line", 1); -$view->write($text); -1; Index: src/bindings/perl/examples/find.pl =================================================================== --- src/bindings/perl/examples/find.pl (revision 23327) +++ src/bindings/perl/examples/find.pl (working copy) @@ -1,7 +0,0 @@ -my $true = 1; -my $false = 0; - -my $frame = abi::XAP_Frame::getLastFocussed; -my $view = $frame->getCurrentView; -$view->find("TiTi", false); -1; Index: src/bindings/perl/examples/test_header_footer_body.pl =================================================================== --- src/bindings/perl/examples/test_header_footer_body.pl (revision 23327) +++ src/bindings/perl/examples/test_header_footer_body.pl (working copy) @@ -1,10 +0,0 @@ -my $frame = AbiWord::XAP_Frame::getLastFocussed; -my $view = $frame->getCurrentView; -$view->write("Body 1\n"); -$view->editHeader; -$view->write("Header"); -$view->editFooter; -$view->write("Footer"); -$view->editBody; -$view->write("Body 2\n"); -1;