* Bug 16328 fixed: typos exists => exist
[scilab.git] / scilab / modules / helptools / macros / help.sci
index 6c4440d..efd7068 100644 (file)
@@ -1,90 +1,64 @@
-
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2008 - INRIA
+// Copyright (C) 2008 - INRIA - Vincent COUVERT
+//
+// Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
-// This file must be used under the terms of the CeCILL.
-// This source file is licensed as described in the file COPYING, which
-// you should have received as part of this distribution.  The terms
-// are also available at
-// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// This file was originally licensed under the terms of the CeCILL v2.1,
+// and continues to be available under such terms.
+// For more information, see the COPYING file which you should have received
+// along with this program.
 
-function help(key)
-       
-       //for compatibility with toolboxes making use of old cat files
-       
-       if (fileinfo('SCI/modules/helptools/help') <> []) then
-               
-               global %browsehelp
-               nwniarg=find(sciargs()=="-nwni");
-               texmacsarg=find(sciargs()=="--texmacs");
-               noguiarg=find(sciargs()=="-nogui");
-               
-               if (%browsehelp<>[])&(nwniarg == [])&(texmacsarg == [])&(noguiarg == []) then
-                       
-                       change_old_man()
-                       INDEX=make_help_index()
-                       
-                       if argn(2)==0 then
-                               global %helps
-                               helpbrowser(%helps(:,1), getlanguage());
-                               //browsehelp(INDEX,"index");
-                               return
-                       end
-                       
-                       key=stripblanks(key)
-                       
-                       if or(part(key,1)==['(',')','[',']','{','}','%','''','""',':','*','/', ...
-                               '\','.','<','>','&','^','|','~','+','-']) then
-                               key="symbols";
-                       end
-                       
-                       path=gethelpfile(key)
-                       
-                       if path<>[] then
-                               global %helps
-                               helpbrowser(%helps(:,1), key, getlanguage());
-                               //browsehelp(path,key)
-                       else
-                               apropos(key)
-                       end
-                       
-               else
-                       if (%browsehelp == []) then
-                               warning('%browsehelp not correctly defined. help browser disabled. ');
-                               return;
-                       end
-                       
-                       errmsg='help browser disabled in this mode : ';
-                       
-                       if ( nwniarg <> []) then
-                               errmsg=errmsg+'-nwni';
-                               warning(errmsg);
-                               return;
-                       end
-                       
-                       if ( texmacsarg <> []) then
-                               errmsg=errmsg+ '--texmacs';
-                               warning(errmsg);
-                               return;
-                       end
-                       
-                       if ( noguiarg <> [] ) then
-                               errmsg=errmsg+ '-nogui';
-                               warning(errmsg);
-                               return;
-                       end
-               end
-       else
-               warning('Help not installed');
-       end
-       
-endfunction
+function help(varargin)
+
+    [lhs,rhs]=argn(0);
 
+    if rhs >= 1 then
+        key = varargin(1);
+    else
+        key = "";
+    end
 
+    if (findfiles("SCI/modules/helptools/jar","*_help.jar") <> []) then
 
+        if getscilabmode() <> "NWNI" then
 
+            // No input argument: launch help browser
+            if argn(2)==0 then
+                global %helps
+                helpbrowser(%helps(:,1), getlanguage());
+                return
+            end
 
+            if type(key) <> 10 then
+                error(msprintf(_("%s: Wrong type for input argument #%d: string expected.\n"),"help",1));
+            end
 
+            // Search a function name
+            key=stripblanks(key)
 
+            global %helps
+            symbols = strsplit("()[]{}%''"":*/\.<>&^|~+-")';
+            exceptions = ["%t" "%T" "%f" "%F" "%onprompt"]; // http://bugzilla.scilab.org/15356
+            if or(part(key,1)==symbols) & exists(key)==0 & and(key~=exceptions) then
+                key="symbols";
+            end
 
+            // Treat "$" apart because contrarily to the previous symbols, "$" is an existing variable in Scilab
+            if part(key,1)=="$" & (exists(key)==0 | length(key)==1) then
+                key="symbols";
+            end
 
+            helpbrowser(%helps(:,1), key, getlanguage(), %f);
+
+            // If the function name does not exist, then full-text search is done (See Java code)
+
+        else
+            error(msprintf(gettext("%s: The help browser is disabled in %s mode.\n"), "help", getscilabmode()));
+        end
+    else
+        error(msprintf(gettext("%s: help file(.jar) is not installed.\n"), "help"));
+    end
+
+endfunction