/* GUIBEGIN WINDOW , 146, 188, 241, 138, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , HTML Processor FONT 8, 400, MS Shell Dlg PUSH 4, 121, 40, 14, TABSTOP, , Search, ALT "S", &Search PUSH 51, 121, 40, 14, TABSTOP, , Process, ALT "P", &Process LIST 0, 16, 241, 97, NOTIFY|MULTI|BORDER|VSCROLL|HSCROLL|TABSTOP, , MyList, ALT "H" TEXT 2, 4, 45, 8, GROUP, , , , &HTML Files DEND GUIEND */ /* Searches for all .HTM and .HTML files under a directory tree, * displays the names in a list box for the user to select, and * then performs an operation upon the selected names. */ OPTIONS "C_CALL LABELCHECK" NUMERIC DIGITS 10 LIBRARY rexxgui GuiErr = "SYNTAX" GuiHeading = 1 GuiCreateWindow('NORMAL') /* We aren't doing a search/process yet */ Processing = 0 Again: DO FOREVER GuiGetMsg() CATCH SYNTAX CONDITION('M') SIGNAL Again CATCH HALT FINALLY GuiDestroyWindow() END RETURN /* Called by Reginald when the user clicks on our "Search" button */ WM_CLICK_Search: /* Are we processing HTML files, or searching for HTML files? */ IF Processing == 1 THEN DO /* This button was clicked while we were either searching * for HTML files below (ie, filling the listbox) or * processing files (in WM_CLICK_Process). In that case, * this is really the "Stop" button. Call GuiWake with * "ABORT", so the next call to GuiGetMsg() will return * with GuiSignal set to "ABORT" */ GuiWake("ABORT") /* Disable the Stop button. This is just to prevent him * from clicking it again, and causing another GuiWake * above. We only need to GuiWake once */ GuiSetCtlPlacement("Search", , , , , "DISABLE") RETURN END /* Start searching for HTML files */ /* Store the directory in the variable directoryName. */ directoryName = '' DO /* Present the dialog. */ err = guifile('directoryName', 'BROWSE|DRIVES', 'Where to find HTML files:') CATCH SYNTAX /* Get the error message. */ err = CONDITION('D') END /* Check for an error. */ SELECT err WHEN "" THEN DO /* Change the "Search" button to "Stop" */ GuiAddCtlText("Search", "&Stop") /* Indicate that we're searching HTML files */ Processing = 1 /* Populate the list box with the names of whatever HTML files we find */ Count = 0 err = GetHtmlNames(directoryName, 1) /* Done searching for HTML files */ Processing = 0 /* Change the "Search" button back to "Search" */ GuiAddCtlText("Search", "&Search") GuiSetCtlPlacement("Search", , , , , "ENABLE") /* If an error, display an error message */ IF err \== "" & err \== "ABORT" THEN GuiSay(err) END WHEN 'DLL function "GUIFILE" reported "Cancel"' THEN NOP /* Ignore CANCEL. Note we assume GuiHeading = 1. */ OTHERWISE /* Some other error, so display it. */ CONDITION('M') END RETURN /* Populates a list box with the names of all files that end in extensions * of .HTM and .HTML. It does a recursive directory search from the passed * directory name. 'Count' contains a count of the collected names. (This * must be set to 0 before this function is called). Each name is fully * qualified. * * Returns an empty string if successful, or an error message. * * Count = 0 * error = GetHtmlNames(directoryName, 1) * IF error \== "" THEN SAY error * * NOTE: Because we call GuiGetMsg(), that means that any of our * event handlers can be called by GetHtmlNames(). And because we * have used a PROCEDURE on GetHtmlNames(), that means we have to * EXPOSE any main level variables that our event handlers need * to access. The one exception is "GuiWindow". */ GetHtmlNames: PROCEDURE EXPOSE Count Processing /* DO UNTIL no more items or an error */ DO UNTIL err \== "" /* Get the name of the next item inside of this dir */ err = MATCHNAME(ARG(2), 'name', ARG(1) || '\*.*', 'DSNHCRAT', 'NS') /* No error? */ IF err == "" THEN DO /* Call GuiGetMsg to allow us to check if the user has interacted * with the window. But use a "CLEAR" operation, so GuiGetMsg doesn't * pause our script if he hasn't done anything. NOTE: If the user * clicks on the "Stop" button, GuiGetMsg will call WM_CLICK_Search() * right here. */ GuiGetMsg("CLEAR") /* Did he click on the "Stop" button? If so, WM_CLICK_Search * called GuiWake, and GuiSignal was set to "ABORT". */ IF GuiSignal == "ABORT" THEN RETURN 'ABORT' /* Is this a sub-dir? If so, its size will be an empty string */ IF name.0 == "" THEN DO /* Enumerate all items in this sub-dir */ err = GetHtmlNames(ARG(1) || '\' || name, ARG(2) + 1) IF err \== "" THEN RETURN err END /* It's a file. Check its extension for HTM or HTML */ ELSE DO ext = TRANSLATE(FILESPEC('E', name)) IF ext == ".HTM" | ext == ".HTML" THEN DO /* Increment count of files */ Count = Count + 1 /* Add the full pathname to the list */ GuiSendMsg("MyList", "ADDSTRING", , ARG(1) || '\' || name) END END END END /* If we enumerated all items successfully, return an empty string */ IF err == 'DONE' THEN err = "" /* Return an empty string if success, or an error message */ RETURN err /* Called by Reginald when the user clicks on our "Process" button */ WM_CLICK_Process: /* Get the selections in the listbox */ GuiGetCtlValue("MyList") /* Change the "Search" button to "Stop" */ GuiAddCtlText("Search", "Stop") /* Indicate that we're processing HTML files */ Processing = 1 /* Do as many items as the user selected */ DO index = 1 TO MyList.0 /* Call GuiGetMsg to allow us to check if the user has interacted * with the window. But use a "CLEAR" operation, so GuiGetMsg doesn't * pause our script if he hasn't done anything */ GuiGetMsg("CLEAR") /* Did he click on the "Stop" button? If so, WM_CLICK_Search * called GuiWake, and GuiSignal was set to "ABORT". */ IF GuiSignal == "ABORT" THEN RETURN /* Here, you would add whatever code you wish to operate upon this one file. The file's * name is STRS.0.index */ SAY MyList.index END /* Done processing HTML files */ Processing = 0 /* Change the "Search" button back to "Search" */ GuiAddCtlText("Search", "&Search") GuiSetCtlPlacement("Search", , , , , "ENABLE") RETURN