Javadoc search macro

Post user created macros to share with others here.

Moderator: Moderators

Javadoc search macro

Postby ajmoraal on Fri Dec 22, 2006 10:00 am

I created a simple macro for Javadoc help files. It just takes the word under the cursor, and searches recursively in configured paths for <word>.html, and displays it in a browser.

I'm not that impressed myself with the way the paths are configured. Since CMAC doesn't support string arrays, I defined several hard coded strings. But that means I can't use a for loop to cycle through all the paths. Any idea how to make this part more elegant?
Attachments
javadoc.s
(2.35 KiB) Downloaded 1044 times
Last edited by ajmoraal on Thu May 31, 2007 7:38 am, edited 2 times in total.
ajmoraal
Registered User
 
Posts: 13
Joined: Thu Nov 09, 2006 11:31 pm
Location: Using Multi-Edit 8.0j

Postby DanHughes on Fri Dec 22, 2006 4:20 pm

Take a look at MeTools^SearchPath for how to search multiple paths for files.
Dan Hughes
DanHughes
Registered User
 
Posts: 600
Joined: Mon Jun 30, 2003 4:29 am
Location: Indiana

Postby ajmoraal on Thu Jan 04, 2007 12:50 pm

Thanks Dan.
I changed the macro so it now uses a similar logic as the SearchPath function, although I couldn't resist replacing the goto statement with a do..while loop :wink:

Code: Select all
macro_file javadoc;

#include metools.sh
#include mewhelp.sh
#include WinExec.sh

str searchFileRecursive(str directory, str filenameToFind) {
  struct WIN32_FIND_DATA win_fd;
  struct DOS_FIND_DATA dos_fd;
  int find_handle;
  str filename = "";
  str searchpath = directory + "\\*.*";
  find_handle = FindFirstFile(searchpath, &win_fd, &dos_fd);
  if (find_handle) {
    do {
      if ((win_fd.cFileName == ".")
           || (win_fd.cFileName == "..")
           || (win_fd.cFileName == "class-use")) {
        // Skip . , .. and class-use directory entries
      } else if (win_fd.dwFileAttributes & 16) {
        // It is a directory, so call ourself recursive.
        filename = searchFileRecursive(directory + "\\" + win_fd.cFileName,
            filenameToFind);
      } else if (win_fd.cFileName == filenameToFind) {
        // Filename matches, so save full path.
        filename = directory + "\\" + win_fd.cFileName;
      }
    } while(filename == "" && FindNextFile(find_handle, &win_fd, &dos_fd));
    FindClose(find_handle);
  }
  return (filename);
}

macro javadoc {
  //str viewer = "c:\\progra~1\\opera\\opera.exe ";
  str viewer = "c:\\windows\\hh.exe";
  str paths[2048] = "d:\\java\\jdk150_05\\docs\\api;"
      +"d:\\Apple\\Developer\\Documentation\\WebObjects\\Reference\\API;"
      +"Q:\\Developers\\SportsStats\\SOLJars\\commons-lang-2.2\\docs\\api;"
      +"Q:\\Developers\\SportsStats\\SOLJars\\commons-net-1.1.0\\docs\\apidocs;"
      +"Q:\\Developers\\SportsStats\\SOLJars\\logging-log4j-1.2.14\\docs\\api";
  str filename = "";
  str searchFile = Get_Context("[A-Za-z0-9_]") + ".html";
  str path[1024];
  int prevPos = 0, curPos = 0;

  // Loop through all the paths specified in the semi-colon separated
  // 'paths' variable.
  do {
    curPos = XPOS(';', paths, prevPos+1);
    if (curPos == 0) {
      curPos = SVL(paths) + 1;
    }
    path = COPY(paths, prevPos + 1, curPos - prevPos - 1);
    prevPos = curPos;
    if (SVL(path) > 0) {
      make_message("Searching "+path);
      filename = searchFileRecursive(path, searchFile);
    }
  } while ((filename == "") && (prevPos < SVL(paths)));

  if (filename == "") {
    make_message("File "+searchFile+" not found!");
  } else {
    make_message("Opening "+filename);
    WinExecAndWait(viewer+" "+filename, "", _EP_Flags_DontWait, "", "" );
  }
}
ajmoraal
Registered User
 
Posts: 13
Joined: Thu Nov 09, 2006 11:31 pm
Location: Using Multi-Edit 8.0j

Postby DanHughes on Thu Jan 04, 2007 3:33 pm

You must be using very old source code as I tend to change all goto statements to "while" or "do while" statements when I update code that contain them. The SearchPath code was changed to using "while" back in version 9.0 and we have had two major releases since then.

I got curious about when the SearchPath code was changed so I went looking in our code repository and found that the code change was checked in on 1999-11-10 a few months before version 9.0 Beta 1 was released.
Dan Hughes
DanHughes
Registered User
 
Posts: 600
Joined: Mon Jun 30, 2003 4:29 am
Location: Indiana

Postby ajmoraal on Thu Jan 04, 2007 3:37 pm

It's quite old indeed, I'm still working with version 8.0j.
ajmoraal
Registered User
 
Posts: 13
Joined: Thu Nov 09, 2006 11:31 pm
Location: Using Multi-Edit 8.0j

Postby DanHughes on Thu Jan 04, 2007 3:42 pm

To make the javadoc macro work with newer versions of Multi-Edit the following line should be changed.

#include mewhelp.sh

to

#include Help.sh

Thanks for contributing to Multi-Edit.
Dan Hughes
DanHughes
Registered User
 
Posts: 600
Joined: Mon Jun 30, 2003 4:29 am
Location: Indiana


Return to User Created Macros

Who is online

Users browsing this forum: No registered users and 0 guests