]> git.lyx.org Git - lyx.git/blobdiff - src/LyXAction.C
Fix assertion when inserting text strings via clipboard or ascii file; small
[lyx.git] / src / LyXAction.C
index 7c7e850196c98a1d449e3e32a65d80481bcec998..acb0edea9771d643227fa15b441e5c2a0439d02e 100644 (file)
@@ -1,12 +1,12 @@
 /* This file is part of
-* ======================================================
-* 
-*           LyX, The Document Processor
-*       
-*          Copyright (C) 1995 Matthias Ettrich
-*           Copyright (C) 1995-1998 The LyX Team.
-*
-*======================================================*/
+ * ====================================================== 
+ 
+ *           LyX, The Document Processor
+ *      
+ *           Copyright 1995 Matthias Ettrich
+ *           Copyright 1995-1999 The LyX Team.
+ *
+ * ====================================================== */
 
 #include <config.h>
 
@@ -20,7 +20,7 @@
 #endif
 
 #include "LyXAction.h"
-#include "error.h"
+#include "debug.h"
 #include "gettext.h"
 #include "support/lstrings.h"
 
@@ -112,6 +112,7 @@ kb_func_table const lyx_func_table[] = {
         { "citation-insert",                     LFUN_INSERT_CITATION },
        { "command-execute",                      LFUN_EXEC_COMMAND },
        { "command-prefix",                       LFUN_PREFIX },
+       { "command-sequence",                       LFUN_SEQUENCE },
        { "copy",                                 LFUN_COPY },
        { "cut",                                  LFUN_CUT },
        { "delete-backward",                      LFUN_BACKSPACE },
@@ -153,7 +154,9 @@ kb_func_table const lyx_func_table[] = {
        { "index-insert",                         LFUN_INDEX_INSERT },
        { "index-insert-last",                    LFUN_INDEX_INSERT_LAST },
        { "index-print",                          LFUN_INDEX_PRINT },
+#if 0
        { "inset-latex-insert",                   LFUN_INSERT_INSET_LATEX },
+#endif
        { "keymap-off",                           LFUN_KMAP_OFF },
        { "keymap-primary",                       LFUN_KMAP_PRIM },
        { "keymap-secondary",                     LFUN_KMAP_SEC },
@@ -282,11 +285,11 @@ kb_func_table const lyx_func_table[] = {
    field with attributes using these tags:
 
 enum FUNC_ATTRIB {
-    LFAT_NONE=0,     // Nothing special
-    LFAT_ISRO=1,     // Is readonly (does not modify a buffer)
-    LFAT_ISIA=2,     // Is interactive (requires a GUI)
-    LFAT_REQARG=4,   // Requires argument
-    LFAT_ISMO=8,     // Only math mode
+    LFAT_NONE= 0,     // Nothing special
+    LFAT_ISRO= 1,     // Is readonly (does not modify a buffer)
+    LFAT_ISIA= 2,     // Is interactive (requires a GUI)
+    LFAT_REQARG= 4,   // Requires argument
+    LFAT_ISMO= 8,     // Only math mode
     LFAT_ETCETC
 };
 
@@ -350,7 +353,9 @@ kb_action func_attrib_table[] = {
        LFUN_INSERTFOOTNOTE,
        LFUN_INSERT_BIBTEX,
        LFUN_INSERT_CITATION,
+#if 0
        LFUN_INSERT_INSET_LATEX,
+#endif
        LFUN_INSERT_LABEL,
        LFUN_INSERT_MATH,
        LFUN_INSERT_MATRIX,
@@ -436,7 +441,7 @@ LyXAction::~LyXAction()
 // This is wrong, so I'll just disable it for now.
 // The problem is that we might free memory twice in some situations...
 // It's better to leak a bit that to crash. (Asger)
-//             for (int i=0; i < psd_idx; i++) {
+//             for (int i= 0; i < psd_idx; i++) {
 //                     free(lyx_func_args[i].name);
 //             }
                delete[] lyx_func_args;
@@ -449,13 +454,12 @@ LyXAction::~LyXAction()
 int  LyXAction::searchActionArg(kb_action action, char const *arg)
 {
        kb_func_table *tb = &lyx_func_args[0];
-       for (int i=0; i<psd_idx; i++) {
-               if (action==tb->action && !strcmp(tb->name, arg)) {      
+       for (int i= 0; i<psd_idx; i++) {
+               if (action == tb->action && !strcmp(tb->name, arg)) {    
 
-                       lyxerr.debug(string("Pseudoaction already exist[") 
-                                    + tostr(action) + '|' 
-                                    + tostr(arg) + ']',
-                                    Error::KEY);
+                       lyxerr[Debug::KEY] << "Pseudoaction already exist[" 
+                                          << action << '|' 
+                                          << arg << ']' << endl;
 
                        return LFUN_LASTACTION+i;
                }
@@ -473,9 +477,9 @@ int LyXAction::getPseudoAction(kb_action action, char const *arg)
    
        if (psdaction >= 0) return psdaction;
 
-       if (psd_idx>=MAX_PSEUDO_ACTION) {
-               lyxerr.print("Lyx Error: No more pseudo-actions allowed");
-               lyxerr.print("           Tell the developers.");
+       if (psd_idx>= MAX_PSEUDO_ACTION) {
+               lyxerr << "Lyx Error: No more pseudo-actions allowed"
+                      << "           Tell the developers." << endl;
                return -1;
        }
        lyx_func_args[psd_idx].name = strdup(arg);
@@ -493,14 +497,14 @@ int LyXAction::retrieveActionArg(int i, char const** arg)
                *arg = lyx_func_args[i].name;
                return (int)lyx_func_args[i].action;
        } else {
-               lyxerr.print("Lyx Error: Unrecognized pseudo-action");
+               lyxerr << "Lyx Error: Unrecognized pseudo-action" << endl;
                return -1;
        }
 }
 
 
 // Returns an action tag from a string.
-int LyXAction::LookupFunc(char const *func)
+int LyXAction::LookupFunc(char const * func)
 {
        if (!func) 
                return LFUN_UNKNOWN_ACTION;         
@@ -511,14 +515,16 @@ int LyXAction::LookupFunc(char const *func)
       valid func table slot. RVDK_PATCH_5 */
        int k, l= 0, r = funcCount;
        int action = LFUN_UNKNOWN_ACTION;
-       char *arg = strchr(func, ' ');
+       char * arg = strchr(const_cast<char*>(func), ' '); // const cast to
+       // help a sun complier, will go away when this func is rewritten
+       // to use std::containers and std::string.
 
        if (arg) *(arg++) = '\0';      
 
        while (l < r) {
                last_action_idx = (l+r)/2;
                k = strcmp(lyx_func_table[last_action_idx].name, func);
-               if (k==0) {
+               if (k == 0) {
                        action = lyx_func_table[last_action_idx].action;
                        break;
                } else
@@ -526,9 +532,9 @@ int LyXAction::LookupFunc(char const *func)
        }
        if (arg && action >= 0) {
                action = getPseudoAction((kb_action)action, arg);
-               lyxerr.debug(string("Pseudo action_arg[")
-                            + tostr(action) + '|' 
-                            + tostr(arg) + ']',Error::KEY);
+               lyxerr[Debug::KEY] << "Pseudo action_arg["
+                                  << action << '|' 
+                                  << arg << ']' << endl;
        }
        return action;
 }
@@ -565,14 +571,14 @@ char const *LyXAction::getActionName(int action) const
        // why LFUN_LASTACTION -1? Because LFUN_LASTACTION is too
        // large an because there is one internal command, hence
        // lyx_func_table is 2 less then LFUN_LASTACTION (Lgb)
-    for (int i=0; i < funcCount; i++) {
-       if (lyx_func_table[i].action==action)
+    for (int i= 0; i < funcCount; i++) {
+       if (lyx_func_table[i].action == action)
          return lyx_func_table[i].name;
     }
     
     // Hmm.. let's see whether this is a pseudoaction
     action -= LFUN_LASTACTION;
-    if (action>=0 && action<psd_idx) {
+    if (action>= 0 && action<psd_idx) {
        return lyx_func_args[action].name;
     }
     
@@ -585,7 +591,7 @@ char const *LyXAction::getActionName(int action) const
 char const *LyXAction::helpText(kb_action action) const
 {
         static bool is_sorted = false;
-       static kb_func_table helpTexts[LFUN_LASTACTION] =
+       static kb_func_table helpTexts[LFUN_LASTACTION] = 
        {
                { _("Describe command"), LFUN_APROPOS },
                { _("Select previous char"), LFUN_LEFTSEL },
@@ -685,7 +691,7 @@ char const *LyXAction::helpText(kb_action action) const
         
         // Sort to make it faster
         if (!is_sorted) {
-               int i=0; 
+               int i= 0; 
                while (i < LFUN_LASTACTION-1) {
                    if (helpTexts[i].action == 0) {
                        helpTexts[i].action = (kb_action)i;
@@ -704,7 +710,7 @@ char const *LyXAction::helpText(kb_action action) const
                is_sorted = true;
        }
 
-       if (action <=1 || action >=funcCount)
+       if (action <= 1 || action >= funcCount)
                goto no_desc;
                
         if (helpTexts[action].action == action) {
@@ -718,9 +724,9 @@ char const *LyXAction::helpText(kb_action action) const
 
 
 // Function to compare items from the attrib table.
-int actioncomp(const void *a, const void *b)
+extern "C" int actioncomp(const void *a, const void *b)
 {
-    int const *ia=(int const*)a, *ib=(int const*)b;
+    int const *ia= (int const*)a, *ib= (int const*)b;
     return (*ia)-(*ib);
 }
 
@@ -733,7 +739,7 @@ bool LyXAction::isFuncRO(kb_action action) const
     if (!is_sorted) {
        qsort(func_attrib_table, fCount, sizeof(kb_action), actioncomp);
        is_sorted = true;
-//     for (int i=0; i<fCount; i++) 
+//     for (int i= 0; i<fCount; i++) 
 //       fprintf(stdout, "%d: %d\n", i, func_attrib_table[i]);
     }
 
@@ -743,14 +749,18 @@ bool LyXAction::isFuncRO(kb_action action) const
     while (l < r) {
        m = (l+r)/2;
        k = func_attrib_table[m] - action;
-       if (k==0) {
+       if (k == 0) {
            is_ro = true;
            break;
        } else
          if (k<0) l = m+1; else r = m;
     }
-    lyxerr.debug(string("RO[") + tostr(action)
-                 + string(" ") + tostr(is_ro) + string("]"));
+    lyxerr.debug() << "RO[" << action
+                  << " " << is_ro << "]" << endl;
     return is_ro;
 }
 
+ostream & operator<<(ostream & o, kb_action action)
+{
+       return o << int(action);
+}