Reply To: Javadoc search macro

Product Compare Forums Multi-Edit User Created Macros Javadoc search macro Reply To: Javadoc search macro

#6965
Anonymous
Inactive

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:2mag09uk]
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, "", "" );
}
}
[/code:2mag09uk]